/*
  SwimNotes visual system
  - One accent: pool blue. Cool neutrals only. Green/red are reserved for the Positive/Constructive badges and validation.
  - Shape rule: containers 12px, controls 8px, chips and pills fully round.
  - Z-index scale: header 20, toast 40.
  - Type: DM Sans for the UI; DM Serif Display only for the wordmark and the page headline.
  - Light and dark themes come from the same tokens (prefers-color-scheme).
*/

@font-face {
  font-family: "DM Sans";
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  src: url("fonts/dm-sans-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "DM Sans";
  font-weight: 500;
  font-style: normal;
  font-display: swap;
  src: url("fonts/dm-sans-latin-500-normal.woff2") format("woff2");
}
@font-face {
  font-family: "DM Sans";
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  src: url("fonts/dm-sans-latin-600-normal.woff2") format("woff2");
}
@font-face {
  font-family: "DM Serif Display";
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  src: url("fonts/dm-serif-display-latin-400-normal.woff2") format("woff2");
}

:root {
  color-scheme: light dark;

  --font-ui: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "DM Serif Display", Georgia, serif;

  --bg: #f3f6f9;
  --surface: #ffffff;
  --surface-sunken: #eaf0f5;
  --ink: #0e2233;
  --ink-2: #3a5266;
  --ink-3: #52697c;
  --line: #d3dee7;
  --line-strong: #b4c4d1;
  --field-border: #758c9e;

  --accent: #0a4f7a;
  --accent-hover: #083f61;
  --accent-ink: #ffffff;
  --accent-soft: #e0eef8;
  --accent-text: #0a4f7a;
  --focus: #1a7aad;

  --pos: #0b6238;
  --pos-bg: #dff2e7;
  --neg: #8b1a1a;
  --neg-bg: #fbe8e8;
  --warn: #6b4f00;
  --warn-bg: #fff3cf;

  --band: #0a4f7a;
  --band-ink: #ffffff;
  --band-ink-2: #cfe3f1;

  --toast-bg: #0e2233;
  --toast-ink: #ffffff;
  --toast-action: #9fd4f3;

  --shadow: 0 1px 2px rgba(10, 50, 80, 0.06), 0 6px 20px rgba(10, 50, 80, 0.06);

  --r-container: 12px;
  --r-control: 8px;
  --r-pill: 999px;

  --header-h: 64px;
  --content-max: 1112px;
  --z-header: 20;
  --z-toast: 40;

  --chevron: url("data:image/svg+xml,%3Csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20viewBox=%270%200%20256%20256%27%20fill=%27%233a5266%27%3E%3Cpath%20d=%22M213.66,101.66l-80,80a8,8,0,0,1-11.32,0l-80-80A8,8,0,0,1,53.66,90.34L128,164.69l74.34-74.35a8,8,0,0,1,11.32,11.32Z%22/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a131b;
    --surface: #101c27;
    --surface-sunken: #0b1620;
    --ink: #e6eef5;
    --ink-2: #b4c5d3;
    --ink-3: #93a8b9;
    --line: #223444;
    --line-strong: #31485b;
    --field-border: #6b8499;

    --accent: #1a7aad;
    --accent-hover: #146592;
    --accent-ink: #ffffff;
    --accent-soft: #15324a;
    --accent-text: #8fd0f5;
    --focus: #7cc7ef;

    --pos: #7fdcab;
    --pos-bg: #11321f;
    --neg: #f5a3a3;
    --neg-bg: #3b1818;
    --warn: #f2d27a;
    --warn-bg: #3a2f0d;

    --band: #0c3047;
    --band-ink: #ffffff;
    --band-ink-2: #bcd3e3;

    --toast-bg: #e6eef5;
    --toast-ink: #0e2233;
    --toast-action: #0a4f7a;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.3);

    --chevron: url("data:image/svg+xml,%3Csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20viewBox=%270%200%20256%20256%27%20fill=%27%23b4c5d3%27%3E%3Cpath%20d=%22M213.66,101.66l-80,80a8,8,0,0,1-11.32,0l-80-80A8,8,0,0,1,53.66,90.34L128,164.69l74.34-74.35a8,8,0,0,1,11.32,11.32Z%22/%3E%3C/svg%3E");
  }
}

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

html {
  scroll-padding-top: 88px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: rgba(26, 122, 173, 0.18);
}

body {
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.5;
  background: var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

[hidden] { display: none !important; }

h1, h2, h3, h4 { text-wrap: balance; }
p { text-wrap: pretty; }

button, select, input, textarea { font: inherit; color: inherit; touch-action: manipulation; }
button { cursor: pointer; }

.icon {
  width: 1.25em;
  height: 1.25em;
  fill: currentColor;
  flex: none;
}

.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

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

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -64px;
  z-index: var(--z-toast);
  background: var(--surface);
  color: var(--ink);
  padding: 10px 16px;
  border-radius: var(--r-control);
  box-shadow: var(--shadow);
  font-weight: 600;
}
.skip-link:focus { top: 12px; }

/* HEADER + HERO */
.site-header,
.hero {
  background: var(--band);
  color: var(--band-ink);
  padding-inline: max(24px, calc((100% - var(--content-max)) / 2));
}

.site-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--band-ink);
  text-decoration: none;
  border-radius: var(--r-control);
}
.logo:focus-visible { outline-color: #ffffff; }

.logo-mark {
  width: 36px;
  height: 36px;
  border-radius: var(--r-control);
  background: rgba(255, 255, 255, 0.14);
  display: grid;
  place-items: center;
  font-size: 1.25rem;
}

.logo-word {
  font-family: var(--font-display);
  font-size: 1.5rem;
  letter-spacing: -0.01em;
  line-height: 1;
}

.header-tag {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--band-ink-2);
  white-space: nowrap;
}

