:root {
  color-scheme: light;
  --ink: #15182c;
  --muted: #65697d;
  --faint: #898da0;
  --brand: #5b5bf6;
  --brand-dark: #4141d6;
  --brand-soft: #eeeeff;
  --blue-soft: #eaf2ff;
  --mint-soft: #e7f6f1;
  --peach-soft: #fff1e7;
  --paper: #f5f5fa;
  --card: #fff;
  --line: #e4e6ef;
  --danger: #d83f48;
  --danger-soft: #fdebed;
  --shadow: 0 1px 2px rgb(29 29 43 / 6%), 0 6px 20px rgb(29 29 43 / 6%);
  --shadow-lg: 0 24px 70px rgb(27 31 57 / 20%);
  --radius: 14px;
  --radius-lg: 20px;
  --ease-out: cubic-bezier(.23, 1, .32, 1);
  --font: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { margin: 0; min-width: 0; min-height: 100vh; overflow-x: hidden; background: var(--paper); color: var(--ink); font: 16px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { line-height: 1.14; letter-spacing: -.025em; }
button, input, select, textarea { color: inherit; font: inherit; }
button, a { touch-action: manipulation; }
button { cursor: pointer; }
svg { display: block; width: 20px; height: 20px; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 3px; }
.skip-link { position: fixed; z-index: 100; top: -80px; left: 20px; padding: 11px 16px; background: var(--ink); color: #fff; border-radius: 8px; }
.skip-link:focus { top: 16px; }
.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; }

.loading { display: grid; place-items: center; align-content: center; gap: 16px; min-height: 75vh; color: var(--muted); text-align: center; padding: 24px; }
.loading img { animation: breathe 1.8s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(.96); opacity: .72; } }

.brand { display: inline-flex; align-items: center; gap: 10px; min-height: 48px; width: fit-content; color: var(--ink); text-decoration: none; }
.brand img { flex: none; }
.brand > span { display: grid; font-size: 18px; font-weight: 760; letter-spacing: -.5px; line-height: 1.05; }
.brand small { margin-top: 4px; color: var(--muted); font-size: 8px; font-weight: 700; letter-spacing: 1.4px; }
.icon-button { display: inline-grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 11px; background: transparent; color: var(--muted); transition: color 150ms ease, background 150ms ease, transform 120ms var(--ease-out); }
.icon-button:hover { color: var(--ink); background: #f0f1f6; }
.icon-button:active, .button:active, .student-chip:active { transform: scale(.97); }
.icon-button.danger { color: var(--danger); }

/* Page head as in Umfrage: compact heading left, the page's controls right. */
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; min-height: 52px; margin-bottom: 24px; }
.eyebrow { color: var(--brand-dark); font-size: 12px; font-weight: 750; letter-spacing: 2px; line-height: 1.5; text-transform: uppercase; }
.page-heading h1 { font-size: 36px; font-weight: 800; letter-spacing: -0.02em; }
select, input, textarea { width: 100%; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; transition: border-color 160ms ease, box-shadow 160ms ease; }
select, input { min-height: 44px; padding: 10px 12px; }
textarea { min-height: 108px; padding: 12px; line-height: 1.55; resize: vertical; }
select:focus, input:focus, textarea:focus { outline: 0; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }

.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border: 1.5px solid transparent; border-radius: 999px; font-weight: 600; white-space: nowrap; text-decoration: none; transition: color 150ms ease, background 150ms ease, border-color 150ms ease, transform 120ms var(--ease-out); }
.button.primary { color: #fff; background: var(--brand); }
.button.primary:hover:not(:disabled) { background: var(--brand-dark); }
.button.danger { color: #fff; background: var(--danger); }
.button.danger:hover:not(:disabled) { background: #bf3139; }
.button.secondary { color: var(--ink); border-color: var(--line); background: #fff; }
.button.secondary:hover:not(:disabled) { border-color: #cfcfdd; background: #fafafe; }
.button.quiet { color: var(--muted); background: transparent; }
.button.quiet:hover { color: var(--ink); background: #f1f2f7; }
.button.big { min-height: 56px; padding: 0 28px; font-size: 18px; }
.button.small { min-height: 44px; padding-inline: 12px; font-size: 14px; }
.button.full { width: 100%; }
.button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.heading-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.text-button { display: inline-flex; align-items: center; gap: 7px; min-height: 44px; padding: 0 8px; border: 0; background: transparent; color: var(--brand-dark); font-weight: 650; font-size: 14px; }

.card, .results-card { border-radius: var(--radius-lg); background: var(--card); box-shadow: var(--shadow); }
.section-heading, .results-heading { display: flex; align-items: start; justify-content: space-between; gap: 18px; }
.section-heading > div, .results-heading > div { display: flex; align-items: start; gap: 13px; }
.section-heading h2, .results-heading h2 { font-size: 21px; }
.section-heading p:not(.step), .results-heading p:not(.step) { margin-top: 5px; color: var(--muted); font-size: 14px; }
.divider { height: 1px; margin: 28px 0; background: var(--line); }
.segmented button.active { color: var(--ink); background: #fff; box-shadow: 0 1px 5px rgb(21 24 44 / 10%); }


@media (prefers-reduced-motion: no-preference) {
  .group-grid.is-staged .group-card { --group-delay: 0ms; opacity: 0; transform: translateY(18px) scale(.975); }
  .group-grid.is-staged .group-card li { --name-delay: 0ms; opacity: 0; transform: translateY(9px); }
  .group-grid.is-staged.reveal .group-card { animation: group-reveal 420ms var(--ease-out) forwards; animation-delay: var(--group-delay); }
  .group-grid.is-staged.reveal .group-card li { animation: name-reveal 300ms var(--ease-out) forwards; animation-delay: calc(var(--group-delay) + var(--name-delay) + 130ms); }
  @keyframes group-reveal { to { opacity: 1; transform: translateY(0) scale(1); } }
  @keyframes name-reveal { to { opacity: 1; transform: translateY(0); } }
  .pick-list.is-staged .pick-card { opacity: 0; transform: translateY(18px) scale(.975); }
  .pick-list.is-staged.reveal .pick-card { animation: group-reveal 420ms var(--ease-out) forwards; animation-delay: var(--pick-delay, 0ms); }
}
/* Random pick: one large card per drawn name. */

.saved-section, .class-section { margin-top: 58px; }
.saved-heading, .section-title { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.saved-heading h2, .section-title h2 { font-size: 24px; }
.saved-heading > span, .section-title > span, .section-title > div:last-child > span { display: inline-grid; place-items: center; min-width: 30px; height: 30px; padding: 0 9px; border-radius: 999px; background: #eceef4; color: var(--muted); font-size: 14px; font-weight: 700; }

.class-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.class-card { display: flex; flex-direction: column; gap: 14px; padding: 20px; border-radius: var(--radius-lg); background: #fff; box-shadow: var(--shadow); }
/* Full class name (3AK, 4AHITN …) in a tag coloured by grade (first digit), so the 1st to 5th years are told apart
   at a glance; names without a grade stay grey. School year top right. */
.class-card-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.class-name-tag { min-width: 0; padding: 8px 14px; border-radius: 12px; color: #4b5064; background: #eef0f5; font-size: 22px; font-weight: 800; line-height: 1.2; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.class-name-tag.grade-1 { color: #1c64b4; background: #e4effc; }
.class-name-tag.grade-2 { color: #0d7358; background: #e0f4ec; }
.class-name-tag.grade-3 { color: #8f5a00; background: #fcefd2; }
.class-name-tag.grade-4 { color: #b02c5a; background: #fce6ee; }
.class-name-tag.grade-5 { color: #5b3cc4; background: #ede8fd; }
.year-chip { flex: none; color: var(--muted); font-size: 14px; font-weight: 600; }
.class-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; background: #f0f1f6; color: var(--muted); font-size: 13px; font-weight: 600; white-space: nowrap; }
/* Tools at the bottom edge, as on the survey cards. */
.class-card-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; padding-top: 4px; }
.class-count { color: var(--muted); font-size: 15px; }
.class-count strong { color: var(--ink); }
.card-tools { display: flex; gap: 6px; }
.button.icon-only { position: relative; width: 44px; padding: 0; }
/* Instant tooltip above icon-only buttons (as in Umfrage); the last one aligns right so the card edge does not clip it. */
.button[data-tip]::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translate(-50%, 4px); padding: 5px 10px; border-radius: 8px; background: var(--ink); color: #fff; font-size: 13px; font-weight: 600; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .12s, transform .12s; }
.button[data-tip]:hover::after, .button[data-tip]:focus-visible::after { opacity: 1; transform: translate(-50%, 0); }
/* Small arrow under the tooltip, always centred on the button it belongs to. */
.button[data-tip]::before { content: ''; position: absolute; bottom: calc(100% + 2px); left: 50%; transform: translate(-50%, 4px); border: 6px solid transparent; border-bottom: 0; border-top-color: var(--ink); opacity: 0; pointer-events: none; transition: opacity .12s, transform .12s; }
.button[data-tip]:hover::before, .button[data-tip]:focus-visible::before { opacity: 1; transform: translate(-50%, 0); }
.card-tools > .button[data-tip]:last-child::after { left: auto; right: 0; transform: translate(0, 4px); }
.card-tools > .button[data-tip]:last-child:hover::after, .card-tools > .button[data-tip]:last-child:focus-visible::after { transform: none; }
.class-card.archived { opacity: .65; }
.learning-section { padding-top: 45px; border-top: 1px solid var(--line); }
.section-title > div:first-child > p { margin-top: 6px; color: var(--muted); font-size: 14px; }
.section-title > div:last-child { display: flex; align-items: center; gap: 10px; }
.archived-section { padding-top: 42px; border-top: 1px solid var(--line); }
.empty-line { padding: 28px; border: 1px dashed #ced1df; border-radius: 15px; color: var(--muted); text-align: center; }

.toast { position: fixed; z-index: 80; left: 50%; bottom: 24px; max-width: calc(100vw - 32px); padding: 12px 20px; border-radius: 999px; background: var(--ink); color: #fff; font-weight: 650; box-shadow: var(--shadow-lg); transform: translate(-50%, 140%); opacity: 0; pointer-events: none; transition: transform 220ms var(--ease-out), opacity 180ms ease; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.error { border-radius: 14px; background: var(--danger); }

dialog { width: min(620px, calc(100vw - 32px)); max-height: min(88vh, 900px); padding: 0; border: 0; border-radius: var(--radius-lg); color: var(--ink); background: #fff; box-shadow: var(--shadow-lg); }
dialog.wide { width: min(850px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(29 29 43 / 45%); }
dialog form { display: grid; gap: 16px; padding: 28px; }
dialog header { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
dialog header > div { min-width: 0; }
dialog h2 { font-size: 22px; }
dialog label { display: grid; gap: 7px; }
dialog label small { color: var(--muted); font-weight: 500; }
.dialog-intro { color: var(--muted); line-height: 1.7; }
label > span { font-size: 14px; font-weight: 600; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.checkbox { display: flex; grid-auto-flow: column; grid-template-columns: auto 1fr; align-items: center; justify-content: start; gap: 10px; min-height: 44px; padding: 0 12px; border-radius: 11px; background: #f6f7fa; }
.checkbox input, .member-choice input, .archive-toggle input { width: 18px; height: 18px; accent-color: var(--brand); }
dialog footer { display: flex; justify-content: flex-end; gap: 9px; margin-top: 5px; }
.form-error { min-height: 1.5em; color: var(--danger); font-size: 14px; }
.rollover-list { display: grid; gap: 9px; max-height: 48vh; overflow: auto; padding-right: 3px; }
.rollover-row { display: grid; grid-template-columns: .7fr 1.2fr auto; align-items: end; gap: 10px; padding: 13px; border: 1px solid var(--line); border-radius: 13px; }
.rollover-row strong { min-height: 46px; display: flex; align-items: center; }
.archive-toggle { display: flex; flex-direction: row; align-items: center; gap: 7px; min-height: 46px; }
.member-picker { border: 1px solid var(--line); border-radius: 15px; overflow: hidden; }
.member-picker-head { padding: 15px 17px; background: #f6f7fb; }
.member-picker-head h3 { font-size: 16px; }
.member-picker-head p { color: var(--muted); font-size: 14px; }
.member-class { margin: 0; padding: 16px; border: 0; border-top: 1px solid var(--line); }
.member-class legend { padding: 0; font-weight: 700; }
.member-class legend span { color: var(--muted); font-size: 13px; }
.member-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; margin-top: 11px; }
.member-choice { display: flex; flex-direction: row; align-items: center; gap: 8px; min-height: 40px; padding: 7px 9px; border-radius: 9px; background: #f8f8fb; font-size: 14px; }

.auth-page { min-height: 100vh; background: linear-gradient(145deg, #f1f4ff, #f3faf7); }
.auth-story { display: flex; flex-direction: column; justify-content: space-between; min-height: 520px; padding: 34px max(32px, 6vw) 165px; text-align: center; }
.auth-story .brand { align-self: flex-start; text-align: left; }
.auth-story > div { width: min(760px, 100%); margin: 68px auto 0; }
.auth-story h1 { margin-top: 20px; font-size: clamp(48px, 6vw, 76px); font-weight: 730; letter-spacing: -4px; }
.auth-story h1 em { color: var(--brand); font-style: normal; }
.auth-story > div > p:last-child { max-width: 560px; margin: 24px auto 0; color: var(--muted); font-size: 18px; line-height: 1.7; }
.auth-foot { align-self: center; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 1.8px; }
.auth-form { display: grid; place-items: center; width: min(520px, calc(100% - 40px)); margin: -125px auto 0; padding: 0 0 72px; }
.auth-form > div { width: 100%; padding: 38px; border: 1px solid var(--line); border-radius: 24px; background: #fff; box-shadow: var(--shadow-lg); }
.auth-form h2 { margin-top: 10px; font-size: 36px; }
.auth-form > div > p:not(.eyebrow) { margin-top: 13px; color: var(--muted); }
.auth-form form { display: grid; gap: 16px; margin-top: 30px; }
.auth-form label { display: grid; gap: 7px; font-weight: 650; }

@media (hover: hover) and (pointer: fine) {
  .class-card { transition: box-shadow 180ms ease; }
  .class-card:hover { box-shadow: 0 2px 4px rgb(29 29 43 / 6%), 0 16px 36px rgb(29 29 43 / 10%); }
}

@media (max-width: 980px) {
  .class-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .auth-story { min-height: 500px; padding: 34px 36px 155px; }
  .auth-story h1 { font-size: 56px; letter-spacing: -2.5px; }
}

@media (max-width: 640px) {
  .brand > span { font-size: 16px; }
  .brand small { display: none; }
  .page-heading h1 { font-size: 28px; }
  .page-heading .class-select { width: 100%; }
  .heading-actions { justify-content: stretch; }
  .heading-actions .button { flex: 1; }
  .saved-grid, .class-grid { grid-template-columns: 1fr; }
  .section-title { align-items: start; }
  .section-title > div:last-child { align-items: flex-end; flex-direction: column; }
  .form-row { grid-template-columns: 1fr; }
  dialog { width: calc(100% - 20px); overflow-x: hidden; }
  dialog form { padding: 20px 16px; }
  dialog h2 { overflow-wrap: anywhere; }
  dialog footer { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  dialog footer .button { min-width: 0; padding-inline: 10px; white-space: normal; }
  .rollover-row { grid-template-columns: 1fr; align-items: start; }
  .member-grid { grid-template-columns: 1fr 1fr; }
  .auth-story { min-height: 450px; padding: 24px 22px 145px; }
  .auth-story > div { margin-top: 48px; }
  .auth-story h1 { font-size: 42px; letter-spacing: -1.8px; }
  .auth-story > div > p:last-child { font-size: 16px; }
  .auth-form { width: calc(100% - 28px); margin-top: -110px; padding-bottom: 42px; }
  .auth-form > div { padding: 28px 22px; border-radius: 20px; }
}

@media (max-width: 380px) {
  .member-grid { grid-template-columns: 1fr; }
  dialog footer { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media print {
  .topbar, .setup-card, .saved-section, .results-heading .button, .save-groups { display: none !important; }
  .page.mentio-page { width: 100%; padding: 0; }
}
