/* ═══════════════════════════════════════════════════════════════════════════
   SINGULARITY, INC. — core visual system
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  /* Surfaces */
  --bg-0: #05060a;
  --bg-1: #080a10;
  --bg-2: #0c0f17;
  --panel: rgba(255,255,255,0.028);
  --panel-2: rgba(255,255,255,0.045);
  --panel-hi: rgba(255,255,255,0.075);
  --line: rgba(255,255,255,0.075);
  --line-2: rgba(255,255,255,0.13);

  /* Ink */
  --ink: #e8ecf3;
  --ink-2: #a3adbd;
  --ink-3: #6b7686;
  --ink-4: #454e5c;

  /* Accents */
  --green: #00e5a0;
  --cyan: #4dd0e1;
  --violet: #8b5cf6;
  --amber: #f5a623;
  --red: #ff4d5e;
  --pink: #f472b6;
  --blue: #60a5fa;
  --white: #ffffff;

  --green-dim: rgba(0,229,160,0.13);
  --cyan-dim: rgba(77,208,225,0.13);
  --violet-dim: rgba(139,92,246,0.14);
  --amber-dim: rgba(245,166,35,0.13);
  --red-dim: rgba(255,77,94,0.13);

  --radius: 10px;
  --radius-lg: 14px;
  --radius-sm: 6px;

  --font: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', system-ui, sans-serif;
  --mono: ui-monospace, 'SF Mono', 'JetBrains Mono', 'Menlo', 'Consolas', monospace;

  --shadow-1: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-2: 0 4px 20px rgba(0,0,0,0.5);
  --shadow-3: 0 16px 60px rgba(0,0,0,0.65);

  --topbar-h: 58px;
  --nav-w: 202px;
  --feed-w: 330px;
}

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

html, body {
  height: 100%;
  background: var(--bg-0);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  overscroll-behavior: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
a { color: var(--cyan); text-decoration: none; }
::selection { background: rgba(0,229,160,0.28); }

/* Scrollbars */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.10); border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.20); background-clip: padding-box; }

/* ── Background ─────────────────────────────────────────────────────────── */
#bg-layer { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
#bg-canvas { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0.5; }
#bg-layer::before {
  content: ''; position: absolute; inset: 0;
  background:
    radial-gradient(1100px 700px at 12% -8%, rgba(139,92,246,0.13), transparent 62%),
    radial-gradient(900px 620px at 92% 8%, rgba(0,229,160,0.09), transparent 60%),
    radial-gradient(800px 800px at 50% 115%, rgba(77,208,225,0.07), transparent 62%);
}
#bg-layer::after {
  content: ''; position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.014) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.014) 1px, transparent 1px);
  background-size: 52px 52px;
  mask-image: radial-gradient(ellipse 100% 80% at 50% 30%, black, transparent 78%);
}

/* ── App shell ──────────────────────────────────────────────────────────── */
#app { position: relative; z-index: 1; height: 100%; display: flex; flex-direction: column; overflow: hidden; }

.shell {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: var(--nav-w) minmax(0,1fr) var(--feed-w);
}
.shell.no-feed { grid-template-columns: var(--nav-w) minmax(0,1fr); }

