/* ============================================================================
   DDoS Tycoon — design system
   Tokens reverse-engineered from terabit.io/ddos-protection/game:
   light theme, #f5f7fb canvas, glassmorphic surfaces, blue/cyan accents,
   .625rem radii, 0 18px 48px shadows, Space Grotesk + DM Sans + mono numerals.
   ========================================================================== */

:root {
  --bg: #f5f7fb;
  --surface: rgba(255, 255, 255, 0.9);
  --surface-solid: #ffffff;
  --surface-2: #eef2f9;
  --border: #dfe6f2;
  --border-strong: #c9d5ea;
  --ink: #0f1b2d;
  --ink-2: #44546a;
  --ink-3: #7c8aa0;
  --blue: #2563eb;
  --blue-soft: #dbe7ff;
  --cyan: #06b6d4;
  --cyan-soft: #d3f3f8;
  --purple: #a855f7;
  --purple-soft: #ecdcfb;
  --orange: #ea580c; /* reserved for upstreams / transit, as in the original */
  --orange-soft: #fde3d2;
  --green: #059669;
  --green-soft: #d3f2e4;
  --red: #dc2626;
  --red-soft: #fbe0e0;
  --amber: #d97706;
  --amber-soft: #fdedc8;
  --ocean: #e9eef7;
  --land: #c7d5e9;
  --marker: #0284c7;
  --radius: 0.625rem;
  --radius-lg: 1rem;
  --shadow: 0 18px 48px rgba(15, 27, 45, 0.12);
  --shadow-sm: 0 6px 18px rgba(15, 27, 45, 0.08);
  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------------------
   layout
   ------------------------------------------------------------------------- */
#app { display: flex; flex-direction: column; height: 100vh; }

#topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.55rem 1rem;
  background: var(--surface);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  z-index: 40;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 0.55rem; font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; }
.brand .dot { width: 12px; height: 12px; border-radius: 50%; background: linear-gradient(135deg, var(--blue), var(--cyan)); box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12); }
.brand small { display: block; font-family: var(--font-body); font-weight: 500; font-size: 0.66rem; color: var(--ink-3); letter-spacing: 0.04em; text-transform: uppercase; }

.stat { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.stat .k { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-3); font-weight: 600; }
.stat .v { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 600; font-size: 0.95rem; }
.stat .v small { font-size: 0.68rem; color: var(--ink-3); font-weight: 500; }
.stat.pos .v { color: var(--green); }
.stat.neg .v { color: var(--red); }
.tb-sep { width: 1px; height: 28px; background: var(--border); }

.spacer { flex: 1; }

