/* Atom Bowl design system: tokens, base, site chrome and shared components.
   Every page links this first, then its own page stylesheet for layout. */

:root {
  --ink: #0e1626;
  --plate: #16213a;
  --plate-2: #1c2a47;
  --rule: #26375a;
  --rule-strong: #34497a;
  --text: #e9eef8;
  --muted: #93a1bc;
  --signal: #5b83ff;
  --signal-ink: #ffffff;
  --signal-strong: #3a63e6;
  --correct: #39d98a;
  --buzz: #ff6b6b;
  --amber: #f5b544;
  --team-a: var(--signal);
  --team-b: var(--buzz);
  --team-c: var(--correct);
  --team-d: var(--amber);

  --signal-soft: color-mix(in srgb, var(--signal) 16%, transparent);
  --correct-soft: color-mix(in srgb, var(--correct) 16%, transparent);
  --buzz-soft: color-mix(in srgb, var(--buzz) 16%, transparent);

  --font-ui: "Schibsted Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Big Shoulders Display", "Schibsted Grotesk", system-ui, sans-serif;
  --font-serif: "Source Serif 4", "Iowan Old Style", Georgia, serif;

  --r-control: 10px;
  --r-panel: 14px;
  --shadow-pop: 0 18px 48px rgb(4 9 20 / 0.45);
  --bar-h: 64px;
  --tab-h: 64px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --fast: 120ms;

  color-scheme: dark;
}

:root.theme-light {
  --ink: #f2f5fb;
  --plate: #ffffff;
  --plate-2: #eef2f9;
  --rule: #d5ddec;
  --rule-strong: #b9c5dc;
  --text: #0e1626;
  --muted: #55617a;
  --correct: #0b7a4b;
  --buzz: #c8363a;
  --amber: #996100;
  --signal: #3a63e6;
  --shadow-pop: 0 16px 40px rgb(14 22 38 / 0.14);
  color-scheme: light;
}

:root.high-contrast {
  --rule: #4a6196;
  --muted: #c3cde0;
}

:root.theme-light.high-contrast {
  --rule: #8a9abb;
  --muted: #2f3a52;
}

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

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

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

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

h1, h2, h3, h4 { margin: 0; line-height: 1.15; font-weight: 700; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0; }

a { color: var(--signal); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }

code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.9em;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--plate-2);
}

::selection { background: color-mix(in srgb, var(--signal) 35%, transparent); }

:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
  border-radius: 4px;
}

.hidden { display: none !important; }

.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;
}

.icon-svg {
  width: 1.15em;
  height: 1.15em;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.no-anim *,
.no-anim *::before,
.no-anim *::after {
  animation: none !important;
  transition: none !important;
  scroll-behavior: auto !important;
}

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

/* ---------- Page frame ---------- */

.main,
.container {
  width: min(1120px, 100% - 32px);
  margin: 0 auto;
  padding: 40px 0 72px;
}

.header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px 24px;
  margin-bottom: 28px;
}

.title,
.display {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.6rem, 5vw, 3.6rem);
  line-height: 0.95;
  letter-spacing: 0.005em;
}

.subtitle {
  margin-top: 10px;
  max-width: 62ch;
  color: var(--muted);
  font-size: 1.05rem;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 14px;
}

.site-footer {
  width: min(1120px, 100% - 32px);
  margin: 0 auto;
  padding: 24px 0 32px;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 0.85rem;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  justify-content: space-between;
}

.site-footer a { color: inherit; }

/* ---------- Site bar (desktop) ---------- */

.site-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--bar-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 max(16px, (100% - 1120px) / 2);
  background: color-mix(in srgb, var(--ink) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--rule);
}

.brand {
  display: inline-flex;
  align-items: center;
  flex: none;
  gap: 10px;
  margin-right: 28px;
  color: var(--text);
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.55rem;
  line-height: 1;
  white-space: nowrap;
}

.brand img { width: 32px; height: 32px; }

.site-links {
  display: flex;
  flex: none;
  align-items: center;
  gap: 4px;
}

