@font-face {
  font-family: "Silkscreen";
  src: url("/fonts/Silkscreen-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Silkscreen";
  src: url("/fonts/Silkscreen-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Cubic11";
  src: url("/fonts/Cubic11-subset.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --sky: #17152d;
  --sky-2: #28234b;
  --dune: #bca8e8;
  --ink: #f4efff;
  --dim: #9990bd;
  --lavender: #d9d1f2;
  --accent: #ffb83d;
  --bad: #ff6b8b;
  --good: #59d9aa;
  --panel: #242044;
  --line: #40386e;
  --f-pixel: "Cubic11", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --f-number: "Silkscreen", "Cubic11", ui-monospace, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  overflow-x: hidden;
  background: var(--sky);
  color: var(--ink);
  font-family: var(--f-pixel);
  font-size: 15px;
  line-height: 1.5;
}
button, input, textarea { font: inherit; }
button { color: inherit; }
.wrap {
  width: min(100% - 32px, 860px);
  margin: 0 auto;
  padding: 18px 0 42px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.marquee {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.marquee h1 {
  margin: 0;
  color: var(--accent);
  font-family: var(--f-number);
  font-size: clamp(26px, 6vw, 40px);
  letter-spacing: .04em;
  line-height: 1.1;
  text-shadow: 3px 3px 0 var(--sky-2);
}
.tag { color: var(--dim); font-size: 13px; }
.connection {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--dim);
  font-size: 12px;
  white-space: nowrap;
}
.connection::before { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); content: ""; }
.connection.online { color: var(--good); }
.connection.online::before { background: var(--good); }
.connection.solo { color: var(--good); }
.connection.solo::before { background: var(--good); }
.connection.connecting::before { background: var(--ink); animation: blink 1s steps(2, jump-none) infinite; }
.connection.offline { color: var(--bad); }
.connection.offline::before { background: var(--bad); }
@keyframes blink { 50% { opacity: .35; } }

.stage {
  position: relative;
  width: min(100%, 720px);
  margin-inline: auto;
  overflow: hidden;
  border: 3px solid var(--line);
  background: var(--sky-2);
  image-rendering: pixelated;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
#cv, #cardCanvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  touch-action: none;
}
.stage * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.stage input, .stage textarea {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}
.mobile-jump-pad { display: none; }
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 12px;
  background: rgba(23, 21, 45, .84);
}
.overlay[hidden], [hidden] { display: none !important; }
.title-screen {
  align-items: stretch;
  justify-content: stretch;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 8px 12px;
  background: linear-gradient(to bottom, rgba(23, 21, 45, .46), rgba(23, 21, 45, .08) 34%, rgba(23, 21, 45, .04) 66%, rgba(23, 21, 45, .50));
}
.title-panel, .panel, .door-panel, .gameover-panel {
  width: min(650px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.title-screen .title-panel {
  width: min(650px, 100%);
  height: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 0;
  margin: 0 auto;
  text-align: center;
}
.title-heading, .title-actions {
  display: flex;
  width: 100%;
  min-width: 0;
  align-items: center;
  flex-direction: column;
}
.title-heading { gap: 2px; }
.title-actions { gap: 5px; }
.title-panel h2 {
  margin: 0;
  color: var(--accent);
  font-family: var(--f-number);
  font-size: clamp(20px, 5vw, 34px);
  line-height: 1.1;
  text-shadow: 2px 2px 0 var(--sky-2);
}
.title-screen .title-panel p { margin: 0; color: var(--lavender); }
.title-screen .title-egg { min-height: 18px; color: var(--ink) !important; }
.title-screen #titlePrompt { max-width: 100%; overflow-wrap: anywhere; }
.title-screen .start-action { max-width: 100%; min-width: min(280px, 100%); }
.eyebrow { margin: 0; color: var(--accent); font-family: var(--f-number); font-size: 12px; letter-spacing: .08em; }
.terminal-screen { align-items: flex-start; justify-content: flex-start; background: rgba(17, 15, 36, .94); }
.terminal-window {
  width: min(760px, 100%);
  min-width: 0;
  margin: auto;
  padding: 12px;
  color: var(--lavender);
  font-family: var(--f-number);
  font-size: clamp(11px, 2.1vw, 15px);
}
.terminal-line { min-height: 24px; overflow-wrap: anywhere; }
.terminal-muted { color: var(--dim); }
.terminal-name-line { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.terminal-name-line label { color: var(--lavender); }
.terminal-decoration { color: var(--accent); }
.terminal-name-line input, .join-row input {
  min-width: 70px;
  width: min(260px, 54vw);
  min-height: 42px;
  border: 2px solid var(--accent);
  border-radius: 0;
  padding: 6px 8px;
  background: var(--sky);
  color: var(--ink);
  outline: 0;
  font-size: 16px;
}
.terminal-name-line input::placeholder { color: var(--dim); opacity: 1; }
.clear-name { min-height: 42px; padding: 4px 8px; color: var(--accent); }
.name-counter { min-width: 3.5em; color: var(--dim); font-family: var(--f-number); font-size: 12px; }
.name-hint, .name-error, .terminal-response { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.name-hint { color: var(--dim); font-size: 12px; }
.name-error { color: var(--bad); font-size: 12px; }
.terminal-response { color: var(--accent); }
.cursor { color: var(--accent); animation: blink 1s steps(2, jump-none) infinite; }
.chars {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin: 4px 0;
}
.char-card {
  display: flex;
  min-width: 0;
  min-height: 76px;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 5px 2px;
  flex-direction: column;
  border: 2px solid var(--line);
  background: rgba(36, 32, 68, .7);
  box-shadow: 0 3px 0 var(--line);
  cursor: pointer;
}
.char-card:hover, .char-card[aria-pressed="true"] { border-color: var(--accent); }
.char-card[aria-pressed="true"] { background: rgba(255, 184, 61, .16); }
.char-card canvas { width: 48px; height: 48px; image-rendering: pixelated; }
.terminal-quote { min-height: 24px; margin: 0; color: var(--accent); }
.mode-buttons, .terminal-actions, .card-actions, .row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mode-buttons button { flex: 1 1 100px; min-height: 44px; }
.mode-buttons button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.join-row { display: flex; gap: 8px; align-items: baseline; }
.terminal-actions { justify-content: flex-end; margin-top: 4px; }
.note { margin: 0; color: var(--dim); font-size: 12px; overflow-wrap: anywhere; }
.note.good { color: var(--good); }
.note.bad { color: var(--bad); }

/* Sound and language toggles live under the game area so they never cover the HUD. */
.utility-controls {
  display: flex;
  gap: 6px;
  margin-left: auto;
}
.mute, .music-toggle, .language-toggle {
  width: 42px;
  min-height: 44px;
  padding: 4px;
  border-color: var(--accent);
  background: rgba(23, 21, 45, .9);
  color: var(--accent);
  font-family: var(--f-number);
  font-size: 18px;
  white-space: nowrap;
  touch-action: manipulation;
}
.music-toggle { width: auto; min-width: 70px; font-size: 12px; }
.mute { width: auto; min-width: 70px; font-size: 12px; }
.language-toggle { width: auto; min-width: 78px; font-size: 12px; }
.intro-controls { position: absolute; z-index: 6; right: 10px; bottom: 10px; }
.intro-controls button { min-width: 64px; min-height: 44px; background: rgba(23,21,45,.9); }
.door-screen { background: rgba(23, 21, 45, .2); align-items: flex-end; padding-bottom: 20px; }
.door-panel { align-items: center; text-align: center; }
.door-panel p { margin: 0; color: var(--ink); text-shadow: 2px 2px var(--sky); }
.lobby-screen { align-items: flex-start; }
.room-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.code { color: var(--ink); font-family: var(--f-number); font-size: clamp(22px, 6vw, 32px); letter-spacing: .16em; }
.plist { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.plist li { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 4px 8px; border: 2px solid var(--line); background: var(--sky); }
.plist canvas { width: 32px; height: 32px; }
.pill { margin-left: auto; border: 1px solid var(--dim); color: var(--dim); font-size: 11px; line-height: 1.4; padding: 0 6px; }
.pill.host { border-color: var(--ink); color: var(--ink); }

.rank-table {
  position: absolute;
  z-index: 5;
  top: 56px;
  right: 8px;
  width: min(245px, 44%);
  padding: 5px;
  border: 2px solid var(--line);
  background: rgba(23,21,45,.88);
  pointer-events: none;
}
.rank-title { padding: 0 4px 3px; color: var(--ink); font-family: var(--f-number); font-size: 11px; }
.rank-row { display: grid; grid-template-columns: 22px 30px minmax(0,1fr) auto; gap: 4px; align-items: center; min-height: 32px; padding: 1px 3px; font-size: 11px; }
.rank-row.mine { border-left: 3px solid var(--accent); background: rgba(255, 184, 61, .2); }
.rank-row.dead { color: #77728e; filter: grayscale(1); }
.rank-row canvas { width: 28px; height: 28px; }
.rank-place, .rank-score { font-family: var(--f-number); }
.rank-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.gameover-screen { align-items: flex-start; }
.gameover-panel { width: min(560px, 100%); margin: auto; }
.gameover-panel > canvas { border: 2px solid var(--line); }
.card-actions { justify-content: center; }
.card-actions button { min-height: 44px; }
#shareFallback { width: 100%; min-height: 70px; resize: vertical; border: 2px solid var(--accent); background: var(--sky); color: var(--ink); padding: 8px; }

.day-event-screen { z-index: 8; background: rgba(244, 239, 255, .86); }
.phone-message {
  width: min(330px, 100%);
  padding: 16px;
  border: 4px solid var(--sky);
  background: #f4efff;
  color: var(--sky);
  box-shadow: 6px 6px 0 var(--sky-2);
  text-align: left;
}
.phone-message p { margin: 0; }
.phone-title { color: var(--accent); font-family: var(--f-number); font-size: 13px; }
.phone-sender { margin-top: 12px !important; font-size: 12px; font-weight: 700; }
.phone-body { margin-top: 8px !important; font-size: 16px; line-height: 1.6; overflow-wrap: anywhere; }

button, input, textarea { border-radius: 0; }
button {
  min-height: 44px;
  border: 2px solid var(--line);
  background: var(--panel);
  padding: 6px 14px;
  box-shadow: 0 3px 0 var(--line);
  cursor: pointer;
  touch-action: manipulation;
}
button:hover { border-color: var(--dim); }
button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
button.go { border-color: var(--accent); background: var(--accent); color: #17152d; box-shadow: 0 3px 0 #b7791f; }
button:disabled { opacity: .45; cursor: not-allowed; }
button:disabled:active { transform: none; box-shadow: 0 3px 0 var(--line); }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

.deck { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.keys { color: var(--dim); font-size: 12px; }
.board { border: 3px solid var(--line); background: var(--panel); }
.board header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-bottom: 2px solid var(--line); flex-wrap: wrap; }
.board h3 { margin: 0; color: var(--ink); font-family: var(--f-number); font-size: 16px; letter-spacing: .08em; }
.board ol { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 6px 12px 10px; list-style: none; }
.board li { display: grid; grid-template-columns: 2.4em 30px minmax(0,1fr) auto; align-items: center; gap: 8px; padding: 3px 0; border-bottom: 1px dashed var(--line); }
.board li:last-child { border-bottom: 0; }
.board .rk { color: var(--dim); font-family: var(--f-number); }
.board .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .sc { font-family: var(--f-number); font-variant-numeric: tabular-nums; }
.board canvas { width: 28px; height: 28px; }
.empty { margin: 0; padding: 14px 12px; color: var(--dim); }
.disclaimer { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; margin: -6px 0 0; color: var(--dim); font-size: 12px; text-align: center; }
.disclaimer a { color: var(--accent); }

@media (max-width: 560px) {
  .wrap { width: min(100% - 18px, 860px); padding-top: 12px; }
  .stage { width: calc(100% + 18px); margin-inline: -9px; border-width: 0; }
  .terminal-window { padding: 6px 2px; }
  .terminal-name-line input { width: min(210px, 56vw); }
  .chars { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .char-card:nth-child(4) { grid-column: 1; }
  .char-card:nth-child(5) { grid-column: 2; }
  .rank-table { width: min(210px, 54%); }
  .rank-row { font-size: 10px; }
  .title-screen { padding: 5px 8px; }
  .title-screen .title-panel h2 { font-size: clamp(18px, 5vw, 26px); }
  .title-screen .title-panel p { font-size: 11px; line-height: 1.2; }
  .title-screen .title-actions { gap: 2px; }
  .title-screen .title-egg { min-height: 0; }
  .card-actions button { flex: 1 1 42%; }

  /* Keep a large thumb target below the pixel viewport without stretching the
     game art. The whole pad is held, so it preserves variable jump height. */
  .stage[data-screen="run"] {
    min-height: clamp(340px, 58svh, 520px);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    background: var(--sky-2);
  }
  .stage[data-screen="run"] > #cv {
    width: 116%;
    max-width: none;
    flex: 0 0 auto;
    align-self: flex-start;
  }
  .stage[data-screen="run"] .mobile-jump-pad {
    display: flex;
    flex: 1 1 auto;
    min-height: 150px;
    align-items: flex-end;
    justify-content: center;
    padding: 18px 12px max(18px, env(safe-area-inset-bottom));
    border-top: 2px dashed rgba(255, 184, 61, .42);
    background: linear-gradient(to bottom, rgba(23, 21, 45, .04), rgba(23, 21, 45, .22));
    color: var(--dim);
    font-family: var(--f-number);
    font-size: 11px;
    letter-spacing: .05em;
    text-align: center;
    touch-action: none;
  }
  .stage[data-screen="run"] .mobile-jump-pad:active { color: var(--accent); }
}
@media (max-width: 360px) {
  .wrap { width: min(100% - 12px, 860px); }
  .stage { width: calc(100% + 12px); margin-inline: -6px; }
  .mute, .music-toggle, .language-toggle { min-height: 44px; }
  .mute, .music-toggle { min-width: 70px; }
  .language-toggle { min-width: 68px; }
  .terminal-name-line input { width: min(180px, 52vw); }
  .terminal-name-line label { flex-basis: 100%; }
  .mode-buttons button { flex-basis: 30%; padding-inline: 6px; }
  .title-screen { padding-inline: 5px; }
  .title-screen .title-panel p { font-size: 10px; }
  .title-screen .start-action { min-width: 0; width: 100%; padding-inline: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .connection.connecting::before, .cursor { animation: none; }
  button:active { transform: none; }
}
/* Keep the attract-mode running lane (bottom third of the canvas) clear on wide screens: stack the title, prompt and start button at the top. */
@media (min-width: 561px) {
  .title-screen .title-panel { justify-content: flex-start; gap: 8px; }
}
/* Phones: the canvas is only ~120px tall, so put the title prompt and start button under it instead of over the runner. The page header already shows the brand. */
@media (max-width: 560px) {
  .title-screen { position: static; padding: 10px 12px 12px; background: var(--sky-2); }
  .title-screen .title-panel { height: auto; gap: 8px; }
  .title-screen .title-heading { display: none; }
  .title-screen .title-panel p { font-size: 13px; line-height: 1.4; }
  .title-screen .title-actions { gap: 8px; }
}

/* The terminal (name, agent, mode) is taller than the canvas: let it size the stage instead of scrolling inside it. */
.terminal-screen { position: relative; inset: auto; overflow: visible; min-height: 100%; padding-top: 56px; }
.stage:has(> .terminal-screen:not([hidden])) > #cv { display: none; }

/* Breathing room between the mode buttons, the room-code row and the start button. */
.terminal-screen .join-row { margin-top: 14px; align-items: center; }
.terminal-screen .terminal-actions { margin-top: 16px; }
.terminal-screen .terminal-name-line { margin-bottom: 8px; }
/* Game-over card and room lobby are also taller than the canvas: grow the stage like the terminal does. */
.lobby-screen, .gameover-screen { position: relative; inset: auto; overflow: visible; min-height: 100%; padding-top: 56px; }
.stage:has(> .lobby-screen:not([hidden])) > #cv, .stage:has(> .gameover-screen:not([hidden])) > #cv { display: none; }
/* Usage-limit notice above the game-over card. */
.limit-banner { text-align: center; }
.limit-banner p { margin: 0; }
.limit-title { color: var(--accent); font-size: clamp(16px, 4vw, 20px); }
.limit-reset { color: var(--dim); font-size: 13px; margin-top: 4px !important; }

.credits-shell { gap: 18px; }
.credits-header { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.credits-back { width: fit-content; color: var(--accent); font-family: var(--f-number); font-size: 13px; overflow-wrap: anywhere; }
.credits-kicker { margin: 8px 0 0; color: var(--dim); font-family: var(--f-number); font-size: 12px; letter-spacing: .12em; }
.credits-title { margin: 0; color: var(--accent); font-family: var(--f-number); font-size: clamp(24px, 7vw, 40px); line-height: 1.15; text-shadow: 3px 3px 0 var(--sky-2); overflow-wrap: anywhere; }
.credits-sections { display: grid; gap: 12px; min-width: 0; }
.credits-section { min-width: 0; padding: 16px; border: 3px solid var(--line); background: var(--panel); }
.credits-heading { margin: 0 0 10px; color: var(--accent); font-family: var(--f-number); font-size: clamp(16px, 4vw, 22px); line-height: 1.3; overflow-wrap: anywhere; }
.credits-section p { margin: 0; color: var(--lavender); line-height: 1.75; overflow-wrap: anywhere; }
.credits-section .credits-en { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); color: var(--dim); }
.credits-list { margin: 0; padding-left: 1.4em; color: var(--lavender); line-height: 1.75; overflow-wrap: anywhere; }
.credits-list li + li { margin-top: 8px; }
.credits-list strong { color: var(--ink); }
.credits-note { color: var(--accent) !important; }

@media (max-width: 560px) {
  .credits-shell { width: min(100% - 18px, 860px); }
  .credits-section { padding: 12px; }
  .credits-title { font-size: clamp(23px, 8vw, 32px); }
}

@media (max-width: 360px) {
  .credits-shell { width: min(100% - 12px, 860px); }
  .credits-section { padding: 10px; }
  .credits-section p, .credits-list { font-size: 14px; }
}
.credits-link { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
/* Credits are for reading: system fonts for everything except the page title. */
.credits-shell, .credits-shell .credits-heading, .credits-shell .credits-back, .credits-shell .credits-kicker {
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, "Segoe UI", sans-serif;
}
.credits-shell .credits-heading { font-weight: 700; letter-spacing: 0; }
.credits-shell .credits-title { font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, "Segoe UI", sans-serif; font-weight: 800; letter-spacing: 0; text-shadow: none; }
.credits-section .credits-note + .credits-list { margin-top: 8px; padding-top: 0; border-top: 0; }

.board-tabs { display: flex; gap: 6px; padding: 8px 12px 0; }
.board-tabs button { flex: 1; min-height: 44px; border: 2px solid var(--line); padding: 7px 10px; background: var(--panel); color: var(--dim); font: inherit; cursor: pointer; }
.board-tabs button[aria-selected="true"] { color: var(--ink); border-color: var(--accent); background: rgba(255,184,61,.12); }
.board-tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.board .agent-row { padding: 7px 0; }
.agent-row .sc { max-width: 40vw; overflow-wrap: anywhere; text-align: right; }
.agent-detail { grid-column: 3 / -1; min-width: 0; }
.agent-stats { display: block; color: var(--dim); font-size: 11px; margin-top: 3px; overflow-wrap: anywhere; }
.agent-bar { height: 4px; background: rgba(255,184,61,.15); }
.agent-bar-fill { height: 100%; background: var(--accent); }
.agent-note { padding: 0 12px 10px; margin: 0; }
