:root {
  color-scheme: dark;
  --bg: #101514;
  --ink: #fbf0d7;
  --muted: #c7b995;
  --soft: #91aaa0;
  --gold: #e2b85d;
  --gold-bright: #ffe09a;
  --red: #b85c4d;
  --green: #64b37f;
  --teal: #64c0b0;
  --blue: #4d7898;
  --panel: rgba(23, 29, 28, 0.92);
  --panel-strong: rgba(34, 40, 38, 0.96);
  --paper: #ead8a9;
  --paper-ink: #21170e;
  --line: rgba(226, 184, 93, 0.28);
  --line-strong: rgba(255, 224, 154, 0.62);
  --texture: url("/tech-tree/assets/parchment-texture.png");
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(12, 16, 16, 0.92), rgba(12, 16, 16, 0.72)),
    radial-gradient(circle at 22% 18%, rgba(226, 184, 93, 0.16), transparent 24rem),
    radial-gradient(circle at 80% 62%, rgba(100, 192, 176, 0.12), transparent 22rem),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 36px),
    #101514;
}

button,
select,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
}

p,
h1,
h2 {
  margin: 0;
}

.shell {
  display: grid;
  width: min(1220px, calc(100% - 32px));
  min-height: 100vh;
  min-height: 100dvh;
  grid-template-columns: minmax(0, 1fr) 320px;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 8px;
  margin: 0 auto;
  padding: 10px 0 8px;
}

.shell.loading-mode,
.shell.quiz-mode {
  grid-template-columns: minmax(0, 1fr);
}

.shell.menu-mode {
  grid-template-columns: minmax(0, 520px);
  justify-content: center;
}

.topbar,
.controls,
.status-panel,
.quiz-board,
.side-pane {
  border: 1px solid var(--line);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(255, 238, 179, 0.055), rgba(0, 0, 0, 0.16)),
    var(--panel);
  box-shadow:
    inset 0 1px 0 rgba(255, 240, 196, 0.08),
    0 20px 48px rgba(0, 0, 0, 0.22);
}

.side-pane {
  grid-column: 2;
  grid-row: 2 / 4;
  display: grid;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  overflow: hidden;
  padding: 8px;
}

.loading-mode .side-pane,
.quiz-mode .side-pane {
  display: none;
}

.menu-mode .side-pane {
  grid-column: 1;
  grid-row: 2 / 4;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 9px;
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 9px;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background:
    linear-gradient(145deg, rgba(255, 224, 154, 0.16), rgba(100, 192, 176, 0.1)),
    rgba(0, 0, 0, 0.36);
  color: var(--gold-bright);
  font-weight: 900;
}

.brand-title,
.brand-subtitle {
  display: block;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 900;
  line-height: 1;
}

.brand-subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.74rem;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.nav a,
.primary-action,
.next-action,
.secondary-action {
  min-height: 32px;
  border: 1px solid rgba(255, 224, 154, 0.38);
  border-radius: 4px;
  background:
    linear-gradient(180deg, rgba(116, 76, 35, 0.96), rgba(37, 27, 18, 0.98)),
    #3d2919;
  color: var(--ink);
  cursor: pointer;
  font-weight: 850;
  text-decoration: none;
  box-shadow: inset 0 1px 0 rgba(255, 238, 179, 0.14);
}

.nav a {
  display: grid;
  place-items: center;
  padding: 0 10px;
  font-size: 0.8rem;
}

.nav a[aria-current="page"] {
  border-color: var(--gold-bright);
  color: var(--gold-bright);
}

.controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-items: stretch;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

