:root {
  --font-display: 'Cinzel', serif;
  --font-body: 'Inter', sans-serif;
  --bg: #f7ffff;
  --surface: #e8f4f8;
  --surface-light: #dceef4;
  --border: #c0dde8;
  --border-light: #a0c8d8;
  --text: #123e59;
  --text-dim: #4a7a94;
  --accent: #3ecafd;
  --accent-dark: #4a99d2;
  --accent-glow: rgba(62, 202, 253, 0.2);
  --deep: #123e59;
  --green: #22a855;
  --red: #d94444;
  --yellow: #d4a020;
  --purple: #9070cc;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  display: flex;
  justify-content: center;
  min-height: 100vh;
  position: relative;
  overflow: hidden;
}

/* ═══════════ PIXEL SPRITE CANVAS ═══════════ */
#pixel-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.18;
}

#root {
  width: 100%;
  padding: 0.3rem 0.4rem;
  position: relative;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  z-index: 1;
}

h1 {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--deep);
  letter-spacing: 3px;
  text-align: center;
}

a { color: var(--accent-dark); transition: all 0.2s; }
a:hover { color: var(--accent); }

/* ═══════════ VIDEO ═══════════ */
.video-container {
  margin: 0;
  background: #fff;
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}
.reaction-video { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }

/* ═══════════ TIMING BAR ═══════════ */
.bar-wrap { width: 100%; margin: 0.15rem 0 0; z-index: 1; position: relative; flex-shrink: 0; }
.progress-bar {
  position: relative;
  height: 28px;
  background: var(--surface);
  overflow: visible;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.progress-fill { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(62, 202, 253, 0.1); pointer-events: none; z-index: 1; border-radius: 4px; }
.segment {
  position: absolute; top: 2px; height: 24px; pointer-events: none; z-index: 2;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid; min-width: 10px; border-radius: 3px;
}
.seg-label { font-size: 0.55rem; font-weight: 700; text-shadow: 0 0 4px #fff, 0 0 4px #fff; white-space: nowrap; pointer-events: none; letter-spacing: 1.5px; }
.playhead { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--deep); pointer-events: none; z-index: 5; opacity: 0.8; }

/* ═══════════ REACTION DISPLAY ═══════════ */
.reaction-display {
  margin-top: 0.15rem; padding: 0.3rem 1.2rem; font-size: 1rem; font-weight: 700;
  border-radius: 6px; display: inline-block; min-width: 200px;
  font-family: var(--font-body); z-index: 1; position: relative;
  letter-spacing: 1px; text-align: center; flex-shrink: 0;
}
.reaction-display.neutral { background: var(--surface); border: 1px solid var(--border); color: var(--text-dim); }
.reaction-display.correct { background: #e8f8ee; border: 1px solid var(--green); color: var(--green); }
.reaction-display.wrong { background: #f8e8e8; border: 1px solid var(--red); color: var(--red); }
@keyframes pop { 0% { transform: scale(1); } 30% { transform: scale(1.15); } 100% { transform: scale(1); } }
.reaction-display.pulse { animation: pop 0.22s ease; }

.score { font-size: 1rem; color: var(--text-dim); font-weight: 700; letter-spacing: 1px; }

button {
  border-radius: 20px; border: 1px solid var(--border); padding: 0.4em 1.2em;
  font-size: 0.85rem; font-weight: 600; font-family: var(--font-body);
  background: var(--surface); color: var(--text); cursor: pointer; transition: all 0.2s;
}
button:hover { border-color: var(--accent-dark); color: var(--accent-dark); background: var(--surface-light); }

/* Unified button styles */
.btn-primary {
  padding: 12px 48px; font-size: 1rem; font-weight: 700; border-radius: 20px;
  border: 2px solid var(--deep); background: var(--deep); color: var(--bg);
  letter-spacing: 3px; text-transform: uppercase; font-family: var(--font-display);
}
.btn-primary:hover {
  border-color: var(--accent); background: transparent; color: var(--deep);
  transform: translateY(-1px); box-shadow: 0 3px 16px rgba(62, 202, 253, 0.15);
}
.btn-secondary {
  padding: 8px 28px; font-size: 0.85rem; font-weight: 600; border-radius: 20px;
  border: 1px solid var(--border); background: transparent; color: var(--text-dim);
}
.btn-secondary:hover { border-color: var(--accent-dark); color: var(--accent-dark); }
.btn-back {
  width: 30px; height: 30px; padding: 0; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.9rem; line-height: 1;
}

/* ═══════════ SETUP SCREEN ═══════════ */
.start-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
  z-index: 1;
  gap: 4px;
  padding: 1rem 0;
  overflow-y: auto;
  min-height: 0;
}

.start-btn {
  padding: 14px 60px; font-size: 1.2rem; font-weight: 700; border-radius: 20px;
  border: 2px solid var(--deep); background: var(--deep); color: var(--bg); cursor: pointer;
  letter-spacing: 4px; text-transform: uppercase; font-family: var(--font-display);
  transition: all 0.25s; margin: 10px 0 14px;
}
.start-btn:hover {
  border-color: var(--accent);
  background: transparent;
  color: var(--deep);
  transform: translateY(-2px);
  box-shadow: 0 4px 24px rgba(62, 202, 253, 0.2);
  letter-spacing: 6px;
}

/* ═══════════ SETTINGS ROW ═══════════ */
.settings-row {
  display: flex; align-items: center; justify-content: center; gap: 20px;
  margin-bottom: 10px; flex-wrap: wrap;
}
.settings-row label { color: var(--text-dim); display: flex; align-items: center; gap: 6px; font-size: 0.85rem; }
.offset-hint { color: var(--border-light); font-size: 0.65rem; margin-top: -2px; margin-bottom: 4px; font-style: italic; }
.settings-row input[type="range"] { width: 130px; accent-color: var(--accent-dark); }
.settings-row .val { color: var(--text-dim); font-size: 0.8rem; min-width: 40px; }
.settings-row select {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 8px; font-size: 0.85rem;
}

/* ═══════════ KEY BINDINGS ═══════════ */
.binds-row {
  display: flex; align-items: center; justify-content: center; gap: 18px;
  margin-bottom: 10px;
}
.bind-group { display: flex; align-items: center; gap: 7px; }
.bind-dot { width: 10px; height: 10px; border-radius: 50%; }
.bind-name { font-size: 0.75rem; font-weight: 700; letter-spacing: 1px; color: var(--text-dim); text-transform: uppercase; }
.bind-btn {
  min-width: 50px; padding: 4px 12px; font-size: 0.75rem; border-radius: 20px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-dim);
  cursor: pointer; font-family: var(--font-body); transition: all 0.12s;
}
.bind-btn:hover { border-color: var(--accent-dark); color: var(--accent-dark); }
.bind-btn.listening { border-color: var(--accent); background: rgba(62, 202, 253, 0.1); color: var(--accent-dark); animation: blink 0.6s infinite alternate; }
@keyframes blink { to { opacity: 0.3; } }

/* ═══════════ CATEGORY TABS ═══════════ */
.cat-row { display: flex; gap: 8px; justify-content: center; margin-bottom: 8px; }
.cat-btn {
  padding: 6px 22px; font-size: 0.85rem; font-weight: 700; border-radius: 20px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-dim); cursor: pointer;
  letter-spacing: 1.5px; transition: all 0.15s;
}
.cat-btn:hover { border-color: var(--accent-dark); color: var(--text); }
.cat-btn.active { border-color: var(--accent-dark); color: var(--accent-dark); background: rgba(74, 153, 210, 0.1); }

