/* ==========================================================================
   InCompetition — Design System
   One set of tokens and components, reused identically on every page (student
   side and admin side). Every colour has a declared role and a verified
   contrast: the numbers below are WCAG 2.2 ratios, measured against the
   background the pair is actually used on.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */

:root {
  /* Colour — roles, not shade names */
  --c-bg: #f4f5f9;              /* page background */
  --c-surface: #ffffff;         /* surface: cards, bars, fields */
  --c-surface-2: #eef0f7;       /* secondary surface: rows, chips, inactive areas */
  --c-surface-3: #e3e6f1;       /* tertiary surface: solid dividers, skeletons */
  --c-border: #d5d9e8;          /* standard border */
  --c-border-strong: #84899d;   /* field and control borders — 3.5:1 on white (WCAG 1.4.11) */

  --c-text: #15172b;           /* primary text    — 17.7:1 on surface */
  --c-text-muted: #585e7c;     /* secondary text  —  6.3:1 on surface */
  --c-text-inverse: #ffffff;   /* text on solid dark fills */

  --c-primary: #4f46e5;        /* main action — 6.3:1 against white */
  --c-primary-hover: #4038cc;
  --c-primary-active: #3730a3;
  --c-primary-soft: #eceafe;   /* soft fill for badges and informative areas */
  --c-primary-text: #3a32b0;   /* text on primary-soft — 7.9:1 */

  --c-success: #0e7a53;        /* confirmations — 5.4:1 on white */
  --c-success-soft: #e2f5ec;
  --c-success-text: #0b5c3e;   /* 7.1:1 on success-soft */

  --c-danger: #c0261f;         /* errors and destructive actions — 5.9:1 on white */
  --c-danger-hover: #a11e18;
  --c-danger-soft: #fdeceb;
  --c-danger-text: #9c1c16;    /* 7.1:1 on danger-soft */

  --c-warning: #8a5a00;        /* attention / pending — 5.9:1 on white */
  --c-warning-soft: #fff3d6;
  --c-warning-text: #714900;   /* 7.2:1 on warning-soft */

  --c-medal: #7a5200;          /* medal — 6.1:1 on medal-soft */
  --c-medal-soft: #fff0c7;
  --c-medal-border: #e0b64d;

  --c-focus: #0b5fd0;          /* focus ring, visible on every surface */
  --c-overlay: rgba(16, 18, 32, 0.58);

  /* Voting: the colours of the three verdicts, used consistently everywhere */
  --c-vote-no: #b02a26;
  --c-vote-no-soft: #fdecec;
  --c-vote-maybe: #8a5a00;
  --c-vote-maybe-soft: #fff3d6;
  --c-vote-yes: #0e7a53;
  --c-vote-yes-soft: #e2f5ec;
  --c-vote-super: #4f46e5;
  --c-vote-super-soft: #eceafe;

  /* Typography — a fixed scale, no improvised sizes */
  --font-sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --fs-xs: 0.75rem;    /* 12px — metadata */
  --fs-sm: 0.875rem;   /* 14px — supporting text, hints */
  --fs-md: 1rem;       /* 16px — body copy (never below this in forms) */
  --fs-lg: 1.125rem;   /* 18px — lead text, the task */
  --fs-xl: 1.375rem;   /* 22px — section headings */
  --fs-2xl: 1.75rem;   /* 28px — page title */
  --fs-3xl: 2.125rem;  /* 34px — numbers and scores */
  --lh-tight: 1.25;
  --lh-normal: 1.55;

  /* Spacing — a 4px scale */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.5rem;
  --sp-6: 2rem;
  --sp-7: 3rem;
  --sp-8: 4rem;

  /* Shape and elevation */
  --r-sm: 0.5rem;
  --r-md: 0.75rem;
  --r-lg: 1.125rem;
  --r-pill: 999px;
  --sh-1: 0 1px 2px rgba(21, 23, 43, 0.08), 0 1px 3px rgba(21, 23, 43, 0.06);
  --sh-2: 0 4px 12px rgba(21, 23, 43, 0.1);
  --sh-3: 0 14px 40px rgba(21, 23, 43, 0.18);

  /* Minimum touch target size (WCAG 2.2 — Target Size) */
  --tap: 44px;
  --tap-lg: 56px;

  --container: 62rem;
  --transition: 160ms ease;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --c-bg: #0f1117;
    --c-surface: #171a24;
    --c-surface-2: #1f2331;
    --c-surface-3: #2a2f40;
    --c-border: #2e3446;
    --c-border-strong: #646d8c;  /* 3.4:1 on the dark surface */

    --c-text: #f2f3f8;
    --c-text-muted: #a7aec6;      /* 7.9:1 on surface */

    --c-primary: #4f46e5;
    --c-primary-hover: #5f57ee;
    --c-primary-active: #6f68f2;
    --c-primary-soft: #232449;
    --c-primary-text: #b9bdff;    /* 8.3:1 on primary-soft */

    --c-success: #109464;
    --c-success-soft: #10291f;
    --c-success-text: #6fd8a8;

    --c-danger: #d8443c;
    --c-danger-hover: #e4564e;
    --c-danger-soft: #2e1614;
    --c-danger-text: #ff9d95;

    --c-warning: #c58a1c;
    --c-warning-soft: #2b2110;
    --c-warning-text: #f0c268;

    --c-medal: #f3c969;
    --c-medal-soft: #2c2311;
    --c-medal-border: #7a5f22;

    --c-focus: #7fb2ff;
    --c-overlay: rgba(4, 6, 14, 0.7);

    --c-vote-no-soft: #2e1614;
    --c-vote-maybe-soft: #2b2110;
    --c-vote-yes-soft: #10291f;
    --c-vote-super-soft: #232449;
    --c-vote-no: #ff9d95;
    --c-vote-maybe: #f0c268;
    --c-vote-yes: #6fd8a8;
    --c-vote-super: #b9bdff;

    --sh-1: 0 1px 2px rgba(0, 0, 0, 0.5);
    --sh-2: 0 6px 16px rgba(0, 0, 0, 0.55);
    --sh-3: 0 18px 44px rgba(0, 0, 0, 0.65);
  }
}

