/* Shell: top bar, navigation, session and theme popovers, mobile menu, views. */

.app {
  min-height: calc(100 * var(--vh));
  min-height: calc(100 * var(--dvh));
}

.shell {
  display: flex;
  flex-direction: column;
  min-height: calc(100 * var(--vh));
  min-height: calc(100 * var(--dvh));
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
}

.view {
  display: none;
}

.view.active {
  display: block;
  flex: 1;
  animation: view-in 220ms var(--ease-out);
}

@keyframes view-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

/* The cream logo sits on a plain navy tile on light grounds and straight on the navy ground in dark. */
.logo-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 56px;
  padding: 0 18px;
  border-radius: var(--r-md);
  background-color: var(--navy);
}

:root[data-theme-mode="dark"] .logo-tile {
  padding: 0;
  background-color: transparent;
}

.logo-tile img {
  height: 40px;
  width: auto;
  user-select: none;
  -webkit-user-drag: none;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: var(--s-4);
  min-height: var(--topbar-h);
  padding: 0 var(--page-gutter);
  padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--ground) 92%, transparent);
  border-bottom: 1px solid var(--rule);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  min-width: 0;
}

.brand-copy {
  min-width: 0;
}

.brand-subtitle {
  overflow: hidden;
  color: var(--ink-2);
  font-size: var(--text-sm);
  font-weight: 550;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.topbar-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-width: 0;
}

.topbar-status:empty {
  display: none;
}

.topbar-status .badge {
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-2);
  font-size: var(--text-sm);
  font-weight: 550;
}

.topbar-status .badge + .badge::before {
  content: "";
  width: 3px;
  height: 3px;
  margin: 0 var(--s-2) 0 2px;
  border-radius: 50%;
  background: var(--ink-3);
}

.topbar-status .badge.red {
  color: var(--red);
}

.topbar-status .badge.red::after {
  content: "";
  order: -1;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--red);
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s-2);
  min-width: 0;
}

/* Views: a segmented control */
.nav-tabs {
  display: inline-flex;
  padding: 3px;
  border-radius: var(--r-sm);
  background: var(--face-3);
  border: 1px solid var(--rule);
}

.nav-tabs .tab-button {
  min-height: 32px;
  padding: 0 var(--s-4);
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-2);
  font-size: var(--text-sm);
  font-weight: 600;
}

.nav-tabs .tab-button:hover:not(.active) {
  background: transparent;
  color: var(--ink);
}

.nav-tabs .tab-button.active {
  background: var(--face);
  color: var(--ink);
  box-shadow: var(--lift-1);
}

