/* ==========================================================================
   Ironcrown — stylesheet
   ========================================================================== */
:root {
  --bg: #12151c;
  --bg2: #1a1f29;
  --panel: #1e2430;
  --panel2: #262d3b;
  --line: #343d4f;
  --text: #e8e2d0;
  --muted: #9aa3b5;
  --gold: #f2c14e;
  --gold-dark: #b8871d;
  --red: #e5534b;
  --green: #57c26b;
  --blue: #4ea1f2;
  --purple: #b07cf2;
  --common: #a8b0bd;
  --rare: #4ea1f2;
  --epic: #b07cf2;
  --legendary: #f2a33a;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --display: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 30% -10%, #232b3b 0%, var(--bg) 60%);
  color: var(--text);
  font: 14px/1.4 var(--font);
  overflow: hidden;
  user-select: none;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ---------- HUD ---------- */
#hud {
  display: flex; align-items: center; gap: 14px;
  padding: 8px 14px;
  background: linear-gradient(180deg, #232a37, #1a1f29);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 12px rgba(0,0,0,.4);
  z-index: 5;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 150px; }
.brand .crown { font-size: 26px; filter: drop-shadow(0 0 6px rgba(242,193,78,.5)); }
.brand b { font-family: var(--display); font-size: 17px; color: var(--gold); display: block; letter-spacing: .5px; }
.brand small { color: var(--muted); font-size: 12px; }

.resources { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; }
.res {
  position: relative; display: flex; align-items: center; gap: 5px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 20px;
  padding: 4px 10px 4px 6px; min-width: 128px; overflow: hidden;
}
.res .fill { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--c, var(--gold)); opacity: .8; transition: width .4s; }
.res .ico { font-size: 17px; width: 22px; text-align: center; }
.res .res-txt { display: flex; align-items: baseline; gap: 1px; }
.res .val { font-weight: 700; font-variant-numeric: tabular-nums; }
.res .cap { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.res.full { border-color: var(--gold); box-shadow: 0 0 8px -2px var(--gold); }
.res .rate { font-size: 11px; color: var(--muted); margin-left: auto; font-variant-numeric: tabular-nums; }
.res .rate.neg { color: var(--red); }
.res.bump .val { animation: bump .35s; }
@keyframes bump { 50% { transform: scale(1.18); color: #fff; } }

.hud-stats { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.chip { background: var(--bg2); border: 1px solid var(--line); border-radius: 16px; padding: 4px 10px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.chip.sync b { color: var(--muted); font-weight: 600; }
.chip.sync.online b { color: var(--green); }
.icon-btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; width: 34px; height: 30px; cursor: pointer; }
.icon-btn:hover { border-color: var(--gold); }

/* ---------- Layout ---------- */
#main { flex: 1; display: flex; min-height: 0; }
#stage-wrap { position: relative; flex: 1; min-width: 0; background: #0d1016; }
#stage { display: block; width: 100%; height: 100%; cursor: pointer; touch-action: none; }
.view-toggle { position: absolute; top: 12px; left: 12px; z-index: 2; display: flex; background: rgba(18,21,28,.85); border: 1px solid var(--line); border-radius: 10px; padding: 3px; backdrop-filter: blur(4px); }
.view-toggle button { background: none; border: 0; padding: 6px 14px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 600; }
.view-toggle button.active { background: var(--gold); color: #2a1d00; }
#placing-hint { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 2; background: rgba(18,21,28,.92); border: 1px solid var(--gold); border-radius: 10px; padding: 7px 14px; font-weight: 600; }
#placing-hint button { margin-left: 10px; }
#tooltip { position: absolute; z-index: 3; pointer-events: none; background: rgba(12,14,20,.94); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 12px; max-width: 240px; }
#tooltip b { color: var(--gold); }

#panel { width: 400px; display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); min-height: 0; }
.tabs { display: grid; grid-template-columns: repeat(5, 1fr); border-bottom: 1px solid var(--line); background: var(--bg2); }
.tabs button { position: relative; background: none; border: 0; padding: 6px 2px 5px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 16px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button span { font-size: 11px; font-weight: 600; }
.tabs button.active { color: var(--gold); border-bottom-color: var(--gold); background: var(--panel); }
.tabs button em { font-style: normal; }
.tabs button i { position: absolute; top: 5px; right: 18px; width: 8px; height: 8px; background: var(--red); border-radius: 50%; }
#panel-body { flex: 1; overflow-y: auto; padding: 14px; }
#panel-body::-webkit-scrollbar { width: 8px; }
#panel-body::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

/* ---------- Panel content ---------- */
h2 { font-family: var(--display); color: var(--gold); font-size: 19px; margin: 0 0 4px; font-weight: 600; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); margin: 18px 0 8px; font-weight: 700; }
h3:first-child { margin-top: 0; }
p { margin: 4px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.card { background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; }
.card.hl { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(242,193,78,.25) inset; }

.btn {
  background: linear-gradient(180deg, #f5cd62, #d9a531); color: #2a1d00; border: 1px solid #a57a18;
  border-radius: 8px; padding: 7px 12px; font-weight: 700; cursor: pointer; white-space: nowrap;
  box-shadow: 0 2px 0 #8a6412;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:active:not(:disabled) { transform: translateY(1px); box-shadow: 0 1px 0 #8a6412; }
.btn:disabled { filter: grayscale(1) brightness(.6); cursor: not-allowed; }
.btn.ghost { background: var(--panel); color: var(--text); border-color: var(--line); box-shadow: none; }
.btn.red { background: linear-gradient(180deg, #ee6b62, #c9423a); color: #fff; border-color: #8f2c26; box-shadow: 0 2px 0 #7a241f; }
.btn.blue { background: linear-gradient(180deg, #6db3f5, #3b86d6); color: #fff; border-color: #2a64a3; box-shadow: 0 2px 0 #214f82; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.block { width: 100%; }

.cost { display: inline-flex; gap: 8px; flex-wrap: wrap; font-size: 12px; font-variant-numeric: tabular-nums; }
.cost span.short { color: var(--red); }

.build-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.build-item {
  background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px; cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 4px; min-height: 92px;
}
.build-item:hover:not(.locked) { border-color: var(--gold); transform: translateY(-1px); }
.build-item.locked { opacity: .45; cursor: not-allowed; }
.build-item .bi-top { display: flex; align-items: center; gap: 6px; }
.build-item .bi-ico { font-size: 20px; }
.build-item b { font-size: 13px; }
.build-item .count { margin-left: auto; font-size: 11px; color: var(--muted); }
.build-item .desc { font-size: 11px; color: var(--muted); line-height: 1.25; }

.progress { height: 8px; background: #11151c; border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold-dark), var(--gold)); transition: width .25s linear; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.unit-row { display: grid; grid-template-columns: 34px 1fr auto; gap: 8px; align-items: center; }
.unit-ico { font-size: 22px; text-align: center; }
.stats-mini { font-size: 11px; color: var(--muted); }
.queue { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.queue span { background: var(--bg2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; font-size: 11px; }
.queue span.first { border-color: var(--gold); }

/* generals */
.general { display: grid; grid-template-columns: 56px 1fr; gap: 10px; align-items: center; }
.portrait { width: 56px; height: 56px; border-radius: 12px; display: grid; place-items: center; font-size: 30px; background: var(--bg2); border: 2px solid var(--r, var(--common)); box-shadow: 0 0 12px -2px var(--r, transparent); }
.rarity { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; font-weight: 800; color: var(--r); }
.r-common { --r: var(--common); } .r-rare { --r: var(--rare); } .r-epic { --r: var(--epic); } .r-legendary { --r: var(--legendary); }
.stars { color: var(--gold); letter-spacing: 1px; font-size: 12px; }
.stat-bar { display: grid; grid-template-columns: 58px 1fr 30px; gap: 6px; align-items: center; font-size: 11px; margin-top: 3px; }
.stat-bar .track { height: 8px; border-radius: 4px; background: #11151c; overflow: hidden; }
.stat-bar .track i { display: block; height: 100%; border-radius: 4px; }
.stat-bar.atk i { background: linear-gradient(90deg, #a8322b, #ef6a5f); }
.stat-bar.hp i { background: linear-gradient(90deg, #2f8a41, #6ad47d); }
.stat-bar.spd i { background: linear-gradient(90deg, #2b69a8, #6db3f5); }
.stat-bar b { text-align: right; font-variant-numeric: tabular-nums; }
.roster { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.roster .card { margin: 0; text-align: center; padding: 8px; }
.roster .portrait { margin: 0 auto 4px; width: 46px; height: 46px; font-size: 24px; }

/* shop */
.box-card { display: grid; grid-template-columns: 64px 1fr; gap: 12px; align-items: center; }
.box-art { width: 64px; height: 64px; border-radius: 12px; display: grid; place-items: center; font-size: 38px; background: radial-gradient(circle at 50% 40%, var(--glow), transparent 70%), var(--bg2); border: 1px solid var(--line); }
.odds { display: flex; gap: 6px; flex-wrap: wrap; font-size: 11px; margin: 4px 0 6px; }
.odds span { color: var(--r); }

/* alliance */
.emblem { width: 38px; height: 38px; border-radius: 10px 10px 18px 18px; display: grid; place-items: center; font-size: 20px; border: 2px solid rgba(255,255,255,.25); flex: none; }
.member { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.member:last-child { border-bottom: 0; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; }
.chat { max-height: 200px; overflow-y: auto; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 8px; font-size: 12px; display: flex; flex-direction: column; gap: 4px; }
.chat b { color: var(--gold); }
input[type=text], select {
  background: var(--bg2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 7px 10px; font: inherit; width: 100%;
}
input[type=text]:focus { outline: none; border-color: var(--gold); }
input[type=range] { width: 100%; accent-color: var(--gold); }
.swatches { display: flex; gap: 6px; }
.swatches button { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatches button.sel { border-color: #fff; }

/* log */
.log-item { padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; display: grid; grid-template-columns: 48px 1fr; gap: 6px; }
.log-item time { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.log-item.good { color: #b6e8bf; } .log-item.bad { color: #f3b1ac; } .log-item.info { color: var(--text); }

/* ---------- Modals ---------- */
.modal { position: fixed; inset: 0; background: rgba(5,7,10,.72); display: grid; place-items: center; z-index: 50; backdrop-filter: blur(3px); animation: fade .2s; padding: 16px; }
@keyframes fade { from { opacity: 0; } }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; width: min(460px, 100%); max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.6); animation: pop .25s cubic-bezier(.2,1.4,.4,1); }
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
.modal-card .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }

.battle-card { background: #11151c; border: 1px solid var(--line); border-radius: 14px; padding: 12px; width: min(1000px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.6); position: relative; }
.battle-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; gap: 8px; flex-wrap: wrap; }
#battle-title { font-family: var(--display); color: var(--gold); font-size: 18px; }
.battle-controls { display: flex; gap: 4px; }
.battle-controls button { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; }
.battle-controls button.active { border-color: var(--gold); color: var(--gold); }
#battle-canvas { width: 100%; height: auto; display: block; border-radius: 8px; background: #3d5a2a; }
#battle-result { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(5,7,10,.6); border-radius: 14px; }
#battle-result .modal-card { text-align: center; }
.big-result { font-family: var(--display); font-size: 36px; margin: 0; }
.big-result.win { color: var(--gold); text-shadow: 0 0 20px rgba(242,193,78,.6); }
.big-result.loss { color: var(--red); }

/* mystery box opening */
.box-open { text-align: center; padding: 10px 0; }
.chest { font-size: 90px; display: inline-block; filter: drop-shadow(0 8px 12px rgba(0,0,0,.5)); }
.chest.shake { animation: shake .12s infinite; }
@keyframes shake { 0% { transform: rotate(-6deg) scale(1); } 50% { transform: rotate(6deg) scale(1.06); } 100% { transform: rotate(-6deg) scale(1); } }
.burst { position: relative; display: inline-block; }
.burst::before { content: ""; position: absolute; inset: -60px; background: conic-gradient(from 0deg, transparent 0 10deg, var(--r) 10deg 20deg, transparent 20deg 40deg, var(--r) 40deg 50deg, transparent 50deg 70deg, var(--r) 70deg 80deg, transparent 80deg 100deg, var(--r) 100deg 110deg, transparent 110deg 130deg, var(--r) 130deg 140deg, transparent 140deg 160deg, var(--r) 160deg 170deg, transparent 170deg 190deg, var(--r) 190deg 200deg, transparent 200deg 220deg, var(--r) 220deg 230deg, transparent 230deg 250deg, var(--r) 250deg 260deg, transparent 260deg 280deg, var(--r) 280deg 290deg, transparent 290deg 310deg, var(--r) 310deg 320deg, transparent 320deg 340deg, var(--r) 340deg 350deg, transparent 350deg); border-radius: 50%; opacity: .35; animation: spin 6s linear infinite; mask: radial-gradient(circle, #000 20%, transparent 70%); -webkit-mask: radial-gradient(circle, #000 20%, transparent 70%); }
@keyframes spin { to { transform: rotate(360deg); } }
.reward { animation: reveal .5s cubic-bezier(.2,1.5,.4,1); position: relative; }
@keyframes reveal { from { transform: scale(.2) rotate(-20deg); opacity: 0; } }
.reward .portrait { width: 96px; height: 96px; font-size: 54px; margin: 0 auto 8px; }
.reward-title { font-family: var(--display); font-size: 24px; color: var(--r, var(--gold)); margin: 4px 0; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; top: 112px; right: 416px; z-index: 40; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.toast { background: rgba(20,24,32,.96); border: 1px solid var(--line); border-left: 4px solid var(--gold); border-radius: 8px; padding: 8px 12px; max-width: 320px; box-shadow: 0 6px 20px rgba(0,0,0,.5); animation: slidein .25s; font-size: 13px; }
.toast.good { border-left-color: var(--green); } .toast.bad { border-left-color: var(--red); }
.toast.out { opacity: 0; transform: translateX(20px); transition: .3s; }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  body { overflow: auto; }
  #app { height: auto; min-height: 100dvh; }
  #main { flex-direction: column; }
  #stage-wrap { height: 58vh; flex: none; }
  #panel { width: 100%; border-left: 0; border-top: 1px solid var(--line); }
  #panel-body { max-height: none; }
  #hud { gap: 8px; padding: 6px 10px; }
  .resources { order: 3; flex-basis: 100%; display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
  .res { min-width: 0; padding: 3px 4px; gap: 3px; justify-content: center; border-radius: 10px; }
  .res .ico { width: auto; font-size: 14px; }
  .res .val { font-size: 12px; }
  .res .rate { display: none; }
  .hud-stats { margin-left: auto; }
  .hud-stats .chip { padding: 3px 7px; font-size: 12px; }
  #sync { display: none; }
  .tabs button span { font-size: 10px; }
  #toasts { right: 12px; }
  .brand { min-width: 0; }
}

/* ==================== v2 additions ==================== */
.icon-btn { font-weight: 700; }
#alerts { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 3; display: flex; flex-direction: column; gap: 4px; align-items: center; pointer-events: none; max-width: 60%; }
.alert { pointer-events: auto; background: rgba(90,20,18,.92); color: #ffd2cf; border: 1px solid #e5534b; border-radius: 8px; padding: 5px 12px; font-weight: 700; font-size: 12px; cursor: pointer; animation: pulse 1.4s infinite; font-family: inherit; }
.alert.pirate { background: rgba(20,20,20,.92); border-color: #888; color: #eee; }
@keyframes pulse { 50% { box-shadow: 0 0 14px rgba(229,83,75,.7); } }
#placing-hint { top: 56px; }
.zoom-ctl { position: absolute; left: 12px; top: 12px; z-index: 2; display: flex; flex-direction: column; gap: 4px; }
.zoom-ctl button { width: 34px; height: 34px; border-radius: 8px; background: rgba(18,21,28,.88); border: 1px solid var(--line); cursor: pointer; font-size: 17px; font-weight: 700; }
.zoom-ctl button:hover { border-color: var(--gold); }
#minimap { position: absolute; right: 12px; bottom: 12px; z-index: 2; border: 2px solid rgba(242,193,78,.6); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.5); cursor: crosshair; background: #0d1016; }
#version { position: absolute; left: 10px; bottom: 8px; z-index: 2; font-size: 11px; color: rgba(232,226,208,.55); background: rgba(12,14,20,.55); padding: 2px 7px; border-radius: 6px; pointer-events: none; font-variant-numeric: tabular-nums; }
.ver { font-size: 12px; color: var(--muted); font-family: var(--font); vertical-align: middle; }
.big-ico { font-size: 30px; line-height: 1; }
.big-ico.sm { font-size: 22px; }
.pill { display: inline-block; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 1px 8px; font-size: 12px; margin: 2px 3px 2px 0; font-variant-numeric: tabular-nums; }
.pills { margin: 4px 0; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; border: 1px solid rgba(255,255,255,.4); flex: none; }
.gchip { font-size: 12px; font-weight: 600; color: var(--r, var(--text)); }
.orders { display: flex; flex-wrap: wrap; gap: 6px; }
.orders .btn { font-size: 12px; padding: 6px 10px; }
.clickable { cursor: pointer; border-radius: 6px; padding-left: 4px; }
.clickable:hover { background: var(--panel2); }
.pips { color: var(--gold); letter-spacing: 1px; font-size: 11px; }
.research.done { opacity: .6; }
.tag { background: var(--bg2); border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; font-size: 12px; }
.rel.war { color: var(--red); font-weight: 700; }
.general-card select, .setting select, .card select { width: auto; flex: 1; padding: 4px 8px; }
.locked-general { opacity: .35; display: flex; align-items: center; gap: 10px; }
.locked-general .portrait { width: 40px; height: 40px; font-size: 20px; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; text-align: left; }
.progress.thin { height: 5px; }
.slider-row { margin: 6px 0; }
textarea { width: 100%; height: 140px; background: var(--bg2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px; font: 12px monospace; }
.setting { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.setting span { flex: 1; }
.check { display: flex; align-items: center; gap: 8px; margin: 8px 0; cursor: pointer; }
.check input { accent-color: var(--gold); width: 16px; height: 16px; }
.modal-card.wide { width: min(980px, 100%); }
.help { display: grid; grid-template-columns: 210px 1fr; gap: 18px; min-height: 60vh; }
.help nav { display: flex; flex-direction: column; gap: 2px; border-right: 1px solid var(--line); padding-right: 10px; }
.help nav button { text-align: left; background: none; border: 0; padding: 7px 10px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 600; }
.help nav button.active, .help nav button:hover { background: var(--panel2); color: var(--gold); }
.help article { max-height: 66vh; overflow-y: auto; padding-right: 8px; line-height: 1.55; }
.help article h4 { color: var(--gold); margin: 16px 0 6px; }
.help article li { margin: 3px 0; }
.help .tip { background: var(--panel2); border-left: 3px solid var(--gold); padding: 8px 12px; border-radius: 6px; }
table.keys { border-collapse: collapse; width: 100%; font-size: 13px; }
table.keys td, table.keys th { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
table.keys th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }
kbd { background: var(--bg2); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 12px; font-family: inherit; margin-right: 2px; }
code { background: var(--bg2); padding: 1px 5px; border-radius: 4px; }
@media (max-width: 900px) {
  .help { grid-template-columns: 1fr; }
  .help nav { flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
  .help nav button { padding: 4px 8px; font-size: 12px; }
  #minimap { width: 130px !important; height: auto !important; }
  #alerts { max-width: 90%; top: 54px; }
  .hud-stats .chip:nth-child(-n+3) { display: none; }
  .res .cap { display: none; }
}

/* HUD: two rows — brand + status chips, then a full-width resource bar */
#hud { row-gap: 6px; }
.brand { order: 1; }
.hud-stats { order: 2; margin-left: auto; }
.resources { order: 3; flex-basis: 100%; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.res { min-width: 0; }

/* ==================== v2.1: on-map battle command bar ==================== */
#battle-hud { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 4; width: min(860px, calc(100% - 250px)); max-height: 46%; overflow-y: auto;
  background: rgba(14,17,24,.93); border: 1px solid #e5534b; border-radius: 12px; padding: 8px 12px; box-shadow: 0 10px 30px rgba(0,0,0,.55); backdrop-filter: blur(4px); font-size: 12px; }
.bh-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.bh-head b { font-family: var(--display); color: var(--gold); font-size: 15px; }
.bh-count { font-weight: 800; font-size: 14px; }
.bh-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 4px 0; border-top: 1px solid var(--line); }
.bh-name { min-width: 130px; }
.bh-row select { width: auto; padding: 3px 6px; font-size: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: var(--panel2); border: 0; border-right: 1px solid var(--line); padding: 4px 8px; cursor: pointer; font-size: 11.5px; font-weight: 600; color: var(--text); }
.seg button:last-child { border-right: 0; }
.seg button:hover { background: #313a4c; }
.seg button.on { background: var(--gold); color: #2a1d00; }
.seg button.warn.on { background: var(--red); color: #fff; }
.bh-tabs { display: flex; gap: 4px; margin-bottom: 6px; flex-wrap: wrap; }
.bh-tabs button { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; font-size: 11px; cursor: pointer; color: var(--muted); }
.bh-tabs button.active { border-color: var(--gold); color: var(--gold); }
.alert.battle { background: rgba(120,70,10,.94); border-color: var(--gold); color: #ffe7a8; }
.bad-txt { color: var(--red); font-weight: 700; }
.bdef select { width: auto; padding: 3px 6px; font-size: 11.5px; }
.tb-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tb-grid .build-item { min-height: 76px; }
@media (max-width: 900px) { #battle-hud { width: calc(100% - 16px); bottom: 8px; max-height: 55%; } .bh-name { min-width: 0; } }
.bh-row.compact { padding: 2px 0; }
.bh-row.compact select { font-size: 11.5px; padding: 2px 5px; }
#battle-hud { max-height: 42%; }

.speed-ctl { position: absolute; left: 56px; top: 12px; z-index: 2; display: flex; background: rgba(18,21,28,.88); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.speed-ctl button { background: none; border: 0; border-right: 1px solid var(--line); padding: 7px 10px; cursor: pointer; font-weight: 700; color: var(--muted); }
.speed-ctl button:last-child { border-right: 0; }
.speed-ctl button.on { background: var(--gold); color: #2a1d00; }
.card.obj { border-color: #4ea1f2; }
.obj-row { margin-top: 3px; }
.paused-banner { position: absolute; top: 56px; left: 50%; transform: translateX(-50%); z-index: 3; background: rgba(18,21,28,.9); border: 1px solid var(--gold); border-radius: 8px; padding: 4px 14px; font-weight: 700; color: var(--gold); pointer-events: none; }

/* ==================== v3.5: loading, catch-up, smoother UI ==================== */
/* Loading screen over the map until its first frame is drawn. */
#boot-screen { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: radial-gradient(ellipse at 50% 40%, #1d2a3d 0%, #0d1016 70%); transition: opacity .4s ease; }
#boot-screen.done { opacity: 0; pointer-events: none; }
#boot-screen .boot-card { text-align: center; color: var(--text); padding: 24px; max-width: 460px; }
#boot-screen .boot-crown { font-size: 54px; animation: boot-bob 1.6s ease-in-out infinite; }
#boot-screen h1 { font-family: var(--display); color: var(--gold); margin: 6px 0 4px; font-size: 30px; letter-spacing: .5px; }
#boot-screen .boot-msg { color: var(--muted); font-size: 14px; }
#boot-screen .boot-bar { width: 220px; height: 4px; margin: 16px auto 0; border-radius: 2px; background: var(--line); overflow: hidden; position: relative; }
#boot-screen .boot-bar::after { content: ""; position: absolute; inset: 0; width: 40%; border-radius: 2px; background: linear-gradient(90deg, var(--gold-dark), var(--gold)); animation: boot-slide 1.1s ease-in-out infinite; }
#boot-screen.failed .boot-bar, #boot-screen.failed .boot-crown { display: none; }
#boot-screen.failed .boot-msg { color: var(--text); }
#boot-screen .boot-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
@keyframes boot-bob { 50% { transform: translateY(-6px); } }
@keyframes boot-slide { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

/* Offline progress banner, with its own progress bar */
.paused-banner.catchup { overflow: hidden; padding-bottom: 6px; }
.paused-banner.catchup i { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--gold); transition: width .2s linear; }

/* If the map ever fails to draw, show sea rather than a black void. */
#stage { background: #1c4a70; }

/* Gentle feedback everywhere you can click */
.btn, .icon-btn, .tabs button, .speed-ctl button, .zoom-ctl button, .chip, .card { transition: background-color .15s, border-color .15s, color .15s, filter .15s, transform .08s, box-shadow .15s; }
.tabs button:hover:not(.active) { color: var(--text); background: rgba(255,255,255,.03); }
.btn:focus-visible, .icon-btn:focus-visible, .tabs button:focus-visible, select:focus-visible, input:focus-visible, .speed-ctl button:focus-visible, .zoom-ctl button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
#panel-body { scroll-behavior: smooth; overscroll-behavior: contain; }
#panel-body.fresh > * { animation: panel-in .18s ease-out; }
@keyframes panel-in { from { opacity: 0; transform: translateY(4px); } }
/* Long modals keep their buttons in reach */
.modal-card .actions:last-child { position: sticky; bottom: -20px; margin: 14px -20px -20px; padding: 12px 20px; background: linear-gradient(180deg, rgba(30,36,48,0), var(--panel) 35%); }
.modal-card { overscroll-behavior: contain; }
#modal[hidden], #boot-screen[hidden] { display: none; }
@media (max-width: 900px) {
  #minimap { width: 112px !important; opacity: .92; }
  #toasts { top: auto; bottom: 12px; left: 12px; right: 12px; align-items: center; }
  .toast { max-width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* Save import: a file picker styled as a button */
.file-pick { display: inline-block; margin: 4px 0; }
.file-pick input { display: none; }
