:root {
  --brown: #5d3a1a;
  --burgundy: #6b1a1a;
  --gold: #d4af37;
  --gold-bright: #f0d78c;
  --parchment: #f5e6c8;
  --parchment-dark: #e8d4a8;
  --green: #1a3a2a;
  --amber: #ffb300;
  --ink: #2a1a10;
  --ink-soft: #4a3424;
  --shadow: rgba(10, 6, 2, 0.72);
  --font-display: "Cinzel", "Palatino Linotype", Palatino, serif;
  --font-body: "IM Fell English", "Palatino Linotype", Palatino, serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: #120c08;
  color: var(--parchment);
  font-family: var(--font-body);
}

body {
  min-height: 100dvh;
}

button {
  font-family: inherit;
  cursor: pointer;
}

img.pixel {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#app {
  min-height: 100dvh;
}

.screen {
  display: none;
  min-height: 100dvh;
}

.screen.is-active {
  display: block;
}

.screen[hidden] {
  display: none !important;
}

.eyebrow {
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.72rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--gold);
}

/* ---------- Title ---------- */

.title-stage {
  position: relative;
  min-height: 100dvh;
  overflow: hidden;
  background: #1a1008;
}

.title-art {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, calc(-50% - 1.7rem));
  width: auto;
  height: min(86dvh, calc(100dvh - 6.2rem));
  max-width: 92vw;
  object-fit: contain;
  object-position: center;
}

.title-copy {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 3.2vh;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 1.25rem;
  text-align: center;
  background: transparent;
}

/* ---------- Buttons ---------- */

.btn-play,
.btn-ink,
.btn-text {
  border: 0;
}

.btn-play {
  min-width: 11rem;
  padding: 0.8rem 1.9rem 0.88rem;
  background: #4a2c16;
  color: var(--parchment);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.02rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  border: 2px solid #c4a574;
  box-shadow: inset 0 1px 0 rgba(245, 230, 200, 0.18);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-play:hover {
  background: #5d3a1a;
  border-color: #e0c48a;
}

.btn-play:focus-visible,
.btn-ink:focus-visible {
  outline: 2px solid #c4a574;
  outline-offset: 2px;
}

.btn-ink {
  min-width: 11rem;
  padding: 0.85rem 1.6rem;
  background: #2a1810;
  color: var(--parchment);
  font-family: var(--font-display);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border: 2px solid var(--gold);
}

.btn-ink:hover {
  background: #3a2418;
}

.btn-text {
  background: transparent;
  color: var(--gold-bright);
  font-family: var(--font-display);
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  padding: 0.4rem 0;
}

.btn-text:hover {
  color: #fff;
}

/* ---------- Shared scenes ---------- */

.scene {
  position: relative;
  overflow: hidden;
  min-height: 100dvh;
  padding: 1.25rem 1.4rem 2rem;
  background:
    radial-gradient(ellipse at 50% 28%, #3a2416 0%, #1a120c 55%, #120c08 100%);
}

.scene--library {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 100dvh;
  overflow: auto;
  padding: clamp(0.85rem, 2vh, 1.4rem) clamp(1rem, 3vw, 2rem) clamp(1.1rem, 2.6vh, 1.8rem);
  background:
    radial-gradient(ellipse at 50% 30%, #4a301c 0%, #24160e 48%, #120c08 100%);
}

.scene--desk {
  display: flex;
  flex-direction: column;
}

.scene--results {
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}

.topbar,
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 980px;
  margin: 0 auto 1rem;
}

.scene--library .topbar {
  flex: 0 0 auto;
  width: 100%;
  max-width: min(1180px, 96vw);
  margin-bottom: clamp(0.35rem, 1.2vh, 0.85rem);
}

.topbar-title h1,
.results-scroll h1 {
  margin: 0.15rem 0 0;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 700;
  color: var(--gold-bright);
}

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

.topbar-spacer {
  width: 6.5rem;
}

.lead {
  max-width: 640px;
  margin: 0 auto 1.6rem;
  text-align: center;
  color: var(--parchment-dark);
  font-size: 1.12rem;
}

.scene--library .lead {
  flex: 0 0 auto;
  width: 100%;
  margin-bottom: clamp(0.7rem, 1.8vh, 1.25rem);
}

/* ---------- Subjects ---------- */

.subject-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(0.85rem, 1.8vw, 1.4rem);
  flex: 1 1 auto;
  width: 100%;
  max-width: min(1180px, 96vw);
  margin: 0 auto;
  min-height: 0;
}

.subject-card {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  height: 100%;
  min-height: 0;
  padding: clamp(1rem, 2.4vh, 1.85rem) 0.9rem;
  background: #2a1810;
  border: 2px solid #8a6a2a;
  color: inherit;
  text-align: center;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.subject-card:hover,
.subject-card:focus-visible {
  transform: translateY(-4px);
  border-color: var(--gold);
  background: rgba(42, 24, 12, 0.9);
  outline: none;
}

.subject-card img {
  width: clamp(88px, 14vh, 148px);
  height: clamp(88px, 14vh, 148px);
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.55));
}

