/* main.css — tumma teema (aurinkoluettavuus), yksi sivu, safe-area-tuki. */
:root {
  --bg: #0c0e12;
  --fg: #f2f4f8;
  --muted: #9aa3b2;
  --gold: #e9c46a;
  --silver: #c7ccd4;
  --bronze: #d08b5b;
  --accent: #e9c46a;
  --warn: #e76f51;
  --ease: cubic-bezier(0.22, 1, 0.36, 1); /* yksi easing koko apissa (M6) */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

#app { position: fixed; inset: 0; }

#cam, #overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#overlay { pointer-events: none; }
/* Ennen kameran käynnistystä video on piilossa, intro päällä. */
#cam[hidden] { display: none; }

.view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-t) + 16px) 16px calc(var(--safe-b) + 16px);
  text-align: center;
}
.view[hidden] { display: none; }

.intro-card {
  max-width: 22rem;
  background: rgba(20, 24, 32, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 18px;
  padding: 28px 24px;
  backdrop-filter: blur(8px);
}
.intro-card h1 { margin: 0 0 12px; font-size: 1.5rem; letter-spacing: 0.01em; }
.intro-card p { color: var(--muted); line-height: 1.5; }
.fineprint { font-size: 0.8rem; margin-top: 16px; }

button.primary {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 14px 28px;
  font-size: 1rem;
  font-weight: 600;
  color: #1a1300;
  background: var(--gold);
  cursor: pointer;
  transition: transform 150ms var(--ease), filter 150ms var(--ease);
}
button.primary:active { transform: scale(0.97); filter: brightness(1.05); }

/* AIM-ristikko ohjaa pallot keskialueelle (linssivääristymä minimiin). */
.reticle {
  width: min(70vw, 70vh);
  aspect-ratio: 1;
  border: 1px dashed rgba(233, 196, 106, 0.5);
  border-radius: 12px;
  animation: breathe 3.2s var(--ease) infinite; /* ristikon hengitys (M6 mikroanimaatio) */
}
@keyframes breathe { 0%, 100% { opacity: 0.45; } 50% { opacity: 0.85; } }

.hint {
  position: absolute;
  bottom: calc(var(--safe-b) + 28px);
  background: rgba(12, 14, 18, 0.7);
  padding: 8px 16px;
  border-radius: 999px;
  color: var(--fg);
  font-size: 0.95rem;
}

.ci-bar {
  width: min(70vw, 320px);
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
.ci-fill {
  height: 100%;
  width: 10%;
  background: var(--accent);
  transition: width 200ms var(--ease);
}

.ranking { display: flex; gap: 18px; font-variant-numeric: tabular-nums; font-size: 1.4rem; }
.ranking .gold { color: var(--gold); }
.ranking .silver { color: var(--silver); }
.ranking .bronze { color: var(--bronze); }
.order-conf { color: var(--muted); margin-top: 18px; }

.banner {
  position: absolute;
  /* Alle yläpalkin (f-badge vasemmalla, setti-toggle keskellä, asetukset oikealla) — ei peitä niitä. */
  top: calc(var(--safe-t) + 58px);
  left: 50%;
  transform: translateX(-50%);
  max-width: 86vw;
  background: var(--warn);
  color: #1a0a05;
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 600;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}
.banner[hidden] { display: none; }

/* Versiomerkki (sw-versio) ruudun kulmassa — cache-arvailu loppuu. */
#verBadge {
  position: fixed; right: 4px; bottom: 2px; z-index: 60; pointer-events: none;
  font: 10px ui-monospace, Menlo, Consolas, monospace; color: rgba(154,163,178,0.55);
}

/* AIM-kontrollit (M3 tap-flow) */
.aim-controls {
  position: absolute;
  bottom: calc(var(--safe-b) + 76px);
  display: flex; gap: 12px; align-items: center;
}
button.ghost {
  appearance: none; border: 1px solid rgba(255,255,255,0.25);
  background: rgba(12,14,18,0.6); color: var(--fg);
  border-radius: 999px; padding: 12px 20px; font-size: 0.95rem; font-weight: 600; cursor: pointer;
}
button.primary:disabled { opacity: 0.45; cursor: default; }

/* Rengas-säätökontrollit (auto-fallback). Overlay sieppaa eleet → napit omassa palkissaan alalaidassa. */
.ring-controls {
  position: absolute; bottom: calc(var(--safe-b) + 20px); left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 10px; z-index: 6; width: calc(100% - 32px);
}
.ring-controls[hidden] { display: none; }
.ring-hint {
  background: rgba(12,14,18,0.72); color: var(--fg); padding: 7px 14px; border-radius: 999px;
  font-size: 0.88rem; text-align: center;
}
.ring-buttons { display: flex; gap: 12px; }
.set-toggle {
  position: absolute; top: calc(var(--safe-t) + 16px);
  display: flex; border-radius: 999px; overflow: hidden; border: 1px solid rgba(233,196,106,0.4);
}
.set-toggle button {
  appearance: none; border: none; background: rgba(12,14,18,0.7); color: var(--muted);
  padding: 8px 16px; font-weight: 600; cursor: pointer;
}
.set-toggle button.active { background: var(--gold); color: #1a1300; }

/* RESULT: KEVYT läpinäkyvä AR-kerros kameran päällä — EI peittävää korttia (JP:n toive).
   Numerot/järjestys piirtyvät overlay-canvakselle pallojen päälle; DOM näyttää vain ohuen
   tuomio-pillun ylhäällä + napit alhaalla. */
#result { justify-content: flex-start; }
.result-card {
  background: transparent; border: none; padding: 0; backdrop-filter: none;
  max-width: 100%; width: 100%; display: flex; flex-direction: column; align-items: center;
}
.ranking, .result-detail, .detail-head { display: none; } /* numerot menevät overlayhin, ei korttiin */
.order-conf {
  margin: calc(var(--safe-t) + 8px) 0 0; font-weight: 700; font-size: 1.02rem; text-align: center;
  background: rgba(12,14,18,0.55); padding: 9px 18px; border-radius: 999px;
  backdrop-filter: blur(6px); box-shadow: 0 4px 18px rgba(0,0,0,0.35); max-width: 90vw;
}
.order-conf.ok { color: var(--gold); }
.order-conf.warn { color: var(--warn); }
.ranking .invalid { color: var(--warn); font-size: 1.1rem; font-weight: 700; }
.result-guide {
  margin: 10px 16px 0; padding: 8px 14px; border-radius: 999px; max-width: 90vw; text-align: center;
  background: rgba(231,111,81,0.9); color: #1a0a05; font-size: 0.85rem; font-weight: 600;
  backdrop-filter: blur(4px);
}
.result-actions {
  position: absolute; bottom: calc(var(--safe-b) + 18px); left: 50%; transform: translateX(-50%);
  display: flex; gap: 12px; justify-content: center; flex-wrap: wrap;
}
.result-actions .ghost { background: rgba(12,14,18,0.5); backdrop-filter: blur(4px); }
.god-canvas { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; }

/* Asetukset */
.settings-btn {
  position: absolute; top: calc(var(--safe-t) + 12px); right: 12px; z-index: 5;
  width: 40px; height: 40px; border-radius: 999px; border: none;
  background: rgba(12,14,18,0.6); color: var(--fg); font-size: 1.1rem; cursor: pointer;
  touch-action: none; /* estä touch-scroll/zoom-eleet → pitkä painallus (dev-tila) ei katkea */
  -webkit-touch-callout: none; user-select: none;
}
.settings-panel {
  position: absolute; top: calc(var(--safe-t) + 56px); right: 12px; z-index: 6;
  background: rgba(20,24,32,0.96); border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px; padding: 16px; width: 17rem; display: flex; flex-direction: column; gap: 10px;
}
.settings-panel[hidden] { display: none; }
.settings-panel header { display: flex; justify-content: space-between; align-items: center; }
.settings-panel header button { background: none; border: none; color: var(--muted); font-size: 1rem; cursor: pointer; }
.settings-panel label { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--muted); }
.settings-panel input, .settings-panel select {
  width: 6rem; background: #0c0e12; color: var(--fg); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px; padding: 6px 8px;
}

/* DEV-paneeli docked YLÄLAITAAN (ei koskaan peitä alalaidan mittauskontrolleja). Oletus minimoitu:
   pelkkä header + aina-näkyvä tap-diag-rivi. Laajenee alaspäin KAMERAN päälle, ei kontrollien. */
#devPanel {
  position: fixed; left: 8px; right: 8px; top: calc(var(--safe-t) + 56px); z-index: 50;
  max-height: 50vh; overflow: auto;
  background: rgba(8,10,14,0.95); border: 1px solid var(--gold); border-radius: 12px;
  padding: 8px 10px; font-size: 0.8rem; box-shadow: 0 8px 28px rgba(0,0,0,0.5);
}
#devPanel[hidden] { display: none; }
#devPanel.min { max-height: none; overflow: visible; }
#devPanel.min #devBody { display: none; } /* diag-rivi jää näkyviin myös minimoituna */
#devPanel header { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
#devPanel header strong { color: var(--gold); margin-right: auto; }
.dev-caps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.dev-caps li { color: var(--muted); }
.dev-caps b { color: var(--fg); }
.dev-details summary { color: var(--gold); cursor: pointer; margin: 6px 0; }

