/* Rackplain — mobile-first. < 1000px: one pane at a time + bottom nav. >= 1000px: 3 columns, no nav. */
:root {
  --bg: #0d1117; --panel: #161b22; --raised: #21262d; --line: #30363d; --text: #e6edf3; --muted: #9da7b3;
  --accent: #3fb950; --accent2: #58a6ff; --warn: #f0883e; --bad: #ff6b61; --gold: #e3b341;
  --tap: 44px; --nav-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--nav-h) + var(--safe-b)); -webkit-tap-highlight-color: transparent; }
h2 { margin: 0 0 8px; font-size: 15px; }
h2 small { color: var(--muted); font-weight: 400; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 8px; top: -60px; z-index: 50; background: var(--accent2); color: #04121f; padding: 12px 16px; border-radius: 6px; font-weight: 700; }
.skip:focus { top: 8px; }
.muted { color: var(--muted); font-size: 13px; }

/* ---------- header ---------- */
header { position: sticky; top: 0; z-index: 20; background: #0f141b; border-bottom: 1px solid var(--line);
  padding: 6px 10px 4px; padding-top: max(6px, env(safe-area-inset-top, 0px)); }
.topline { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 32px; }
.brand { font-weight: 800; font-size: 17px; white-space: nowrap; }
.brand small { display: none; color: var(--muted); font-weight: 400; margin-left: 6px; font-size: 13px; }
.logo { color: var(--accent); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.stat { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; text-align: left;
  min-height: var(--tap); padding: 2px 8px; background: transparent; border: 1px solid transparent; border-radius: 6px; }
.stat:hover { border-color: var(--line); }
.stat .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat b { font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat.wide { display: none; }
.warn-top { margin: 2px 0 2px; font-size: 13px; color: var(--warn); font-weight: 600; }
.warn-top:empty { display: none; }
.chip { min-height: var(--tap); min-width: var(--tap); padding: 4px 10px; border-radius: 18px; border: 1px solid #6b5a1e;
  background: #2a2410; color: #ffd866; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- panes ---------- */
main { padding: 10px; }
.pane { display: none; }
.pane.active { display: block; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.row.center { justify-content: center; }

/* ---------- controls ---------- */
button, .filebtn, select { font: inherit; color: var(--text); background: var(--raised); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px; min-height: var(--tap); min-width: var(--tap); cursor: pointer; touch-action: manipulation; }
.filebtn { display: inline-flex; align-items: center; }
button:hover:not(:disabled), .filebtn:hover { border-color: var(--accent2); }
button:disabled { color: var(--muted); background: var(--panel); border-style: dashed; cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--accent2); outline-offset: 2px; }
input[type=file]:focus-visible + .filebtn, .filebtn:focus-within { outline: 3px solid var(--accent2); outline-offset: 2px; }
button.primary { background: #1f6f3a; border-color: #2ea043; color: #fff; font-weight: 700; }
button.primary:disabled { background: var(--panel); color: var(--muted); border-color: var(--line); }
button.danger { color: var(--bad); }
button.link { background: none; border-color: transparent; color: var(--muted); text-decoration: underline; }
button.big { display: block; width: 100%; padding: 16px; font-size: 19px; font-weight: 800; margin-bottom: 10px; color: #fff;
  background: linear-gradient(135deg, #1f6f3a, #1b4f8a); border: none; border-radius: 12px; transition: transform .05s; }
button.big:active { transform: scale(.98); }
button.big small { font-weight: 500; font-size: 14px; }
label { font-size: 14px; }
textarea { width: 100%; margin-top: 6px; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  font: 12px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; padding: 8px; }

/* ---------- facility ---------- */
.meter { display: grid; grid-template-columns: 78px 1fr auto; align-items: center; gap: 8px; margin: 8px 0; font-size: 13px; }
.bar { height: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.bar i.hot { background: var(--bad); }
.bar i.warm { background: var(--warn); }
.meter em { font-style: normal; color: var(--muted); font-variant-numeric: tabular-nums; }
.warn { color: var(--warn); font-size: 13px; min-height: 1em; margin: 4px 0 0; }
.hall { display: flex; flex-wrap: wrap; gap: 4px; max-height: 220px; overflow: auto; }
.rack { width: 22px; border: 1px solid #3a4250; border-radius: 3px; padding: 2px; background: #0b0f14; display: flex; flex-direction: column-reverse; gap: 1px; }
.rack i { display: block; height: 4px; border-radius: 1px; background: #1c222b; }
.rack i.on { box-shadow: 0 0 3px currentColor; }
.hall .more { color: var(--muted); font-size: 12px; align-self: center; }

/* ---------- shop ---------- */
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.tabs button[aria-selected="true"] { border-color: var(--accent); color: var(--accent); background: #12261a; font-weight: 700; }
.qtyrow { display: flex; gap: 6px; align-items: center; justify-content: flex-end; margin-bottom: 8px; }
.qtyrow .qty[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: #12261a; font-weight: 700; }
.shop { display: grid; gap: 8px; }
.item { display: grid; grid-template-columns: 8px 1fr auto; gap: 10px; align-items: center; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 10px 10px 8px; }
.item.locked h3 { color: var(--muted); font-style: italic; }
.item .swatch { width: 8px; align-self: stretch; min-height: 40px; border-radius: 3px; }
.item h3 { margin: 0; font-size: 15px; }
.item .meta { color: var(--muted); font-size: 13px; }
.item .side { display: flex; align-items: center; gap: 8px; }
.item .own { font-size: 20px; font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 2ch; text-align: right; }
.item .buy { min-width: 96px; text-align: center; font-variant-numeric: tabular-nums; }
.item .buy:not(:disabled) { border-color: #2ea043; }

/* ---------- upgrades / log / achievements ---------- */
.upgrades { display: grid; gap: 6px; }
.upg { text-align: left; display: block; width: 100%; }
.upg b { display: block; }
.upg span { color: var(--muted); font-size: 13px; }
.upg.affordable { border-color: var(--accent); background: #12261a; }
.log { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow: auto; font-size: 13px; color: var(--muted); }
.log li { padding: 3px 0; border-bottom: 1px dashed #262d36; }
.ach { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.ach li { display: grid; grid-template-columns: 28px 1fr; gap: 6px; align-items: center; padding: 6px 8px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); font-size: 13px; }
.ach li b { display: block; font-size: 13px; }
.ach li span { color: var(--muted); font-size: 12px; }
.ach li.got { border-color: #6b5a1e; background: #1d1a0e; }
.ach li .ic { font-size: 20px; text-align: center; }
.ach li:not(.got) .ic { filter: grayscale(1); opacity: .5; }
.boost { border-color: #6b5a1e; }

/* ---------- bottom nav (phones / tablets) ---------- */
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(4, 1fr);
  background: #0f141b; border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.bottom-nav button { position: relative; height: var(--nav-h); border: none; border-radius: 0; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 13px; padding: 4px; }
.bottom-nav button span { font-size: 19px; }
.bottom-nav button[aria-current="page"] { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); font-weight: 700; }
.bottom-nav .dot { position: absolute; top: 8px; right: calc(50% - 22px); width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }

/* ---------- overlays ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 16px; }
.modal[hidden] { display: none; }
.modal-body { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; max-width: 400px; width: 100%;
  max-height: calc(100vh - 32px); overflow: auto; text-align: center; }
.modal-body h2 { font-size: 19px; }
.modal-body kbd { display: inline-block; min-width: 26px; padding: 2px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; background: var(--bg); font: 13px ui-monospace, monospace; }
.modal-body table { margin: 0 auto; text-align: left; border-spacing: 10px 4px; }
.coach { position: fixed; z-index: 30; left: 10px; right: 10px; bottom: calc(var(--nav-h) + var(--safe-b) + 10px); max-width: 360px; margin: 0 auto;
  background: #10233d; border: 2px solid var(--accent2); border-radius: 12px; padding: 12px 14px; box-shadow: 0 8px 30px rgba(0,0,0,.5); }
.coach p { margin: 0; font-size: 15px; }
.coach .row { justify-content: space-between; }
.coach-target { outline: 3px solid var(--accent2) !important; outline-offset: 3px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { outline-color: rgba(88,166,255,.35); } }
.tip { position: fixed; z-index: 45; max-width: 260px; padding: 8px 10px; border-radius: 8px; background: #2d333b; border: 1px solid #444c56;
  color: var(--text); font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.5); pointer-events: none; }
.toasts { position: fixed; z-index: 35; left: 50%; transform: translateX(-50%); top: 120px; display: grid; gap: 6px; width: min(92vw, 340px); pointer-events: none; }
.toast { background: #1d1a0e; border: 1px solid var(--gold); color: var(--text); border-radius: 10px; padding: 10px 12px; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,.5); animation: toast 3.5s ease forwards; }
.toast b { color: #ffd866; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-8px); } 8%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }
.float { position: fixed; pointer-events: none; color: #7ee787; font-weight: 800; animation: up .8s ease-out forwards; z-index: 25; }
@keyframes up { to { transform: translateY(-40px); opacity: 0; } }
body.ad-active main, body.ad-active .bottom-nav { pointer-events: none; }

/* ad stub (ads.js placeholder provider) */
.ad-stub { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; padding: 16px; }
.ad-stub-card { background: #fff; color: #111; border-radius: 12px; padding: 22px; width: min(92vw, 360px); text-align: center; }
.ad-stub-tag { font: 700 12px ui-monospace, monospace; color: #555; letter-spacing: .08em; }
.ad-stub-body { font-size: 18px; margin: 16px 0; }
.ad-stub-body small { color: #444; }
.ad-stub-count { font-size: 28px; font-weight: 800; margin-bottom: 12px; }
.ad-stub button { display: block; width: 100%; margin-top: 8px; background: #e8eaed; color: #111; border-color: #999; }
.ad-stub .ad-stub-close { background: #1f6f3a; color: #fff; border-color: #1f6f3a; font-weight: 700; }

/* ---------- wider phones / tablets ---------- */
@media (min-width: 600px) {
  .stats { grid-template-columns: repeat(5, 1fr); }
  .stat.wide { display: flex; }
  .brand small { display: inline; }
  main { padding: 12px 16px; }
}

/* ---------- desktop: all panes visible in 3 columns ---------- */
@media (min-width: 1000px) {
  body { padding-bottom: 0; }
  header { display: grid; grid-template-columns: auto 1fr; grid-template-areas: "top stats" "warn warn"; column-gap: 24px; padding: 8px 16px; }
  .topline { grid-area: top; }
  .stats { grid-area: stats; justify-self: end; grid-template-columns: repeat(5, minmax(110px, auto)); }
  .warn-top { grid-area: warn; display: none; }
  main { display: grid; grid-template-columns: 330px minmax(0, 1fr) 340px; grid-template-areas: "ops build upg" "company build upg";
    grid-template-rows: auto 1fr; gap: 0 16px; align-items: start; }
  .pane { display: block; }
  #pane-ops { grid-area: ops; } #pane-build { grid-area: build; } #pane-upg { grid-area: upg; } #pane-company { grid-area: company; }
  .bottom-nav { display: none; }
  .coach { bottom: auto; right: auto; margin: 0; }
  .upgrades { max-height: 55vh; overflow: auto; }
  .ach { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .toast { animation: none; }
}
