/* ═══════════════════════════════════════════════════════
   QUANTA — Reusable Components
   ═══════════════════════════════════════════════════════ */

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-5);
  height: 40px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font-family: var(--ff-body);
  font-size: var(--text-sm);
  font-weight: 500;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition:
    background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease);
  white-space: nowrap;
  user-select: none;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.97); }

/* Primary */
.btn-primary {
  background: var(--accent);
  color: var(--text-inv);
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-2);
  border-color: var(--accent-2);
  box-shadow: 0 0 0 4px var(--accent-dim);
}

/* Secondary */
.btn-secondary {
  background: var(--surface);
  color: var(--text-1);
  border-color: var(--border-hi);
}
.btn-secondary:hover {
  background: var(--surface-2);
  border-color: var(--text-3);
}

/* Ghost */
.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text-1);
}

/* Danger */
.btn-danger {
  background: var(--err-dim);
  color: var(--err);
  border-color: var(--err-border);
}
.btn-danger:hover {
  background: var(--err);
  color: white;
}

/* Sizes */
.btn-sm  { height: 32px; padding: 0 var(--sp-3); font-size: var(--text-xs); border-radius: var(--r-xs); }
.btn-lg  { height: 52px; padding: 0 var(--sp-8); font-size: var(--text-md); border-radius: var(--r-md); }
.btn-xl  { height: 60px; padding: 0 var(--sp-10); font-size: var(--text-lg); border-radius: var(--r-lg); font-weight: 600; }
.btn-full { width: 100%; }

/* ── Icon Button ── */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
  font-size: 1rem;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text-1); border-color: var(--border-hi); }
.btn-icon:active { transform: scale(0.93); }

/* ── Theme Toggle ── */
.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--dur-fast) var(--ease);
}
.theme-toggle:hover { background: var(--surface-2); color: var(--text-1); }

/* ── Badge / Pill ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 2px var(--sp-2);
  border-radius: var(--r-full);
  font-family: var(--ff-mono);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.badge-outline {
  background: transparent;
  border: 1px solid var(--border-hi);
  color: var(--text-2);
}

.badge-accent {
  background: var(--accent-dim);
  border: 1px solid rgba(79, 103, 255, 0.2);
  color: var(--accent);
}

.badge-ok {
  background: var(--ok-dim);
  border: 1px solid var(--ok-border);
  color: var(--ok);
}

.badge-err {
  background: var(--err-dim);
  border: 1px solid var(--err-border);
  color: var(--err);
}

.badge-warn {
  background: var(--warn-dim);
  border: 1px solid rgba(217, 119, 6, 0.25);
  color: var(--warn);
}

/* Difficulty badges */
.badge-easy   { background: var(--ok-dim);   border: 1px solid var(--ok-border);  color: var(--d-easy); }
.badge-medium { background: rgba(37,99,235,0.10); border: 1px solid rgba(37,99,235,0.25); color: var(--d-medium); }
.badge-hard   { background: var(--err-dim);  border: 1px solid var(--err-border); color: var(--d-hard); }

/* Tag chip */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--sp-3);
  border-radius: var(--r-full);
  font-size: var(--text-xs);
  font-weight: 500;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-2);
  white-space: nowrap;
}

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  box-shadow: var(--shadow-xs);
  transition:
    border-color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease),
    transform var(--dur) var(--ease);
}

.card:hover {
  border-color: var(--border-hi);
  box-shadow: var(--shadow-md);
}

.card-interactive {
  cursor: pointer;
}
.card-interactive:hover { transform: translateY(-2px); }
.card-interactive:active { transform: translateY(0); }

/* ── Toggle Switch ── */
.toggle-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-3) 0;
}

.toggle-label {
  font-size: var(--text-sm);
  color: var(--text-2);
  font-weight: 500;
}

.toggle {
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: var(--r-full);
  background: var(--border-hi);
  cursor: pointer;
  transition: background var(--dur) var(--ease);
  border: none;
  flex-shrink: 0;
}

.toggle.active { background: var(--accent); }

.toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform var(--dur) var(--ease-spring);
}

.toggle.active::after { transform: translateX(18px); }

/* ── Modal / Overlay ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6);
}

/* Shown by removing .is-hidden */
.overlay:not(.is-hidden) {
  display: flex;
  animation: fadeIn var(--dur) var(--ease-out) both;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border-hi);
  border-radius: var(--r-xl);
  padding: var(--sp-8);
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-xl);
  animation: scaleIn var(--dur-slow) var(--ease-spring) both;
}

.modal-title {
  font-family: var(--ff-display);
  font-size: var(--text-2xl);
  font-weight: 700;
  margin-bottom: var(--sp-2);
}

.modal-body {
  color: var(--text-2);
  font-size: var(--text-sm);
  line-height: 1.65;
  margin-bottom: var(--sp-6);
}

.modal-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-3);
  margin-bottom: var(--sp-6);
}

.modal-stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-4);
}

.modal-stat-val {
  font-family: var(--ff-mono);
  font-size: var(--text-xl);
  font-weight: 500;
  color: var(--text-1);
  display: block;
}

.modal-stat-label {
  font-size: var(--text-xs);
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  display: block;
  margin-top: var(--sp-1);
}

.modal-actions {
  display: flex;
  gap: var(--sp-3);
}
.modal-actions .btn { flex: 1; }

/* ── Progress Bar ── */
.progress-bar {
  height: 3px;
  background: var(--surface-3);
  border-radius: var(--r-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--r-full);
  transition: width 0.4s var(--ease);
}

/* ── Score Ring (SVG) ── */
.score-ring-wrap {
  position: relative;
  width: 160px;
  height: 160px;
  margin: 0 auto var(--sp-6);
}

.score-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.score-ring-track {
  fill: none;
  stroke: var(--surface-3);
  stroke-width: 10;
}

.score-ring-fill {
  fill: none;
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke-dashoffset 1.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.score-ring-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.score-ring-pct {
  font-family: var(--ff-display);
  font-size: var(--text-3xl);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
}

.score-ring-label {
  font-family: var(--ff-mono);
  font-size: var(--text-xs);
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: 2px;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: var(--sp-6);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-3);
  border: 1px solid var(--border-hi);
  border-radius: var(--r-full);
  padding: var(--sp-2) var(--sp-5);
  font-size: var(--text-sm);
  color: var(--text-1);
  box-shadow: var(--shadow-lg);
  z-index: 500;
  pointer-events: none;
  animation: toastIn var(--dur-slow) var(--ease-spring) both,
             toastOut var(--dur) var(--ease) 2s both;
  white-space: nowrap;
}

@keyframes toastIn  { from { opacity:0; transform: translateX(-50%) translateY(12px); } }
@keyframes toastOut { to   { opacity:0; transform: translateX(-50%) translateY(6px); } }

/* ── Section dot/color mapping ── */
.sec-color-1 { color: var(--c1); }
.sec-color-2 { color: var(--c2); }
.sec-color-3 { color: var(--c3); }
.sec-color-4 { color: var(--c4); }
.sec-color-5 { color: var(--c5); }
.sec-color-6 { color: var(--c6); }

.sec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Divider ── */
.divider {
  height: 1px;
  background: var(--border);
  margin: var(--sp-6) 0;
}

/* ── Keyboard hint ── */
.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 4px;
  background: var(--surface-2);
  border: 1px solid var(--border-hi);
  border-bottom-width: 2px;
  border-radius: 4px;
  font-family: var(--ff-mono);
  font-size: 11px;
  color: var(--text-2);
}

.kbd-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-4);
}

.kbd-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-xs);
  color: var(--text-3);
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: var(--sp-16) var(--sp-6);
  color: var(--text-3);
}

.empty-state-icon { font-size: 2.5rem; margin-bottom: var(--sp-4); }
.empty-state-title { font-size: var(--text-md); color: var(--text-2); margin-bottom: var(--sp-2); }
.empty-state-desc  { font-size: var(--text-sm); }