.site-link,
.site-more-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--r-control);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 500;
  font-size: 0.95rem;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--fast) var(--ease), background-color var(--fast) var(--ease);
}

.site-link:hover,
.site-more-btn:hover { color: var(--text); background: var(--plate); }
.site-more-btn[data-current] { color: var(--text); background: var(--plate); box-shadow: inset 0 -2px 0 var(--signal); }

.settings-gear {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin-left: 4px;
  border-radius: 999px;
  color: var(--muted);
}
.settings-gear:hover,
.settings-gear[aria-current="page"] { color: var(--text); background: var(--plate); }
.settings-gear .icon-svg { width: 20px; height: 20px; transition: transform 400ms var(--ease); }
.settings-gear:hover .icon-svg,
.settings-gear:focus-visible .icon-svg { transform: rotate(90deg); }

.site-link[aria-current="page"] {
  color: var(--text);
  background: var(--plate);
  box-shadow: inset 0 -2px 0 var(--signal);
}

.site-link .icon-svg,
.site-more-btn .icon-svg { width: 18px; height: 18px; }

.site-spacer { flex: 1; }

.site-more { position: relative; flex: none; margin-left: 10px; }

/* With a mouse, the SI menu opens on hover too. The ::before bridges the gap under the button. */
@media (hover: hover) and (pointer: fine) {
  .site-more:hover > .menu { display: grid; }
  .site-more > .menu::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: -10px;
    height: 10px;
  }
}

.menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 230px;
  padding: 6px;
  border: 1px solid var(--rule);
  border-radius: var(--r-panel);
  background: var(--plate);
  box-shadow: var(--shadow-pop);
  display: none;
  z-index: 60;
}

.menu.open { display: grid; }

.menu a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
}

.menu a:hover,
.menu a:focus-visible { background: var(--plate-2); }
.menu a[aria-current="page"] { background: var(--signal-soft); }
.menu a .icon-svg { color: var(--muted); }

.menu .soon {
  margin-left: auto;
  font-size: 0.78rem;
  color: var(--muted);
}

.account-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  margin-left: 6px;
  padding: 0 14px 0 4px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  white-space: nowrap;
  transition: border-color var(--fast) var(--ease);
}

.account-chip:hover { border-color: var(--rule-strong); }
.account-chip[aria-current="page"] { border-color: var(--signal); }

.avatar-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--plate-2);
  color: var(--muted);
  font-weight: 700;
  font-size: 0.85rem;
}

.avatar-dot img { width: 100%; height: 100%; object-fit: cover; }
.avatar-dot .icon-svg { width: 18px; height: 18px; }

.account-chip .chip-name { max-width: 14ch; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Focus bar (practice engine) ---------- */

.site-bar.focus-bar .site-links,
.site-bar.focus-bar .site-more,
.site-bar.focus-bar .account-chip { display: none; }

/* ---------- Tab bar (mobile) ---------- */

.tab-bar { display: none; }
.sheet-backdrop { display: none; }
body.sheet-open .tutor-fab { display: none; }

@media (max-width: 1280px) {
  .site-link .icon-svg { display: none; }
  .site-link, .site-more-btn { padding: 0 10px; }
}

@media (max-width: 960px) {
  .site-links,
  .site-more,
  .account-chip .chip-name { display: none; }

  .account-chip { padding: 0 4px; border: 0; }

  .site-bar { gap: 4px; }

  body.has-tab-bar { padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); }

  .tab-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 70;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    height: calc(var(--tab-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--plate);
    border-top: 1px solid var(--rule);
  }

  .tab-bar a,
  .tab-bar button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border: 0;
    background: none;
    color: var(--muted);
    font: inherit;
    font-size: 0.72rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
  }

  .tab-bar .icon-svg { width: 22px; height: 22px; }
  .tab-bar [aria-current="page"],
  .tab-bar [aria-expanded="true"] { color: var(--signal); }

  .sheet-backdrop.open {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 65;
    background: rgb(4 9 20 / 0.5);
  }

  .sheet {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 8px);
    top: auto;
    min-width: 0;
    z-index: 68;
  }

  .sheet a { padding: 13px 12px; font-size: 1rem; }
}

