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

:root {
  --bg: #0f0f14;
  --surface: #16161e;
  --surface2: #1e1e2e;
  --border: #2a2a3d;
  --accent: #c792ea;
  --accent2: #82aaff;
  --correct: #c3e88d;
  --incorrect: #f07178;
  --text-main: #cdd6f4;
  --text-dim: #6272a4;
  --text-muted: #45475a;
  --cursor: #c792ea;
  --radius: 12px;
}

body {
  background: var(--bg);
  color: var(--text-main);
  font-family: 'Inter', 'Roboto Mono', monospace;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

/* Background glow */
body::before {
  content: '';
  position: fixed;
  top: -20%;
  left: 50%;
  transform: translateX(-50%);
  width: 800px;
  height: 400px;
  background: radial-gradient(ellipse, rgba(199,146,234,0.08) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* ========== HEADER ========== */
header {
  width: 100%;
  max-width: 1100px;
  padding: 28px 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 10;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.logo-icon {
  font-size: 1.6rem;
  filter: drop-shadow(0 0 8px rgba(199,146,234,0.5));
}

.logo-text {
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

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

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  padding: 8px 12px;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.2s;
}

.icon-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(199,146,234,0.08);
}

/* ========== MAIN ========== */
main {
  width: 100%;
  max-width: 1100px;
  padding: 0 24px;
  flex: 1;
  position: relative;
  z-index: 10;
}

/* ========== TOOLBAR ========== */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 40px 0 36px;
  flex-wrap: wrap;
}

.toolbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.mode-btn {
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text-muted);
  padding: 7px 14px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: inherit;
}

.mode-btn:hover {
  color: var(--text-main);
  background: var(--surface);
}

.mode-btn.active {
  color: var(--accent);
  background: rgba(199,146,234,0.1);
}

.mode-btn .icon { font-size: 0.8rem; }

.toolbar-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  padding: 6px 12px;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: all 0.2s;
}

.toolbar-select:hover,
.toolbar-select:focus {
  color: var(--text-main);
  border-color: var(--accent);
  background: var(--surface);
}
.live-stats {
  display: flex;
  gap: 28px;
  margin-bottom: 28px;
  min-height: 52px;
  align-items: flex-end;
}

.live-stat {
  display: flex;
  flex-direction: column;
}

.live-stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  transition: color 0.2s;
}

.live-stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 3px;
}

/* ========== TEST AREA ========== */
.test-container {
  position: relative;
  margin-bottom: 24px;
}

#words-display {
  font-size: 1.35rem;
  line-height: 2.2;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  height: 138px;
  overflow: hidden;
  position: relative;
  cursor: text;
  user-select: none;
  transition: filter 0.3s;
}

#words-display.blurred {
  filter: blur(4px);
}

#words-display .word {
  display: inline-block;
  margin-right: 0.6em;
  position: relative;
}

#words-display .word .char {
  position: relative;
  display: inline-block;
  transition: color 0.05s;
}

#words-display .word .char.correct { color: var(--correct); }
#words-display .word .char.incorrect { color: var(--incorrect); text-decoration: underline wavy rgba(240,113,120,0.5); }
#words-display .word .char.cursor::before {
  content: '';
  position: absolute;
  left: -1px;
  top: 10%;
  width: 2px;
  height: 80%;
  background: var(--cursor);
  border-radius: 1px;
  animation: blink 1s ease infinite;
  box-shadow: 0 0 6px var(--cursor);
}

#words-display .word .char.cursor-after::after {
  content: '';
  position: absolute;
  right: -3px;
  top: 10%;
  width: 2px;
  height: 80%;
  background: var(--cursor);
  border-radius: 1px;
  animation: blink 1s ease infinite;
  box-shadow: 0 0 6px var(--cursor);
}

#words-display .word.incorrect-word > span:not(.correct):not(.incorrect) {
  text-decoration: underline;
  text-decoration-color: rgba(240,113,120,0.4);
}

#words-display.quote-mode .word { margin-right: 0.5em; }

/* extra chars (typed beyond word length) */
.extra-char {
  color: var(--incorrect) !important;
  opacity: 0.7;
}

/* Caret when no word is focused */
.caret-standalone {
  display: inline-block;
  width: 2px;
  height: 1.2em;
  background: var(--cursor);
  border-radius: 1px;
  vertical-align: middle;
  animation: blink 1s ease infinite;
  box-shadow: 0 0 8px var(--cursor);
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Click-to-focus overlay */
.focus-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15,15,20,0.7);
  border-radius: var(--radius);
  backdrop-filter: blur(2px);
  cursor: text;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  gap: 10px;
  color: var(--text-dim);
  font-size: 0.95rem;
}

