/* ==========================================================================
   Kartuli — application shell & components
   Depends on tokens.css + base.css.

   Sections
     1  Layout: shell, container, page head, stacks
     2  Top bar: logo, language switcher, avatar menu
     3  Cards
     4  Buttons
     5  Form controls
     6  Chips (student tags)
     7  Tables & lists
     8  Empty states
     9  Toasts
     10 Modal / bottom sheet
     11 Tabs
     12 Set grid & game picker tiles
     13 Landing / hero
     14 Small utilities
   ========================================================================== */

/* ==========================================================================
   1. Layout
   ========================================================================== */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100svh;
}

.app-main {
  flex: 1 1 auto;
  padding-block: var(--sp-6) calc(var(--sp-12) + var(--safe-b));
}

.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}
.container-wide  { max-width: var(--container-wide); }
.container-prose { max-width: var(--container-prose); }

/* Page header: title + optional description + actions.
   On a phone the actions wrap under the title; from 640px they sit right. */
.page-head {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin-bottom: var(--sp-6);
}
.page-head__text { min-width: 0; }
.page-head__title {
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
}
.page-head__sub {
  margin-top: var(--sp-1);
  color: var(--ink-soft);
  font-size: var(--fs-md);
}
.page-head__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

@media (min-width: 40rem) {
  .page-head {
    flex-direction: row;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--sp-6);
  }
  .page-head__actions { flex-shrink: 0; }
}

/* Vertical rhythm helpers */
.stack       > * + * { margin-top: var(--sp-4); }
.stack-sm    > * + * { margin-top: var(--sp-2); }
.stack-lg    > * + * { margin-top: var(--sp-8); }

.row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
}
.row-tight { gap: var(--sp-2); }
.row-between { justify-content: space-between; }
.spacer { flex: 1 1 auto; }

.section-title {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--track-wide);
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: var(--sp-3);
}

/* Sticky bottom action bar — thumb-reachable primary action on phones. */
.action-bar {
  position: sticky;
  bottom: 0;
  z-index: var(--z-sticky);
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--gutter) calc(var(--sp-3) + var(--safe-b));
  margin-inline: calc(-1 * var(--gutter));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.action-bar > .btn { flex: 1 1 auto; }
@media (min-width: 40rem) {
  .action-bar {
    position: static;
    background: none;
    backdrop-filter: none;
    border-top: 0;
    padding-inline: 0;
    margin-inline: 0;
  }
  .action-bar > .btn { flex: 0 0 auto; }
}

/* ==========================================================================
   2. Top bar
   ========================================================================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
  padding-top: var(--safe-t);
}

.topbar__inner {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  height: var(--topbar-h);
  max-width: var(--container-wide);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* Logo — wordmark with a small wine seal. */
.logo {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: var(--fw-bold);
  font-size: var(--fs-lg);
  color: var(--ink);
  text-decoration: none;
  letter-spacing: var(--track-tight);
  flex-shrink: 0;
}
.logo:hover { color: var(--ink); }
.logo__mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(150deg, var(--wine), var(--wine-deep));
  color: var(--ink-invert);
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
  box-shadow: var(--shadow-1), var(--shadow-inset);
}
.logo__text { white-space: nowrap; }
.logo__dot { color: var(--apricot); }

.topbar__nav {
  display: none;
  gap: var(--sp-1);
  margin-inline-start: var(--sp-4);
}
@media (min-width: 48rem) { .topbar__nav { display: flex; } }

