:root {
  --bg: #E6EAE2;            /* lichen */
  --ink: #1F2A2E;           /* slate */
  --muted: #66706B;
  --them: #FBFBF7;
  --line: rgba(31, 42, 46, 0.11);
  --bar: rgba(230, 234, 226, 0.88);
  --lamp: #E3A535;          /* on-air amber */
  --lamp-off: #A9B1AC;
  --danger: #A63D2C;
  --radius: 20px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141A24;
    --ink: #E4E7EB;
    --muted: #8D96A3;
    --them: #232B38;
    --line: rgba(228, 231, 235, 0.10);
    --bar: rgba(20, 26, 36, 0.88);
    --lamp-off: #4A5362;
    --danger: #E07A66;
  }
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
}
body {
  font: 17px/1.36 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* The app shell tracks the *visual* viewport so the composer rides above the iOS keyboard. */
#app {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--app-h, 100dvh);
  transform: translateY(var(--vv-top, 0px));
  display: flex;
  flex-direction: column;
}

/* ── header: her photo, name, and live status (laid out like a Messages conversation) ── */
.top {
  padding: calc(env(safe-area-inset-top) + 4px) 18px 7px;
  background: var(--bar);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  backdrop-filter: blur(16px) saturate(1.2);
  border-bottom: 1px solid var(--line);
  z-index: 2;
}
.who {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  width: 100%; padding: 2px 0 0; margin: 0;
  background: none; border: 0; text-align: center; cursor: pointer;
}
.avatar {
  position: relative; flex: none; display: grid; place-items: center;
  width: 52px; height: 52px; border-radius: 50%;
  background: linear-gradient(180deg, #A6ACB9, #858B98) center / cover no-repeat;
  color: #fff;
}
.avatar.has-photo { background-color: #858B98; }
.initials {
  font: 500 23px/1 ui-rounded, -apple-system, "SF Pro Rounded", system-ui, sans-serif;
  letter-spacing: .01em;
}
.avatar.big { width: 96px; height: 96px; }
.avatar.big .initials { font-size: 42px; }
.lamp {
  flex: none; width: 12px; height: 12px; margin-top: 9px;
  border-radius: 50%;
  background: var(--lamp-off);
  transition: background-color .6s, box-shadow .6s;
}
.avatar .lamp {                     /* awake/asleep, as a small badge on her photo */
  position: absolute; right: -1px; bottom: 0; margin: 0;
  width: 15px; height: 15px; border: 2.5px solid var(--bg);
}
.lamp.awake {
  background: var(--lamp);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--lamp) 22%, transparent),
              0 0 14px 2px color-mix(in srgb, var(--lamp) 50%, transparent);
  animation: glow 5s ease-in-out infinite;
}
.avatar .lamp.awake { box-shadow: 0 0 8px 1px color-mix(in srgb, var(--lamp) 55%, transparent); animation: none; }
@keyframes glow {
  50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--lamp) 12%, transparent),
                    0 0 20px 4px color-mix(in srgb, var(--lamp) 32%, transparent); }
}
.name {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 15px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.2;
}
.chev { width: 7px; height: 11px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.status {
  display: block; max-width: 100%; min-height: 1.3em;
  font-size: 13px; font-style: italic; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── thread ─────────────────────────────────────────────── */
.thread {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 10px 12px 10px;
}
.older { text-align: center; margin: 6px 0 2px; }
.older button, .text-btn {
  background: none; border: 0; padding: 8px 10px; cursor: pointer;
  color: var(--accent); font-size: 15px; font-weight: 600;
}
@media (prefers-color-scheme: dark) {
  .older button, .text-btn { color: color-mix(in srgb, var(--accent) 55%, white); }
}
.day { margin: 20px 0 6px; text-align: center; font-size: 13px; font-weight: 600; color: var(--muted); }
.empty { margin: 28vh 24px 0; text-align: center; color: var(--muted); }

.row { display: flex; flex-direction: column; align-items: flex-start; margin-top: 10px; }
.row.me { align-items: flex-end; }
.bubble {
  max-width: min(80%, 34rem);
  margin-top: 3px;
  padding: 8px 13px 9px;
  border-radius: var(--radius);
  background: var(--them);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 1px 0 var(--line);
}
.them .bubble:last-of-type { border-bottom-left-radius: 7px; }
.me .bubble { background: var(--accent); color: #fff; box-shadow: none; }
.me .bubble:last-of-type { border-bottom-right-radius: 7px; }
.bubble.pending { opacity: .6; }
.stamp { margin: 4px 8px 0; font-size: 12px; color: var(--muted); }

.bubble.error {
  background: transparent; box-shadow: none;
  border: 1px dashed var(--danger); color: var(--danger);
  font-size: 15px;
}

.typing { display: inline-flex; gap: 5px; padding: 13px 15px; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted); opacity: .45;
  animation: bob 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes bob { 30% { transform: translateY(-3px); opacity: .9; } 60% { transform: none; opacity: .45; } }
.tool-status { margin: 4px 8px 0; font-size: 13px; font-style: italic; color: var(--muted); }
.tool-status:empty { display: none; }

/* ── composer ───────────────────────────────────────────── */
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: var(--bar);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  backdrop-filter: blur(16px) saturate(1.2);
  border-top: 1px solid var(--line);
}
.kb-open .composer { padding-bottom: 8px; }
.slot:empty { display: none; }
#input {
  flex: 1; min-width: 0;
  max-height: 8.4em;
  margin: 0; padding: 8px 14px;
  resize: none;
  font: inherit; font-size: 17px; line-height: 1.3;   /* ≥16px stops Safari zooming in */
  color: var(--ink);
  background: var(--them);
  border: 1px solid var(--line);
  border-radius: 20px;
  outline: none;
}
#input:focus { border-color: color-mix(in srgb, var(--accent) 60%, transparent); }
#send {
  flex: none; display: grid; place-items: center;
  width: 38px; height: 38px; margin-bottom: 0;
  border: 0; border-radius: 50%;
  background: var(--accent); color: #fff; cursor: pointer;
  transition: opacity .2s, transform .15s;
}
#send:disabled { opacity: .3; cursor: default; }
#send:not(:disabled):active { transform: scale(.92); }