label,
.category-field,
.civilization-field {
  display: grid;
  gap: 3px;
  color: var(--gold-bright);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.civilization-field {
  gap: 5px;
}

.checkbox-option {
  display: flex;
  min-height: 32px;
  align-items: center;
  gap: 7px;
  border: 1px solid rgba(255, 224, 154, 0.3);
  border-radius: 4px;
  background:
    linear-gradient(180deg, rgba(34, 40, 38, 0.96), rgba(14, 18, 18, 0.98)),
    var(--panel-strong);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 900;
  padding: 6px 8px;
  text-transform: uppercase;
}

.checkbox-option input {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  accent-color: var(--gold);
}

.checkbox-option:has(input:checked) {
  border-color: rgba(255, 224, 154, 0.72);
  background:
    linear-gradient(180deg, rgba(116, 76, 35, 0.98), rgba(37, 27, 18, 0.98)),
    #3d2919;
  color: var(--gold-bright);
}

.ranked-option {
  color: var(--gold-bright);
}

.expansion-dropdown {
  position: relative;
}

.expansion-dropdown-trigger {
  display: flex;
  width: 100%;
  min-height: 34px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid #a77a36;
  border-radius: 4px;
  background:
    linear-gradient(180deg, #fff4c7, #d8b267 78%, #9c682d),
    var(--paper);
  color: #21170e;
  cursor: pointer;
  font-weight: 850;
  padding: 6px 8px;
  text-align: left;
}

.expansion-dropdown-trigger::after {
  content: "";
  width: 0;
  height: 0;
  flex: 0 0 auto;
  border-right: 5px solid transparent;
  border-left: 5px solid transparent;
  border-top: 6px solid currentColor;
}

.expansion-dropdown-trigger[aria-expanded="true"]::after {
  transform: rotate(180deg);
}

.expansion-dropdown-panel {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  right: 0;
  left: 0;
  border: 1px solid rgba(255, 224, 154, 0.42);
  border-radius: 4px;
  background:
    linear-gradient(180deg, rgba(34, 40, 38, 0.99), rgba(14, 18, 18, 0.99)),
    var(--panel-strong);
  box-shadow:
    inset 0 1px 0 rgba(255, 240, 196, 0.08),
    0 20px 42px rgba(0, 0, 0, 0.42);
  padding: 6px;
}

.expansion-checklist {
  display: grid;
  gap: 4px;
  max-height: min(360px, 58vh);
  overflow-y: auto;
  padding-right: 2px;
}

.expansion-count {
  margin-left: auto;
  color: var(--soft);
  font-size: 0.68rem;
}

.category-toggle {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  min-height: 32px;
}

.category-button {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  min-width: 0;
  min-height: 32px;
  border: 1px solid rgba(255, 224, 154, 0.3);
  border-radius: 4px;
  background:
    linear-gradient(180deg, rgba(34, 40, 38, 0.96), rgba(14, 18, 18, 0.98)),
    var(--panel-strong);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 900;
  padding: 0 8px;
  text-transform: uppercase;
}

.category-button::before {
  display: grid;
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 50%;
  content: "X";
  font-size: 0.6rem;
  font-weight: 1000;
  line-height: 1;
  opacity: 0.84;
}

.category-button.active {
  border-color: rgba(255, 224, 154, 0.72);
  background:
    linear-gradient(180deg, rgba(116, 76, 35, 0.98), rgba(37, 27, 18, 0.98)),
    #3d2919;
  color: var(--gold-bright);
}

.category-button.active::before {
  content: "\2713";
}

select {
  width: 100%;
  min-height: 32px;
  border: 1px solid #a77a36;
  border-radius: 4px;
  background:
    linear-gradient(180deg, #fff4c7, #d8b267 78%, #9c682d),
    var(--paper);
  color: #21170e;
  font-weight: 850;
  padding: 5px 8px;
}

select:focus,
input:focus-visible,
.expansion-dropdown-trigger:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 2px;
}

.primary-action {
  padding: 0 14px;
}

.secondary-action {
  width: 100%;
  padding: 0 12px;
}

.status-panel {
  grid-column: 1;
  grid-row: 2;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  padding: 0;
}

.loading-mode .status-panel,
.menu-mode .status-panel {
  display: none;
}

.quiz-mode .status-panel {
  grid-column: 1 / -1;
  grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(132px, auto);
}

.status-panel div {
  display: grid;
  gap: 2px;
  min-height: 42px;
  align-content: center;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.035);
}

.status-panel .status-action-cell {
  padding: 5px;
}

.status-label {
  color: var(--soft);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.status-panel strong {
  overflow: hidden;
  color: var(--gold-bright);
  font-size: 0.96rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-panel strong.warning {
  color: #ffb7a8;
}

.quiz-board {
  grid-column: 1;
  grid-row: 3;
  position: relative;
  min-height: 0;
  overflow: hidden;
  padding: 14px;
}

.menu-mode .quiz-board {
  display: none;
}

.loading-mode .quiz-board,
.quiz-mode .quiz-board {
  grid-column: 1 / -1;
}

.loading-mode .quiz-board {
  grid-row: 2 / 4;
}

.quiz-board::before {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(rgba(255, 243, 208, 0.08), rgba(255, 243, 208, 0.08)),
    var(--texture);
  background-size: auto, 880px auto;
  content: "";
  opacity: 0.16;
  pointer-events: none;
}

.loading,
.question-card,
.results-card {
  position: relative;
  z-index: 1;
}

.loading {
  display: grid;
  min-height: 390px;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: var(--muted);
  text-align: center;
}

.loading-mark {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border: 2px solid var(--line-strong);
  border-radius: 50%;
  color: var(--gold-bright);
  font-size: 2rem;
  font-weight: 900;
}

.question-card,
.results-card {
  display: grid;
  gap: 12px;
  min-height: 390px;
  align-content: start;
}

.question-topline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.question-type,
.question-source,
.results-kicker {
  color: var(--soft);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.question-type {
  color: var(--gold-bright);
}

.timer-bar {
  position: relative;
  height: 18px;
  overflow: hidden;
  border: 1px solid rgba(255, 224, 154, 0.62);
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.4), rgba(255, 255, 255, 0.06)),
    rgba(0, 0, 0, 0.32);
  box-shadow:
    inset 0 1px 3px rgba(0, 0, 0, 0.46),
    0 0 20px rgba(226, 184, 93, 0.22);
}

.timer-bar span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background:
    linear-gradient(90deg, #64b37f, #ffe09a 58%, #e2b85d),
    var(--gold);
  box-shadow: 0 0 18px rgba(255, 224, 154, 0.5);
  transform: scaleX(1);
  transform-origin: left center;
}

.timer-bar.running span {
  transition-property: transform;
  transition-timing-function: linear;
}

.timer-bar.warning {
  border-color: rgba(255, 183, 168, 0.85);
  box-shadow:
    inset 0 1px 3px rgba(0, 0, 0, 0.46),
    0 0 24px rgba(184, 92, 77, 0.34);
}

.timer-bar.warning span {
  background:
    linear-gradient(90deg, #ffb7a8, #e26d58),
    var(--red);
  box-shadow: 0 0 20px rgba(255, 183, 168, 0.58);
}

.prompt-media {
  display: grid;
  width: min(174px, 100%);
  min-height: 112px;
  place-items: center;
  justify-self: center;
  border: 1px solid rgba(255, 224, 154, 0.36);
  border-radius: 6px;
  background:
    radial-gradient(circle at 50% 34%, rgba(255, 224, 154, 0.16), transparent 6rem),
    rgba(0, 0, 0, 0.26);
  box-shadow: inset 0 1px 0 rgba(255, 240, 196, 0.08);
}

.prompt-media.with-copy {
  width: min(560px, 100%);
  grid-template-columns: 94px minmax(0, 1fr);
  gap: 14px;
  justify-self: center;
  justify-items: start;
  min-height: 112px;
  padding: 10px 13px;
}

.prompt-media img {
  display: block;
  width: min(92px, 72%);
  height: min(92px, 72%);
  object-fit: contain;
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.36));
}

.prompt-media.with-copy img {
  width: 82px;
  height: 82px;
}

.prompt-media div {
  display: grid;
  gap: 5px;
  align-content: center;
  min-width: 0;
  color: var(--ink);
  text-align: left;
}

.prompt-media strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 1rem;
  font-weight: 950;
  line-height: 1.1;
}