/* ═══════════ PRESETS GRID ═══════════ */
.presets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 4px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  text-align: left;
}
.preset-item {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px;
  background: var(--surface); border-radius: 6px; cursor: pointer;
  font-size: 0.85rem; color: var(--text); border: 1px solid transparent; transition: all 0.12s;
}
.preset-item:hover { border-color: var(--border-light); background: var(--surface-light); }
.preset-item input[type="checkbox"] { cursor: pointer; accent-color: var(--accent-dark); }
.preset-name { flex: 1; }
.preset-phase { color: var(--text-dim); font-size: 0.7rem; font-weight: 500; margin-left: auto; letter-spacing: 1px; }

/* ═══════════ TWITCH FOOTER ═══════════ */
.footer { text-align: center; margin-top: 14px; }
.twitch-link {
  display: inline-block;
  text-decoration: none;
  color: var(--text-dim);
  font-size: 0.8rem;
  font-family: var(--font-body);
  letter-spacing: 0.5px;
  padding: 8px 20px;
  border: 1px solid var(--border);
  border-radius: 20px;
  transition: all 0.3s;
}
.twitch-link b {
  color: var(--deep);
  font-weight: 700;
  transition: color 0.3s;
}
.twitch-link:hover {
  color: #9146ff;
  border-color: #9146ff;
  background: rgba(145, 70, 255, 0.05);
  transform: translateY(-1px);
  box-shadow: 0 3px 12px rgba(145, 70, 255, 0.12);
}
.twitch-link:hover b { color: #9146ff; }

/* ═══════════ GAME SCREEN ═══════════ */
.game-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 2px; flex-shrink: 0;
}
.game-header-label { color: var(--text-dim); font-size: 0.72rem; letter-spacing: 1px; }
.game-header-label span { color: var(--accent-dark); }
.game-header-score { font-size: 0.9rem; color: var(--text-dim); font-weight: 600; }

