/* The renderer owns appearance. Nothing in sim/ knows any of these values
   exist, which is the whole reason the art can be replaced without touching the
   game. */

:root {
  --bg:        #0d1015;
  --panel:     #151a22;
  --panel-2:   #1b2029;
  --line:      #262d38;
  --ink:       #e6ebf2;
  --ink-2:     #9aa7b8;
  --ink-3:     #6b788a;

  --good:      #58d68d;
  --warn:      #f5c451;
  --bad:       #ff6b6b;
  --good:      #58d68d;
  --accent:    #4ea3ff;

  --f0: #4ea3ff;
  --f1: #ff8a3d;
  --f2: #58d68d;
  --f3: #c58af9;
  --f4: #f5d76e;
  --f5: #ff6b6b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--ink);
  font: 14px/1.45 ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; flex-direction: column; height: 100%; }

/* ---- top bar ---- */

#bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: var(--panel);
  border-bottom: 1px solid var(--line); flex: 0 0 auto;
}
.brand { font-weight: 700; letter-spacing: .06em; font-size: 15px; }
.brand .thin { font-weight: 300; color: var(--ink-2); margin-left: 2px; }
.spacer { flex: 1; }

.pill {
  padding: 2px 9px; border-radius: 999px; background: var(--panel-2);
  border: 1px solid var(--line); font-variant-numeric: tabular-nums;
  font-size: 12px;
}
.pill.dim { color: var(--ink-3); }
.pill.shared { color: var(--warn, #f5c451); border-color: #4a3f22; }
.btn:disabled, input:disabled { opacity: .38; cursor: not-allowed; }

.btn {
  background: var(--panel-2); color: var(--ink); border: 1px solid var(--line);
  padding: 5px 12px; border-radius: 7px; cursor: pointer; font: inherit;
  font-size: 13px;
}
.btn:hover { border-color: #3a444f; background: #222835; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06203a; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 3px 9px; font-size: 12px; }

.speed { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--ink-2); }
.speed input { width: 110px; accent-color: var(--accent); }
#speedval { min-width: 30px; font-variant-numeric: tabular-nums; }

/* ---- layout ---- */

main { flex: 1; display: flex; min-height: 0; min-width: 0; }

/* The canvas is positioned out of the flex flow on purpose. A canvas gets an
   intrinsic size from its width/height attributes, so as a plain flex child it
   grows to its own bitmap width, shoves the sidebar off screen, and the next
   resize measures the larger box and grows it again. Absolute inside a relative
   stage means the layout drives the bitmap and never the other way round. */
#stage { flex: 1 1 auto; min-width: 0; min-height: 0; position: relative; }
#view { position: absolute; inset: 0; width: 100%; height: 100%;
        display: block; cursor: grab; background: #0a0d11; }
#view.dragging { cursor: grabbing; }
#view.over { cursor: pointer; }

/* Hover card. Pointer-events off so it can sit under the cursor without
   stealing the very hover that summoned it. */
#tip {
  position: absolute; z-index: 5; pointer-events: none;
  max-width: 268px; padding: 9px 11px;
  background: rgba(15,19,26,.96); border: 1px solid var(--line);
  border-left: 3px solid var(--tipc, var(--accent));
  border-radius: 9px; box-shadow: 0 8px 26px rgba(0,0,0,.5);
  font-size: 12.5px; line-height: 1.45;
}
#tip[hidden] { display: none; }
#tip .t-name { font-weight: 650; color: var(--tipc, var(--ink)); }
#tip .t-who { color: var(--ink-3); font-size: 11.5px; margin-left: 6px; }
#tip .t-sub { color: var(--ink-2); margin-top: 2px; }
#tip .t-bar {
  height: 4px; background: #0e1218; border-radius: 3px;
  overflow: hidden; margin: 6px 0 4px;
}
#tip .t-bar i { display: block; height: 100%; background: var(--good); }
#tip .t-bar i.mid { background: var(--warn); }
#tip .t-bar i.low { background: var(--bad); }
#tip dl {
  margin: 5px 0 0; display: grid; grid-template-columns: auto 1fr;
  gap: 1px 9px; font-size: 11.5px;
}
#tip dt { color: var(--ink-3); }
#tip dd { margin: 0; color: var(--ink-2); font-variant-numeric: tabular-nums; }
#tip .t-warn { color: var(--bad); font-weight: 600; }

#side {
  width: 320px; flex: 0 0 320px; background: var(--panel);
  border-left: 1px solid var(--line); overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px; padding: 10px;
}

.panel {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 9px; padding: 10px 11px;
}
.panel h3 {
  margin: 0 0 7px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .08em; color: var(--ink-3); font-weight: 600;
}
.muted { color: var(--ink-2); }
.small { font-size: 12px; }

/* ---- faction cards ---- */

