:root {
  --paper: #f6f8fa;
  --grid: #dfe7f0;
  --ink: #1c2a44;
  --ink-soft: #55627a;
  --line: #c9d3df;
  --white: #ffffff;
  --done: #2e7d4f;
  --late: #b3362d;
  --highlight: #e2b02a;
  --tint: var(--tint);
  --tint-line: var(--tint-line);
  --hover: var(--hover);
  --accent: var(--ink);
  --bar: var(--accent);
  --on-bar: #ffffff;
  --border: var(--ink);
  color-scheme: light;

  --radius-sm: 6px;
  --radius-lg: 14px;
  --body: "Atkinson Hyperlegible", system-ui, sans-serif;
  --hand: "Kalam", "Comic Sans MS", cursive;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0f1726; --grid: #18233a; --ink: #e6ecf5; --ink-soft: #9fb0c8; --line: #33435e;
    --white: #182236; --done: #3fa86b; --late: #ff8a7d;
    --tint: #3a3216; --tint-line: #c79a2a; --hover: #22304a;
    --bar: #0b1220; --on-bar: #e6ecf5; --border: #46587a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0f1726; --grid: #18233a; --ink: #e6ecf5; --ink-soft: #9fb0c8; --line: #33435e;
  --white: #182236; --done: #3fa86b; --late: #ff8a7d;
  --tint: #3a3216; --tint-line: #c79a2a; --hover: #22304a;
  --bar: #0b1220; --on-bar: #e6ecf5; --border: #46587a;
  color-scheme: dark;
}

