/* Phase 1 presentation layer. Gameplay state and resolution stay in game.js. */
:root {
  --dd-ink: #0b1322;
  --dd-panel: #17273d;
  --dd-edge: #40536a;
  --dd-cyan: #5fe5ff;
  --dd-pink: #ff638c;
  --dd-gold: #ffcf60;
  --dd-slime: #a7e55b;
  --dd-copy: #d1dfed;
}
body { font-family: 'Trebuchet MS', 'Segoe UI', sans-serif; background: var(--dd-ink); }
button { font-family: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--dd-cyan); outline-offset: 3px; }
.jellykid-home-tag { border-color: #82b553; background: #101d29; }
body:has(#game-screen:not(.hidden)) .jellykid-home-tag { display: none; }
#title-party { position: absolute; left: clamp(20px, 5vw, 90px); top: 50%; transform: translateY(-50%); width: clamp(190px, 21vw, 300px); padding: 16px; border: 3px solid #596b7c; border-radius: 18px; background: linear-gradient(#1c3044ed, #0d182aef); box-shadow: 0 5px 0 #06101b, 0 20px 45px #0007; }
#title-party h2 { font-family: Georgia, serif; color: var(--dd-gold); font-size: 21px; margin: 0 0 16px; }
.title-hero { display: flex; align-items: center; gap: 10px; margin: 9px 0; padding: 9px; border: 1px solid #54718b; border-radius: 10px; background: #152a42; }
.title-hero img { width: 56px; height: 56px; object-fit: contain; background: radial-gradient(#4488ab, #1a2e47); border: 1px solid #689abb; border-radius: 8px; }
.title-hero strong { font-size: 13px; line-height: 1.3; }
.title-hero small { display: block; font-size: 10px; color: #a4c6dc; margin-top: 5px; }

/* Menu art is a backdrop. Every label and control remains live HTML. */
#title-screen {
  padding: 24px;
  background: linear-gradient(90deg, #06132135, #0713217a 50%, #06132135),
    url('Assets/Titles and Maps/Forest-Menu-Phase1.png') center / cover;
  overflow: auto;
  justify-content: safe center;
}
#title-logo { width: min(400px, 55vw); max-height: 24vh; margin: 0 0 4px; }
#title-screen .subtitle { margin: 0 0 12px; color: #b9f3ff; font-size: 14px; letter-spacing: .08em; text-shadow: 0 2px 4px #000; }
#title-screen .menu {
  width: min(380px, 88vw); margin: 0; gap: 10px;
  padding: 14px; border: 3px solid #53647a; border-radius: 20px;
  background: linear-gradient(160deg, #23374af5, #0d1726f7);
  box-shadow: 0 6px 0 #030b15, 0 22px 50px #0009, inset 0 0 0 2px #0a1326;
  position: relative;
}
#title-screen .menu::before, #panel-left::after {
  content: ''; position: absolute; top: -4px; left: 26px; width: 50px; height: 10px;
  border-radius: 3px 4px 12px 12px; background: linear-gradient(#c7fa74, #69ad34);
  box-shadow: 16px 5px 0 -2px #80c444; pointer-events: none;
}
#title-screen .menu button {
  min-height: 40px; padding: 8px 18px; text-align: left;
  font-size: 17px; font-weight: 800; color: #def4ff;
  border: 2px solid #527594; border-radius: 10px;
  background: linear-gradient(#263c58, #12243c); box-shadow: 0 3px 0 #030a14, inset 0 1px 0 #ffffff20;
}
#title-screen .menu button::after { content: '\203a'; float: right; color: #8adaf1; }
#title-screen .menu #btn-play { min-height: 56px; font-size: 23px; color: #291a0a; border-color: #ffe39c; background: linear-gradient(#ffdc75, #e8a32f); box-shadow: 0 4px 0 #8b581c, 0 0 20px #ffc64a30; }
#title-screen .menu #btn-play::after { color: #553613; }
#title-screen .menu button:hover { filter: brightness(1.15); transform: translateY(-1px); }
#title-screen .menu #btn-iso-prototype { font-size: 12px; min-height: 36px; color: #aabdd1; border-color: #394f68; }
#title-screen .version { position: static; margin: 12px 0 0; color: #b9cbda; font-size: 11px; text-shadow: 0 2px 3px #000; }
#title-mode-note { max-width: 420px; margin: 14px 0 0; font-size: 11px; line-height: 1.4; }

/* Connected dungeon HUD. */
#game-screen {
  background: radial-gradient(ellipse at 50% 40%, #224b4960, transparent 65%),
    repeating-linear-gradient(135deg, #ffffff02 0 2px, transparent 2px 24px), #0b1625;
  height: 100dvh;
}
#hud-top {
  flex: 0 0 auto; min-height: 78px; padding: 8px 18px;
  grid-template-columns: minmax(180px, 230px) minmax(160px, 1fr) minmax(130px, 240px) auto;
  grid-template-rows: auto auto; column-gap: 20px; row-gap: 3px;
  border-bottom: 3px solid #425267; background: linear-gradient(#223146, #101c2e);
  box-shadow: 0 4px 0 #030b14, inset 0 -1px 0 #94a7bd30;
}
.battle-brand { grid-column: 1; grid-row: 1 / 3; display: flex; align-items: center; gap: 8px; text-decoration: none; }
.battle-progress { grid-column: 2; grid-row: 1 / 3; min-width: 0; }
#battle-stage-label { display: block; font-size: 17px; color: #fff0c7; margin-bottom: 3px; }
.battle-brand img { width: 98px; height: 62px; object-fit: contain; }
.battle-brand span { font-size: 11px; font-weight: 900; color: var(--dd-cyan); letter-spacing: .04em; }
.battle-brand small { display: block; color: #a9bfcd; font-weight: 400; font-size: 10px; margin-top: 4px; }
#turn-indicator { grid-column: 2; grid-row: 1; font-size: 13px; }
#round-counter { grid-column: 2; grid-row: 2; text-align: left; color: #b5cadf; font-size: 12px; }
#battle-objective { grid-column: 3; grid-row: 1 / 3; padding: 9px 14px; border: 2px solid #ad8537; border-radius: 12px; background: #0a1524; }
#battle-objective small { display: block; color: var(--dd-gold); font-size: 10px; font-weight: 900; letter-spacing: .14em; text-transform: uppercase; }
#battle-objective strong { display: block; margin-top: 4px; font-size: 13px; }
#hud-settings { grid-column: 4; grid-row: 1 / 3; }
.hud-top-button { border: 2px solid #64758b; background: linear-gradient(#2e4058, #15243b); border-radius: 10px; min-height: 44px; padding: 8px 12px; font-size: 11px; }
#game-area { min-height: 0; position: relative; padding: 14px; gap: 14px; }
#board-stage-area { min-width: 0; min-height: 0; gap: 8px; }
#board-stage-inner { min-height: 0; }
canvas#grid { border: 0; outline: 2px solid #b9cf80; border-radius: 3px; box-shadow: 0 0 0 5px #1b2b35, 0 0 0 8px #536576, 0 0 0 10px #263c34, 0 16px 30px #0007; }
#unit-info { min-width: 0; width: 100%; max-width: 100%; min-height: 42px; font-size: 12px; border: 2px solid #5d7390; border-radius: 12px; background: linear-gradient(#243650, #152337); box-shadow: 0 3px 0 #07111d; }
#unit-info .turn-flow-end-button { color: #2b1c08; background: linear-gradient(#ffe18c, #eab147); border: 1px solid #fff0b1; border-radius: 7px; font-weight: 900; min-height: 28px; }
.side-panel { background: linear-gradient(160deg, #24344b, #111d30); border: 2px solid #485c76; border-radius: 16px; box-shadow: 0 5px 0 #06101c, inset 0 0 0 2px #0a1728; }
#panel-left, #panel-right { position: relative; padding: 12px; }
#panel-left { border-color: #397b99; }
#panel-right { border-color: #895066; }
.side-panel-header { margin-bottom: 4px; border: 0; padding: 0; }
.panel-title-button { min-height: 42px; background: linear-gradient(#263d58, #14263f); border: 2px solid #4b7897; color: #d7f7ff; letter-spacing: .07em; font-size: 13px; box-shadow: 0 3px 0 #08121f; }
#panel-right .panel-title-button { border-color: #9e526b; color: #ffdce7; background: linear-gradient(#493044, #281c31); }
#red-roster, #blue-roster { gap: 9px; padding: 3px 2px 5px; scrollbar-gutter: auto; }
.roster-unit { position: relative; flex: 0 0 auto; padding: 10px; gap: 5px; border: 2px solid #40516c; border-radius: 12px; background: linear-gradient(130deg, #2c3b55, #17243b); box-shadow: 0 3px 0 #091320; }
.roster-unit .unit-label { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 800; line-height: 1.25; color: #f1f7ff; }
.roster-unit .unit-badge, .roster-unit .unit-badge-fallback { width: 48px; height: 48px; flex: 0 0 48px; border: 2px solid #479ec5; border-radius: 10px; background: radial-gradient(#3f95bc, #132b47); object-fit: contain; }
#blue-roster .roster-unit { background: linear-gradient(130deg, #3c2b41, #211d32); border-color: #674158; }
#blue-roster .unit-badge { border-color: #ba4f71; background: radial-gradient(#a63c60, #37203d); }
.roster-role { display: block; font-size: 10px; color: #9dbedb; font-weight: 400; margin-top: 5px; }
#blue-roster .roster-role { color: #e3aebf; }
.roster-unit .hp-bar { height: 7px; }
.roster-unit .hp-bar-track { border-radius: 6px; background: #050e1c; border: 1px solid #8294ac50; }
.roster-unit .hp-fill { border-radius: 5px; }
.roster-hp-text { font-size: 11px; color: #e1edf8; }
.roster-unit.is-active { border-color: var(--dd-gold); }
.roster-unit.is-selected { border-color: var(--dd-cyan); box-shadow: 0 0 0 2px #5fe5ff25, 0 0 20px #33c6ef38, inset 0 0 18px #5fe5ff12; }
#blue-roster .roster-unit.is-selected { border-color: var(--dd-pink); box-shadow: 0 0 18px #ff638c40; }
.roster-unit.is-selected::before { content: ''; position: absolute; left: -8px; top: 22px; border-top: 8px solid transparent; border-bottom: 8px solid transparent; border-left: 10px solid var(--dd-cyan); }
#panel-initiative { width: 100%; height: auto; max-height: 50%; flex: 0 1 auto; border: 0; border-top: 2px solid #5b4963; padding: 8px 0 0; border-radius: 0; background: transparent; box-shadow: none; overflow: hidden; }
#panel-initiative { order: -1; border-top: 0; border-bottom: 2px solid #5b4963; padding: 0 0 8px; }
#panel-initiative.collapsed { width: 100%; padding: 8px 0 0; }
#panel-initiative:not(.collapsed) { width: 100%; }
#panel-initiative .history-toggle { writing-mode: horizontal-tb; min-height: 36px; padding: 7px; font-size: 11px; border-color: #856c42; background: #111c2d; }
#panel-initiative .history-content { min-height: 0; }
#initiative-log { font-size: 11px; padding: 0 2px; }
.initiative-entry { min-height: 34px; padding: 5px 6px; border-radius: 8px; gap: 6px; }
.initiative-name { font-size: 10px; }
.initiative-entry { grid-template-columns: 20px minmax(0, 1fr) auto; }
.initiative-main, .initiative-name { justify-content: flex-start; }
.initiative-name { gap: 6px; }
.initiative-name .unit-badge, .initiative-name .unit-badge-fallback { width: 24px; height: 24px; flex: 0 0 24px; }
.initiative-name-text { line-height: 1.25; overflow-wrap: anywhere; }
.initiative-roll { min-width: 32px; padding: 3px 4px; font-size: 10px; }
.initiative-rank { width: 20px; height: 20px; font-size: 10px; }
.initiative-roll { font-size: 11px; }

/* The command bar has a permanent home, independent of roster length. */
#hud-bottom { flex: 0 0 auto; padding: 12px 16px; border-top: 3px solid #52627a; background: linear-gradient(#25364c, #101d30); box-shadow: 0 -4px 0 #081321; }
#hud-bottom-center { display: flex; flex-direction: row; flex-wrap: nowrap; align-items: center; gap: 12px; }
#hud-bottom .hud-buttons #btn-rules-toggle, #hud-bottom .hud-buttons #btn-menu { order: 2; }
#selected-unit-card { flex: 1 1 330px; max-width: 460px; min-width: 230px; display: flex; gap: 12px; align-items: center; padding: 8px 12px; border: 2px solid #456b88; border-radius: 14px; background: linear-gradient(120deg, #203950, #112138); }
#selected-unit-card[data-team="blue"] { border-color: #ad5779; background: linear-gradient(120deg, #412a44, #231d33); }
.command-portrait { width: 68px; height: 68px; object-fit: contain; flex: 0 0 68px; background: radial-gradient(#397ba0, #14283f); border: 2px solid #558cad; border-radius: 12px; }
.command-unit-copy { min-width: 0; flex: 1; }
.command-unit-copy h3 { margin-bottom: 3px; font-size: 16px; color: #f0faff; }
.command-unit-copy p { color: #9fcae5; font-size: 11px; margin-bottom: 5px; }
.command-stats { display: flex; gap: 12px; flex-wrap: wrap; color: #a7bdcf; font-size: 10px; }
.command-stats strong { color: #fff0c9; font-size: 13px; margin-left: 3px; }
.command-health { font-size: 11px; color: #aef0b3; margin-bottom: 6px; }
.hud-buttons { display: flex; flex-wrap: nowrap; align-items: center; gap: 10px; }
#hud-bottom .hud-buttons button { min-height: 48px; padding: 10px 14px; border: 2px solid #5c7694; background: linear-gradient(#2e425d, #172a43); border-radius: 12px; font-size: 13px; font-weight: 800; color: #edf5ff; box-shadow: 0 4px 0 #06101e, inset 0 1px 0 #ffffff25; }
#hud-bottom .hud-buttons .command-button, #hud-bottom #btn-ultimate, #hud-bottom #btn-end-turn { min-width: 108px; min-height: 72px; text-align: center; }
.command-button small { display: block; margin-bottom: 6px; font-size: 9px; text-transform: uppercase; letter-spacing: .09em; opacity: .8; }
.command-button strong { font-size: 20px; }
#hud-bottom .hud-buttons .command-move { border-color: #54c9f3; background: linear-gradient(#20618c, #123456); color: #bcefff; }
#hud-bottom .hud-buttons .command-attack { border-color: #e96986; background: linear-gradient(#83354f, #471d35); color: #ffe1e9; }
#hud-bottom #btn-ultimate { border-color: #b58aef; background: linear-gradient(#60428d, #302348); color: #ecdfff; font-size: 18px; }
#hud-bottom #btn-end-turn { border-color: #ffe391; background: linear-gradient(#ffda73, #d89a30); color: #291c0b; font-size: 17px; }
#hud-bottom #btn-ultimate::before, #hud-bottom #btn-end-turn::before { display: block; margin-bottom: 6px; font-size: 9px; text-transform: uppercase; letter-spacing: .09em; opacity: .8; }
#hud-bottom #btn-ultimate::before { content: '03 / Ultimate'; }
#hud-bottom #btn-end-turn::before { content: '04 / Finish'; }
#hud-bottom .hud-buttons button:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.12); }
#hud-bottom .hud-buttons button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #06101e; }
#hud-bottom .hud-buttons button:disabled { filter: saturate(.25); opacity: .45; cursor: not-allowed; box-shadow: none; }
#btn-mobile-select-active { display: none !important; }
#command-instruction { font-size: 10px; color: #e2cd93; margin-top: 6px; line-height: 1.3; }
.command-button.attention { animation: command-attention 1.6s ease-in-out infinite; }
@keyframes command-attention { 50% { box-shadow: 0 0 18px #9fe9ff55, inset 0 0 14px #ffffff10; } }
#choice-actions[data-overlay-mode="initiative"] { top: 83%; }
#choice-actions[data-overlay-mode="initiative"] .choice-button { min-width: 160px; min-height: 38px; padding: 9px 16px; font-size: 14px; background: linear-gradient(#ffda73, #d89a30); color: #291c0b; border-color: #ffe391; box-shadow: 0 4px 0 #805116; }
.command-hp-track { height: 6px; background: #06101c; border-radius: 8px; overflow: hidden; margin-bottom: 5px; }
.command-hp-track span { display: block; height: 100%; background: linear-gradient(90deg, #35cf84, #a2e869); }

/* Dice feedback mirrors the existing animation without owning its timing. */
#combat-readout { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); width: min(430px, 94%); z-index: 3; pointer-events: none; padding: 9px 16px; border: 2px solid var(--dd-gold); border-radius: 12px; background: #101c30f2; text-align: center; box-shadow: 0 6px 20px #0008; }
#combat-readout strong { color: var(--dd-gold); font-size: 16px; }
#combat-readout span { display: block; font-size: 11px; color: #dfebf7; margin-top: 3px; }
#combat-readout[data-outcome="miss"] { border-color: #a4bad5; }
#combat-readout[data-outcome="hit"] { border-color: #8cdeac; }
#combat-readout[data-outcome="crit-hit"], #combat-readout[data-outcome="crit-heal"] { box-shadow: 0 0 24px #ffce6045; }

@media (min-width: 981px) {
  #game-area { display: grid; grid-template-columns: clamp(190px, 17vw, 265px) minmax(0, 1fr) clamp(190px, 17vw, 265px); align-items: stretch; }
  #panel-left { grid-column: 1; grid-row: 1; }
  #board-stage-area { grid-column: 2; grid-row: 1; width: 100%; height: 100%; }
  #panel-right { grid-column: 3; grid-row: 1; }
  #panel-left, #panel-right { width: 100%; height: 100%; max-height: 100%; }
  #panel-guide, #panel-rules, #panel-treasure, #panel-history { position: absolute; right: 22px; top: 18px; z-index: 12; width: min(360px, 90vw); height: calc(100% - 36px); max-height: none; }
  #panel-history.collapsed { position: absolute; right: 25px; bottom: 20px; top: auto; height: 36px; width: 90px; padding: 0; z-index: 13; }
  #panel-history.collapsed .history-toggle { writing-mode: horizontal-tb; min-height: 32px; padding: 7px; font-size: 10px; border: 0; }
  #panel-right { padding-bottom: 58px; }
}
@media (min-width: 981px) and (max-width: 1250px) {
  .battle-brand span { display: none; }
  #hud-top { grid-template-columns: 120px minmax(160px, 1fr) 170px auto; }
  #selected-unit-card { min-width: 210px; padding: 6px 8px; }
  .command-portrait { width: 50px; height: 50px; flex-basis: 50px; }
  #hud-bottom .hud-buttons .command-button, #hud-bottom #btn-ultimate, #hud-bottom #btn-end-turn { min-width: 90px; }
  #hud-bottom .hud-buttons button { padding: 8px 10px; }
  .hud-buttons { gap: 7px; }
}
@media (max-width: 980px) {
  #title-party { display: none; }
  #hud-top { min-height: 62px; padding: 7px 12px; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 3px 10px; }
  .battle-brand { grid-column: 1; }
  .battle-brand img { width: 64px; height: 44px; }
  .battle-brand span, #battle-objective { display: none; }
  #hud-settings { display: block; grid-column: 3; }
  #battle-stage-label { font-size: 13px; margin-bottom: 2px; }
  #turn-indicator { font-size: 11px; }
  #round-counter { font-size: 10px; }
  .hud-top-button { min-height: 38px; padding: 6px 8px; font-size: 9px; }
  #game-area { padding: 10px; justify-content: center; min-height: 0; }
  #board-stage-area { height: 100%; justify-content: center; }
  canvas#grid { max-width: none; max-height: none; }
  #mobile-turn-card { display: none; }
  #unit-info { display: flex; min-height: 36px; padding: 6px 8px; font-size: 10px; }
  #hud-bottom { padding: 8px 10px max(8px, env(safe-area-inset-bottom)); }
  #hud-bottom-center { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
  #selected-unit-card { max-width: none; min-width: 0; width: 100%; padding: 6px 10px; gap: 10px; }
  .command-portrait { width: 42px; height: 42px; flex-basis: 42px; }
  .command-unit-copy h3 { font-size: 13px; }
  .command-unit-copy p { display: none; }
  .command-health { margin-bottom: 3px; font-size: 10px; }
  .command-stats { gap: 10px; font-size: 9px; }
  .command-stats strong { font-size: 11px; }
  .hud-buttons { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  #hud-bottom .hud-buttons button { min-width: 0; min-height: 40px; padding: 7px 4px; font-size: 11px; }
  #hud-bottom .hud-buttons .command-button, #hud-bottom #btn-ultimate, #hud-bottom #btn-end-turn { min-width: 0; min-height: 48px; font-size: 12px; }
  .command-button small { display: none; }
  #hud-bottom #btn-ultimate::before, #hud-bottom #btn-end-turn::before { display: none; }
  .command-button strong { font-size: 14px; }
  #btn-menu { grid-column: auto; }
  #command-instruction { font-size: 9px; }
  #choice-actions[data-overlay-mode="initiative"] { top: 83%; }
  #choice-actions[data-overlay-mode="initiative"] .choice-button { width: auto; }
  #title-logo { width: min(360px, 70vw); max-height: 28vh; }
  #title-screen { padding: 18px 12px; }
  #title-screen .menu { padding: 12px; gap: 8px; }
  #title-screen .menu button { min-height: 40px; font-size: 14px; }
  #title-screen .menu #btn-play { min-height: 52px; font-size: 20px; }
  #title-screen .subtitle { margin-bottom: 12px; font-size: 12px; }
}
@media (max-width: 980px) and (orientation: landscape) {
  #hud-top { min-height: 48px; padding: 4px 10px; }
  .battle-brand img { height: 36px; }
  #game-area { padding: 8px; }
  #hud-bottom { padding: 6px 10px; }
  #hud-bottom-center { grid-template-columns: minmax(190px, 1fr) minmax(360px, 1.5fr); gap: 10px; }
  .hud-buttons { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  #selected-unit-card { min-height: 56px; }
  #command-instruction { display: none; }
  #unit-info { display: none; }
  #title-screen { flex-direction: row; gap: 20px; }
  #title-logo { width: 32vw; max-height: 65vh; }
  #title-screen .subtitle, #title-screen .version { display: none; }
  #title-screen .menu { width: 42vw; gap: 5px; }
  #title-screen .menu button { min-height: 30px; padding: 6px 12px; }
  #title-screen .menu #btn-play { min-height: 42px; }
  .command-hp-track { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  #game-screen *, #title-screen * { animation: none !important; transition: none !important; }
}
