:root {
  color-scheme: dark;
  --bg: #070807;
  --panel: #10140f;
  --panel-strong: #141910;
  --ink: #f6f1e4;
  --muted: #a9ab98;
  --line: #33412d;
  --acid: #b6f44f;
  --gold: #ffd15c;
  --cool: #7ec7d8;
  --violet: #b493ff;
  --hot: #ff7042;
  --bad: #ff5268;
  --paper: #efe4c6;
  --paper-ink: #181a14;
  --shadow: rgba(0, 0, 0, 0.36);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 20% 12%, rgba(126, 199, 216, 0.14), transparent 30%),
    radial-gradient(circle at 82% 20%, rgba(255, 209, 92, 0.1), transparent 28%),
    linear-gradient(135deg, #070807, #0c100c 54%, #080907);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  background: #172014;
  color: var(--ink);
  cursor: pointer;
}

button:hover {
  border-color: rgba(182, 244, 79, 0.68);
}

button:focus-visible {
  outline: 3px solid rgba(126, 199, 216, 0.75);
  outline-offset: 2px;
}

.mobile-text-input {
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  appearance: none;
  opacity: 0.01;
  overflow: hidden;
  color: transparent;
  background: transparent;
  caret-color: transparent;
  font-size: 16px;
  pointer-events: none;
}

.app-shell {
  width: min(1440px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 30px;
}

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.studio-link {
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  text-decoration: none;
  white-space: nowrap;
}

.game-title {
  text-align: center;
}

.game-title p,
.quote-header span,
.clue-header span,
.panel-heading p,
#status-kicker {
  margin: 0;
  color: var(--acid);
  font-size: 11px;
  font-weight: 950;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(46px, 7vw, 86px);
  line-height: 0.9;
}

.top-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.top-actions button {
  min-width: 78px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 900;
}

.audio-button.on {
  background: var(--acid);
  color: #111608;
}

.game-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.side-panel,
.quote-panel,
.clue-panel,
.settings-dialog,
.result-dialog {
  border: 1px solid rgba(246, 241, 228, 0.1);
  background: rgba(12, 16, 11, 0.88);
  box-shadow: 0 24px 72px var(--shadow);
}

.side-panel {
  position: sticky;
  top: 14px;
  padding: 14px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.stats div {
  min-height: 64px;
  padding: 10px;
  border: 1px solid var(--line);
  background: rgba(8, 9, 7, 0.45);
}

.stats span {
  display: block;
  margin-bottom: 6px;
  color: var(--acid);
  font-size: 10px;
  font-weight: 950;
  text-transform: uppercase;
}

.stats strong {
  font-size: 21px;
  font-variant-numeric: tabular-nums;
}

.spine-panel,
.status-panel {
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  background:
    linear-gradient(135deg, rgba(182, 244, 79, 0.09), transparent 58%),
    rgba(8, 9, 7, 0.38);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.panel-heading strong {
  color: var(--gold);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.spine-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(28px, 1fr));
  gap: 6px;
}

.spine-cell {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 1px solid rgba(255, 209, 92, 0.28);
  background: #11170f;
  color: var(--gold);
  font-size: 18px;
  font-weight: 950;
}

.spine-cell.solved {
  border-color: rgba(182, 244, 79, 0.72);
  background: rgba(182, 244, 79, 0.14);
  color: var(--acid);
}

.status-panel {
  min-height: 116px;
}

.status-panel strong {
  display: block;
  margin: 7px 0 6px;
  font-size: 19px;
}

.status-panel span {
  display: block;
  color: var(--muted);
  line-height: 1.38;
}

.actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.actions button {
  font-weight: 950;
}

.puzzle-wrap {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.quote-panel,
.clue-panel {
  padding: 14px;
}

.quote-header,
.clue-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.quote-header strong,
.clue-header strong {
  display: block;
  margin-top: 3px;
  font-size: clamp(22px, 2.2vw, 34px);
}

#quote-progress {
  margin: 0;
  color: var(--cool);
  font-size: 28px;
  font-weight: 950;
  font-variant-numeric: tabular-nums;
}

.quote-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px 5px;
  min-height: 156px;
  padding: 16px;
  border: 1px solid rgba(239, 228, 198, 0.18);
  background:
    linear-gradient(135deg, rgba(239, 228, 198, 0.08), transparent 60%),
    #0a0d09;
}

