:root {
  --bg: #07090f;
  --ink: #f4f0e6;
  --muted: #a7b0c0;
  --gold: #f2c14a;
  --gold-2: #ffe7a8;
  --mint: #8ef0c8;
  --bad: #ff5d73;
  --line: rgba(255, 255, 255, 0.12);
  --panel: rgba(8, 10, 16, 0.82);
  --sans: "Syne", "Avenir Next", "Segoe UI", sans-serif;
  --ui: "Avenir Next", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { overflow: hidden; font-family: var(--ui); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
::selection { background: var(--gold); color: #1a1408; }

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
body.seated #view { filter: brightness(0.45) saturate(1.05); }

#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(0, 0, 0, 0.45) 100%);
}

#title {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(320px, 480px) 1fr;
  pointer-events: none;
}
#title .panel {
  pointer-events: auto;
  padding: 48px 40px 36px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: linear-gradient(90deg, rgba(7, 9, 15, 0.94) 0%, rgba(7, 9, 15, 0.88) 62%, rgba(7, 9, 15, 0) 100%);
}
.crescent {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 32%, #fff7df, #f2c14a 46%, #c4892a 70%, #8a5a16);
  box-shadow: 0 0 40px rgba(242, 193, 74, 0.45);
  position: relative;
  margin-bottom: 18px;
}
.crescent::after {
  content: "";
  position: absolute;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #07090f;
  left: 16px;
  top: -6px;
}
.eyebrow {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold-2);
}
#title h1 {
  font-family: var(--sans);
  font-weight: 800;
  font-size: clamp(64px, 7vw, 96px);
  letter-spacing: -0.07em;
  line-height: 0.86;
  margin: 10px 0 14px;
  white-space: nowrap;
}
#title h1::after {
  content: "_";
  color: #9ad7ff;
  animation: blink 1.1s steps(1) infinite;
  font-weight: 700;
}
@keyframes blink { 50% { opacity: 0; } }
.tag {
  font-size: 18px;
  line-height: 1.35;
  max-width: 28ch;
  margin: 0 0 22px;
  color: #d9deea;
}
.fine {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  margin: 0 0 22px;
}
#clock-form { display: flex; flex-direction: column; gap: 8px; max-width: 320px; }
#clock-form label { font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
#name {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  font-family: var(--mono);
}
#name:focus { border-color: rgba(242, 193, 74, 0.7); }
.row { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
button.primary {
  background: var(--gold);
  color: #1a1408;
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  font-family: var(--sans);
  font-weight: 700;
  letter-spacing: -0.03em;
  font-size: 16px;
}
button.primary:hover { background: var(--gold-2); }
button.ghost, button.texty {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 14px;
}
button.texty { border: 0; padding: 8px 0; color: var(--muted); border-radius: 0; }
.title-actions { display: flex; gap: 16px; margin-top: 18px; }
.title-board { margin-top: 28px; max-width: 340px; }
.title-board h2 {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  margin: 0 0 8px;
}
.title-board ol { list-style: none; margin: 0; padding: 0; }
.title-board li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-family: var(--mono);
  font-size: 13px;
  padding: 4px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.title-board .empty { color: var(--muted); font-family: var(--mono); font-size: 13px; }
.pid { color: var(--muted); font-size: 11px; }

#hud {
  position: fixed;
  inset: 16px 16px auto 16px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}
#hud button, #hud .pips { pointer-events: auto; }
.hud-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 14px;
  backdrop-filter: blur(8px);
}
.mark {
  font-family: var(--sans);
  font-weight: 800;
  letter-spacing: -0.05em;
  font-size: 18px;
}
#hud-name { color: var(--muted); font-family: var(--mono); font-size: 12px; }
#hud-score {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 22px;
  color: var(--gold-2);
  line-height: 1.1;
  margin-top: 2px;
}
#hud-tickets, #hud-online, #hud-clock { font-family: var(--mono); font-size: 12px; color: var(--muted); }
#hud-clock { font-size: 22px; color: var(--ink); letter-spacing: -0.04em; font-family: var(--sans); font-weight: 700; }
.hud-right { text-align: right; }
.hud-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.hud-actions button {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  font-family: var(--mono);
  font-size: 12px;
}
#dept-pips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
  max-width: 230px;
}
.pip {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  background: rgba(8, 10, 16, 0.55);
  border-radius: 999px;
  padding: 3px 8px;
  width: max-content;
}
.pip.done { color: var(--mint); }

