/* tutor-ai — shared design system.
   Page-specific styles live in assets/css/<page>.css and reuse these tokens. */

:root {
  --bg: #f6f6fb;
  --surface: #ffffff;
  --surface-2: #f0f1f8;
  --surface-3: #e6e8f3;
  --text: #171a2b;
  --muted: #5b6078;
  --faint: #8a8fa6;
  --border: #e1e3ee;
  --border-strong: #c9ccdc;

  --primary: #5046e5;
  --primary-strong: #3f35cc;
  --primary-soft: #eceafe;
  --on-primary: #ffffff;

  /* Game position classes and answer states */
  --win: #15803d;
  --win-soft: #dcfce7;
  --win2: #0f766e;
  --win2-soft: #ccfbf1;
  --lose: #dc2626;
  --lose-soft: #fee2e2;
  --lose2: #c2410c;
  --lose2-soft: #ffedd5;
  --warn: #a16207;
  --warn-soft: #fef3c7;
  --info: #1d4ed8;
  --info-soft: #dbeafe;

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgb(23 26 43 / 6%);
  --shadow: 0 1px 2px rgb(23 26 43 / 6%), 0 8px 24px rgb(23 26 43 / 8%);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1120;
    --surface: #171a2e;
    --surface-2: #1e2238;
    --surface-3: #282d48;
    --text: #eceefa;
    --muted: #a4a9c3;
    --faint: #7d829c;
    --border: #2a2f4a;
    --border-strong: #3a4062;

    --primary: #8b83ff;
    --primary-strong: #a49dff;
    --primary-soft: #26244d;
    --on-primary: #0f1120;

    --win: #4ade80;
    --win-soft: #123524;
    --win2: #2dd4bf;
    --win2-soft: #0f3430;
    --lose: #f87171;
    --lose-soft: #3b1616;
    --lose2: #fb923c;
    --lose2-soft: #3b2412;
    --warn: #fbbf24;
    --warn-soft: #3a2c0b;
    --info: #60a5fa;
    --info-soft: #14284a;

    --shadow-sm: 0 1px 2px rgb(0 0 0 / 30%);
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 28%);
    color-scheme: dark;
  }
}

/* ---------- Base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

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

img,
svg {
  max-width: 100%;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1,
h2,
h3,
h4 {
  line-height: 1.2;
  margin: 0 0 0.5em;
  letter-spacing: -0.01em;
}

h1 {
  font-size: clamp(1.8rem, 1.2rem + 2.2vw, 2.6rem);
  font-weight: 750;
}

h2 {
  font-size: clamp(1.35rem, 1.1rem + 1vw, 1.75rem);
  font-weight: 700;
}

h3 {
  font-size: 1.15rem;
  font-weight: 650;
}

p {
  margin: 0 0 1em;
}

code,
kbd,
pre {
  font-family: var(--mono);
}

:not(pre) > code {
  font-size: 0.92em;
  padding: 0.1em 0.35em;
  border-radius: 6px;
  background: var(--surface-2);
}

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 55%, transparent);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

/* ---------- Layout ---------- */

.container {
  width: min(1120px, 100% - 32px);
  margin-inline: auto;
}

