/* Earthrise — dawn palette: indigo night giving way to peach light */
[hidden] { display: none !important; }

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Nunito', system-ui, sans-serif;
  background: #2b2440;
  color: #f4eee6;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
#stage, #stage canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

h1, h2, h3, .wordmark, .btn { font-family: 'Baloo 2', 'Nunito', sans-serif; }

/* ---------- shared ---------- */
.screen {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  overflow-y: auto;
}
.btn {
  font-size: 16px; font-weight: 700; color: #2b2440;
  background: linear-gradient(180deg, #f6cf5a, #f2b84b);
  border: none; border-radius: 14px; padding: 10px 22px;
  box-shadow: 0 3px 0 #a87a22, 0 8px 18px rgba(0,0,0,.25);
  cursor: pointer; transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #a87a22; }
.btn.big { font-size: 20px; padding: 13px 34px; border-radius: 18px; }
.btn.ghost {
  background: rgba(244,238,230,.1); color: #f4eee6;
  box-shadow: inset 0 0 0 2px rgba(244,238,230,.35);
}
.btn.ghost:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.icon-btn {
  background: rgba(244,238,230,.12); color: #f4eee6; border: none;
  width: 34px; height: 34px; border-radius: 10px; font-size: 17px; cursor: pointer;
}
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(30,25,48,.72); backdrop-filter: blur(6px);
  border-radius: 12px; padding: 7px 12px; font-size: 14px; font-weight: 700;
}
.chip.gold { color: #f6cf5a; }
.chip.warn { color: #f0a58f; }
.chip small { opacity: .7; font-weight: 600; }
.btn-chip { border: none; cursor: pointer; font-family: inherit; color: inherit; }
.btn-chip:active { transform: translateY(1px); }

#res-pop {
  position: absolute; top: 56px; right: 12px; min-width: 220px;
  background: rgba(30,25,48,.92); backdrop-filter: blur(10px);
  border-radius: 14px; padding: 10px 14px; pointer-events: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,.35); font-size: 13.5px;
}
.rp-title { font-weight: 800; margin-bottom: 6px; font-size: 13px; opacity: .75; }
.rp-row { display: flex; justify-content: space-between; gap: 18px; padding: 2px 0; }
.rp-row b { color: #f6cf5a; }
.rp-net { border-top: 1px solid rgba(244,238,230,.2); margin-top: 5px; padding-top: 5px; font-weight: 800; }

/* ---------- title ---------- */
#title { background: radial-gradient(120% 90% at 50% 110%, #f0a58f 0%, #7a5a8f 42%, #2b2440 78%); }
#title-fx { position: absolute; inset: 0; width: 100%; height: 100%; }
.title-card { position: relative; z-index: 1; text-align: center; animation: rise .9s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(26px); } }
.title-logo { width: 116px; height: 116px; filter: drop-shadow(0 10px 24px rgba(0,0,0,.35)); }
.wordmark {
  font-size: clamp(46px, 11vw, 84px); font-weight: 800; letter-spacing: .06em;
  background: linear-gradient(110deg, #ffe9b0 20%, #f2b84b 42%, #e07a5f 62%, #ffe9b0 85%);
  background-size: 220% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  line-height: 1.05;
  margin-bottom: 26px;
  animation: shine 7s ease-in-out infinite;
}
@keyframes shine { 0%, 100% { background-position: 0% 0; } 50% { background-position: 90% 0; } }
@media (prefers-reduced-motion: reduce) { .wordmark { animation: none; } }
.title-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
#title-ver {
  position: absolute; right: 12px; bottom: max(10px, env(safe-area-inset-bottom));
  font-size: 11px; opacity: .38; letter-spacing: .08em; z-index: 1;
  font-variant-numeric: tabular-nums;
}

/* ---------- setup ---------- */
#setup { background: linear-gradient(180deg, #2b2440 0%, #3d3054 100%); align-items: flex-start; }
.setup-card { width: min(860px, 100%); padding: 8px 0 30px; }
.setup-card h2 { font-size: 26px; margin: 10px 0 14px; }
#species-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px;
}
.sp-card {
  background: rgba(244,238,230,.07); border: 2px solid transparent; border-radius: 16px;
  padding: 10px 6px 8px; text-align: center; cursor: pointer; transition: all .12s;
}
.sp-card:hover { background: rgba(244,238,230,.13); }
.sp-card.on { border-color: #f2b84b; background: rgba(242,184,75,.14); }
.sp-card img { width: 64px; height: 64px; image-rendering: auto; }
.sp-card .sp-name { font-weight: 800; font-size: 14px; margin-top: 2px; }
#species-detail {
  margin-top: 14px; background: rgba(244,238,230,.07); border-radius: 18px; padding: 14px 16px;
}
#species-detail .sd-blurb { opacity: .8; font-size: 14px; margin-bottom: 10px; }
.sd-units { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.sd-unit {
  display: flex; gap: 10px; align-items: center; min-width: 0;
  background: rgba(30,25,48,.5); border-radius: 14px; padding: 8px 10px;
}
.sd-unit > div { min-width: 0; flex: 1; overflow-wrap: break-word; }
.sd-unit img.u { width: 52px; height: 52px; flex: none; }
.sd-unit img.d { width: 62px; height: 62px; flex: none; border-radius: 8px; background: rgba(244,238,230,.06); }
.sd-unit .un { font-weight: 800; font-size: 14px; }
.sd-unit .uc { color: #f6cf5a; font-size: 12.5px; font-weight: 700; }
.sd-unit .uh { opacity: .7; font-size: 11.5px; line-height: 1.25; }
.setup-row { display: flex; gap: 22px; margin-top: 16px; flex-wrap: wrap; }
.opt label { display: block; font-size: 13px; opacity: .7; font-weight: 700; margin-bottom: 6px; }
.seg { display: inline-flex; background: rgba(30,25,48,.6); border-radius: 12px; padding: 3px; }
.seg button {
  border: none; background: transparent; color: #f4eee6; font: 700 14px 'Nunito', sans-serif;
  padding: 7px 16px; border-radius: 9px; cursor: pointer;
}
.seg button.on { background: #f2b84b; color: #2b2440; }
.setup-actions { display: flex; justify-content: space-between; margin-top: 22px; }

/* ---------- world / battle HUD ---------- */
#world-hud, #battle-hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
.topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  pointer-events: none;
}
.topbar > div { display: flex; gap: 8px; align-items: center; }
.topbar .btn, .topbar .icon-btn, .topbar .chip { pointer-events: auto; }

#hex-panel {
  position: absolute; right: 12px; bottom: 12px; width: min(320px, calc(100vw - 24px));
  max-height: 62vh; overflow-y: auto;
  background: rgba(30,25,48,.86); backdrop-filter: blur(10px);
  border-radius: 18px; padding: 12px 14px; pointer-events: auto;
  box-shadow: 0 12px 34px rgba(0,0,0,.35);
}
.hp-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.hp-head span { font-weight: 800; font-size: 15px; }
#hp-units { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.u-chip {
  display: flex; align-items: center; gap: 6px;
  background: rgba(244,238,230,.1); border: 2px solid transparent;
  border-radius: 12px; padding: 4px 8px 4px 4px; cursor: pointer; font-size: 12.5px; font-weight: 700;
}
.u-chip img { width: 30px; height: 30px; }
.u-chip.on { border-color: #4fb3a5; background: rgba(79,179,165,.15); }
.u-chip.spent { opacity: .45; }
.u-chip.civ { opacity: .8; cursor: default; border-style: dashed; border-color: rgba(244,238,230,.25); font-style: italic; }
.hp-cont { font-size: 12px; color: #f6cf5a; opacity: .85; margin-bottom: 8px; }
.hp-cont:empty { display: none; }
.sd-folk { background: rgba(79,179,165,.08); }
.r-row {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: rgba(244,238,230,.07); border: none; border-radius: 12px;
  padding: 6px 8px; margin-bottom: 6px; color: #f4eee6; cursor: pointer; text-align: left;
}
.r-row:disabled { opacity: .4; cursor: default; }
.r-row img.u { width: 36px; height: 36px; flex: none; }
.r-row img.d { width: 44px; height: 44px; flex: none; margin-left: auto; border-radius: 6px; background: rgba(244,238,230,.05); }
.r-row .rn { font-weight: 800; font-size: 13px; }
.r-row .rc { color: #f6cf5a; font-size: 12px; font-weight: 700; }
.hp-hint { font-size: 12px; opacity: .65; line-height: 1.35; }

#battle-picker {
  position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: stretch;
  background: rgba(30,25,48,.9); backdrop-filter: blur(10px);
  border-radius: 18px; padding: 12px 14px; pointer-events: auto;
  box-shadow: 0 14px 40px rgba(0,0,0,.4); max-width: min(420px, calc(100vw - 24px));
}
.bp-title { font-weight: 800; font-size: 13px; opacity: .75; text-align: center; margin-bottom: 2px; }
.bp-btn {
  display: flex; align-items: center; gap: 10px;
  background: rgba(244,238,230,.09); border: 2px solid transparent; border-radius: 14px;
  padding: 7px 12px; color: #f4eee6; font: 700 14px 'Nunito', sans-serif; cursor: pointer;
}
.bp-btn:hover { border-color: #f2b84b; background: rgba(242,184,75,.12); }
.bp-btn img { width: 38px; height: 38px; }
.bp-mid { font-size: 15px; }
.bp-mid b { color: #f6cf5a; }
.bp-where { margin-left: auto; opacity: .65; font-size: 12.5px; }

#toast {
  position: absolute; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: rgba(30,25,48,.9); border-radius: 14px; padding: 10px 18px;
  font-weight: 700; font-size: 14px; pointer-events: none; white-space: nowrap;
  animation: toast 2.6s forwards;
}
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, 8px); } 10%, 80% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }

