* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #fbbf24;
  --panel: rgba(12, 14, 20, 0.84);
  --border: rgba(251, 191, 36, 0.22);
}

html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif;
  color: var(--text);
  background: #0a0b10;
}

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; touch-action: none; }

.hud-top, .hud-bot, .dock, .card {
  position: fixed;
  z-index: 2;
}

.hud-top {
  top: 0; left: 0; right: 0;
  padding: 0.85rem 1.2rem 0.75rem;
  padding-left: max(1.2rem, env(safe-area-inset-left));
  padding-right: max(1.2rem, env(safe-area-inset-right));
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(10, 11, 16, 0.92) 40%, transparent);
  z-index: 3;
}
.nav { margin-bottom: 0.35rem; font-size: 0.88rem; pointer-events: auto; }
.nav a { color: var(--muted); text-decoration: none; }
.nav a:hover { color: var(--accent); }

h1 {
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(100deg, #fde68a, #fdba74, #e2e8f0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.lede {
  color: var(--muted);
  font-size: 0.9rem;
  max-width: min(38rem, calc(100vw - 22rem));
  margin-top: 0.25rem;
  line-height: 1.45;
}

@media (min-width: 721px) {
  .hud-top > div {
    margin-left: min(288px, 34vw);
  }
  .dock { top: 4.25rem; }
}

.hud-bot {
  bottom: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1.2rem max(0.95rem, env(safe-area-inset-bottom));
  font-size: 0.76rem;
  color: #cbd5e1;
  background: linear-gradient(to top, rgba(10, 11, 16, 0.8), transparent);
  pointer-events: none;
}
.muted { color: var(--muted); }

.dock {
  left: 1rem;
  top: 6.75rem;
  width: min(268px, calc(100vw - 2rem));
  max-height: calc(100dvh - 9.2rem);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1rem 1.05rem 1.1rem;
  border-radius: 1rem;
  border: 1px solid var(--border);
  background: var(--panel);
  backdrop-filter: blur(12px);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.4);
}
.dock-toggle { display: none; }
.dock-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.4rem;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0.7rem 0 0.35rem;
}
.readout {
  letter-spacing: 0.02em;
  text-transform: none;
  color: #fde68a;
  font-weight: 600;
}
.finish-wrap.hidden, .modules-wrap.hidden, .chime-wrap.hidden { display: none; }
.chime-wrap {
  margin-top: 0.55rem;
}
.chime-wrap select {
  width: 100%;
  margin-bottom: 0.15rem;
}
#chime-now-btn {
  width: 100%;
  margin-top: 0.35rem;
}
#chime-silence-btn {
  width: 100%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--border);
}
.modules-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.mod-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: #e2e8f0;
  cursor: pointer;
}
.mod-row input {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: #fbbf24;
  flex: 0 0 auto;
}
.mod-row.is-locked { opacity: 0.55; cursor: default; }
.finish-hint { margin-top: 0.35rem; }
.dock-label:first-child { margin-top: 0; }

.brand-box {
  margin-top: 0.75rem;
  padding: 0.6rem 0.65rem 0.7rem;
  border-radius: 0.65rem;
  border: 1px solid rgba(251, 191, 36, 0.18);
  background: rgba(0, 0, 0, 0.28);
}
.brand-name {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #fbbf24;
  font-weight: 700;
}
.brand-cal {
  font-size: 0.92rem;
  font-weight: 700;
  margin: 0.15rem 0 0.35rem;
}
.cell-box {
  margin-top: 0.55rem;
  padding: 0.5rem 0.65rem 0.6rem;
  border-radius: 0.65rem;
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(0, 0, 0, 0.22);
}
.cell-box.hidden { display: none; }
.cell-name {
  font-size: 0.86rem;
  font-weight: 700;
  margin: 0.1rem 0 0.25rem;
  font-variant-numeric: tabular-nums;
}
.cell-spec {
  font-size: 0.74rem;
  color: #cbd5e1;
  line-height: 1.4;
}
.brand-blurb {
  font-size: 0.76rem;
  color: #cbd5e1;
  line-height: 1.4;
}

