:root {
  --stone: #1c1814;
  --stone-2: #26201a;
  --stone-3: #33291f;
  --cream: #f3ead8;
  --cream-dim: #d9ccb0;
  --ember: #e86b2a;
  --ember-dark: #b94d17;
  --ink: #1c1814;
  --good: #3f8f4e;
  --bad: #b3361f;
  --radius: 14px;
  --display: "Cinzel", Georgia, "Times New Roman", serif;
  --body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@font-face { font-family: "Cinzel"; src: url("../assets/fonts/Cinzel.ttf") format("truetype"); font-weight: 400 900; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("../assets/fonts/AtkinsonHyperlegible-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("../assets/fonts/AtkinsonHyperlegible-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }

* { box-sizing: border-box; }
html { background: var(--stone); color: var(--cream); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; font-family: var(--body); font-size: 18px; line-height: 1.45;
  background:
    linear-gradient(180deg, rgba(28,24,20,.82), rgba(28,24,20,.92)),
    url("../assets/bg/cave.jpg") center / cover fixed no-repeat,
    var(--stone);
}
#app { min-height: 100dvh; }
h1, h2 { font-family: var(--display); margin: 0; line-height: 1.1; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--ember); outline-offset: 3px; }
h1:focus, h2:focus { outline: none; }
img { max-width: 100%; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 16px 18px calc(18px + env(safe-area-inset-bottom)); min-height: 100dvh; display: flex; flex-direction: column; }
.foot { margin-top: auto; padding-top: 18px; text-align: center; color: var(--cream-dim); font-size: .85rem; letter-spacing: .04em; }
.eyebrow { font-family: var(--display); font-weight: 700; font-size: .85rem; letter-spacing: .22em; text-transform: uppercase; color: var(--ember); margin: 0 0 6px; }
.eyebrow.dark { font-family: var(--body); color: var(--ember-dark); letter-spacing: .02em; font-size: .9rem; text-transform: none; }
.std { font-family: var(--body); font-weight: 700; color: #6b5a44; margin-left: 6px; font-size: .78rem; border: 1px solid #b9a98a; border-radius: 6px; padding: 0 6px; }

/* ---- buttons ---- */
.btn { min-height: 56px; padding: 12px 26px; border-radius: var(--radius); border: 2px solid var(--cream-dim); background: var(--stone-2); color: var(--cream); font-weight: 700; font-size: 1.1rem; cursor: pointer; letter-spacing: .02em; }
.btn:hover { background: var(--stone-3); }
.btn.primary { background: var(--ember); border-color: var(--ember); color: #1c1814; }
.btn.primary:hover { background: #f07c3b; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 44px; padding: 6px 16px; font-size: 1rem; }
.btns { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 22px; }
.btns.col { flex-direction: column; align-items: stretch; max-width: 420px; }

/* ---- ogre ---- */
.stage { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
.ogre { display: block; height: min(34dvh, 320px); width: auto; filter: drop-shadow(0 12px 14px rgba(0,0,0,.7)); transform-origin: 50% 100%; user-select: none; -webkit-user-drag: none; }
.ogre.idle { animation: breathe 3.6s ease-in-out infinite; }
.ogre.hurt { animation: flinch .5s ease-out; }
.ogre.down { animation: fall .7s ease-in forwards; }
@keyframes breathe { 50% { transform: translateY(-4px) scale(1.01); } }
@keyframes flinch { 0% { transform: translateX(0); } 20% { transform: translateX(-14px) rotate(-3deg); } 50% { transform: translateX(8px) rotate(2deg); } 100% { transform: none; } }
@keyframes fall { from { transform: translateY(-14px); opacity: .85; } to { transform: none; opacity: 1; } }

.hp { display: flex; align-items: center; gap: 5px; margin-top: 12px; padding: 7px 10px; background: rgba(28,24,20,.82); border: 2px solid var(--cream-dim); border-radius: 999px; }
.hp .seg { width: 30px; height: 14px; border-radius: 4px; border: 2px solid var(--ember); }
.hp .seg.on { background: var(--ember); }
.hp .seg.off { background: transparent; opacity: .45; }
.hp .hpn { margin-left: 6px; font-weight: 700; font-size: .95rem; }

.hearts { display: flex; gap: 6px; }
.heart { width: 30px; height: 28px; }
.heart.full { fill: var(--ember); stroke: var(--cream); stroke-width: 1.5; }
.heart.empty { fill: transparent; stroke: var(--cream-dim); stroke-width: 1.5; opacity: .6; }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; }
.cavetag { font-family: var(--display); font-weight: 700; letter-spacing: .08em; color: var(--cream); text-align: center; flex: 1; }

/* ---- title / result ---- */
.title, .result { justify-content: center; gap: 12px; }
.title .ogre, .result .ogre { height: min(38dvh, 380px); }
.panel { text-align: center; }
.panel h1 { font-size: clamp(2.6rem, 11vw, 5rem); font-weight: 800; letter-spacing: .01em; color: var(--cream); text-shadow: 0 3px 0 #000, 0 0 24px rgba(232,107,42,.35); }
.result .panel h1 { font-size: clamp(2rem, 8vw, 3.4rem); }
.tag { font-size: 1.25rem; margin: 14px 0 6px; color: var(--cream); }
.sub { margin: 0; color: var(--cream-dim); }
.panel .btns { justify-content: center; }
.panel .btns.col { margin-left: auto; margin-right: auto; }
.stats { display: flex; gap: 12px; justify-content: center; margin: 18px 0 8px; }
.stats div { background: rgba(28,24,20,.8); border: 2px solid var(--cream-dim); border-radius: var(--radius); padding: 10px 18px; min-width: 130px; }
.stats dt { font-size: .85rem; color: var(--cream-dim); }
.stats dd { margin: 0; font-family: var(--display); font-weight: 800; font-size: 1.6rem; color: var(--ember); }
.practiced { color: var(--cream-dim); max-width: 34ch; margin: 8px auto 0; }
.result.lost h1 { color: #f6c9b0; }

@media (orientation: landscape) and (min-width: 760px) {
  .title, .result { flex-direction: row; align-items: center; gap: 40px; }
  .title .stage, .result .stage { flex: 0 0 38%; }
  .title .ogre, .result .ogre { height: min(70dvh, 560px); }
  .panel { text-align: left; flex: 1; }
  .panel .btns { justify-content: flex-start; }
  .panel .btns.col { margin-left: 0; }
  .stats { justify-content: flex-start; }
  .practiced { margin-left: 0; }
}

/* ---- caves ---- */
.h-sm { font-size: clamp(1.8rem, 6vw, 2.6rem); margin: 8px 0 4px; }
.lead { margin: 0 0 14px; color: var(--cream-dim); }
.cavelist { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.cave { display: flex; flex-direction: column; gap: 4px; width: 100%; height: 100%; text-align: left; padding: 16px 18px; border-radius: var(--radius); border: 2px solid var(--ember); background: linear-gradient(180deg, #3a2e22, #2a2118); color: var(--cream); cursor: pointer; }
.cave.open:hover { background: linear-gradient(180deg, #4a3826, #33271b); }
.cave .cname { font-family: var(--display); font-weight: 800; font-size: 1.35rem; }
.cave .cblurb { color: var(--cream); }
.cave .cmeta { color: var(--cream-dim); font-size: .85rem; margin-top: 4px; }
.cave.locked { border-color: #5a4d3d; background: rgba(28,24,20,.7); color: #a79a82; cursor: not-allowed; border-style: dashed; }
.cave.locked .cblurb { color: #a79a82; }
.lock { font-size: 1rem; }

/* ---- fight ---- */
.fight { gap: 8px; }
.arena { display: grid; gap: 14px; grid-template-columns: 1fr; align-items: start; }
.fight .stage { align-self: center; }
.fight .ogre { height: min(20dvh, 170px); }
@media (min-width: 820px) {
  .arena { grid-template-columns: minmax(220px, 32%) 1fr; gap: 28px; align-items: center; }
  .fight .ogre { height: min(52dvh, 440px); }
  .fight .stage { align-self: end; }
}
.qcard { background: var(--cream); color: var(--ink); border-radius: 18px; padding: 18px 18px 20px; box-shadow: 0 8px 30px rgba(0,0,0,.55); border: 3px solid #cdbf9f; }
.stem { font-family: var(--body); font-weight: 700; font-size: clamp(1.2rem, 4.2vw, 1.55rem); line-height: 1.3; margin: 2px 0 12px; color: var(--ink); }
.visuals { display: grid; gap: 12px; margin-bottom: 14px; }
.visuals.n2 { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.vis { margin: 0; background: #fbf6ea; border: 2px solid #d7c9a8; border-radius: 12px; padding: 10px; text-align: center; overflow-x: auto; }
.vis figcaption { font-family: var(--display); font-weight: 800; color: var(--ember-dark); margin-bottom: 6px; letter-spacing: .04em; }
.vis .eq { font-size: 1.7rem; font-weight: 700; padding: 6px; letter-spacing: .02em; }
.vis .verbal { margin: 0; font-size: 1.15rem; padding: 4px 6px; text-align: left; }
.vis .pairs { font-size: 1.25rem; font-weight: 700; padding: 4px; word-spacing: .15em; }
table.data { border-collapse: collapse; margin: 0 auto; font-size: 1.2rem; max-width: 100%; }
table.data th, table.data td { border: 2px solid #8e7d60; padding: 6px 14px; min-width: 52px; text-align: center; }
table.data th { background: #ead9b5; font-weight: 700; text-align: left; white-space: nowrap; }
table.data td { background: #fff9ea; font-weight: 700; }
svg.graph { width: 100%; max-width: 400px; height: auto; display: block; margin: 0 auto; }
svg.graph.mini { max-width: 190px; }
svg.mapping { width: 100%; max-width: 280px; height: auto; display: block; margin: 0 auto; }
svg .gr { stroke: #e0d3b4; stroke-width: 1; }
svg .frame { fill: none; stroke: #8e7d60; stroke-width: 1.5; }
svg .ax { stroke: #1c1814; stroke-width: 2.2; }
svg .ln { stroke: var(--ember); stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; fill: none; }
svg .ln.thin { stroke-width: 2.4; stroke: #6b5a44; }
svg .ahp { fill: #6b5a44; }
svg .dt { fill: var(--ink); stroke: var(--cream); stroke-width: 1.5; }
svg .tk { font: 700 11px var(--body); fill: #4a3f30; }
svg .ttl { font: 700 12px var(--body); fill: #4a3f30; }
svg .lb { font: 700 12px var(--body); fill: var(--ink); paint-order: stroke; stroke: #fbf6ea; stroke-width: 3px; }
svg .tl { font: 700 12px var(--body); fill: var(--ember-dark); paint-order: stroke; stroke: #fbf6ea; stroke-width: 3px; }
svg .tri { fill: rgba(232,107,42,.14); stroke: var(--ember-dark); stroke-width: 2; stroke-dasharray: 6 4; }
svg .oval { fill: #fff9ea; stroke: #8e7d60; stroke-width: 2; }
svg .mv { font: 700 17px var(--body); fill: var(--ink); }

.choices { display: grid; gap: 10px; grid-template-columns: 1fr; }
.choice { position: relative; display: flex; align-items: center; gap: 12px; text-align: left; min-height: 62px; padding: 10px 14px; background: #fffaf0; color: var(--ink); border: 3px solid #1c1814; border-radius: 14px; font-size: 1.15rem; font-weight: 700; cursor: pointer; }
.choice:hover:not(:disabled) { background: #ffe9d2; border-color: var(--ember-dark); }
.choice:disabled { cursor: default; opacity: 1; }
.choice .letter { flex: 0 0 34px; height: 34px; border-radius: 50%; background: var(--ink); color: var(--cream); display: grid; place-items: center; font-family: var(--display); font-weight: 800; }
.choice .ctext { flex: 1; overflow-wrap: anywhere; }
.choice .eqc { font-size: 1.3rem; }
.choice .cvis { flex: 1; display: block; }
.choice .cvis .vis { padding: 4px; background: #fbf6ea; border-width: 1px; }
.choice .cvis table.data { font-size: .95rem; }
.choice .cvis table.data th, .choice .cvis table.data td { padding: 3px 8px; min-width: 30px; }
.choice .mark { flex: 0 0 24px; font-size: 1.5rem; font-weight: 800; text-align: center; }
.choice.right { background: #d9efd8; border-color: var(--good); }
.choice.right .mark { color: var(--good); }
.choice.wrong { background: #f8d9d0; border-color: var(--bad); }
.choice.wrong .mark { color: var(--bad); }
.choice:disabled:not(.right):not(.wrong) { opacity: .55; }
.choices.two-col { grid-template-columns: 1fr 1fr; }
.choice.has-vis { flex-direction: column; align-items: stretch; gap: 6px; }
.choice.has-vis .letter { align-self: flex-start; }
.choice.has-vis .mark { position: absolute; right: 10px; top: 8px; }
@media (min-width: 640px) {
  .choices:not(.two-col) { grid-template-columns: 1fr 1fr; }
  .choices:not(.two-col) .choice.long { grid-column: 1 / -1; }
}
@media (max-width: 600px) { .choices.two-col.tables { grid-template-columns: 1fr; } }
.choice { min-width: 0; }
.choice .cvis { min-width: 0; overflow-x: auto; }
@media (max-width: 480px) {
  body { font-size: 17px; }
  .choices.two-col { gap: 8px; }
  .choice { padding: 8px 10px; font-size: 1.05rem; }
  .qcard { padding: 14px 12px 16px; }
}

.reason { margin: 0 0 12px; padding: 10px 14px; border-radius: 12px; font-weight: 400; font-size: 1.05rem; line-height: 1.35; }
.reason.bad { background: #f8d9d0; border: 2px solid var(--bad); color: #3d0f06; }
.reason.good { background: #d9efd8; border: 2px solid var(--good); color: #10361a; font-weight: 700; }
.reason .tap { display: block; margin-top: 4px; font-size: .8rem; font-weight: 700; color: #7a2a18; text-transform: uppercase; letter-spacing: .08em; }

.flash-hit .stage::after, .flash-miss .qcard { animation: pulse .5s ease-out; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(232,107,42,.9); } 100% { box-shadow: 0 0 0 22px rgba(232,107,42,0); } }
.flash-miss .qcard { animation-name: shake; }
@keyframes shake { 0%,100% { transform: none; } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* ---- recap ---- */
.recap { gap: 14px; }
.card { background: var(--cream); color: var(--ink); border-radius: 18px; padding: 16px 18px; border: 3px solid #cdbf9f; }
.card h2 { font-size: 1.3rem; color: var(--ember-dark); margin-bottom: 8px; }
.hitlist { margin: 0; padding-left: 22px; font-weight: 700; font-size: 1.1rem; }
.hitlist .x { color: var(--ember-dark); }
.empty { margin: 0; }
.miss { border-top: 2px dashed #b9a98a; padding-top: 12px; margin-top: 12px; }
.miss:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.miss p { margin: 4px 0; }
.mstem { font-weight: 700; }
.recapvis svg.graph { max-width: 260px; }
.recapvis .vis { padding: 6px; }
.move { background: #d9efd8; border-radius: 10px; padding: 8px 10px; }
.mine { color: #5a2415; }
.fine { text-align: center; color: var(--cream-dim); margin: 0; }
.recap .btns { justify-content: center; margin-top: 4px; }

/* ---- how to play ---- */
dialog.how { max-width: 520px; width: calc(100% - 28px); background: var(--cream); color: var(--ink); border: 4px solid var(--ember); border-radius: 18px; padding: 22px; }
dialog.how::backdrop { background: rgba(0,0,0,.72); }
dialog.how h2 { font-size: 1.8rem; margin-bottom: 8px; }
dialog.how ol { padding-left: 22px; margin: 0 0 10px; }
dialog.how li { margin: 6px 0; }
dialog.how .note { font-size: .9rem; color: #5a4a35; }

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