.focus-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.focus-overlay .key-icon {
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--text-main);
}

/* Hidden input */
#typing-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
}

/* ========== BOTTOM ACTIONS ========== */
.bottom-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 8px;
}

.action-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
  font-family: inherit;
}

.action-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(199,146,234,0.06);
}

.action-btn.primary {
  background: rgba(199,146,234,0.12);
  border-color: rgba(199,146,234,0.3);
  color: var(--accent);
}

.action-btn.primary:hover {
  background: rgba(199,146,234,0.2);
}

.action-btn.secondary {
  background: rgba(255,85,85,0.08);
  border-color: rgba(255,85,85,0.25);
  color: #ff5555;
}
.action-btn.secondary:hover {
  background: rgba(255,85,85,0.16);
  border-color: #ff5555;
}

/* ========== QUOTE NAVIGATION ========== */
.quote-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 14px;
  animation: fadeIn 0.3s ease;
}

.nav-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}
.nav-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(199,146,234,0.06);
}
.nav-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.progress-text {
  font-size: 0.78rem;
  color: var(--text-dim);
  font-weight: 500;
  font-family: 'Roboto Mono', monospace;
  letter-spacing: 0.04em;
}

/* ========== CHART LEGEND ========== */
.chart-legend {
  display: flex;
  gap: 18px;
  margin-top: 8px;
  justify-content: center;
}
.chart-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-dim);
}
.chart-legend-dot {
  width: 20px;
  height: 2px;
  border-radius: 2px;
}
.chart-legend-dot.wpm   { background: #c792ea; }
.chart-legend-dot.raw   { background: rgba(98,114,164,0.55); border-top: 2px dashed rgba(98,114,164,0.55); height: 0; }
.chart-legend-dot.error { background: #ff5555; border-radius: 50%; width: 8px; height: 8px; }

/* ========== TIMER ========== */
.timer-bar-wrap {
  height: 3px;
  background: var(--surface2);
  border-radius: 2px;
  margin-bottom: 24px;
  overflow: hidden;
}

.timer-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 2px;
  transition: width 0.5s linear;
  box-shadow: 0 0 8px rgba(199,146,234,0.4);
}

/* ========== RESULTS ========== */
#results-screen {
  display: none;
  animation: fadeInUp 0.5s ease;
}

#results-screen.visible { display: block; }

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

.results-hero {
  display: flex;
  gap: 48px;
  align-items: flex-end;
  margin-bottom: 48px;
  flex-wrap: wrap;
}

.result-big {
  display: flex;
  flex-direction: column;
}

.result-big-value {
  font-size: 5rem;
  font-weight: 800;
  line-height: 1;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-variant-numeric: tabular-nums;
}

.result-big-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-top: 4px;
}

.results-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 16px;
  margin-bottom: 48px;
}

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.2s;
}

.result-card:hover { border-color: var(--accent); }

.result-card-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.result-card-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

.result-card-unit {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* Chart */
.chart-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 32px;
}

.chart-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 16px;
}

#wpm-chart {
  width: 100%;
  height: 140px;
}

/* Quote author in results */
.quote-attr {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
  color: var(--text-dim);
  font-size: 0.9rem;
  font-style: italic;
}

.quote-attr::before { content: '— '; }

/* ========== NOTIFICATION TOAST ========== */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 20px;
  color: var(--text-main);
  font-size: 0.875rem;
  transition: transform 0.3s ease;
  z-index: 1000;
  white-space: nowrap;
}

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

/* ========== THEME SWITCH ========== */
body.light {
  --bg: #f8f8f8;
  --surface: #ffffff;
  --surface2: #f0f0f5;
  --border: #ddd;
  --text-main: #2b2b3b;
  --text-dim: #7a7a9a;
  --text-muted: #aaaacc;
}

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ========== RESPONSIVE ========== */
@media (max-width: 640px) {
  #words-display { font-size: 1.1rem; line-height: 2; height: 120px; }
  .result-big-value { font-size: 3.5rem; }
  .live-stat-value { font-size: 1.5rem; }
  .toolbar { gap: 4px; }
  .mode-btn { padding: 6px 10px; font-size: 0.8rem; }
}

/* ========== CONTENT MANAGER MODAL ========== */
.cm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.cm-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.cm-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  width: min(640px, 94vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 32px 80px rgba(0,0,0,0.5), 0 0 0 1px rgba(199,146,234,0.1);
  transform: translateY(20px) scale(0.97);
  transition: transform 0.25s ease;
}

.cm-overlay.open .cm-modal {
  transform: translateY(0) scale(1);
}

/* Header */
.cm-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 24px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.cm-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.3px;
}