select, button, input[type="range"] { width: 100%; }
select {
  appearance: none;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  padding: 0.5rem 0.65rem;
  font: inherit;
}
input[type="range"] { accent-color: #fbbf24; }

.vitals {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin: 0.85rem 0 0.75rem;
}
.vitals > div {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.55rem;
  padding: 0.4rem 0.5rem;
}
.vitals span {
  display: block;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.vitals strong {
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 0.55rem 0.7rem;
  margin-top: 0.4rem;
  font: inherit;
  font-weight: 700;
  font-size: 0.86rem;
  cursor: pointer;
  color: #1c1408;
  background: linear-gradient(90deg, #fde68a, #fdba74);
}
#light-btn { display: none; }
#shake-btn, #light-btn, #mute-btn, #theme-btn {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--border);
}

html.theme-light {
  --text: #1c1916;
  --muted: #5f574e;
  --accent: #b45309;
  --panel: rgba(255, 251, 246, 0.9);
  --border: rgba(146, 96, 32, 0.24);
}
html.theme-light,
html.theme-light body {
  background: #d4e4f4;
  color: var(--text);
}
html.theme-light .hud-top {
  background: linear-gradient(to bottom, rgba(212, 228, 244, 0.94) 38%, transparent);
}
html.theme-light .hud-bot {
  color: #3f3a34;
  background: linear-gradient(to top, rgba(212, 228, 244, 0.88), transparent);
}
html.theme-light h1 {
  background: linear-gradient(100deg, #9a3412, #b45309, #292524);
  -webkit-background-clip: text;
  background-clip: text;
}
html.theme-light .dock,
html.theme-light .card {
  box-shadow: 0 16px 36px rgba(70, 50, 20, 0.12);
}
html.theme-light select {
  background: rgba(255, 255, 255, 0.78);
}
html.theme-light .vitals > div {
  background: rgba(255, 255, 255, 0.58);
  border-color: rgba(40, 32, 24, 0.08);
}
html.theme-light .brand-box,
html.theme-light .cell-box {
  background: rgba(255, 255, 255, 0.48);
  border-color: rgba(146, 96, 32, 0.18);
}
html.theme-light .brand-name,
html.theme-light .readout,
html.theme-light .kicker {
  color: #b45309;
}
html.theme-light .mod-row {
  color: #1c1916;
}
html.theme-light .card p,
html.theme-light .cell-spec,
html.theme-light .brand-blurb {
  color: #4b453d;
}
html.theme-light #shake-btn,
html.theme-light #light-btn,
html.theme-light #mute-btn,
html.theme-light #theme-btn,
html.theme-light #chime-silence-btn {
  background: rgba(255, 255, 255, 0.55);
  color: var(--text);
}
html.theme-light .close {
  color: var(--muted);
}
.hint {
  margin-top: 0.65rem;
  font-size: 0.76rem;
  color: var(--muted);
  line-height: 1.4;
}

.card {
  top: 50%;
  right: 1.1rem;
  transform: translateY(-50%);
  width: min(300px, calc(100vw - 1.6rem));
  padding: 1rem 1.05rem;
  border-radius: 1rem;
  border: 1px solid var(--border);
  background: var(--panel);
  backdrop-filter: blur(12px);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}
.card.hidden { display: none; }
.kicker {
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.25rem;
}
.card h2 { font-size: 1.12rem; margin-bottom: 0.4rem; }
.card p { color: #cbd5e1; font-size: 0.9rem; line-height: 1.5; }
.close {
  display: block;
  margin-top: 0.65rem;
  background: transparent;
  color: var(--muted);
  border: 0;
  font: inherit;
  cursor: pointer;
  font-size: 0.82rem;
  padding: 0;
  width: auto;
}

@media (max-width: 900px) {
  .lede { max-width: calc(100vw - 2.4rem); }
}

@media (max-width: 720px) {
  .lede { display: none; }
  .hud-top { padding-bottom: 0.4rem; }
  .hud-bot { display: none; }

  .dock {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    max-height: min(48dvh, 22rem);
    border-radius: 1rem 1rem 0 0;
    padding: 0.45rem 0.9rem max(0.85rem, env(safe-area-inset-bottom));
    box-shadow: 0 -12px 36px rgba(0, 0, 0, 0.45);
  }
  .dock-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin: 0 0 0.35rem;
    padding: 0.45rem 0.15rem 0.55rem;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
  }
  .dock-toggle .chevron {
    width: 0.55rem;
    height: 0.55rem;
    border-right: 2px solid #fde68a;
    border-bottom: 2px solid #fde68a;
    transform: rotate(45deg);
    transition: transform 0.2s ease;
  }
  .dock.collapsed .dock-toggle .chevron { transform: rotate(-135deg); }
  .dock.collapsed {
    max-height: none;
    overflow: visible;
  }
  .dock.collapsed .dock-body,
  .dock.collapsed .brand-box,
  .dock.collapsed .cell-box { display: none; }

  .card {
    top: 4.6rem;
    right: 0.6rem;
    left: 0.6rem;
    width: auto;
    max-height: 36dvh;
    overflow-y: auto;
    transform: none;
  }

  select, button, input[type="range"] { font-size: 16px; }
  input[type="range"] { min-height: 1.6rem; }
  button { min-height: 2.6rem; }
}