#bt-inspect {
  position: absolute; left: 12px; bottom: 12px;
  display: flex; gap: 10px; align-items: center;
  background: rgba(30,25,48,.86); backdrop-filter: blur(10px);
  border-radius: 16px; padding: 10px 12px; pointer-events: auto;
}
#bt-inspect img.u { width: 46px; height: 46px; }
#bt-inspect img.d { width: 76px; height: 76px; border-radius: 8px; background: rgba(244,238,230,.06); }
#bt-inspect .bn { font-weight: 800; font-size: 14px; }
#bt-inspect .bh { font-size: 11.5px; opacity: .7; max-width: 150px; line-height: 1.3; }

/* ---------- result ---------- */
#result { background: rgba(24,20,38,.66); backdrop-filter: blur(6px); }
.result-card {
  text-align: center; background: rgba(43,36,64,.96); border-radius: 24px;
  padding: 30px 34px; max-width: 420px; box-shadow: 0 18px 60px rgba(0,0,0,.5);
  animation: rise .5s ease-out;
}
.result-card h2 { font-size: 32px; margin-bottom: 8px; }
.result-card p { opacity: .8; font-size: 15px; margin-bottom: 14px; line-height: 1.4; }
#result-forces { display: flex; gap: 10px; margin-bottom: 18px; }
.rf-col { flex: 1; background: rgba(30,25,48,.5); border-radius: 12px; padding: 8px; min-width: 0; }
.rf-h { font-size: 11.5px; font-weight: 800; opacity: .7; margin-bottom: 6px; letter-spacing: .04em; }
.rf-units { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; }
.rf-u { position: relative; width: 34px; height: 34px; }
.rf-u img { width: 100%; height: 100%; }
.rf-u.dead img { filter: grayscale(1); opacity: .4; }
.rf-u.dead::after {
  content: '✕'; position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #d95f6e; font-weight: 800; font-size: 19px; text-shadow: 0 1px 3px rgba(0,0,0,.7);
}
.icon-btn.on { background: rgba(217,95,110,.35); box-shadow: inset 0 0 0 2px #d95f6e; }

/* ---------- mobile ---------- */
@media (max-width: 640px) {
  .topbar { padding: max(8px, env(safe-area-inset-top)) 8px 8px; flex-wrap: wrap; gap: 6px; }
  .topbar > div { gap: 5px; flex-wrap: wrap; }
  .topbar .btn { font-size: 13.5px; padding: 8px 12px; border-radius: 11px; }
  .chip { font-size: 12px; padding: 6px 8px; border-radius: 10px; }
  .icon-btn { width: 30px; height: 30px; font-size: 15px; }
  .title-logo { width: 88px; height: 88px; }
  .btn.big { font-size: 17px; padding: 12px 26px; }

  .setup-card h2 { font-size: 21px; margin: 4px 0 10px; }
  #species-grid { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 7px; }
  .sp-card { padding: 7px 4px 6px; border-radius: 12px; }
  .sp-card img { width: 48px; height: 48px; }
  .sp-card .sp-name { font-size: 11.5px; }
  #species-detail { padding: 10px 12px; border-radius: 14px; }
  .sd-units { grid-template-columns: 1fr; gap: 7px; }
  .sd-unit img.u { width: 44px; height: 44px; }
  .sd-unit img.d { width: 54px; height: 54px; }
  .seg button { padding: 9px 14px; }
  .setup-row { flex-direction: column; gap: 12px; }
  .setup-actions { margin-top: 16px; }

  #hex-panel { right: 8px; left: 8px; bottom: 8px; width: auto; max-height: 46vh; padding: 10px 12px; }
  .r-row img.d { width: 38px; height: 38px; }
  #res-pop { top: auto; bottom: 8px; right: 8px; left: 8px; min-width: 0; }
  #bt-inspect { left: 8px; right: auto; bottom: 8px; padding: 8px 9px; gap: 7px; }
  #bt-inspect img.u { width: 38px; height: 38px; }
  #bt-inspect img.d { width: 58px; height: 58px; }
  #bt-inspect .bh { max-width: 110px; font-size: 10.5px; }
  #toast { bottom: 60px; font-size: 12.5px; max-width: 92vw; white-space: normal; text-align: center; }
}
@media (max-width: 640px) and (orientation: landscape) {
  #hex-panel { left: auto; width: min(300px, 46vw); max-height: 70vh; }
  #res-pop { left: auto; min-width: 220px; }
}