/* ── diary sheet ────────────────────────────────────────── */
.sheet {
  width: 100%; max-width: 40rem; max-height: 84dvh;
  margin: auto auto 0; padding: 0;
  border: 0; border-radius: 22px 22px 0 0;
  background: var(--bg); color: var(--ink);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .18);
}
.sheet[open] { display: flex; flex-direction: column; animation: rise .28s ease-out; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.sheet::backdrop { background: rgba(10, 14, 20, .38); }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 10px 6px 20px;
}
.sheet-head h2 { margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -0.01em; }
.sheet-body {
  overflow-y: auto; padding: 0 20px calc(24px + env(safe-area-inset-bottom));
}
.now-line { margin: 0 0 14px; color: var(--muted); font-style: italic; }
.entries { margin: 0; padding: 0; list-style: none; }
.entry { display: grid; grid-template-columns: 4.9em 1fr; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.entry time { font-size: 14px; color: var(--muted); padding-top: 2px; font-variant-numeric: tabular-nums; }
.entry p { margin: 0; line-height: 1.45; }
.entry.plan p, .entry.diary p { font-style: italic; }
.sheet h3 { margin: 22px 0 6px; font-size: 15px; font-weight: 650; }
.today {
  margin: 0 0 14px; padding: 12px 14px;
  border-radius: 16px; background: var(--them); box-shadow: 0 1px 0 var(--line);
}
.today-student { margin: 0 0 8px; font-size: 14px; color: var(--muted); }
.today-row { display: grid; grid-template-columns: 4.9em 1fr; gap: 10px; padding: 6px 0; }
.today-row + .today-row { border-top: 1px solid var(--line); }
.today-label { font-size: 14px; color: var(--muted); padding-top: 1px; }
.today-value { line-height: 1.4; }
.class-line.done { color: var(--muted); }
.class-time { font-variant-numeric: tabular-nums; font-size: 14px; color: var(--muted); }
.reading + .reading { margin-top: 8px; }
.bar { height: 5px; margin: 5px 0 3px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 3px; background: var(--lamp); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tag {
  display: inline-block; margin-right: 6px; padding: 1px 7px;
  border-radius: 999px; font-size: 12px; font-style: normal; vertical-align: 1px;
  color: var(--muted); border: 1px solid var(--line);
}
.lately { margin: 0; padding-left: 1.1em; line-height: 1.45; }
.lately li + li { margin-top: 7px; }
.take { font-size: 14px; color: var(--muted); font-style: italic; }
.arcs { margin: 0; padding-left: 1.1em; line-height: 1.45; }
.arcs li + li { margin-top: 4px; }
.dev { margin-top: 26px; padding-top: 12px; border-top: 1px solid var(--line); }
.dev p { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.dev-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 7px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--them); font-size: 14px;
}
.chip:disabled { opacity: .5; }

/* ── gifts ──────────────────────────────────────────────── */
.gift-btn {
  flex: none; display: grid; place-items: center;
  width: 38px; height: 38px; padding: 0;
  border: 1px solid var(--line); border-radius: 50%;
  background: var(--them); color: var(--muted); cursor: pointer;
}
.gift-btn:active { transform: scale(.92); }
.gift-form { display: flex; flex-direction: column; gap: 12px; margin-bottom: 8px; }
.gift-form .field { display: flex; flex-direction: column; gap: 5px; }
.gift-form label, .field-label { font-size: 14px; color: var(--muted); }
.gift-form input, .gift-form select, .gift-form textarea {
  font: inherit; font-size: 17px; padding: 9px 12px; width: 100%;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--them); color: var(--ink);
}
.gift-form textarea { resize: vertical; min-height: 3.2em; }
.gift-form .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.hint { margin: 0 0 14px; font-size: 14px; color: var(--muted); font-style: italic; }
.gift-error { min-height: 1.2em; margin: 0; font-size: 14px; color: var(--danger); }
.gift-list { margin: 0; padding: 0; list-style: none; }
.gift-list li {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 8px 0; border-top: 1px solid var(--line); line-height: 1.4;
}
.gift-list .text-btn { padding: 2px 4px; font-size: 14px; flex: none; }

