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

:root {
  --bg: #0a0a0f;
  --surface: #12121a;
  --border: #1e1e2e;
  --text: #e0e0f0;
  --text-dim: #6b6b8b;
  --accent: #7c5cfc;
  --accent-glow: rgba(124, 92, 252, 0.25);
  --success: #34d399;
  --error: #f87171;
  --radius: 12px;
  --radius-sm: 8px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
  gap: 12px;
  flex-wrap: wrap;
}

header h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.accent { color: var(--accent); }

nav {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 3px;
  border: 1px solid var(--border);
}

.nav-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.nav-btn.active {
  background: var(--accent);
  color: white;
}

.nav-btn:hover:not(.active) { color: var(--text); }

.score-card {
  display: flex;
  gap: 12px;
  font-size: 14px;
  font-weight: 600;
}

.score-card .score { color: var(--text-dim); }
.score-card .streak { color: #fbbf24; }

/* Game Area */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.mode { display: none; flex-direction: column; align-items: center; gap: 28px; width: 100%; }
.mode.active { display: flex; }

/* Decode Mode */
.flash-area {
  width: 160px;
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.morse-flash {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--border);
  transition: all 0.1s;
}

.morse-flash.on {
  background: var(--accent);
  box-shadow: 0 0 60px var(--accent-glow), 0 0 120px rgba(124, 92, 252, 0.1);
  border-color: var(--accent);
}

.morse-flash.flash-dot {
  animation: flash-pulse 0.15s ease-out;
}

.morse-flash.flash-dash {
  animation: flash-pulse 0.45s ease-out;
}

@keyframes flash-pulse {
  0% { transform: scale(1); background: var(--accent); box-shadow: 0 0 40px var(--accent-glow); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); background: var(--surface); box-shadow: none; }
}

.play-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 12px 40px;
  border-radius: 50px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 1px;
}

.play-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 20px var(--accent-glow); }
.play-btn:active { transform: scale(0.97); }

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  max-width: 360px;
}

.choice-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 16px;
  border-radius: var(--radius);
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.choice-btn:hover { border-color: var(--accent); background: rgba(124, 92, 252, 0.08); }
.choice-btn:active { transform: scale(0.97); }
.choice-btn.correct { border-color: var(--success); background: rgba(52, 211, 153, 0.12); color: var(--success); }
.choice-btn.wrong { border-color: var(--error); background: rgba(248, 113, 113, 0.12); color: var(--error); }
.choice-btn:disabled { opacity: 0.5; cursor: default; }

/* Encode Mode */
.target-letter {
  font-size: 96px;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
  text-shadow: 0 0 60px var(--accent-glow);
  letter-spacing: -2px;
}

.morse-input-area {
  min-height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.morse-preview {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 12px;
  color: var(--text);
  min-height: 40px;
  font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace;
}

.morse-status {
  font-size: 14px;
  color: var(--text-dim);
  min-height: 20px;
}

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

.key-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 28px;
  cursor: pointer;
  transition: all 0.12s;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.key-btn:active { transform: scale(0.92); }
.key-btn.dot { color: #60a5fa; border-color: #60a5fa; }
.key-btn.dot:active { background: rgba(96, 165, 250, 0.2); }
.key-btn.dash { color: #f59e0b; border-color: #f59e0b; }
.key-btn.dash:active { background: rgba(245, 158, 11, 0.2); }

.encode-actions {
  display: flex;
  gap: 8px;
}

.action-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.action-btn:hover { transform: translateY(-1px); }
.action-btn:active { transform: scale(0.97); }

.action-btn.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.action-btn.secondary:hover { border-color: var(--text-dim); color: var(--text); }

/* Toast */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 12px 28px;
  border-radius: 50px;
  font-weight: 600;
  font-size: 15px;
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
  z-index: 10;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.success { background: var(--success); color: #002010; }
.toast.error { background: var(--error); color: #200005; }

/* Chart */
.chart-section {
  margin-top: auto;
  padding-top: 24px;
}

.chart-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 20px;
  border-radius: 50px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
}

.chart-btn:hover { border-color: var(--accent); color: var(--accent); }

.chart {
  margin-top: 12px;
  transition: all 0.3s;
}

.chart.hidden { display: none; }

.chart-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.chart-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 6px;
  text-align: center;
  font-size: 12px;
  line-height: 1.4;
}

.chart-cell .char { font-weight: 700; font-size: 16px; color: var(--text); }
.chart-cell .code { font-size: 11px; color: var(--accent); font-family: 'SF Mono', 'Fira Code', monospace; margin-top: 2px; }

/* Responsive */
@media (max-width: 380px) {
  #app { padding: 16px 12px; }
  header { margin-bottom: 20px; }
  header h1 { font-size: 20px; }
  .target-letter { font-size: 72px; }
  .key-btn { width: 68px; height: 68px; font-size: 24px; }
  .choice-btn { font-size: 17px; padding: 14px; }
  .chart-grid { grid-template-columns: repeat(3, 1fr); }
}