/* Book, subject and swatch colours. Anything with data-color gets --cover. */
[data-color]          { --cover: #2f5da8; }
[data-color="green"]  { --cover: #2e8b57; }
[data-color="red"]    { --cover: #c8463d; }
[data-color="purple"] { --cover: #6b4fa0; }
[data-color="yellow"] { --cover: #d9a520; }
[data-color="orange"] { --cover: #d9772b; }
[data-color="teal"]   { --cover: #1f8a8a; }
[data-color="pink"]   { --cover: #c2477f; }
[data-color="slate"]  { --cover: #5b6b82; }

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--body);
  font-size: 1.0625rem;
  line-height: 1.5;
  color: var(--ink);
  background-color: var(--paper);
  /* Squared maths paper */
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  min-height: 100vh;
}

main { max-width: 1120px; margin: 0 auto; padding: 20px 16px 64px; outline: none; }

h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
p { margin: 0; }

button, input, select { font: inherit; color: inherit; }

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

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

.hint { font-size: .9375rem; color: var(--ink-soft); }
.empty { color: var(--ink-soft); margin: 4px 0; }
small { font-size: .875rem; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 8px 18px;
  border: 2px solid var(--accent); border-radius: var(--radius-sm);
  background: var(--accent); color: var(--white);
  font-weight: 700; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: color-mix(in srgb, var(--accent) 85%, var(--paper)); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: var(--white); color: var(--accent); }
.btn.secondary:hover { background: var(--hover); }
.btn.quiet { background: transparent; color: var(--ink); border-color: transparent; text-decoration: underline; padding-inline: 8px; }
.btn.danger { background: var(--white); color: var(--late); border-color: var(--late); }
.btn.wide { width: 100%; }
.btn.on-dark { background: var(--on-bar); color: var(--bar); border-color: var(--on-bar); }
.btn.on-dark.quiet { background: transparent; color: var(--on-bar); border-color: transparent; }

.link {
  border: 0; padding: 0; background: none; cursor: pointer;
  color: var(--ink); font-weight: 700; text-decoration: underline;
}

/* ---------- Child screen ---------- */

.top { margin-bottom: 20px; }
.top p { margin-top: 4px; color: var(--ink-soft); }

.widgets { display: grid; gap: 20px; grid-auto-flow: dense; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 820px) {
  .widgets { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .widget.wide { grid-column: 1 / -1; }
}

.widget, .card {
  background: var(--white);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  min-width: 0;
}
.widget > h2 { margin-bottom: 10px; }
.widget > .hint { margin: -6px 0 10px; }
.widget h3 { margin: 12px 0 2px; color: var(--ink-soft); font-size: .9375rem; }

/* The apps widget sits on the paper, so the books stand out */
.widget.w-apps { background: transparent; border: 0; padding: 0; }

.parent-link { margin-top: 36px; text-align: center; }

/* ---------- Exercise book tiles ---------- */

.books {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 18px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (min-width: 560px) { .books { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 820px) { .books { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.book {
  position: relative;
  display: flex; flex-direction: column; justify-content: center;
  width: 100%; aspect-ratio: 4 / 5;
  padding: 14px 12px;
  border: 0; border-radius: 3px 8px 8px 3px;
  background:
    linear-gradient(90deg, rgba(0,0,0,.22) 0 6px, rgba(255,255,255,.08) 6px 8px, transparent 8px),
    var(--cover);
  box-shadow: 0 1px 0 rgba(0,0,0,.25), 3px 4px 0 rgba(28,42,68,.18);
  cursor: pointer; text-align: left;
  transition: transform .12s ease;
}
.book:hover { transform: translateY(-2px) rotate(-.6deg); }
.book:active { transform: translateY(1px); }

.label {
  margin-left: 6px;
  padding: 8px 10px 6px;
  background: #fff;
  border: 2px solid #1c2a44;
  border-radius: 10px;
  color: #1c2a44;
}
.label-row {
  display: flex; align-items: baseline; gap: 6px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 2px; margin-bottom: 4px;
  font-size: .75rem; color: var(--ink-soft);
}
.label-row:last-child { border-bottom: 0; margin-bottom: 0; }
.label-row span:last-child {
  font-family: var(--hand); font-size: 1.125rem; line-height: 1.15;
  color: #23407a; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.sticker {
  position: absolute; top: -8px; right: -6px;
  padding: 2px 10px;
  background: var(--highlight); color: #1c2a44;
  border: 2px solid #1c2a44; border-radius: 999px;
  font-size: .8125rem; font-weight: 700;
  transform: rotate(6deg);
}

/* ---------- Today's lessons ---------- */

.lessons { list-style: none; margin: 0; padding: 0; }
.lesson {
  display: grid; grid-template-columns: 52px 1fr auto; gap: 10px; align-items: start;
  padding: 8px 0 8px 10px; border-left: 5px solid var(--cover, transparent);
  margin-bottom: 4px; border-radius: 3px;
}
.lesson .time { font-variant-numeric: tabular-nums; color: var(--ink-soft); font-size: .9375rem; padding-top: 1px; }
.lesson-body { display: grid; }
.lesson-body small { color: var(--ink-soft); }
.lesson.is-break { padding-block: 2px; color: var(--ink-soft); font-size: .875rem; border-left-color: transparent; }
.lesson.is-break .time { font-size: .875rem; }
.lesson .free { color: var(--ink-soft); font-style: italic; }
.lesson.is-now { background: var(--tint); }
.now-tag {
  align-self: center; padding: 1px 8px; border-radius: 999px;
  border: 2px solid var(--ink); font-size: .8125rem; font-weight: 700;
}
.lesson.is-now .now-tag { background: var(--highlight); color: #1c2a44; border-color: #1c2a44; }

.bring {
  justify-self: start; margin-top: 4px; padding: 1px 8px;
  background: var(--tint); border: 1px dashed var(--tint-line); border-radius: 4px;
  font-size: .8125rem; font-weight: 700;
}

/* ---------- Lists with tick boxes ---------- */

.tick {
  flex: none; width: 32px; height: 32px; margin-top: 2px;
  border: 2px solid var(--ink); border-radius: 6px;
  background: var(--white); cursor: pointer;
  display: grid; place-items: center; padding: 0;
}
.tick svg { width: 20px; height: 20px; visibility: hidden; }
.tick[aria-checked="true"] { background: var(--done); border-color: var(--done); }
.tick[aria-checked="true"] svg { visibility: visible; }

.hw-list, .checklist, .plain-list { list-style: none; margin: 0; padding: 0; }
.hw-item, .checklist li { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.hw-item:last-child, .checklist li:last-child { border-bottom: 0; }
.hw-text { flex: 1; min-width: 0; }
.hw-title { font-weight: 700; }
.hw-meta { color: var(--ink-soft); font-size: .9375rem; }
.hw-item.is-done .hw-title, .checklist li.is-done strong { text-decoration: line-through; color: var(--ink-soft); font-weight: 400; }
.checklist li span { display: grid; }
.checklist small { color: var(--ink-soft); }

.due { white-space: nowrap; font-weight: 700; font-size: .9375rem; }
.due.today, .due.late { color: var(--late); }

details.done-list { margin-top: 8px; }
details.done-list summary { cursor: pointer; color: var(--ink-soft); padding: 6px 0; }

.plain-list li { display: grid; grid-template-columns: 84px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.plain-list li:last-child { border-bottom: 0; }
.plain-list li > span { display: grid; }
.plain-list small { color: var(--ink-soft); }
.plain-list .when { font-weight: 700; font-variant-numeric: tabular-nums; }
.plain-list .when small { font-weight: 400; }
.plain-list li.is-past { color: var(--ink-soft); }
.plain-list li.is-past span:last-child { text-decoration: line-through; }

/* ---------- Timetable grids ---------- */

.tt-scroll { overflow-x: auto; margin-inline: -4px; padding-inline: 4px; }

.tt-mini { width: 100%; border-collapse: separate; border-spacing: 4px; font-size: .875rem; table-layout: fixed; min-width: 480px; }
.tt-mini th { font-weight: 700; color: var(--ink-soft); text-align: left; padding: 2px 4px; }
.tt-mini thead th.is-today { color: var(--ink); text-decoration: underline 3px var(--highlight); text-underline-offset: 4px; }
.tt-mini tbody th { width: 52px; font-weight: 400; font-variant-numeric: tabular-nums; }
.tt-mini td {
  padding: 4px 6px; border-radius: 4px; vertical-align: top;
  background: color-mix(in srgb, var(--cover, #fff) 16%, var(--white));
  border-left: 4px solid var(--cover, transparent);
}
.tt-mini td strong, .tt-mini td small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tt-mini td small { color: var(--ink-soft); font-size: .75rem; }
.tt-mini td.free { background: transparent; border: 1px dashed var(--line); }
.tt-mini td.is-today { outline: 2px solid var(--ink); }

.tt-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 8px; }
.segmented { display: inline-flex; border: 2px solid var(--accent); border-radius: var(--radius-sm); overflow: hidden; }
.segmented button { min-height: 40px; padding: 6px 16px; border: 0; background: var(--white); font-weight: 700; cursor: pointer; }
.segmented button + button { border-left: 2px solid var(--accent); }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--white); }

.tt-edit { width: 100%; border-collapse: separate; border-spacing: 4px; table-layout: fixed; min-width: 640px; margin-top: 8px; }
.tt-edit thead th { text-align: left; font-size: .9375rem; padding: 0 4px; }
.tt-edit tbody th { width: 96px; text-align: left; font-size: .875rem; font-weight: 700; vertical-align: middle; }
.tt-edit tbody th small { display: block; font-weight: 400; color: var(--ink-soft); font-size: .75rem; font-variant-numeric: tabular-nums; }
.tt-edit td { padding: 0; }
.slot {
  display: grid; align-content: center; width: 100%; min-height: 56px; padding: 6px 8px;
  border: 2px dashed var(--line); border-radius: var(--radius-sm);
  background: transparent; text-align: left; cursor: pointer; color: var(--ink-soft); font-size: 1.25rem;
}
.slot:hover { border-color: var(--ink-soft); background: var(--white); }
.slot.filled {
  border: 0; border-left: 5px solid var(--cover); color: var(--ink); font-size: .9375rem;
  background: color-mix(in srgb, var(--cover) 18%, var(--white));
}
.slot.filled:hover { background: color-mix(in srgb, var(--cover) 28%, var(--white)); }
.slot strong, .slot small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot small { color: var(--ink-soft); font-size: .75rem; }
.tt-break th { font-weight: 400 !important; color: var(--ink-soft); }
.tt-break td { background: repeating-linear-gradient(135deg, transparent 0 6px, var(--grid) 6px 7px); border-radius: 4px; }

/* ---------- Sheet (dialog) ---------- */

dialog {
  width: min(460px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0; border: 2px solid var(--ink); border-radius: var(--radius-lg);
  background: var(--white); color: var(--ink);
}
dialog.wide { width: min(720px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(28,42,68,.55); }

@media (max-width: 559px) {
  dialog, dialog.wide {
    margin: auto 0 0; width: 100vw; max-width: 100vw; max-height: 92vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0; border-bottom: 0;
  }
}

.sheet { padding: 20px 20px 24px; display: grid; gap: 16px; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.sheet-head p { margin-top: 2px; color: var(--ink-soft); }
.close {
  flex: none; width: 44px; height: 44px; border: 0; background: transparent;
  font-size: 1.75rem; line-height: 1; cursor: pointer; border-radius: var(--radius-sm);
}
.close:hover { background: var(--hover); }

.cred { display: grid; gap: 10px; }
.cred-row {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px;
  padding: 10px 12px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.cred-row small { display: block; color: var(--ink-soft); font-size: .8125rem; }
.cred-row code { font-family: var(--body); font-size: 1.125rem; font-weight: 700; word-break: break-all; letter-spacing: .02em; }

/* ---------- Forms ---------- */

.stack { display: grid; gap: 14px; }
.new-subject[hidden] { display: none; }
.field { display: grid; gap: 4px; min-width: 0; align-content: start; }
.field label, .field legend { font-weight: 700; font-size: .9375rem; }
.field input, .field select, .period-row input, .time-field input {
  min-height: 44px; padding: 8px 10px; width: 100%; min-width: 0;
  border: 2px solid var(--ink-soft); border-radius: var(--radius-sm); background: var(--white);
}
/* iPhones draw date and time boxes wider than their column unless told not to. */
input[type="time"], input[type="date"] { -webkit-appearance: none; appearance: none; display: block; min-width: 0; text-align: left; }
input[type="time"]::-webkit-date-and-time-value, input[type="date"]::-webkit-date-and-time-value { text-align: left; }
select { height: 44px; }
.field input:focus, .field select:focus, .period-row input:focus, .time-field input:focus { border-color: var(--ink); }
.field small { color: var(--ink-soft); }
.field-pair { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: end; }
fieldset.field, fieldset.ping-group { border: 0; padding: 0; margin: 0; min-width: 0; }
.form-error { color: var(--late); font-weight: 700; min-height: 0; }
.form-error:empty { display: none; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; }

.inline-check { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; cursor: pointer; }
.inline-check input { flex: none; width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
.day-checks { display: flex; flex-wrap: wrap; gap: 4px 18px; }

.colors { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.colors label { position: relative; cursor: pointer; }
.colors input { position: absolute; opacity: 0; }
.colors .swatch { display: block; width: 32px; height: 40px; border: 2px solid transparent; }
.colors input:checked + .swatch { border-color: var(--ink); box-shadow: 0 0 0 2px var(--white) inset; }
.colors input:focus-visible + .swatch { outline: 3px solid var(--highlight); outline-offset: 2px; }

.period-list { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 8px; }
.period-row { display: grid; grid-template-columns: minmax(0, 1fr) 120px 120px auto 44px; gap: 8px; align-items: center; }
@media (max-width: 559px) {
  /* Name and remove on the first line; start, end and "Lesson" on the second. */
  .period-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; padding-bottom: 10px; border-bottom: 1px dashed var(--line); }
  .period-row input[name="label"] { grid-column: 1 / 3; grid-row: 1; }
  .period-row .close { grid-column: 3; grid-row: 1; justify-self: end; }
  .period-row .inline-check { grid-column: 3; grid-row: 2; }
}

/* ---------- Parent mode ---------- */

.parent-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  margin: -20px -16px 20px; padding: 12px 16px;
  background: var(--bar); color: var(--on-bar);
}
.parent-bar h1 { font-size: 1.25rem; }
.bar-actions { display: flex; gap: 8px; }

.notice {
  padding: 10px 14px; margin-bottom: 20px;
  background: var(--tint); border: 2px solid var(--highlight); border-radius: var(--radius-sm);
  font-size: .9375rem;
}

.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.tab {
  display: inline-grid; justify-items: start; min-height: 48px; padding: 6px 18px;
  border: 2px solid var(--ink); border-radius: var(--radius-sm);
  background: var(--white); font-weight: 700; cursor: pointer; line-height: 1.2;
}
.tab small { font-weight: 400; font-size: .8125rem; color: var(--ink-soft); }
.tab[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--white); }
.tab[aria-selected="true"] small { color: #c9d3e6; }
.tab.add { border-style: dashed; font-weight: 400; align-content: center; }

.parent-layout { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); }
.section-nav { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.section-nav button {
  flex: none; min-height: 44px; padding: 8px 14px;
  border: 2px solid transparent; border-radius: var(--radius-sm);
  background: transparent; text-align: left; cursor: pointer; font-weight: 700; color: var(--ink-soft);
}
.section-nav button:hover { color: var(--ink); background: rgba(255,255,255,.7); }
.section-nav button[aria-current="page"] { color: var(--accent); background: var(--white); border-color: var(--accent); }

@media (min-width: 820px) {
  .parent-layout { grid-template-columns: 190px 1fr; align-items: start; }
  .section-nav { flex-direction: column; position: sticky; top: 20px; }
}

.section-body { display: grid; gap: 20px; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.card > h2 { margin-bottom: 8px; }
.card > p + p { margin-top: 8px; }

.row-list { list-style: none; margin: 8px 0 0; padding: 0; }
.row {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center;
  padding: 10px 0; border-bottom: 1px dashed var(--line);
}
.row:last-child { border-bottom: 0; }
.row small { display: block; color: var(--ink-soft); }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.row-actions .btn { min-height: 40px; padding: 6px 14px; }

.swatch { display: inline-block; width: 18px; height: 24px; border-radius: 2px 4px 4px 2px; background: var(--cover, var(--line)); }
.day-chip {
  min-width: 44px; padding: 2px 6px; text-align: center;
  border: 2px solid var(--ink); border-radius: var(--radius-sm); font-weight: 700; font-size: .875rem;
}

.choice-list { display: grid; gap: 10px; margin-top: 16px; }
.choice {
  display: grid; gap: 2px; padding: 14px 16px; text-align: left; cursor: pointer;
  border: 2px solid var(--ink); border-radius: var(--radius-sm); background: var(--white);
}
.choice:hover { background: var(--hover); }
.choice small { color: var(--ink-soft); }

/* Pings */
.pings-layout { display: grid; gap: 20px; }
@media (min-width: 1000px) { .pings-layout { grid-template-columns: 1fr 1fr; align-items: start; } }
.ping-group { display: grid; gap: 4px; padding: 12px 0; border-bottom: 1px dashed var(--line) !important; }
.ping-group:last-child { border-bottom: 0 !important; }
.ping-group legend { font-weight: 700; padding: 0; margin-bottom: 4px; }
.time-field { display: inline-flex; align-items: center; gap: 10px; }
.time-field input { width: auto; }
.ping-day { margin: 14px 0 4px; }
.ping-list { list-style: none; margin: 0; padding: 0; }
.ping-list li { display: grid; grid-template-columns: 48px auto 1fr; gap: 10px; align-items: start; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.ping-list .when { font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.who { padding: 0 8px; border-radius: 999px; font-size: .8125rem; font-weight: 700; border: 2px solid var(--ink); white-space: nowrap; }
.who.parent { background: var(--ink); color: var(--white); }

/* Widgets picker */
.widget-list { list-style: none; margin: 8px 0 0; padding: 0; }
.widget-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px dashed var(--line); }
.widget-row:last-child { border-bottom: 0; }
.widget-row.is-off strong { color: var(--ink-soft); }
.switch { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: start; cursor: pointer; }
.switch > span:last-child { display: grid; }
.switch small { color: var(--ink-soft); }
.switch input { position: absolute; opacity: 0; }
.switch-track {
  position: relative; width: 48px; height: 28px; margin-top: 2px;
  border: 2px solid var(--ink); border-radius: 999px; background: var(--white);
}
.switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
  border-radius: 50%; background: var(--ink); transition: transform .15s;
}
.switch input:checked + .switch-track { background: var(--done); border-color: var(--done); }
.switch input:checked + .switch-track::after { transform: translateX(20px); background: var(--white); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--highlight); outline-offset: 2px; }
.order-btns { display: flex; gap: 6px; }
.order-btns .btn { min-height: 40px; width: 44px; padding: 0; }

.danger-zone { border-color: var(--line); }
.danger-zone .hint { margin: 4px 0 12px; }

/* ---------- Toast ---------- */

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  padding: 10px 18px; border-radius: 999px;
  background: var(--ink); color: var(--white); font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  z-index: 10;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- Printed timetable ---------- */
/* Sizes are in em, so one layout scales from A4 down to A6 by changing the page font size. */

#print-root { display: none; }

.print-options { gap: 8px; }
.print-option { display: block; cursor: pointer; }
.print-option input { position: absolute; opacity: 0; }
.print-option span { display: grid; padding: 10px 14px; border: 2px solid var(--line); border-radius: var(--radius-sm); }
.print-option small { color: var(--ink-soft); }
.print-option input:checked + span { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.print-option input:focus-visible + span { outline: 3px solid var(--highlight); outline-offset: 2px; }

@media print {
  :root, :root[data-theme="dark"] {
    --paper: #fff; --grid: #dfe7f0; --ink: #1c2a44; --ink-soft: #55627a; --line: #c9d3df; --white: #fff;
    --tint: #fff6d8; --tint-line: #a77d0c;
  }
  body { background: none; }
  #app, #sheet, #toast { display: none !important; }
  #print-root { display: block; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  .print-page { break-after: page; display: flex; flex-direction: column; gap: .5em; line-height: 1.25; }
  .print-page:last-child { break-after: auto; }
  .print-page.a4 { font-size: 10pt; height: 188mm; }
  .print-page.a5 { font-size: 7pt; height: 132mm; }
  .print-page.a6 { font-size: 5.4pt; height: 93mm; }

  .print-head { display: flex; justify-content: space-between; align-items: baseline; border-bottom: .2em solid var(--ink); padding-bottom: .3em; }
  .print-head h1 { font-family: var(--hand); font-size: 2.5em; font-weight: 700; }
  .print-head p { display: flex; gap: 1.6em; font-size: 1.3em; }

  .print-tt { width: 100%; flex: 1; border-collapse: separate; border-spacing: .5em; table-layout: fixed; }
  .print-tt col.time-col { width: 7.5em; }
  .print-tt thead th { text-align: left; font-size: 1.1em; padding: 0 .4em; }
  .print-tt tbody th { text-align: left; font-size: .95em; vertical-align: middle; }
  .print-tt tbody th small { display: block; font-weight: 400; color: var(--ink-soft); font-size: .9em; }
  .print-tt td { padding: .35em .6em; vertical-align: top; border-radius: .45em; border: .08em solid var(--line); }
  .print-tt td[data-color] {
    border: 0; border-left: .5em solid var(--cover);
    background: color-mix(in srgb, var(--cover) 18%, #fff);
  }
  .print-tt td strong { display: block; font-size: 1.1em; }
  .print-tt td small { display: block; color: var(--ink-soft); font-size: .85em; }
  .print-tt td em {
    display: inline-block; margin-top: .3em; padding: 0 .4em; border-radius: .3em;
    font-style: normal; font-weight: 700; font-size: .8em;
    border: .08em dashed #a77d0c; background: #fff6d8;
  }
  .print-break th { font-size: .85em !important; color: var(--ink-soft); }
  .print-break th small { display: inline; margin-left: .4em; }
  .print-break td { height: .9em; border: 0; background: repeating-linear-gradient(135deg, transparent 0 .4em, var(--grid) .4em .5em); }

  .print-foot { display: flex; gap: 3em; font-size: .95em; border-top: .08em solid var(--line); padding-top: .5em; }
  .print-foot h2 { font-size: 1.05em; margin-bottom: .2em; }
  .print-foot ul { margin: 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 0 1.6em; }

  /* Half page: kit is listed along the bottom instead of in each box. */
  .print-page.a5 .print-tt td em { display: none; }
  /* Planner size: subjects and rooms only. */
  .print-page.a6 .teacher, .print-page.a6 .print-foot, .print-page.a6 .print-tt td em { display: none; }
  .print-page.a6 .print-tt col.time-col { width: 6em; }
}

/* ---------- Simple tiles (for older children) ---------- */

[data-tiles="simple"] .books { gap: 12px; }
[data-tiles="simple"] .book {
  aspect-ratio: auto; min-height: 96px; justify-content: flex-end;
  padding: 14px 14px 12px 18px;
  background: var(--white); color: var(--ink);
  border: 2px solid var(--border); border-left: 8px solid var(--cover); border-radius: 10px;
  box-shadow: none;
}
[data-tiles="simple"] .book:hover { transform: none; background: var(--hover); }
[data-tiles="simple"] .label { margin: 0; padding: 0; background: none; border: 0; color: inherit; display: grid; gap: 2px; }
[data-tiles="simple"] .label-row { display: none; border: 0; margin: 0; padding: 0; color: var(--ink); }
[data-tiles="simple"] .label-row:nth-child(2), [data-tiles="simple"] .label-row:nth-child(3) { display: block; }
[data-tiles="simple"] .label-row span:first-child { display: none; }
[data-tiles="simple"] .label-row span:last-child { font-family: var(--body); color: inherit; white-space: normal; }
[data-tiles="simple"] .label-row:nth-child(2) span:last-child { font-size: 1.125rem; font-weight: 700; }
[data-tiles="simple"] .label-row:nth-child(3) span:last-child { font-size: .875rem; color: var(--ink-soft); }
[data-tiles="simple"] .sticker { position: absolute; top: 10px; right: 10px; transform: none; border-width: 0; font-size: .75rem; }
[data-tiles="simple"] .widget.w-apps h2 { margin-bottom: 10px; }

/* ---------- Welcome and sign-in ---------- */

.welcome { max-width: 520px; margin: 0 auto; display: grid; gap: 20px; padding-top: 4vh; }
.welcome-head { display: flex; align-items: center; gap: 12px; font-size: 1.5rem; font-weight: 700; }
.welcome-head .mark { width: 56px; height: 56px; }
.welcome-intro { font-size: 1.25rem; }
.welcome-foot { text-align: center; }
.welcome .card h1 { font-size: 1.5rem; }
.welcome .choice-list { margin-top: 0; }

.recovery-code, .code-input {
  font-family: var(--body); font-weight: 700; letter-spacing: .08em; font-variant-numeric: tabular-nums;
}
.recovery-code {
  padding: 14px 12px; text-align: center; font-size: clamp(1rem, 5.4vw, 1.375rem); letter-spacing: .04em;
  background: var(--paper); border: 2px dashed var(--border); border-radius: var(--radius-sm);
  overflow-wrap: normal;
}
.code-input { font-size: 1.25rem; text-transform: uppercase; }

.steps { margin: 0; padding-left: 1.4em; display: grid; gap: 4px; }

/* ---------- Family settings and devices ---------- */

.family-grid { display: grid; gap: 20px; }
@media (min-width: 820px) { .family-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; } }
.family-grid .card > p + p, .family-grid .card > p + ol, .family-grid .card > ol + p { margin-top: 10px; }
.tab.family { margin-left: auto; font-weight: 400; align-content: center; }
.device-dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--ink-soft); }
.device-dot.on { background: var(--done); border-color: var(--done); }

.pings-nudge { border-color: var(--highlight); margin-bottom: 20px; }
.pings-nudge p + p { margin-top: 10px; }

.parent-link { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

/* ---------- Look picker ---------- */

.look-options { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.look-option { position: relative; cursor: pointer; }
.look-option input { position: absolute; opacity: 0; }
.look-option span {
  display: inline-flex; align-items: center; min-height: 44px; padding: 8px 16px;
  border: 2px solid var(--border); border-radius: var(--radius-sm); font-weight: 700;
}
.look-option input:checked + span { background: var(--accent); color: var(--white); border-color: var(--accent); }
.look-option input:focus-visible + span { outline: 3px solid var(--highlight); outline-offset: 2px; }

/* ---------- Add to Home Screen guide ---------- */

.install-card { border-color: var(--highlight); }
.install-card > * + * { margin-top: 10px; }
.install-steps { gap: 8px; }
.ico {
  display: inline-block; width: 1.3em; height: 1.3em; vertical-align: -0.3em;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.ico circle { fill: currentColor; stroke: none; }

.sub-head { margin: 16px 0 0; font-size: .9375rem; color: var(--ink-soft); }

/* ---------- Invited parent ---------- */

.invite-card h1 { font-size: 1.5rem; }
.invite-card h2 { margin-top: 8px; }
.join-steps { gap: 18px; padding-left: 1.6em; }
.join-steps > li::marker { font-weight: 700; }
.join-steps > li > * + * { margin-top: 8px; }
.join-steps .install-steps { margin-top: 8px; }
.invite-card { overflow-wrap: anywhere; }
.join-steps .install-steps { list-style-type: lower-alpha; }
.join-steps .recovery-code { font-size: clamp(.875rem, 4.3vw, 1.25rem); letter-spacing: .02em; padding-inline: 8px; overflow-wrap: normal; }

/* ---------- App picker ---------- */

.app-picker {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  max-height: 46vh; overflow-y: auto;
}
.app-choice {
  display: grid; width: 100%; height: 100%; padding: 10px 12px; text-align: left; cursor: pointer;
  border: 2px solid var(--line); border-left: 6px solid var(--cover); border-radius: var(--radius-sm);
  background: var(--white);
}
.app-choice:hover { background: var(--hover); }
.app-choice small { color: var(--ink-soft); }
.app-choice:disabled { opacity: .5; cursor: default; }

/* ---------- Colour themes, backgrounds and text size (per device) ---------- */

:root[data-accent="forest"] { --accent: #1f5e45; }
:root[data-theme="dark"][data-accent="forest"] { --accent: #86d4ae; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"])[data-accent="forest"] { --accent: #86d4ae; } }
[data-swatch="forest"] { background: #1f5e45; }
:root[data-accent="berry"] { --accent: #8a2a5c; }
:root[data-theme="dark"][data-accent="berry"] { --accent: #f2a0c8; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"])[data-accent="berry"] { --accent: #f2a0c8; } }
[data-swatch="berry"] { background: #8a2a5c; }
:root[data-accent="ocean"] { --accent: #135e8a; }
:root[data-theme="dark"][data-accent="ocean"] { --accent: #8ccaf2; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"])[data-accent="ocean"] { --accent: #8ccaf2; } }
[data-swatch="ocean"] { background: #135e8a; }
:root[data-accent="sunset"] { --accent: #a9431b; }
:root[data-theme="dark"][data-accent="sunset"] { --accent: #ffb38c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"])[data-accent="sunset"] { --accent: #ffb38c; } }
[data-swatch="sunset"] { background: #a9431b; }
:root[data-accent="grape"] { --accent: #57388f; }
:root[data-theme="dark"][data-accent="grape"] { --accent: #c8b4f6; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"])[data-accent="grape"] { --accent: #c8b4f6; } }
[data-swatch="grape"] { background: #57388f; }
[data-swatch="ink"] { background: #1c2a44; }

:root[data-paper="lined"] body {
  background-image: linear-gradient(var(--grid) 1px, transparent 1px);
  background-size: 100% 28px;
}
:root[data-paper="dots"] body {
  background-image: radial-gradient(circle, color-mix(in srgb, var(--grid) 55%, var(--ink-soft)) 1.2px, transparent 1.6px);
  background-size: 22px 22px;
}
:root[data-paper="plain"] body { background-image: none; }

/* Bigger text: everything is sized in rem, so this scales the whole app. */
:root[data-text="large"] { font-size: 115%; }

.swatch-options { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }
.swatch-option { position: relative; cursor: pointer; display: grid; justify-items: center; gap: 2px; font-size: .8125rem; }
.swatch-option input { position: absolute; opacity: 0; }
.swatch-option .dot { width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--white); box-shadow: 0 0 0 2px var(--line); }
.swatch-option input:checked + .dot { box-shadow: 0 0 0 3px var(--ink); }
.swatch-option input:focus-visible + .dot { outline: 3px solid var(--highlight); outline-offset: 3px; }

/* ---------- Getting started checklist ---------- */

.setup { padding: 0; }
.setup summary {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
  padding: 14px 16px; cursor: pointer; list-style: none;
}
.setup summary::-webkit-details-marker { display: none; }
.setup summary::after { content: "Show"; margin-left: auto; font-size: .875rem; text-decoration: underline; color: var(--ink-soft); }
.setup[open] summary::after { content: "Close"; }
.setup > :not(summary) { margin: 0 16px; }
.setup > :last-child { margin-bottom: 14px; }
.setup-count { color: var(--ink-soft); font-size: .9375rem; }
.setup-bar { display: flex; gap: 4px; }
.setup-bar i { width: 22px; height: 6px; border-radius: 3px; background: var(--line); }
.setup-bar i.on { background: var(--done); }
.setup-list { list-style: none; padding: 0; display: grid; gap: 4px; margin-top: 8px !important; margin-bottom: 8px !important; }
.setup-list button {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 6px 8px;
  border: 0; border-radius: var(--radius-sm); background: transparent; text-align: left; cursor: pointer; font-weight: 700;
}
.setup-list button:hover { background: var(--hover); }
.setup-list .is-done button { font-weight: 400; color: var(--ink-soft); text-decoration: line-through; }
.setup-tick {
  flex: none; display: grid; place-items: center; width: 24px; height: 24px;
  border: 2px solid var(--ink); border-radius: 6px;
}
.setup-tick svg { width: 16px; height: 16px; }
.is-done .setup-tick { background: var(--done); border-color: var(--done); }

/* ---------- Tour ---------- */

#tour { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
#tour[hidden] { display: none; }
.tour-dim { position: fixed; inset: 0; background: rgba(15, 23, 38, .6); pointer-events: auto; }
.tour-spot {
  position: fixed; border-radius: 12px; pointer-events: none;
  box-shadow: 0 0 0 4px var(--highlight), 0 0 0 9999px rgba(15, 23, 38, .6);
  transition: top .2s, left .2s, width .2s, height .2s;
}
.tour-card {
  position: fixed; width: min(360px, calc(100vw - 32px)); pointer-events: auto;
  padding: 16px; display: grid; gap: 8px;
  background: var(--white); color: var(--ink); border: 2px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: 0 8px 30px rgba(0, 0, 0, .25);
}
.tour-card.docked { left: 16px !important; right: 16px; bottom: 16px; top: auto !important; width: auto; max-width: 480px; margin: 0 auto; }
.tour-card.docked-top { top: 16px !important; bottom: auto; }
.tour-count { font-size: .8125rem; color: var(--ink-soft); }
.tour-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 4px; }
.tour-actions span { display: flex; gap: 8px; }
.tour-actions [hidden] { display: none; }

/* ---------- Kids adding homework, stars, holidays, quiet hours ---------- */

.widget-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: .9375rem; }
.link.small { font-size: .875rem; font-weight: 400; margin-top: 2px; }
.added-by {
  display: inline-block; padding: 0 6px; border-radius: 4px;
  background: var(--hover); color: var(--ink-soft); font-size: .8125rem; font-weight: 400;
}
.holiday-note { font-size: 1.0625rem; }
.tt-mini td.off { border-style: solid; text-align: center; color: var(--ink-soft); }
.quiet-times { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.allow-add { margin: 12px 0 4px; padding: 12px; border: 2px dashed var(--line); border-radius: var(--radius-sm); }

.stars-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.stars-count { display: flex; align-items: center; gap: 8px; font-size: 1.0625rem; }
.stars-count strong { font-size: 2rem; line-height: 1; }
.star svg { width: 32px; height: 32px; fill: var(--highlight); stroke: #1c2a44; stroke-width: 1.2; }
.streak { padding: 2px 10px; border-radius: 999px; background: var(--tint); border: 1px solid var(--tint-line); font-weight: 700; font-size: .9375rem; }
.stickers { list-style: none; margin: 14px 0 8px; padding: 0; display: flex; gap: 10px; flex-wrap: wrap; }
.sticker-slot {
  position: relative; display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%;
  border: 2px dashed var(--line); color: var(--ink-soft); font-weight: 700; font-size: .875rem;
}
.sticker-slot svg { position: absolute; inset: 7px; fill: var(--highlight); stroke: #1c2a44; stroke-width: 1.2; }
.sticker-slot span { position: relative; }
.sticker-slot.earned { border: 2px solid #1c2a44; background: #fff6d8; color: #1c2a44; transform: rotate(-6deg); }
.sticker-slot.earned:nth-child(even) { transform: rotate(5deg); }
.sticker-slot.earned span { font-size: .75rem; margin-top: 4px; }

.confetti { position: fixed; z-index: 60; pointer-events: none; }
.confetti i {
  position: absolute; width: 8px; height: 12px; border-radius: 2px;
  animation: confetti .9s cubic-bezier(.2, .7, .3, 1) forwards;
}
@keyframes confetti {
  to { transform: translate(var(--dx), var(--dy)) rotate(var(--r)); opacity: 0; }
}

/* ---------- Feedback ---------- */

.field textarea {
  width: 100%; min-width: 0; padding: 8px 10px; resize: vertical;
  border: 2px solid var(--ink-soft); border-radius: var(--radius-sm); background: var(--white); font: inherit; color: inherit;
}
.field textarea:focus { border-color: var(--ink); }
.feedback-inbox { grid-column: 1 / -1; }
.feedback-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 10px; }
.feedback-item { padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); display: grid; gap: 6px; }
.feedback-item.is-done { opacity: .7; }
.feedback-message { white-space: pre-wrap; }
.feedback-meta { display: flex; gap: 10px; flex-wrap: wrap; color: var(--ink-soft); font-size: .875rem; }
.feedback-meta strong { color: var(--ink); }
