/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --red:      #ff2d2d;
  --green:    #00e676;
  --yellow:   #ffd600;
  --bg:       #1a1a2e;
  --card:     #16213e;
  --text:     #ffffff;
  --accent:   #e94560;
  --font:     'Segoe UI', 'Comic Sans MS', cursive, sans-serif;
  --radius:   20px;
  --sidebar-w: 190px;
}

html, body {
  width: 100%; height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  user-select: none;
}

/* ===== SCREENS ===== */
.screen {
  display: none;
  position: fixed; inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.screen.active { display: flex; }
.hidden { display: none !important; }

/* ===== START SCREEN ===== */
#screen-start {
  background: radial-gradient(ellipse at center, #0f3460 0%, #1a1a2e 70%);
  overflow-y: auto;
}

.start-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 24px 20px;
  width: 100%;
  max-width: 480px;
}

/* Daruma on start screen */
.start-daruma { line-height: 0; }
.start-daruma .daruma-svg {
  width: 110px;
  height: auto;
  filter: drop-shadow(0 12px 24px rgba(192,57,43,0.6));
}

.daruma-bounce { animation: darumaFloat 2.5s ease-in-out infinite; }
@keyframes darumaFloat {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50%       { transform: translateY(-14px) rotate(3deg); }
}

.game-title {
  font-size: clamp(2rem, 6vw, 3.4rem);
  font-weight: 900;
  text-align: center;
  line-height: 1.1;
  background: linear-gradient(135deg, var(--red), var(--yellow), var(--green));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 2px 6px rgba(255,255,255,0.08));
}

.subtitle {
  font-size: 1rem;
  text-align: center;
  color: #ccc;
  line-height: 1.6;
}

/* Player name */
.name-row { width: 100%; }
#player-name {
  width: 100%;
  padding: 12px 18px;
  background: rgba(255,255,255,0.07);
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 30px;
  color: white;
  font-size: 1rem;
  font-family: var(--font);
  outline: none;
  text-align: center;
  transition: border-color 0.2s;
}
#player-name::placeholder { color: #888; }
#player-name:focus { border-color: var(--accent); }

/* Option groups */
.option-group { width: 100%; text-align: center; }
.option-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #aaa;
  display: block;
  margin-bottom: 8px;
}

.lang-buttons, .diff-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.lang-btn, .diff-btn {
  padding: 9px 14px;
  border: 2px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.05);
  color: #ccc;
  border-radius: 30px;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
  white-space: nowrap;
}
.lang-btn:hover, .lang-btn.active,
.diff-btn:hover, .diff-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  transform: scale(1.05);
}

.start-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-main {
  padding: 14px 44px;
  font-size: 1.3rem;
  font-weight: 800;
  font-family: var(--font);
  border: none;
  border-radius: 50px;
  background: linear-gradient(135deg, var(--accent), #ff6b35);
  color: white;
  cursor: pointer;
  box-shadow: 0 8px 30px rgba(233,69,96,0.5);
  transition: transform 0.15s, box-shadow 0.15s;
}
.btn-main:hover  { transform: scale(1.07); box-shadow: 0 12px 40px rgba(233,69,96,0.7); }
.btn-main:active { transform: scale(0.97); }

.btn-secondary {
  padding: 12px 22px;
  font-size: 1rem;
  font-weight: 700;
  font-family: var(--font);
  border: 2px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.05);
  color: #ccc;
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-secondary:hover { background: rgba(255,255,255,0.1); color: white; }

.pulse { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 8px 30px rgba(233,69,96,0.5); }
  50%       { box-shadow: 0 8px 50px rgba(233,69,96,0.9), 0 0 0 10px rgba(233,69,96,0.1); }
}

.camera-notice { font-size: 0.78rem; color: #666; text-align: center; }

/* ===== GAME SCREEN ===== */
#screen-game {
  background: linear-gradient(180deg, #0d1b2a 0%, #1a1a2e 100%);
  padding: 0;
  overflow: hidden;
}

/* HUD */
#hud {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 14px;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255,255,255,0.05);
  z-index: 50;
  gap: 6px;
}
#hud > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.hud-label { font-size: 0.58rem; text-transform: uppercase; letter-spacing: 1px; color: #666; }
#score-value, #round-value { font-size: 1.3rem; font-weight: 900; color: var(--yellow); }
#score-value { transition: transform 0.2s, color 0.2s; }