.speed-group { display: flex; gap: 0.2rem; background: var(--surface-2); padding: 0.2rem; border-radius: var(--radius); border: 1px solid var(--border); }
.speed-group button { border: 0; background: transparent; padding: 0.28rem 0.55rem; border-radius: 0.4rem; font-size: 0.75rem; font-weight: 600; color: var(--ink-2); }
.speed-group button.on { background: var(--blue); color: #fff; box-shadow: var(--shadow-sm); }

#alertbar {
  display: none;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 1rem;
  background: linear-gradient(90deg, #fff1f2, #fff7f8);
  border-bottom: 1px solid #f6c9c9;
  color: var(--red);
  font-weight: 600;
  font-size: 0.82rem;
}
#alertbar.show { display: flex; }
#alertbar .pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--red); animation: blink 0.9s infinite; }

#main { flex: 1; display: flex; min-height: 0; }

#rail {
  width: 196px;
  background: var(--surface);
  backdrop-filter: blur(14px);
  border-right: 1px solid var(--border);
  padding: 0.6rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  overflow-y: auto;
  flex-shrink: 0;
}
.rail-btn {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.83rem;
  color: var(--ink-2);
}
.rail-btn:hover { background: var(--surface-2); }
.rail-btn.on { background: var(--blue-soft); color: var(--blue); }
.rail-btn .ico { width: 18px; text-align: center; }
.rail-btn .badge { margin-left: auto; background: var(--red); color: #fff; font-size: 0.62rem; font-weight: 700; border-radius: 999px; padding: 0.05rem 0.36rem; min-width: 17px; text-align: center; }
.rail-btn .badge.calm { background: var(--cyan); }

#workspace { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#panel { flex: 1; overflow-y: auto; padding: 1rem 1.1rem 2rem; }
#mapwrap { flex: 1.08; min-height: 0; position: relative; background: var(--ocean); border-top: 1px solid var(--border); }
#map { width: 100%; height: 100%; display: block; }
#map .land { fill: var(--land); stroke: #ffffff; stroke-width: 0.4; }
#map .graticule { stroke: #d5deed; stroke-width: 0.3; fill: none; }
#map .link-up { stroke: var(--orange); stroke-width: 1.1; opacity: 0.45; stroke-dasharray: 3 3; }
#map .link-bb { stroke: var(--purple); stroke-width: 1.6; opacity: 0.75; }
#map .arc { fill: none; stroke: var(--red); stroke-width: 1.8; opacity: 0.85; stroke-dasharray: 5 7; animation: arcflow 0.8s linear infinite; }
#map .arc.sec { stroke: var(--amber); opacity: 0.65; }
@keyframes arcflow { to { stroke-dashoffset: -12; } }
#map .marker { fill: var(--marker); stroke: #fff; stroke-width: 1; cursor: pointer; }
#map .marker.hq { fill: var(--purple); }
#map .marker.bad { fill: var(--red); animation: blink 0.9s infinite; }
#map .marker.warn { fill: var(--amber); }
#map .marker.dead { fill: #9aa8bd; }
#map .botnet-origin { fill: var(--red); opacity: 0.55; }
#map .marker-label { font-family: var(--font-body); font-size: 7px; fill: var(--ink-2); pointer-events: none; }
#map .tooltip { font-family: var(--font-body); font-size: 10px; fill: var(--ink); }
@keyframes blink { 50% { opacity: 0.25; } }

/* ---------------------------------------------------------------------------
   panels & cards
   ------------------------------------------------------------------------- */
.panel-head { display: flex; align-items: baseline; gap: 0.6rem; margin-bottom: 0.8rem; flex-wrap: wrap; }
.panel-head h2 { font-family: var(--font-display); font-size: 1.3rem; letter-spacing: -0.02em; }
.panel-head p { color: var(--ink-3); font-size: 0.8rem; }

.card {
  background: var(--surface);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 0.85rem 0.95rem;
  margin-bottom: 0.7rem;
}
.card h3 { font-family: var(--font-display); font-size: 0.98rem; margin-bottom: 0.15rem; display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap; }
.card .sub { color: var(--ink-3); font-size: 0.74rem; margin-bottom: 0.55rem; }
.grid { display: grid; gap: 0.7rem; }
.grid.c2 { grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }

.row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.row.tight { gap: 0.3rem; }
.muted { color: var(--ink-3); }
.tiny { font-size: 0.7rem; }
.right { margin-left: auto; }
.nowrap { white-space: nowrap; }

.btn {
  border: 1px solid var(--border-strong);
  background: var(--surface-solid);
  padding: 0.36rem 0.7rem;
  border-radius: var(--radius);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(15, 27, 45, 0.05);
}
.btn:hover { border-color: var(--blue); color: var(--blue); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #1d4ed8; color: #fff; }
.btn.danger { border-color: #f1b6b6; color: var(--red); }
.btn.danger:hover { background: var(--red-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.xs { padding: 0.2rem 0.45rem; font-size: 0.68rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.pill { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.68rem; font-weight: 700; padding: 0.14rem 0.5rem; border-radius: 999px; border: 1px solid transparent; text-transform: uppercase; letter-spacing: 0.04em; }
.pill.ok { background: var(--green-soft); color: var(--green); }
.pill.warn { background: var(--amber-soft); color: var(--amber); }
.pill.bad { background: var(--red-soft); color: var(--red); }
.pill.info { background: var(--blue-soft); color: var(--blue); }
.pill.cyan { background: var(--cyan-soft); color: #0e7490; }
.pill.purple { background: var(--purple-soft); color: var(--purple); }
.pill.orange { background: var(--orange-soft); color: var(--orange); }
.pill.grey { background: var(--surface-2); color: var(--ink-3); }

.bar { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--blue), var(--cyan)); }
.bar > i.warn { background: linear-gradient(90deg, var(--amber), #fbbf24); }
.bar > i.bad { background: linear-gradient(90deg, var(--red), #f87171); }

table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
th { text-align: left; font-size: 0.64rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); padding: 0.3rem 0.4rem; border-bottom: 1px solid var(--border); }
td { padding: 0.35rem 0.4rem; border-bottom: 1px solid #edf1f8; }
tr:hover td { background: #f6f9fd; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 0.7rem; font-size: 0.78rem; }
.kv dt { color: var(--ink-3); }
.kv dd { font-family: var(--font-mono); text-align: right; }

/* research tree */
.branch { margin-bottom: 0.9rem; }
.branch > h4 { font-family: var(--font-display); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-2); margin-bottom: 0.4rem; display: flex; gap: 0.5rem; align-items: center; }
.nodes { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 0.55rem; }
.node { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem 0.65rem; background: var(--surface-solid); }
.node.done { border-color: #a7d8bd; background: #f4fcf7; }
.node.affordable { border-color: #bfd4fb; box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.08); }
.node.locked { opacity: 0.55; }
.node h5 { font-size: 0.82rem; font-family: var(--font-display); }
.node p { font-size: 0.7rem; color: var(--ink-3); margin: 0.2rem 0 0.4rem; }

/* log */
.log-entry { display: flex; gap: 0.55rem; padding: 0.28rem 0; border-bottom: 1px solid #eef2f9; font-size: 0.76rem; }
.log-entry .t { font-family: var(--font-mono); color: var(--ink-3); flex-shrink: 0; font-size: 0.7rem; padding-top: 0.05rem; }
.log-entry.good .text { color: #0b7a4f; }
.log-entry.bad .text { color: var(--red); }
.log-entry.warn .text { color: var(--amber); }
.log-entry.attack .text { color: var(--purple); font-weight: 600; }

/* toasts */
#toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: 0.4rem; z-index: 200; pointer-events: none; }
.toast {
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.55rem 0.8rem;
  font-size: 0.8rem;
  font-weight: 600;
  animation: toastin 0.25s ease-out;
  max-width: 320px;
}
.toast.good { border-left-color: var(--green); }
.toast.bad { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--amber); }
@keyframes toastin { from { transform: translateX(30px); opacity: 0; } }

/* modal */
#modal-back { position: fixed; inset: 0; background: rgba(15, 27, 45, 0.42); backdrop-filter: blur(3px); display: none; align-items: center; justify-content: center; z-index: 300; }
#modal-back.show { display: flex; }
#modal { background: var(--surface-solid); border-radius: var(--radius-lg); box-shadow: var(--shadow); width: min(560px, 92vw); max-height: 84vh; overflow-y: auto; padding: 1.3rem; }
#modal h3 { font-family: var(--font-display); font-size: 1.15rem; margin-bottom: 0.4rem; }
#modal p { color: var(--ink-2); font-size: 0.85rem; margin-bottom: 0.9rem; line-height: 1.5; }
#modal .options { display: flex; gap: 0.5rem; flex-wrap: wrap; }

#booting { position: fixed; inset: 0; background: var(--bg); display: none; align-items: center; justify-content: center; z-index: 400; font-family: var(--font-display); color: var(--ink-2); }
#booting.show { display: flex; }

.empty { text-align: center; color: var(--ink-3); padding: 2.4rem 1rem; font-size: 0.85rem; }
.empty .big { font-size: 2rem; margin-bottom: 0.4rem; }

.status-board { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0.7rem; }
.status-tile { background: var(--surface-solid); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 0.8rem 0.9rem; box-shadow: var(--shadow-sm); }
.status-tile .k { font-size: 0.64rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-3); font-weight: 600; }
.status-tile .v { font-family: var(--font-display); font-size: 1.35rem; margin-top: 0.15rem; }

select, input[type='text'], input[type='number'] {
  border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 0.3rem 0.45rem; font-size: 0.78rem; background: #fff;
}
label.check { display: flex; align-items: center; gap: 0.35rem; font-size: 0.78rem; }

.legend { display: flex; gap: 0.9rem; flex-wrap: wrap; font-size: 0.68rem; color: var(--ink-2); padding: 0.35rem 1rem; background: var(--surface); border-top: 1px solid var(--border); }
.legend span { display: inline-flex; align-items: center; gap: 0.3rem; }
.legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

@media (max-width: 900px) {
  #rail { width: 56px; }
  .rail-btn { justify-content: center; padding: 0.5rem 0; }
  .rail-btn .label, .rail-btn .badge { display: none; }
  #mapwrap { min-height: 240px; }
}
