/* Anatomy game layout */
body.game { overflow: hidden; height: 100dvh; touch-action: none; user-select: none; -webkit-user-select: none; }

body.game {
  background:
    radial-gradient(900px 700px at 50% 55%, rgba(70, 80, 190, 0.32), transparent 65%),
    radial-gradient(800px 600px at 85% 0%, rgba(150, 90, 255, 0.18), transparent 60%),
    linear-gradient(180deg, #121633, #080a18);
}

#scene { position: fixed; inset: 0; width: 100vw; height: 100dvh; display: block; z-index: 1; outline: none; cursor: grab; }
#scene:active { cursor: grabbing; }
#scene.pointing { cursor: pointer; }

.game-top { position: fixed; top: 0; left: 0; right: 0; z-index: 10; pointer-events: none; }
.game-top > * { pointer-events: auto; }
.game-title {
  margin: 0; font-size: clamp(1.1rem, 2.6vw, 1.6rem); font-weight: 900;
  background: linear-gradient(90deg, #c4ceff, #ffb8d6);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

.panel {
  position: fixed; z-index: 10;
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 24px; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 14px 40px rgba(0, 0, 0, .35);
}
.panel h2 { margin: 0 0 10px; font-size: .95rem; font-weight: 800; color: var(--text-dim); }

/* Views (left) */
.views-panel { left: clamp(10px, 2vw, 24px); top: 50%; transform: translateY(-50%); padding: 16px; width: 200px; }
.view-buttons { display: flex; flex-direction: column; gap: 8px; }
.view-btn {
  font: inherit; font-weight: 800; font-size: 1.02rem; color: var(--text);
  display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 10px 14px; border-radius: 16px; cursor: pointer;
  background: rgba(255, 255, 255, .04); border: 2px solid transparent;
  transition: background .2s, border-color .2s, transform .15s;
}
.view-btn .ico { font-size: 1.5rem; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 12px; background: color-mix(in srgb, var(--c) 18%, transparent); }
.view-btn:hover { background: rgba(255, 255, 255, .08); transform: translateX(2px); }
.view-btn.active { border-color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); box-shadow: 0 0 18px color-mix(in srgb, var(--c) 30%, transparent); }
.view-btn:focus-visible, .chip:focus-visible, .round-btn:focus-visible, .layers-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.quiz-btn { width: 100%; margin-top: 12px; background: linear-gradient(135deg, #ffb86b, #ff7eb3); border: none; color: #2a1030; font-size: 1.02rem; }
.quiz-btn.active { box-shadow: 0 0 0 3px #fff6, 0 8px 24px rgba(255, 140, 160, .45); }

/* Layers (right) */
.layers-panel { right: clamp(10px, 2vw, 24px); top: 50%; transform: translateY(-50%); padding: 14px 16px 16px; width: 230px; }
.layers-toggle { all: unset; cursor: pointer; display: flex; gap: 8px; align-items: center; font-weight: 800; font-size: .95rem; color: var(--text-dim); margin-bottom: 8px; border-radius: 8px; }
.layer-row { display: grid; grid-template-columns: 14px 1fr auto; align-items: center; gap: 4px 10px; padding: 8px 0; }
.layer-row + .layer-row { border-top: 1px solid rgba(255, 255, 255, .06); }
.layer-row .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); box-shadow: 0 0 10px var(--c); }
.layer-row .name { font-weight: 800; }
.layer-row .pct { font-size: .8rem; color: var(--text-dim); font-variant-numeric: tabular-nums; min-width: 3ch; text-align: right; }
.layer-row input[type=range] { grid-column: 1 / -1; width: 100%; }

input[type=range] {
  -webkit-appearance: none; appearance: none; height: 22px; background: transparent; cursor: pointer; margin: 0;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 8px; border-radius: 99px;
  background: linear-gradient(90deg, var(--c) 0 var(--p, 50%), rgba(255, 255, 255, .12) var(--p, 50%));
}
input[type=range]::-moz-range-track { height: 8px; border-radius: 99px; background: rgba(255, 255, 255, .12); }
input[type=range]::-moz-range-progress { height: 8px; border-radius: 99px; background: var(--c); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%; margin-top: -7px;
  background: #fff; border: 4px solid var(--c); box-shadow: 0 2px 8px #0006;
}
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 4px solid var(--c); }

/* Bottom: info card + camera bar + hint */
.bottom-ui {
  position: fixed; left: 50%; bottom: max(12px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 10; display: flex; flex-direction: column; align-items: center; gap: 10px; width: min(760px, 96vw);
  pointer-events: none;
}
.bottom-ui > * { pointer-events: auto; }
.cam-bar { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; padding: 6px; border-radius: 999px; background: var(--panel); border: 1px solid var(--panel-border); backdrop-filter: blur(14px); }
.cam-bar .sep { width: 1px; background: rgba(255, 255, 255, .12); margin: 4px 4px; }
.chip {
  font: inherit; font-weight: 800; font-size: .9rem; color: var(--text);
  padding: 8px 14px; border-radius: 999px; border: 1px solid transparent; cursor: pointer;
  background: rgba(255, 255, 255, .05); transition: background .2s, border-color .2s;
}
.chip:hover { background: rgba(255, 255, 255, .11); }
.chip.toggle[aria-pressed=false] { opacity: .5; }
.chip.toggle[aria-pressed=true] { border-color: rgba(142, 166, 255, .5); background: rgba(142, 166, 255, .14); }
/* The spin icon turns while the body is turning, so the button's effect is obvious. */
.spin-ico { display: inline-block; }
#spinBtn[aria-pressed=true] .spin-ico { animation: spin 2.5s linear infinite; }
@media (prefers-reduced-motion: reduce) { #spinBtn[aria-pressed=true] .spin-ico { animation: none; } }
.hint { margin: 0; font-size: .82rem; color: var(--text-dim); text-align: center; opacity: .85; text-shadow: 0 1px 4px #000; }

.info-card {
  display: flex; align-items: center; gap: 14px; padding: 12px 14px 12px 18px;
  border-radius: 22px; background: rgba(20, 24, 56, .82); border: 1px solid var(--panel-border);
  backdrop-filter: blur(14px); box-shadow: 0 12px 36px rgba(0, 0, 0, .4);
  animation: pop .25s ease-out;
}
.info-card[hidden], .quiz-bar[hidden], .tooltip[hidden] { display: none; }
.info-card .dot { width: 16px; height: 16px; border-radius: 50%; background: var(--c, #fff); box-shadow: 0 0 14px var(--c, #fff); flex: none; }
.info-name { font-size: clamp(1.3rem, 3.4vw, 1.9rem); font-weight: 900; line-height: 1.1; }
.info-layer { font-size: .85rem; color: var(--text-dim); font-weight: 700; }
.round-btn { font-size: 1.4rem; width: 48px; height: 48px; border-radius: 50%; border: none; cursor: pointer; background: rgba(255, 255, 255, .1); flex: none; transition: transform .15s, background .2s; }
.round-btn:hover { background: rgba(255, 255, 255, .18); transform: scale(1.06); }
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }

/* Tooltip that follows the pointer */
.tooltip {
  position: fixed; left: 0; top: 0; z-index: 20; pointer-events: none;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 14px; font-weight: 900; font-size: 1.05rem; white-space: nowrap;
  background: rgba(14, 17, 40, .88); border: 1px solid rgba(255, 255, 255, .14);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
  transform: translate(16px, -50%);
}
.tooltip .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c, #fff); box-shadow: 0 0 10px var(--c, #fff); }

/* Quiz */
.quiz-bar {
  margin-top: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 12px 6px; border-radius: 18px; text-align: center;
  background: linear-gradient(135deg, rgba(255, 184, 107, .18), rgba(255, 126, 179, .18)), rgba(20, 24, 56, .6);
  border: 1px solid rgba(255, 190, 160, .35);
  animation: pop .25s ease-out;
}
.quiz-text { font-size: 1.3rem; font-weight: 900; line-height: 1.2; overflow-wrap: break-word; hyphens: auto; }
.quiz-text.good { color: var(--green); animation: pop .3s ease-out; }
.quiz-text.bad { color: #ffb3a8; animation: shake .4s ease-in-out; }
.quiz-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; align-items: center; }
.quiz-bar .chip { padding: 6px 10px; font-size: .85rem; }
.quiz-score { font-weight: 900; font-size: 1.1rem; width: 100%; font-variant-numeric: tabular-nums; }
@keyframes shake { 0%, 100% { transform: none; } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.confetti { position: fixed; z-index: 30; pointer-events: none; font-size: 1.6rem; animation: burst 1.1s ease-out forwards; }
@keyframes burst {
  from { transform: translate(-50%, -50%) scale(.4); opacity: 1; }
  to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.1) rotate(var(--rot)); opacity: 0; }
}

/* Loader */
.loader { position: fixed; inset: 0; z-index: 50; display: grid; place-content: center; justify-items: center; gap: 16px; font-weight: 800; color: var(--text-dim); background: #0b0e22; transition: opacity .5s ease; }
.loader.done { opacity: 0; pointer-events: none; }
.spinner { width: 54px; height: 54px; border-radius: 50%; border: 5px solid rgba(255, 255, 255, .1); border-top-color: var(--accent-2); border-right-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Small screens ---------- */
@media (max-width: 860px) {
  .hide-sm { display: none; }
  .views-panel { top: auto; transform: none; left: 8px; right: 8px; width: auto; bottom: max(8px, env(safe-area-inset-bottom)); padding: 8px; border-radius: 20px; }
  .views-panel h2 { display: none; }
  .view-buttons { flex-direction: row; overflow-x: auto; gap: 6px; }
  .view-btn { flex-direction: column; gap: 2px; padding: 6px 8px; font-size: .78rem; min-width: 64px; text-align: center; align-items: center; flex: 1; }
  .view-btn .ico { font-size: 1.3rem; width: 30px; height: 30px; }
  .view-btn:hover { transform: none; }
  .quiz-btn { margin-top: 6px; padding: 8px; }
  .layers-panel { top: 64px; transform: none; right: 8px; width: 200px; padding: 8px 12px; }
  .layers-panel:not(.open) .layer-rows { display: none; }
  .layers-panel:not(.open) .layers-toggle { margin-bottom: 0; }
  .bottom-ui { bottom: 150px; gap: 6px; }
  .cam-bar { padding: 4px; gap: 4px; }
  .chip { padding: 6px 10px; font-size: .8rem; }
  .hint { display: none; }
  /* Quiz card floats just above the bottom views row, in place of the camera bar. */
  .quiz-bar {
    position: absolute; left: 0; right: 0; bottom: calc(100% + 8px); margin: 0;
    flex-direction: row; flex-wrap: wrap; justify-content: center; padding: 8px 12px;
    background: linear-gradient(135deg, rgba(255, 184, 107, .2), rgba(255, 126, 179, .2)), rgba(20, 24, 56, .94);
    box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
  }
  .quiz-text { font-size: 1.15rem; width: 100%; }
  .quiz-score { width: auto; margin-right: 4px; }
  body.quiz-on .bottom-ui { display: none; }
}
@media (min-width: 861px) {
  .layers-toggle { pointer-events: none; }
}
/* Short desktop windows: keep the views panel below the top bar and make it more compact. */
@media (min-width: 861px) and (max-height: 780px) {
  .views-panel { top: 76px; transform: none; max-height: calc(100dvh - 90px); overflow-y: auto; padding: 12px; }
  .views-panel h2 { margin-bottom: 6px; }
  .view-buttons { gap: 6px; }
  .view-btn { padding: 6px 12px; }
  .view-btn .ico { width: 30px; height: 30px; font-size: 1.3rem; }
  .quiz-btn { margin-top: 8px; padding: 8px 18px; }
}
