/* One stylesheet, no framework, no font from another origin.

   That last part is a constraint and not a preference: under Family Link's
   "only allow approved sites", every subresource host must also be approved, so
   a webfont from elsewhere half-loads the app on the child's phone and works
   perfectly on the parent's. System fonts only. */

:root {
  --ink: #17202a;
  --muted: #5b6b7c;
  --line: #d7dee6;
  --bg: #f6f8fa;
  --card: #ffffff;
  --accent: #1d4ed8;
  --bad: #b42318;
  --tap: 56px;                     /* nothing a child taps is smaller than this */
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  color: var(--ink);
  background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom);
}

#bar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
#bar h1 { font-size: 18px; margin: 0; flex: 1; }
#left { color: var(--muted); font-size: 14px; }

main { padding: 16px 14px 32px; max-width: 640px; margin: 0 auto; }
.screen { display: flex; flex-direction: column; gap: 14px; }
.screen[hidden] { display: none; }

.lead { font-size: 19px; margin: 0; }
p { margin: 0; line-height: 1.45; }
.hint { color: var(--muted); font-size: 15px; }
.error { color: var(--bad); font-weight: 600; }
.error[hidden] { display: none; }
.code { font-size: 15px; color: var(--muted); letter-spacing: 1px; }

button {
  font: inherit; border-radius: 14px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink);
  min-height: var(--tap); padding: 0 18px; cursor: pointer;
}
button:disabled { opacity: .45; }
button.primary {
  background: var(--accent); color: #fff; border-color: var(--accent);
  font-weight: 650; font-size: 19px;
}
button.ghost { background: transparent; }
button.ghost.wide { width: 100%; }
#back { min-height: 40px; min-width: 44px; padding: 0; font-size: 20px; border: none; }
#back[hidden] { display: none; }

button.big {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  padding: 20px 18px; min-height: 96px; text-align: left;
}
button.big b { font-size: 21px; }
button.big small { color: var(--muted); font-size: 15px; }

button.tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; min-height: 132px; border-style: dashed; border-width: 2px;
}
.tile-icon { font-size: 34px; line-height: 1; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field span { color: var(--muted); font-size: 15px; }
input, textarea {
  font: inherit; padding: 13px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  width: 100%;
}
#code { font-size: 28px; text-align: center; letter-spacing: 3px; }
textarea { resize: vertical; }

#thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
#thumbs:empty { display: none; }
#thumbs figure { position: relative; margin: 0; }
#thumbs img { width: 84px; height: 84px; object-fit: cover; border-radius: 10px;
              border: 1px solid var(--line); display: block; }
#thumbs button {
  position: absolute; top: -6px; right: -6px;
  min-height: 28px; height: 28px; width: 28px; padding: 0; border-radius: 14px;
  background: var(--ink); color: #fff; border: none; font-size: 15px; line-height: 1;
}

#pages { display: flex; flex-direction: column; gap: 12px; }
#pages img { width: 100%; border-radius: 12px; border: 1px solid var(--line);
             background: var(--card); }
.row { display: flex; gap: 10px; }
.row button { flex: 1; }

.spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--accent);
  animation: spin 1s linear infinite; margin: 8px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

@media (prefers-color-scheme: dark) {
  :root { --ink: #e8edf3; --muted: #9aa8b8; --line: #2c3846;
          --bg: #10161d; --card: #18212b; --accent: #4f7fee; --bad: #ff7b6b; }
}

/* --- chips, used for the pupil chooser and the parent's tabs --------------- */

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px; padding: 0 16px; border-radius: 22px;
  font-size: 16px; white-space: nowrap;
}
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }
/* The pupil chooser. Its own class rather than reusing .chip, because these are
   containers with a button (and sometimes two) inside, while the parent's tabs
   are plain buttons -- overloading one class made the tabs lose their padding. */
.who-chip {
  display: inline-flex; align-items: center; gap: 2px; padding: 0;
  border: 1px solid var(--line); border-radius: 22px; background: var(--card);
}
.who-chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
/* A name that lives only on this phone, until a scored sheet makes it real. */
.who-chip.temp { border-style: dashed; padding-right: 4px; }
.who-chip .chip-label {
  border: none; background: none; color: inherit; font: inherit;
  min-height: 44px; padding: 0 16px; border-radius: 22px; font-size: 16px;
  white-space: nowrap;
}
.who-chip.temp .chip-label { padding-right: 6px; }
.who-chip .chip-x {
  border: none; background: none; color: inherit; opacity: .55;
  min-height: 36px; height: 36px; width: 32px; padding: 0; font-size: 20px;
  line-height: 1;
}
.field-label { color: var(--muted); font-size: 15px; display: block; margin-bottom: 6px; }
#who[hidden] { display: none; }
#parent { min-height: 40px; min-width: 44px; padding: 0; font-size: 20px; border: none; }
#parent[hidden] { display: none; }

/* --- the parent view ------------------------------------------------------ */

#parent-body { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 13px 15px; display: flex; flex-direction: column; gap: 5px;
}
.card .top { display: flex; align-items: baseline; gap: 8px; justify-content: space-between; }
.card b { font-size: 16px; }
.card .meta, .card li { color: var(--muted); font-size: 14px; }
.card ul { margin: 4px 0 0; padding-left: 18px; }
.card .row { margin-top: 8px; }
.card .row button { min-height: 44px; font-size: 15px; }
.tag {
  font-size: 12px; padding: 2px 8px; border-radius: 10px;
  background: var(--bg); border: 1px solid var(--line); color: var(--muted);
}
.tag.bad { color: var(--bad); border-color: var(--bad); }
.stack { display: flex; align-items: center; gap: 10px; }
.stack input { width: 96px; }