.cm-title-icon { font-size: 1.2rem; }

.cm-close {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  font-family: inherit;
}

.cm-close:hover {
  color: var(--incorrect);
  border-color: var(--incorrect);
  background: rgba(240,113,120,0.08);
}

/* Tabs */
.cm-tabs {
  display: flex;
  gap: 4px;
  padding: 14px 20px 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.cm-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  padding: 8px 16px 10px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.18s;
  border-radius: 6px 6px 0 0;
  margin-bottom: -1px;
}

.cm-tab:hover { color: var(--text-main); }

.cm-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: rgba(199,146,234,0.07);
}

/* Panels */
.cm-panel {
  display: none;
  flex-direction: column;
  gap: 14px;
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

.cm-panel.active { display: flex; }

.cm-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0;
}

.cm-hint strong { color: var(--text-dim); }

/* Input row */
.cm-input-row {
  display: flex;
  gap: 8px;
}

.cm-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-main);
  padding: 10px 14px;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.cm-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(199,146,234,0.12);
}

.cm-textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-main);
  padding: 10px 14px;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  resize: vertical;
  min-height: 80px;
  transition: border-color 0.2s, box-shadow 0.2s;
  line-height: 1.6;
}

.cm-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(199,146,234,0.12);
}

.cm-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cm-add-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  border-radius: 10px;
  color: #0f0f14;
  padding: 10px 20px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.2s, transform 0.15s;
  white-space: nowrap;
}

.cm-add-btn:hover { opacity: 0.88; transform: translateY(-1px); }
.cm-add-btn:active { transform: translateY(0); }
.cm-add-btn.wide { align-self: flex-end; }

/* List */
.cm-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
  padding-right: 2px;
}

.cm-empty {
  color: var(--text-muted);
  font-size: 0.82rem;
  text-align: center;
  padding: 16px 0;
}

.cm-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  gap: 10px;
  transition: border-color 0.2s;
  animation: cmItemIn 0.18s ease;
}

@keyframes cmItemIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.cm-item:hover { border-color: rgba(199,146,234,0.3); }

.cm-item.column {
  flex-direction: column;
  align-items: stretch;
}

.cm-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cm-item-text {
  font-size: 0.85rem;
  color: var(--text-main);
  line-height: 1.5;
  word-break: break-word;
}

.cm-item-author {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.cm-del-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-muted);
  width: 26px;
  height: 26px;
  cursor: pointer;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.18s;
  font-family: inherit;
}

.cm-del-btn:hover {
  color: var(--incorrect);
  border-color: rgba(240,113,120,0.4);
  background: rgba(240,113,120,0.08);
}

/* Clear button */
.cm-clear-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  padding: 7px 12px;
  font-size: 0.78rem;
  cursor: pointer;
  font-family: inherit;
  align-self: flex-start;
  transition: all 0.2s;
  margin-top: 2px;
}

.cm-clear-btn:hover {
  color: var(--incorrect);
  border-color: rgba(240,113,120,0.5);
  background: rgba(240,113,120,0.06);
}

/* Light theme overrides for modal */
body.light .cm-modal {
  box-shadow: 0 32px 80px rgba(0,0,0,0.2);
}

body.light .cm-overlay {
  background: rgba(0,0,0,0.35);
}

/* ---- Item action buttons (edit / save / cancel / delete) ---- */
.cm-item-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  align-items: center;
}

/* shared base for all icon action buttons */
.cm-edit-btn,
.cm-save-btn,
.cm-cancel-btn,
.cm-del-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.18s;
  font-family: inherit;
  color: var(--text-muted);
}

.cm-edit-btn:hover {
  color: var(--accent2);
  border-color: rgba(130,170,255,0.4);
  background: rgba(130,170,255,0.08);
}

.cm-save-btn {
  color: var(--correct);
  font-size: 1rem;
}
.cm-save-btn:hover {
  border-color: rgba(195,232,141,0.5);
  background: rgba(195,232,141,0.1);
}

.cm-cancel-btn:hover {
  color: var(--text-dim);
  border-color: var(--border);
  background: var(--surface);
}

.cm-del-btn:hover {
  color: var(--incorrect);
  border-color: rgba(240,113,120,0.4);
  background: rgba(240,113,120,0.08);
}

/* Row highlight while editing */
.cm-item.editing {
  border-color: rgba(199,146,234,0.45);
  background: rgba(199,146,234,0.04);
}

/* Edit inputs inside rows */
.cm-item .cm-edit-input {
  margin-top: 4px;
  flex: 1;
}

/* Prevent textarea resize from overflowing the modal */
.cm-item .cm-textarea {
  resize: vertical;
  max-height: 200px;
}

