/* Shared look for ieMR Integration Match, ieMR Pac-Man and Flappy ieMR.
   Matches the games menu: charcoal page, teal accent. Scores read like a patient monitor's
   parameter boxes: big condensed numbers, colour-coded (green score, cyan moves/lives, yellow best). */

:root {
  --bg: #1e2124;
  --panel: #26292d;
  --panel-2: #2c3035;
  --line: #3a3f45;
  --text: #e8ecef;
  --muted: #9aa4ad;
  --teal: #1fa3b5;
  --teal-dark: #127a88;
  --screen: #070a0a;
  --ecg: #3ddc84;
  --spo2: #22d3ee;
  --best: #f5c542;
  --alarm: #fb7185;
  --num: "Barlow Condensed", "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;
  --ui: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  padding: max(12px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
.wrap { max-width: 560px; margin: 0 auto; }
.hidden { display: none !important; }

/* ---------- Top bar ---------- */
.topbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; min-height: 40px; }
.topbar h1 { flex: 1; min-width: 0; margin: 0; font-size: 1.15rem; font-weight: 700; display: flex; align-items: center; gap: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar h1 .logo { width: 26px; height: 26px; flex: none; }
.topbar h1 .logo svg { width: 100%; height: 100%; display: block; }
.back { color: var(--muted); text-decoration: none; font-size: 1.35rem; line-height: 1; padding: 6px 4px; border-radius: 6px; }
.back:hover { color: var(--text); }
.tools { display: flex; gap: 6px; align-items: center; flex: none; }

button, select { font: inherit; color: var(--text); }
.icon-btn, .tools select {
  height: 36px; min-width: 36px; padding: 0 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  font-size: 0.9rem; cursor: pointer;
}
.icon-btn:hover, .tools select:hover { background: var(--panel-2); }
.tools select { max-width: 7.5rem; }
@media (max-width: 420px) { .tools select { max-width: 5.4rem; padding: 0 4px; } .tools { gap: 4px; } }
.btn {
  border: 0; border-radius: 10px; padding: 11px 22px; cursor: pointer;
  background: var(--teal); color: #fff; font-weight: 600; font-size: 1rem;
  touch-action: manipulation;
}
.btn:hover { background: var(--teal-dark); }
.btn.quiet { background: var(--panel-2); border: 1px solid var(--line); }
.btn.quiet:hover { background: var(--line); }
.btn:disabled { opacity: 0.55; cursor: default; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

/* ---------- Monitor-style score boxes ---------- */
.hud { display: grid; grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr)); gap: 6px; margin-bottom: 8px; }
.param {
  --c: var(--text);
  background: var(--screen); border: 1px solid #23292b; border-radius: 8px;
  padding: 5px 9px 6px; min-width: 0;
}
.param .k { display: block; font-size: 0.72rem; color: var(--c); opacity: 0.8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.param .v { display: block; font-family: var(--num); font-weight: 600; font-size: 1.75rem; line-height: 1; color: var(--c); font-variant-numeric: tabular-nums; white-space: nowrap; }
.param.score { --c: var(--ecg); }
.param.count { --c: var(--spo2); }
.param.best { --c: var(--best); }

/* ---------- Game stage and overlay cards ---------- */
.stage { position: relative; width: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }
.stage canvas { display: block; width: 100%; height: auto; border-radius: 12px; background: var(--screen); border: 1px solid #23292b; touch-action: none; }
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; border-radius: 12px; background: rgba(7, 10, 10, 0.55); }
.card {
  width: min(100%, 320px);
  background: rgba(38, 41, 45, 0.96); border: 1px solid var(--line); border-radius: 14px;
  padding: 18px 18px 16px; text-align: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}
.card h2 { margin: 0 0 6px; font-size: 1.3rem; }
.card p { margin: 0 0 10px; color: var(--muted); font-size: 0.9rem; line-height: 1.4; }
.card .final { display: flex; justify-content: center; gap: 22px; margin: 4px 0 8px; }
.card .final div { display: flex; flex-direction: column; align-items: center; }
.card .final .k { font-size: 0.75rem; color: var(--muted); }
.card .final .v { font-family: var(--num); font-weight: 700; font-size: 2.6rem; line-height: 1; font-variant-numeric: tabular-nums; }
.card .final .score .v { color: var(--ecg); }
.card .final .best .v { color: var(--best); }
.tag { display: inline-block; background: rgba(245, 197, 66, 0.15); color: var(--best); border-radius: 999px; padding: 3px 10px; font-size: 0.8rem; font-weight: 600; margin-bottom: 8px; }
.save-form { display: flex; gap: 6px; justify-content: center; margin: 4px 0 6px; }
.save-form input {
  width: 150px; padding: 9px 10px; border-radius: 8px; font: inherit; font-size: 0.95rem;
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
}
.save-form .btn { padding: 9px 14px; font-size: 0.9rem; }
.save-status { color: var(--muted); font-size: 0.85rem; min-height: 1.2em; margin: 0 0 12px; }
.save-status:empty { display: none; }
.status-line { color: var(--muted); font-size: 0.85rem; min-height: 1.3em; margin: 8px 2px 0; }

/* ---------- Leaderboard ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-top: 14px; }
.lb-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.lb-top h3 { margin: 0; font-size: 0.95rem; }
.tabs { display: flex; gap: 2px; background: var(--bg); border-radius: 8px; padding: 2px; }
.tabs button { white-space: nowrap; background: none; border: 0; border-radius: 6px; color: var(--muted); padding: 5px 10px; font-size: 0.8rem; font-weight: 600; cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--teal); color: #fff; }
.lb { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.lb li { display: grid; grid-template-columns: 26px 1fr auto; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 6px; font-size: 0.92rem; }
.lb li:nth-child(odd) { background: rgba(255, 255, 255, 0.03); }
.lb li.me { background: rgba(31, 163, 181, 0.2); outline: 1px solid var(--teal); }
.lb .rank { color: var(--muted); font-weight: 700; }
.lb li:nth-child(1) .rank { color: var(--best); }
.lb .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb .pts { font-family: var(--num); font-weight: 600; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.lb-status, .plays { color: var(--muted); font-size: 0.82rem; margin: 6px 0 0; }
.lb-status:empty, .plays:empty { display: none; }

/* ---------- How to play ---------- */
details.howto { margin-top: 10px; }
details.howto summary { cursor: pointer; font-weight: 600; font-size: 0.95rem; list-style: none; display: flex; justify-content: space-between; align-items: center; }
details.howto summary::-webkit-details-marker { display: none; }
details.howto summary::after { content: "+"; color: var(--muted); font-size: 1.2rem; }
details.howto[open] summary::after { content: "\2212"; }
details.howto ul { margin: 10px 0 2px; padding-left: 18px; color: var(--muted); font-size: 0.88rem; line-height: 1.5; }
details.howto li strong { color: var(--text); font-weight: 600; }
.key-icons { display: flex; flex-wrap: wrap; gap: 8px 14px; margin: 10px 0 2px; font-size: 0.82rem; color: var(--muted); }
.key-icons span { display: inline-flex; align-items: center; gap: 6px; }
.key-icons svg, .key-icons img { width: 20px; height: 20px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