.prompt-media span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  line-height: 1.2;
  text-transform: uppercase;
}

.prompt-media p {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.25;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.clues {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.clues li {
  min-height: 48px;
  border: 1px solid rgba(255, 224, 154, 0.28);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(255, 244, 202, 0.94), rgba(225, 197, 129, 0.9)),
    var(--texture),
    var(--paper);
  background-size: auto, 620px auto, auto;
  color: var(--paper-ink);
  font-weight: 850;
  line-height: 1.35;
  padding: 8px 10px;
}

.clues span {
  display: block;
  color: #74501f;
  font-size: 0.7rem;
  font-weight: 950;
  text-transform: uppercase;
}

.question-card h1,
.results-card h1 {
  max-width: 760px;
  color: var(--ink);
  font-size: clamp(1.6rem, 4vw, 3.15rem);
  line-height: 1;
  letter-spacing: 0;
  text-wrap: balance;
}

.answers {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 0;
}

.answer {
  display: grid;
  min-height: 58px;
  align-items: center;
  border: 1px solid rgba(226, 184, 93, 0.34);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(255, 240, 196, 0.08), rgba(0, 0, 0, 0.18)),
    var(--panel-strong);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.96rem;
  font-weight: 850;
  line-height: 1.2;
  padding: 11px 12px;
  text-align: left;
  transition:
    border-color 140ms ease,
    background 140ms ease,
    transform 140ms ease;
}