@media (min-width: 961px) {
  .sheet { display: none !important; }
}

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

.btn,
.quick-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--rule);
  border-radius: var(--r-control);
  background: var(--plate);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--fast) var(--ease), border-color var(--fast) var(--ease), color var(--fast) var(--ease);
}

.btn:hover,
.quick-btn:hover { border-color: var(--rule-strong); background: var(--plate-2); }

.btn.primary,
.quick-btn-primary {
  background: var(--signal-strong);
  border-color: var(--signal-strong);
  color: var(--signal-ink);
}

.btn.primary:hover,
.quick-btn-primary:hover {
  background: color-mix(in srgb, var(--signal-strong) 86%, #000);
  border-color: color-mix(in srgb, var(--signal-strong) 86%, #000);
}

.btn.ghost,
.btn.quiet {
  background: transparent;
}

.btn.quiet { border-color: transparent; color: var(--muted); }
.btn.quiet:hover { color: var(--text); background: var(--plate); }

.btn.danger { color: var(--buzz); border-color: color-mix(in srgb, var(--buzz) 45%, var(--rule)); background: transparent; }
.btn.danger:hover { background: var(--buzz-soft); border-color: var(--buzz); }

.btn.good { color: var(--correct); border-color: color-mix(in srgb, var(--correct) 45%, var(--rule)); background: transparent; }
.btn.good:hover { background: var(--correct-soft); border-color: var(--correct); }

.btn.mini,
.btn.small { min-height: 34px; padding: 0 12px; font-size: 0.88rem; }
.btn.large { min-height: 52px; padding: 0 22px; font-size: 1.05rem; }

.btn:disabled,
.btn[aria-disabled="true"],
.quick-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn .kbd { margin-left: 4px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid transparent;
  border-radius: var(--r-control);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 1.3rem;
  cursor: pointer;
}

.icon-btn:hover { color: var(--text); background: var(--plate-2); }

.button-row,
.btnrow,
.btn-row,
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

/* ---------- Form controls ---------- */

.label {
  display: block;
  margin: 14px 0 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
}

.input,
.select,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--r-control);
  background: var(--ink);
  color: var(--text);
  font: inherit;
  font-size: 0.97rem;
  transition: border-color var(--fast) var(--ease);
}

textarea { min-height: 96px; resize: vertical; }

.input:hover,
select:hover,
input:hover { border-color: var(--rule-strong); }

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

input::placeholder,
textarea::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }

select,
.select {
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2393a1bc' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 18px;
}

input[type="file"] { padding: 7px; min-height: 0; }
input[type="file"]::file-selector-button {
  margin-right: 12px;
  padding: 6px 12px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--plate-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

input[type="checkbox"],
input[type="radio"] { accent-color: var(--signal); width: 18px; height: 18px; }

input[type="range"] {
  width: 100%;
  accent-color: var(--signal);
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.input-readonly,
input[readonly],
input:disabled { color: var(--muted); background: var(--plate-2); cursor: default; }

/* Switch: button.toggle > .knob (aria-checked / .on) */
.toggle {
  position: relative;
  flex: none;
  width: 44px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  background: var(--plate-2);
  cursor: pointer;
  transition: background-color var(--fast) var(--ease), border-color var(--fast) var(--ease);
}

.toggle .knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform var(--fast) var(--ease), background-color var(--fast) var(--ease);
}

.toggle.on,
.toggle[aria-checked="true"] { background: var(--signal-strong); border-color: var(--signal-strong); }
.toggle.on .knob,
.toggle[aria-checked="true"] .knob { transform: translateX(18px); background: #fff; }

/* ---------- Surfaces ---------- */

.panel,
.card {
  border: 1px solid var(--rule);
  border-radius: var(--r-panel);
  background: var(--plate);
  padding: 22px;
}

.panel > h2,
.card > h2 { margin-bottom: 12px; }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0 4px;
  color: var(--muted);
  font-size: 0.85rem;
}

.divider::before,
.divider::after { content: ""; flex: 1; height: 1px; background: var(--rule); }

/* ---------- Pills, tags, kbd ---------- */

.pill,
.tag,
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--plate-2);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
}