#lives-display { display: flex; gap: 2px; font-size: 1.1rem; }
.life-heart { display: inline-block; transition: all 0.3s; }
.life-heart.lost { filter: grayscale(1) opacity(0.3); transform: scale(0.8); }

/* Timer Ring */
#timer-ring-wrap {
  position: relative;
  width: 52px; height: 52px;
  flex-shrink: 0;
}
#timer-ring { width: 52px; height: 52px; }
#timer-number {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.95rem; font-weight: 900; color: var(--yellow);
}
#timer-progress { transition: stroke-dashoffset 0.95s linear, stroke 0.3s; }

/* ===== GAME AREA: sidebar + camera ===== */
#game-area {
  flex: 1;
  display: flex;
  align-items: stretch;
  width: 100%;
  overflow: hidden;
}

/* Sidebar */
#game-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 12px 8px;
  background: rgba(0,0,0,0.35);
  border-right: 1px solid rgba(255,255,255,0.05);
  gap: 10px;
}

/* Traffic Light */
#traffic-light { display: flex; flex-direction: column; align-items: center; }
.light-housing {
  background: #111;
  border: 3px solid #2a2a2a;
  border-radius: 16px;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.6);
}
.light {
  width: 58px; height: 58px;
  border-radius: 50%;
  background: #252525;
  border: 3px solid #1a1a1a;
  transition: all 0.3s ease;
  position: relative;
}
.light::after {
  content: '';
  position: absolute;
  top: 8px; left: 8px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
}
#light-red.on {
  background: var(--red);
  box-shadow: 0 0 30px var(--red), 0 0 60px rgba(255,45,45,0.4);
  border-color: #ff6666;
}
#light-green.on {
  background: var(--green);
  box-shadow: 0 0 30px var(--green), 0 0 60px rgba(0,230,118,0.4);
  border-color: #66ffaa;
}
.light-post {
  width: 12px; height: 36px;
  background: linear-gradient(180deg, #555, #333);
  border-radius: 0 0 4px 4px;
  margin: 0 auto;
}

/* Daruma in sidebar */
#daruma-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  width: 100%;
  padding-bottom: 8px;
}

#daruma-game {
  width: 100%;
  max-width: 155px;
  height: auto;
  filter: drop-shadow(0 8px 20px rgba(192,57,43,0.5));
  transform-origin: center bottom;
}

/* Daruma state animations */
#daruma-game.daruma-idle  { animation: darumaIdleRock 4s ease-in-out infinite; }
#daruma-game.daruma-green { animation: darumaHappy 0.35s ease-in-out infinite alternate; }
#daruma-game.daruma-red   { transform: scaleX(-1); filter: drop-shadow(0 8px 20px rgba(255,45,45,0.6)); }
#daruma-game.daruma-angry { animation: darumaAngry 0.25s ease-in-out 5; filter: drop-shadow(0 8px 20px rgba(255,45,45,0.8)); }

@keyframes darumaIdleRock {
  0%, 100% { transform: rotate(-2deg); }
  50%       { transform: rotate(2deg); }
}
@keyframes darumaHappy {
  from { transform: translateY(0) rotate(-3deg) scale(1); }
  to   { transform: translateY(-7px) rotate(3deg) scale(1.04); }
}
@keyframes darumaAngry {
  0%, 100% { transform: scaleX(-1) rotate(0); }
  25%       { transform: scaleX(-1) rotate(-8deg) scale(1.06); }
  75%       { transform: scaleX(-1) rotate(8deg) scale(1.06); }
}

/* Speech bubble */
#doll-speech {
  background: white;
  color: #333;
  border-radius: 14px 14px 14px 4px;
  padding: 7px 11px;
  font-size: 0.76rem;
  font-weight: 700;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  opacity: 0;
  transform: translateY(4px);
  transition: all 0.3s;
  max-width: 165px;
  line-height: 1.35;
  word-break: break-word;
}
#doll-speech.visible { opacity: 1; transform: translateY(0); }

