/* Pastel theme, always light (a dark phone does not turn it grey): soft tinted backgrounds, dark ink on top.
   Subject colors come from subjects.js (--color) and are turned pastel with color-mix. */
:root {
  --bg: #e6ddff;
  --surface: #fff;
  --sheet: #f7f3ff;
  --field: #e9e2ff;
  --text: #34304a;
  --muted: #736d8c;
  --line: #ddd3fb;
  --accent: #d2c5ff;
  --accent-ink: #45388f;
  --accent-strong: #8f7ce8;
  --danger: #b02a45;
  --danger-bg: #ffcfd8;
  --todo: #ffd8b5;
  --todo-ink: #8f4812;
  --doing: #c5e2ff;
  --doing-ink: #235287;
  --done: #c2eed4;
  --done-ink: #256642;
  --tint: 30%;
  --tint-ink: 70%;
  --shadow: 0 1px 2px rgb(52 48 74 / .04), 0 6px 20px rgb(52 48 74 / .06);
  --radius: 18px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font: 16px/1.45 ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(180deg, #e3d8ff 0%, #ffd9e8 55%, #ffe0c4 100%) fixed var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
}

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

/* Line icons from /icons.svg, sized and colored like the text around them. */
.icon {
  width: 1.2em;
  height: 1.2em;
  flex-shrink: 0;
  vertical-align: -.25em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-button { display: inline-grid; place-items: center; }
.icon-button .icon { width: 20px; height: 20px; }

/* Top bar */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, #e3d8ff 85%, transparent);
  backdrop-filter: blur(12px);
  padding: calc(16px + env(safe-area-inset-top)) 20px 12px;
}
.top-bar h1 { margin: 0; font-size: 1.5rem; font-weight: 700; letter-spacing: -.01em; }
.top-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.top-actions { display: flex; gap: 10px; }
.top-button { box-shadow: var(--shadow); }
#menu-button { position: relative; background: var(--surface); color: var(--accent-ink); }
#chat-button { background: var(--accent); color: var(--accent-ink); }
/* The frozen calendar is running out (calendar.js): a dot on the menu button and on its entry. */
.has-alert::after {
  content: "";
  position: absolute;
  top: 2px;
  right: 2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
}
.menu .has-alert::after { position: static; margin-left: auto; }

/* Login screen: the sheet style, as a card. */
.login { display: block; max-width: 420px; margin: 10dvh auto 0; border-radius: 28px; box-shadow: var(--shadow); }
.login h1 { margin: 0; text-align: center; font-size: 1.5rem; }
.login .hint { text-align: center; }
.login-logo { justify-self: center; border-radius: 18px; }
.login-error { margin: 0; color: var(--danger); font-weight: 600; }

/* Menu of the top bar, under its button. A popover: its UA styles are undone here. */
.menu {
  position: fixed;
  inset: calc(64px + env(safe-area-inset-top)) 20px auto auto;
  min-width: 240px;
  margin: 0;
  padding: 6px;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 4px rgb(52 48 74 / .06), 0 12px 32px rgb(52 48 74 / .16);
}
.menu:popover-open { display: grid; }
.menu button {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.menu button:hover { background: var(--field); }
.menu .icon { width: 20px; height: 20px; color: var(--accent-ink); }
.menu small { margin-left: auto; font-weight: 400; color: var(--muted); }
#push-button.is-on .icon { color: var(--done-ink); }
.chat-button { position: relative; }
.chat-button .count { position: absolute; top: -4px; right: -6px; background: var(--danger-bg); color: var(--danger); }

.count {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 .45em;
  border-radius: 99px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: .85rem;
  font-weight: 700;
  text-align: center;
  vertical-align: middle;
}
.count:empty { display: none; }

/* Segmented control */
.filters {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 99px;
  background: var(--accent);
}
.filters button {
  border: 0;
  background: transparent;
  padding: 6px 16px;
  border-radius: 99px;
  color: var(--accent-ink);
  font-weight: 600;
  cursor: pointer;
}
.filters button.is-active { background: var(--surface); color: var(--accent-ink); box-shadow: var(--shadow); }

/* Between the homework before and after the holidays. */
.holiday-separator {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin: 20px 0 4px;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--todo);
  color: var(--todo-ink);
  font-weight: 700;
}
.holiday-separator small { font-weight: 500; }

/* Homework list */
.list { padding: 4px 20px; }
.group h3 {
  margin: 20px 4px 10px;
  font-size: .9rem;
  font-weight: 700;
  color: var(--accent-ink);
}
.group.is-late h3 { color: var(--danger); }
.cards { display: grid; gap: 12px; }

.card {
  display: flex;
  gap: 12px;
  background: color-mix(in srgb, var(--color, var(--muted)) 16%, var(--surface));
  border-radius: var(--radius);
  padding: 14px 14px 14px 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .15s;
}
.card:active { transform: scale(.99); }
.card.is-done { opacity: .6; }
/* An évaluation (test in class) stands out, gold like a medal to win: outlined, its subject a gold badge. */
.card.is-evaluation { box-shadow: inset 0 0 0 2px var(--color), 0 6px 20px rgb(234 179 8 / .25); }
.card.is-evaluation .card-subject {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: linear-gradient(135deg, #fde047, #fb923c);
  color: #7c2d12;
}
.card.is-done .card-text { text-decoration: line-through; }
.card-main { flex: 1; min-width: 0; }
.card-subject {
  display: inline-block;
  padding: 1px 10px;
  border-radius: 99px;
  background: color-mix(in srgb, var(--color, var(--muted)) 38%, var(--surface));
  color: color-mix(in srgb, var(--color, var(--muted)) var(--tint-ink), var(--text));
  font-size: .78rem;
  font-weight: 700;
}
.card-text { margin: 6px 0 0; overflow-wrap: anywhere; white-space: pre-line; }
.card-meta { margin-top: 4px; font-size: .8rem; color: var(--danger); }
.card-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.card-chip.is-unread { background: var(--danger-bg); color: var(--danger); }
.card-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 99px;
  background: color-mix(in srgb, var(--surface) 75%, transparent);
  color: color-mix(in srgb, var(--color, var(--muted)) var(--tint-ink), var(--text));
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
}

.status {
  align-self: center;
  flex-shrink: 0;
  min-height: 36px;
  padding: 6px 14px;
  border: 0;
  border-radius: 99px;
  font-size: .85rem;
  font-weight: 700;
  cursor: pointer;
}
.status[data-status="todo"] { background: var(--todo); color: var(--todo-ink); }
.status[data-status="doing"] { background: var(--doing); color: var(--doing-ink); }
.status[data-status="done"] { background: var(--done); color: var(--done-ink); }

.empty { padding: 56px 16px; text-align: center; color: var(--muted); }
.empty b { display: block; margin-bottom: 8px; font-size: 2.5rem; color: var(--accent-strong); }
.empty .icon { stroke-width: 1.5; }

/* Bottom action bar */
.actions {
  position: fixed;
  inset: auto 0 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, #ffe0c4 85%, transparent);
  backdrop-filter: blur(12px);
}
.actions .btn { flex: 1; }
/* One pastel per action. */
#edit-scan { background: var(--done); color: var(--done-ink); }
#edit-dictate { background: var(--doing); color: var(--doing-ink); }
#edit-dictate.is-recording { background: var(--danger-bg); color: var(--danger); }

/* Undo toast, above the action bar. A popover (top layer, above dialogs): its UA styles are undone here. */
.toast {
  position: fixed;
  inset: auto 20px calc(88px + env(safe-area-inset-bottom));
  width: auto;
  margin: 0;
  border: 0;
  overflow: visible;
}
.toast:popover-open {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 18px;
  border-radius: 16px;
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 8px 28px rgb(0 0 0 / .18);
}
.toast span { flex: 1; }
.toast button {
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  cursor: pointer;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 50px;
  padding: 0 18px;
  border: 0;
  border-radius: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: filter .15s;
}
.btn:hover { filter: brightness(.97); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--field); color: var(--accent-ink); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-small { min-height: 38px; padding: 0 14px; border-radius: 12px; font-size: .9rem; }
.btn-block { width: 100%; }
.btn.is-recording { background: var(--danger-bg); color: var(--danger); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .65; } }
.btn:disabled { opacity: .5; cursor: default; }

