/* ============================================================
   LEGION — dark-fantasy theme. Warm firelight vs cold void.
   No framework. ============================================================ */

:root {
  --bg: #14110f;
  --bg-2: #1c1814;
  --panel: #221d18;
  --panel-2: #2a231c;
  --ink: #ece3d4;
  --ink-dim: #b6a98f;
  --ink-faint: #7d7261;
  --gold: #e7b24c;
  --gold-deep: #b07d28;
  --ember: #d9542b;
  --void: #6b3fa0;
  --line: #3a3128;
  --good: #6cc04a;
  --warn: #e7b24c;
  --bad: #d9542b;
  --shadow: 0 6px 24px rgba(0,0,0,.5);
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background:
    radial-gradient(1200px 600px at 50% -10%, #2a201a 0%, var(--bg) 60%),
    var(--bg);
  color: var(--ink);
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 16px;
  overflow: hidden;
  user-select: none;
}
h1, h2, h3, .cinzel { font-family: 'Cinzel', serif; letter-spacing: .04em; }

.hidden { display: none !important; }

#app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  max-width: 1280px;
  margin: 0 auto;
}

/* ---------- HUD ---------- */
#hud {
  background: linear-gradient(180deg, var(--bg-2), transparent);
  border-bottom: 1px solid var(--line);
  padding: 10px 18px 12px;
}
.hud-top {
  display: flex; align-items: center; gap: 16px; margin-bottom: 8px;
}
.hud-title { font-size: 20px; color: var(--gold); margin: 0; }
.hud-title small { color: var(--ink-faint); font-family: 'EB Garamond'; font-style: italic; letter-spacing: 0; font-size: 13px; margin-left: 8px; }
.hud-overall {
  margin-left: auto; display: flex; align-items: center; gap: 10px;
  font-family: 'Cinzel';
}
.hud-overall .num { font-size: 26px; color: var(--gold); }
.hud-overall .lbl { font-size: 11px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .12em; }

.hud-controls { display: flex; gap: 6px; }
.icon-btn {
  background: var(--panel); color: var(--ink-dim); border: 1px solid var(--line);
  border-radius: 8px; width: 34px; height: 34px; cursor: pointer; font-size: 15px;
  transition: .12s;
}
.icon-btn:hover { color: var(--gold); border-color: var(--gold-deep); }