/* ===== CAMERA — takes remaining space ===== */
#camera-container {
  flex: 1;
  position: relative;
  background: #000;
  overflow: hidden;
}

#webcam {
  width: 100%; height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  display: block;
}
#pose-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  transform: scaleX(-1);
  pointer-events: none;
}
#camera-overlay {
  position: absolute; inset: 0;
  pointer-events: none;
  transition: box-shadow 0.4s;
}
#camera-overlay.state-green {
  box-shadow: inset 0 0 0 5px var(--green), 0 0 40px rgba(0,230,118,0.15);
}
#camera-overlay.state-red {
  box-shadow: inset 0 0 0 5px var(--red), 0 0 40px rgba(255,45,45,0.15);
}
#camera-overlay.state-caught {
  box-shadow: inset 0 0 0 7px var(--red), 0 0 70px rgba(255,45,45,0.7);
  animation: caughtFlash 0.25s ease-in-out 5;
}
@keyframes caughtFlash {
  0%, 100% { background: transparent; }
  50%       { background: rgba(255,45,45,0.28); }
}

#scan-line {
  position: absolute; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, rgba(0,230,118,0.9), transparent);
  top: -3px; display: none;
}
#scan-line.active { display: block; animation: scanDown 2s linear infinite; }
@keyframes scanDown { from { top: -3px; } to { top: 100%; } }

#movement-indicator {
  position: absolute;
  bottom: 12px; left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.78);
  backdrop-filter: blur(5px);
  border-radius: 20px;
  padding: 6px 18px;
  font-size: 0.78rem; font-weight: 700; letter-spacing: 1px;
  opacity: 0; transition: opacity 0.3s;
  border: 1px solid rgba(255,255,255,0.1);
  white-space: nowrap;
}
#movement-indicator.visible { opacity: 1; }
#movement-indicator.safe    { color: var(--green); border-color: var(--green); }
#movement-indicator.moving  { color: var(--red);   border-color: var(--red); }

#camera-badge {
  position: absolute; top: 10px; right: 12px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.7rem; color: #999; letter-spacing: 0.5px;
}

/* Status Banner */
#status-banner {
  width: 100%; text-align: center;
  padding: 9px;
  font-size: clamp(1rem, 2.4vw, 1.55rem);
  font-weight: 900; letter-spacing: 2px; text-transform: uppercase;
  transition: all 0.3s;
  border-top: 1px solid rgba(255,255,255,0.04);
}
#status-banner.state-green {
  background: rgba(0,230,118,0.1); color: var(--green);
  text-shadow: 0 0 20px rgba(0,230,118,0.5);
}
#status-banner.state-red {
  background: rgba(255,45,45,0.1); color: var(--red);
  text-shadow: 0 0 20px rgba(255,45,45,0.5);
}
#status-banner.state-neutral { background: rgba(255,255,255,0.02); color: #777; }

/* Countdown Overlay */
#countdown-overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.72);
  backdrop-filter: blur(8px);
  z-index: 100;
}
#countdown-number {
  font-size: clamp(5rem, 18vw, 13rem);
  font-weight: 900;
  animation: countPop 0.85s ease-out forwards;
  line-height: 1;
}
@keyframes countPop {
  0%   { transform: scale(0.2); opacity: 0; }
  65%  { transform: scale(1.25); opacity: 1; }
  100% { transform: scale(1);    opacity: 1; }
}

/* Caught Overlay */
#caught-overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(220,0,0,0.18);
  backdrop-filter: blur(3px);
  z-index: 90;
}
.caught-text {
  font-size: clamp(1.8rem, 7vw, 3.4rem);
  font-weight: 900; color: white;
  text-shadow: 0 0 30px rgba(255,80,80,0.9), 0 4px 8px rgba(0,0,0,0.5);
  animation: caughtShake 0.4s ease-in-out;
}
@keyframes caughtShake {
  0%, 100% { transform: translateX(0) rotate(0); }
  20%       { transform: translateX(-14px) rotate(-3deg); }
  40%       { transform: translateX(14px)  rotate(3deg); }
  60%       { transform: translateX(-9px)  rotate(-2deg); }
  80%       { transform: translateX(9px)   rotate(2deg); }
}