.hero { padding-block: 16px 48px; }

.hero h1 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(2rem, 1.3rem + 2.4vw, 2.875rem);
  line-height: 1.1;
  letter-spacing: -0.015em;
  max-width: 16em;
  margin-bottom: 12px;
}

.hero p {
  color: var(--band-ink-2);
  max-width: 52ch;
  font-size: 1.0625rem;
  line-height: 1.55;
}

/* LAYOUT */
.app {
  width: 100%;
  max-width: calc(var(--content-max) + 48px);
  margin-inline: auto;
  padding: 32px 24px 72px;
  flex: 1;
}

.layout {
  display: grid;
  gap: 24px;
  align-items: start;
}

@media (min-width: 1024px) {
  .layout { grid-template-columns: 320px minmax(0, 1fr); gap: 32px; }
  .level-panel {
    position: sticky;
    top: calc(var(--header-h) + 16px);
    max-height: calc(100dvh - var(--header-h) - 32px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-container);
  box-shadow: var(--shadow);
}

.level-panel { padding: 20px; }

.panel-title,
.section-title {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  line-height: 1.3;
}

.panel-title { margin-bottom: 16px; }

.level-groups { display: grid; gap: 16px; }

.level-group-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 8px;
}

.level-pills { display: flex; flex-wrap: wrap; gap: 8px; }

.level-pill {
  min-height: 36px;
  padding: 0 14px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 0.9375rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}
.level-pill:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }
.level-pill:active { transform: scale(0.97); }
.level-pill[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.level-info-bar {
  display: none;
  margin-top: 20px;
  padding: 14px 16px;
  background: var(--accent-soft);
  border-radius: var(--r-control);
}
.level-info-bar.visible { display: block; }
.level-info-bar h3 { font-size: 1rem; font-weight: 600; margin-bottom: 4px; color: var(--ink); }
.level-info-bar p { font-size: 0.875rem; line-height: 1.55; color: var(--ink-2); }

/* WORKSPACE */
.workspace { min-width: 0; }

.workspace-head { margin-bottom: 20px; }

.workspace-head-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.rail-hint { margin: -8px 0 16px; }

/* CLASS TABS (shown once there is more than one class) */
.class-bar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; margin-bottom: 20px; }

.class-tabs { display: flex; flex-wrap: wrap; gap: 8px; min-width: 0; }

.class-tab {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  max-width: 100%;
  padding: 6px 8px 6px 14px;
  text-align: left;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-control);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 0.9375rem;
  font-weight: 500;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}