/* Sync state */
.sync-dot {
  position: relative;
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.hosted-session-chip[data-status="syncing"] .sync-dot {
  background: var(--amber);
  animation: sync-breathe 1.2s var(--ease-in-out) infinite;
}

.hosted-session-chip[data-status="offline"] .sync-dot {
  background: var(--red);
  box-shadow: 0 0 0 3px var(--red-soft);
}

@keyframes sync-breathe {
  50% {
    opacity: 0.35;
  }
}

.sync-state {
  display: none;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 0 var(--s-2);
  border-radius: var(--r-xs);
  color: var(--ink-2);
  font-size: var(--text-xs);
  font-weight: 600;
}

.sync-state i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.sync-state[data-status="syncing"] i {
  background: var(--amber);
  animation: sync-breathe 1.2s var(--ease-in-out) infinite;
}

.sync-state[data-status="offline"] {
  background: var(--red-soft);
  color: var(--red);
}

.sync-state[data-status="offline"] i {
  background: var(--red);
}

/* Session chip and popovers */
.hosted-session-switcher,
.theme-picker {
  position: relative;
}

.hosted-session-chip {
  min-height: 38px;
  padding: 0 var(--s-3);
  gap: var(--s-2);
  border-color: var(--rule);
  background: var(--face);
  font-size: var(--text-sm);
}

.session-chip-name {
  max-width: 180px;
  overflow: hidden;
  padding-right: var(--s-2);
  border-right: 1px solid var(--rule);
  color: var(--ink);
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.session-chip-name:empty {
  display: none;
}

body.projector-mode .brand-subtitle {
  display: none;
}

.session-chip-label {
  color: var(--ink-3);
  font-weight: 500;
}

.session-chip-code strong {
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: 0.08em;
}

.session-chip-chevron {
  width: 14px;
  height: 14px;
  color: var(--ink-3);
  transition: transform var(--t-base) var(--ease-out);
}

.hosted-session-chip[aria-expanded="true"] .session-chip-chevron {
  transform: rotate(180deg);
}

.popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 60;
  width: 320px;
  padding: var(--s-4);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  background: var(--face);
  box-shadow: var(--lift-3);
  animation: pop-in 180ms var(--ease-out);
  transform-origin: top right;
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
}

.menu-label {
  color: var(--ink-3);
  font-size: var(--text-xs);
  font-weight: 600;
}

.hosted-session-menu {
  display: grid;
  gap: var(--s-4);
}

.hosted-session-menu-heading {
  display: grid;
  gap: 2px;
}

.hosted-session-menu-heading strong {
  font: 600 var(--text-3xl) / 1.1 var(--font-mono);
  letter-spacing: 0.12em;
  user-select: all;
}

.hosted-session-copy {
  justify-content: flex-start;
  min-height: 52px;
  padding: 0 var(--s-3);
  text-align: left;
}

.hosted-session-copy span {
  display: grid;
  gap: 2px;
}

.hosted-session-copy small {
  color: var(--ink-3);
  font-size: var(--text-xs);
  font-weight: 450;
}

.hosted-session-recent {
  display: grid;
  gap: var(--s-2);
}

.hosted-session-recent-list {
  display: grid;
  gap: 2px;
}

.hosted-session-recent-list button {
  justify-content: space-between;
  min-height: 40px;
  border-color: transparent;
  background: var(--face-2);
  font-size: var(--text-sm);
}

.hosted-session-recent-list button strong {
  font-family: var(--font-mono);
  letter-spacing: 0.08em;
}

.hosted-session-form {
  gap: var(--s-2);
}

.hosted-session-form > div {
  display: flex;
  gap: var(--s-2);
}

.hosted-session-form input {
  flex: 1;
}

.hosted-session-code-input {
  font-family: var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hosted-session-menu-error {
  color: var(--red);
  font-size: var(--text-sm);
}

/* Theme picker */
.theme-picker > summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 44px;
  height: 38px;
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  background: var(--face);
  color: var(--ink-2);
  transition: background-color var(--t-fast) var(--ease-out);
}

.theme-picker > summary:hover {
  background: var(--face-2);
}

.theme-picker .theme-current-swatch {
  display: none;
}

.theme-popover {
  display: grid;
  gap: var(--s-4);
  width: 280px;
}

.theme-popover > p {
  color: var(--ink-3);
  font-size: var(--text-xs);
}

.theme-control-group {
  display: grid;
  gap: var(--s-2);
}

.theme-control-label {
  display: block;
  color: var(--ink-3);
  font-size: var(--text-xs);
  font-weight: 600;
}

.theme-mode-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  background: var(--face-3);
}

.theme-mode-options button {
  min-height: 32px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-2);
  font-size: var(--text-sm);
}

.theme-mode-options button:hover:not(.active) {
  background: transparent;
  color: var(--ink);
}

.theme-mode-options button.active {
  background: var(--face);
  color: var(--ink);
  box-shadow: var(--lift-1);
}

