:root {
  color-scheme: dark;
  --bg: #0a0e1a;
  --panel: #111827;
  --panel-2: #172033;
  --paper: #d4c5a9;
  --paper-deep: #b9a783;
  --gold: #c9a84c;
  --gold-soft: #ead28a;
  --ink: #f4ead7;
  --muted: #8f9bb1;
  --line: #314059;
  --danger: #c86f5a;
  --success: #8fbf8f;
  --shadow: rgba(0, 0, 0, 0.32);
  --focus: #f2d36b;
  --radius: 8px;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
}

button,
input,
textarea {
  font: inherit;
  max-width: 100%;
}

button,
a {
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(201, 168, 76, 0.22);
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: #0c1220;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1,
.doc-shell h1,
.vault-shell h1 {
  margin: 0;
  color: var(--paper);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2rem;
  font-weight: 700;
}

.eyebrow {
  margin: 0 0 0.15rem;
  color: var(--gold-soft);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
}

.toplinks {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.language-switcher {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 2.4rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.language-switcher select {
  min-height: 2.4rem;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #121a2a;
  color: var(--ink);
  padding: 0.45rem 0.65rem;
}

.toplinks a,
.back-link,
.ghost-button,
.primary-button,
.copy-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 2.4rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: #121a2a;
  text-decoration: none;
  padding: 0.55rem 0.75rem;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
}

.primary-button {
  background: #263757;
  border-color: #50648a;
  color: #fff4d1;
  font-weight: 700;
}

.ghost-button:hover,
.primary-button:hover,
.copy-button:hover,
.icon-button:hover,
.toplinks a:hover,
.back-link:hover {
  border-color: var(--gold);
}

.ghost-button:active,
.primary-button:active,
.copy-button:active,
.icon-button:active,
.toplinks a:active,
.back-link:active {
  transform: translateY(1px);
}

.danger {
  color: #ffd0c7;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(17rem, 22rem) minmax(0, 1fr);
  align-items: start;
  gap: 1rem;
  width: min(94rem, calc(100% - 2rem));
  margin: 1rem auto 2rem;
}

.side-panel,
.game-panel,
.doc-shell,
.vault-shell {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 1rem 2rem var(--shadow);
}

.side-panel {
  padding: 1rem;
  align-self: start;
  position: sticky;
  top: 6.2rem;
}

.side-panel section + section {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}

.side-panel h2,
.game-panel h2,
.doc-shell h2 {
  margin: 0 0 0.75rem;
  color: var(--paper);
  font-family: Georgia, "Times New Roman", serif;
}

.side-panel h2 {
  font-size: 1.05rem;
}

.game-panel {
  min-height: 42rem;
  padding: 1.25rem;
  overflow: hidden;
}

.room-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.progress-rail {
  flex: 0 1 11rem;
  width: 11rem;
  max-width: 100%;
  height: 0.5rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: #080c14;
}

.progress-rail span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--gold);
}

.room-nav {
  display: grid;
  gap: 0.45rem;
}

.room-button {
  display: grid;
  grid-template-columns: 2rem 1fr auto;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  min-height: 3rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0f1727;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  padding: 0.5rem;
}

.room-button:focus-visible {
  outline-offset: 2px;
}

.room-button[aria-current="true"] {
  border-color: var(--gold);
  background: #18233a;
}

.room-button:disabled {
  color: #657086;
  cursor: not-allowed;
  opacity: 0.82;
}

.room-number {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  background: #1c2941;
  color: var(--gold-soft);
  font-weight: 800;
}

.room-label {
  min-width: 0;
  overflow-wrap: anywhere;
}

.room-state {
  color: var(--muted);
  font-size: 0.8rem;
}

.fragment-list {
  margin: 0;
  padding-left: 1.4rem;
  color: var(--paper);
}

.fragment-list li + li {
  margin-top: 0.35rem;
}

.empty-fragment {
  color: var(--muted);
}