/* ── her contact card (top of the diary sheet) and the photo cropper ── */
.card { display: flex; flex-direction: column; align-items: center; gap: 4px; margin: 2px 0 16px; }
.card-actions { display: flex; gap: 6px; }
.card-actions .text-btn { padding: 6px 8px; }
#photo .sheet-head h2 { flex: 1; text-align: center; }
#photo .sheet-head { padding: 10px 6px 6px; }
.text-btn.strong { font-weight: 700; }
.text-btn:disabled { opacity: .45; }
.crop-body { display: flex; flex-direction: column; align-items: center; }
.crop {
  position: relative; width: min(78vw, 320px); aspect-ratio: 1; margin: 8px auto 16px;
  overflow: hidden; border-radius: 16px; background: #000;
  touch-action: none; cursor: grab;
}
.crop img {
  position: absolute; left: 0; top: 0; max-width: none;
  transform-origin: 0 0; pointer-events: none; user-select: none; -webkit-user-select: none;
}
.crop::after {                      /* the circle she'll appear in; outside it is dimmed */
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, .55); pointer-events: none;
}
#crop-zoom { width: min(78vw, 320px); accent-color: var(--accent); }
#photo .hint { margin: 10px 0 0; text-align: center; }
#photo .hint.bad { color: var(--danger); font-style: normal; }

/* ── login ──────────────────────────────────────────────── */
.login {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center; padding: 24px;
  background: var(--bg);
}
.login[hidden] { display: none; }
.login-card { width: 100%; max-width: 20rem; display: flex; flex-direction: column; gap: 10px; }
.login-card .lamp { margin: 0 0 6px; }
.login-card h1 { margin: 0 0 12px; font-size: 30px; font-weight: 650; letter-spacing: -0.02em; }
.login-card label { font-size: 15px; color: var(--muted); }
.login-card input {
  font: inherit; font-size: 17px; padding: 11px 14px;
  border-radius: 14px; border: 1px solid var(--line);
  background: var(--them); color: var(--ink);
}
.login-error { min-height: 1.3em; margin: 0; font-size: 14px; color: var(--danger); }
.primary {
  padding: 12px; border: 0; border-radius: 14px; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 600;
}

/* ── the disguise: an algebra practice test page (app/decoy.py) ──
   Always light, nothing reacts to touch, and nothing can be selected, so it reads as a page
   that has stopped responding. */