.navlink {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 var(--sp-3);
  border-radius: var(--radius-s);
  color: var(--ink-soft);
  text-decoration: none;
  font-weight: var(--fw-medium);
  font-size: var(--fs-md);
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.navlink:hover { background: var(--surface-2); color: var(--ink); }
.navlink[aria-current="page"] {
  color: var(--wine);
  background: var(--wine-tint);
}

/* --- Menus (language switcher + avatar). Pure CSS via <details>. --------- */

.menu { position: relative; }
.menu > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 var(--sp-3);
  border-radius: var(--radius-s);
  border: 1px solid transparent;
  color: var(--ink-soft);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary:hover { background: var(--surface-2); color: var(--ink); }
.menu[open] > summary { background: var(--surface-2); border-color: var(--line); color: var(--ink); }

.menu__panel {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + var(--sp-2));
  z-index: var(--z-dropdown);
  min-width: 12rem;
  padding: var(--sp-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-3);
  animation: kt-fade-up var(--dur-2) var(--ease-out) both;
}
.menu__item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  min-height: var(--tap);
  padding: 0 var(--sp-3);
  border-radius: var(--radius-s);
  color: var(--ink);
  text-decoration: none;
  font-size: var(--fs-md);
  text-align: start;
  cursor: pointer;
  transition: background var(--dur-1) var(--ease);
}
.menu__item:hover { background: var(--surface-2); color: var(--ink); }
.menu__item[aria-current="true"] { color: var(--wine); font-weight: var(--fw-semibold); }
.menu__item--danger { color: var(--berry); }
.menu__item--danger:hover { background: var(--berry-tint); }
.menu__sep { height: 1px; background: var(--line); margin: var(--sp-2) var(--sp-1); }
.menu__label {
  padding: var(--sp-2) var(--sp-3) var(--sp-1);
  font-size: var(--fs-xs);
  letter-spacing: var(--track-wide);
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* Language switcher: compact code on phones, full name from 48rem. */
.lang__code { text-transform: uppercase; letter-spacing: var(--track-wide); }
.lang__name { display: none; }
@media (min-width: 48rem) { .lang__name { display: inline; } }

/* Avatar */
.avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  color: var(--ink-soft);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  overflow: hidden;
  object-fit: cover;
}
.avatar--lg { width: 44px; height: 44px; font-size: var(--fs-lg); }
.avatar--wine { background: var(--wine); color: var(--ink-invert); }

/* ==========================================================================
   3. Cards
   ========================================================================== */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-1);
  overflow: clip;
}
.card--flat  { box-shadow: none; }
.card--quiet { background: var(--surface-2); border-color: transparent; box-shadow: none; }
.card--raised { box-shadow: var(--shadow-2); }

.card__head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--line);
}
.card__title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.card__sub { color: var(--ink-soft); font-size: var(--fs-sm); }
.card__body { padding: var(--sp-5); }
.card__foot {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}

/* A card that is a link: lift on pointer devices only. */
.card--link {
  display: block;
  color: inherit;
  text-decoration: none;
  transition: transform var(--dur-2) var(--ease),
              box-shadow var(--dur-2) var(--ease),
              border-color var(--dur-2) var(--ease);
}
.card--link:hover { color: inherit; }
@media (hover: hover) {
  .card--link:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-2);
    border-color: var(--line-strong);
  }
}
.card--link:active { transform: translateY(0); }

/* ==========================================================================
   4. Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--tap);
  padding: 0 var(--sp-5);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: background var(--dur-1) var(--ease),
              border-color var(--dur-1) var(--ease),
              color var(--dur-1) var(--ease),
              transform var(--dur-1) var(--ease),
              box-shadow var(--dur-1) var(--ease);
}
.btn:hover { color: var(--ink); border-color: var(--line-strong); background: var(--surface-2); }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn svg { width: 20px; height: 20px; flex-shrink: 0; }

.btn[disabled], .btn[aria-disabled="true"], .btn.is-disabled {
  opacity: .5;
  cursor: not-allowed;
  pointer-events: none;
  box-shadow: none;
}

/* Primary — the wine action. */
.btn-primary {
  background: linear-gradient(180deg, var(--wine), var(--wine-deep));
  border-color: var(--wine-deep);
  color: var(--ink-invert);
  box-shadow: var(--shadow-1), var(--shadow-inset);
}
.btn-primary:hover {
  color: var(--ink-invert);
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--wine) 88%, #fff),
    var(--wine));
  border-color: var(--wine-deep);
}