.class-tab:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }
.class-tab:active { transform: translateY(1px); }
.class-tab[aria-current="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.class-tab > span:first-child { min-width: 0; overflow-wrap: anywhere; }

.class-tab-count {
  flex: none;
  min-width: 24px;
  padding: 0 7px;
  border-radius: var(--r-pill);
  background: var(--surface-sunken);
  color: var(--ink-2);
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 24px;
  text-align: center;
}
.class-tab[aria-current="true"] .class-tab-count { background: var(--surface); color: var(--ink); }

.class-meta { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.class-meta .field-group { flex: 1 1 260px; max-width: 420px; }

.method-note {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
  font-size: 0.875rem;
  color: var(--ink-2);
}
.method-note strong { font-weight: 600; }
.method-note .is-pos { color: var(--pos); }
.method-note .is-neg { color: var(--neg); }

.no-level-msg {
  display: none;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding: 12px 16px;
  border-radius: var(--r-control);
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 0.9375rem;
  font-weight: 500;
}
.no-level-msg.visible { display: flex; }

#students-container { display: grid; gap: 20px; }

.empty-state {
  padding: 28px 20px;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--r-container);
  color: var(--ink-2);
  text-align: center;
}
.empty-state[hidden] { display: none; }

/* STUDENT CARD */
.student-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-container);
  box-shadow: var(--shadow);
}

.student-card.is-leaving { opacity: 0; transform: translateY(-6px); transition: opacity 0.15s, transform 0.15s; }

.student-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 12px 14px 20px;
  border-bottom: 1px solid var(--line);
}

.student-number { font-size: 0.8125rem; font-weight: 500; color: var(--ink-3); }

.student-name-display {
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.student-name-display.empty { color: var(--ink-3); font-weight: 400; }

.remove-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--r-control);
  background: transparent;
  color: var(--ink-3);
  font-size: 1.125rem;
  transition: background-color 0.15s, color 0.15s;
}
.remove-btn:hover { background: var(--neg-bg); color: var(--neg); }

.student-card-body { padding: 20px; display: grid; gap: 20px; }

.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; }
.field-row.single { grid-template-columns: minmax(0, 1fr); }
.field-row.name-row { grid-template-columns: minmax(0, 1fr) auto; }

.field-group { display: grid; gap: 8px; align-content: start; min-width: 0; }

.field-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.field-label { font-size: 0.875rem; font-weight: 600; color: var(--ink); }

.field-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: var(--r-pill);
}
.badge-strength { background: var(--pos-bg); color: var(--pos); }
.badge-weakness { background: var(--neg-bg); color: var(--neg); }
.badge-optional { background: var(--surface-sunken); color: var(--ink-2); }

input[type="text"],
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--field-border);
  border-radius: var(--r-control);
  background: var(--surface);
  color: var(--ink);
  font-size: 1rem;
  transition: border-color 0.15s, background-color 0.15s;
  appearance: none;
}

input::placeholder,
textarea::placeholder { color: var(--ink-3); opacity: 1; }

input[type="text"]:focus-visible,
select:focus-visible,
textarea:focus-visible { border-color: var(--focus); outline-offset: 0; }

input[aria-invalid="true"],
select[aria-invalid="true"] { border-color: var(--neg); }

select {
  padding-right: 40px;
  background-image: var(--chevron);
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.segmented {
  display: flex;
  min-height: 44px;
  border: 1px solid var(--field-border);
  border-radius: var(--r-control);
  background: var(--surface);
  overflow: hidden;
}
.seg-btn {
  padding: 0 13px;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font-size: 0.9375rem;
  font-weight: 500;
  transition: background-color 0.15s, color 0.15s;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--field-border); }
.seg-btn:hover { background: var(--accent-soft); color: var(--accent-text); }
.seg-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.seg-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.part-note { min-height: 38px; font-size: 0.9375rem; background: var(--surface-sunken); }

textarea {
  min-height: 88px;
  padding: 10px 12px;
  line-height: 1.5;
  resize: vertical;
}

.hint { font-size: 0.8125rem; color: var(--ink-3); }

.card-divider { height: 1px; background: var(--line); margin-inline: -20px; }

.form-error {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--r-control);
  background: var(--neg-bg);
  color: var(--neg);
  font-size: 0.9375rem;
  font-weight: 500;
}
.form-error[hidden] { display: none; }

/* BUTTONS */
.generate-btn,
.generate-all-btn,
.add-student-btn,
.copy-btn,
.copy-all-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--r-control);
  font-weight: 600;
  line-height: 1.2;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}

.generate-btn,
.generate-all-btn {
  width: 100%;
  min-height: 48px;
  padding: 0 20px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1rem;
}
.generate-btn:hover:not(:disabled),
.generate-all-btn:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.generate-btn:active:not(:disabled),
.generate-all-btn:active:not(:disabled) { transform: translateY(1px) scale(0.99); }
.generate-btn:disabled,
.generate-all-btn:disabled { opacity: 0.65; cursor: progress; }