.quote-cell,
.quote-space,
.quote-punct {
  flex: 0 0 auto;
  width: 38px;
  height: 48px;
}

.quote-space {
  width: 18px;
}

.quote-punct {
  display: grid;
  place-items: end center;
  color: var(--muted);
  font-size: 26px;
  font-weight: 900;
}

.quote-cell,
.answer-cell {
  position: relative;
  display: grid;
  place-items: center;
  scroll-margin: 96px 24px;
  min-height: 0;
  padding: 0;
  border: 1px solid #8b835e;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.42), transparent 42%),
    var(--paper);
  color: var(--paper-ink);
  font-weight: 950;
  line-height: 1;
  text-transform: uppercase;
  box-shadow:
    inset 0 -4px rgba(0, 0, 0, 0.11),
    0 4px 10px rgba(0, 0, 0, 0.22);
}

.quote-cell {
  font-size: 25px;
}

.quote-cell .cell-number,
.answer-cell .cell-number {
  position: absolute;
  top: 3px;
  left: 4px;
  color: rgba(24, 26, 20, 0.54);
  font-size: 9px;
  font-weight: 950;
  font-variant-numeric: tabular-nums;
}

.quote-cell.empty,
.answer-cell.empty {
  color: transparent;
}

.quote-cell.selected,
.answer-cell.selected {
  border-color: var(--cool);
  box-shadow:
    inset 0 -4px rgba(0, 0, 0, 0.11),
    0 0 0 3px rgba(126, 199, 216, 0.28),
    0 7px 14px rgba(0, 0, 0, 0.26);
}

.quote-cell.correct,
.answer-cell.correct {
  border-color: #6ca42f;
}

.quote-cell.incorrect,
.answer-cell.incorrect {
  border-color: var(--bad);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.38), transparent 42%),
    #f6c4c7;
}

.quote-cell.hinted,
.answer-cell.hinted {
  border-color: var(--violet);
}

.attribution {
  min-height: 28px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.clue-tools {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.segment {
  min-width: 42px;
  min-height: 38px;
  color: var(--muted);
  font-weight: 950;
}

.segment.active {
  border-color: rgba(182, 244, 79, 0.74);
  background: var(--acid);
  color: #101608;
}

.clue-list {
  display: grid;
  gap: 10px;
}

.clue-row {
  display: grid;
  grid-template-columns: 34px minmax(180px, 0.85fr) minmax(260px, 1fr);
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid rgba(246, 241, 228, 0.1);
  background: rgba(8, 9, 7, 0.42);
}

.clue-row.active {
  border-color: rgba(126, 199, 216, 0.62);
  background:
    linear-gradient(90deg, rgba(126, 199, 216, 0.12), transparent 52%),
    rgba(8, 9, 7, 0.42);
}

.clue-index {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 209, 92, 0.46);
  background: rgba(255, 209, 92, 0.12);
  color: var(--gold);
  font-size: 17px;
  font-weight: 950;
}

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

.clue-copy strong {
  display: block;
  margin-bottom: 3px;
  font-size: 13px;
  color: var(--cool);
  text-transform: uppercase;
}

.clue-copy span {
  display: block;
  color: var(--muted);
  line-height: 1.35;
}

.answer-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.answer-cell {
  width: 34px;
  height: 42px;
  font-size: 22px;
}

.answer-cell.unlinked {
  border-style: dashed;
}

.answer-cell.acrostic {
  border-color: var(--gold);
}

.solved-flash {
  animation: solved-flash 520ms ease;
}

.settings-dialog,
.result-dialog {
  width: min(520px, calc(100% - 28px));
  color: var(--ink);
  padding: 24px;
}

.settings-dialog:not([open]),
.result-dialog:not([open]) {
  display: none;
}

.settings-dialog[open],
.result-dialog[open] {
  display: block;
  position: fixed;
  inset: 50% auto auto 50%;
  z-index: 50;
  max-height: calc(100vh - 28px);
  overflow: auto;
  transform: translate(-50%, -50%);
}

.settings-dialog::backdrop,
.result-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.settings-dialog h2,
.result-dialog h2 {
  margin: 0 0 10px;
  font-size: 34px;
}

.settings-dialog p,
.result-dialog p {
  color: var(--muted);
  line-height: 1.45;
}

.setting-row {
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr) 58px;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  background: #10150d;
}

