:root {
  --pn-vh: 1vh;
  --ink: #eaf2ff;
  --muted: #9fb1ca;
  --bg: #0d1b2a;
  --panel: #13263b;
  --accent: #ffd166;
  --good: #63d297;
  --bad: #ff7b7b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100%;
}

#app {
  width: min(960px, 100%);
  margin: 0 auto;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.topbar, #statusbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.topbar .title { font-weight: 700; font-size: 18px; }
.topbar .title small { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 4px; }
.spacer { flex: 1 1 auto; }

.hud {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.hud b { color: var(--ink); }
.hud .opt { text-transform: uppercase; font-size: 10px; letter-spacing: .07em; }

#stage {
  position: relative;
  background: var(--panel);
  border: 1px solid #27435e;
  border-radius: 12px;
  overflow: hidden;
}

#board {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  cursor: crosshair;
}

#overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(7, 16, 27, .72);
}
#overlay.hidden, #modal.hidden { display: none; }

.card, .modal-card {
  background: #162b43;
  border: 1px solid #355573;
  border-radius: 12px;
  padding: 18px 22px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
  max-width: min(460px, 90%);
}
.card-label { font-size: 20px; font-weight: 700; color: var(--accent); margin-bottom: 10px; }
.card-body { display: flex; gap: 18px; margin-bottom: 14px; }
.card-body div { display: flex; flex-direction: column; }
.card-body span { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.card-body b { font-size: 18px; font-variant-numeric: tabular-nums; }

#statusbar #status {
  flex: 1 1 220px;
  min-height: 22px;
  font-size: 13px;
  color: var(--muted);
}
#status[data-tone="good"] { color: var(--good); }
#status[data-tone="bad"] { color: var(--bad); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.btn {
  min-height: 38px;
  padding: 6px 12px;
  border: 1px solid #355573;
  border-radius: 8px;
  background: #162b43;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:hover { background: #1d3a5a; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #231a05; font-weight: 700; }
.btn.icon { min-width: 38px; padding: 6px 8px; font-size: 18px; line-height: 1; }

#modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(7, 16, 27, .78);
  padding: 16px;
  z-index: 10;
}
.modal-card h2 { margin: 0 0 8px; }
.modal-card p, .modal-card li { font-size: 14px; line-height: 1.55; color: #d7e4f5; }
.modal-card ol { padding-left: 20px; }
.modal-card .muted { color: var(--muted); font-size: 12px; }
.modal-card .btn { margin-top: 8px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: #162b43;
  border: 1px solid #355573;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s;
  z-index: 11;
}
#toast.show { opacity: 1; }

@media (max-width: 560px) {
  #app { padding: 6px 8px calc(10px + env(safe-area-inset-bottom)); }
  .topbar .title { font-size: 15px; }
  .hud { font-size: 11px; gap: 4px; }
  .actions { width: 100%; }
  .actions .btn { flex: 1 1 auto; padding: 6px 8px; font-size: 12px; }
  .card-body { gap: 12px; }
}
