/* App shell. Brand values come from theme.css; nothing brand-specific is hardcoded here. */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app { height: 100%; }

/* ---------- wordmark ---------- */
.brand {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -.3px;
  white-space: nowrap;
}
.brand::before { content: var(--brand-name-a) " "; }
.brand::after { content: var(--brand-name-b); color: var(--accent); }

/* ---------- loading screen (shown until Blazor renders) ---------- */
.boot {
  position: fixed; inset: 0;
  display: grid; place-content: center; justify-items: center; gap: 22px;
  background:
    radial-gradient(120% 70% at 50% 40%, var(--scene-ground-hi), transparent 70%),
    var(--bg);
}
.boot .brand { font-size: 30px; }
.boot-loop { width: 180px; height: 90px; overflow: visible; }
.boot-loop .track { fill: none; stroke: var(--scene-rail); stroke-width: 10; }
.boot-loop .inner { fill: none; stroke: var(--scene-track); stroke-width: 7; }
.boot-loop .glow {
  fill: none; stroke: var(--sorter); stroke-width: 3; stroke-linecap: round;
  stroke-dasharray: 46 400; filter: drop-shadow(0 0 6px var(--sorter));
  animation: boot-run 1.6s linear infinite;
}
.boot-loop .bag { fill: var(--accent); filter: drop-shadow(0 0 4px var(--accent)); }
@keyframes boot-run { to { stroke-dashoffset: -446; } }
.boot-progress {
  width: 180px; height: 4px; border-radius: 99px; background: var(--panel); overflow: hidden;
}
.boot-progress::after {
  content: ""; display: block; height: 100%;
  width: var(--blazor-load-percentage, 4%);
  background: linear-gradient(90deg, var(--sorter), var(--accent));
  transition: width .15s ease-out;
}
.boot-text { font: 600 12px var(--font-body); color: var(--muted); letter-spacing: .4px; }
.boot-text::after { content: var(--blazor-load-percentage-text, "Loading"); }

/* ---------- game shell ---------- */
.shell {
  height: 100%;
  max-width: 620px;
  margin: 0 auto;
  display: flex; flex-direction: column; gap: 8px;
  padding:
    calc(10px + env(safe-area-inset-top, 0px))
    calc(12px + env(safe-area-inset-right, 0px))
    calc(10px + env(safe-area-inset-bottom, 0px))
    calc(12px + env(safe-area-inset-left, 0px));
}

.topbar { display: flex; justify-content: space-between; align-items: center; min-height: 32px; }
.topbar .brand { font-size: 22px; }
.clock { font: 700 20px var(--font-display); font-variant-numeric: tabular-nums; }

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.tile {
  background: var(--panel); border-radius: var(--radius-m); padding: 6px 8px;
  display: flex; flex-direction: column; min-width: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .03);
}
.tile span { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile strong { font: 700 18px var(--font-display); font-variant-numeric: tabular-nums; }
.tile.ok strong { color: var(--success); }

.banner {
  border-radius: var(--radius-m); padding: 8px 12px; min-height: 36px;
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); color: var(--muted); font-size: 13px; line-height: 1.35;
}
.banner .chip {
  flex: none; font: 700 11px var(--font-display); letter-spacing: .6px; text-transform: uppercase;
  color: var(--sorter); border: 1px solid color-mix(in srgb, var(--sorter) 45%, transparent);
  padding: 3px 8px; border-radius: 99px;
}

.stage {
  flex: 1; position: relative; min-height: 0;
  border-radius: var(--radius-l); overflow: hidden;
  background: var(--scene-ground);
  box-shadow: 0 0 0 1px var(--line), 0 18px 40px -18px rgba(0, 0, 0, .8);
}
.stage canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  touch-action: manipulation; display: block;
}

.footnote {
  display: flex; justify-content: space-between; gap: 8px;
  font: 600 11px var(--font-body); color: var(--dim);
}
.footnote b { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }

button:focus-visible { outline: 2px solid var(--sorter); outline-offset: 2px; }