.setting-row label,
.setting-row strong {
  font-weight: 900;
}

.setting-row input {
  width: 100%;
  accent-color: var(--acid);
}

.settings-dialog button,
.result-dialog button {
  width: 100%;
  background: var(--acid);
  color: #101608;
  font-weight: 950;
}

@keyframes solved-flash {
  0% { filter: none; }
  45% { filter: brightness(1.32) saturate(1.2); }
  100% { filter: none; }
}

@media (min-width: 1500px) {
  .app-shell {
    width: min(1760px, calc(100% - 64px));
  }

  .game-layout {
    grid-template-columns: 360px minmax(0, 1fr);
    gap: 32px;
  }

  .quote-cell,
  .quote-space,
  .quote-punct {
    width: 44px;
    height: 56px;
  }

  .quote-space {
    width: 24px;
  }

  .answer-cell {
    width: 40px;
    height: 48px;
  }
}

@media (min-width: 2600px) and (min-height: 1400px) {
  .app-shell {
    width: min(2240px, calc(100% - 96px));
  }

  .game-layout {
    grid-template-columns: 390px minmax(0, 1fr);
    gap: 40px;
  }

  .quote-cell,
  .quote-space,
  .quote-punct {
    width: 54px;
    height: 68px;
  }

  .quote-space {
    width: 30px;
  }

  .quote-cell {
    font-size: 32px;
  }

  .answer-cell {
    width: 48px;
    height: 58px;
    font-size: 28px;
  }
}

@media (max-width: 1040px) {
  .topbar {
    grid-template-columns: 1fr auto;
    gap: 12px;
  }

  .game-title {
    grid-column: 1 / -1;
    grid-row: 1;
    text-align: left;
  }

  .studio-link,
  .top-actions {
    grid-row: 2;
  }

  .game-layout {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .side-panel {
    position: static;
    order: 2;
  }

  .puzzle-wrap {
    order: 1;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 16px, 1440px);
    padding-top: 12px;
  }

  h1 {
    font-size: clamp(38px, 14vw, 58px);
  }

  .top-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .top-actions button {
    flex: 1 1 92px;
    min-width: 0;
    padding: 0 10px;
  }

  .stats {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .stats div {
    min-height: 58px;
    padding: 8px;
  }

  .stats span {
    font-size: 10px;
  }

  .stats strong {
    font-size: 16px;
  }

  .quote-panel,
  .clue-panel,
  .side-panel {
    padding: 10px;
  }

  .quote-grid {
    gap: 5px 3px;
    min-height: 130px;
    padding: 10px;
  }

  .quote-cell,
  .quote-space,
  .quote-punct {
    width: 30px;
    height: 40px;
  }

  .quote-space {
    width: 12px;
  }

  .quote-cell {
    font-size: 20px;
  }

  .quote-punct {
    font-size: 20px;
  }

  .clue-header,
  .quote-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .clue-row {
    grid-template-columns: 30px minmax(0, 1fr);
    align-items: start;
  }

  .answer-grid {
    grid-column: 1 / -1;
  }

  .answer-cell {
    width: 30px;
    height: 38px;
    font-size: 19px;
  }

  .actions {
    grid-template-columns: 1fr;
  }
}