.protocol p,
.small-note,
.hint,
.locked-note {
  color: var(--muted);
}

.story-beat {
  border-color: #5b4d29;
  background: #17150f;
}

.clue-box {
  border-color: #3e526f;
  background: #0d1724;
}

.clue-list {
  margin: 0.75rem 0;
  padding-left: 1.25rem;
}

.clue-list li + li {
  margin-top: 0.45rem;
}

.support-prompt {
  border-color: #536b4d;
  background: #102016;
}

.support-prompt .primary-button,
.share-panel .primary-button {
  margin-top: 0.75rem;
}

.share-panel {
  border-color: #5b613b;
  background: #171b10;
}

.scene {
  display: grid;
  gap: 1rem;
  min-width: 0;
}

.brief-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
  gap: 1rem;
}

.brief-box,
.answer-box,
.copy-box,
.paper-card,
.locked-card,
.success-card,
.story-beat,
.clue-box,
.support-prompt,
.share-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0f1727;
  padding: 1rem;
}

.success-card {
  border-color: #476b52;
  background: #102116;
}

.paper-card {
  color: #201a12;
  background: var(--paper);
  border-color: #8f7b57;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.paper-card h3,
.brief-box h3,
.copy-box h3,
.answer-box h3,
.locked-card h3,
.story-beat h3,
.clue-box h3,
.support-prompt h3,
.share-panel h3 {
  margin: 0 0 0.6rem;
  font-size: 1rem;
}

.paper-card p {
  margin: 0;
}

.cipher-text,
.mirror-transcript,
.packet-text,
.data-preview {
  -webkit-overflow-scrolling: touch;
  overflow: auto;
  max-height: 18rem;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #070b13;
  color: var(--paper);
  padding: 0.85rem;
  font-family: "Courier New", ui-monospace, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.copy-row,
.answer-row,
.sequence-row {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  flex-wrap: wrap;
}

.answer-row input {
  flex: 1 1 16rem;
  min-width: 0;
  min-height: 2.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #070b13;
  color: var(--ink);
  padding: 0.6rem 0.75rem;
}

.answer-feedback {
  min-height: 1.5rem;
  color: var(--gold-soft);
}

.room-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.shelf-clue {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(2.4rem, 1fr));
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.shelf-clue span {
  min-height: 3.4rem;
  display: grid;
  place-items: center;
  border: 1px solid #7e6936;
  border-radius: var(--radius);
  background: #20190e;
  color: var(--gold-soft);
  font-weight: 900;
}

.shelf-clue .active {
  background: #4a3510;
  border-color: var(--gold);
}

.diary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr));
  gap: 0.8rem;
}

.diary-card {
  min-height: 10rem;
}

.diary-date {
  display: inline-block;
  margin-bottom: 0.45rem;
  color: #604514;
  font-weight: 800;
}

.mirror-plate {
  overflow: hidden;
  border: 1px solid #5d6890;
  border-radius: var(--radius);
  background: #121a2c;
  padding: 1rem;
}

.mirror-plate p {
  margin: 0;
  color: var(--paper);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.25rem;
  transform: scaleX(-1);
  white-space: pre-wrap;
}

.vault-link-note {
  border-left: 3px solid var(--gold);
  padding-left: 0.8rem;
  color: var(--paper);
}

.capture-screen,
.cell-bars {
  position: relative;
  overflow: hidden;
  min-height: 18rem;
  border: 1px solid #4b5568;
  border-radius: var(--radius);
  background: #05070c;
}

.capture-screen::before,
.cell-bars::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0) 0 8%, rgba(8, 10, 14, 0.96) 8% 11%),
    radial-gradient(circle at 50% 35%, rgba(201, 168, 76, 0.15), rgba(0, 0, 0, 0) 32%);
  pointer-events: none;
  z-index: 2;
}

.capture-message,
.cell-shadow {
  position: relative;
  z-index: 1;
  display: grid;
  align-content: end;
  min-height: 18rem;
  padding: 1.25rem;
  color: var(--paper);
}