/* ── Topbar ─────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 0;
  padding: 0 14px 0 0;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(10,12,18,0.92), rgba(8,10,16,0.78));
  backdrop-filter: blur(18px);
  position: relative; z-index: 40;
}
.brand {
  width: var(--nav-w); flex: 0 0 var(--nav-w);
  display: flex; align-items: center; gap: 9px;
  padding-left: 16px; height: 100%;
  border-right: 1px solid var(--line);
}
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; flex: 0 0 26px;
  display: grid; place-items: center; font-size: 13px;
  background: linear-gradient(135deg, var(--violet), var(--green));
  color: #05060a; font-weight: 800;
  box-shadow: 0 0 18px rgba(139,92,246,0.45);
}
.brand-text { min-width: 0; }
.brand-name {
  font-size: 12.5px; font-weight: 650; letter-spacing: 0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-sub { font-size: 9.5px; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.09em; }

.stat-strip { flex: 1; display: flex; align-items: center; gap: 2px; padding: 0 12px; min-width: 0; overflow: hidden; }
.stat {
  display: flex; flex-direction: column; gap: 1px;
  padding: 4px 13px; border-radius: 8px; min-width: 0;
  transition: background 0.18s;
}
.stat:hover { background: var(--panel); }
.stat-label {
  font-size: 8.5px; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--ink-3); white-space: nowrap; font-weight: 600;
}
.stat-value {
  font-family: var(--mono); font-size: 14.5px; font-weight: 600;
  letter-spacing: -0.02em; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.stat-value.sm { font-size: 12.5px; }
.stat-delta { font-size: 9.5px; font-family: var(--mono); }
.up { color: var(--green); } .down { color: var(--red); } .flat { color: var(--ink-3); }

.time-block { display: flex; align-items: center; gap: 10px; padding-left: 10px; border-left: 1px solid var(--line); }
.speed-group { display: flex; gap: 2px; background: rgba(0,0,0,0.3); padding: 3px; border-radius: 8px; border: 1px solid var(--line); }
.speed-btn {
  min-width: 27px; height: 24px; border-radius: 5px; font-size: 11px;
  font-family: var(--mono); font-weight: 600; color: var(--ink-3);
  transition: all 0.14s; display: grid; place-items: center;
}
.speed-btn:hover { color: var(--ink); background: var(--panel-2); }
.speed-btn.on { background: var(--green); color: #05060a; box-shadow: 0 0 12px rgba(0,229,160,0.4); }
.speed-btn.pause.on { background: var(--amber); box-shadow: 0 0 12px rgba(245,166,35,0.4); }
.speed-btn.next { letter-spacing: -0.08em; }
.speed-btn.next.on { background: var(--cyan); color: #04141a; box-shadow: 0 0 12px rgba(77,208,225,0.4); }

/* ── Nav ────────────────────────────────────────────────────────────────── */
.nav {
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(9,11,17,0.6), rgba(6,7,11,0.45));
  padding: 12px 10px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
}
.nav-section { font-size: 9px; text-transform: uppercase; letter-spacing: 0.13em; color: var(--ink-4);
  padding: 14px 10px 6px; font-weight: 700; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 11px; border-radius: 8px;
  color: var(--ink-2); font-size: 13px; font-weight: 500;
  transition: all 0.14s; position: relative; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--panel); color: var(--ink); }
.nav-item.on { background: var(--panel-2); color: var(--ink); }
.nav-item.on::before {
  content: ''; position: absolute; left: -10px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 17px; border-radius: 0 3px 3px 0; background: var(--green);
  box-shadow: 0 0 10px var(--green);
}
.nav-item.locked { opacity: 0.32; cursor: not-allowed; }
.nav-icon { width: 17px; text-align: center; font-size: 14px; opacity: 0.85; }
.nav-badge {
  margin-left: auto; min-width: 17px; height: 17px; padding: 0 5px;
  border-radius: 9px; background: var(--red); color: #fff;
  font-size: 9.5px; font-weight: 700; display: grid; place-items: center;
  font-family: var(--mono); box-shadow: 0 0 10px rgba(255,77,94,0.5);
}
.nav-badge.soft { background: var(--panel-hi); color: var(--ink-2); box-shadow: none; }
.nav-spacer { flex: 1; }

.act-card {
  margin-top: 10px; padding: 11px; border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(139,92,246,0.10), rgba(0,229,160,0.05));
  border: 1px solid var(--line);
}
.act-num { font-family: var(--mono); font-size: 10px; color: var(--violet); letter-spacing: 0.14em; font-weight: 700; }
.act-name { font-size: 13px; font-weight: 620; margin-top: 2px; }
.act-goal { font-size: 10.5px; color: var(--ink-3); margin-top: 6px; line-height: 1.42; }