.icon-button {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 1.15rem;
  cursor: pointer;
}

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

/* Dialogs: bottom sheet on mobile */
dialog::backdrop { background: rgb(40 36 60 / .35); backdrop-filter: blur(2px); }

.sheet {
  width: 100%;
  max-width: 100%;
  max-height: 92dvh;
  margin: auto 0 0;
  padding: 0;
  border: 0;
  border-radius: 28px 28px 0 0;
  background: var(--sheet);
  color: var(--text);
}
.sheet-body, .sheet-body-section {
  display: grid;
  gap: 16px;
}
.sheet-body { padding: 12px 20px calc(20px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { margin: 0; font-size: 1.25rem; font-weight: 700; }
.sheet-head .icon-button { background: var(--field); font-size: 1rem; }
.sheet-foot { display: flex; gap: 10px; }
.sheet-foot .btn { flex: 1; }
.sheet label { display: grid; gap: 6px; font-size: .85rem; font-weight: 600; color: var(--muted); }
/* File pickers are labels styled as buttons. */
.sheet label.btn { display: inline-flex; gap: 6px; font-weight: 700; color: var(--accent-ink); }
.sheet label.btn-small { font-size: .9rem; }
.sheet label.btn-primary { font-size: 1rem; color: var(--accent-ink); }
.sheet input:not([type=radio], [type=checkbox]), .sheet select, .sheet textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: var(--field);
  color: var(--text);
  font-size: 16px; /* prevents iOS auto-zoom */
  font-weight: 400;
}
.sheet input:focus, .sheet select:focus, .sheet textarea:focus { outline: none; border-color: var(--accent-strong); }
.hint { margin: 0; color: var(--muted); font-size: .9rem; }

.statuses { display: flex; gap: 8px; margin: 0; padding: 0; border: 0; }
.statuses legend { margin-bottom: 6px; padding: 0; font-size: .85rem; font-weight: 600; color: var(--muted); }
.sheet .statuses label {
  flex: 1;
  display: block;
  padding: 10px 4px;
  border-radius: 14px;
  background: var(--field);
  color: var(--text);
  text-align: center;
  font-weight: 600;
  cursor: pointer;
}
.statuses input { position: absolute; opacity: 0; pointer-events: none; }
.sheet .statuses label:has(input[value=todo]:checked) { background: var(--todo); color: var(--todo-ink); }
.sheet .statuses label:has(input[value=doing]:checked) { background: var(--doing); color: var(--doing-ink); }
.sheet .statuses label:has(input[value=done]:checked) { background: var(--done); color: var(--done-ink); }
.statuses label:has(input:focus-visible) { outline: 3px solid var(--accent-strong); outline-offset: 2px; }

.photo-buttons { display: flex; gap: 8px; }
/* PC: no camera, capture would just open the file picker a second way. */
@media (pointer: fine) { .camera-only { display: none; } }

.photos-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: .85rem;
  font-weight: 600;
  color: var(--muted);
}
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.thumb { position: relative; aspect-ratio: 1; overflow: hidden; border-radius: 14px; background: var(--line); }
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.thumb button {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: rgb(0 0 0 / .5);
  color: #fff;
  cursor: pointer;
}