.capture-message p {
  max-width: 42rem;
}

.guard-figure {
  width: 5rem;
  height: 6.5rem;
  margin: 1rem 0;
  border: 1px solid #6b5a31;
  border-radius: 42% 42% 8px 8px;
  background:
    radial-gradient(circle at 35% 28%, #ead28a 0 0.18rem, transparent 0.22rem),
    radial-gradient(circle at 65% 28%, #ead28a 0 0.18rem, transparent 0.22rem),
    linear-gradient(#2b2415, #111722);
  box-shadow: 0 0 1rem rgba(201, 168, 76, 0.16);
  transform-origin: 50% 100%;
  transition: transform 600ms ease, opacity 600ms ease;
}

.guard-asleep .guard-figure {
  transform: rotate(76deg) translate(1.25rem, 1.5rem);
  opacity: 0.58;
}

.cage-open::before {
  transform: translateY(-110%);
  transition: transform 900ms ease;
}

.terminal-log {
  overflow: auto;
  min-height: 7rem;
  border: 1px solid #25344c;
  border-radius: var(--radius);
  background: #05070c;
  color: #9fe0a3;
  padding: 0.85rem;
  font-family: "Courier New", ui-monospace, monospace;
  white-space: pre-wrap;
}

.cell-bars {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
}

.cell-bars > span {
  z-index: 3;
  border-left: 0.55rem solid #111722;
  box-shadow: 0 0 1rem rgba(0, 0, 0, 0.55);
}

.cell-shadow {
  grid-column: 1 / -1;
  grid-row: 1;
}

.faint-writing {
  color: rgba(212, 197, 169, 0.38);
  text-shadow: 0 0 0.45rem rgba(201, 168, 76, 0.2);
}

.hidden-cell-note {
  opacity: 0.32;
  transition: opacity 140ms ease;
}

.hidden-cell-note:hover,
.hidden-cell-note:focus-within {
  opacity: 1;
}

.stats-wrap {
  -webkit-overflow-scrolling: touch;
  overflow: auto;
  max-height: 27rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  scrollbar-gutter: stable both-edges;
}

.stats-table {
  width: 100%;
  min-width: 52rem;
  border-collapse: collapse;
  font-family: "Courier New", ui-monospace, monospace;
  font-size: 0.82rem;
}

.stats-table th,
.stats-table td {
  border: 1px solid #25344c;
  padding: 0.35rem 0.45rem;
  text-align: right;
  background: #0b111d;
}

.stats-table th {
  color: var(--gold-soft);
  background: #172033;
}

.stats-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}

.stats-table th[scope="row"] {
  position: sticky;
  left: 0;
  z-index: 1;
}

.stats-table thead th:first-child {
  left: 0;
  z-index: 3;
}

.stats-table td.clickable {
  cursor: pointer;
}

.stats-table td.clickable:hover,
.stats-table td.marked {
  outline: 2px solid var(--gold);
  outline-offset: -2px;
  background: #332813;
}

.burn-message {
  display: grid;
  gap: 0.2rem;
  width: max-content;
  max-width: 100%;
  overflow: auto;
  padding: 1rem;
  border: 1px solid #5f4d1f;
  border-radius: var(--radius);
  background: #090b0f;
}

.burn-row {
  display: flex;
  gap: 0.2rem;
}

.burn-pixel {
  width: 0.72rem;
  height: 0.72rem;
  border-radius: 2px;
  background: #151b24;
}

.burn-pixel.on {
  background: var(--gold);
  box-shadow: 0 0 0.5rem rgba(201, 168, 76, 0.35);
}

.book-wall {
  --book-width: 6rem;
  --book-half: 3rem;
  position: relative;
  min-height: 24rem;
  border: 1px solid #3a4b67;
  border-radius: var(--radius);
  background: #0d1422;
  overflow: hidden;
  padding: 1rem;
}

.book-button {
  position: absolute;
  left: clamp(calc(var(--book-half) + 0.25rem), var(--x), calc(100% - var(--book-half) - 0.25rem));
  bottom: var(--rise);
  width: var(--book-width);
  min-height: 4.2rem;
  border: 1px solid #594c31;
  border-radius: var(--radius);
  background: #261f17;
  color: var(--paper);
  cursor: pointer;
  padding: 0.45rem;
  transform: translateX(-50%);
  overflow-wrap: anywhere;
}

.book-button:hover,
.book-button.selected {
  border-color: var(--gold);
  background: #3a2d16;
}

.height-mark {
  display: block;
  color: var(--gold-soft);
  font-size: 0.78rem;
}

.sequence-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  min-height: 2rem;
  align-items: center;
}

.sequence-pills span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.25rem 0.55rem;
  background: #101827;
}

