:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #09101d;
  color: #e9eef8;
  --panel: rgba(22, 33, 54, 0.9);
  --line: #34425d;
  --quest: #e78b35;
  --coqui: #35b87a;
  --accent: #7aa7ff;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at top, #1b2944, #09101d 55%); }
button, input, select { font: inherit; }
button { cursor: pointer; }
.shell { width: min(1720px, calc(100% - 28px)); margin: 0 auto; padding: 24px 0 48px; }
.hero { text-align: center; margin-bottom: 28px; }
.hero h1 { margin: 4px 0 8px; font-size: clamp(2rem, 5vw, 4rem); letter-spacing: -0.04em; }
.hero h1 span { color: var(--accent); font-size: 0.65em; }
.hero p { color: #afbdd3; }
.eyebrow { margin: 0; text-transform: uppercase; letter-spacing: 0.18em; font-size: 0.72rem; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px; box-shadow: 0 18px 50px rgba(0,0,0,.2); }
.grid-two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
form { display: grid; gap: 16px; }
form h2 { margin: 0; }
label { display: grid; gap: 7px; color: #c6d0e0; }
input, select { width: 100%; padding: 11px 12px; color: white; background: #0d1627; border: 1px solid var(--line); border-radius: 9px; }
button { border: 0; border-radius: 10px; padding: 11px 15px; font-weight: 750; color: #07101f; background: var(--accent); }
button:hover:not(:disabled) { filter: brightness(1.1); transform: translateY(-1px); }
button:disabled { cursor: not-allowed; opacity: .42; }
.secondary { color: #dce5f4; background: #2a3851; }
.hidden { display: none !important; }
.status { display: grid; grid-template-columns: repeat(4, minmax(110px, 1fr)) auto; gap: 10px; align-items: center; padding: 12px 16px; }
.status div { display: grid; gap: 2px; }
.status small { color: #8fa1bc; }
.status strong { font-size: .92rem; }
.message { min-height: 42px; margin: 10px 0; padding: 10px 14px; border-radius: 10px; color: #b9c8dd; }
.message[data-kind="error"] { background: #4a1f2a; color: #ffbdc8; }
.message[data-kind="success"] { background: #17412f; color: #aaf2cf; }
.waiting { text-align: center; font-size: 1.2rem; }
.resources { grid-column: 2; grid-row: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; margin: 0; padding: 0; overflow: hidden; }
.resources span { display: flex; align-items: baseline; justify-content: center; gap: 7px; }
.resources span { padding: 10px 12px; background: rgba(8, 16, 30, .58); }
.resources small { color: #93a4be; }
.resources strong { font-size: 1.2rem; }
.battle-toolbar { grid-column: 2; grid-row: 2; display: flex; gap: 10px; align-items: stretch; }
.score { flex: 1; display: flex; justify-content: space-between; align-items: center; gap: 16px; margin: 0; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: rgba(11, 20, 36, .76); }
#battle { display: grid; grid-template-columns: minmax(250px, 290px) minmax(0, 1fr) minmax(280px, 330px); grid-template-rows: auto auto minmax(430px, 1fr) auto; gap: 12px; align-items: start; transition: grid-template-columns .22s ease; }
#battle:has(.game-sidebar.collapsed) { grid-template-columns: 62px minmax(0, 1fr) minmax(280px, 330px); }
.board { grid-column: 2; grid-row: 3; display: grid; grid-template-columns: repeat(10, minmax(78px, 1fr)); gap: 7px; min-height: min(52vh, 560px); overflow-x: auto; padding: 12px; border: 1px solid var(--line); border-radius: 16px; background: rgba(5, 11, 22, .7); box-shadow: inset 0 0 70px rgba(0, 0, 0, .34), 0 20px 55px rgba(0, 0, 0, .22); }
.sector { min-width: 78px; min-height: 100%; display: flex; flex-direction: column; justify-content: space-between; padding: 10px; color: white; border: 2px solid transparent; background: #26334a; }
.sector.questinianos { background: linear-gradient(160deg, #63371f, #282f42); border-color: #9c5b2d; }
.sector.coquinianos { background: linear-gradient(160deg, #16543a, #282f42); border-color: #24815a; }
.sector.neutral { border-color: #4a5870; }
.sector-label { font-size: .8rem; color: #bcc8d9; }
.fortification { align-self: center; filter: drop-shadow(0 2px 4px rgba(0,0,0,.45)); }
.units { display: flex; flex-wrap: wrap; gap: 5px; }
.unit { position: relative; display: inline-grid; place-items: center; min-width: 34px; width: 34px; height: 34px; padding: 0 4px; border-radius: 50%; font-size: .7rem; font-weight: 800; border: 2px solid rgba(255,255,255,.45); }
.unit.questinianos { background: var(--quest); color: #251206; }
.unit.coquinianos { background: var(--coqui); color: #04190f; }
.unit.soldier { grid-template-rows: 34px 13px; width: 34px; height: 47px; padding: 0; border: 0; border-radius: 7px; overflow: hidden; background: transparent; filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .48)); }
.unit-portrait { display: block; width: 34px; height: 34px; object-fit: contain; pointer-events: none; }
.unit-code { display: grid; place-items: center; width: 34px; height: 13px; padding: 0 2px; color: #fff; background: rgba(5, 10, 18, .78); font-size: .5rem; line-height: 1; letter-spacing: .02em; pointer-events: none; }
.unit.spy { border-style: dashed; }
.unit.selected { outline: 3px solid white; outline-offset: 2px; transform: scale(1.08); }
.game-sidebar { grid-column: 1; grid-row: 1 / 5; padding: 10px; max-height: calc(100vh - 86px); overflow: hidden auto; position: sticky; top: 10px; }
.sidebar-toggle { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; margin-bottom: 10px; padding: 8px; }
.sidebar-toggle-icon { font-size: 1.45rem; line-height: 1; }
.sidebar-content { display: grid; gap: 9px; }
.sidebar-submenu { border: 1px solid #34425d; border-radius: 11px; background: rgba(9, 17, 31, .56); overflow: hidden; }
.sidebar-submenu summary { cursor: pointer; padding: 12px 13px; color: #e4ebf7; font-size: .9rem; font-weight: 800; user-select: none; }
.sidebar-submenu[open] summary { border-bottom: 1px solid #34425d; }
.sidebar-submenu > section { padding: 10px; }
.sidebar-submenu > section > h2 { display: none; }
.game-sidebar.collapsed { overflow: hidden; }
.game-sidebar.collapsed .sidebar-content, .game-sidebar.collapsed .sidebar-toggle-label { display: none; }
.game-sidebar.collapsed .sidebar-toggle { margin: 0; }
.roles { max-height: none; overflow: visible; }
.roster { display: grid; gap: 8px; }
.role-card { display: grid; gap: 4px; padding: 10px; background: #111c2f; border: 1px solid #32415c; border-radius: 10px; }
.role-card small, .help { color: #94a5bf; }
.actions { display: grid; gap: 9px; max-height: none; overflow: visible; }
.action-group { display: grid; gap: 8px; padding: 11px; background: #111c2f; border-radius: 10px; }
.action-group p { margin: 0; }
.help { margin: 0; font-size: .84rem; }
.inline-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.end-turn { width: auto; min-width: 150px; margin: 0; color: #08101d; background: #f0aa4f; box-shadow: 0 8px 18px rgba(8, 16, 29, .48); }
.intelligence { grid-column: 3; grid-row: 4; }
.intelligence ol, .history ol { max-height: 180px; overflow: auto; margin-bottom: 0; padding-left: 24px; color: #b8c5d7; }
.intelligence li, .history li { padding: 4px; }
.history { grid-column: 3; grid-row: 1 / 4; margin: 0; min-height: min(52vh, 560px); }
.history ol { max-height: calc(min(52vh, 560px) - 64px); }
.history h2 { margin-top: 0; }

body:has(#game:not(.hidden)) .hero { display: none; }
body:has(#game:not(.hidden)) .shell { padding-top: 14px; }

@media (max-width: 1120px) {
  #battle { grid-template-columns: minmax(220px, 250px) minmax(0, 1fr) minmax(240px, 270px); }
  #battle:has(.game-sidebar.collapsed) { grid-template-columns: 62px minmax(0, 1fr) minmax(240px, 270px); }
}

@media (max-width: 720px) {
  .grid-two { grid-template-columns: 1fr; }
  .status { grid-template-columns: repeat(2, 1fr); }
  .resources { grid-template-columns: repeat(2, 1fr); }
  #battle, #battle:has(.game-sidebar.collapsed) { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; }
  .resources, .battle-toolbar, .board, .game-sidebar, .intelligence, .history { grid-column: 1; grid-row: auto; }
  .battle-toolbar { flex-wrap: wrap; }
  .score { min-width: min(100%, 280px); }
  .end-turn { flex: 1; }
  .board { min-height: 360px; }
  .game-sidebar { position: static; max-height: none; overflow: visible; }
  .game-sidebar .sidebar-content { display: grid; }
  .game-sidebar .sidebar-toggle-label { display: inline; }
  .game-sidebar.collapsed .sidebar-content, .game-sidebar.collapsed .sidebar-toggle-label { display: none; }
  .history { min-height: 260px; }
  .history ol { max-height: 220px; }
}