/* Accent — apricot, for "play" style calls to action. */
.btn-accent {
  background: linear-gradient(180deg, var(--apricot),
    color-mix(in srgb, var(--apricot) 82%, #000));
  border-color: color-mix(in srgb, var(--apricot) 70%, #000);
  color: #fff;
  box-shadow: var(--shadow-1), var(--shadow-inset);
}
.btn-accent:hover { color: #fff; filter: brightness(1.05); }

/* Ghost — no chrome until touched. */
.btn-ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--ink-soft);
  font-weight: var(--fw-medium);
}
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; color: var(--ink); }

/* Outline — secondary next to a primary. */
.btn-outline {
  background: transparent;
  border-color: var(--line-strong);
  box-shadow: none;
}
.btn-outline:hover { background: var(--surface-2); }

/* Danger */
.btn-danger {
  background: var(--berry);
  border-color: color-mix(in srgb, var(--berry) 72%, #000);
  color: #fff;
  box-shadow: var(--shadow-1), var(--shadow-inset);
}
.btn-danger:hover { color: #fff; filter: brightness(1.06); }
.btn-danger.btn-ghost {
  background: transparent;
  color: var(--berry);
  border-color: transparent;
  box-shadow: none;
  filter: none;
}
.btn-danger.btn-ghost:hover { background: var(--berry-tint); }

/* Sizes — small never goes under 44px of *touch* area, it only looks smaller. */
.btn-sm {
  min-height: 36px;
  padding: 0 var(--sp-3);
  font-size: var(--fs-sm);
  border-radius: var(--radius-xs);
  position: relative;
}
/* Looks 36px, taps 44px: a centred, horizontally-contained hit area. */
.btn-sm::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  height: var(--tap);
  transform: translateY(-50%);
}
.btn-lg {
  min-height: 52px;
  padding: 0 var(--sp-6);
  font-size: var(--fs-lg);
  border-radius: var(--radius-m);
}
.btn-xl {
  min-height: 60px;
  padding: 0 var(--sp-8);
  font-size: var(--fs-xl);
  border-radius: var(--radius-m);
}
.btn-block { display: flex; width: 100%; }

/* Icon-only */
.btn-icon {
  padding: 0;
  width: var(--tap);
  min-width: var(--tap);
  border-radius: var(--radius-s);
}

/* Busy state — a calm pulse, not a spinner that needs JS. */
.btn.is-loading { pointer-events: none; position: relative; color: transparent; }
.btn.is-loading::before {
  content: "";
  position: absolute;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  color: var(--ink-invert);
  animation: kt-spin 700ms linear infinite;
}
.btn-ghost.is-loading::before, .btn-outline.is-loading::before { color: var(--ink-soft); }

/* Button group */
.btn-group { display: inline-flex; }
.btn-group > .btn { border-radius: 0; margin-inline-start: -1px; box-shadow: none; }
.btn-group > .btn:first-child {
  border-start-start-radius: var(--radius-s);
  border-end-start-radius: var(--radius-s);
  margin-inline-start: 0;
}
.btn-group > .btn:last-child {
  border-start-end-radius: var(--radius-s);
  border-end-end-radius: var(--radius-s);
}

/* ==========================================================================
   5. Form controls
   ========================================================================== */

.field { display: block; margin-bottom: var(--sp-4); }
.field:last-child { margin-bottom: 0; }

.label {
  display: block;
  margin-bottom: var(--sp-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--ink);
}
.label__opt { font-weight: var(--fw-regular); color: var(--ink-faint); }
.label__req { color: var(--berry); margin-inline-start: 2px; }

.input, .textarea, .select {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
  font-size: 1rem;               /* 16px: stops iOS zooming on focus */
  line-height: 1.4;
  box-shadow: inset 0 1px 2px rgba(60,40,20,.04);
  transition: border-color var(--dur-1) var(--ease),
              box-shadow var(--dur-1) var(--ease),
              background var(--dur-1) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-faint); }

.input:hover, .textarea:hover, .select:hover { border-color: var(--ink-faint); }

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

.input:focus-visible, .textarea:focus-visible, .select:focus-visible {
  outline: 2px solid var(--focus-ring-color);
  outline-offset: 1px;
  box-shadow: none;
}

.textarea { min-height: 7.5rem; resize: vertical; line-height: var(--lh-normal); }
.textarea--paste { min-height: 14rem; font-family: var(--font-mono); font-size: var(--fs-md); }

/* Select gets a chevron drawn in CSS — no image, no JS. */
.select {
  appearance: none;
  padding-inline-end: var(--sp-10);
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position:
    right calc(var(--sp-4) + 6px) center,
    right var(--sp-4) center;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  cursor: pointer;
}
[dir="rtl"] .select {
  background-position: left var(--sp-4) center, left calc(var(--sp-4) + 6px) center;
}

.help {
  display: block;
  margin-top: var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--ink-soft);
}