#prompt {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  align-items: center;
  background: rgba(8, 10, 16, 0.82);
  border: 1px solid var(--line);
  padding: 10px 14px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 13px;
  max-width: min(560px, calc(100% - 32px));
}
kbd {
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-bottom-width: 3px;
  border-radius: 6px;
  padding: 2px 7px;
  font-family: inherit;
  background: rgba(255, 255, 255, 0.04);
}

#toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(360px, calc(100% - 32px));
  pointer-events: none;
  z-index: 20;
}
.toast {
  background: rgba(10, 12, 18, 0.92);
  border: 1px solid var(--line);
  border-left: 3px solid var(--gold);
  border-radius: 12px;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.4;
  animation: rise 0.35s ease;
}
.toast.bad { border-left-color: var(--bad); }
.toast.good { border-left-color: var(--mint); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

#terminal-wrap {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 76px 16px 16px;
  background: rgba(0, 0, 0, 0.28);
  z-index: 5;
}
#terminal-wrap.shake { animation: shake 0.35s ease; }
@keyframes shake {
  25% { translate: -8px 0; }
  75% { translate: 8px 0; }
}
#terminal {
  width: min(860px, calc(100vw - 32px));
  height: min(640px, calc(100vh - 48px));
  background: #0c1018;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  --accent: var(--gold);
}
.term-top {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 14px 16px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  border-top: 3px solid var(--accent);
}
.lights { display: flex; gap: 6px; }
.lights i { width: 10px; height: 10px; border-radius: 50%; display: block; background: #3a4254; }
.lights i:nth-child(1) { background: #ff5d73; }
.lights i:nth-child(2) { background: #f2c14a; }
.lights i:nth-child(3) { background: #8ef0c8; }
#term-kicker { font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
#term-title { margin: 0; font-family: var(--sans); font-size: 26px; letter-spacing: -0.04em; }
#term-pay { margin-left: auto; text-align: right; font-family: var(--mono); font-size: 12px; color: var(--muted); line-height: 1.45; white-space: pre-line; }
#term-close {
  flex: none;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  font-family: var(--mono);
  font-size: 13px;
}
#term-brief {
  margin: 0;
  padding: 12px 16px;
  color: #d7deea;
  line-height: 1.45;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
#term-scroll {
  flex: 1;
  overflow: auto;
  padding: 12px 16px 8px;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
#term-scroll .cmd { color: #d7e6ff; }
#term-scroll .err { color: #ffb3c0; }
#term-scroll .sys { color: #8ef0c8; }
#term-scroll .hint { color: #ffe7a8; }
.lesson {
  margin: 10px 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(142, 240, 200, 0.08);
  border: 1px solid rgba(142, 240, 200, 0.25);
  white-space: normal;
}
.lesson .kicker { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--mint); }
.lesson p { margin: 4px 0 0; }
#term-form {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 16px 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
#term-prompt { font-family: var(--mono); color: var(--mint); font-size: 13px; flex: none; }
#term-input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: none;
  font-family: var(--mono);
  font-size: 13.5px;
  padding: 6px 0;
}
.term-foot {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 0 16px 14px;
}
.term-foot button {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  font-family: var(--mono);
  font-size: 12px;
}
#term-hint { color: var(--gold-2); }
#term-hint-left { margin-left: auto; color: var(--muted); font-family: var(--mono); font-size: 12px; }

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.45);
  z-index: 6;
}
.modal-card {
  width: min(720px, calc(100vw - 32px));
  max-height: min(80vh, 760px);
  overflow: auto;
  background: #10141d;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px 18px 20px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.4);
}
.modal-card header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.modal-card h2 { font-family: var(--sans); letter-spacing: -0.04em; margin: 0; font-size: 32px; }
.modal-card h3 { font-family: var(--sans); margin: 18px 0 6px; }
table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 13px; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
th, td { padding: 8px 6px; border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
td.num, th.num { text-align: right; }
tr.me td { color: var(--gold-2); }
.note {
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.note .meta { font-family: var(--mono); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--mint); }
.howto p, .howto li { line-height: 1.5; color: #d7deea; }
.howto ul { padding-left: 18px; }

#finale .modal-card {
  background:
    radial-gradient(circle at 20% 0%, rgba(242, 193, 74, 0.18), transparent 40%),
    #10141d;
}
#finale p { font-size: 18px; line-height: 1.45; max-width: 40ch; }

#pad { display: none; }

@media (max-width: 900px), ((pointer: coarse) and (max-height: 520px)) {
  #title { grid-template-columns: 1fr; }
  #title .panel { background: rgba(7, 9, 15, 0.88); }
  #dept-pips { display: none; }

  #hud {
    inset: max(8px, env(safe-area-inset-top)) 8px auto 8px;
    gap: 8px;
  }
  .hud-card { padding: 8px 10px; }
  .mark, #hud-score, #hud-clock { font-size: 16px; }
  .hud-actions button { padding: 8px 10px; }

  body.playing #pad {
    display: block;
    position: fixed;
    z-index: 4;
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    bottom: calc(var(--vv-bottom, 0px) + max(10px, env(safe-area-inset-bottom)));
    height: 156px;
    pointer-events: none;
  }
  body.seated #pad { display: none; }
  .pad-move, #pad-sit { pointer-events: auto; touch-action: none; }
  .pad-move {
    width: 150px;
    height: 150px;
    display: grid;
    grid-template-columns: repeat(3, 46px);
    grid-template-rows: repeat(3, 46px);
    gap: 6px;
  }
  .pad-move button, #pad-sit {
    background: rgba(8, 10, 16, 0.82);
    border: 1px solid var(--line);
    color: var(--ink);
    font-family: var(--mono);
    font-size: 18px;
    user-select: none;
    -webkit-user-select: none;
  }
  .pad-move button { border-radius: 12px; }
  .pad-move button[data-dir="n"] { grid-area: 1 / 2; }
  .pad-move button[data-dir="w"] { grid-area: 2 / 1; }
  .pad-move button[data-dir="e"] { grid-area: 2 / 3; }
  .pad-move button[data-dir="s"] { grid-area: 3 / 2; }
  #pad-sit {
    position: absolute;
    right: 0;
    bottom: 28px;
    width: 74px;
    height: 74px;
    border-radius: 50%;
    font-size: 15px;
  }
  #pad-sit.ready { border-color: var(--gold); color: var(--gold-2); }

  #prompt {
    bottom: calc(176px + var(--vv-bottom, 0px) + env(safe-area-inset-bottom));
    z-index: 4;
  }

  #terminal-wrap {
    display: flex;
    align-items: stretch;
    justify-content: center;
    top: var(--vv-top, 0px);
    right: 0;
    bottom: auto;
    left: 0;
    height: var(--vv-h, 100dvh);
    max-height: var(--vv-h, 100dvh);
    padding:
      max(8px, env(safe-area-inset-top))
      8px
      max(8px, env(safe-area-inset-bottom));
  }
  #terminal {
    width: 100%;
    height: auto;
    flex: 1;
    min-height: 0;
    border-radius: 14px;
  }
  .term-top { gap: 8px; padding: 10px 12px 8px; }
  #term-title { font-size: 18px; }
  #term-pay { font-size: 11px; }
  #term-brief {
    padding: 8px 12px;
    font-size: 13px;
    max-height: 4.6em;
    overflow: auto;
  }
  #term-input { font-size: 16px; }
  .term-foot { padding: 0 12px 12px; }
  .term-foot button { padding: 10px 14px; font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; }
}