.theme-color-options {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.theme-color-swatch {
  width: 32px;
  min-width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  border: 2px solid var(--face);
  border-radius: 50%;
  background: var(--theme-swatch);
  box-shadow: 0 0 0 1px var(--rule-strong);
}

.theme-color-swatch:hover:not(:disabled) {
  background: var(--theme-swatch);
  border-color: var(--face);
  transform: scale(1.06);
}

.theme-color-swatch.active {
  box-shadow: 0 0 0 2px var(--ink);
}

.theme-custom-color {
  position: relative;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: conic-gradient(#d4433b, #e2a33b, #4aa26c, #3b7bd4, #8c5bd4, #d4433b);
  box-shadow: 0 0 0 1px var(--rule-strong);
}

.theme-custom-color input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  opacity: 0;
  border-radius: 50%;
}

/* Mobile menu */
.mobile-app-menu-shell {
  display: none;
}

.mobile-app-menu-button {
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  border-color: transparent;
  background: transparent;
}

.mobile-app-menu-button .icon {
  width: 22px;
  height: 22px;
}

.mobile-app-menu {
  position: fixed;
  top: calc(var(--topbar-h) + env(safe-area-inset-top));
  left: 0;
  right: 0;
  z-index: 70;
  display: grid;
  gap: var(--s-4);
  max-height: calc(calc(100 * var(--dvh)) - var(--topbar-h) - env(safe-area-inset-top));
  overflow: auto;
  padding: var(--s-4) var(--page-gutter) calc(var(--s-6) + env(safe-area-inset-bottom));
  background: var(--ground);
  border-bottom: 1px solid var(--rule);
  box-shadow: var(--lift-3);
  animation: menu-in 220ms var(--ease-out);
}

@keyframes menu-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
}

.mobile-app-menu-nav {
  display: grid;
  gap: 2px;
  padding: 4px;
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  background: var(--face);
}

.mobile-app-menu-nav .tab-button {
  justify-content: flex-start;
  min-height: 48px;
  padding: 0 var(--s-4);
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  font-size: var(--text-lg);
  font-weight: 600;
}

.mobile-app-menu-nav .tab-button.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.mobile-session-current {
  display: grid;
  gap: var(--s-2);
  padding: var(--s-4);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  background: var(--face);
}

.mobile-session-code-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
}

.mobile-session-code-row code {
  font-size: var(--text-3xl);
  font-weight: 600;
  letter-spacing: 0.12em;
  user-select: all;
  -webkit-user-select: all;
}

.mobile-session-copy-hint {
  color: var(--ink-3);
  font-size: var(--text-xs);
}

.menu-disclosure {
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  background: var(--face);
}

.menu-disclosure > summary {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-height: 52px;
  padding: 0 var(--s-4);
  font-weight: 600;
}

.menu-disclosure > summary > span:not(.theme-current-swatch) {
  flex: 1;
}

.disclosure-chevron {
  width: 16px;
  height: 16px;
  color: var(--ink-3);
  transition: transform var(--t-base) var(--ease-out);
}

details[open] > summary .disclosure-chevron {
  transform: rotate(180deg);
}

.menu-disclosure > :not(summary) {
  padding: 0 var(--s-4) var(--s-4);
}

.menu-disclosure .theme-current-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--rule-strong);
}

.theme-panel-body {
  display: grid;
  gap: var(--s-4);
}

/* Boot */
.boot-state {
  display: grid;
  justify-items: center;
  gap: var(--s-3);
  max-width: 420px;
  margin: calc(18 * var(--vh)) auto 0;
  padding: 0 var(--page-gutter);
  text-align: center;
}

.boot-state p {
  color: var(--ink-2);
}

.boot-card {
  display: grid;
  place-items: center;
  width: 56px;
  height: 76px;
  margin-bottom: var(--s-2);
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-sm);
  background: var(--face);
  box-shadow: var(--lift-2);
  font-size: 26px;
  animation: boot-turn 1.6s var(--ease-in-out) infinite;
}

@keyframes boot-turn {
  50% {
    transform: rotateY(180deg);
  }
}

.load-error {
  max-width: 560px;
  margin: calc(12 * var(--vh)) auto 0;
  padding: var(--s-8);
}

.load-error h2 {
  margin-bottom: var(--s-2);
}

.load-error p {
  color: var(--ink-2);
}
