/* Responsive layout owns sizes and spacing; battle.css owns fantasy materials. */
:root { --ui-font: 'Segoe UI', Nunito, system-ui, sans-serif; --hud-left: 230px; --hud-right: 210px; --hand-card-width: 164px; }
body { font: 16px/1.45 var(--ui-font); height: auto; min-height: 100dvh; overflow-y: auto; background-attachment: fixed; }
button, input, select { font-family: var(--ui-font); }
button.action-btn, .menu-box .action-btn:not(.menu-btn):not(:disabled), .wiki-modal .action-btn:not(:disabled) { font-family: var(--ui-font); font-weight: 700; letter-spacing: 0; }
button, select, input, summary, [role="button"] { touch-action: manipulation; }
:is(button, input, select, summary, [role="button"]):focus-visible { outline: 3px solid #ffe0a3; outline-offset: 3px; }
[hidden] { display: none !important; }
.game-icon { display: inline-block; width: 22px; height: 22px; flex: 0 0 auto; vertical-align: middle; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; color: #e5c789; pointer-events: none; }
.side-btn-float .game-icon { width: 25px; height: 25px; }
.trait-icons-container { gap: 3px; }
.trait-icons-container > div { display: flex; align-items: center; padding: 2px; }
.trait-icons-container .game-icon { width: 16px; height: 16px; }
.stat-icon .game-icon { width: 19px; height: 19px; }
.hero-poison-badge .game-icon, .poison-badge .game-icon { width: 15px; height: 15px; }
.arena-passive-status .game-icon { width: 14px; height: 14px; }
.fullscreen-overlay, .wiki-modal-overlay { padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); justify-content: safe center; }
.menu-box, .wiki-modal { box-sizing: border-box; max-width: 100%; max-height: calc(100dvh - 24px); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
#main-menu .home-menu { width: min(640px,100%); padding: 24px 36px; }
#main-menu .menu-btn { font-size: 18px; min-height: 52px; padding: 12px 16px; margin: 5px 0; }
#main-menu .primary-menu-btn { min-height: 74px; font-size: 21px; }
.menu-btn small { font-size: 14px; line-height: 1.4; }
#ai-difficulty { width: 100%; }
.filter-select { min-width: 0; font-size: 16px; }
.battle-shell, body:has(#tutorial-panel:not([hidden])) .battle-shell { height: auto; min-height: 100dvh; max-width: 2200px; margin-inline: auto; }
.floating-ui { position: fixed; box-sizing: border-box; padding: 16px; gap: 8px; }
.floating-ui.left { width: var(--hud-left); left: max(0px,calc((100vw - 2200px) / 2)); }
.floating-ui.right { width: var(--hud-right); right: max(0px,calc((100vw - 2200px) / 2)); }
.hero-name { font: 700 16px/1.4 var(--ui-font); letter-spacing: 0; overflow-wrap: anywhere; }
.hero-resource { font-size: 12px; line-height: 1.4; }
.hero-portrait { width: 26px; height: 26px; }
.hero-power-btn { font-size: 14px !important; min-height: 48px; }
.bar-wrapper { flex: 1; min-width: 16px; }
.stat-val-out { flex-shrink: 0; font-variant-numeric: tabular-nums; }
.deck-display.interactive { min-width: 44px; min-height: 44px; }
#surrender-btn { min-height: 44px; font-size: 14px; }
.game-area { display: flex; flex-direction: column; gap: 10px; height: auto; min-height: 100dvh; overflow: visible; padding: 10px 0 12px; }
.board { flex: 0 0 auto; min-height: 200px; padding: 4px var(--hud-right) 4px var(--hud-left); gap: 10px; align-items: stretch; overflow: visible; }
.card, .board .card, .hand .card, .builder-card-wrapper > .card { box-sizing: border-box; }
.board .card, body:has(#tutorial-panel:not([hidden])) .board .card { width: clamp(84px, calc((100vw - var(--hud-left) - var(--hud-right) - 60px) / 5), 184px); height: auto; min-height: 200px; }
.card-name, .board .card-name, .hand .card-name { font: 700 14px/1.3 var(--ui-font); display: block; min-height: 0; padding: 6px 5px; white-space: normal; overflow: visible; text-overflow: clip; -webkit-line-clamp: unset; }
.card-desc-container, .board .card-desc-container, .hand .card-desc-container { display: block; flex: 1 0 auto; min-height: 0; overflow: visible; }
.card-desc-text, .board .card-desc-text, .hand .card-desc-text, .builder-card-wrapper .card-desc-text { display: block; position: static; transform: none; -webkit-line-clamp: unset; overflow: visible; font: 400 13px/1.35 var(--ui-font); padding: 6px 7px; width: 100%; box-sizing: border-box; }
.card-img, .board .card-img, .hand .card-img { flex: 0 0 90px; height: 90px; margin: 5px 5px 0; box-sizing: border-box; }
.board .card-img { height: 64px; flex-basis: 64px; }
.card-stats, .board .card-stats, .hand .card-stats { height: 36px; box-sizing: border-box; padding: 3px 5px; flex-shrink: 0; margin-top: auto; }
.card-cost, .stat { width: 27px; height: 27px; font: 800 18px var(--ui-font); }
.card-state, .board .card-state { top: 77px; left: 6px; right: 6px; font-size: 10px; }
.board .card-state { top: 51px; }
.hand { --hand-space: calc(100vw - var(--hud-left) - var(--hud-right) - 24px); flex: 0 0 auto; min-height: 0; padding: 36px var(--hud-right) 36px var(--hud-left); align-items: stretch; }
.hand.active-hand .card { width: var(--hand-card-width); height: auto; min-height: 240px; }
#player-hand { padding-bottom: 36px; }
.hand.active-hand .card:hover, .hand.active-hand .card:focus-visible, .hand.active-hand .card.selected-for-play { transform: translateY(-12px) rotate(0deg) scale(1.02) !important; }
#enemy-hand, body:has(#tutorial-panel:not([hidden])) #enemy-hand { flex: 0 0 auto; padding-inline: var(--hud-left) var(--hud-right); }
.hand.hidden-hand, #enemy-hand.hidden-hand { align-items: center; padding-top: 0; padding-bottom: 0; min-height: 94px; }
.hand.hidden-hand .card { width: 58px; height: 84px; min-width: 58px; min-height: 84px; max-height: 84px; flex: 0 0 58px; margin-left: -18px; transform: none !important; background-size: 100% 100%; }
.hand.hidden-hand .card:first-child { margin-left: 0; }
#enemy-hand.active-hand { flex: 0 0 auto; }
#tutorial-panel { position: relative; width: min(620px,calc(100% - var(--hud-left) - var(--hud-right) - 20px)); margin: 0; }
#challenge-objective { left: var(--hud-left); right: var(--hud-right); top: 6px; font-size: 13px; }
#selection-panel { right: 12px; left: auto; top: 50%; bottom: auto; transform: translateY(-50%); width: calc(var(--hud-right) - 24px); }
#selection-copy strong { font-family: var(--ui-font); font-size: 15px; }
#selection-copy p { font-size: 14px; }
.selection-actions { flex-wrap: wrap; }
.selection-actions #selection-play { flex-basis: 100%; }
.card-details { max-height: calc(100dvh - 24px); }
.card-details p { font-size: 18px; line-height: 1.55; }
.ability-guide li { font-size: 16px; line-height: 1.5; }

/* Forge: title and setup above, collection left, deck and file actions right. */
.deck-builder-menu-box { display: flex; flex-direction: column; height: calc(100dvh - 24px); width: min(1500px,100%); padding: 22px; overflow: hidden; }
.forge-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.forge-heading > span { color: #c6b89e; font-size: 14px; }
.deck-builder-title { margin: 0; font-size: 28px; }
.hero-choice { display: grid; grid-template-columns: auto minmax(200px,1.2fr) minmax(150px,1fr) minmax(150px,1fr); gap: 8px 12px; align-items: center; margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid #b8955840; }
.hero-choice p { grid-column: 1 / -1; grid-row: 2; margin: 0; font-size: 14px; line-height: 1.4; text-align: left; }
.hero-choice .deck-select { min-width: 0; max-width: none; width: 100%; }
.deck-workspace { display: grid; grid-template-columns: minmax(0,1fr) 292px; gap: 18px; flex: 1; min-height: 0; }
.deck-collection { min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.deck-builder-filters { display: grid; grid-template-columns: minmax(120px,1fr) 140px 200px; gap: 8px; margin-bottom: 8px; }
#filter-search { width: 100%; min-width: 0; }
.deck-builder-filters .filter-select { width: 100%; }
.catalog-toolbar { font-size: 14px; margin-bottom: 8px; }
.deck-builder-instructions { display: none; }
.deck-builder-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(184px,1fr)); align-items: start; align-content: start; gap: 18px; padding: 12px; min-height: 0; max-height: none; flex: 1; overflow-y: auto; margin: 0; }
.builder-card-wrapper { min-width: 0; contain-intrinsic-size: auto 360px; }
.builder-card-wrapper > .card { width: 100%; min-height: 300px; height: auto; transform: none !important; }
.builder-card-wrapper .card-img { height: 112px; flex-basis: 112px; }
.builder-card-wrapper .card-state { display: none; }
.builder-card-controls { display: grid; grid-template-columns: 44px minmax(20px,1fr) 44px 44px; gap: 3px; margin-top: 6px; }
.builder-card-controls button { width: 44px; min-width: 44px; height: 44px; }
.builder-card-controls span { font-size: 14px; }
.deck-summary { display: flex; flex-direction: column; overflow: hidden; padding: 14px; }
.deck-summary > details { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: thin; }
.deck-summary > details > summary { font-size: 18px; }
.forge-library { flex: none; margin-top: 12px; padding-top: 10px; border-top: 1px solid #b8955840; }
.forge-library h3 { margin: 0 0 8px; }
.deck-manager-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0; }
.deck-manager-bar .deck-select { grid-column: 1 / -1; min-width: 0; width: 100%; }
.deck-manager-btn { min-width: 0; margin: 0 !important; min-height: 44px !important; padding: 8px !important; font-size: 14px !important; }
.deck-manager-btn .game-icon { width: 17px; height: 17px; }
.deck-builder-actions { position: static; display: flex; justify-content: flex-end; gap: 12px; padding-top: 14px; margin: 0; background: none; border: 0; flex-shrink: 0; }
.deck-builder-actions .action-btn { min-height: 48px; font-size: 16px; min-width: 200px; }

@media (max-width: 1200px) {
  :root { --hud-left: 176px; --hud-right: 172px; --hand-card-width: 148px; }
  .floating-ui { padding: 10px; }
  .hero-name { font-size: 14px; }
  .player-stats-header { gap: 6px; }
  .deck-display img { width: 30px; height: 44px; }
  .arena-slot { width: 42px; height: 58px; }
  .arena-slot .card { transform: scale(.31); }
  .board .card-cost, .board .stat { width: 23px; height: 25px; font-size: 16px; }
  .board .card-name { font-size: 13px; }
  .board .card-desc-text { font-size: 12px; padding-inline: 4px; }
  .deck-workspace { grid-template-columns: minmax(0,1fr) 250px; }
  .deck-builder-filters { grid-template-columns: minmax(0,1fr) minmax(0,1fr); }
  #filter-search { grid-column: 1 / -1; }
  .hero-choice { grid-template-columns: auto minmax(0,1fr) minmax(0,1fr); }
  .hero-choice #starter-deck-select { grid-column: 2 / -1; }
  .hero-choice p { grid-row: auto; }
}
@media (max-width: 700px), (max-width: 980px) and (orientation: portrait) {
  :root { --hud-left: 0px; --hud-right: 0px; --hand-card-width: 150px; }
  body { background-attachment: scroll; }
  .floating-ui.left { width: 54%; max-width: 260px; }
  .floating-ui.right { width: 43%; max-width: 220px; }
  .floating-ui { position: absolute; padding: 10px; gap: 6px; }
  .floating-ui.top { top: env(safe-area-inset-top,0px); }
  .floating-ui.bottom { bottom: env(safe-area-inset-bottom,0px); }
  .hero-stats-container { padding: 6px 8px; }
  .hero-target-row { min-height: 44px; }
  .hero-resource { font-size: 12px; }
  .hero-power-btn { font-size: 13px !important; min-height: 44px; }
  #end-turn-btn-top, #end-turn-btn-bottom { min-height: 48px; padding: 8px; font-size: 16px; }
  .deck-display img { width: 28px; height: 40px; }
  .game-area { padding: 224px 0 230px; gap: 16px; }
  .side-menu-buttons { top: 164px; right: 10px; left: auto; transform: none; flex-direction: row; gap: 6px; }
  .side-btn-float { width: 44px; height: 44px; }
  .board { padding: 8px 12px; gap: 8px; min-height: 0; overflow-x: auto; overflow-y: hidden; justify-content: safe center; align-items: stretch; scrollbar-width: thin; }
  .board .card, body:has(#tutorial-panel:not([hidden])) .board .card { width: 132px; min-width: 132px; min-height: 240px; height: auto; }
  .board .card-img { height: 80px; flex-basis: 80px; }
  .board .card-state { top: 67px; }
  .board .card-name { font-size: 13px; }
  .board .card-desc-container { display: block; }
  .board .card-desc-text { font-size: 12px; }
  .board .card-cost { display: flex; }
  .board .card-stats { justify-content: space-between; height: 34px; }
  .board .stat, .board .card-cost { width: 24px; height: 26px; font-size: 17px; }
  .board .card, .hand.active-hand .card { touch-action: pan-x pan-y !important; }
  .hand.active-hand, #enemy-hand.active-hand { justify-content: flex-start; gap: 10px; overflow-x: auto; overflow-y: hidden; padding: 14px 12px; min-height: 0; scroll-snap-type: x proximity; scrollbar-width: thin; }
  .hand.active-hand:not(:empty) { pointer-events: auto; }
  .hand.active-hand .card { margin-left: 0; transform: none !important; scroll-snap-align: center; min-height: 270px; }
  .hand.active-hand .card:hover, .hand.active-hand .card:focus-visible, .hand.active-hand .card.selected-for-play { transform: none !important; }
  #player-hand { padding-bottom: 14px; }
  .hand.hidden-hand .card { width: 38px; min-width: 38px; flex-basis: 38px; height: 55px; min-height: 55px; max-height: 55px; margin-left: -10px; }
  .hand.hidden-hand, #enemy-hand.hidden-hand { min-height: 58px; }
  #selection-panel { top: auto; bottom: 230px; left: 10px; right: 10px; width: auto; transform: none; padding: 12px; }
  .selection-actions { flex-wrap: nowrap; }
  .selection-actions #selection-play { flex-basis: auto; }
  #selection-copy p:last-child { display: none; }
  #tutorial-panel { width: calc(100% - 24px); padding: 10px; }
  #challenge-objective { left: 10px; right: 10px; top: 210px; }
  #connection-status { top: 208px; }
  .history-panel { top: 220px; left: 10px; right: 10px; width: auto; max-height: 50dvh; transform: none; }
}
@media (max-width: 900px) {
  .deck-builder-menu-box { display: flex; padding: 14px; overflow-y: auto; height: calc(100dvh - 24px); }
  .forge-heading { display: block; margin-bottom: 12px; }
  .deck-builder-title { font-size: 24px; }
  .hero-choice { flex-shrink: 0; grid-template-columns: 1fr 1fr; }
  .hero-choice label { grid-column: 1 / -1; }
  .hero-choice #hero-select, .hero-choice #starter-deck-select { grid-column: 1 / -1; }
  .hero-choice #thematic-deck-select { grid-column: 1 / -1; }
  .hero-choice p { grid-column: 1 / -1; }
  .deck-workspace { display: flex; flex-direction: column; flex: none; gap: 16px; }
  .deck-collection { flex: none; }
  .deck-builder-grid { flex: none; height: 58dvh; min-height: 320px; max-height: none; grid-template-columns: repeat(auto-fill,minmax(180px,1fr)); }
  .deck-summary { flex: none; max-height: none; overflow: visible; }
  .deck-summary > details { flex: none; overflow: visible; }
  .deck-builder-actions { position: sticky; bottom: -14px; margin: 12px -14px -14px; padding: 10px 14px; background: #170f20f5; border-top: 1px solid #987c50; flex-wrap: wrap; }
  .deck-builder-actions .action-btn { flex: 1; min-width: 0; font-size: 15px; padding: 10px; }
}
@media (max-width: 430px) {
  .fullscreen-overlay, .wiki-modal-overlay { padding: 8px; }
  .menu-box, .wiki-modal, .card-details { max-height: calc(100dvh - 16px); }
  .deck-builder-menu-box { height: calc(100dvh - 16px); padding: 12px; }
  .deck-builder-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; padding: 8px 0; }
  .builder-card-wrapper > .card { min-height: 300px; }
  .builder-card-wrapper .card-name { font-size: 13px; }
  .builder-card-wrapper .card-desc-text { font-size: 12px; }
  .builder-card-controls { grid-template-columns: 44px minmax(0,1fr) 44px; gap: 2px; }
  .builder-card-controls button:last-child { grid-column: 1 / -1; width: 100%; }
  .deck-builder-actions { bottom: -12px; margin-inline: -12px; margin-bottom: -12px; padding: 10px 12px; }
  #main-menu .menu-multiplayer { grid-template-columns: 1fr; gap: 0; }
  #main-menu .menu-multiplayer .menu-btn { font-size: 16px; }
  .card-details { padding: 14px; }
  .card-details p { font-size: 16px; }
}