/* --------------------------------------------------------------------------
   2. Base
   -------------------------------------------------------------------------- */

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

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-normal);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  line-height: var(--lh-tight);
  font-weight: 700;
  letter-spacing: -0.01em;
}

h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }

p { margin: 0; }

img {
  max-width: 100%;
  display: block;
}

a {
  color: var(--c-primary);
  text-underline-offset: 0.2em;
}

a:hover { color: var(--c-primary-hover); }

/* One focus style for the whole app: always visible, never removed. */
:where(a, button, input, select, textarea, [tabindex], summary):focus-visible {
  outline: 3px solid var(--c-focus);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

::selection {
  background: var(--c-primary);
  color: var(--c-text-inverse);
}

.skip-link {
  position: absolute;
  left: var(--sp-2);
  top: -100px;
  z-index: 100;
  padding: var(--sp-3) var(--sp-4);
  background: var(--c-surface);
  color: var(--c-text);
  border-radius: var(--r-sm);
  box-shadow: var(--sh-2);
  font-weight: 600;
}

.skip-link:focus {
  top: var(--sp-2);
}

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

/* --------------------------------------------------------------------------
   3. Layout
   -------------------------------------------------------------------------- */

.page {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--sp-4);
}

.main {
  flex: 1;
  padding-block: var(--sp-5) var(--sp-8);
}

.stack > * + * { margin-top: var(--sp-4); }
.stack-sm > * + * { margin-top: var(--sp-2); }
.stack-lg > * + * { margin-top: var(--sp-5); }

