:root {
  --bg: #05090f;
  --panel: rgba(10, 18, 28, 0.82);
  --line: rgba(140, 200, 255, 0.18);
  --text: #e8f3ff;
  --muted: #8aa4bd;
  --accent: #5cc8ff;
  --accent-2: #ffe066;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: 0.55; }

/* ---------- Stage: camera / photo + drawing layer ---------- */
#stage {
  position: fixed;
  inset: 0;
  background: #000;
}
#stage video, #stage img, #stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
#stage.fit-cover video, #stage.fit-cover img, #stage.fit-cover canvas { object-fit: cover; }
#stage.fit-contain video, #stage.fit-contain img, #stage.fit-contain canvas { object-fit: contain; }
#stage canvas { touch-action: manipulation; }
#tissue, #bones3d { pointer-events: none; }
/* Realistic look: a soft shadow where the flesh is, so the bones seem to sit inside it */
#tissue { opacity: 0.42; }
#stage.xray #tissue { opacity: 0.2; }
#video.mirror { transform: scaleX(-1); }

/* X-ray look: darken, desaturate and tint the camera picture blue */
#stage.xray video, #stage.xray img {
  filter: grayscale(1) contrast(1.4) brightness(0.3) sepia(0.6) hue-rotate(175deg) saturate(1.6);
}
.scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  background:
    radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.65) 100%),
    repeating-linear-gradient(0deg, rgba(120, 200, 255, 0.04) 0 1px, transparent 1px 3px);
}
#stage.xray .scanlines { opacity: 1; }

/* ---------- Top bar ---------- */
.topbar {
  position: fixed;
  top: calc(var(--safe-t) + 12px);
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.brand {
  font-weight: 700;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 8px;
  text-shadow: 0 1px 6px #000;
}
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}
.chip {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.hint {
  position: fixed;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  width: min(320px, calc(100% - 32px));
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 16px;
  color: var(--text);
  pointer-events: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* ---------- Bottom controls ---------- */
.controls {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 12px 16px calc(var(--safe-b) + 16px);
  background: linear-gradient(to top, rgba(0, 0, 0, 0.75), transparent);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.toggles {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.toggle {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13px;
  color: var(--muted);
}
.toggle.on {
  color: #04121d;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}
.buttons {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.round {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  padding: 0;
}
.round svg { width: 22px; height: 22px; }
.shutter {
  width: 72px; height: 72px;
  border-radius: 50%;
  border: 4px solid var(--text);
  background: transparent;
  padding: 5px;
}
.shutter span {
  display: block;
  width: 100%; height: 100%;
  border-radius: 50%;
  background: var(--accent);
  transition: border-radius 0.2s, transform 0.2s;
}
.shutter.frozen span {
  border-radius: 8px;
  transform: scale(0.6);
  background: var(--accent-2);
}

/* ---------- Bone info sheet ---------- */
.info {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 160px);
  width: min(440px, calc(100% - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px 12px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  animation: rise 0.2s ease-out;
}
.info.top {
  bottom: auto;
  top: calc(var(--safe-t) + 56px);
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } }
.info h2 { margin: 6px 0 2px; font-size: 20px; }
.info p { margin: 6px 0 0; }
.info .meaning { color: var(--muted); font-size: 13px; font-style: italic; margin-top: 0; }
.info .group {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  color: #04121d;
  background: var(--accent);
}
.close {
  position: absolute;
  top: 6px; right: 8px;
  width: 34px; height: 34px;
  border: 0;
  background: none;
  font-size: 24px;
  color: var(--muted);
}

/* ---------- Start screen ---------- */
.start {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(60, 140, 220, 0.25), transparent 60%),
    var(--bg);
  overflow-y: auto;
}
.start .card {
  width: min(400px, 100%);
  text-align: center;
}
.logo {
  width: 84px; height: 84px;
  margin: 0 auto 10px;
  color: var(--accent);
  filter: drop-shadow(0 0 12px rgba(92, 200, 255, 0.7));
}
.start h1 { margin: 0 0 8px; font-size: 30px; letter-spacing: 0.02em; }
.lead { color: var(--muted); margin: 0 0 22px; }
.lead b { color: var(--text); }
.primary, .secondary {
  display: block;
  width: 100%;
  border-radius: 12px;
  padding: 14px;
  font-weight: 600;
  margin-bottom: 10px;
}
.primary { background: var(--accent); color: #04121d; border: 0; }
.secondary { background: transparent; border: 1px solid var(--line); }
.status { min-height: 1.4em; color: var(--accent-2); font-size: 13px; }
.fine { color: var(--muted); font-size: 12px; margin-top: 18px; }
.fine.credit { font-size: 11px; margin-top: 8px; opacity: 0.8; }

[hidden] { display: none !important; }

/* ---------- Hand / Body / Skull switcher ---------- */
.tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  pointer-events: auto;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.tab {
  border: 0;
  background: none;
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
}
.tab.on { background: var(--accent); color: #04121d; }
.start-tabs { justify-content: center; margin: 0 auto 16px; width: fit-content; }

.counter {
  position: fixed;
  top: calc(var(--safe-t) + 54px);
  right: 16px;
  pointer-events: none;
}

/* ---------- Countdown ---------- */
.countdown {
  position: fixed;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  width: min(300px, calc(100% - 32px));
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.count-number { font-size: 64px; font-weight: 700; line-height: 1.1; color: var(--accent); }
.count-text { margin-bottom: 12px; }
.secondary.small { width: auto; display: inline-block; padding: 8px 18px; margin: 0; }

/* ---------- Quiz ---------- */
.quiz {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  top: calc(var(--safe-t) + 56px);
  width: min(460px, calc(100% - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 16px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.quiz h2 { margin: 4px 0; font-size: 20px; line-height: 1.25; }
.quiz-top { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; }
.quiz-score { color: var(--accent-2); font-weight: 700; }
.quiz-feedback { margin: 4px 0 10px; font-size: 14px; color: var(--muted); }
.quiz-feedback.good { color: #8df0a4; }
.quiz-feedback.bad { color: #ffa0a0; }
.quiz-feedback.info { color: var(--text); }
.quiz-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
}
.pill.strong { background: var(--accent); border-color: var(--accent); color: #04121d; font-weight: 700; }
#quizEnd { margin-left: auto; color: var(--muted); }

.toggle.quiz-btn { background: var(--accent-2); border-color: var(--accent-2); color: #1b1500; font-weight: 700; }
