:root {
  --bg-gradient-start: #0f172a;
  --bg-gradient-end: #1e293b;
  --panel-bg: rgba(15, 23, 42, 0.82);
  --panel-border: rgba(148, 163, 184, 0.18);
  --surface: rgba(30, 41, 59, 0.6);
  --text-primary: #e2e8f0;
  --text-secondary: #cbd5f5;
  --accent: #60a5fa;
  --accent-strong: #6366f1;
  --success: #22d3ee;
  --error: #f87171;
  --warning: #fbbf24;
  --shadow-soft: 0 18px 45px rgba(8, 15, 30, 0.35);
}

[data-theme="light"] {
  --bg-gradient-start: #f8fafc;
  --bg-gradient-end: #e0f2fe;
  --panel-bg: rgba(255, 255, 255, 0.92);
  --panel-border: rgba(148, 163, 184, 0.2);
  --surface: rgba(248, 250, 252, 0.85);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --accent: #4f46e5;
  --accent-strong: #8b5cf6;
  --success: #0ea5e9;
  --error: #ef4444;
  --warning: #f59e0b;
  --shadow-soft: 0 18px 40px rgba(99, 102, 241, 0.18);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: radial-gradient(circle at 20% 20%, rgba(96, 165, 250, 0.15), transparent 55%),
              radial-gradient(circle at 80% 0%, rgba(236, 72, 153, 0.12), transparent 60%),
              linear-gradient(160deg, var(--bg-gradient-start), var(--bg-gradient-end));
  color: var(--text-primary);
  display: flex;
  justify-content: center;
  padding: 40px 16px;
}

.page-shell {
  position: relative;
  width: min(1040px, 100%);
  padding: clamp(24px, 4vw, 40px);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 32px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px);
}

.theme-toggle {
  position: absolute;
  top: clamp(12px, 2vw, 20px);
  right: clamp(12px, 2vw, 20px);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-primary);
  font-size: 1.3rem;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.theme-toggle:hover {
  transform: translateY(-2px);
}

.hero {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: clamp(16px, 4vw, 32px);
  align-items: center;
  margin-bottom: clamp(32px, 5vw, 48px);
}

.hero-icon {
  width: clamp(64px, 12vw, 92px);
  height: clamp(64px, 12vw, 92px);
  border-radius: 24px;
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  display: grid;
  place-items: center;
  font-size: clamp(2.2rem, 5vw, 3.2rem);
  box-shadow: 0 18px 30px rgba(96, 165, 250, 0.25);
}

.hero-copy {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hero-title {
  font-size: clamp(2.2rem, 5vw, 3rem);
  font-weight: 800;
  line-height: 1.1;
}

.hero-subtitle {
  font-size: clamp(1rem, 2vw, 1.25rem);
  color: var(--text-secondary);
}

.hero-stats {
  display: flex;
  gap: 16px;
}

.stat {
  min-width: 90px;
  padding: 12px 18px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--panel-border);
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: clamp(24px, 4vw, 40px);
  align-items: start;
}

.game-panel {
  background: var(--surface);
  border-radius: 28px;
  border: 1px solid var(--panel-border);
  padding: clamp(24px, 4vw, 40px);
  display: grid;
  gap: clamp(24px, 4vw, 32px);
}

.board {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(16px, 3vw, 24px);
}

.pad {
  aspect-ratio: 1;
  border: none;
  border-radius: 28px;
  position: relative;
  cursor: pointer;
  overflow: hidden;
  transform: translateZ(0);
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.pad::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0.92;
  transition: opacity 0.2s ease;
}

.pad::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.65), transparent);
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

.pad-green::before { background: linear-gradient(135deg, #0ea5e9, #14b8a6); }
.pad-red::before { background: linear-gradient(135deg, #ef4444, #f97316); }
.pad-yellow::before { background: linear-gradient(135deg, #facc15, #fbbf24); }
.pad-blue::before { background: linear-gradient(135deg, #6366f1, #3b82f6); }

.pad:hover {
  transform: translateY(-4px);
  box-shadow: 0 16px 32px rgba(15, 23, 42, 0.35);
}

.pad.lit::before,
.pad:active::before {
  opacity: 1;
}

.pad.lit::after,
.pad:active::after {
  opacity: 1;
}

.pad.flash-error::before {
  animation: flashError 0.3s ease;
}

.pad.success-pulse::before {
  animation: successPulse 0.45s ease;
}

@keyframes flashError {
  0% { filter: brightness(1); }
  50% { filter: brightness(1.5); }
  100% { filter: brightness(1); }
}

@keyframes successPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.message {
  border-radius: 18px;
  padding: 16px 20px;
  font-size: 1rem;
  line-height: 1.5;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: background 0.3s ease, border-color 0.3s ease;
}

.message[data-state="ready"] { border-color: rgba(99, 102, 241, 0.35); }
.message[data-state="play"] { border-color: rgba(14, 165, 233, 0.35); }
.message[data-state="success"] { border-color: rgba(34, 211, 238, 0.45); }
.message[data-state="error"] { border-color: rgba(248, 113, 113, 0.45); }

.controls {
  display: flex;
  gap: 16px;
}

.control-btn {
  flex: 1;
  border: none;
  border-radius: 16px;
  padding: 14px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-primary);
}

.control-btn.primary {
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  color: white;
  box-shadow: 0 16px 30px rgba(99, 102, 241, 0.3);
}

.control-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.control-btn:not(:disabled):hover {
  transform: translateY(-3px);
}

.toggles {
  display: flex;
  gap: 12px;
}

.toggle-btn {
  flex: 1;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.2s ease;
}

.toggle-icon {
  font-size: 1.15rem;
}

.toggle-text {
  font-size: 0.95rem;
}

.toggle-btn.active {
  border-color: rgba(99, 102, 241, 0.45);
  background: rgba(99, 102, 241, 0.18);
}

.toggle-btn:hover {
  transform: translateY(-2px);
}

.info-panel {
  background: var(--surface);
  border-radius: 28px;
  border: 1px solid var(--panel-border);
  padding: clamp(24px, 4vw, 36px);
  display: grid;
  gap: clamp(20px, 3vw, 28px);
  align-self: stretch;
}

.info-panel h2 {
  font-size: 1.35rem;
  font-weight: 700;
}

.steps {
  display: grid;
  gap: 12px;
  list-style: none;
  counter-reset: step;
}

.steps li {
  background: rgba(255, 255, 255, 0.08);
  padding: 14px 16px;
  border-radius: 16px;
  position: relative;
  color: var(--text-secondary);
}

.steps li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  top: 50%;
  left: 16px;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  color: white;
  display: grid;
  place-items: center;
  font-weight: 700;
}

.steps li { padding-left: 60px; }

.tips {
  display: grid;
  gap: 10px;
}

.tips ul {
  list-style: none;
  display: grid;
  gap: 10px;
}

.tips li {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(148, 163, 184, 0.08);
  color: var(--text-secondary);
}

.footer {
  margin-top: clamp(28px, 5vw, 40px);
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.privacy {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 10px 16px;
  display: inline-block;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .info-panel {
    order: -1;
  }
}

@media (max-width: 640px) {
  body {
    padding: 24px 12px;
  }

  .page-shell {
    border-radius: 24px;
    padding: 24px 18px 28px;
  }

  .hero {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .hero-icon {
    margin: 0 auto;
  }

  .hero-stats {
    justify-content: center;
  }

  .controls {
    flex-direction: column;
  }

  .toggles {
    flex-direction: column;
  }
}