.subject-card h2 {
  margin: 0.2rem 0 0;
  font-family: var(--font-display);
  font-size: clamp(1.02rem, 1.6vw, 1.22rem);
  color: var(--gold-bright);
}

.subject-card p {
  margin: 0;
  font-size: 0.95rem;
  color: #d8c4a0;
}

.subject-card .count {
  margin-top: 0.2rem;
  font-family: var(--font-display);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--amber);
}

/* ---------- Game HUD ---------- */

.hud-block {
  flex: 1;
}

.hud-meta {
  display: block;
  margin-top: 0.35rem;
  color: #d8c4a0;
  font-size: 0.95rem;
}

.progress-track {
  margin-top: 0.45rem;
  height: 10px;
  max-width: 280px;
  background: #2a1810;
  border: 1px solid #8a6a2a;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--burgundy), var(--gold));
  transition: width 0.25s ease;
}

.hud-score {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.85rem;
  background: rgba(20, 12, 8, 0.72);
  border: 1px solid #8a6a2a;
}

.hud-star {
  width: 42px;
  height: 42px;
  object-fit: contain;
  image-rendering: pixelated;
}

.hud-score strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1.55rem;
  color: var(--gold-bright);
  line-height: 1;
}

.hud .btn-text {
  align-self: flex-start;
}

/* ---------- Case card ---------- */

.case-card {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  align-items: stretch;
  justify-content: center;
  max-width: 920px;
  width: 100%;
  margin: 0.4rem auto 0.85rem;
  min-height: min(42vh, 340px);
}

.case-card-frame {
  display: none;
}

.case-card-inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: min(920px, 100%);
  margin: 0;
  padding: 1.8rem 2rem 2rem;
  background: #f5e6c8;
  color: var(--ink);
  border: 2px solid #8a6a2a;
}

.case-card-inner .eyebrow {
  color: var(--brown);
  font-size: 0.82rem;
}

.precedent-text {
  margin: 0.7rem 0 0;
  font-size: clamp(1.28rem, 2.6vw, 1.7rem);
  line-height: 1.5;
}

/* ---------- Options ---------- */

.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  max-width: 920px;
  width: 100%;
  margin: 0 auto;
}

.option {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  min-height: 4.4rem;
  padding: 0.85rem 1.1rem;
  background: #f5e6c8;
  color: #2a1a10;
  text-align: left;
  font-size: 1.02rem;
  line-height: 1.3;
  border: 2px solid #8a6a2a;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.option:hover:not(:disabled) {
  background: #efe0b8;
  border-color: #c4a574;
}

.option:disabled {
  cursor: default;
}

.option-key {
  flex: 0 0 1.7rem;
  width: 1.7rem;
  height: 1.7rem;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 0.82rem;
  color: var(--parchment);
  background: #5d3a1a;
  border: 1px solid #8a6a2a;
}

.option-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: break-word;
}

.option.is-correct {
  outline: none;
  border-color: #2f7a3a;
  background: #e4efd8;
}