.row {
  display: flex;
  gap: var(--sp-3);
  flex-wrap: wrap;
  align-items: center;
}

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

.row--end { justify-content: flex-end; }

.section-title {
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-3);
}

.section-title small {
  color: var(--c-text-muted);
  font-size: var(--fs-sm);
  font-weight: 500;
}

/* --------------------------------------------------------------------------
   4. Header and navigation
   -------------------------------------------------------------------------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
}

.app-header__bar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  justify-content: space-between;
  min-height: 60px;
  padding-block: var(--sp-2);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 800;
  font-size: var(--fs-lg);
  color: var(--c-text);
  text-decoration: none;
  letter-spacing: -0.02em;
}

.brand__mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--c-primary);
  color: #fff;
  font-size: var(--fs-md);
  font-weight: 800;
}

.brand em {
  font-style: normal;
  color: var(--c-primary);
}

.app-header__user {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--fs-sm);
  color: var(--c-text-muted);
}

.app-nav {
  display: flex;
  gap: var(--sp-1);
  overflow-x: auto;
  scrollbar-width: none;
  border-top: 1px solid var(--c-border);
  padding-block: var(--sp-2);
}

.app-nav::-webkit-scrollbar { display: none; }

.app-nav a {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--tap);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  color: var(--c-text-muted);
  text-decoration: none;
  font-weight: 600;
  font-size: var(--fs-sm);
  white-space: nowrap;
}

.app-nav a:hover {
  background: var(--c-surface-2);
  color: var(--c-text);
}

.app-nav a[aria-current="page"] {
  background: var(--c-primary-soft);
  color: var(--c-primary-text);
}

/* --------------------------------------------------------------------------
   5. Buttons — every state is defined here and reused everywhere
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--tap);
  padding: var(--sp-2) var(--sp-4);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: var(--c-surface-2);
  color: var(--c-text);
  font: inherit;
  font-weight: 650;
  font-size: var(--fs-md);
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition),
    transform var(--transition), box-shadow var(--transition);
}

.btn:hover { background: var(--c-surface-3); }
.btn:active { transform: translateY(1px); }

.btn[disabled],
.btn[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 1;
  background: var(--c-surface-2);
  border-color: var(--c-border);
  color: var(--c-text-muted);
  box-shadow: none;
  transform: none;
}

.btn--primary {
  background: var(--c-primary);
  color: var(--c-text-inverse);
  box-shadow: var(--sh-1);
}

.btn--primary:hover { background: var(--c-primary-hover); }
.btn--primary:active { background: var(--c-primary-active); }

.btn--secondary {
  background: var(--c-surface);
  border-color: var(--c-border-strong);
  color: var(--c-text);
}

.btn--secondary:hover { background: var(--c-surface-2); }

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

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

.btn--danger {
  background: var(--c-danger);
  color: #fff;
}

.btn--danger:hover { background: var(--c-danger-hover); }

.btn--success {
  background: var(--c-success);
  color: #fff;
}

.btn--lg {
  min-height: var(--tap-lg);
  font-size: var(--fs-lg);
  padding-inline: var(--sp-5);
  border-radius: var(--r-md);
}

.btn--sm {
  min-height: 36px;
  font-size: var(--fs-sm);
  padding-inline: var(--sp-3);
}

.btn--block {
  width: 100%;
}

.btn.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid currentcolor;
  border-radius: 50%;
  border-top-color: transparent;
  color: var(--c-text-inverse);
  animation: spin 700ms linear infinite;
}

.btn--secondary.is-loading::after,
.btn--ghost.is-loading::after,
.btn.is-loading:not([class*="--"])::after {
  color: var(--c-text);
}

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

/* --------------------------------------------------------------------------
   6. Cards and surfaces
   -------------------------------------------------------------------------- */

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
  overflow: hidden;
}

.card__body {
  padding: var(--sp-5);
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--c-border);
  background: var(--c-surface);
}