/* Error state: colour AND an icon-less text message, never colour alone. */
.field.is-invalid .input,
.field.is-invalid .textarea,
.field.is-invalid .select,
.input[aria-invalid="true"],
.textarea[aria-invalid="true"],
.select[aria-invalid="true"] {
  border-color: var(--berry);
  background: var(--berry-tint);
}
.field.is-invalid .input:focus,
.input[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--berry) 22%, transparent);
}
.field-error {
  display: block;
  margin-top: var(--sp-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--berry);
}
.field-error::before { content: "! "; font-weight: var(--fw-bold); }

/* Input with a leading/trailing adornment (e.g. the share URL). */
.input-group { display: flex; }
.input-group > .input {
  border-start-end-radius: 0;
  border-end-end-radius: 0;
}
.input-group > .btn {
  border-start-start-radius: 0;
  border-end-start-radius: 0;
  margin-inline-start: -1px;
}

/* Checkbox / radio */
.check {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  min-height: var(--tap);
  padding: var(--sp-2) 0;
  cursor: pointer;
}
.check input[type="checkbox"], .check input[type="radio"] {
  appearance: none;
  flex: 0 0 auto;
  width: 22px; height: 22px;
  margin-top: 1px;
  border: 2px solid var(--line-strong);
  background: var(--surface);
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}
.check input[type="radio"] { border-radius: 50%; }
.check input:checked {
  background: var(--wine);
  border-color: var(--wine);
}
.check input[type="checkbox"]:checked {
  background-image: linear-gradient(45deg, transparent 44%, #fff 44%, #fff 56%, transparent 56%),
                    linear-gradient(-45deg, transparent 44%, #fff 44%, #fff 56%, transparent 56%);
  background-size: 60% 60%;
  background-position: center;
  background-repeat: no-repeat;
}
.check input[type="radio"]:checked {
  box-shadow: inset 0 0 0 4px var(--surface);
}
.check__text { font-size: var(--fs-md); }
.check__hint { display: block; font-size: var(--fs-sm); color: var(--ink-soft); }

/* Switch */
.switch { display: inline-flex; align-items: center; gap: var(--sp-3); cursor: pointer; min-height: var(--tap); }
.switch input {
  appearance: none;
  width: 46px; height: 28px;
  border-radius: var(--radius-pill);
  background: var(--line-strong);
  position: relative;
  cursor: pointer;
  transition: background var(--dur-2) var(--ease);
  flex: 0 0 auto;
}
.switch input::after {
  content: "";
  position: absolute;
  top: 3px; inset-inline-start: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-1);
  transition: transform var(--dur-2) var(--ease-spring);
}
.switch input:checked { background: var(--olive); }
.switch input:checked::after { transform: translateX(18px); }
[dir="rtl"] .switch input:checked::after { transform: translateX(-18px); }

/* Fieldset */
.fieldset { border: 0; padding: 0; margin: 0 0 var(--sp-6); }
.fieldset > legend {
  padding: 0;
  margin-bottom: var(--sp-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
}

/* Two-column form rows from 40rem */
.form-row { display: grid; gap: var(--sp-4); }
@media (min-width: 40rem) { .form-row { grid-template-columns: 1fr 1fr; } }

/* ==========================================================================
   6. Chips — student tags and small labels
   ========================================================================== */

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  max-width: 100%;
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--ink-soft);
  border: 1px solid transparent;
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  line-height: 1.6;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip__dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}

/* Colour variants — tint background, readable ink, in both themes. */
.chip--wine    { background: var(--wine-tint);    color: var(--wine-ink); }
.chip--apricot { background: var(--apricot-tint); color: var(--apricot-ink); }
.chip--olive   { background: var(--olive-tint);   color: var(--olive-ink); }
.chip--gold    { background: var(--gold-tint);    color: var(--gold-ink); }
.chip--berry   { background: var(--berry-tint);   color: var(--berry-ink); }
.chip--indigo  { background: var(--indigo-tint);  color: var(--indigo-ink); }

/* A chip that is a button/link gets a 44px touch area without growing. */
.chip--action { cursor: pointer; position: relative; transition: filter var(--dur-1) var(--ease); }
.chip--action::after { content: ""; position: absolute; inset: -5px; }
.chip--action:hover { filter: brightness(.97); }
:root[data-theme="dark"] .chip--action:hover { filter: brightness(1.15); }

