/* Buttons, options, cards, modals, toasts, progress, timer. */

/* --- Buttons ------------------------------------------------------------ */

.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  --btn-bd: var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  min-height: 40px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--btn-fg);
  background: var(--btn-bg);
  border: 1px solid var(--btn-bd);
  border-radius: var(--radius);
  transition: background var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              transform var(--dur-fast) var(--ease),
              opacity var(--dur-fast) var(--ease);
}

.btn:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--border-strong); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.42; cursor: not-allowed; }

.btn--primary {
  --btn-bg: var(--accent);
  --btn-fg: var(--accent-text);
  --btn-bd: transparent;
}

.btn--primary:hover:not(:disabled) {
  background: color-mix(in oklab, var(--accent) 88%, var(--text));
  border-color: transparent;
}

.btn--ghost { --btn-bg: transparent; --btn-bd: transparent; }
.btn--ghost:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--border); }

.btn--danger { --btn-bg: var(--incorrect-soft); --btn-fg: var(--incorrect); --btn-bd: transparent; }

.btn--icon { padding: var(--sp-2); min-width: 40px; }

.btn--lg { min-height: 48px; padding: var(--sp-3) var(--sp-5); font-size: var(--text-base); }

/* --- Keyboard hints ----------------------------------------------------- */

kbd, .kbd {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding-inline: 5px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
}

/* --- Panels and cards --------------------------------------------------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card {
  position: relative;
  display: block;
  width: 100%;
  text-align: start;
  padding: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--dur-fast) var(--ease),
              transform var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
}

.card:hover { border-color: var(--border-strong); transform: translateY(-2px); box-shadow: var(--shadow); }

.card[aria-selected="true"], .card.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

/* --- Answer options ----------------------------------------------------- */

.options { display: grid; gap: var(--sp-2); }

.option {
  --opt-accent: var(--border-strong);
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: start;
  gap: var(--sp-3);
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  text-align: start;
  font-size: var(--text-base);
  line-height: 1.55;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: background var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              transform var(--dur-fast) var(--ease);
}

.option:hover:not(.is-locked) { background: var(--surface-hover); border-color: var(--opt-accent); }
.option:active:not(.is-locked) { transform: scale(0.995); }
.option.is-locked { cursor: default; }

.option__key {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--dur-fast) var(--ease);
}

.option__mark { align-self: center; opacity: 0; transition: opacity var(--dur-fast) var(--ease); }

.option.is-selected {
  --opt-accent: var(--accent);
  border-color: var(--accent);
  background: color-mix(in oklab, var(--accent) 8%, var(--surface));
}

.option.is-selected .option__key {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
}

.option.is-correct {
  border-color: var(--correct);
  background: var(--correct-soft);
  animation: pop var(--dur) var(--ease);
}

.option.is-correct .option__key {
  color: var(--bg);
  background: var(--correct);
  border-color: var(--correct);
}

.option.is-correct .option__mark { opacity: 1; color: var(--correct); }

.option.is-incorrect {
  border-color: var(--incorrect);
  background: var(--incorrect-soft);
  animation: shake var(--dur-slow) var(--ease-inout);
}

.option.is-incorrect .option__key {
  color: var(--bg);
  background: var(--incorrect);
  border-color: var(--incorrect);
}

.option.is-incorrect .option__mark { opacity: 1; color: var(--incorrect); }

@keyframes pop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.015); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

/* --- Progress ----------------------------------------------------------- */

.progress {
  position: relative;
  height: 5px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
}

.progress__fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), color-mix(in oklab, var(--accent) 55%, var(--correct)));
  border-radius: inherit;
  transition: width var(--dur-slow) var(--ease);
}

/* --- Stat pills --------------------------------------------------------- */

.stats { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

.stat {
  display: inline-flex;
  align-items: baseline;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-3);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 99px;
}

.stat__label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
}

.stat--correct   { color: var(--correct);   border-color: color-mix(in oklab, var(--correct) 35%, var(--border)); }
.stat--incorrect { color: var(--incorrect); border-color: color-mix(in oklab, var(--incorrect) 35%, var(--border)); }

/* --- Timer -------------------------------------------------------------- */

.timer {
  font-family: var(--font-mono);
  font-size: var(--text-md);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.timer.is-warning { color: var(--flag); border-color: var(--flag); }

.timer.is-critical {
  color: var(--incorrect);
  border-color: var(--incorrect);
  animation: pulse 1.6s ease-in-out infinite;
}

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

/* --- Question palette --------------------------------------------------- */

.palette {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: var(--sp-2);
}

.palette__btn {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--dur-fast) var(--ease);
}

.palette__btn:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.palette__btn.is-answered { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.palette__btn.is-flagged  { color: var(--flag); border-color: var(--flag); background: var(--flag-soft); }
.palette__btn.is-current  { outline: 2px solid var(--text); outline-offset: 1px; }

/* --- Modal -------------------------------------------------------------- */

dialog.modal {
  /* The global `* { margin: 0 }` reset in base.css overrides the UA rule that
     centres a modal dialog, leaving it pinned to the top-left. Restore it. */
  margin: auto;
  width: min(100% - 2 * var(--sp-4), 560px);
  max-height: 86dvh;
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

dialog.modal--wide { width: min(100% - 2 * var(--sp-4), 820px); }

dialog.modal::backdrop {
  background: oklch(12% 0.02 260 / 0.62);
  backdrop-filter: blur(3px);
}

dialog.modal[open] { animation: modal-in var(--dur) var(--ease); }

@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to   { opacity: 1; transform: none; }
}

.modal__head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}

.modal__body { padding: var(--sp-5); overflow-y: auto; max-height: 60dvh; }

.modal__foot {
  display: flex;
  gap: var(--sp-2);
  justify-content: flex-end;
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--border);
}

/* --- Toasts ------------------------------------------------------------- */

.toasts {
  position: fixed;
  inset-block-end: var(--sp-5);
  inset-inline: 0;
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  max-width: min(92vw, 460px);
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-sm);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-inline-start: 3px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: toast-in var(--dur) var(--ease);
}

.toast.is-leaving { animation: toast-out var(--dur) var(--ease) forwards; }
.toast--error   { border-inline-start-color: var(--incorrect); }
.toast--success { border-inline-start-color: var(--correct); }

@keyframes toast-in  { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* --- Misc --------------------------------------------------------------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 4px var(--sp-3);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  transition: all var(--dur-fast) var(--ease);
}

.chip[aria-pressed="true"] {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
}

.field {
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-base);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

.field:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 20%, transparent);
}

.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

mark {
  padding: 0 2px;
  color: inherit;
  background: color-mix(in oklab, var(--flag) 40%, transparent);
  border-radius: 3px;
}
