:root {
  --bg: #0b0f17;
  --surface: #121826;
  --surface-2: #192234;
  --border: #25324a;
  --text: #eef2f8;
  --muted: #93a4bf;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --good: #34d399;
  --good-soft: rgba(52, 211, 153, 0.15);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.15);
  --danger: #f87171;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans KR", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(11, 15, 23, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.95rem;
}

h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.subtitle {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--border);
}

.pill-muted { color: var(--muted); background: var(--surface); }
.pill-accent { color: var(--accent); background: var(--accent-soft); border-color: rgba(56, 189, 248, 0.35); }
.pill-good { color: var(--good); background: var(--good-soft); border-color: rgba(52, 211, 153, 0.35); }
.pill-warn { color: var(--warn); background: var(--warn-soft); border-color: rgba(251, 191, 36, 0.35); }

.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s ease, background 0.15s ease;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: scale(0.98); }

.btn-primary { background: #0284c7; border-color: #38bdf8; color: #fff; }
.btn-primary:hover { background: #0369a1; }
.btn-ghost { background: transparent; }
.btn-good { background: var(--good-soft); border-color: rgba(52, 211, 153, 0.45); color: var(--good); }
.btn-warn { background: var(--warn-soft); border-color: rgba(251, 191, 36, 0.45); color: var(--warn); }
.btn-recording { background: rgba(248, 113, 113, 0.18); border-color: var(--danger); color: var(--danger); }

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  cursor: pointer;
}

.select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 0.82rem;
  max-width: 190px;
}
.select-sm { max-width: 90px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-accent {
  border-color: rgba(56, 189, 248, 0.45);
  background: linear-gradient(180deg, rgba(56, 189, 248, 0.08), var(--surface));
}

.kpi-label { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 1.8rem; font-weight: 800; letter-spacing: -0.02em; }
.kpi-sub { font-size: 0.78rem; color: var(--muted); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-header h2 { margin: 0; font-size: 1.05rem; }
.panel-desc { margin: 2px 0 0; font-size: 0.82rem; color: var(--muted); }

.voice-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.tab {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tab.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

.badge {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.74rem;
}

.deck-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.review-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.review-card.is-speaking {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.card-text {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0;
  color: #fff;
}

.card-translation {
  margin: 0;
  font-size: 0.92rem;
  color: var(--muted);
}

.card-note {
  margin: 0;
  font-size: 0.82rem;
  color: #cbd5e1;
  background: rgba(255, 255, 255, 0.04);
  border-left: 3px solid var(--accent);
  padding: 6px 10px;
  border-radius: 4px;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.action-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stt-feedback {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.88rem;
}

.word-hit { color: var(--good); font-weight: 600; }
.word-miss { color: var(--warn); text-decoration: underline wavy rgba(251, 191, 36, 0.6); }

.deck-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.84rem;
  color: var(--muted);
}

.analytics-grid {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 16px;
}

.chart-box {
  width: 100%;
  overflow-x: auto;
}

.bars-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: 76px 1fr 40px;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
}

.bar-track {
  height: 10px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #818cf8);
  border-radius: 999px;
}

.bar-fill.mastered { background: var(--good); }

.weakness-row {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.archive-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.archive-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
}

.archive-summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 600;
}
.archive-summary::-webkit-details-marker { display: none; }

.archive-body {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.archive-line {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.88rem;
}

.empty-state {
  text-align: center;
  padding: 30px 16px;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 12px;
}

.modal {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  background: transparent;
  color: var(--text);
  max-width: 640px;
  width: 92vw;
}
.modal::backdrop { background: rgba(0, 0, 0, 0.65); }

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-head h3 { margin: 0; }

textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.82rem;
  resize: vertical;
}

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-btns { display: flex; gap: 8px; }
.status-text { font-size: 0.8rem; color: var(--muted); }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--surface-2);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 820px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .analytics-grid { grid-template-columns: 1fr; }
}