/* Aina näkyvä tap-diagnostiikka-siru (ei peitä kameraa) */
#tapDiagHud {
  position: fixed; left: 8px; top: calc(var(--safe-t) + 38px); z-index: 49;
  max-width: calc(100vw - 16px); padding: 4px 8px; border-radius: 8px;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.68rem;
  background: rgba(8,10,14,0.8); color: var(--muted); border: 1px solid rgba(255,255,255,0.12);
  pointer-events: auto;
}
#tapDiagHud.ok { color: #6fd08b; border-color: rgba(111,208,139,0.4); }
#tapDiagHud.fail { color: var(--warn); border-color: rgba(231,111,81,0.45); }

/* Aktiivinen polttoväli AIM-näkymässä (pieni) */
.focal-badge {
  position: absolute; left: 12px; top: calc(var(--safe-t) + 12px); z-index: 4;
  padding: 4px 9px; border-radius: 999px; font-size: 0.72rem; color: var(--muted);
  background: rgba(12,14,18,0.6); border: 1px solid rgba(255,255,255,0.1);
}
.focal-badge.weak { color: var(--warn); border-color: rgba(231,111,81,0.4); }
.focal-badge[hidden] { display: none; }
#devPanel button {
  appearance: none; border: 1px solid rgba(255,255,255,0.2); background: #14181f; color: var(--fg);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 0.8rem;
}
#devPanel .dev-apply { background: var(--gold); color: #1a1300; border: none; font-weight: 600; }
#devPanel .dev-send { background: var(--gold); color: #1a1300; border: none; font-weight: 700; }
#devPanel .dev-send.ok { background: #6fd08b; color: #04210f; }
#devPanel .dev-send.fail { background: var(--warn); color: #1a0a05; }
.dev-pre { white-space: pre-wrap; word-break: break-word; background: #0c0e12; padding: 10px; border-radius: 8px; color: #9aef9a; font-size: 0.72rem; }
.dev-tapdiag {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.7rem;
  background: #0c0e12; border: 1px solid rgba(255,255,255,0.1); border-radius: 6px;
  padding: 6px 8px; margin-bottom: 8px; color: var(--muted); word-break: break-word;
}
.dev-tapdiag.ok { color: #6fd08b; border-color: rgba(111,208,139,0.4); }
.dev-tapdiag.fail { color: var(--warn); border-color: rgba(231,111,81,0.45); }
.dev-note { color: var(--muted); font-size: 0.78rem; }
.dev-row { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin: 6px 0; }
.dev-row input { width: 9rem; background: #0c0e12; color: var(--fg); border: 1px solid rgba(255,255,255,0.15); border-radius: 6px; padding: 5px; }
.ft-step, .ft-capture, .ft-summary { display: flex; flex-direction: column; gap: 8px; }
.ft-head { color: var(--gold); font-weight: 600; }
.ft-diagram { width: 100%; max-width: 260px; background: #0c0e12; border-radius: 8px; }
.ft-instr { line-height: 1.45; }
.ft-measured { font-variant-numeric: tabular-nums; font-size: 1rem; }
.ft-pass { color: #6fd08b; font-weight: 600; }
.ft-fail { color: var(--warn); font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  .reticle { animation: none; }
  button.primary, .ci-fill { transition: none; }
}