.card__footer {
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--c-border);
  background: var(--c-surface-2);
}

.panel {
  background: var(--c-surface-2);
  border-radius: var(--r-md);
  padding: var(--sp-4);
}

/* The "task of the week" block: presented identically wherever it appears. */
.task-block {
  background: var(--c-primary-soft);
  border: 1px solid color-mix(in srgb, var(--c-primary) 25%, transparent);
  border-radius: var(--r-md);
  padding: var(--sp-4);
}

.task-block__label {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-primary-text);
  margin-bottom: var(--sp-1);
}

.task-block__text {
  font-size: var(--fs-lg);
  color: var(--c-text);
}

/* --------------------------------------------------------------------------
   7. Badges, chips, medal
   -------------------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 0.2em 0.7em;
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--c-surface-2);
  color: var(--c-text);
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge--pending {
  background: var(--c-warning-soft);
  color: var(--c-warning-text);
}

.badge--accepted {
  background: var(--c-success-soft);
  color: var(--c-success-text);
}

.badge--hidden {
  background: var(--c-danger-soft);
  color: var(--c-danger-text);
}

.badge--info {
  background: var(--c-primary-soft);
  color: var(--c-primary-text);
}

.badge--medal {
  background: var(--c-medal-soft);
  color: var(--c-medal);
  border-color: var(--c-medal-border);
}

.badge--lg {
  font-size: var(--fs-sm);
  padding: 0.35em 0.9em;
}

/* --------------------------------------------------------------------------
   8. Phase indicator — system status, always in view
   -------------------------------------------------------------------------- */

.phases {
  display: flex;
  gap: var(--sp-1);
  list-style: none;
  margin: 0;
  padding: var(--sp-1);
  background: var(--c-surface-2);
  border-radius: var(--r-pill);
  overflow-x: auto;
  scrollbar-width: none;
}

.phases::-webkit-scrollbar { display: none; }

.phase {
  flex: 1 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 36px;
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--c-text-muted);
  white-space: nowrap;
}

.phase__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c-border-strong);
}

.phase.is-done {
  color: var(--c-text);
}

.phase.is-done .phase__dot {
  background: var(--c-success);
}

.phase.is-current {
  background: var(--c-primary);
  color: #fff;
  box-shadow: var(--sh-1);
}

.phase.is-current .phase__dot {
  background: #fff;
  animation: pulse 1.8s ease-in-out infinite;
}

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

/* --------------------------------------------------------------------------
   9. Forms
   -------------------------------------------------------------------------- */

.field {
  display: block;
}

.field + .field { margin-top: var(--sp-4); }

.label {
  display: block;
  font-weight: 650;
  font-size: var(--fs-sm);
  margin-bottom: var(--sp-2);
  color: var(--c-text);
}

.label .req {
  color: var(--c-danger);
  margin-left: 2px;
}

.input,
.textarea,
.select {
  width: 100%;
  min-height: var(--tap);
  padding: var(--sp-3);
  font: inherit;
  font-size: var(--fs-md); /* 16px: stops iOS zooming in on focus */
  color: var(--c-text);
  background: var(--c-surface);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.textarea {
  resize: vertical;
  min-height: 6.5rem;
  line-height: var(--lh-normal);
}

.select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--c-text-muted) 50%),
    linear-gradient(135deg, var(--c-text-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 12px) 52%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: var(--sp-7);
}

.input:hover,
.textarea:hover,
.select:hover {
  border-color: var(--c-text-muted);
}

.input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-primary) 22%, transparent);
  outline: none;
}

.input:focus-visible,
.textarea:focus-visible,
.select:focus-visible {
  outline: 3px solid var(--c-focus);
  outline-offset: 1px;
}

.input[disabled],
.textarea[disabled],
.select[disabled] {
  background: var(--c-surface-2);
  color: var(--c-text-muted);
  cursor: not-allowed;
}

.input[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  border-color: var(--c-danger);
  background: var(--c-danger-soft);
}

