:root {
  --bg-1: #fef6ff;
  --bg-2: #e7f7ff;
  --ink: #2b3440;
  --ink-soft: #6b7785;
  --green: #6ecc7b;
  --green-dark: #3a8d4a;
  --pink: #ff9eb5;
  --pink-dark: #ff5d8a;
  --apple: #ff5d6c;
  --card: #ffffffd9;
  --shadow: 0 10px 30px rgba(80, 100, 130, 0.12);
  --radius: 18px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #ffe6f3 0%, transparent 60%),
    radial-gradient(1000px 500px at 110% 10%, #d8f1ff 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-1), var(--bg-2));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  max-width: 1100px;
  margin: 0 auto;
}
.topbar h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0.2px;
}
.scores { display: flex; gap: 10px; }
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.lang-select {
  background: var(--card);
  border: none;
  padding: 8px 12px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-weight: 700;
  font-size: 13px;
  color: var(--ink);
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  padding-right: 28px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' stroke='%232b3440' stroke-width='1.5' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.lang-select:hover { filter: brightness(0.97); }
.pill {
  background: var(--card);
  padding: 8px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-weight: 700;
  font-size: 14px;
  color: var(--ink-soft);
}
.pill span { color: var(--ink); margin-left: 6px; font-size: 16px; }

.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 28px 40px;
}
@media (max-width: 900px) {
  .stage { grid-template-columns: 1fr; }
}

.game-wrap {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
}
#game {
  width: 100%;
  max-width: 672px;
  aspect-ratio: 1 / 1;
  height: auto;
  border-radius: var(--radius-sm);
  background: #f4fbe9;
  display: block;
  image-rendering: optimizeQuality;
}

.overlay {
  position: absolute;
  inset: 16px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  transition: opacity 0.25s ease;
}
.overlay.hidden { opacity: 0; pointer-events: none; }

.card {
  background: white;
  padding: 28px 32px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
  max-width: 360px;
}
.card.hidden { display: none; }
.card h2 { margin: 0 0 8px; font-size: 24px; }
.card p { margin: 6px 0 14px; color: var(--ink-soft); line-height: 1.5; }
.card .muted { font-size: 12px; opacity: 0.75; margin-top: 14px; }

.btn {
  display: inline-block;
  border: none;
  cursor: pointer;
  font-weight: 700;
  font-size: 15px;
  padding: 11px 22px;
  border-radius: 999px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.2s;
  margin: 4px 4px 0;
  font-family: inherit;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(180deg, #7ed98c, var(--green-dark));
  color: white;
  box-shadow: 0 4px 0 #2c7039, var(--shadow);
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost {
  background: #f1f3f7;
  color: var(--ink);
}
.btn-ghost:hover { background: #e6eaf1; }

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.cam-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.cam-card h3 { margin: 0 0 10px; font-size: 16px; }
.cam-frame {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #1e2a36;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.cam-frame video,
.cam-frame canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* mirror */
}
.cam-status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #cdd5e0;
  font-size: 13px;
  background: rgba(30, 42, 54, 0.6);
}
.cam-status.hidden { display: none; }

.quality { margin: 12px 0 8px; }
.quality label { font-size: 12px; color: var(--ink-soft); }
.bar {
  height: 8px;
  background: #eef1f6;
  border-radius: 999px;
  margin-top: 4px;
  overflow: hidden;
}
#qualityBar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ff9eb5, #7ed98c);
  transition: width 0.2s ease;
}

.slider-row { margin: 10px 0 4px; }
.slider-row label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 4px;
}
.slider-row label span { color: var(--ink); font-weight: 700; }
.slider-row input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
}
.slider-row input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffd6e7, #c8f4b6);
}
.slider-row input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffd6e7, #c8f4b6);
}
.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  border: 2px solid var(--green-dark);
  margin-top: -5px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}
.slider-row input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  border: 2px solid var(--green-dark);
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.dir-indicator {
  display: grid;
  grid-template-rows: auto auto auto;
  justify-items: center;
  gap: 4px;
  margin: 12px 0;
  user-select: none;
}
.dir-indicator .dir-row { display: flex; gap: 6px; }
.dir-indicator .dir,
.dir-indicator .center {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #f1f3f7;
  color: #b0b8c4;
  font-size: 14px;
  transition: background 0.15s, color 0.15s, transform 0.15s;
}
.dir-indicator .dir.active {
  background: var(--green);
  color: white;
  transform: scale(1.1);
}

.help {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow);
  font-size: 13px;
  color: var(--ink-soft);
}
.help summary { cursor: pointer; font-weight: 700; color: var(--ink); }
.help p { margin: 8px 0 0; line-height: 1.5; }