#decoy {
  position: fixed; inset: 0; z-index: 100;
  width: 100%; height: 100%; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0; outline: none;
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  background: #fff; color: #333; color-scheme: light;
  font: 16px/1.4 -apple-system, "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
#decoy:not([open]) { display: none; }
#decoy::backdrop { background: #fff; }
.d-top {
  display: flex; align-items: center; gap: 26px;
  padding: calc(env(safe-area-inset-top) + 16px) 22px 6px;
}
.d-logo { display: flex; flex-direction: column; align-items: flex-start; margin-right: auto; }
.d-mark {
  font: 900 36px/0.9 "Arial Black", "Helvetica Neue", Arial, sans-serif;
  letter-spacing: -0.045em; color: #2F6EC4;
}
.d-sub {
  margin-top: 5px; padding: 2px 7px 1px; border-radius: 2px;
  background: #F2C230; color: #1D1D1D;
  font-size: 10.5px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase;
}
.d-icon { width: 30px; height: 30px; fill: none; stroke: #222; stroke-width: 2; stroke-linecap: round; }
.d-rule { height: 56px; margin: 0 10px; border-bottom: 2px solid #D5D5D5; }
.d-page { padding: 22px 16px 130px; background: #F5F5F5; }
.d-title {
  margin: 10px 4px 40px;
  font: 800 clamp(32px, 10.4vw, 50px)/1.02 "Helvetica Neue", Helvetica, Arial, sans-serif;
  letter-spacing: -0.02em; text-transform: uppercase; color: #333;
}
.d-q h2 { margin: 0 0 22px; font-size: clamp(19px, 5.9vw, 24px); font-weight: 700; line-height: 1.3; color: #333; }
.d-num { margin-right: 8px; }
.d-eq, .choices .math, .d-q h2 .math {
  font-family: "Times New Roman", "STIX Two Text", Times, Georgia, serif;
}
.d-eq {
  margin: 0 0 22px 18px; padding: 2px 0 2px 16px; border-left: 5px solid #3472C5;
  font-size: clamp(19px, 6vw, 25px); white-space: nowrap;
}
.d-q h2 .math { font-weight: 400; }
.d-eq b { font-family: -apple-system, Helvetica, Arial, sans-serif; font-size: .85em; }
.choices { list-style: none; margin: 0 0 30px 22px; padding: 0; }
.choices li { display: flex; align-items: baseline; gap: 10px; margin: 0 0 20px; }
.letter { flex: none; width: 1.35em; font-size: clamp(17px, 5.2vw, 21px); color: #333; }
.choices .math { font-size: clamp(17px, 5.3vw, 22px); }
#decoy i { font-style: italic; }
#decoy sup { font-size: .66em; line-height: 0; vertical-align: .62em; }
#decoy .op { margin: 0 .24em; }
#decoy .n { position: relative; padding: 12px 6px; margin: 0 -6px; }   /* easy to hit, looks like plain text */
.show-answer {
  width: min(100%, 330px); margin: 4px auto 12px; padding: 14px;
  border-radius: 6px; background: #3472C5; color: #fff;
  text-align: center; font-size: 22px;
}
.report { margin-bottom: 64px; text-align: center; font-size: 15px; text-decoration: underline; color: #222; }
.graph { display: block; width: min(76%, 260px); margin: 0 auto 26px; background: #fff; border: 1px solid #C9C9C9; }
.graph path { fill: none; stroke: #DDD; stroke-width: 1; }
.graph .axis { stroke: #555; fill: #555; stroke-width: 1.3; }
.graph .line { stroke: #2F6EC4; stroke-width: 2.6; }
.graph text { font: italic 14px "Times New Roman", serif; fill: #555; }
.d-foot { margin: 0; text-align: center; font-size: 14px; color: #777; }
.d-a11y {
  position: fixed; left: 18px; bottom: calc(env(safe-area-inset-bottom) + 18px);
  display: grid; place-items: center; width: 58px; height: 58px; border-radius: 50%;
  background: #1D4ED8; border: 3px solid #fff; box-shadow: 0 0 0 3px #1D4ED8;
}
.d-a11y svg { width: 32px; height: 32px; fill: none; stroke: #fff; stroke-width: 2.2; stroke-linecap: round; }
.d-a11y circle { fill: #fff; stroke: none; }

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