.generate-all-btn { min-height: 52px; }

.add-student-btn {
  width: 100%;
  min-height: 52px;
  margin-top: 20px;
  padding: 0 20px;
  border: 1.5px dashed var(--line-strong);
  background: transparent;
  color: var(--accent-text);
  font-size: 1rem;
}
.add-student-btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.add-student-btn:active { transform: translateY(1px); }

.copy-btn,
.copy-all-btn {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 0.875rem;
}
.copy-btn:hover,
.copy-all-btn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }
.copy-btn:active,
.copy-all-btn:active { transform: translateY(1px); }
.copy-btn.copied,
.copy-all-btn.copied { background: var(--pos-bg); border-color: var(--pos); color: var(--pos); }

/* RESULT */
.result-area { display: none; }
.result-area.visible { display: block; }

.result-box {
  background: var(--surface-sunken);
  border-radius: var(--r-control);
  padding: 12px 16px 16px;
}

.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.result-label { font-size: 0.875rem; font-weight: 600; color: var(--ink-2); }

.result-text { line-height: 1.65; overflow-wrap: anywhere; }

/* GENERATE ALL + COMBINED COMMENTS */
.generate-all-wrap {
  display: none;
  margin-top: 32px;
  padding-top: 32px;
  border-top: 1px solid var(--line);
  gap: 12px;
}
.generate-all-wrap.visible { display: grid; }

.all-comments-wrap { display: none; margin-top: 32px; }
.all-comments-wrap.visible { display: block; }

.all-comments-wrap,
.result-area { scroll-margin-top: 88px; }

.all-comments-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.all-comments-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.all-comments-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-container);
  box-shadow: var(--shadow);
  padding: 4px 24px;
}

.comment-group + .comment-group { border-top: 2px solid var(--line); }

.comment-group-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 20px;
}

.comment-group-title { font-size: 1.0625rem; font-weight: 600; color: var(--accent-text); overflow-wrap: anywhere; }

.group-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.group-actions .copy-all-btn { min-height: 36px; padding: 0 12px; }

.all-comment-entry { padding: 20px 0; }
.all-comment-entry + .all-comment-entry { border-top: 1px solid var(--line); }

.all-comment-name { font-size: 1rem; font-weight: 600; margin-bottom: 6px; overflow-wrap: anywhere; }

.all-comment-text { line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }

/* TOAST */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: calc(100vw - 32px);
  padding: 12px 16px;
  border-radius: var(--r-control);
  background: var(--toast-bg);
  color: var(--toast-ink);
  font-size: 0.9375rem;
  box-shadow: var(--shadow);
}
.toast[hidden] { display: none; }

.toast-action {
  border: 0;
  background: transparent;
  color: var(--toast-action);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 6px 4px;
  border-radius: var(--r-control);
}

/* FOOTER */
.site-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 24px;
  border-top: 1px solid var(--line);
  padding: 24px max(24px, calc((100% - var(--content-max)) / 2));
  font-size: 0.875rem;
  color: var(--ink-3);
}

.footer-credit { margin-left: auto; }

/* MOTION (only when the visitor has not asked for less) */
@media (prefers-reduced-motion: no-preference) {
  .student-card.is-new { animation: enter 0.24s cubic-bezier(0.16, 1, 0.3, 1); }
  .result-area.visible .result-box { animation: enter 0.2s cubic-bezier(0.16, 1, 0.3, 1); }
  .toast:not([hidden]) { animation: toast-in 0.2s cubic-bezier(0.16, 1, 0.3, 1); }
  .generate-btn.is-busy,
  .generate-all-btn.is-busy { animation: pulse 1.1s ease-in-out infinite; }
}

@keyframes enter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes pulse {
  0%, 100% { opacity: 0.65; }
  50% { opacity: 0.9; }
}

/* SMALL SCREENS */
@media (max-width: 639px) {
  .header-tag { display: none; }
  .hero { padding-bottom: 36px; }
  .app { padding: 24px 16px 56px; }
  .student-card-body { padding: 16px; }
  .card-divider { margin-inline: -16px; }
  .all-comments-box { padding: 4px 16px; }
  .all-comments-actions { width: 100%; }
  .all-comments-actions > button { flex: 1; }
}
