:root {
  --ink: #f3e9d2;
  --muted: #b9a988;
  --gold: #e0b354;
  --gold-deep: #9c7426;
  --panel: rgba(20, 15, 10, 0.82);
  --panel-edge: rgba(224, 179, 84, 0.35);
  --side-w: #2c5bb8;
  --side-b: #9c1d1d;
  --serif: "Trajan Pro", "Cinzel", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #120e0a; color: var(--ink); font-family: var(--sans); -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
#stage.pointer { cursor: pointer; }

.loading { position: fixed; inset: 0; display: grid; place-items: center; margin: 0; background: #120e0a; font-family: var(--serif); font-size: 1.3rem; letter-spacing: 0.08em; color: var(--gold); z-index: 50; transition: opacity 0.6s; }
.loading.gone { opacity: 0; pointer-events: none; }

/* ---------- Panels and buttons ---------- */
.panel {
  background: linear-gradient(180deg, rgba(38, 28, 18, 0.92), rgba(16, 12, 8, 0.94));
  border: 1px solid var(--panel-edge);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 230, 170, 0.08);
  padding: 22px;
}
.overlay { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; z-index: 20; background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.25), rgba(0, 0, 0, 0.6)); overflow-y: auto; }
#menu { background: linear-gradient(90deg, rgba(10, 7, 4, 0.82) 0%, rgba(10, 7, 4, 0.55) 55%, rgba(10, 7, 4, 0.1) 100%); place-items: center start; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 18px; }
.actions button, .toolbar button, .letterbox button {
  background: rgba(255, 240, 210, 0.06);
  border: 1px solid var(--panel-edge);
  border-radius: 9px;
  padding: 10px 16px;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.actions button:hover, .toolbar button:hover, .letterbox button:hover { background: rgba(255, 220, 150, 0.14); border-color: var(--gold); }
.actions button:active, .toolbar button:active { transform: translateY(1px); }
button.primary { background: linear-gradient(180deg, #e7bd5e, #a87b2a); color: #1b1206; border-color: #f0cf7e; font-family: var(--serif); font-weight: 700; letter-spacing: 0.06em; padding: 12px 28px; }
button.primary:hover { background: linear-gradient(180deg, #f2cb6e, #b98a33); }

/* ---------- Menu ---------- */
.menu-panel { width: min(560px, 100%); margin-left: max(0px, 4vw); }
.menu-panel h1 { font-family: var(--serif); font-size: clamp(2rem, 6vw, 3.1rem); margin: 0; letter-spacing: 0.06em; color: var(--gold); text-shadow: 0 2px 0 #4a3510, 0 0 30px rgba(224, 179, 84, 0.3); line-height: 1.05; }
.menu-panel h1 span { color: var(--ink); font-size: 0.7em; }
.sub { margin: 4px 0 16px; color: var(--muted); font-family: var(--serif); letter-spacing: 0.05em; }
.group { margin-top: 14px; flex: 1; min-width: 0; }
.group h2 { font-family: var(--serif); font-size: 0.78rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); margin: 0 0 7px; font-weight: 600; }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.row .group { min-width: 220px; }
.hint { font-size: 0.78rem; color: var(--muted); text-align: center; margin: 14px 0 0; }

.themes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.theme-card { position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 3px; text-align: left; padding: 10px 10px 11px; border-radius: 10px; border: 1px solid rgba(255, 240, 210, 0.12); background: rgba(255, 240, 210, 0.04); transition: border-color 0.15s, background 0.15s, transform 0.15s; min-width: 0; }
.theme-card:hover { border-color: var(--panel-edge); transform: translateY(-1px); }
.theme-card.active { border-color: var(--gold); background: rgba(224, 179, 84, 0.12); box-shadow: 0 0 0 1px var(--gold) inset; }
.theme-card strong { font-family: var(--serif); font-size: 1.02rem; letter-spacing: 0.04em; }
.theme-card small { color: var(--muted); font-size: 0.74rem; line-height: 1.25; }
.theme-card em { font-style: normal; font-size: 0.68rem; color: #d8c79e; opacity: 0.8; line-height: 1.25; }
.swatch { width: 100%; height: 34px; border-radius: 6px; margin-bottom: 5px; border: 1px solid rgba(0, 0, 0, 0.4); }
.theme-medieval .swatch { background: linear-gradient(135deg, #2c5bb8 0 33%, #c7ccd4 33% 50%, #4c4b55 50% 67%, #9c1d1d 67%); }
.theme-romans .swatch { background: linear-gradient(135deg, #b3201f 0 33%, #d9b25a 33% 50%, #eee7da 50% 67%, #3a3f8f 67%); }
.theme-spartans .swatch { background: linear-gradient(135deg, #a3161a 0 33%, #c98a3a 33% 50%, #d9bf8c 50% 67%, #2a2a30 67%); }

.seg { display: flex; border: 1px solid rgba(255, 240, 210, 0.14); border-radius: 9px; overflow: hidden; }
.seg button { flex: 1; background: transparent; border: 0; border-right: 1px solid rgba(255, 240, 210, 0.1); padding: 9px 6px; display: flex; flex-direction: column; align-items: center; line-height: 1.1; font-size: 0.9rem; transition: background 0.15s; }
.seg button:last-child { border-right: 0; }
.seg button small { font-size: 0.68rem; color: var(--muted); margin-top: 2px; }
.seg button:hover { background: rgba(255, 220, 150, 0.08); }
.seg button.active { background: rgba(224, 179, 84, 0.22); color: #ffe7b0; box-shadow: inset 0 -2px 0 var(--gold); }

/* ---------- HUD ---------- */
.hud { position: fixed; top: 0; left: 0; right: 0; display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 10px; padding: max(10px, env(safe-area-inset-top)) 14px 0; pointer-events: none; z-index: 5; transition: opacity 0.4s; }
.army { display: flex; gap: 10px; align-items: flex-start; padding: 8px 12px; border-radius: 10px; background: var(--panel); border: 1px solid rgba(255, 240, 210, 0.1); min-width: 0; transition: border-color 0.3s, box-shadow 0.3s; }
.army-b { justify-self: end; text-align: right; }
.army.turn { border-color: var(--gold); box-shadow: 0 0 18px rgba(224, 179, 84, 0.35); }
.banner { flex: none; width: 12px; height: 38px; border-radius: 2px 2px 6px 6px; background: var(--side-w); box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.25); }
.army-b .banner { background: var(--side-b); }
.army-name { font-family: var(--serif); font-size: 0.95rem; letter-spacing: 0.03em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.army-tag { font-size: 0.72rem; color: var(--muted); }
.captured { min-height: 1.2em; font-size: 1.05rem; line-height: 1.2; letter-spacing: -0.05em; }
.captured b { font-size: 0.75rem; color: var(--gold); letter-spacing: 0; font-weight: 600; }
.cap.of-w { color: #f1ead8; text-shadow: 0 0 2px #000, 0 0 1px #000; }
.cap.of-b { color: #1a1a1a; text-shadow: 0 0 2px rgba(255, 240, 210, 0.9); }
.status { justify-self: center; margin-top: 4px; padding: 8px 18px; border-radius: 999px; background: var(--panel); border: 1px solid var(--panel-edge); font-family: var(--serif); letter-spacing: 0.05em; white-space: nowrap; }

.moves { position: fixed; right: 14px; top: 110px; bottom: 76px; width: 190px; display: flex; flex-direction: column; background: var(--panel); border: 1px solid rgba(255, 240, 210, 0.1); border-radius: 10px; padding: 10px 12px; z-index: 4; transition: opacity 0.4s; }
.moves h3 { margin: 0 0 6px; font-family: var(--serif); font-size: 0.78rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.moves ol { margin: 0; padding: 0 0 0 2.2em; overflow-y: auto; font-size: 0.86rem; flex: 1; scrollbar-width: thin; }
.moves li { padding: 2px 0; color: var(--muted); }
.moves li span { display: inline-block; min-width: 4.2em; color: var(--ink); }
.moves.toggled { display: none; }
@media (min-width: 760px) and (max-width: 1099px) {
  .moves { display: none; }
  .moves.toggled { display: flex; }
}

.toolbar { position: fixed; left: 50%; bottom: max(12px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; gap: 6px; padding: 6px; background: var(--panel); border: 1px solid rgba(255, 240, 210, 0.1); border-radius: 12px; z-index: 5; transition: opacity 0.4s; max-width: calc(100% - 24px); overflow-x: auto; }
.toolbar button { padding: 8px 12px; font-size: 0.86rem; white-space: nowrap; }

body.in-menu .hud, body.in-menu .toolbar, body.in-menu .moves { opacity: 0; pointer-events: none; }
body.in-fight .hud, body.in-fight .toolbar, body.in-fight .moves { opacity: 0; pointer-events: none; }

/* ---------- Cutscene letterbox ---------- */
.letterbox { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.letterbox .bar { position: absolute; left: 0; right: 0; height: 0; background: #000; transition: height 0.5s ease; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.letterbox .top { top: 0; }
.letterbox .bottom { bottom: 0; gap: 18px; }
.letterbox.on .bar { height: 11vh; }
.letterbox.on .bottom { pointer-events: auto; }
#duelTitle { font-family: var(--serif); letter-spacing: 0.12em; text-transform: uppercase; font-size: clamp(0.8rem, 2.2vw, 1.15rem); color: var(--gold); }
.letterbox button { padding: 6px 12px; font-size: 0.8rem; background: rgba(255, 255, 255, 0.06); }

/* ---------- Promotion and game over ---------- */
.promo-panel, .go-panel { text-align: center; width: min(460px, 100%); }
.promo-panel h2, .go-panel h2 { font-family: var(--serif); color: var(--gold); letter-spacing: 0.06em; margin: 0 0 14px; }
.go-panel h2 { font-size: 2.3rem; }
.go-panel p { color: var(--ink); margin: 0; }
.promo-choices { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.promo-choices button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 4px; border-radius: 10px; border: 1px solid var(--panel-edge); background: rgba(255, 240, 210, 0.05); }
.promo-choices button:hover { border-color: var(--gold); background: rgba(224, 179, 84, 0.14); }
.promo-choices span { font-size: 2.2rem; line-height: 1; color: #f1ead8; text-shadow: 0 0 3px #000; }
.promo-choices button.dark span { color: #1a1a1a; text-shadow: 0 0 3px rgba(255, 240, 210, 0.9); }
.promo-choices small { font-size: 0.7rem; color: var(--muted); }

.toast { position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%) scale(0.8); font-family: var(--serif); font-size: clamp(2.2rem, 8vw, 4.5rem); color: var(--gold); text-shadow: 0 3px 0 #4a1a10, 0 0 40px rgba(255, 80, 40, 0.6); letter-spacing: 0.08em; opacity: 0; pointer-events: none; z-index: 30; white-space: nowrap; }
.toast.small { font-size: clamp(1.2rem, 4vw, 1.8rem); text-shadow: 0 2px 0 #3a2a10; }
.toast.show { animation: toast 1.6s ease forwards; }
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1.6); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(0.95); }
}

/* ---------- Small screens ---------- */
@media (max-width: 759px) {
  #menu { place-items: center; background: rgba(10, 7, 4, 0.7); }
  .menu-panel { margin-left: 0; padding: 18px 16px; }
  .themes { grid-template-columns: 1fr; }
  .theme-card { flex-direction: row; flex-wrap: wrap; align-items: center; column-gap: 10px; }
  .theme-card .swatch { width: 44px; height: 30px; margin: 0; }
  .theme-card small { flex-basis: calc(100% - 60px); margin-left: 54px; margin-top: -6px; }
  .theme-card em { display: none; }
  .row { gap: 0; }
  .row .group { min-width: 100%; }
  .hud { grid-template-columns: 1fr 1fr; padding: max(8px, env(safe-area-inset-top)) 8px 0; gap: 6px; }
  .status { grid-column: 1 / -1; grid-row: 2; font-size: 0.85rem; padding: 6px 14px; margin-top: 0; }
  .army { padding: 6px 8px; gap: 6px; }
  .army-name { font-size: 0.8rem; }
  .banner { width: 8px; height: 30px; }
  .moves { display: none; top: auto; bottom: 74px; left: 8px; right: 8px; width: auto; height: 30vh; }
  .moves.toggled { display: flex; }
  .toolbar button { padding: 8px 9px; font-size: 0.8rem; }
}

/* The war room: a restrained, tactile frame for the battlefield. */
:root {
  --ink: #f1e9da;
  --muted: #aa9e89;
  --gold: #d5b77c;
  --panel: rgba(19, 21, 20, 0.88);
  --panel-edge: rgba(211, 183, 124, 0.3);
}
#menu {
  background: linear-gradient(90deg, rgba(12, 16, 16, .96) 0%, rgba(12, 16, 16, .88) 39%, rgba(12, 16, 16, .24) 75%, rgba(12, 16, 16, .12) 100%);
  padding: 24px clamp(24px, 5vw, 80px);
}
.menu-panel {
  width: min(590px, 100%);
  margin: 0;
  padding: clamp(25px, 3vw, 42px);
  border: 1px solid rgba(211, 183, 124, .23);
  border-radius: 2px;
  background: linear-gradient(135deg, rgba(30, 35, 33, .96), rgba(14, 17, 17, .96));
  box-shadow: 0 24px 80px #0009, inset 0 0 0 5px rgba(211, 183, 124, .035);
}
.eyebrow { display:flex; align-items:center; gap:12px; color:#a99776; font-size:.58rem; letter-spacing:.22em; font-weight:700; }
.eyebrow span:nth-child(2) { font-size:1rem; color:var(--gold); }
.menu-panel h1 { margin: 16px 0 8px; color:#f4e8cf; font-size:clamp(2.6rem, 5vw, 4.2rem); font-weight:400; letter-spacing:-.035em; text-shadow:none; }
.menu-panel h1 span { color:var(--gold); font-size:.62em; font-style:italic; }
.sub { color:var(--gold); font-family:var(--sans); font-size:.62rem; font-weight:700; letter-spacing:.19em; margin:0; }
.sub span { padding:0 5px; }
.menu-intro { color:#c5bcaa; font-family:var(--serif); font-size:1rem; margin:14px 0 24px; }
.group { margin-top:18px; }
.group h2 { color:#a99b81; font-family:var(--sans); font-size:.62rem; letter-spacing:.18em; margin-bottom:9px; }
.themes { gap:7px; }
.theme-card { min-height:116px; padding:11px; border-radius:2px; background:rgba(255,255,255,.025); border-color:rgba(219,210,190,.13); }
.theme-card:hover { transform:translateY(-2px); background:rgba(255,255,255,.06); }
.theme-card.active { background:rgba(202,170,110,.1); border-color:#b99a62; box-shadow:inset 0 -2px #cbaa6d; }
.theme-card strong { font-size:1rem; font-weight:400; letter-spacing:.02em; }
.theme-card small { font-size:.69rem; color:#b5ac9b; }
.theme-card em { display:none; }
.swatch { height:23px; border-radius:1px; opacity:.8; }
.seg { border-radius:2px; border-color:rgba(219,210,190,.15); }
.seg button { min-height:39px; font-size:.78rem; color:#c5bdad; }
.seg button.active { background:rgba(204,176,122,.14); color:#f3e4c5; box-shadow:inset 0 -2px #cbaa6d; }
.actions { justify-content:flex-start; margin-top:24px; }
.actions button, .toolbar button, .letterbox button { border-radius:2px; }
button.primary { background:#d0b17a; border-color:#d0b17a; color:#191b19; font-family:var(--sans); font-size:.73rem; letter-spacing:.14em; text-transform:uppercase; padding:15px 22px; }
button.primary:hover { background:#e6cb99; }
button.primary span { margin-left:18px; font-size:1rem; }
.hint { margin-top:20px; padding-top:16px; border-top:1px solid rgba(211,183,124,.15); color:#8e897d; text-align:left; font-size:.7rem; line-height:1.5; }
.hud { padding:18px 22px 0; }
.army { min-width:195px; border-radius:2px; padding:11px 14px; background:rgba(18,22,21,.87); }
.army.turn { border-color:rgba(211,183,124,.65); box-shadow:0 8px 24px #0005; }
.banner { width:5px; height:35px; border-radius:0; box-shadow:none; }
.army-name { font-size:1rem; }
.army-tag { color:#b6ad9b; font-size:.68rem; letter-spacing:.06em; }
.status { border-radius:2px; background:rgba(18,22,21,.88); font-size:.85rem; padding:10px 20px; }
.toolbar { border-radius:3px; background:rgba(18,22,21,.9); padding:5px; gap:2px; }
.toolbar button { background:transparent; border-color:transparent; color:#ddd3c1; }
.toolbar button:hover { background:rgba(211,183,124,.1); }
.moves { border-radius:2px; background:rgba(18,22,21,.88); }
.moves h3 { font-family:var(--sans); font-size:.65rem; }
.panel:not(.menu-panel) { border-radius:2px; background:linear-gradient(135deg, #252c29, #111514); }
button:focus-visible { outline:2px solid #f0d498; outline-offset:2px; }
@media (max-width:759px) {
  #menu { padding:16px; background:rgba(10,14,13,.8); }
  .menu-panel { padding:24px 20px; margin:auto; }
  .menu-panel h1 { font-size:2.8rem; }
  .menu-intro { margin-bottom:12px; }
  .themes { grid-template-columns:repeat(3, 1fr); }
  .theme-card { min-height:90px; display:flex; flex-direction:column; align-items:flex-start; gap:3px; }
  .theme-card .swatch { width:100%; height:18px; }
  .theme-card small { flex-basis:auto; margin:0; font-size:.62rem; }
  .row { gap:10px; flex-wrap:nowrap; }
  .row .group { min-width:0; }
  .army { min-width:0; }
  .hud { padding:8px; }
}
@media (max-width:480px) {
  .row { flex-wrap:wrap; gap:0; }
  .row .group { min-width:100%; }
  .menu-panel h1 { font-size:2.4rem; }
}

/* Illustrated faction portraits; the canvas remains the live board preview. */
.theme-card { min-height: 186px; padding: 0 0 10px; overflow: hidden; gap: 4px; }
.theme-card .swatch { display:block; flex:none; width:100%; height:115px; margin:0 0 5px; border:0; border-radius:0; opacity:.9; background-image:linear-gradient(0deg, rgba(16,19,18,.45), transparent 55%), url('../assets/art/armies.png'); background-size:100% 100%, 300% auto; background-repeat:no-repeat; }
.theme-medieval .swatch { background-position:center, left center; }
.theme-romans .swatch { background-position:center, center center; }
.theme-spartans .swatch { background-position:center, right center; }
.theme-card strong, .theme-card small { margin: 0 10px; }
.theme-card:hover .swatch, .theme-card.active .swatch { opacity:1; }
@media (max-width:759px) {
  .theme-card { min-height:130px; padding:0 0 8px; }
  .theme-card .swatch { width:100%; height:70px; margin:0 0 4px; }
  .theme-card strong, .theme-card small { margin:0 7px; }
}
