:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #14141f;
  --bg-tertiary: #1e1e2e;
  --text-primary: #ffffff;
  --text-secondary: #a0a0b0;
  --text-muted: #606070;
  --accent: #00d4ff;
  --accent-secondary: #00ff88;
  --danger: #ff4466;
  --focus-ring: #00d4ff;
  --focus-glow: rgba(0, 212, 255, 0.4);
  --radius-md: 12px;
  --radius-lg: 16px;
}

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

html, body {
  width: 600px;
  height: 600px;
  overflow: hidden;
  background: #000;
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app { width: 100%; height: 100%; position: relative; }

.screen {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  padding: 30px;
}

.screen.hidden { display: none; }

.focusable {
  transition: all 0.15s ease;
  border: 2px solid transparent;
  cursor: pointer;
  outline: none;
  background: none;
  color: inherit;
  font-family: inherit;
}

.focusable:focus {
  border-color: var(--focus-ring);
  box-shadow: 0 0 20px var(--focus-glow);
}

.hidden { display: none !important; }

/* ===== Home ===== */
#home {
  justify-content: space-between;
  align-items: center;
  padding: 40px 30px;
}

.home-header {
  text-align: center;
  margin-top: 30px;
}

#home h1 {
  font-size: 48px;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 12px;
}

.tagline {
  font-size: 15px;
  color: var(--text-secondary);
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 380px;
}

.menu-btn {
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 22px;
  font-weight: 600;
  padding: 22px;
  border-radius: var(--radius-md);
  min-height: 88px;
  width: 100%;
  letter-spacing: 0.02em;
  text-align: center;
}

.best-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 18px 40px;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
}

.best-label {
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

#best-score {
  font-size: 32px;
  font-weight: 800;
  color: var(--accent-secondary);
}

/* ===== How to Play ===== */
#howto {
  padding: 40px 30px;
  justify-content: space-between;
  gap: 20px;
}

#howto h2 {
  font-size: 36px;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 8px;
}

.howto-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
}

.howto-list li {
  font-size: 19px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--bg-secondary);
  padding: 16px 20px;
  border-radius: var(--radius-md);
}

.howto-list .num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: #000;
  font-weight: 800;
  font-size: 18px;
  flex-shrink: 0;
}

/* ===== Game ===== */
#game {
  padding: 20px;
  gap: 16px;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-secondary);
  padding: 14px 20px;
  border-radius: var(--radius-md);
  min-height: 72px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 72px;
  gap: 2px;
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

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

.phase {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.22em;
  color: var(--accent);
  padding: 10px 20px;
  background: var(--bg-tertiary);
  border-radius: 20px;
  text-align: center;
  min-width: 130px;
}

.phase.watch { color: var(--accent); }
.phase.input { color: var(--accent-secondary); }
.phase.correct { color: var(--accent-secondary); }
.phase.wrong { color: var(--danger); }

.grid-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 14px;
  width: 380px;
  height: 380px;
}

.grid-cell {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  border: 2px solid var(--bg-tertiary);
  transition: background 0.12s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  cursor: pointer;
  outline: none;
}

.grid-cell:focus {
  border-color: var(--focus-ring);
  box-shadow: 0 0 24px var(--focus-glow);
}

.grid-cell.lit {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 28px rgba(0, 212, 255, 0.55);
}

.grid-cell.selected {
  background: var(--bg-tertiary);
  border-color: var(--accent-secondary);
  box-shadow: inset 0 0 0 6px rgba(0, 255, 136, 0.85);
}

.grid-cell.selected:focus {
  border-color: var(--focus-ring);
  box-shadow: inset 0 0 0 6px rgba(0, 255, 136, 0.85), 0 0 24px var(--focus-glow);
}

.grid-cell.correct {
  background: var(--accent-secondary);
  border-color: var(--accent-secondary);
  box-shadow: 0 0 28px rgba(0, 255, 136, 0.55);
}

.grid-cell.wrong {
  background: var(--danger);
  border-color: var(--danger);
  box-shadow: 0 0 28px rgba(255, 68, 102, 0.55);
}

.submit-btn {
  background: var(--bg-secondary);
  color: var(--accent);
  font-size: 18px;
  font-weight: 800;
  padding: 14px;
  border-radius: var(--radius-md);
  min-height: 56px;
  letter-spacing: 0.18em;
  width: 100%;
  border: 2px solid var(--accent);
}

.submit-btn:focus {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  box-shadow: 0 0 30px rgba(0, 212, 255, 0.6);
}

/* ===== Game Over ===== */
#gameover {
  justify-content: center;
  align-items: center;
  gap: 22px;
  padding: 30px;
}

.game-over-title {
  font-size: 40px;
  font-weight: 800;
  color: var(--danger);
  text-align: center;
  letter-spacing: 0.02em;
}

.final-stats {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-secondary);
  padding: 18px 24px;
  border-radius: var(--radius-md);
}

.stat-row span:first-child {
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 13px;
  font-weight: 600;
}

.stat-row span:last-child {
  font-weight: 800;
  font-size: 26px;
  color: var(--accent);
}

.stat-row.best span:last-child {
  color: var(--accent-secondary);
}
