:root {
  --ink: #07172d;
  --ink-2: #102a4b;
  --paper: #f3ead7;
  --paper-dark: #d7c8aa;
  --orange: #f16a36;
  --gold: #d9a441;
  --green: #3f7d62;
  --blue: #3277a8;
  --white: #fffdf7;
  --line: rgba(7, 23, 45, .23);
  --mono: "DM Mono", ui-monospace, monospace;
  --sans: "Manrope", system-ui, sans-serif;
  --serif: "Spectral", Georgia, serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--ink); }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 10%, rgba(241, 106, 54, .09), transparent 28rem),
    var(--ink);
  color: var(--white);
  font-family: var(--sans);
  line-height: 1.5;
}
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; }

.skip-link {
  position: fixed;
  top: -4rem;
  left: 1rem;
  z-index: 100;
  padding: .8rem 1rem;
  background: var(--orange);
  color: var(--ink);
  font-weight: 800;
}
.skip-link:focus { top: 1rem; }

.game-header {
  min-height: 74px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  padding: .8rem clamp(1rem, 3vw, 2.5rem);
  border-bottom: 1px solid rgba(255,255,255,.15);
  background: rgba(7, 23, 45, .96);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: .75rem;
  justify-self: start;
  text-decoration: none;
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .1em;
}
.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  background: var(--orange);
  color: var(--ink);
  font: 700 1rem var(--mono);
}
.game-name { text-align: center; line-height: 1.15; }
.game-name span { display: block; color: var(--orange); font: 500 .62rem var(--mono); letter-spacing: .14em; }
.game-name strong { font: 700 1rem var(--serif); letter-spacing: .06em; }
.plain-button {
  justify-self: end;
  border: 1px solid rgba(255,255,255,.4);
  background: transparent;
  color: var(--white);
  padding: .6rem .85rem;
  font-size: .76rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .07em;
}
.plain-button:hover { border-color: var(--orange); color: var(--orange); }

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(290px, 340px);
  gap: 1rem;
  max-width: 1580px;
  margin: 0 auto;
  padding: 1rem;
}
.scene-panel { min-width: 0; }
.scene {
  position: relative;
  min-height: min(63vw, 700px);
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.18);
  background: #17233a;
}
.scene > img:first-child {
  display: block;
  width: 100%;
  height: 100%;
  min-height: min(63vw, 700px);
  object-fit: cover;
  object-position: center;
  transition: filter .35s ease, transform .7s ease;
}
.scene[data-category="History"] > img:first-child { filter: sepia(.16) saturate(.88); }
.scene[data-category="Literature"] > img:first-child { filter: hue-rotate(335deg) saturate(.92); }
.scene[data-category="Codes"] > img:first-child { filter: hue-rotate(175deg) saturate(.72) brightness(.86); }
.scene[data-category="Film & Music"] > img:first-child { filter: hue-rotate(315deg) saturate(.95) contrast(1.05); }
.scene[data-category="Machines"] > img:first-child { filter: saturate(.7) contrast(1.1); }
.scene[data-category="Natural World"] > img:first-child { filter: hue-rotate(35deg) saturate(1.15); }
.scene-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(7,23,45,.04) 38%, rgba(7,23,45,.92) 100%);
  pointer-events: none;
}
.room-host {
  position: absolute;
  z-index: 2;
  left: -2%;
  bottom: -10%;
  width: clamp(210px, 35%, 470px);
  height: 92%;
  object-fit: contain;
  object-position: left bottom;
  filter: drop-shadow(0 18px 24px rgba(0,0,0,.35));
  pointer-events: none;
  transition: opacity .22s ease, transform .32s ease;
}
.host-card {
  position: absolute;
  z-index: 5;
  left: clamp(1rem, 3vw, 2.2rem);
  top: clamp(1rem, 3vw, 2.2rem);
  width: min(320px, 43%);
  padding: .8rem 1rem;
  border: 1px solid rgba(255,255,255,.62);
  background: rgba(7,23,45,.89);
  box-shadow: 0 10px 30px rgba(0,0,0,.28);
}
.host-card strong { display: block; color: #ffd59f; font: 600 1.05rem var(--serif); }
.host-card span { display: block; margin-top: .2rem; color: #edf3fa; font-size: .75rem; line-height: 1.35; }
.room-caption {
  position: absolute;
  left: clamp(1rem, 38%, 31rem);
  bottom: clamp(1rem, 3vw, 2.3rem);
  z-index: 2;
  max-width: 70%;
}
.room-caption p {
  margin: 0 0 .45rem;
  color: #ffd59f;
  font: 500 .7rem var(--mono);
  letter-spacing: .14em;
}
.room-caption h1 {
  margin: 0;
  font: 700 clamp(2.2rem, 5vw, 5rem)/.95 var(--serif);
  letter-spacing: -.035em;
  text-shadow: 0 2px 18px rgba(0,0,0,.48);
}
.door-options {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}
.door-route {
  position: absolute;
  bottom: 34%;
  width: clamp(110px, 14vw, 170px);
  border: 1px solid rgba(255,255,255,.72);
  background: rgba(7,23,45,.88);
  color: var(--white);
  padding: .65rem .7rem;
  font-size: .72rem;
  font-weight: 800;
  pointer-events: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.door-route:hover { background: var(--orange); color: var(--ink); border-color: var(--orange); }
.door-route:nth-child(1) { left: 12%; }
.door-route:nth-child(2) { left: 50%; transform: translateX(-50%); }
.door-route:nth-child(3) { right: 12%; }

.question-panel {
  padding: clamp(1.3rem, 3vw, 2.4rem);
  border: 1px solid var(--paper-dark);
  border-top: 0;
  background: var(--paper);
  color: var(--ink);
}
.question-meta { display: flex; justify-content: space-between; gap: 1rem; color: #9a4f2f; font: 500 .68rem var(--mono); letter-spacing: .12em; }
.question-panel h2 { max-width: 930px; margin: 1rem 0 1.35rem; font: 600 clamp(1.5rem, 3vw, 2.55rem)/1.16 var(--serif); }
.answer-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
.answer-button {
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--ink);
  padding: .9rem 1rem;
  text-align: left;
  font-weight: 700;
}
.answer-button:hover:not(:disabled) { border-color: var(--orange); box-shadow: inset 4px 0 0 var(--orange); }
.answer-button.correct { border-color: var(--green); background: #e4f1e9; }
.answer-button.wrong { border-color: #a43c36; background: #f5ded8; }
.answer-button:disabled { cursor: default; }
.feedback { min-height: 1.5rem; margin: 1rem 0 0; color: #5f5b50; }
.feedback.success { color: #235f43; font-weight: 800; }
.feedback.error { color: #85332f; font-weight: 700; }

.status-panel { display: flex; flex-direction: column; gap: 1rem; }
.status-card { border: 1px solid rgba(255,255,255,.17); background: var(--ink-2); padding: 1.2rem; }
.panel-label { margin: 0 0 .9rem; color: var(--orange); font: 500 .68rem var(--mono); letter-spacing: .13em; }
.score-line { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.score-line strong { font: 700 2.3rem var(--serif); }
.score-line span { color: #b7c7da; font-size: .78rem; }
.meter { height: 8px; margin: .75rem 0 1rem; overflow: hidden; background: rgba(255,255,255,.12); }
.meter span { display: block; width: 0; height: 100%; background: var(--orange); transition: width .35s ease; }
.score-details { display: flex; justify-content: space-between; color: #b7c7da; font-size: .76rem; }
.score-details strong { color: var(--white); }
.map-heading { display: flex; align-items: start; justify-content: space-between; gap: 1rem; }
.map-heading span { color: #b7c7da; font-size: .68rem; }
.maze-map { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; }
.map-room {
  position: relative;
  aspect-ratio: 1.15;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.04);
  color: #657990;
  font: 500 .62rem var(--mono);
}
.map-room:disabled { cursor: default; }
.map-room.open { border-color: var(--blue); background: rgba(50,119,168,.2); color: #b8def7; }
.map-room.cleared { border-color: var(--green); background: rgba(63,125,98,.34); color: #d9f2e5; }
.map-room.current { outline: 2px solid var(--orange); outline-offset: 1px; color: var(--white); }
.map-room.final { border-radius: 50% 50% 8% 8%; }
.map-room span { position: absolute; inset: auto 4px 3px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.map-key { display: flex; flex-wrap: wrap; gap: .7rem; margin-top: .85rem; color: #b7c7da; font-size: .62rem; }
.map-key span { display: inline-flex; align-items: center; gap: .3rem; }
.map-key i { width: 10px; height: 10px; border: 1px solid; }
.map-key i.current { border-color: var(--orange); }
.map-key i.open { border-color: var(--blue); }
.map-key i.cleared { border-color: var(--green); background: rgba(63,125,98,.5); }
.journal-card { flex: 1; }
.journal-card > p:nth-child(2) { color: #d5dfeb; }
.hint-button {
  width: 100%;
  margin-top: 1rem;
  border: 1px solid rgba(255,255,255,.36);
  background: transparent;
  color: var(--white);
  padding: .7rem;
  font-weight: 800;
}
.hint-button:hover:not(:disabled) { border-color: var(--orange); color: var(--orange); }
.hint-button:disabled { opacity: .35; cursor: default; }

.start-screen, .ending-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: 1rem;
  background: rgba(3, 12, 25, .9);
  backdrop-filter: blur(10px);
}
.start-card, .ending-card {
  width: min(760px, 100%);
  border: 1px solid var(--gold);
  background:
    linear-gradient(rgba(7,23,45,.95), rgba(7,23,45,.98)),
    url("assets/archive-hall.png") center / cover;
  padding: clamp(1.5rem, 5vw, 4rem);
  box-shadow: 0 24px 70px rgba(0,0,0,.55);
}
.start-card h2, .ending-card h2 { margin: 0 0 1rem; font: 700 clamp(3rem, 8vw, 6.5rem)/.9 var(--serif); letter-spacing: -.04em; }
.start-card > p:nth-of-type(2), .ending-card > p { color: #ced9e7; font-size: 1.05rem; }
fieldset { margin: 2rem 0 1rem; padding: 0; border: 0; }
legend { margin-bottom: .8rem; font: 500 .7rem var(--mono); letter-spacing: .12em; text-transform: uppercase; }
.level-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .65rem; }
.level-grid button {
  border: 1px solid rgba(255,255,255,.3);
  background: rgba(255,255,255,.05);
  color: var(--white);
  padding: 1rem .5rem;
}
.level-grid button:hover, .level-grid button.selected { border-color: var(--orange); background: rgba(241,106,54,.17); }
.level-grid strong { display: block; color: var(--orange); font: 700 2.5rem var(--serif); }
.level-grid span { font-size: .72rem; }
.start-button, .resume-button {
  width: 100%;
  border: 0;
  padding: .95rem 1rem;
  font-weight: 800;
}
.start-button { background: var(--orange); color: var(--ink); }
.start-button:disabled { background: #6f7783; cursor: default; }
.resume-button { margin-top: .65rem; border: 1px solid rgba(255,255,255,.35); background: transparent; color: var(--white); }
.ending-card { text-align: center; }
.ending-card .final-score { color: var(--gold); font: 600 1.3rem var(--serif); }
.ending-card a { display: inline-block; margin-top: 1rem; text-underline-offset: .3rem; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--orange); outline-offset: 3px; }

@media (max-width: 980px) {
  .game-layout { grid-template-columns: 1fr; }
  .status-panel { display: grid; grid-template-columns: repeat(2, 1fr); }
  .journal-card { grid-column: 1 / -1; }
  .scene, .scene > img:first-child { min-height: min(78vw, 650px); }
}

@media (max-width: 640px) {
  .game-header { grid-template-columns: 1fr auto; }
  .game-name { display: none; }
  .brand > span:last-child { display: none; }
  .game-layout { padding: .55rem; gap: .55rem; }
  .scene, .scene > img:first-child { min-height: 88vw; }
  .room-host { width: 43%; height: 82%; bottom: -8%; }
  .host-card { top: .65rem; left: .65rem; width: 58%; padding: .55rem .65rem; }
  .host-card strong { font-size: .85rem; }
  .host-card span { font-size: .64rem; }
  .room-caption { left: 42%; bottom: .75rem; max-width: 55%; }
  .door-route { bottom: 40%; width: 95px; padding: .5rem; font-size: .61rem; }
  .door-route:nth-child(1) { left: 4%; }
  .door-route:nth-child(3) { right: 4%; }
  .answer-grid, .status-panel { grid-template-columns: 1fr; }
  .journal-card { grid-column: auto; }
  .level-grid { grid-template-columns: repeat(2, 1fr); }
  .start-card h2, .ending-card h2 { font-size: clamp(2.8rem, 16vw, 5rem); }
}

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