/* ===== RESULT SCREENS ===== */
#screen-win, #screen-lose { gap: 18px; padding: 30px; text-align: center; }
#screen-win  { background: radial-gradient(ellipse at center, #0a3d20 0%, #1a1a2e 70%); }
#screen-lose { background: radial-gradient(ellipse at center, #3d0a0a 0%, #1a1a2e 70%); }

.result-emoji { font-size: 90px; }
.shake-emoji  { animation: caughtShake 0.6s ease-in-out infinite; }
.result-title { font-size: clamp(2.2rem, 6vw, 3.5rem); font-weight: 900; }
#screen-win  .result-title { color: var(--green); text-shadow: 0 0 30px rgba(0,230,118,0.4); }
#screen-lose .result-title { color: var(--red);   text-shadow: 0 0 30px rgba(255,45,45,0.4); }
.result-msg  { color: #ccc; font-size: 1rem; }
.final-score { font-size: 1.6rem; font-weight: 800; color: var(--yellow); }
.result-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

/* ===== LEADERBOARD MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.78);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  z-index: 300; padding: 20px;
}
.modal-box {
  background: #16213e;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 24px;
  width: 100%; max-width: 560px; max-height: 80vh;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
.modal-header h2 { font-size: 1.35rem; color: var(--yellow); }

.modal-close {
  background: rgba(255,255,255,0.06); border: none;
  color: #aaa; font-size: 1rem;
  width: 32px; height: 32px;
  border-radius: 50%; cursor: pointer;
  transition: all 0.2s; font-family: var(--font);
}
.modal-close:hover { background: var(--accent); color: white; }

#lb-table-wrap { flex: 1; overflow-y: auto; padding: 8px 0; }

#lb-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
#lb-table thead th {
  padding: 8px 16px; text-align: left;
  color: #777; font-size: 0.72rem;
  text-transform: uppercase; letter-spacing: 0.5px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
#lb-table tbody tr { border-bottom: 1px solid rgba(255,255,255,0.04); }
#lb-table tbody tr:hover { background: rgba(255,255,255,0.03); }
#lb-table tbody td { padding: 10px 16px; color: #ccc; }
/* Medal colors */
#lb-table tbody tr:nth-child(1) td { color: var(--yellow); font-weight: 800; font-size: 0.95rem; }
#lb-table tbody tr:nth-child(2) td { color: #c0c0c0; font-weight: 700; }
#lb-table tbody tr:nth-child(3) td { color: #cd7f32; font-weight: 700; }

.lb-empty { text-align: center; color: #555; padding: 30px; font-size: 1rem; }

.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid rgba(255,255,255,0.07);
  display: flex; justify-content: flex-end;
}
.btn-danger {
  padding: 10px 22px;
  background: rgba(255,45,45,0.12);
  border: 1px solid rgba(255,45,45,0.35);
  color: var(--red); border-radius: 30px;
  font-size: 0.88rem; cursor: pointer;
  font-family: var(--font); font-weight: 700;
  transition: all 0.2s;
}
.btn-danger:hover { background: rgba(255,45,45,0.28); border-color: var(--red); }

/* ===== CONFETTI ===== */
#confetti-canvas {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 200;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  :root { --sidebar-w: 80px; }

  #game-sidebar { padding: 6px 4px; gap: 6px; }
  .light-housing { padding: 8px; gap: 8px; }
  .light { width: 42px; height: 42px; }
  .light-post { display: none; }

  #daruma-game { max-width: 68px; }
  #doll-speech { font-size: 0.65rem; max-width: 74px; padding: 5px 8px; }

  #timer-ring-wrap { width: 42px; height: 42px; }
  #timer-ring { width: 42px; height: 42px; }
  #timer-number { font-size: 0.72rem; }

  .modal-box { max-height: 90vh; }
  #lb-table thead th, #lb-table tbody td { padding: 8px 10px; font-size: 0.8rem; }
}