/* Scan */
.scan-preview { width: 100%; max-height: 30dvh; object-fit: contain; border-radius: 14px; }
progress { width: 100%; accent-color: var(--accent-strong); }
.scan-items { display: grid; gap: 10px; }
.scan-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 10px;
  align-items: start;
  padding: 12px;
  border-radius: 16px;
  background: var(--field);
}
.scan-item input[type=checkbox] { width: 22px; height: 22px; margin-top: 10px; accent-color: var(--accent-strong); }
.scan-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.scan-fields textarea { grid-column: 1 / -1; }
.sheet .scan-item input:not([type=checkbox]), .sheet .scan-item select, .sheet .scan-item textarea { background: var(--surface); }
.scan-item:has(input[type=checkbox]:not(:checked)) .scan-fields { opacity: .5; }
.raw-text pre { max-height: 200px; overflow: auto; white-space: pre-wrap; font-size: .8rem; color: var(--muted); }

/* Chat */
.chat-messages {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 30dvh;
  max-height: 50dvh;
  overflow-y: auto;
  padding: 4px 0;
}
.bubble {
  justify-self: start;
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 20px 20px 20px 6px;
  background: var(--doing);
  color: var(--doing-ink);
}
.bubble.is-mine { justify-self: end; border-radius: 20px 20px 6px 20px; background: var(--accent); color: var(--accent-ink); }
.bubble p { margin: 2px 0 0; white-space: pre-line; overflow-wrap: anywhere; }
.bubble[data-message] { cursor: pointer; }
.bubble.is-pending { opacity: .6; }
.bubble-actions { display: none; gap: 6px; margin-top: 8px; }
.bubble.is-selected .bubble-actions { display: flex; }
.bubble-actions button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 0;
  border-radius: 99px;
  background: var(--surface);
  color: var(--accent-ink);
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
}
.bubble-actions [data-delete] { color: var(--danger); }
.chat-editing {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 12px;
  border-radius: 12px;
  background: var(--todo);
  color: var(--todo-ink);
  font-size: .9rem;
  font-weight: 600;
}
.chat-editing span { flex: 1; }
.household-welcome { margin: 0; padding: 10px 14px; border-radius: 14px; background: var(--field); font-size: .95rem; }
.household-welcome .icon { vertical-align: -3px; }
.calendar-outdated {
  margin: 0;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: .9rem;
}
.bubble-head { font-size: .75rem; font-weight: 600; opacity: .65; }
.bubble-ref {
  display: block;
  max-width: 100%;
  margin-top: 6px;
  padding: 2px 10px;
  border: 0;
  border-radius: 99px;
  background: color-mix(in srgb, var(--color) var(--tint), var(--surface));
  color: color-mix(in srgb, var(--color) var(--tint-ink), var(--text));
  font-size: .8rem;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.chat-form { display: grid; gap: 10px; }
/* A text field with its buttons (mic, send) on the right: chat and homework editor. */
.compose { display: flex; gap: 8px; align-items: end; }
.sheet .compose textarea { flex: 1; resize: none; }

/* Calendar */
.calendar-list { max-height: 70dvh; overflow-y: auto; }
.calendar-list h3 { margin: 4px 0 8px; font-size: .9rem; font-weight: 600; color: var(--muted); }
.calendar-list section + section h3 { margin-top: 20px; }
.calendar-list ul { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.cal-event {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--field);
}
.cal-event.is-holidays { background: color-mix(in srgb, var(--todo) 55%, var(--sheet)); }
.cal-event.is-past { opacity: .45; }
.cal-event.is-current { background: var(--done); color: var(--done-ink); }
.cal-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--doing);
  color: var(--doing-ink);
}
.cal-event.is-holidays .cal-icon { background: var(--todo); color: var(--todo-ink); }
.cal-main { flex: 1; min-width: 0; }
.cal-name { font-weight: 700; }
.cal-dates { font-size: .85rem; color: var(--muted); }
.cal-event.is-current .cal-dates { color: inherit; }
.cal-when { flex-shrink: 0; font-size: .8rem; font-weight: 700; color: var(--accent-ink); }
.cal-event.is-current .cal-when { color: inherit; }