.memory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr));
  gap: 0.7rem;
}

.memory-card {
  min-height: 9rem;
}

.escape-seal {
  border: 1px solid #658a6a;
  border-radius: var(--radius);
  background: #0f2217;
  padding: 1rem;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 20;
  max-width: min(28rem, calc(100% - 2rem));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #111827;
  color: var(--ink);
  padding: 0.8rem 1rem;
  box-shadow: 0 0.75rem 1.5rem var(--shadow);
  opacity: 0;
  transform: translateY(0.75rem);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.doc-page,
.vault-page {
  min-height: 100vh;
  padding: 1rem;
}

.doc-shell,
.vault-shell {
  width: min(54rem, 100%);
  margin: 0 auto;
  padding: 1.25rem;
}

.doc-shell h1,
.vault-shell h1 {
  margin: 0.5rem 0 1rem;
}

.doc-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.back-link {
  display: inline-flex;
  align-items: center;
}

.vault-instruction {
  color: var(--paper);
}

.moon-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(2.8rem, 1fr));
  gap: 0.6rem;
  width: min(27rem, 100%);
  margin: 1.25rem auto;
}

.moon-grid span {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 1px solid #384965;
  border-radius: var(--radius);
  background: #101827;
  color: #738097;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.5rem;
  font-weight: 800;
}

.moon-grid .moon {
  border-color: var(--gold);
  background: #3a2b10;
  color: #fff0a8;
  box-shadow: 0 0 1.2rem rgba(201, 168, 76, 0.28);
}

.noscript {
  margin: 1rem;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 1rem;
  background: #24110f;
}

@media (max-width: 960px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .toplinks {
    justify-content: flex-start;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-panel {
    position: static;
  }

  .brief-grid,
  .diary-grid,
  .memory-grid {
    grid-template-columns: 1fr;
  }

  .progress-rail {
    width: 8rem;
  }

  .book-wall {
    --book-width: 5.3rem;
    --book-half: 2.65rem;
    min-height: 32rem;
  }

  .book-button {
    min-height: 4rem;
  }
}

@media (max-width: 560px) {
  .topbar h1,
  .doc-shell h1,
  .vault-shell h1 {
    font-size: 1.55rem;
  }

  .toplinks,
  .copy-row,
  .answer-row,
  .sequence-row {
    width: 100%;
  }

  .toplinks a,
  .toplinks button,
  .language-switcher,
  .copy-button,
  .primary-button,
  .ghost-button {
    width: 100%;
    justify-content: center;
  }

  .language-switcher select {
    flex: 1;
  }

  .game-panel,
  .side-panel,
  .doc-shell,
  .vault-shell {
    padding: 0.85rem;
  }

  .room-meta {
    align-items: flex-start;
    flex-direction: column;
  }

  .shelf-clue {
    grid-template-columns: repeat(4, minmax(2rem, 1fr));
  }

  .moon-grid {
    gap: 0.4rem;
  }

  .moon-grid span {
    font-size: 1.15rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }

  .toast {
    transition: none;
  }
}