.chip--removable { padding-inline-end: var(--sp-1); }
.chip__x {
  display: grid;
  place-items: center;
  width: 20px; height: 20px;
  border-radius: 50%;
  color: inherit;
  opacity: .65;
  cursor: pointer;
  position: relative;
}
.chip__x::after { content: ""; position: absolute; inset: -6px -5px -6px -2px; }
.chip__x:hover { opacity: 1; background: rgba(0,0,0,.08); }

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

/* Selected state for a filter chip */
.chip.is-selected {
  border-color: currentColor;
  font-weight: var(--fw-semibold);
}

/* Small square badge (counts) */
.badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--wine);
  color: var(--ink-invert);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  line-height: 1;
}
.badge--quiet { background: var(--surface-3); color: var(--ink-soft); }
.badge--gold  { background: var(--gold); color: #3A2A06; }

/* ==========================================================================
   7. Tables & lists
   On a phone a .table--cards table reflows into stacked rows using the
   data-label attribute on each cell. No JS.
   ========================================================================== */

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

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-md);
}
.table th, .table td {
  padding: var(--sp-3) var(--sp-4);
  text-align: start;
  vertical-align: middle;
}
.table thead th {
  background: var(--surface-2);
  color: var(--ink-soft);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--track-wide);
  text-transform: uppercase;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
.table tbody tr + tr td { border-top: 1px solid var(--line); }
.table tbody tr:hover td { background: var(--surface-2); }
.table td.num, .table th.num { text-align: end; font-variant-numeric: tabular-nums; }
.table .cell-actions { width: 1%; white-space: nowrap; text-align: end; }

@media (max-width: 39.99rem) {
  .table--cards, .table--cards tbody, .table--cards tr, .table--cards td { display: block; }
  .table--cards thead { display: none; }
  .table--cards tr {
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--line);
  }
  .table--cards tbody tr + tr td { border-top: 0; }
  .table--cards td {
    display: flex;
    justify-content: space-between;
    gap: var(--sp-4);
    padding: var(--sp-1) 0;
  }
  .table--cards td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    color: var(--ink-faint);
    font-size: var(--fs-sm);
  }
  .table--cards td:empty { display: none; }
}

/* Plain list of rows (word list, student list) */
.list {
  list-style: none;
  padding: 0;
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  overflow: clip;
}
.list__item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 56px;
  padding: var(--sp-3) var(--sp-4);
  color: inherit;
  text-decoration: none;
}
.list__item + .list__item { border-top: 1px solid var(--line); }
.list__item:hover { background: var(--surface-2); color: inherit; }
.list__main { min-width: 0; flex: 1 1 auto; }
.list__title { font-weight: var(--fw-medium); }
.list__sub { font-size: var(--fs-sm); color: var(--ink-soft); }
.list__end { flex: 0 0 auto; display: flex; align-items: center; gap: var(--sp-2); }

/* A word pair row: term (Georgian) on the left, translation on the right. */
.pair {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: baseline;
  gap: var(--sp-3);
}
.pair__term { font-size: var(--fs-lg); font-weight: var(--fw-medium); }
.pair__arrow { color: var(--ink-faint); }
.pair__tr { color: var(--ink-soft); text-align: end; }

/* ==========================================================================
   8. Empty states
   ========================================================================== */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--sp-3);
  padding: var(--sp-12) var(--sp-5);
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-l);
}
.empty__art {
  display: grid;
  place-items: center;
  width: 64px; height: 64px;
  border-radius: var(--radius-l);
  background: var(--surface);
  color: var(--apricot);
  box-shadow: var(--shadow-1);
}
.empty__art svg { width: 28px; height: 28px; }
.empty__title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.empty__text {
  max-width: 34ch;
  color: var(--ink-soft);
  font-size: var(--fs-md);
}
.empty__actions { margin-top: var(--sp-2); display: flex; gap: var(--sp-2); flex-wrap: wrap; justify-content: center; }

/* ==========================================================================
   9. Toasts — bottom on phones (thumb + out of the way), top-right on desktop
   ========================================================================== */