/* ── Main ───────────────────────────────────────────────────────────────── */
.main { overflow-y: auto; overflow-x: hidden; padding: 20px 24px 60px; min-width: 0; max-width: 100%; scroll-behavior: smooth; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.view-title { font-size: 21px; font-weight: 660; letter-spacing: -0.02em; }
.view-sub { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }

/* ── Feed rail ──────────────────────────────────────────────────────────── */
.feed-rail {
  border-left: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(9,11,17,0.5), rgba(6,7,11,0.35));
  display: flex; flex-direction: column; min-height: 0;
}
.feed-head {
  padding: 12px 14px 10px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px; flex: 0 0 auto;
}
.feed-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-3); font-weight: 700; }
.live-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--red); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; box-shadow: 0 0 0 0 rgba(255,77,94,0.6);} 50% { opacity: 0.5; box-shadow: 0 0 0 5px rgba(255,77,94,0);} }
.feed-list { flex: 1; overflow-y: auto; padding: 8px 10px 24px; display: flex; flex-direction: column; gap: 6px; }

/* ── Utility ────────────────────────────────────────────────────────────── */
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.dim { color: var(--ink-3); }
.dimmer { color: var(--ink-4); }
.tiny { font-size: 10.5px; }
.small { font-size: 12px; }
.bold { font-weight: 650; }
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.center { align-items: center; }
.g4 { gap: 4px } .g6 { gap: 6px } .g8 { gap: 8px } .g10 { gap: 10px } .g12 { gap: 12px } .g16 { gap: 16px }
.mt4{margin-top:4px}.mt8{margin-top:8px}.mt12{margin-top:12px}.mt16{margin-top:16px}.mt24{margin-top:24px}
.mb8{margin-bottom:8px}.mb12{margin-bottom:12px}.mb16{margin-bottom:16px}
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.c-green{color:var(--green)}.c-cyan{color:var(--cyan)}.c-violet{color:var(--violet)}
.c-amber{color:var(--amber)}.c-red{color:var(--red)}.c-pink{color:var(--pink)}.c-blue{color:var(--blue)}
.c-ink{color:var(--ink)}