.hint {
  display: block;
  margin-top: var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--c-text-muted);
}

.field-error {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--c-danger-text);
}

.field-error:empty { display: none; }

.counter {
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-sm);
  color: var(--c-text-muted);
}

.counter.is-warning { color: var(--c-warning); font-weight: 700; }
.counter.is-over { color: var(--c-danger-text); font-weight: 700; }

.code-input {
  text-transform: uppercase;
  letter-spacing: 0.3em;
  font-size: var(--fs-xl);
  font-weight: 700;
  text-align: center;
  min-height: var(--tap-lg);
}

/* File field: a large tappable area that always shows the chosen preview. */
.filefield {
  position: relative;
  display: block;
  border: 2px dashed var(--c-border-strong);
  border-radius: var(--r-md);
  background: var(--c-surface-2);
  padding: var(--sp-5) var(--sp-4);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}

.filefield:hover {
  border-color: var(--c-primary);
  background: var(--c-primary-soft);
}

.filefield input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

/* Icon, title and instruction stacked, one per line. */
.filefield__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-1);
  overflow-wrap: anywhere; /* a long file name wraps instead of widening the field */
}

.filefield input[type="file"]:focus-visible + .filefield__inner {
  outline: 3px solid var(--c-focus);
  outline-offset: 6px;
  border-radius: var(--r-sm);
}

.filefield__icon {
  font-size: 2rem;
  line-height: 1;
}

.filefield__title {
  font-weight: 700;
  margin-top: var(--sp-2);
}

.filefield.has-file {
  border-style: solid;
  border-color: var(--c-success);
  background: var(--c-success-soft);
}

.preview {
  margin-top: var(--sp-3);
  border-radius: var(--r-md);
  overflow: hidden;
  border: 1px solid var(--c-border);
  background: var(--c-surface-3);
}

/* The whole photo, never cropped: the empty sides show the surface behind it. */
.preview img {
  display: block;
  width: 100%;
  max-height: 420px;
  object-fit: contain;
}

/* --------------------------------------------------------------------------
   10. Messages: alerts, toasts, dialogs
   -------------------------------------------------------------------------- */

.alert {
  display: flex;
  gap: var(--sp-3);
  align-items: flex-start;
  padding: var(--sp-4);
  border-radius: var(--r-md);
  border: 1px solid transparent;
  font-size: var(--fs-sm);
}

.alert__icon { font-size: var(--fs-lg); line-height: 1.2; }
.alert__title { font-weight: 700; font-size: var(--fs-md); }
.alert__body { color: inherit; }

.alert--info {
  background: var(--c-primary-soft);
  color: var(--c-primary-text);
  border-color: color-mix(in srgb, var(--c-primary) 28%, transparent);
}

.alert--success {
  background: var(--c-success-soft);
  color: var(--c-success-text);
  border-color: color-mix(in srgb, var(--c-success) 30%, transparent);
}

.alert--warning {
  background: var(--c-warning-soft);
  color: var(--c-warning-text);
  border-color: color-mix(in srgb, var(--c-warning) 32%, transparent);
}

.alert--error {
  background: var(--c-danger-soft);
  color: var(--c-danger-text);
  border-color: color-mix(in srgb, var(--c-danger) 30%, transparent);
}