.pill b,
.pill strong { color: var(--text); font-weight: 600; }

.tag.accent { color: var(--signal); border-color: color-mix(in srgb, var(--signal) 40%, var(--rule)); background: var(--signal-soft); }
.tag.good { color: var(--correct); border-color: color-mix(in srgb, var(--correct) 40%, var(--rule)); background: var(--correct-soft); }
.tag.bad { color: var(--buzz); border-color: color-mix(in srgb, var(--buzz) 40%, var(--rule)); background: var(--buzz-soft); }

.kbd {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border: 1px solid var(--rule-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--plate-2);
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}

.btn.primary .kbd { background: transparent; border-color: rgb(255 255 255 / 0.5); color: inherit; }

/* ---------- Tabs ---------- */

.tab-row {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: var(--r-control);
  background: var(--ink);
  border: 1px solid var(--rule);
}

.tab {
  flex: 1;
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.tab:hover { color: var(--text); }
.tab.active { background: var(--plate-2); color: var(--text); }

/* ---------- Messages ---------- */

.error {
  color: var(--buzz);
  font-size: 0.92rem;
  font-weight: 500;
}

.error:empty { display: none; }

.status-note { margin-top: 6px; color: var(--muted); font-size: 0.85rem; }
.status-note.good { color: var(--correct); }
.status-note.bad { color: var(--buzz); }

.notice {
  padding: 12px 14px;
  border: 1px solid var(--rule);
  border-left: 3px solid var(--signal);
  border-radius: var(--r-control);
  background: var(--plate);
  color: var(--text);
  font-size: 0.93rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 90;
  transform: translate(-50%, 12px);
  padding: 10px 16px;
  border: 1px solid var(--rule);
  border-radius: var(--r-control);
  background: var(--plate);
  box-shadow: var(--shadow-pop);
  color: var(--text);
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--fast) var(--ease), transform var(--fast) var(--ease);
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 960px) {
  .toast { bottom: calc(var(--tab-h) + 16px); }
}

/* ---------- Modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgb(4 9 20 / 0.6);
  overflow-y: auto;
}

.modal-card {
  width: min(560px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 24px;
  border: 1px solid var(--rule);
  border-radius: var(--r-panel);
  background: var(--plate);
  box-shadow: var(--shadow-pop);
}

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

.modal-header h2 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 2rem;
  line-height: 1;
}

/* ---------- Question text ---------- */

.q-serif {
  font-family: var(--font-serif);
  font-optical-sizing: auto;
  font-size: 1.22rem;
  line-height: 1.6;
  font-variant-numeric: lining-nums;
}

/* ---------- Scoreboard numerals ---------- */

.numerals {
  font-family: var(--font-display);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

/* ---------- Tutor (floating button and chat panel) ---------- */

.tutor-fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 75;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 48px;
  padding: 0 18px 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--signal-strong);
  color: var(--signal-ink);
  box-shadow: var(--shadow-pop);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--fast) var(--ease), background var(--fast) var(--ease);
}

.tutor-fab:hover { transform: translateY(-1px); }
.tutor-fab .icon-svg { width: 20px; height: 20px; }
.tutor-fab[aria-expanded="true"] { background: var(--plate-2); color: var(--text); box-shadow: none; outline: 1px solid var(--rule); }

.tutor-panel {
  position: fixed;
  right: 20px;
  bottom: 80px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  width: min(400px, calc(100vw - 32px));
  height: min(600px, calc(100vh - var(--bar-h) - 112px));
  border: 1px solid var(--rule);
  border-radius: var(--r-panel);
  background: var(--plate);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
}

.tutor-panel[hidden] { display: none; }

.tutor-panel.embedded {
  position: static;
  width: 100%;
  height: min(680px, calc(100vh - 260px));
  min-height: 440px;
  box-shadow: none;
}

.tutor-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 12px 16px;
  border-bottom: 1px solid var(--rule);
}

