:root {
  --cyan: #00d4ff;
  --cyan-soft: rgba(0, 212, 255, 0.35);
  --panel: rgba(6, 10, 20, 0.78);
  --ink: #e0faff;
  --muted: #8fb2c0;
  --danger: #ff3355;
  --gold: #ffd24a;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: #000;
  color: var(--ink);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* hidden media sources: in the viewport (so they keep playing) but invisible */
.src {
  position: fixed; left: 0; top: 0; width: 2px; height: 2px;
  opacity: 0.01; pointer-events: none; z-index: -1;
}

#stage { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; z-index: 1; }
#flash { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 90; }
#flash.go { animation: flash 0.35s ease-out; }
@keyframes flash { 0% { opacity: 0.85; } 100% { opacity: 0; } }

/* ---------- HUD ---------- */
#hud {
  position: fixed; top: calc(14px + var(--safe-t)); left: calc(14px + var(--safe-l)); z-index: 30;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; max-width: calc(100vw - 28px);
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid var(--cyan-soft);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  padding: 8px 14px; border-radius: 22px;
  font-size: 13px; user-select: none;
}
#hand_info {
  position: fixed; top: calc(64px + var(--safe-t)); left: calc(18px + var(--safe-l)); z-index: 30;
  font-size: 12px; color: rgba(224, 250, 255, 0.75); text-shadow: 0 1px 3px #000; pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #ffaa00; box-shadow: 0 0 8px #ffaa00; flex: none; }
.status-dot.ready { background: #00fbff; box-shadow: 0 0 8px #00fbff; }
.status-dot.error { background: var(--danger); box-shadow: 0 0 8px var(--danger); }

button {
  font: inherit; color: #fff; cursor: pointer;
  background: rgba(0, 212, 255, 0.15);
  border: 1px solid rgba(0, 212, 255, 0.4);
  padding: 8px 14px; border-radius: 999px;
  transition: background 0.2s, transform 0.1s;
}
button:hover { background: rgba(0, 212, 255, 0.3); }
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: linear-gradient(135deg, #00b7ff, #3a6bff); border-color: transparent; font-weight: 700; }
button.primary:hover { filter: brightness(1.12); }
.hud-btn { padding: 4px 10px; font-size: 12px; }
.hud-btn.active { background: rgba(0, 212, 255, 0.45); box-shadow: 0 0 10px rgba(0, 251, 255, 0.4); }

/* ---------- dock ---------- */
#dock {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(14px + var(--safe-b)); z-index: 40;
  display: flex; gap: 6px; padding: 6px;
  background: var(--panel); border: 1px solid var(--cyan-soft);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-radius: 24px; max-width: calc(100vw - 16px); overflow-x: auto; scrollbar-width: none;
}
#dock::-webkit-scrollbar { display: none; }
.dock-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 58px; padding: 6px 8px; border-radius: 16px; background: transparent; border-color: transparent; font-size: 11px;
}
.dock-btn i { font-style: normal; font-size: 20px; line-height: 1.1; }
.dock-btn.active { background: rgba(0, 212, 255, 0.35); border-color: var(--cyan-soft); }
.dock-btn.rec { background: rgba(255, 51, 85, 0.35); border-color: rgba(255, 51, 85, 0.7); }
.dock-btn.rec i { animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.25; } }

#rec_badge {
  position: fixed; top: calc(14px + var(--safe-t)); right: calc(14px + var(--safe-r)); z-index: 35;
  display: none; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.65); border: 1px solid rgba(255, 51, 85, 0.7); font-size: 12px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
#rec_badge.show { display: flex; }
#rec_badge i { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); animation: blink 1s steps(2) infinite; }