.option.is-wrong {
  outline: none;
  border-color: var(--burgundy);
  background: #ead4c8;
  animation: shake 0.35s ease;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-6px);
  }
  75% {
    transform: translateX(6px);
  }
}

/* ---------- Feedback ---------- */

.feedback {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(18, 12, 8, 0.82);
  padding: 1rem;
}

.feedback[hidden] {
  display: none !important;
}

.feedback-panel,
.results-scroll {
  width: min(640px, 92vw);
  background-color: #f5e6c8;
  background-image: url("../assets/panel-scroll.png");
  background-size: 100% 100%;
  background-repeat: no-repeat;
  color: var(--ink);
  border: 0;
  text-align: center;
}

.scroll-inner {
  box-sizing: border-box;
  width: 100%;
  padding: 3.4rem clamp(4.8rem, 11vw, 6.4rem) 2.8rem;
}

.feedback-panel h2 {
  margin: 0.2rem 0 0.35rem;
  font-family: var(--font-display);
  font-size: 1.8rem;
  color: var(--green);
}

.feedback.is-wrong .feedback-panel h2 {
  color: var(--burgundy);
}

.feedback-case {
  margin: 0 0 0.8rem;
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--brown);
}

.feedback-fact {
  margin: 0 0 1.3rem;
  font-style: italic;
  line-height: 1.4;
  color: var(--ink-soft);
}

.feedback-panel .btn-play {
  width: 100%;
}

/* ---------- Results ---------- */

.results-scroll {
  text-align: center;
}

.results-scroll .eyebrow,
.scroll-inner .eyebrow {
  color: var(--brown);
}

.results-scroll h1 {
  color: var(--brown);
}

.score-label {
  margin: 1rem 0 0;
  font-family: var(--font-display);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-size: 0.78rem;
  color: var(--brown);
}

.score-num {
  margin: 0.1rem 0 0;
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 7vw, 3.6rem);
  font-weight: 900;
  color: #c9a227;
  line-height: 1;
  text-shadow: 1px 2px 0 #5c4310;
}

.accuracy,
.high-score,
.results-blurb {
  margin: 0.35rem 0 0;
  color: var(--ink-soft);
}

.results-blurb {
  margin-top: 0.8rem;
  font-style: italic;
}

.results-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  margin-top: 1.3rem;
}

@media (max-width: 820px) {
  .subject-grid,
  .options {
    grid-template-columns: 1fr 1fr;
  }

  .scene--library {
    height: auto;
  }

  .subject-card {
    height: auto;
    min-height: 11.5rem;
  }

  .topbar-spacer {
    display: none;
  }

  .case-card {
    min-height: min(36vh, 280px);
  }

  .case-card-inner {
    margin: 0;
    padding: 1.4rem 1.25rem 1.5rem;
  }

  .results-scroll,
  .feedback-panel {
    width: min(100%, 96vw);
  }

  .scroll-inner {
    padding: 2.6rem clamp(3.2rem, 10vw, 5rem) 2.2rem;
  }
}

@media (min-width: 1100px) {
  .title-art {
    top: 50%;
    left: 50%;
    right: auto;
    bottom: auto;
    width: min(100vw, 140dvh);
    height: min(100vw, 140dvh);
    max-width: none;
    transform: translate(-50%, -50%);
    object-fit: contain;
    object-position: center;
  }

  .title-copy {
    bottom: 3.6vh;
  }

  .title-stage .btn-play {
    min-width: 16.5rem;
    padding: 1.12rem 2.8rem 1.2rem;
    font-size: 1.32rem;
    letter-spacing: 0.22em;
  }
}

@media (max-width: 560px) {
  .subject-grid {
    grid-template-columns: 1fr;
  }

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

  .title-art {
    width: auto;
    height: min(82dvh, calc(100dvh - 5.4rem));
    max-width: 94vw;
    transform: translate(-50%, calc(-50% - 1.1rem));
  }

  .title-copy {
    bottom: 2.4vh;
  }

  .scene--library {
    height: auto;
  }

  .subject-card {
    height: auto;
  }
}