.tutor-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--r-control);
  background: var(--signal-soft);
  color: var(--signal);
}

.tutor-mark .icon-svg { width: 18px; height: 18px; }
.tutor-title { flex: 1; min-width: 0; }
.tutor-title h2 { font-size: 1.05rem; }
.tutor-credits { color: var(--muted); font-size: 0.8rem; }
.tutor-credits:empty { display: none; }

.tutor-context {
  display: grid;
  gap: 6px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--rule);
  background: var(--plate-2);
}

.tutor-context[hidden] { display: none; }
.tutor-context-label { color: var(--muted); font-size: 0.8rem; font-weight: 500; }

.tutor-q {
  font-size: 1rem;
  line-height: 1.45;
  white-space: pre-line;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tutor-answers { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: 0; font-size: 0.85rem; }
.tutor-answers div { display: flex; gap: 6px; }
.tutor-answers dt { color: var(--muted); }
.tutor-answers dd { margin: 0; font-weight: 600; }

.tutor-log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.tutor-log[hidden] { display: none; }

.tutor-msg {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 0.95rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.tutor-msg.user {
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  background: var(--signal-strong);
  color: var(--signal-ink);
}

.tutor-msg.bot {
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  background: var(--plate-2);
}

.tutor-msg.notice a {
  color: inherit;
  text-decoration: underline;
  overflow-wrap: anywhere;
}

.tutor-msg p + p,
.tutor-msg p + ul,
.tutor-msg p + ol,
.tutor-msg ul + p,
.tutor-msg ol + p { margin-top: 8px; }
.tutor-msg ul,
.tutor-msg ol { margin: 0; padding-left: 20px; }
.tutor-msg strong { font-weight: 700; }
.tutor-msg .katex { font-size: 1.05em; }
.tutor-msg .katex-display { margin: 8px 0; overflow-x: auto; overflow-y: hidden; }

.tutor-msg.typing { display: flex; gap: 4px; padding: 14px; }
.tutor-msg.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: tutor-dot 1s infinite var(--ease);
}
.tutor-msg.typing span:nth-child(2) { animation-delay: 0.15s; }
.tutor-msg.typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes tutor-dot {
  0%, 60%, 100% { opacity: 0.3; transform: none; }
  30% { opacity: 1; transform: translateY(-3px); }
}

.no-anim .tutor-msg.typing span { animation: none; }

.tutor-empty { display: grid; gap: 12px; margin: auto 0 0; color: var(--muted); font-size: 0.93rem; }
.tutor-starters { display: flex; flex-wrap: wrap; gap: 8px; }
.tutor-starters .btn { text-align: left; }

.tutor-gate {
  display: grid;
  gap: 12px;
  margin: auto 16px;
  padding: 14px;
  border: 1px solid var(--rule);
  border-left: 3px solid var(--signal);
  border-radius: var(--r-control);
  font-size: 0.93rem;
}

.tutor-gate[hidden] { display: none; }
.tutor-gate .btn { justify-self: start; }

.tutor-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--rule);
}

.tutor-form[hidden] { display: none; }
.tutor-form textarea { flex: 1 1 0; min-width: 0; min-height: 42px; max-height: 160px; resize: none; line-height: 1.4; }
.tutor-send { width: 42px; min-height: 42px; padding: 0; flex: none; }
.tutor-send .icon-svg { width: 18px; height: 18px; }

.tutor-think {
  display: flex;
  flex: 1 0 100%;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  font-size: 0.85rem;
}
.tutor-think .muted { font-size: 0.8rem; }

.tutor-error { padding: 0 14px 10px; font-size: 0.85rem; }

@media (max-width: 960px) {
  .tutor-fab { bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 14px); right: 14px; height: 44px; }
  .tutor-panel:not(.embedded) {
    left: 8px;
    right: 8px;
    width: auto;
    top: calc(var(--bar-h) + 8px);
    bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 70px);
    height: auto;
  }
  body:not(.has-tab-bar) .tutor-panel:not(.embedded) { bottom: 8px; }
}