/* ---------- bars / game hud ---------- */
#bars {
  position: fixed; top: calc(66px + var(--safe-t)); left: 50%; transform: translateX(-50%); z-index: 30;
  width: min(340px, 34vw); display: none; flex-direction: column; gap: 5px; pointer-events: none;
}
#bars.show { display: flex; }
.bar-row { display: flex; align-items: center; gap: 8px; font-size: 10px; letter-spacing: 0.08em; color: #cfe9f2; }
.bar-row label { width: 52px; text-align: right; }
.bar { flex: 1; height: 10px; background: rgba(0, 0, 0, 0.6); border-radius: 6px; overflow: hidden; border: 1px solid rgba(255, 255, 255, 0.18); }
.fill { height: 100%; width: 100%; transition: width 0.12s linear; }
.fill.hp { background: linear-gradient(90deg, #ff3355, #ff8a5a); }
.fill.ck { background: linear-gradient(90deg, #00b7ff, #7df9ff); }
.fill.ck.low { background: #66727a; }

.hud-card {
  position: fixed; top: calc(14px + var(--safe-t)); right: calc(14px + var(--safe-r)); z-index: 30;
  display: none; gap: 14px; padding: 8px 14px; border-radius: 16px;
  background: rgba(0, 0, 0, 0.65); border: 1px solid var(--cyan-soft); backdrop-filter: blur(8px);
  text-align: center; pointer-events: none;
}
.hud-card.show { display: flex; }
.hud-card small { display: block; font-size: 9px; letter-spacing: 0.12em; color: var(--muted); }
.hud-card b { font-size: 18px; color: var(--gold); font-variant-numeric: tabular-nums; }
body[data-mode='game'] #rec_badge { top: calc(76px + var(--safe-t)); }

#toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translate(-50%, 10px);
  z-index: 150; max-width: min(92vw, 560px); text-align: center;
  background: rgba(0, 0, 0, 0.78); border: 1px solid var(--cyan-soft); border-radius: 14px; padding: 10px 16px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- modals ---------- */
.modal, #start {
  position: fixed; inset: 0; z-index: 100; display: none; align-items: center; justify-content: center;
  background: rgba(0, 4, 10, 0.62); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); padding: 16px;
}
.modal.open { display: flex; }
#start { display: flex; z-index: 200; background: radial-gradient(circle at 50% 30%, #0b1f33 0%, #02060d 70%); }
#start.hidden { display: none; }

.card {
  width: min(460px, 100%); max-height: 100%; overflow: auto;
  background: rgba(8, 14, 26, 0.95); border: 1px solid var(--cyan-soft); border-radius: 20px; padding: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.card.wide { width: min(760px, 100%); }
.card h1 { margin: 0 0 10px; font-size: 30px; letter-spacing: 0.04em; }
.card h1 em { font-style: normal; color: var(--cyan); }
.card h2 { margin: 0 0 12px; font-size: 22px; }
.card h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }
.card p { line-height: 1.5; }
.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; }
.row { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 14px; }
#start .card { text-align: center; }
#start button.primary { padding: 12px 28px; font-size: 16px; margin: 8px 0; }

#gesture_list { list-style: none; padding: 0; margin: 0 0 8px; display: grid; gap: 8px; font-size: 14px; line-height: 1.4; }
#gesture_list li { background: rgba(0, 212, 255, 0.07); border-radius: 10px; padding: 8px 10px; }
#gesture_list b { display: inline-block; min-width: 128px; color: var(--cyan); }

.field { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 10px 0; }
select, input {
  font: inherit; color: #fff; background: rgba(255, 255, 255, 0.08); border: 1px solid var(--cyan-soft);
  border-radius: 10px; padding: 8px 10px; min-width: 0;
}
select option { color: #000; }

#cap_img, #cap_video { width: 100%; max-height: 62vh; object-fit: contain; border-radius: 12px; background: #000; display: block; }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.split > div { display: flex; flex-direction: column; gap: 8px; }
.split input { width: 100%; }
#duel_code_box { display: none; flex-direction: column; gap: 8px; }
#duel_code_box.show { display: flex; }
.code { font-size: 34px; font-weight: 900; letter-spacing: 0.18em; text-align: center; color: var(--gold); }
#duel_join_input { text-transform: uppercase; letter-spacing: 0.15em; text-align: center; font-weight: 700; }
#duel_status.bad { color: #ff8a8a; }
#duel_result { text-align: center; font-size: 38px; color: var(--danger); margin: 6px 0 0; }
#duel_result.win { color: var(--gold); }

.stats { width: 100%; border-collapse: collapse; font-size: 16px; }
.stats td { padding: 6px 4px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.stats td:last-child { text-align: right; font-weight: 800; color: var(--gold); }

@media (max-width: 620px) {
  #hud { font-size: 12px; padding: 6px 10px; gap: 6px; }
  #hand_info { top: calc(84px + var(--safe-t)); }
  .dock-btn { min-width: 52px; }
  #bars { width: 44vw; top: calc(104px + var(--safe-t)); }
  .split { grid-template-columns: 1fr; }
  #gesture_list b { min-width: 0; display: block; }
}
@media (prefers-reduced-motion: reduce) {
  #flash.go { animation-duration: 0.01s; }
}