.toast-region {
  position: fixed;
  left: 50%;
  bottom: max(var(--sp-4), env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  width: min(28rem, calc(100vw - 2 * var(--sp-4)));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-left: 4px solid var(--c-text-muted);
  box-shadow: var(--sh-3);
  font-size: var(--fs-sm);
  pointer-events: auto;
  animation: toast-in 200ms ease;
}

.toast strong { display: block; font-size: var(--fs-md); }
.toast p { color: var(--c-text-muted); }
.toast--success { border-left-color: var(--c-success); }
.toast--error { border-left-color: var(--c-danger); }
.toast--info { border-left-color: var(--c-primary); }

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

dialog.modal {
  width: min(30rem, calc(100vw - 2 * var(--sp-4)));
  padding: 0;
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  background: var(--c-surface);
  color: var(--c-text);
  box-shadow: var(--sh-3);
}

dialog.modal::backdrop {
  background: var(--c-overlay);
}

.modal__body { padding: var(--sp-5); }
.modal__title { font-size: var(--fs-xl); margin-bottom: var(--sp-2); }
.modal__text { color: var(--c-text-muted); }

.modal__actions {
  display: flex;
  gap: var(--sp-3);
  justify-content: flex-end;
  padding: var(--sp-4) var(--sp-5);
  background: var(--c-surface-2);
  border-top: 1px solid var(--c-border);
  flex-wrap: wrap;
}

.modal__actions .btn { flex: 1 1 auto; }

@media (min-width: 30rem) {
  .modal__actions .btn { flex: 0 0 auto; }
}

/* --------------------------------------------------------------------------
   11. Empty and loading states
   -------------------------------------------------------------------------- */

.empty {
  display: grid;
  gap: var(--sp-3);
  justify-items: center;
  text-align: center;
  padding: var(--sp-7) var(--sp-4);
  background: var(--c-surface);
  border: 1px dashed var(--c-border-strong);
  border-radius: var(--r-lg);
}

.empty__icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--c-surface-2);
  font-size: 1.75rem;
}

.empty__title { font-size: var(--fs-xl); }

.empty__text {
  color: var(--c-text-muted);
  max-width: 34ch;
}

.skeleton {
  background: linear-gradient(90deg, var(--c-surface-2) 25%, var(--c-surface-3) 37%, var(--c-surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: var(--r-sm);
}

@keyframes shimmer {
  from { background-position: 100% 50%; }
  to { background-position: 0 50%; }
}

.skeleton--text { height: 1rem; }
.skeleton--title { height: 1.75rem; width: 60%; }
.skeleton--card { height: 320px; border-radius: var(--r-lg); }

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--c-border-strong);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.loading-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  color: var(--c-text-muted);
  padding: var(--sp-5);
  justify-content: center;
}

/* --------------------------------------------------------------------------
   12. Tables and leaderboards
   -------------------------------------------------------------------------- */

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

table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

.table th,
.table td {
  padding: var(--sp-3);
  text-align: left;
  border-bottom: 1px solid var(--c-border);
  vertical-align: middle;
}

.table thead th {
  position: sticky;
  top: 0;
  background: var(--c-surface-2);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--c-text-muted);
  white-space: nowrap;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--c-surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .is-you { background: var(--c-primary-soft); }
.table .is-you td { font-weight: 700; }

.rank-pos {
  display: inline-grid;
  place-items: center;
  min-width: 2rem;
  height: 2rem;
  padding-inline: 0.4em;
  border-radius: var(--r-sm);
  background: var(--c-surface-2);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.rank-pos--medal {
  background: var(--c-medal-soft);
  color: var(--c-medal);
  border: 1px solid var(--c-medal-border);
}

.score {
  font-size: var(--fs-lg);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.meter {
  --value: 0;
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--c-surface-3);
  overflow: hidden;
}

.meter__fill {
  height: 100%;
  width: calc(var(--value) * 1%);
  background: var(--c-primary);
  border-radius: inherit;
  transition: width var(--transition);
}

/* --------------------------------------------------------------------------
   13. Utilities
   -------------------------------------------------------------------------- */

.muted { color: var(--c-text-muted); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.strong { font-weight: 700; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mono {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: 0.12em;
  font-weight: 700;
}
.grow { flex: 1; }
.hidden { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  .app-header,
  .app-nav,
  .no-print,
  .toast-region {
    display: none !important;
  }

  body { background: #fff; }
  .card { box-shadow: none; border-color: #999; }
  .main { padding: 0; }
}