/* Lessons */
.lessons-filters { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.sheet .lessons-filters select { width: auto; max-width: 45vw; }
.lessons-list { display: grid; align-content: start; gap: 8px; min-height: 40dvh; max-height: 62dvh; overflow-y: auto; }
.lesson {
  border-radius: 16px;
  background: color-mix(in srgb, var(--color) 12%, var(--surface));
}
.lesson summary {
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  list-style: none;
  cursor: pointer;
}
.lesson summary::-webkit-details-marker { display: none; }
.lesson-subject { font-size: .75rem; font-weight: 700; color: color-mix(in srgb, var(--color) var(--tint-ink), var(--text)); }
.lesson-title { font-weight: 700; }
.lesson[open] summary { border-bottom: 1px solid color-mix(in srgb, var(--color) 25%, var(--surface)); }
.lesson-body { padding: 4px 14px 14px; line-height: 1.5; overflow-x: auto; }
.lesson-body p { margin: 10px 0 0; }
.lesson-body ul, .lesson-body ol { margin: 10px 0 0; padding-left: 20px; }
.lesson-body li + li { margin-top: 4px; }
.lesson-body b { color: color-mix(in srgb, var(--color) var(--tint-ink), var(--text)); }
.lesson-body table { margin-top: 10px; border-collapse: collapse; font-size: .9rem; }
.lesson-body th, .lesson-body td { padding: 4px 8px; border: 1px solid color-mix(in srgb, var(--color) 25%, var(--surface)); text-align: center; }
.lesson-body th { background: color-mix(in srgb, var(--color) 15%, var(--surface)); }

/* Photo viewer */
.viewer {
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: 0;
  background: #111016;
}
.viewer[open] { display: flex; flex-direction: column; }
/* touch-action: the page must not zoom or scroll, the viewer handles the fingers (viewer.js). */
.viewer-stage { flex: 1; min-height: 0; display: grid; place-items: center; overflow: hidden; touch-action: none; }
.viewer img { user-select: none; -webkit-user-select: none; }
/* Wraps the image exactly, so the cover lines up with it. */
.viewer-frame { position: relative; }
.viewer img {
  display: block;
  max-width: 100vw;
  max-height: calc(100dvh - 64px - env(safe-area-inset-bottom));
}
/* Recite a lesson: hides the photo below --reveal. */
.viewer-mask {
  position: absolute;
  inset: var(--reveal, 0%) 0 0;
  display: flex;
  justify-content: center;
  padding-top: 12px;
  overflow: hidden;
  border-top: 3px dashed var(--accent-strong);
  background: var(--surface);
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  gap: 6px;
}
.viewer-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: calc(64px + env(safe-area-inset-bottom));
  padding: 0 8px env(safe-area-inset-bottom);
  color: #fff;
}
.viewer-bar .icon-button { color: #fff; }
.viewer-close {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  right: 8px;
  background: rgb(255 255 255 / .15);
  color: #fff;
}

/* Desktop */
@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px max(24px, calc((100vw - 1100px) / 2));
  }
  .top-row { gap: 16px; margin: 0; }
  .menu { top: 68px; right: max(24px, calc((100vw - 1100px) / 2)); }
  .list { max-width: 1100px; margin: 0 auto; padding: 8px 24px 100px; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
  .card:hover { box-shadow: 0 2px 4px rgb(52 48 74 / .05), 0 10px 28px rgb(52 48 74 / .1); }
  .actions { inset: auto 24px 24px auto; padding: 0; background: transparent; backdrop-filter: none; }
  .actions .btn { flex: none; box-shadow: 0 8px 24px rgb(52 48 74 / .14); }
  .toast { inset: auto 24px 92px auto; width: 380px; }
  .sheet { width: 560px; max-height: 88dvh; margin: auto; border-radius: 28px; }
}
