:root { color-scheme: dark; background: #141c25; color: #e9e5d9; font-family: system-ui, sans-serif; }
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { min-height: 100svh; background: radial-gradient(ellipse at 45% 25%, #293844 0, #141c25 75%); }
/* Anchor the board so showing targeting/inspection cards only grows downward. */
main { min-height: 100svh; display: grid; place-items: start center; padding: 12px; }
.game-screen { width: min(100%, max(540px, calc((100svh - 320px) * 1040 / 864))); max-width: 1160px; container-type: inline-size; }
#dungeon { display: block; width: 100%; height: auto; filter: drop-shadow(0 15px 22px #050a1260); }
.game-tray {
  display: grid; grid-template-columns: 170px minmax(0, 1fr); align-items: center; gap: 20px;
  margin: 0 1.5%; padding: 18px 24px; border: 1px solid #46535b;
  border-radius: 14px; background: #1e2a34;
  box-shadow: 0 8px 28px #080e1640, inset 0 1px #ffffff06;
}
.player-stats { min-width: 0; }
.stat-heading { display: flex; justify-content: space-between; gap: 16px; align-items: baseline; margin-bottom: 10px; font-size: 17px; font-weight: 600; }
.turn { font-size: 14px; font-weight: 400; color: #b3bcc0; }
.turn b { color: #e9e5d9; font-variant-numeric: tabular-nums; }
.health { position: relative; overflow: hidden; height: 26px; border-radius: 99px; background: #48363e; }
.health-fill { position: absolute; inset: 0; background: #ac5263; }
.health-value { position: relative; height: 100%; display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 14px; color: #fff5ef; }
.health-value b { font-variant-numeric: tabular-nums; }
.abilities { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; min-width: 0; border-left: 1px solid #42515a; padding-left: 18px; }
.ability { display: grid; align-content: start; justify-items: center; gap: 18px; min-width: 0; border: 0; padding: 4px 0; background: none; font: 500 14px/1.2 system-ui, sans-serif; color: #d7ddda; cursor: default; opacity: 1; }
.bubble { display: grid; place-items: center; position: relative; width: 54px; height: 54px; border-radius: 50%; border: 1px solid #657374; background: #2c3c46; color: #d9d6b9; box-shadow: inset 0 1px #ffffff0d; }
.bubble svg { width: 30px; height: 30px; transform: translateY(-5px); fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.staff .bubble { color: #c3b0e0; background: #39344c; border-color: #756784; }
.fire .bubble { color: #ecb485; background: #493a36; border-color: #8a6854; }
.frost .bubble { color: #a8d8e3; background: #2c414d; border-color: #608794; }
.count, .movement-left { position: absolute; bottom: -14px; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; background: #dec182; color: #253039; border: 2px solid #1e2a34; font-size: 11px; line-height: 1; font-weight: 750; font-variant-numeric: tabular-nums; white-space: nowrap; }
.count { right: -7px; }
.movement-left { left: -7px; background: #c2d3cf; }
@media (max-width: 600px) { main { padding: 6px; } .game-screen { width: 100%; } }

.turn-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; font-size: 14px; color: #b3bcc0; }
.turn-actions b { color: #e9e5d9; }
#end-turn { border: 1px solid #6b705f; border-radius: 6px; background: #36413f; color: #e9d8af; font: 500 14px system-ui; padding: 7px 9px; cursor: pointer; min-height: 36px; }
#end-turn:disabled { opacity: .5; cursor: default; }
#end-turn.turn-exhausted:not(:disabled) { border-color: #eac877; box-shadow: 0 0 0 2px #eac877; animation: end-turn-pulse 1.6s ease-in-out infinite; }
@keyframes end-turn-pulse {
  0%, 100% { box-shadow: 0 0 0 2px #eac87770, 0 0 0 3px #eac87700; }
  50% { box-shadow: 0 0 0 2px #eac877, 0 0 0 7px #eac87725; }
}
@media (prefers-reduced-motion: reduce) { #end-turn.turn-exhausted:not(:disabled) { animation: none; } }
.ability:not(:disabled) { cursor: pointer; }
.ability[aria-pressed="true"] .bubble { border-color: #f4d88e; box-shadow: 0 0 0 3px #eac87730; background: #4b4a37; }
.ability:disabled { opacity: .55; }
button:focus-visible { outline: 2px solid #eac877; outline-offset: 4px; }
#dungeon { touch-action: manipulation; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.result-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.result-actions button { min-height: 44px; font: inherit; color: #e9dfca; background: #2b3b43; border: 1px solid #718082; border-radius: 6px; padding: 10px 12px; cursor: pointer; }
.result-actions #restart, .result-actions #next-dungeon { grid-column: 1 / -1; }
.result-actions button:not([hidden]) { display: flex; align-items: center; justify-content: center; gap: 8px; }
.result-actions button svg { width: 44px; height: 44px; flex: 0 0 44px; }
.result-actions button span { min-width: 0; }
.result-actions button.primary { grid-column: 1 / -1; color: #262720; background: #e5c180; border-color: #f3d799; font-weight: 700; }
@media (max-width: 420px) {
  .result-actions { grid-template-columns: 1fr; }
  .result-art { width: 112px; }
  .run-stats { margin-bottom: 16px; }
}


.fireball .bubble { color: #f6a278; background: #50352f; border-color: #9f674c; }
.potion .bubble { color: #b5d6b7; background: #30443b; border-color: #66866c; }
#targeting:not([hidden]) { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: center; margin: 10px 1.5% 0; padding: 13px 16px; border: 1px solid #665d49; border-radius: 10px; background: linear-gradient(120deg, #2c302e, #202c35); box-shadow: inset 0 1px #ffffff06, 0 4px 12px #080e1620; font-size: 14px; line-height: 1.45; text-align: center; color: #e6c395; }
#target-info { min-width: 0; overflow-wrap: anywhere; }
/* Size the tray against its actual width, including short desktop windows. */
@container (max-width: 660px) {
  .game-tray { grid-template-columns: minmax(0, 1fr); gap: 14px; padding: 14px 12px; }
  .player-stats { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 16px; }
  .stat-heading { margin-bottom: 8px; font-size: 15px; gap: 8px; }
  .health { grid-column: 1; }
  .turn-actions { grid-column: 2; grid-row: 1 / span 2; justify-content: flex-end; margin: 0; }
  .abilities { border-left: 0; border-top: 1px solid #42515a; padding: 14px 0 0; gap: 4px; }
}
@container (max-width: 420px) {
  .bubble { width: 44px; height: 44px; }
  .bubble svg { width: 26px; height: 26px; }
  .ability { font-size: 12px; }
  .turn-actions { gap: 8px; font-size: 13px; }
  #end-turn { padding: 7px; font-size: 13px; }
  .health-value { gap: 4px; font-size: 13px; }
}

#enemy-details:not([hidden]) { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px; margin: 10px 1.5% 0; padding: 8px 12px; border: 1px solid #756b50; border-radius: 10px; background: #1e2a34; font-size: 14px; }
#enemy-name { color: #eed29a; }
#enemy-type { color: #b3bcc0; }
#enemy-health { font-variant-numeric: tabular-nums; }
#close-enemy-details { margin-left: auto; border: 0; border-radius: 6px; background: transparent; color: #e9e5d9; font: 24px system-ui; min-width: 36px; min-height: 36px; cursor: pointer; }
[data-enemy-id] { cursor: pointer; }
[data-enemy-id]:focus-visible { outline: 2px solid #eac877; outline-offset: 3px; }

#run-result { width: min(420px, calc(100% - 28px)); max-height: calc(100svh - 28px); overflow: auto; padding: 24px; border: 1px solid #8a7958; border-radius: 18px; background: #1e2a34; color: #e9e5d9; text-align: center; box-shadow: 0 20px 80px #0009; }
#run-result::backdrop { background: #080e16c9; }
.result-art { width: 144px; margin: 0 auto; }
.result-art svg { display: block; width: 100%; }
#result-title { margin: 10px 0 20px; font-size: 26px; color: #eed29a; }
.run-stats { margin: 0 0 24px; }
.run-stats div { display: flex; justify-content: space-between; gap: 20px; padding: 9px 0; border-bottom: 1px solid #42515a; }
.run-stats dt { color: #bfc8cb; }
.run-stats dd { margin: 0; font-weight: 650; font-variant-numeric: tabular-nums; }
@media (max-height: 600px) { #run-result { padding: 16px; } .result-art { width: 90px; } #result-title { margin: 6px 0 12px; } .run-stats { margin-bottom: 16px; } .run-stats div { padding: 6px 0; } }

#targeting.cast-rejected { color: #f2b4a8; border-color: #8c605b; background: #332d32; }
/* The board uses tile cursors; never draw a focus frame around the entire SVG. */
#dungeon, #dungeon:focus, #dungeon:focus-visible { outline: none; }
[data-enemy-id]:focus:not(:focus-visible) { outline: none; }
.cast-fizzle { transform-box: fill-box; transform-origin: center; animation: spell-fizzle 650ms ease-out forwards; }
@keyframes spell-fizzle { 0% { opacity: .9; transform: scale(.6); } 35% { opacity: 1; } 100% { opacity: 0; transform: scale(1.25); } }
@media (prefers-reduced-motion: reduce) { .cast-fizzle { animation: none; } }

#cast-confirm { flex: 0 0 auto; min-height: 44px; padding: 9px 16px; border: 1px solid #f3d799; border-radius: 8px; background: #e5c180; color: #262720; font: 600 14px system-ui; cursor: pointer; }
#cast-confirm:disabled { opacity: .55; cursor: default; }


#result-tabs:not([hidden]) { display: flex; padding: 4px; gap: 4px; margin: 0 0 18px; border-radius: 10px; background: #14212a; }
#result-tabs button, #comparison-range button, #comparison-retry { font: 600 13px system-ui; color: #bfc8cb; background: transparent; border: 1px solid transparent; border-radius: 7px; padding: 8px; min-height: 44px; cursor: pointer; }
#result-tabs button { flex: 1; }
#result-tabs [aria-selected="true"] { background: #34434b; color: #ffe7a3; box-shadow: 0 1px 4px #0003; }
#run-result.showing-comparisons .result-art { display: none; }
#run-result.showing-comparisons #result-title { margin-top: 0; font-size: 22px; }
#comparison-context { margin: 0 0 12px; color: #dec182; text-align: left; font-size: 13px; }
.comparison-filters { display: grid; grid-template-columns: 1.3fr 1fr; gap: 10px; text-align: left; }
.comparison-filters label { min-width: 0; font-size: 12px; color: #aebcc2; }
.comparison-filters select { display: block; width: 100%; min-height: 44px; margin-top: 5px; padding: 7px; background: #24343e; color: #e9e5d9; border: 1px solid #4e616b; border-radius: 7px; font: 13px system-ui; }
#comparison-range { display: flex; gap: 4px; margin: 14px 0; padding: 3px; background: #14212a; border-radius: 9px; }
#comparison-range button { flex: 1; min-height: 40px; }
#comparison-range [aria-pressed="true"] { background: #dec182; color: #202c31; }
#comparison-range button:hover:not([aria-pressed="true"]), #result-tabs button:hover:not([aria-selected="true"]) { background: #2a3b45; }
#comparison-status, #comparison-own { margin: 10px 0; font-size: 12px; line-height: 1.5; color: #bfc8cb; }
#comparison-status:empty, #comparison-own:empty { display: none; }
#comparison-retry { border-color: #62717b; }
#comparison-table { width: 100%; border-collapse: collapse; text-align: left; margin: 0 0 18px; }
#comparison-table th { padding: 0 10px 8px; color: #aebcc2; font-size: 12px; font-weight: 500; }
#comparison-table td { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 38px; padding: 8px 10px; border-top: 1px solid #ffffff0d; font-size: 15px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
#comparison-table td > span:first-child { min-width: 0; }
#comparison-table .your-run td { background: #dec18212; color: #ffe7a3; border-radius: 6px; }
.your-run-badge { flex-shrink: 0; color: #eed29a; font-size: 11px; font-weight: 600; }
#run-result :focus-visible { outline: 2px solid #ffe7a3; outline-offset: 3px; }
.archer .bubble { color: #c9daa0; background: #344737; border-color: #7b946b; }
.soldier .bubble { color: #bcd9e8; background: #304654; border-color: #7297ae; }
.ability > span:last-child { overflow-wrap: anywhere; text-align: center; }

.game-title { margin: 0 1.5% 12px; color: #dec182; font: 700 clamp(28px, 5vw, 40px)/1.2 Georgia, serif; text-align: center; }
a:focus-visible { outline: 2px solid #eac877; outline-offset: 4px; }
main.enemy-gallery { display: block; max-width: 1080px; margin: auto; padding: 24px; }
.enemy-gallery > a { color: #dec182; display: inline-block; padding: 10px 0; }
.enemy-gallery h1 { font-size: 28px; margin: 16px 0 8px; }
.enemy-gallery p { color: #b3bcc0; line-height: 1.5; }
.enemy-gallery-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr)); gap: 16px; margin-top: 28px; }
.enemy-gallery figure { margin: 0; padding: 16px; border: 1px solid #46535b; border-radius: 14px; background: #1e2a34; text-align: center; }
.enemy-gallery figure svg { width: 100%; max-width: 240px; }
.enemy-gallery h2 { font-size: 18px; margin: 12px 0 8px; }
.enemy-gallery figcaption p { font-size: 14px; margin: 0; }

#player-status { margin: 8px 1.5%; padding: 10px 14px; color: #e7d1ff; background: #342b46; border: 1px solid #8f75af; border-radius: 8px; font-size: 14px; }


.game-menu { display: flex; justify-content: center; margin: 0 0 12px; }
#new-game { border: 1px solid #ae955f; border-radius: 8px; background: #334441; color: #f1dfb6; padding: 10px 24px; font: 600 15px system-ui; cursor: pointer; min-height: 44px; }
#new-game:disabled { opacity: .5; cursor: default; }
#new-game-dialog { width: min(740px, calc(100% - 24px)); max-height: calc(100svh - 24px); overflow-y: auto; padding: clamp(12px, 3vw, 28px); border: 1px solid #8a7958; border-radius: 20px; color: #e9e5d9; background: radial-gradient(ellipse at 50% 20%, #30423f, #19242e 75%); box-shadow: 0 24px 90px #000b; }
#new-game-dialog::backdrop { background: #080e16c9; }
.new-game-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.new-game-heading h2 { margin: 0; color: #e6ce97; font: 700 26px Georgia, serif; }
#close-new-game { border: 0; border-radius: 8px; background: transparent; color: #e9e5d9; font: 28px system-ui; width: 44px; height: 44px; cursor: pointer; }
.dungeon-map { position: relative; margin: 12px 0 24px; }
.dungeon-connections { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.dungeon-connections polyline { fill: none; stroke: #ad945d; stroke-width: 3; stroke-dasharray: 3 7; stroke-linecap: round; stroke-linejoin: round; opacity: .75; }
#dungeon-nodes { position: relative; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 32px 4px; list-style: none; margin: 0; padding: 12px 0 32px; }
#dungeon-nodes li { display: flex; justify-content: center; transform: translateY(var(--node-offset)); }
.dungeon-node { position: relative; width: clamp(44px, 8vw, 58px); height: clamp(44px, 8vw, 58px); border-radius: 50%; border: 2px solid #a18a5d; background: #253a3c; color: #f0dfb6; font: 700 19px Georgia, serif; box-shadow: 0 4px 0 #0e181f, inset 0 0 0 4px #ffffff08; cursor: pointer; }
.dungeon-node.completed { border-color: #92c9ac; }
.dungeon-node:disabled { color: #879393; border-color: #556265; background: #202c32; box-shadow: none; cursor: default; }
.dungeon-lock { display: none; }
.dungeon-node:disabled .dungeon-lock { display: block; position: absolute; right: -4px; bottom: -3px; width: 20px; height: 20px; padding: 2px; background: #19242e; border-radius: 4px; }
.dungeon-node[aria-current="true"] { background: #e0bf7b; color: #1a2b30; border-color: #fff0be; box-shadow: 0 0 0 4px #e0bf7b30, 0 4px 0 #0e181f; }
#class-choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(8px, 2vw, 18px); }
.class-choice { display: grid; justify-items: center; gap: 8px; min-width: 0; padding: 14px 4px; border: 2px solid #52616b; border-radius: 14px; background: #22313c; color: #c5cfd0; font: 600 clamp(13px, 2.5vw, 17px) system-ui; cursor: pointer; }
.class-choice svg { width: clamp(60px, 12vw, 110px); max-width: 100%; height: auto; filter: drop-shadow(0 5px 4px #0006); }
.class-choice[aria-pressed="true"] { border-color: #eac877; color: #ffedbb; background: #3c4036; box-shadow: inset 0 0 0 2px #eac87740, 0 0 18px #eac87718; }
#new-game:focus-visible, #new-game-dialog button:focus-visible { outline: 3px solid #b9e6e8; outline-offset: 3px; }
@media (hover: hover) { #new-game-dialog button:not(:disabled):hover { border-color: #f4d995; background-color: #40504b; } }

/* Scenery review shares the actual game art and palette. */
main.scenery-gallery { display: block; place-items: normal; max-width: 1160px; margin: auto; padding: clamp(16px, 3vw, 36px); }
.scenery-gallery a { color: #dec182; text-underline-offset: 4px; }
#scenery-back { display: inline-block; padding: 12px 0; }
.scenery-gallery header { padding: 28px 0 24px; }
.scenery-gallery .scenery-eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .16em; color: #b9a576; }
.scenery-gallery h1 { margin: 8px 0 12px; color: #e8d9b6; font: 700 clamp(32px, 5vw, 48px) Georgia, serif; }
.scenery-gallery p { margin: 0; color: #bbc4c6; line-height: 1.6; }
#scenery-nav { display: flex; flex-wrap: wrap; gap: 8px 24px; border-top: 1px solid #45535a; border-bottom: 1px solid #45535a; padding: 10px 0; }
#scenery-nav a { padding: 10px 0; font-size: 14px; }
.scenery-gallery section { padding-top: 28px; scroll-margin-top: 20px; }
.scenery-gallery h2 { margin: 10px 0 18px; font: 600 25px Georgia, serif; color: #d7c7a3; }
.scenery-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr)); gap: 16px; }
.scenery-gallery figure { margin: 0; min-width: 0; border: 1px solid #46535b; border-radius: 12px; background: #1e2a34; overflow: hidden; }
.scenery-gallery figure svg { display: block; width: 100%; height: 224px; background: #2d3b43; }
.scenery-gallery figcaption { padding: 18px; border-top: 1px solid #46535b; }
.scenery-gallery h3 { margin: 0 0 6px; font-size: 16px; color: #e1d3b5; }
.scenery-gallery figcaption p { font-size: 14px; }
.scenery-gallery footer { margin: 32px 0 12px; padding-top: 20px; border-top: 1px solid #45535a; color: #a9b5ba; font-size: 14px; line-height: 1.6; }
.scenery-gallery a:focus-visible { outline: 2px solid #eac877; outline-offset: 4px; }

/* Compact tutorial cards sit over the unexplored upper board, leaving targets and controls free. */
#tutorial { position: fixed; z-index: 20; width: min(320px, calc(100vw - 16px)); padding: 17px 42px 17px 18px; border: 1px solid #72bb91; border-radius: 14px; background: linear-gradient(135deg, #243e39, #1b2b33); color: #eff6ed; box-shadow: 0 12px 36px #050d16a8, inset 0 1px #d4ffe51a; }
#tutorial[hidden] { display: none; }
.tutorial-kicker { color: #9cddb5; font-size: 11px; letter-spacing: .12em; font-weight: 700; }
#tutorial h2 { margin: 7px 0; font-size: 18px; line-height: 1.2; }
#tutorial p { margin: 0; font-size: 14px; line-height: 1.5; }
.tutorial-close { position: absolute; top: 3px; right: 3px; width: 40px; height: 40px; border: 0; background: transparent; color: #cbe8d8; font: 26px system-ui; cursor: pointer; }
.tutorial-next { margin-top: 13px; min-height: 40px; padding: 8px 16px; border-radius: 7px; border: 1px solid #a2e7b9; background: #a2e7b9; color: #163327; font: 650 14px system-ui; cursor: pointer; }
button.tutorial-highlight { outline: 3px solid #8affb7; outline-offset: 3px; border-radius: 8px; }
#end-turn.tutorial-highlight { animation: none; box-shadow: 0 0 16px #8affb72b; }
@media (max-width: 600px) {
  #tutorial:not([data-step="intro"]) { position: relative; left: auto !important; top: auto !important; margin: 8px auto 14px; width: calc(100% - 16px); }
}

/* Three permanent class slots, shared by the dungeon path and victory screen. */
.class-stars { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.class-star { display: grid; justify-items: center; align-content: start; gap: 3px; min-width: 0; }
.star-symbol { width: 100%; height: auto; color: #81918f; overflow: visible; }
.star-symbol path { fill: #26333a; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; }
.earned .star-symbol { color: #ffe3a0; filter: drop-shadow(0 1px 3px #f2c15d30); }
.earned .star-symbol path { fill: #e8bf65; }
.class-emblem { display: block; width: 85%; height: auto; max-width: 30px; }
.class-star:not(.earned) .class-emblem { filter: grayscale(1); opacity: .7; }
#dungeon-nodes { row-gap: 24px; }
#dungeon-nodes li { padding-bottom: 56px; }
.dungeon-stars { position: absolute; top: calc(100% + 10px); left: 50%; transform: translateX(-50%); width: clamp(48px, 10vw, 78px); gap: clamp(1px, .5vw, 4px); pointer-events: none; }
#result-star-panel { margin: -8px 0 22px; padding: 12px 16px 16px; border: 1px solid #76613e; border-radius: 12px; background: linear-gradient(145deg, #344039, #202e34); }
#star-award { margin: 0 0 13px; color: #f2d38f; font-size: 15px; line-height: 1.4; font-weight: 600; }
#result-stars { max-width: 260px; margin: auto; gap: 16px; }
#result-stars .star-symbol { width: 38px; }
#result-stars .class-emblem { width: 27px; }
.star-class-name { font: 500 14px/1.3 system-ui, sans-serif; color: #bdc9c7; }
.earned .star-class-name { color: #ffe3a0; }
.newly-earned .star-symbol { animation: star-earned 650ms ease-out both; }
@keyframes star-earned { 0% { transform: scale(.6); opacity: .3; } 65% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .newly-earned .star-symbol { animation: none; } }