.game-enter {
  animation: flashIn 0.18s ease-out;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
@keyframes flashIn { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }

/* ═══════════ SCORE OVERLAY ═══════════ */
.set-overlay {
  position: fixed; inset: 0; background: var(--bg); z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  animation: fadeIn 0.4s ease;
  gap: 4px;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.set-label { font-family: var(--font-display); font-size: 1rem; color: var(--text-dim); letter-spacing: 6px; text-transform: uppercase; }
.set-accuracy { font-family: var(--font-display); font-size: 5rem; font-weight: 900; margin: 10px 0; }
.set-accuracy.great { color: var(--green); }
.set-accuracy.ok { color: var(--yellow); }
.set-accuracy.bad { color: var(--red); }
.set-detail { font-size: 1rem; color: var(--text-dim); margin: 6px 0; letter-spacing: 1px; }
.set-stat { font-size: 0.9rem; color: var(--accent-dark); margin: 2px 0; }
.set-attacks { color: var(--red); font-weight: 600; }
.set-buttons { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 16px; }

/* ═══════════ TOUCH CONTROLS ═══════════ */
.touch-controls {
  display: none;
  gap: 6px;
  justify-content: center;
  padding: 4px 0;
  flex-shrink: 0;
}
.touch-btn {
  flex: 1;
  max-width: 120px;
  padding: 14px 8px;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 2px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.touch-btn:active { transform: scale(0.95); }
.touch-duck { border-color: #d4a020; color: #d4a020; }
.touch-parry { border-color: #4a99d2; color: #4a99d2; }
.touch-jump { border-color: #9070cc; color: #9070cc; }
.touch-attack { border-color: #d94444; color: #d94444; }

@media (pointer: coarse) {
  .touch-controls { display: flex; }
}

/* ═══════════ RESPONSIVE ═══════════ */
@media (max-width: 600px) {
  #root { padding: 0.3rem; }
  h1 { font-size: 1.4rem; }
  .start-btn { padding: 12px 36px; font-size: 1rem; }
  .presets-grid { grid-template-columns: 1fr; }
  .set-accuracy { font-size: 3.5rem; }
  .binds-row { gap: 10px; }
  .settings-row { gap: 12px; }
}