.beacon-btn {
  background: linear-gradient(180deg, var(--ember), #a23718);
  color: #fff; border: 1px solid #6e2410; border-radius: 8px;
  padding: 8px 16px; font-family: 'Cinzel'; font-weight: 700; font-size: 14px;
  cursor: pointer; box-shadow: 0 0 18px rgba(217,84,43,.45); transition: .15s;
}
.beacon-btn:hover { filter: brightness(1.12); }
.beacon-btn[disabled] {
  background: var(--panel); color: var(--ink-faint); border-color: var(--line);
  box-shadow: none; cursor: not-allowed;
}

.stat-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 9px;
}
.stat.weakest { border-color: var(--ember); box-shadow: 0 0 0 1px rgba(217,84,43,.3) inset; }
.stat-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; }
.stat-head .name { color: var(--ink-dim); }
.stat-head .pct { color: var(--ink); font-family: 'Cinzel'; }
.bar { height: 7px; background: #0e0c0a; border-radius: 5px; margin-top: 5px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 5px; transition: width .25s; }
.stat .tagline { font-size: 11px; color: var(--ink-faint); margin-top: 4px; min-height: 14px; }
.weakest-flag { color: var(--ember); font-size: 11px; }

/* ---------- STAGE ---------- */
#stage { display: grid; grid-template-columns: 1fr 300px; gap: 14px; padding: 14px 18px; min-height: 0; }

/* ---------- PANEL ---------- */
.panel {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; overflow-y: auto; box-shadow: var(--shadow);
}
.panel-head { display: flex; gap: 14px; align-items: center; margin-bottom: 6px; }
.portrait {
  width: 76px; height: 76px; border-radius: 12px; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 40px;
  background: radial-gradient(circle at 50% 35%, #3a2f24, #1a1511);
  border: 1px solid var(--gold-deep); box-shadow: inset 0 0 16px rgba(0,0,0,.6);
}

/* image-with-emoji-fallback box */
.imgbox { position: relative; overflow: hidden; }
.imgbox > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.imgbox > .em { position: relative; }
.res-ic { display: inline-grid; place-items: center; width: 1.2em; height: 1.2em; border-radius: 4px; vertical-align: -0.2em; }
.click-btn .ic { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 7px; margin: 0 auto 4px; }
.panel-head .who .name { font-family: 'Cinzel'; font-size: 19px; color: var(--gold); }
.panel-head .who .role { font-size: 13px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: .1em; }
.panel-head .who .persona { font-style: italic; color: var(--ink-faint); font-size: 13px; margin-top: 3px; }
.goal { font-size: 13px; color: var(--ink-dim); margin: 8px 0 14px; padding: 8px 10px; background: #00000026; border-left: 2px solid var(--gold-deep); border-radius: 4px; }

.click-row { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.click-btn {
  position: relative; cursor: pointer; border: none; border-radius: 14px;
  padding: 18px 22px; min-width: 220px;
  background: radial-gradient(circle at 50% 30%, #4a3a2a, #241a12);
  border: 1px solid var(--gold-deep); color: var(--ink);
  font-family: 'Cinzel'; font-size: 16px; box-shadow: var(--shadow);
  transition: transform .05s;
}
.click-btn:active { transform: scale(.97); }
.click-btn .ic { font-size: 30px; display: block; margin-bottom: 4px; }
.click-yield { font-size: 13px; color: var(--ink-faint); }
.resource-readout { font-family: 'Cinzel'; }
.resource-readout .amt { font-size: 26px; color: var(--gold); }
.resource-readout .rname { color: var(--ink-dim); font-size: 14px; }
.resource-readout .rate { color: var(--good); font-size: 13px; display: block; margin-top: 2px; }

.section-title { font-family: 'Cinzel'; font-size: 13px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .14em; margin: 14px 0 8px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.section-title .hint { float: right; font-family: 'EB Garamond'; text-transform: none; letter-spacing: 0; font-size: 11px; color: var(--ink-faint); opacity: .7; }

.item {
  display: flex; align-items: center; gap: 12px; padding: 9px 11px; margin-bottom: 7px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  cursor: pointer; transition: .12s;
}
.item:hover { border-color: var(--gold-deep); }
.item.affordable { border-color: #4a5a30; }
.item.unaffordable { opacity: .62; cursor: not-allowed; }
.item.locked { opacity: .55; cursor: not-allowed; border-style: dashed; }
.item.owned { opacity: .8; border-color: #3c4a2a; background: #1e231733; cursor: default; }
.item .ic { font-size: 24px; width: 30px; text-align: center; flex: 0 0 auto; }
.item .body { flex: 1 1 auto; min-width: 0; }
.item .nm { font-weight: 600; }
.item .nm .count { color: var(--gold); font-family: 'Cinzel'; font-size: 13px; margin-left: 6px; }
.item .ds { font-size: 12px; color: var(--ink-faint); overflow: hidden; text-overflow: ellipsis; }
.item .cost { font-family: 'Cinzel'; font-size: 13px; color: var(--ink-dim); white-space: nowrap; text-align: right; }
.item.affordable .cost { color: var(--good); }
.item .lock { font-size: 11px; color: var(--ember); white-space: nowrap; text-align: right; }
.item .check { color: var(--good); font-size: 18px; }

/* Supply-line readout on generator rows */
.gfeed { font-size: 11px; color: var(--ink-faint); margin-top: 2px; }
.gfeed.fed { color: var(--good); }
.gfeed.starved { color: var(--ember); }

/* ---------- SIGNATURE WIDGET ---------- */
.sig-widget {
  background: linear-gradient(180deg, var(--panel-2), #221c1633);
  border: 1px solid var(--gold-deep); border-radius: 8px;
  padding: 10px 12px; margin-bottom: 4px;
}
.sig-head { display: flex; align-items: baseline; gap: 8px; }
.sig-head .ic { font-size: 18px; }
.sig-name { font-family: 'Cinzel'; color: var(--gold); font-size: 14px; }
.sig-desc { font-size: 12px; color: var(--ink-faint); font-style: italic; margin: 2px 0 8px; }
.sig-line { font-size: 12px; color: var(--ink-dim); margin-top: 6px; display: flex; justify-content: space-between; gap: 8px; }
.sig-line.dim { color: var(--ink-faint); }
.sig-line.away { color: var(--ink); }
.sig-line.ok { color: var(--good); }
.sig-mult { font-family: 'Cinzel'; color: var(--gold); }

.sig-meter { height: 10px; background: #0e0c0a; border-radius: 5px; overflow: hidden; border: 1px solid var(--line); }
.sig-meter > span { display: block; height: 100%; width: 0; border-radius: 5px; background: linear-gradient(90deg, var(--gold-deep), var(--ember)); transition: width .15s; }
.sig-meter.grow > span { background: linear-gradient(90deg, #3c4a2a, var(--good)); }

.sig-btn {
  display: inline-block; padding: 7px 12px; margin-top: 4px;
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--gold-deep); border-radius: 7px; color: var(--ink);
  font-family: 'Cinzel'; font-size: 13px; cursor: pointer; transition: .12s;
}
.sig-btn:hover { border-color: var(--gold); color: var(--gold); }
.sig-btn:active { transform: scale(.97); }
.sig-btn.unaffordable { opacity: .55; cursor: not-allowed; }
.sig-btn.affordable { border-color: #4a5a30; }
.sig-btn.ready { border-color: var(--good); box-shadow: 0 0 10px rgba(108,192,74,.25); animation: sigPulse 1.6s infinite; }
@keyframes sigPulse { 50% { box-shadow: 0 0 16px rgba(108,192,74,.5); } }

.sig-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.sig-chip {
  width: 30px; height: 30px; font-size: 16px; display: grid; place-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 7px;
  cursor: pointer; transition: .12s;
}
.sig-chip:hover { border-color: var(--gold-deep); transform: translateY(-2px); }
.sig-chip.on { border-color: var(--gold); box-shadow: 0 0 8px rgba(231,178,76,.4); }

.sig-node { font-size: 12px; padding: 6px 8px; margin-top: 6px; border-radius: 6px; border: 1px solid var(--line); background: #00000022; }
.sig-node.locked { color: var(--ink-faint); border-style: dashed; }
.sig-node.open { display: flex; align-items: center; gap: 8px; border-color: var(--gold-deep); }
.sig-node.open .vs { color: var(--ink-faint); font-style: italic; }
.sig-node.open .sig-btn.half { flex: 1 1 0; margin-top: 0; }
.sig-node.picked { display: flex; gap: 8px; align-items: baseline; }
.sig-node.picked .ok { color: var(--good); white-space: nowrap; }
.sig-node.picked .ds { color: var(--ink-faint); flex: 1 1 auto; }
.sig-node.picked .other { color: var(--ink-faint); font-style: italic; text-decoration: line-through; opacity: .6; white-space: nowrap; }

.sig-jobs { font-size: 16px; letter-spacing: 2px; min-height: 20px; }
.sig-slots { font-size: 18px; letter-spacing: 3px; margin-top: 2px; }

/* Supply-shortage marker on the switcher */
.chip .starve-dot {
  position: absolute; top: -5px; left: -5px; width: 16px; height: 16px;
  font-size: 11px; display: grid; place-items: center; color: var(--ember);
  background: var(--bg-2); border: 1px solid var(--ember); border-radius: 8px;
}

/* ---------- FEED ---------- */
.feed { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; overflow: hidden; display: flex; flex-direction: column; }
.feed-title { margin: 0 0 8px; color: var(--gold); font-size: 15px; }
.feed-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; font-size: 13px; }
.feed-list li { padding: 6px 8px; border-left: 2px solid var(--line); margin-bottom: 5px; color: var(--ink-dim); animation: fade .4s; }
.feed-list li.unlock { border-color: var(--gold); color: var(--ink); }
.feed-list li.milestone { border-color: var(--void); color: var(--ink); }
.feed-list li.battle { border-color: var(--ember); }
@keyframes fade { from { opacity: 0; transform: translateX(-6px); } }

/* ---------- SWITCHER ---------- */
.switcher {
  display: flex; gap: 6px; padding: 10px 14px; background: linear-gradient(0deg, var(--bg-2), transparent);
  border-top: 1px solid var(--line); overflow-x: auto;
}
.chip {
  position: relative; flex: 1 1 0; min-width: 46px; max-width: 70px; aspect-ratio: 1;
  border-radius: 12px; cursor: pointer; display: grid; place-items: center;
  background: var(--panel); border: 1px solid var(--line); transition: .12s;
  font-size: 26px;
}
.chip:hover { transform: translateY(-3px); border-color: var(--gold-deep); }
.chip.active { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(231,178,76,.3), 0 -4px 14px rgba(231,178,76,.25); transform: translateY(-3px); }
.chip .face { width: 100%; height: 100%; border-radius: 11px; display: grid; place-items: center; }
.chip .ring {
  position: absolute; inset: -3px; border-radius: 14px; padding: 3px;
  background: conic-gradient(var(--gold) calc(var(--p) * 1%), transparent 0);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude; pointer-events: none;
}
.chip .badge {
  position: absolute; top: -5px; right: -5px; min-width: 18px; height: 18px; padding: 0 4px;
  background: var(--ember); color: #fff; border-radius: 9px; font-size: 11px; font-family: 'Cinzel';
  display: grid; place-items: center; box-shadow: 0 0 8px rgba(217,84,43,.7);
}
.chip .pillar-dot { position: absolute; bottom: 3px; left: 50%; transform: translateX(-50%); width: 16px; height: 3px; border-radius: 2px; }
.chip .nm { position: absolute; bottom: -16px; left: 0; right: 0; text-align: center; font-size: 9px; color: var(--ink-faint); opacity: 0; transition: .12s; pointer-events: none; }
.chip:hover .nm { opacity: 1; }

/* ---------- FLOATS (click numbers) ---------- */
.floats { position: fixed; inset: 0; pointer-events: none; z-index: 40; }
.float { position: absolute; font-family: 'Cinzel'; color: var(--gold); font-size: 18px; text-shadow: 0 1px 4px #000; animation: floatUp .9s ease-out forwards; }
@keyframes floatUp { to { transform: translateY(-46px); opacity: 0; } }

/* ---------- TOASTS ---------- */
.toasts { position: fixed; right: 16px; bottom: 96px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  background: var(--panel-2); border: 1px solid var(--gold-deep); border-left: 3px solid var(--gold);
  border-radius: 8px; padding: 10px 14px; min-width: 220px; max-width: 320px; box-shadow: var(--shadow);
  animation: toastIn .25s ease-out;
}
.toast.unlock { border-left-color: var(--gold); }
.toast.milestone { border-left-color: var(--void); }
.toast.error { border-left-color: var(--bad); }
.toast .t { font-family: 'Cinzel'; color: var(--gold); font-size: 14px; }
.toast .m { font-size: 13px; color: var(--ink-dim); }
@keyframes toastIn { from { opacity: 0; transform: translateX(30px); } }

/* ---------- MODAL ---------- */
.modal-layer, .battle-layer {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 30%, rgba(40,20,15,.7), rgba(0,0,0,.86));
  backdrop-filter: blur(3px);
}
.modal {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--gold-deep); border-radius: 14px; box-shadow: var(--shadow);
  max-width: 560px; width: calc(100% - 40px); max-height: 86vh; overflow-y: auto; padding: 26px 28px;
}
.intro-banner { height: 170px; border-radius: 10px; margin: -6px 0 16px; border: 1px solid var(--gold-deep); display: grid; place-items: center; font-size: 50px; background: radial-gradient(circle at 50% 120%, #4a1d6b, #12060f); }
.modal h1 { color: var(--gold); margin: 0 0 4px; font-size: 34px; text-align: center; }
.modal .subtitle { text-align: center; color: var(--ink-faint); font-style: italic; margin-bottom: 18px; }
.modal p { color: var(--ink-dim); line-height: 1.55; }
.modal .actions { display: flex; gap: 10px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
.btn {
  background: var(--panel-2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 9px; padding: 11px 20px; cursor: pointer; font-family: 'Cinzel'; font-size: 14px; transition: .12s;
}
.btn:hover { border-color: var(--gold); color: var(--gold); }
.btn.primary { background: linear-gradient(180deg, var(--gold), var(--gold-deep)); color: #2a1c08; border: none; }
.btn.danger { border-color: #6e2410; color: var(--ember); }
.banner-good { color: var(--good); } .banner-warn { color: var(--warn); } .banner-bad { color: var(--bad); }
.predict { text-align: center; font-family: 'Cinzel'; font-size: 22px; margin: 14px 0; }

.offline-list { list-style: none; padding: 0; margin: 14px 0; max-height: 40vh; overflow-y: auto; }
.offline-list li { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.offline-list .emoji { font-size: 22px; }
.offline-list .amt { margin-left: auto; font-family: 'Cinzel'; color: var(--gold); }

/* ---------- BATTLE ---------- */
.battle { width: min(820px, 94vw); }
.battle-stage {
  background: linear-gradient(180deg, #1a1016, #0c0810);
  border: 1px solid var(--void); border-radius: 14px; padding: 22px 24px; box-shadow: 0 0 40px rgba(107,63,160,.3);
}
.battle h1 { font-family: 'Cinzel'; color: var(--ember); text-align: center; margin: 0 0 4px; font-size: 30px; }
.battle .wave-label { text-align: center; color: var(--ink-dim); margin-bottom: 14px; }
.battle .scene { height: 150px; border-radius: 10px; margin-bottom: 16px; background: radial-gradient(circle at 50% 120%, #4a1d6b, #12060f); display: grid; place-items: center; font-size: 46px; background-size: cover; background-position: center; }
.clash { display: flex; justify-content: space-around; text-align: center; margin-bottom: 14px; font-family: 'Cinzel'; }
.clash .inc { color: var(--ember); } .clash .kill { color: var(--good); } .clash .over { color: var(--bad); }
.clash .v { font-size: 24px; } .clash .l { font-size: 11px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .1em; }
.seal-wrap { margin: 12px 0; }
.seal-wrap .lbl { display: flex; justify-content: space-between; font-size: 12px; color: var(--void); font-family: 'Cinzel'; }
.seal-bar { height: 12px; background: #0e0c0a; border-radius: 6px; overflow: hidden; border: 1px solid var(--void); }
.seal-bar > span { display: block; height: 100%; background: linear-gradient(90deg, #8e44ad, #c39bd3); transition: width .4s; }
.battle-stats { display: grid; grid-template-columns: repeat(6,1fr); gap: 8px; margin-top: 12px; }
.battle-stats .s { text-align: center; font-size: 11px; color: var(--ink-faint); }
.battle-stats .s .bar { margin-top: 4px; }
.epilogue-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0; max-height: 40vh; overflow-y: auto; }
.epi { display: flex; gap: 8px; align-items: flex-start; font-size: 12px; color: var(--ink-dim); }
.epi .em { font-size: 20px; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #3a3128; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 900px) {
  #stage { grid-template-columns: 1fr; }
  .feed { display: none; }
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
}