@media (max-width: 1300px) { :root { --feed-w: 288px; } }
@media (max-width: 1120px) {
  .shell { grid-template-columns: var(--nav-w) minmax(0,1fr); }
  .feed-rail { display: none; }
}
@media (max-width: 860px) {
  :root { --nav-w: 60px; }
  .brand-text { display: none; }
  .nav-item span:not(.nav-icon):not(.nav-badge) { display: none; }
  .nav-item { justify-content: center; }
  .act-card { display: none; }
  .main { padding: 14px; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════════════════ */
.split-main { grid-template-columns: minmax(0,1.35fr) minmax(0,1fr); gap: 14px; }
.split-side { grid-template-columns: minmax(0,1fr) minmax(0,340px); gap: 14px; }
.split-left { grid-template-columns: minmax(0,340px) minmax(0,1fr); gap: 14px; }

@media (max-width: 1180px) {
  .split-main, .split-side, .split-left { grid-template-columns: minmax(0,1fr); }
}

/* Tablet: hide the feed rail, keep the icon nav */
@media (max-width: 1120px) {
  .shell { grid-template-columns: var(--nav-w) minmax(0,1fr); }
  .feed-rail { display: none; }
}

/* Narrow: icon-only nav, scrollable stat strip */
@media (max-width: 900px) {
  :root { --nav-w: 56px; --topbar-h: 54px; }
  .brand { width: var(--nav-w); flex: 0 0 var(--nav-w); padding-left: 0; justify-content: center; }
  .brand-text { display: none; }
  .nav-item > span:not(.nav-icon) { display: none; }
  .nav-item { justify-content: center; padding: 9px 0; }
  .nav-item .nav-badge { position: absolute; top: 3px; right: 5px; min-width: 14px; height: 14px; font-size: 8px; padding: 0 3px; }
  .nav-section { text-align: center; font-size: 8px; padding: 10px 0 4px; letter-spacing: 0.06em; }
  .act-card { display: none; }
  .main { padding: 14px 12px 70px; }
  .stat-strip { gap: 0; padding: 0 4px; overflow-x: auto; scrollbar-width: none; }
  .stat-strip::-webkit-scrollbar { display: none; }
  .stat { padding: 3px 9px; }
  .stat-value { font-size: 13px; }
  .stat-value.sm { font-size: 11.5px; }
  .stat-label { font-size: 7.5px; }
  .time-block { padding-left: 6px; gap: 6px; }
  .speed-btn { min-width: 23px; height: 22px; font-size: 10px; }
  .view-title { font-size: 18px; }
  .view-sub { font-size: 11.5px; }
  #toast-root { left: calc(var(--nav-w) + 8px); right: 8px; bottom: 10px; max-width: none; }
  .modal { border-radius: 14px; max-height: 92vh; }
  .modal-top { padding: 15px 17px 12px; }
  .modal-body { padding: 16px 17px; }
  .modal-choices { padding: 4px 13px 14px; }
  .event-title { font-size: 18px; }
  .event-body { font-size: 13.5px; line-height: 1.66; }
  .ending-inner { padding: 40px 16px 90px; }
  .alloc-row { grid-template-columns: 88px 1fr 40px; gap: 8px; }
  .tier-nodes { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .tier-label { display: none; }
}

/* Phone: everything single column, bigger tap targets */
@media (max-width: 620px) {
  .modal-backdrop { padding: 10px; }
  .grid-2, .grid-3, .grid-4, .grid-auto, .grid-auto-lg { grid-template-columns: minmax(0,1fr); }
  .rival-row { grid-template-columns: 1fr auto; gap: 8px 12px; }
  .action-btn { padding: 12px 13px; }
  .btn { padding: 9px 14px; }
  .panel-body { padding: 13px; }
  .panel-head { padding: 11px 13px; }
  .ending-title { font-size: 30px; }
  .setup { padding: 26px 14px 60px; }
  .setup-title { font-size: 26px; }
  .branch-tab { padding: 6px 10px; font-size: 12px; }
}

/* Short viewports: trim vertical chrome */
@media (max-height: 620px) {
  :root { --topbar-h: 50px; }
  .main { padding-top: 12px; }
}

/* Topbar on narrow screens: give the numbers room, trim the chrome */
@media (max-width: 900px) {
  .stat { flex: 0 0 auto; }
  .time-block .col { display: none; }
  .speed-btn:nth-child(3), .speed-btn:nth-child(5) { display: none; }
  .brand-mark { width: 24px; height: 24px; flex: 0 0 24px; font-size: 12px; }
}
@media (max-width: 700px) {
  .stat-strip .stat:nth-child(n+4) { display: none; }
}
.brand-day { display: none; font-size: 10px; color: var(--ink-4); }
@media (max-width: 900px) { .brand-day { display: block; } .brand { gap: 4px; } }

/* ── Scene grade ─────────────────────────────────────────────────────────── */
/* A faint vignette and grain over the whole app: it reads as a scene rather
   than a page, and it costs one composited layer. */
#app::after {
  content: ''; position: fixed; inset: 0; z-index: 60; pointer-events: none;
  background:
    radial-gradient(ellipse 130% 105% at 50% 45%, transparent 52%, rgba(0,0,0,0.42) 100%),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.011) 0 1px, transparent 1px 3px);
  mix-blend-mode: normal;
}
html.reduced-motion #app::after { background: radial-gradient(ellipse 130% 105% at 50% 45%, transparent 60%, rgba(0,0,0,0.30) 100%); }

/* The game fades up out of the curtain rather than snapping in. */
#app.booting .shell { animation: bootIn 1.1s cubic-bezier(.16,1,.3,1) both; }
#app.booting .topbar { animation: bootIn 1.1s .12s cubic-bezier(.16,1,.3,1) both; }
@keyframes bootIn { from { opacity: 0; transform: translateY(10px); filter: blur(6px); } to { opacity: 1; } }