.toasts {
  position: fixed;
  z-index: var(--z-toast);
  inset-inline: var(--sp-4);
  bottom: calc(var(--sp-4) + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  pointer-events: none;
}
@media (min-width: 40rem) {
  .toasts {
    inset-inline: auto var(--sp-6);
    bottom: auto;
    top: calc(var(--topbar-h) + var(--sp-4) + var(--safe-t));
    width: min(24rem, calc(100vw - var(--sp-12)));
  }
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-inline-start: 4px solid var(--ink-faint);
  border-radius: var(--radius-s);
  box-shadow: var(--shadow-3);
  pointer-events: auto;
  animation: kt-fade-up var(--dur-3) var(--ease-out) both;
}
.toast--success { border-inline-start-color: var(--olive); }
.toast--error   { border-inline-start-color: var(--berry); }
.toast--info    { border-inline-start-color: var(--apricot); }
.toast__title { font-weight: var(--fw-semibold); font-size: var(--fs-md); }
.toast__text  { font-size: var(--fs-sm); color: var(--ink-soft); }
.toast__close { margin-inline-start: auto; color: var(--ink-faint); cursor: pointer; }
.toast.is-leaving { animation: kt-fade-out var(--dur-2) var(--ease-in) both; }

/* Inline banner (same language, inside the page flow) */
.banner {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-s);
  font-size: var(--fs-md);
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
}
.banner--success { background: var(--olive-tint);   color: var(--olive-ink);   border-color: transparent; }
.banner--error   { background: var(--berry-tint);   color: var(--berry-ink);   border-color: transparent; }
.banner--warn    { background: var(--gold-tint);    color: var(--gold-ink);    border-color: transparent; }
.banner--info    { background: var(--apricot-tint); color: var(--apricot-ink); border-color: transparent; }

/* ==========================================================================
   10. Modal / bottom sheet
   Uses <dialog>. On phones it is a bottom sheet; from 40rem a centred modal.
   ========================================================================== */

.modal {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  max-width: 100%;
  max-height: 100%;
}
.modal::backdrop {
  background: rgba(26,22,20,.45);
  backdrop-filter: blur(2px);
}

/* Bottom sheet (mobile default) */
.modal__panel {
  width: 100vw;
  max-height: 88svh;
  overflow-y: auto;
  background: var(--surface);
  border-start-start-radius: var(--radius-l);
  border-start-end-radius: var(--radius-l);
  box-shadow: var(--shadow-3);
  padding-bottom: var(--safe-b);
}
.modal[open] { animation: kt-fade-in var(--dur-2) var(--ease) both; }
.modal[open] .modal__panel { animation: kt-sheet-up var(--dur-3) var(--ease-out) both; }

/* Grab handle — signals "drag/close" on a sheet. */
.modal__grip {
  width: 40px; height: 4px;
  margin: var(--sp-3) auto var(--sp-1);
  border-radius: var(--radius-pill);
  background: var(--line-strong);
}

.modal__head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: var(--z-raised);
}
.modal__title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.modal__close { margin-inline-start: auto; color: var(--ink-soft); }
.modal__body { padding: var(--sp-5); }
.modal__foot {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5) calc(var(--sp-4) + var(--safe-b));
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  position: sticky;
  bottom: 0;
}
.modal__foot > .btn { flex: 1 1 auto; }

/* Position the dialog itself at the bottom on phones. */
.modal {
  margin: auto auto 0;
}
@media (min-width: 40rem) {
  .modal { margin: auto; }
  .modal__panel {
    width: min(34rem, calc(100vw - var(--sp-8)));
    max-height: 80svh;
    border-radius: var(--radius-l);
  }
  .modal[open] .modal__panel { animation: kt-pop-in var(--dur-3) var(--ease-out) both; }
  .modal__grip { display: none; }
  .modal__foot { justify-content: flex-end; }
  .modal__foot > .btn { flex: 0 0 auto; }
}
.modal--wide .modal__panel { width: min(52rem, calc(100vw - var(--sp-8))); }

/* Non-dialog fallback scrim, if a template needs a div-based overlay. */
.scrim {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  background: rgba(26,22,20,.45);
}

/* ==========================================================================
   11. Tabs
   Scrollable on a phone, never wrapping to a second confusing row.
   ========================================================================== */

.tabs {
  display: flex;
  gap: var(--sp-1);
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--line);
  margin-bottom: var(--sp-5);
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--tap);
  padding: 0 var(--sp-4);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--ink-soft);
  font-weight: var(--fw-medium);
  font-size: var(--fs-md);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"], .tab.is-active {
  color: var(--wine);
  border-bottom-color: var(--wine);
  font-weight: var(--fw-semibold);
}

