/* bowling3d — 3D Bowling (Three.js + cannon-es) */

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

/* ── HUD ─────────────────────────────────────────────────────────── */
.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 12px 0;
}
.hud-box {
  background: linear-gradient(180deg, var(--surface), color-mix(in srgb, var(--surface) 80%, #000));
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 8px 6px;
  text-align: center;
  box-shadow: var(--shadow-sm), 0 0 0 1px rgba(255, 215, 0, 0.08) inset;
  position: relative;
}
.hud-box::before {
  content: '';
  position: absolute;
  top: 0; left: 8px; right: 8px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 215, 0, 0.45), transparent);
}
.hud-label {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.8px;
  text-transform: uppercase;
}
.hud-value {
  font-size: 24px;
  font-weight: 900;
  color: var(--accent);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 12px color-mix(in srgb, var(--accent) 30%, transparent);
}

/* ── Scorecard ───────────────────────────────────────────────────── */
.scorecard {
  display: grid;
  grid-template-columns: repeat(9, 1fr) 1.4fr;
  gap: 1px;
  background: var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}
.frame {
  background: linear-gradient(180deg, var(--surface), color-mix(in srgb, var(--surface) 92%, #000));
  padding: 4px 2px;
  display: flex;
  flex-direction: column;
  min-height: 54px;
  position: relative;
  transition: background 0.25s ease;
}
.frame.active {
  background: linear-gradient(180deg, #fff8c8, #ffd54f);
  box-shadow: 0 0 12px rgba(255, 213, 79, 0.6) inset;
}
.frame-throws {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  font-size: 11px;
  font-weight: 800;
  color: var(--text-strong);
  height: 16px;
  border-bottom: 1px solid var(--border);
  padding: 0 2px;
  font-variant-numeric: tabular-nums;
}
.frame.last .frame-throws {
  /* 10th frame has up to 3 throws */
  gap: 2px;
}
.frame-total {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.throw.strike { color: #c0392b; }
.throw.spare  { color: #2980b9; }

/* ── Scene canvas ────────────────────────────────────────────────── */
#scene-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 11;
  max-height: 460px;
  /* Layered ambience — radial neon glow + base gradient */
  background:
    radial-gradient(ellipse 70% 50% at 50% 30%, rgba(255, 110, 180, 0.18), transparent 60%),
    radial-gradient(ellipse 60% 45% at 50% 75%, rgba(92, 198, 255, 0.14), transparent 65%),
    linear-gradient(180deg, #0e1428 0%, #1a2638 45%, #060a18 100%);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow:
    0 0 0 2px rgba(255, 215, 0, 0.15) inset,
    0 12px 28px rgba(0,0,0,0.5),
    0 0 50px rgba(92, 198, 255, 0.18);
}
#scene-wrap #scene {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* "Strike!" / "Spare!" / "Gutter…" message overlay — STRIKE gets oversize
   chromatic / rainbow treatment for maximum drama. */
.throw-msg {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.78);
  color: gold;
  padding: 14px 32px;
  border-radius: 14px;
  font-size: 42px;
  font-weight: 900;
  letter-spacing: 6px;
  pointer-events: none;
  z-index: 5;
  animation: throw-msg-pop 1.7s cubic-bezier(.2,.7,.3,1) forwards;
  text-shadow:
    0 0 8px gold,
    0 0 20px gold,
    0 0 36px #ff8800,
    0 2px 0 #5b1a14;
  white-space: nowrap;
}
.throw-msg[hidden] { display: none; }
.throw-msg.spare  { color: #4af0ff; text-shadow: 0 0 8px #4af0ff, 0 0 24px #4af0ff, 0 2px 0 #08506a; }
.throw-msg.gutter { color: #ff7676; text-shadow: 0 0 8px #ff7676; font-size: 24px; }
.throw-msg.open   { color: #fff;    text-shadow: 0 0 8px #fff;    font-size: 24px; }
@keyframes throw-msg-pop {
  0%   { opacity: 0; transform: translateX(-50%) scale(0.4) rotate(-3deg); }
  10%  { opacity: 1; transform: translateX(-50%) scale(1.35) rotate(2deg); }
  20%  { transform: translateX(-50%) scale(1.05) rotate(-1deg); }
  30%  { transform: translateX(-50%) scale(1.15) rotate(1deg); }
  85%  { opacity: 1; transform: translateX(-50%) scale(1) rotate(0deg); }
  100% { opacity: 0; transform: translate(-50%, -28px) scale(0.85); }
}

/* Body screen-shake on STRIKE — short violent jolt felt across the whole UI */
body.bowling-strike-shake { animation: bowling-shake 0.85s cubic-bezier(.36,.07,.19,.97); }
@keyframes bowling-shake {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(-10px, 5px); }
  20% { transform: translate( 9px, -4px); }
  30% { transform: translate(-8px, 6px); }
  40% { transform: translate( 7px, -5px); }
  55% { transform: translate(-5px, 4px); }
  70% { transform: translate( 4px, -3px); }
  85% { transform: translate(-2px, 1px); }
}

/* Tighter, faster shake when ball first contacts pins (NOT a strike, just
   the moment of impact). High-frequency jitter, quick decay. */
body.bowling-impact-shake { animation: bowling-impact 0.32s cubic-bezier(.36,.07,.19,.97); }
@keyframes bowling-impact {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(-5px, 3px); }
  25% { transform: translate( 6px, -3px); }
  40% { transform: translate(-4px, 2px); }
  55% { transform: translate( 3px, -2px); }
  75% { transform: translate(-1px, 1px); }
}

/* ── Swipe overlay (renders the drag arrow over the 3D scene) ────── */
.swipe-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.swipe-overlay.active { opacity: 1; }

.swipe-hint {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  padding: 8px 16px;
  border-radius: 18px;
  font-size: 12px;
  letter-spacing: 0.5px;
  pointer-events: none;
  z-index: 4;
  text-shadow: 0 1px 2px rgba(0,0,0,0.7);
  border: 1px solid rgba(255, 215, 0, 0.25);
  box-shadow: 0 0 12px rgba(255, 215, 0, 0.2);
}
.swipe-hint.fade { opacity: 0; transition: opacity 0.4s ease; }

#scene-wrap #scene { cursor: grab; }
#scene-wrap.dragging #scene { cursor: grabbing; }

.action-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
}
.action-row .btn {
  min-width: 130px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--btn-bg) 110%, #fff), var(--btn-bg));
  border: 1px solid var(--border);
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  font-weight: 700;
  letter-spacing: 0.5px;
}
.action-row .btn:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}
.action-row .btn.primary {
  background: linear-gradient(180deg, #e74c3c, #922b21);
  color: #fff;
  border: none;
  font-weight: 900;
  font-size: 16px;
  letter-spacing: 2px;
  min-width: 180px;
  padding: 12px 24px;
  border-radius: 10px;
  box-shadow: 0 4px 0 #5b1a14, 0 6px 14px rgba(0,0,0,0.35);
  user-select: none;
  touch-action: manipulation;
  animation: throw-btn-pulse 1.8s ease-in-out infinite alternate;
}
@keyframes throw-btn-pulse {
  0%   { box-shadow: 0 4px 0 #5b1a14, 0 6px 14px rgba(0,0,0,0.35), 0 0 0 0 rgba(255, 215, 0, 0); }
  100% { box-shadow: 0 4px 0 #5b1a14, 0 6px 14px rgba(0,0,0,0.35), 0 0 24px 6px rgba(255, 215, 0, 0.55); }
}
.action-row .btn.primary:active,
.action-row .btn.primary.charging {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #5b1a14, 0 4px 8px rgba(0,0,0,0.4);
  animation: none;
}
.action-row .btn.primary:disabled {
  background: linear-gradient(180deg, #555, #333);
  color: #999;
  cursor: not-allowed;
  animation: none;
  box-shadow: 0 2px 0 #222;
}

/* Power meter — fills while user holds the throw button */
.power-meter {
  position: relative;
  height: 18px;
  background: var(--btn-bg);
  border-radius: 10px;
  margin-top: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 2px 4px rgba(0,0,0,0.15) inset;
}
.power-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #4caf50, #ffeb3b 50%, #f44336);
  transition: width 0.04s linear;
  border-radius: 9px;
  box-shadow: 0 0 10px rgba(255, 235, 59, 0.5);
}
.power-fill.releasing {
  animation: power-flash 0.35s ease-out;
}
@keyframes power-flash {
  0%   { filter: brightness(1.8) saturate(1.5); }
  100% { filter: brightness(1) saturate(1); }
}
.power-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.7);
  letter-spacing: 1.5px;
  pointer-events: none;
}

/* ── 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: 1fr 1fr; }
  #scene-wrap { aspect-ratio: 3 / 4; max-height: 540px; }
  .scorecard { font-size: 10px; }
  .frame { min-height: 44px; }
  .frame-total { font-size: 12px; }
  .controls { grid-template-columns: 1fr; }
}