.fac {
  background: var(--panel-2); border: 1px solid var(--line);
  border-left: 3px solid var(--fc, var(--accent));
  border-radius: 9px; padding: 9px 11px; margin-bottom: 8px;
}
.fac.dead { opacity: .45; }
.fac header {
  display: flex; align-items: baseline; gap: 7px; margin-bottom: 6px;
}
.fac .name { font-weight: 600; color: var(--fc); }
.fac .sup { margin-left: auto; font-size: 12px; color: var(--ink-2);
            font-variant-numeric: tabular-nums; }

.res { display: grid; grid-template-columns: 1fr auto auto; gap: 1px 8px;
       font-size: 12px; font-variant-numeric: tabular-nums; }
.res .k { color: var(--ink-2); }
.res .v { text-align: right; }
.res .r { text-align: right; width: 54px; }
.res .r.up { color: var(--good); }
.res .r.down { color: var(--warn); }
.res .r.crit { color: var(--bad); font-weight: 600; }
.res .bar { grid-column: 1 / -1; height: 3px; background: #0f131a;
            border-radius: 2px; overflow: hidden; margin: 1px 0 3px; }
.res .bar i { display: block; height: 100%; background: var(--fc); }
.res .bar i.crit { background: var(--bad); }

.alarm {
  margin-top: 7px; padding: 5px 8px; border-radius: 6px;
  background: rgba(255,107,107,.13); border: 1px solid rgba(255,107,107,.35);
  color: #ffb0b0; font-size: 12px;
}
.shed {
  margin-top: 5px; font-size: 11px; color: var(--warn);
}

/* ---- events ---- */

#events { list-style: none; margin: 0; padding: 0; max-height: 210px;
          overflow-y: auto; font-size: 12px; }
#events li { padding: 3px 0; border-bottom: 1px solid #1e242e;
             display: flex; gap: 7px; }
#events li:last-child { border-bottom: 0; }
#events .t { color: var(--ink-3); font-variant-numeric: tabular-nums;
             flex: 0 0 42px; }
#events .built   { color: var(--good); }
#events .trained { color: var(--ink-2); }
#events .destroyed, #events .unit_lost { color: var(--bad); }
#events .deficit { color: var(--warn); }
#events .defeated, #events .game_over { color: var(--accent); font-weight: 600; }

/* ---- detail ---- */

#detail dl { margin: 0; display: grid; grid-template-columns: auto 1fr;
             gap: 2px 10px; font-size: 12px; }
#detail dt { color: var(--ink-3); }
#detail dd { margin: 0; font-variant-numeric: tabular-nums; }
#detail h3 { color: var(--ink); font-size: 13px; text-transform: none;
             letter-spacing: 0; }

/* ---- setup modal ---- */

#setup {
  position: fixed; inset: 0; display: none; align-items: center;
  justify-content: center; background: rgba(6,8,11,.82); backdrop-filter: blur(3px);
  z-index: 20;
}
#setup.open { display: flex; }
#setup form {
  background: var(--panel); border: 1px solid var(--line); border-radius: 13px;
  padding: 20px 22px; width: min(460px, 92vw); max-height: 88vh; overflow-y: auto;
}
#setup h2 { margin: 0 0 14px; font-size: 18px; }
#setup label { display: block; margin-bottom: 12px; font-size: 12px;
               color: var(--ink-2); }
#setup small { display: block; color: var(--ink-3); margin-top: 3px; }
#setup select, #setup input[type=number], #setup input[type=text] {
  width: 100%; margin-top: 4px; background: var(--panel-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px;
  font: inherit; font-size: 13px;
}
.slotrow { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.slotrow .dot { width: 11px; height: 11px; border-radius: 3px; flex: 0 0 auto; }
.slotrow select { flex: 1; margin-top: 0; }
.slotrow .rm { color: var(--ink-3); cursor: pointer; padding: 0 5px;
               background: none; border: 0; font-size: 16px; }
.lr-blurb { color: var(--ink-3); font-size: 11.5px; margin: -3px 0 9px 21px; }
.actions { margin-top: 16px; display: flex; justify-content: flex-end; gap: 8px; }

/* Matches already running, listed inside the dialog. */
#livelist { margin-bottom: 14px; }
.liverow {
  display: flex; align-items: center; gap: 9px; padding: 7px 9px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; margin-bottom: 6px; font-size: 12.5px;
}
.liverow .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--good, #58d68d);
  flex: 0 0 auto;
}
.liverow .dot.live { animation: pulse 2.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }
.liverow .lr-name { font-weight: 650; letter-spacing: .04em; }
.liverow .lr-meta { color: var(--ink-3); flex: 1; }
@media (prefers-reduced-motion: reduce) { .liverow .dot.live { animation: none } }

header#bar a.btn { text-decoration: none; line-height: 1.5; }

/* ---- narrow ---- */

@media (max-width: 860px) {
  main { flex-direction: column; }
  #side { width: auto; flex: 0 0 46%; border-left: 0; border-top: 1px solid var(--line); }
}