/* Pill variant, for a small segmented control */
.tabs--pills { border-bottom: 0; gap: var(--sp-1); padding: var(--sp-1); background: var(--surface-2); border-radius: var(--radius-pill); }
.tabs--pills .tab {
  border: 0;
  margin: 0;
  border-radius: var(--radius-pill);
}
.tabs--pills .tab[aria-selected="true"], .tabs--pills .tab.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-1);
}

/* ==========================================================================
   12. Set grid & game picker tiles
   ========================================================================== */

/* Sets the teacher owns */
.set-grid {
  display: grid;
  gap: var(--sp-4);
  grid-template-columns: 1fr;
}
@media (min-width: 34rem) { .set-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 56rem) { .set-grid { grid-template-columns: repeat(3, 1fr); } }

.set-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-5);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-1);
  color: inherit;
  text-decoration: none;
  position: relative;
  isolation: isolate;
  transition: transform var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease);
}
/* A thin warm spine, cycling hue by nth-child so a grid never looks flat. */
.set-card::before {
  content: "";
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  width: 4px;
  border-start-start-radius: var(--radius-m);
  border-end-start-radius: var(--radius-m);
  background: var(--wine);
}
.set-card:nth-child(6n+2)::before { background: var(--apricot); }
.set-card:nth-child(6n+3)::before { background: var(--olive); }
.set-card:nth-child(6n+4)::before { background: var(--gold); }
.set-card:nth-child(6n+5)::before { background: var(--indigo); }
.set-card:nth-child(6n)::before   { background: var(--berry); }
@media (hover: hover) {
  .set-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); color: inherit; }
}
.set-card__title {
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-snug);
}
.set-card__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--ink-soft);
  margin-top: auto;
}
.set-card__preview {
  font-size: var(--fs-sm);
  color: var(--ink-soft);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-clamp: 2;
  overflow: hidden;
}

/* --- The game picker: ~10 tiles a child taps ---------------------------- */

.game-grid {
  display: grid;
  gap: var(--sp-3);
  grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 30rem) { .game-grid { grid-template-columns: repeat(3, 1fr); gap: var(--sp-4); } }
@media (min-width: 48rem) { .game-grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 64rem) { .game-grid { grid-template-columns: repeat(5, 1fr); } }

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 112px;
  padding: var(--sp-4) var(--sp-2);
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-1);
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  transition: transform var(--dur-2) var(--ease-spring),
              box-shadow var(--dur-2) var(--ease),
              border-color var(--dur-2) var(--ease);
}
.tile:hover { color: var(--ink); }
@media (hover: hover) {
  .tile:hover { transform: translateY(-3px) rotate(-.4deg); box-shadow: var(--shadow-2); }
}
.tile:active { transform: scale(.97); }

.tile__icon {
  display: grid;
  place-items: center;
  width: 48px; height: 48px;
  border-radius: var(--radius-m);
  background: var(--surface-2);
  color: var(--wine);
  transition: transform var(--dur-2) var(--ease-spring);
}
.tile__icon svg { width: 24px; height: 24px; }
@media (hover: hover) { .tile:hover .tile__icon { transform: scale(1.08) rotate(3deg); } }

.tile__name {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-snug);
}

/* Rotate the accent so the picker reads as a colourful board. */
.tile:nth-child(6n+1) .tile__icon { background: var(--wine-tint);    color: var(--wine-ink); }
.tile:nth-child(6n+2) .tile__icon { background: var(--apricot-tint); color: var(--apricot-ink); }
.tile:nth-child(6n+3) .tile__icon { background: var(--olive-tint);   color: var(--olive-ink); }
.tile:nth-child(6n+4) .tile__icon { background: var(--gold-tint);    color: var(--gold-ink); }
.tile:nth-child(6n+5) .tile__icon { background: var(--indigo-tint);  color: var(--indigo-ink); }
.tile:nth-child(6n)   .tile__icon { background: var(--berry-tint);   color: var(--berry-ink); }

/* A game the set cannot support (too few items, no translations). */
.tile.is-locked {
  opacity: .55;
  cursor: not-allowed;
  box-shadow: none;
  background: var(--surface-2);
}
.tile.is-locked:hover { transform: none; }
.tile__lock {
  font-size: var(--fs-xs);
  color: var(--ink-faint);
}

/* ==========================================================================
   13. Landing / hero
   ========================================================================== */

