:root {
  --bg-primary: #0D1117;
  --bg-secondary: #161B22;
  --bg-tertiary: #21262D;
  --text-primary: #F0F6FC;
  --text-secondary: #8B949E;
  --text-muted: #484F58;
  --accent: #3B82F6;
  --accent-glow: rgba(59, 130, 246, 0.3);
  --border: #30363D;
  --btn-bg: #21262D;
  --btn-active: #30363D;
  --overlay-bg: rgba(0, 0, 0, 0.85);
  --board-bg: #0A0E14;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg-primary: #FFFFFF;
    --bg-secondary: #F6F8FA;
    --bg-tertiary: #E9ECF0;
    --text-primary: #1B1E28;
    --text-secondary: #57606A;
    --text-muted: #8C959F;
    --accent: #3182F6;
    --accent-glow: rgba(49, 130, 246, 0.2);
    --border: #D0D7DE;
    --btn-bg: #E9ECF0;
    --btn-active: #D0D7DE;
    --overlay-bg: rgba(255, 255, 255, 0.9);
    --board-bg: #F0F2F5;
  }
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  touch-action: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Pretendard', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ===== OVERLAY SCREENS ===== */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 32px 24px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  background: var(--overlay-bg);
  transition: opacity 0.3s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ===== START SCREEN ===== */
#start-screen {
  gap: 0;
}

.game-icon {
  font-size: 72px;
  line-height: 1;
  margin-bottom: 20px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-10px); }
}

.game-title {
  font-size: 52px;
  font-weight: 900;
  letter-spacing: 4px;
  background: linear-gradient(135deg, #3B82F6, #8B5CF6, #EC4899);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 12px;
  text-align: center;
}

.game-subtitle {
  font-size: 15px;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 40px;
  line-height: 1.6;
}

.best-record-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 20px;
  margin-bottom: 40px;
  font-size: 13px;
  color: var(--text-secondary);
}

.best-record-badge .record-value {
  color: var(--accent);
  font-weight: 700;
  font-size: 15px;
}

.btn-start {
  width: 100%;
  max-width: 280px;
  padding: 18px 32px;
  border-radius: 16px;
  border: none;
  background: linear-gradient(135deg, #3B82F6, #8B5CF6);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 1px;
  box-shadow: 0 8px 32px rgba(59, 130, 246, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn-start:active {
  transform: scale(0.97);
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.25);
}

/* ===== GAME AREA ===== */
#game-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease;
  position: relative;
  cursor: pointer;
}

#game-area.state-idle {
  background: var(--bg-primary);
}

#game-area.state-waiting {
  background: linear-gradient(160deg, #7C1D1D, #C0392B, #E74C3C);
}

#game-area.state-go {
  background: linear-gradient(160deg, #1A4731, #1E8449, #27AE60);
}

#game-area.state-early {
  background: linear-gradient(160deg, #4A1F1F, #922B21, #C0392B);
}

/* ===== GAME HEADER (always visible) ===== */
.game-header {
  padding: 20px 20px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.round-indicator {
  display: flex;
  gap: 6px;
}

.round-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 1.5px solid var(--border);
  transition: all 0.3s ease;
}

.round-dot.done {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
}

.round-dot.current {
  background: transparent;
  border-color: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
  animation: pulse-dot 1.2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 6px var(--accent-glow); }
  50% { box-shadow: 0 0 12px var(--accent), 0 0 20px var(--accent-glow); }
}

.header-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.header-best {
  font-size: 12px;
  color: var(--text-muted);
}

.header-best span {
  color: var(--accent);
  font-weight: 700;
}

/* ===== GAME CONTENT AREA ===== */
.game-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 16px;
  text-align: center;
}

.state-label {
  font-size: 36px;
  font-weight: 900;
  letter-spacing: 1px;
  color: #fff;
  text-shadow: 0 2px 16px rgba(0,0,0,0.3);
  transition: all 0.3s ease;
}

.state-sublabel {
  font-size: 16px;
  color: rgba(255,255,255,0.75);
  font-weight: 500;
  line-height: 1.5;
}

.result-time-display {
  font-size: 72px;
  font-weight: 900;
  color: #fff;
  letter-spacing: -2px;
  text-shadow: 0 4px 24px rgba(0,0,0,0.2);
  line-height: 1;
}

.result-time-unit {
  font-size: 20px;
  font-weight: 400;
  opacity: 0.75;
  letter-spacing: 1px;
}

.rating-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  border-radius: 100px;
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(4px);
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.5px;
}

.tap-hint {
  font-size: 13px;
  color: rgba(255,255,255,0.5);
  margin-top: 8px;
}

/* ===== ROUND LOG (bottom strip) ===== */
.round-log {
  padding: 12px 20px 20px;
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.round-log-item {
  background: rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,0.8);
  border: 1px solid rgba(255,255,255,0.15);
}

.round-log-item.latest {
  background: rgba(255,255,255,0.25);
  color: #fff;
  border-color: rgba(255,255,255,0.35);
}

/* ===== RESULTS OVERLAY ===== */
#results-screen {
  gap: 0;
  padding: 32px 24px 40px;
  overflow-y: auto;
}

.results-title {
  font-size: 28px;
  font-weight: 900;
  background: linear-gradient(135deg, #3B82F6, #8B5CF6, #EC4899);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
  letter-spacing: 1px;
}

.results-avg-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

.results-avg-time {
  font-size: 64px;
  font-weight: 900;
  color: var(--text-primary);
  letter-spacing: -2px;
  line-height: 1;
}

.results-avg-unit {
  font-size: 18px;
  font-weight: 400;
  color: var(--text-secondary);
  letter-spacing: 1px;
}

.results-rating {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 28px;
  margin-top: 6px;
}

.results-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  margin-bottom: 24px;
}

.result-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  text-align: center;
}

.result-card-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 6px;
}

.result-card-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-primary);
}

.result-card-value .unit {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
}

.result-card.best .result-card-value {
  color: var(--accent);
}

.rounds-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 28px;
}

.rounds-list-title {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 4px;
  text-align: left;
}

.round-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
}

.round-row-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.round-row-time {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.round-row-time .unit {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}

.round-row.best-round .round-row-time {
  color: var(--accent);
}

.new-record-banner {
  width: 100%;
  background: linear-gradient(135deg, rgba(59,130,246,0.15), rgba(139,92,246,0.15));
  border: 1px solid rgba(59,130,246,0.3);
  border-radius: 12px;
  padding: 12px 20px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.5px;
  margin-bottom: 20px;
  display: none;
}

.new-record-banner.show {
  display: block;
  animation: pop-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pop-in {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.btn-retry {
  width: 100%;
  max-width: 280px;
  padding: 18px 32px;
  border-radius: 16px;
  border: none;
  background: linear-gradient(135deg, #3B82F6, #8B5CF6);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.5px;
  box-shadow: 0 8px 32px rgba(59, 130, 246, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn-retry:active {
  transform: scale(0.97);
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.25);
}

/* ===== ANIMATIONS ===== */
@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-in {
  animation: fade-in-up 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

@keyframes pulse-go {
  0% { transform: scale(1); }
  30% { transform: scale(1.08); }
  60% { transform: scale(0.97); }
  100% { transform: scale(1); }
}

.pulse-go {
  animation: pulse-go 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-8px); }
  80% { transform: translateX(8px); }
}

.shake {
  animation: shake 0.45s ease-in-out;
}

/* ===== IDLE STATE STYLES ===== */
#game-area.state-idle .state-label,
#game-area.state-idle .state-sublabel {
  color: var(--text-secondary);
}
