/* screw3d — 拆螺絲 3D (Three.js + raycaster) */

.app {
  max-width: 720px;
  padding-bottom: 32px;
}

/* ── HUD ─────────────────────────────────────────────────────────── */
.hud {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin: 12px 0;
}
.hud-sep { opacity: 0.55; padding: 0 2px; }
#optimal.perfect {
  color: gold;
  text-shadow: 0 0 6px gold;
  animation: optimal-pulse 0.9s ease-in-out infinite alternate;
}
@keyframes optimal-pulse {
  0%   { transform: scale(1); }
  100% { transform: scale(1.18); }
}
.hud-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 8px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.hud-label {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}
.hud-value {
  font-size: 20px;
  font-weight: 800;
  color: var(--accent);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

/* ── Target boxes row ───────────────────────────────────────────── */
.boxes-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 4px 0 10px;
  flex-wrap: wrap;
}
.tbox {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 4px;
  box-sizing: border-box;
  box-shadow: inset 0 -2px 6px rgba(0,0,0,0.25), 0 2px 4px rgba(0,0,0,0.2);
  border: 3px solid #222;
  transition: transform 0.15s, box-shadow 0.2s;
}
.tbox.full {
  filter: brightness(0.7) saturate(0.6);
}
.tbox.full::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0,0,0,0.7);
  font-weight: 900;
}
.tbox.reject {
  animation: tbox-reject 0.25s ease-in-out;
}
@keyframes tbox-reject {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-4px); }
  75%      { transform: translateX(4px); }
}
.tbox-count {
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
  letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums;
}

/* Per-color tile backgrounds — keep in sync with COLORS dict in game.js */
.tbox[data-color="red"]    { background: #ff5252; }
.tbox[data-color="blue"]   { background: #4a90e2; }
.tbox[data-color="green"]  { background: #4caf50; }
.tbox[data-color="yellow"] { background: #ffd54f; }
.tbox[data-color="purple"] { background: #ab47bc; }

/* ── 3D scene canvas wrap ───────────────────────────────────────── */
#scene-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 480px;
  background: linear-gradient(180deg, #b3e0ff 0%, #ffd6f2 100%);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18), 0 0 0 1px var(--border) inset;
}
/* Scope canvas styling — never bare `canvas {}` (would hit the confetti
   canvas too and create a ghost frame). */
#scene-wrap #scene {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;       /* OrbitControls handles touch */
  cursor: grab;
}
#scene-wrap #scene:active { cursor: grabbing; }

/* "Box full" feedback message floating over the scene */
.full-msg {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.78);
  color: #ff7676;
  padding: 12px 22px;
  border-radius: 10px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 1px;
  pointer-events: none;
  z-index: 5;
  animation: full-msg-pop 1.2s ease-out forwards;
}
.full-msg[hidden] { display: none; }
@keyframes full-msg-pop {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  15%  { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  85%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(0.9); }
}

/* ── Action buttons ─────────────────────────────────────────────── */
.action-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
}
.action-row .btn { min-width: 120px; }
.action-row .btn.primary {
  background: linear-gradient(180deg, #4caf50, #2e7d32);
  color: #fff;
  border: none;
  font-weight: 700;
  animation: next-glow 1.6s ease-in-out infinite alternate;
}
@keyframes next-glow {
  0%   { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0); }
  100% { box-shadow: 0 0 18px 4px rgba(76, 175, 80, 0.55); }
}

/* ── Error overlay (Track-C convention) ─────────────────────────── */
#error[hidden] { display: none; }
#error {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.85);
  color: #fff;
  font-size: 18px;
  padding: 20px;
  text-align: center;
  z-index: 9999;
}
#error .err-box {
  background: #2a2a3a;
  border: 1px solid #444;
  border-radius: 12px;
  padding: 20px 28px;
  max-width: 320px;
}
#error .err-detail {
  margin-top: 10px;
  font-size: 13px;
  opacity: 0.75;
  font-family: monospace;
}

/* ── Mobile ─────────────────────────────────────────────────────── */
@media (max-width: 520px) {
  .hud { grid-template-columns: repeat(3, 1fr); }
  .tbox { width: 52px; height: 52px; }
  #scene-wrap { aspect-ratio: 3 / 4; max-height: 540px; }
}