/* ---------- Blazor error UI ---------- */
#blazor-error-ui {
  display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--alert-bg); color: var(--alert-text); border-top: 1px solid var(--alert-line);
  font-size: 14px;
}
#blazor-error-ui a { color: var(--accent); }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 16px; top: 10px; }

@media (prefers-reduced-motion: reduce) {
  .boot-loop .glow { animation-duration: 6s; }
}

/* ---------- self-test ---------- */
.selftest { overflow-y: auto; }
.selftest .back { color: var(--sorter); font: 600 14px var(--font-body); min-height: var(--touch); display: inline-flex; align-items: center; }
.selftest .panel { background: var(--panel); border-radius: var(--radius-l); padding: 16px; }
.selftest h2 { font: 700 18px var(--font-display); margin: 0 0 8px; }
.selftest p { color: var(--muted); font-size: 14px; line-height: 1.45; }
.selftest .status { font: 700 16px var(--font-display); color: var(--text); }
.selftest .status.ok { color: var(--success); }
.selftest .status.bad { color: var(--danger); }
.selftest dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.selftest dt { color: var(--muted); }
.selftest dd { margin: 0; font-variant-numeric: tabular-nums; }
.selftest code { color: var(--accent); }

/* ---------- game controls (SPEC §7) ---------- */
.game { gap: 7px; }
.tile.bad strong { color: var(--danger); }

.banner.warn { background: var(--alert-bg); color: var(--alert-text); box-shadow: inset 0 0 0 1px var(--alert-line); }
.banner.need { background: var(--need-bg); color: var(--need-text); box-shadow: inset 0 0 0 1px var(--accent); }

.tabs {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px;
  background: var(--panel); border-radius: var(--radius-m); padding: 4px;
}
.tabs button {
  min-height: 36px; border: 0; border-radius: var(--radius-s); background: transparent; color: var(--muted);
  font: 700 15px var(--font-display); cursor: pointer; transition: background .15s, color .15s;
}
.tabs button[aria-selected="true"] { background: var(--panel-raised); color: var(--text); box-shadow: inset 0 -2px 0 var(--sorter); }

.tugs { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
.tug {
  min-height: var(--touch); min-width: 0; padding: 4px 6px; text-align: left; cursor: pointer;
  display: flex; flex-direction: column; justify-content: center; gap: 1px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel);
  color: var(--muted); font: 600 10.5px var(--font-body);
  transition: background .15s, box-shadow .15s;
}
.tug b { font: 700 13px var(--font-display); color: var(--tag, var(--text)); }
.tug span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tug[aria-pressed="true"] {
  background: color-mix(in srgb, var(--sorter) 14%, var(--panel));
  box-shadow: 0 0 0 2px var(--sorter), 0 0 14px -2px color-mix(in srgb, var(--sorter) 60%, transparent);
}

.stage canvas { cursor: pointer; }
.toast {
  position: absolute; left: 50%; bottom: 12px; transform: translate(-50%, 6px);
  max-width: calc(100% - 24px); padding: 8px 14px; border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 94%, transparent); color: var(--text);
  border: 1px solid var(--line); box-shadow: 0 10px 24px -10px rgba(0, 0, 0, .8);
  font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.paused {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  background: rgba(5, 8, 18, .35); font: 700 22px var(--font-display); letter-spacing: 2px; text-transform: uppercase;
  color: var(--text);
}

.controls { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 6px; }
.controls button {
  min-height: 46px; border: 1px solid var(--line); border-radius: var(--radius-m);
  background: var(--panel); color: var(--text); font: 700 14px var(--font-display); cursor: pointer;
}
.controls button:active { transform: translateY(1px); }
.controls button.storm { background: var(--alert-bg); border-color: var(--alert-line); color: var(--alert-text); }
.controls button:disabled { opacity: .5; cursor: default; }
.footnote a { color: var(--muted); }

@media (max-height: 700px) {
  .tile { padding: 4px 8px; }
  .tile strong { font-size: 16px; }
  .banner { min-height: 32px; padding: 6px 10px; font-size: 12px; }
  .controls button { min-height: var(--touch); }
}