.answer:hover:not(:disabled) {
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

.answer:disabled {
  cursor: default;
}

.answer.correct {
  border-color: rgba(100, 179, 127, 0.86);
  background:
    linear-gradient(180deg, rgba(100, 179, 127, 0.22), rgba(0, 0, 0, 0.12)),
    var(--panel-strong);
}

.answer.incorrect {
  border-color: rgba(184, 92, 77, 0.9);
  background:
    linear-gradient(180deg, rgba(184, 92, 77, 0.22), rgba(0, 0, 0, 0.12)),
    var(--panel-strong);
}

.feedback {
  border: 1px solid rgba(255, 224, 154, 0.32);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(255, 244, 202, 0.94), rgba(225, 197, 129, 0.92)),
    var(--texture),
    var(--paper);
  background-size: auto, 680px auto, auto;
  color: var(--paper-ink);
  font-weight: 800;
  line-height: 1.45;
  padding: 10px 12px;
}

.next-action {
  width: max-content;
  min-width: 118px;
  justify-self: end;
  padding: 0 16px;
}

.results-card {
  align-content: center;
  text-align: center;
}

.results-card h1,
.results-card p {
  justify-self: center;
}

.results-card p {
  max-width: 600px;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.55;
}

.results-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.results-review {
  min-height: 0;
  overflow: auto;
  padding: 8px 0 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.results-review {
  width: min(760px, 100%);
  max-height: 420px;
  justify-self: center;
  margin-top: 4px;
  text-align: left;
}

.results-review h2 {
  color: var(--gold-bright);
  font-size: 1rem;
  line-height: 1;
  text-transform: uppercase;
}

.results-review ol {
  display: grid;
  gap: 7px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.results-review li {
  border: 1px solid rgba(226, 184, 93, 0.2);
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.18);
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
  padding: 8px;
}

.results-review li.correct {
  border-color: rgba(100, 179, 127, 0.45);
}

.results-review li.incorrect {
  border-color: rgba(184, 92, 77, 0.52);
}

.results-review strong {
  display: block;
  color: var(--ink);
  font-size: 0.92rem;
  margin-bottom: 4px;
}

.results-review span {
  display: block;
}

.legal-notice {
  grid-column: 1 / -1;
  color: var(--soft);
  font-size: 0.7rem;
  line-height: 1.3;
  padding: 0 2px;
}

.legal-notice a {
  color: var(--gold-bright);
}

[hidden] {
  display: none !important;
}

@media (max-width: 860px) {
  .shell {
    width: min(100% - 22px, 1220px);
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

  .side-pane,
  .status-panel,
  .quiz-board {
    grid-column: auto;
    grid-row: auto;
  }

  .side-pane {
    overflow: visible;
  }

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

  .category-toggle {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .primary-action {
    min-height: 36px;
  }

  .status-panel {
    grid-template-columns: 1fr;
  }

  .status-panel div {
    min-height: 58px;
  }

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

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

  .quiz-board {
    min-height: 0;
    padding: 12px;
  }

  .question-card,
  .results-card,
  .loading {
    min-height: 380px;
  }
}

@media (max-width: 540px) {
  .nav {
    width: 100%;
  }

  .nav a {
    flex: 1;
  }

  .question-card h1,
  .results-card h1 {
    font-size: 2rem;
  }

  .answer {
    min-height: 66px;
    font-size: 0.98rem;
  }
}