.hero {
  position: relative;
  overflow: hidden;
  padding-block: var(--sp-12) var(--sp-16);
  text-align: center;
  isolation: isolate;
}
/* Two soft washes of wine + apricot, like ink bleeding into paper. */
.hero::before {
  content: "";
  position: absolute;
  inset: -20% -10% auto;
  height: 36rem;
  z-index: -1;
  background:
    radial-gradient(34rem 20rem at 22% 30%, color-mix(in srgb, var(--wine) 16%, transparent), transparent 70%),
    radial-gradient(30rem 18rem at 78% 20%, color-mix(in srgb, var(--apricot) 20%, transparent), transparent 70%);
  filter: blur(6px);
}

.hero__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-3);
  margin-bottom: var(--sp-5);
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-1);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--ink-soft);
}

.hero__title {
  font-size: var(--fs-3xl);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
  letter-spacing: -0.02em;
  max-width: 18ch;
  margin-inline: auto;
}
.hero__title em {
  font-style: normal;
  color: var(--wine);
  /* An apricot underline drawn under the key phrase. */
  background-image: linear-gradient(transparent 68%, color-mix(in srgb, var(--apricot) 40%, transparent) 68%);
  padding-inline: .1em;
}

.hero__lead {
  max-width: 46ch;
  margin: var(--sp-5) auto 0;
  font-size: var(--fs-lg);
  color: var(--ink-soft);
  line-height: var(--lh-normal);
}

.hero__actions {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  align-items: stretch;
  margin-top: var(--sp-8);
}
@media (min-width: 30rem) {
  .hero__actions { flex-direction: row; justify-content: center; align-items: center; }
}

.hero__note {
  margin-top: var(--sp-4);
  font-size: var(--fs-sm);
  color: var(--ink-faint);
}

/* Feature row under the hero */
.features {
  display: grid;
  gap: var(--sp-6);
  grid-template-columns: 1fr;
  padding-block: var(--sp-10);
}
@media (min-width: 48rem) { .features { grid-template-columns: repeat(3, 1fr); gap: var(--sp-8); } }

.feature__icon {
  display: grid;
  place-items: center;
  width: 44px; height: 44px;
  margin-bottom: var(--sp-3);
  border-radius: var(--radius-m);
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--apricot);
  box-shadow: var(--shadow-1);
}
.feature__title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); margin-bottom: var(--sp-2); }
.feature__text { color: var(--ink-soft); }

/* Footer */
.footer {
  border-top: 1px solid var(--line);
  padding-block: var(--sp-8) calc(var(--sp-8) + var(--safe-b));
  color: var(--ink-faint);
  font-size: var(--fs-sm);
}
.footer a { color: var(--ink-soft); text-decoration: none; }
.footer a:hover { color: var(--wine); text-decoration: underline; }
.footer__row { display: flex; flex-wrap: wrap; gap: var(--sp-4); align-items: center; }

/* Long-form copy (terms, help, a set description). The reset zeroes every
   margin, so prose needs its own rhythm back. */
.prose { max-width: var(--container-prose); }
.prose > * + *   { margin-top: var(--sp-4); }
.prose h2        { margin-top: var(--sp-8); }
.prose h3        { margin-top: var(--sp-6); }
.prose ul, .prose ol { padding-inline-start: var(--sp-6); }
.prose li + li   { margin-top: var(--sp-2); }
.prose a         { text-decoration: underline; }

/* ==========================================================================
   14. Utilities & shell keyframes
   ========================================================================== */

.center-text { text-align: center; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hide-sm { display: none; }
@media (min-width: 40rem) { .hide-sm { display: initial; } .only-sm { display: none; } }
.mt-0 { margin-top: 0; }
.mt-4 { margin-top: var(--sp-4); }
.mt-6 { margin-top: var(--sp-6); }
.mt-8 { margin-top: var(--sp-8); }
.num { font-variant-numeric: tabular-nums; }

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

@keyframes kt-fade-in { from { opacity: 0; } to { opacity: 1; } }

@keyframes kt-fade-out { to { opacity: 0; transform: translateY(4px); } }

@keyframes kt-fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

@keyframes kt-sheet-up {
  from { transform: translateY(100%); }
  to   { transform: none; }
}

@keyframes kt-pop-in {
  from { opacity: 0; transform: scale(.96) translateY(6px); }
  to   { opacity: 1; transform: none; }
}
