:root {
  /* Light Theme (Default) */
  --bg: #f8fafc;
  --bg-soft: #f1f5f9;
  --panel: rgba(255, 255, 255, 0.9);
  --line: rgba(0, 0, 0, 0.05);
  --line-strong: rgba(0, 0, 0, 0.1);
  --text: #0f172a;
  --text-dim: #334155;
  --muted: #64748b;
  --accent: #0284c7;
  --accent-glow: rgba(14, 165, 233, 0.15);
  --success: #059669;
  --error: #dc2626;
  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.08);
  --font-main: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", monospace;
}

[data-theme="dark"] {
  --bg: #05070a;
  --bg-soft: #0f121a;
  --panel: rgba(17, 22, 31, 0.9);
  --line: rgba(255, 255, 255, 0.05);
  --line-strong: rgba(255, 255, 255, 0.12);
  --text: #f8fafc;
  --text-dim: #cbd5e1;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-glow: rgba(56, 189, 248, 0.2);
  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  font-family: var(--font-main);
  color: var(--text);
  background: var(--bg);
  background-image: 
    radial-gradient(circle at 0% 0%, var(--accent-glow) 0%, transparent 40%),
    radial-gradient(circle at 100% 0%, rgba(139, 92, 246, 0.08) 0%, transparent 40%);
  min-height: 100vh;
  line-height: 1.5;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.app {
  width: min(1000px, calc(100% - 40px));
  margin: 0 auto;
  padding: 80px 0;
}

.header {
  display: grid;
  grid-template-columns: 1fr 320px;
  align-items: flex-start;
  margin-bottom: 56px;
  gap: 40px;
}

.header-main {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 20px;
}

.header-copy h1 {
  font-size: 3.25rem;
  font-weight: 800;
  margin: 8px 0 16px;
  letter-spacing: -0.04em;
  color: var(--text);
  line-height: 1.1;
}

.theme-toggle {
  background: var(--bg-soft);
  border: 1px solid var(--line-strong);
  color: var(--text);
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 0;
}

.theme-toggle:hover {
  background: var(--line-strong);
  transform: translateY(-2px);
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
}

[data-theme="dark"] .sun-icon { display: block; }
[data-theme="dark"] .moon-icon { display: none; }
.sun-icon { display: none; }
.moon-icon { display: block; }

.label, .small-label {
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  display: block;
}

.desc {
  color: var(--text-dim);
  font-size: 1.125rem;
  max-width: 52ch;
  line-height: 1.7;
}

/* Editor Card Inside Header */
.header .editor-card {
  margin-bottom: 0;
  background: var(--bg-soft);
  border: 1px solid var(--line-strong);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.editor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.apply-btn {
  background: var(--accent);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.apply-btn:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.editor-head h2 {
  font-size: 1rem;
  font-weight: 600;
  margin: 4px 0 0;
  color: var(--text-dim);
}

.editor-input {
  width: 100%;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  color: var(--text);
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  resize: vertical;
  min-height: 80px;
  margin-top: 16px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.editor-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: rgba(0, 0, 0, 0.4);
}

/* Main Card */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 48px;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(12px);
}

.row {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 48px;
  margin-bottom: 40px;
}

select {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  color: var(--text);
  padding: 12px 16px;
  font-family: inherit;
  font-size: 0.95rem;
  margin: 12px 0 24px;
  cursor: pointer;
}

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.stat-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  transition: all 0.2s ease;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 4px;
  display: block;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  font-family: var(--font-mono);
}

/* Sample Text Area */
.sample-container {
  margin-top: 16px;
  position: relative;
}

.sample {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  padding: 32px;
  font-size: 1.4rem;
  line-height: 1.8;
  min-height: 140px;
  margin: 0;
  font-family: var(--font-mono);
  color: var(--text-dim);
  transition: all 0.3s ease;
}

.sample.completed {
  border-color: var(--success);
  box-shadow: 0 0 24px rgba(16, 185, 129, 0.1);
  background: rgba(16, 185, 129, 0.02);
}

.progress-track {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 16px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.char {
  display: inline;
  padding: 0 0.5px;
  border-radius: 2px;
}

.char.matched {
  color: var(--text);
  opacity: 0.9;
}

.char.current {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 15px var(--accent-glow);
  border-radius: 4px;
}

.char.error {
  color: #fff;
  background: var(--error);
  border-radius: 4px;
}

.char.pending {
  opacity: 0.5;
}

/* Input */
input#typingInput {
  width: 100%;
  background: var(--bg-soft);
  border: 2px solid var(--line-strong);
  border-radius: 16px;
  padding: 24px;
  font-family: var(--font-mono);
  font-size: 1.4rem;
  color: var(--accent);
  margin: 24px 0;
  transition: all 0.2s ease;
}

input#typingInput:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow);
  background: rgba(0, 0, 0, 0.2);
}

/* Line Map */
.line-map {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  width: 320px;
}

.line-map-list {
  margin-top: 16px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 12px;
}

.line-map-item {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
  margin-bottom: 4px;
  transition: all 0.2s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--font-mono);
}

.line-map-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-dim);
}

.line-map-item.active {
  background: rgba(56, 189, 248, 0.1);
  color: var(--accent);
  font-weight: 600;
}

.line-map-item.done {
  opacity: 0.3;
}

/* Actions */
.actions {
  display: flex;
  gap: 16px;
}

button {
  padding: 16px 32px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: none;
}

button#startBtn {
  background: var(--accent);
  color: var(--bg);
}

button#startBtn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px var(--accent-glow);
  filter: brightness(1.1);
}

button.secondary {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-dim);
}

button.secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.status {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 4px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 10px;
}

@media (max-width: 1100px) {
  .header { flex-direction: column; align-items: flex-start; gap: 24px; }
  .row { grid-template-columns: 1fr; gap: 32px; }
  .line-map { width: 100%; }
  .header-copy h1 { font-size: 2.75rem; }
  .card { padding: 32px; }
}