main {
  padding-top: 28px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.875rem;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

.stack > * + * {
  margin-top: var(--stack, 16px);
}

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

.row-between {
  justify-content: space-between;
}

.grid-2 {
  display: grid;
  gap: 20px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
}

.grid-3 {
  display: grid;
  gap: 20px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
}

.scroll-x {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 22px 0;
  border: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Header / footer ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 60px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 750;
  color: var(--text);
  font-size: 1.05rem;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  flex: none;
}

.site-nav {
  display: flex;
  gap: 2px;
}

.site-nav a {
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 10px;
  font-weight: 560;
}

.site-nav a:hover,
.site-nav a[aria-current="page"] {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

.site-footer {
  margin-top: 72px;
  padding: 28px 0 40px;
  border-top: 1px solid var(--border);
  color: var(--faint);
  font-size: 0.875rem;
}

.site-footer a {
  color: var(--muted);
}

/* ---------- Cards & panels ---------- */

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

.card-tight {
  padding: 16px;
}

.card > :last-child {
  margin-bottom: 0;
}

.panel {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 16px;
}

.panel > :last-child {
  margin-bottom: 0;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.08s, box-shadow 0.15s, color 0.15s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover {
  background: var(--surface-2);
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}

.btn-primary:hover {
  background: var(--primary-strong);
  border-color: var(--primary-strong);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn-sm {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 0.9rem;
}

.btn-lg {
  min-height: 52px;
  padding: 0 22px;
  font-size: 1.05rem;
  border-radius: 14px;
}

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

.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  padding: 4px;
  gap: 4px;
  background: var(--surface-2);
  border-radius: 12px;
  border: 1px solid var(--border);
}

.segmented button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 9px;
  cursor: pointer;
}

.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ---------- Inputs ---------- */

.input,
.select {
  min-height: 42px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.input:focus,
.select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.input-num {
  width: 120px;
  font-variant-numeric: tabular-nums;
}

.field {
  display: grid;
  gap: 6px;
}

.label,
.field > label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

.is-correct {
  border-color: var(--win) !important;
  box-shadow: 0 0 0 3px var(--win-soft) !important;
}

.is-wrong {
  border-color: var(--lose) !important;
  box-shadow: 0 0 0 3px var(--lose-soft) !important;
}

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 650;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.badge-primary {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: transparent;
}

.badge-success {
  background: var(--win-soft);
  color: var(--win);
  border-color: transparent;
}

.badge-warn {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: transparent;
}

.task-num {
  display: inline-grid;
  place-items: center;
  min-width: 44px;
  height: 44px;
  padding: 0 8px;
  border-radius: 12px;
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 800;
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}

.task-num-sm {
  min-width: 32px;
  height: 32px;
  border-radius: 9px;
  font-size: 0.9rem;
}

/* Position classes for the stone game: W1/W2 — the player to move wins, L1/L2 — loses */
.cls {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  padding: 1px 8px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.cls-W1 {
  background: var(--win-soft);
  color: var(--win);
}

.cls-W2 {
  background: var(--win2-soft);
  color: var(--win2);
}

.cls-L1 {
  background: var(--lose-soft);
  color: var(--lose);
}

.cls-L2 {
  background: var(--lose2-soft);
  color: var(--lose2);
}

.cls-other {
  background: var(--surface-2);
  color: var(--muted);
}

/* ---------- Callouts ---------- */

.callout {
  border-radius: var(--radius);
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.callout-info {
  background: var(--info-soft);
  border-color: transparent;
}

.callout-success {
  background: var(--win-soft);
  border-color: transparent;
}

.callout-error {
  background: var(--lose-soft);
  border-color: transparent;
}

.callout-warn {
  background: var(--warn-soft);
  border-color: transparent;
}

.callout > :last-child {
  margin-bottom: 0;
}

/* ---------- Trainer page ---------- */

.task-hero {
  display: grid;
  gap: 18px;
  grid-template-columns: auto 1fr;
  align-items: start;
  margin-bottom: 24px;
}

@media (max-width: 640px) {
  .task-hero {
    grid-template-columns: 1fr;
  }
}

.task-badges {
  display: flex;
  gap: 6px;
}

.lead {
  font-size: 1.08rem;
  color: var(--muted);
  max-width: 72ch;
}

.task-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  padding: 0;
  margin: 0;
}

.task-stats li {
  font-size: 0.85rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
}

.task-stats b {
  color: var(--text);
}

.stage-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 10px;
  margin: 0 0 18px;
  scroll-margin-top: 76px;
  scrollbar-width: thin;
}

.stage-tab {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 7px 14px 7px 7px;
  border-radius: 14px;
  cursor: pointer;
}

.stage-tab:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.stage-tab[aria-selected="true"] {
  color: var(--text);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.stage-num {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: var(--surface-2);
  font-weight: 750;
  font-size: 0.9rem;
}

.stage-tab[aria-selected="true"] .stage-num {
  background: var(--primary);
  color: var(--on-primary);
}

.stage-check {
  display: none;
  color: var(--win);
  font-weight: 800;
}

.stage-tab.is-done .stage-check {
  display: inline;
}

.stage {
  animation: fade-in 0.25s ease;
}

.stage-intro {
  margin-bottom: 18px;
}

.stage-intro p {
  color: var(--muted);
  max-width: 75ch;
}

.stage-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 24px;
}

/* ---------- Exam format ---------- */

.statement {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.statement > :last-child {
  margin-bottom: 0;
}

.answer-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

/* ---------- Code runner ---------- */

.code-runner {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px 8px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

textarea.code {
  display: block;
  width: 100%;
  min-height: 260px;
  resize: vertical;
  border: 0;
  margin: 0;
  padding: 14px 16px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.55;
  tab-size: 4;
  white-space: pre;
  overflow: auto;
}

textarea.code:focus {
  outline: none;
}

.code-output {
  margin: 0;
  padding: 12px 16px;
  background: #0f1120;
  color: #e6e8f5;
  font-family: var(--mono);
  font-size: 13.5px;
  white-space: pre-wrap;
  min-height: 48px;
  max-height: 300px;
  overflow: auto;
  border-top: 1px solid var(--border);
}

.code-output .err {
  color: #ff9b9b;
}

pre.code-block {
  margin: 0;
  padding: 14px 16px;
  background: var(--surface-2);
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 14px;
  line-height: 1.55;
}

/* ---------- Tables ---------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

table.data {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
}

table.data th,
table.data td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

table.data th {
  background: var(--surface-2);
  font-weight: 650;
  color: var(--muted);
}

table.data tr:last-child td {
  border-bottom: 0;
}

/* ---------- Toast ---------- */

.toast-host {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  z-index: 100;
  width: min(92vw, 460px);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--text);
  color: var(--bg);
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-weight: 560;
  animation: fade-in 0.2s ease;
}

.toast-success {
  background: #15803d;
  color: #fff;
}

.toast-error {
  background: #dc2626;
  color: #fff;
}

/* ---------- Motion ---------- */

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

@keyframes shake {
  10%,
  90% {
    transform: translateX(-1px);
  }
  20%,
  80% {
    transform: translateX(2px);
  }
  30%,
  50%,
  70% {
    transform: translateX(-4px);
  }
  40%,
  60% {
    transform: translateX(4px);
  }
}

@keyframes pop {
  0% {
    transform: scale(0.85);
  }
  60% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

.shake {
  animation: shake 0.4s ease;
}

.pop {
  animation: pop 0.3s ease;
}

/* SVG marks animate around their own center; wide drawings keep their size inside scroll containers. */
.shake,
.pop {
  transform-box: fill-box;
  transform-origin: center;
}

.scroll-x svg {
  max-width: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
