/* Uchi — one accent (emerald), warm neutrals, system font (SF on iPhone). */
:root {
  color-scheme: light;
  --canvas: #f7f7f5;
  --surface: #ffffff;
  --text: #1c1c1e;
  --text-2: #5f5f66;
  --text-3: #8e8e93;
  --line: rgba(60, 60, 67, 0.14);
  --accent: #047857;
  --accent-hover: #065f46;
  --accent-soft: #e3f5ec;
  --accent-ink: #065f46;
  --warn: #b45309;
  --warn-soft: #fdf1e0;
  --danger: #be123c;
  --danger-soft: #fdecef;
  --shadow: 0 1px 2px rgba(20, 20, 20, 0.04), 0 12px 32px -12px rgba(20, 20, 20, 0.12);
  --r-lg: 24px;
  --r-md: 16px;
  --r-sm: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --canvas: #111113;
    --surface: #1c1c1f;
    --text: #f2f2f4;
    --text-2: #b0b0b8;
    --text-3: #7c7c85;
    --line: rgba(235, 235, 245, 0.14);
    --accent: #34d399;
    --accent-hover: #6ee7b7;
    --accent-soft: #10372b;
    --accent-ink: #a7f3d0;
    --warn: #fbbf24;
    --warn-soft: #3a2a0c;
    --danger: #fb7185;
    --danger-soft: #3b1219;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px -12px rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; touch-action: manipulation; }
body {
  margin: 0; min-height: 100dvh; background: var(--canvas); color: var(--text);
  font: 17px/1.5 var(--font); -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; line-height: 1.15; letter-spacing: -0.02em; text-wrap: balance; }
h1 { font-size: clamp(1.75rem, 6vw, 2.4rem); font-weight: 800; }
h2 { font-size: 1.3rem; font-weight: 750; }
h3 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0; }
a { color: var(--accent); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.small { font-size: 0.8125rem; color: var(--text-3); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app { max-width: 760px; margin: 0 auto; padding: calc(16px + var(--safe-t)) 16px calc(24px + var(--safe-b)); }
.app.wide { max-width: 1180px; }
.stack { display: grid; gap: 16px; }
.stack-lg { display: grid; gap: 28px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > * { min-width: 0; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* ---------- buttons ---------- */
button, .btn {
  font: inherit; font-weight: 650; border: 0; cursor: pointer; border-radius: 999px;
  min-height: 48px; padding: 12px 20px; display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; text-decoration: none; transition: transform 120ms ease-out, background-color 150ms ease-out;
  -webkit-user-select: none; user-select: none;
}
button:active, .btn:active { transform: translateY(1px) scale(0.985); }
button:disabled { opacity: 0.55; cursor: default; }
button:focus-visible, .btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.primary { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .primary { color: #052e22; } }
.primary:hover { background: var(--accent-hover); }
.secondary { background: var(--surface); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.secondary:hover { background: var(--accent-soft); }
.ghost { background: transparent; color: var(--accent); padding-inline: 12px; }
.danger-btn { background: var(--danger-soft); color: var(--danger); }
.block { width: 100%; }
.big { min-height: 64px; font-size: 1.15rem; border-radius: var(--r-md); }
.chip {
  min-height: 40px; padding: 8px 14px; border-radius: 999px; background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line); color: var(--text); font-weight: 600; font-size: 0.95rem;
}
.chip[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-ink); box-shadow: inset 0 0 0 1.5px var(--accent); }

/* ---------- cards & forms ---------- */
.card { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 20px; }
.card.tight { padding: 14px 16px; border-radius: var(--r-md); }
.card.accent { background: var(--accent-soft); border-color: transparent; box-shadow: none; }
.card.warn { background: var(--warn-soft); border-color: transparent; box-shadow: none; }
.card.danger { background: var(--danger-soft); border-color: transparent; box-shadow: none; }
label.field { display: grid; gap: 6px; font-weight: 600; font-size: 0.95rem; }
label.field .hint { font-weight: 400; color: var(--text-3); font-size: 0.8125rem; }
input, textarea, select {
  font: inherit; font-size: 17px; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px 14px; width: 100%; min-height: 48px;
}
textarea { resize: vertical; min-height: 96px; line-height: 1.45; }
select { appearance: none; background-image: none; }
.error { color: var(--danger); font-size: 0.9rem; min-height: 1.2em; }
.code-input { font-family: var(--mono); letter-spacing: 0.25em; text-transform: uppercase; font-size: 1.5rem; text-align: center; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.topbar .title { flex: 1; min-width: 0; }
.topbar .title h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { min-height: 44px; min-width: 44px; padding: 0 12px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); color: var(--text); }
.logo { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -0.02em; font-size: 1.15rem; }
.logo img { width: 32px; height: 32px; border-radius: 9px; }

/* ---------- child home ---------- */
.hello { display: grid; gap: 6px; margin: 8px 0 24px; }
.hello .sub { color: var(--text-2); font-size: 1.05rem; }
.home-actions { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .home-actions { grid-template-columns: 2fr 1fr; } }
.camera-btn { min-height: 120px; border-radius: var(--r-lg); font-size: 1.25rem; flex-direction: column; gap: 6px; }
.camera-btn .icon { width: 36px; height: 36px; }
.subjects { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: none; }
.subjects::-webkit-scrollbar { display: none; }
.task-list { display: grid; gap: 8px; }
.task-item {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; text-align: left;
  width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 14px 16px; color: var(--text); font-weight: 500; min-height: 56px;
}
.task-item .preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 0.75rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink); white-space: nowrap; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.grey { background: var(--canvas); color: var(--text-2); box-shadow: inset 0 0 0 1px var(--line); }

/* ---------- chat ---------- */
.chat { display: grid; gap: 10px; padding-bottom: 8px; }
.msg { max-width: 88%; padding: 12px 16px; border-radius: 20px; white-space: pre-wrap; overflow-wrap: anywhere; animation: rise 260ms cubic-bezier(.2,.9,.3,1.2) both; }
.msg.tutor { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; justify-self: start; }
.msg.child { background: var(--accent); color: #fff; border-bottom-right-radius: 6px; justify-self: end; }
@media (prefers-color-scheme: dark) { .msg.child { color: #052e22; } }
.msg.notice { background: var(--warn-soft); justify-self: stretch; max-width: 100%; border-radius: var(--r-md); }
.msg.good { background: var(--accent-soft); border-color: transparent; color: var(--accent-ink); font-weight: 600; }
.msg.bad { background: var(--danger-soft); border-color: transparent; }
.msg.example { background: var(--surface); border: 1.5px dashed var(--accent); justify-self: stretch; max-width: 100%; }
.msg .meta { margin-top: 6px; font-size: 0.78rem; color: var(--text-3); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.msg .say { min-height: 32px; padding: 4px 10px; font-size: 0.82rem; background: var(--canvas); color: var(--text-2); }
.msg img.thumb { display: block; max-width: 220px; max-height: 220px; border-radius: 12px; margin-top: 6px; object-fit: cover; }
.thinking { justify-self: start; width: 140px; height: 44px; border-radius: 20px; border-bottom-left-radius: 6px; background: linear-gradient(90deg, var(--surface) 0%, var(--accent-soft) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.3s linear infinite; border: 1px solid var(--line); }
.confirm-box { display: grid; gap: 12px; }
.confirm-text { white-space: pre-wrap; font-size: 1.05rem; line-height: 1.55; }
.confirm-text mark { background: var(--warn-soft); color: inherit; border-radius: 4px; padding: 0 2px; box-shadow: inset 0 -2px 0 var(--warn); }

.composer { position: sticky; bottom: 0; padding: 22px 0 calc(10px + var(--safe-b)); background: linear-gradient(to top, var(--canvas) calc(100% - 22px), transparent); display: grid; gap: 10px; }
.help-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.help-row button { font-size: 0.95rem; white-space: nowrap; padding-inline: 10px; min-width: 0; }
.help-row .call, .help-row .finish { grid-column: 1 / -1; }
.send-row { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: end; }
.send-row textarea { min-height: 48px; max-height: 140px; border-radius: 24px; padding: 12px 16px; }
.icon-btn { min-width: 48px; width: 48px; padding: 0; border-radius: 50%; }
.icon { width: 22px; height: 22px; flex: none; }
.done-banner { text-align: center; display: grid; gap: 12px; justify-items: center; padding: 24px 16px; }
.done-banner .star { width: 64px; height: 64px; color: var(--accent); animation: pop 520ms cubic-bezier(.2,.9,.3,1.4) both; }

/* ---------- lock ---------- */
.lock { min-height: 70dvh; display: grid; align-content: center; gap: 18px; }
.pin { font-family: var(--mono); font-size: 2rem; letter-spacing: 0.5em; text-align: center; }

/* ---------- parent ---------- */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 20px; padding: 0 16px 4px; scrollbar-width: none; position: sticky; top: 0; z-index: 5; background: var(--canvas); padding-top: 8px; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { text-decoration: none; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1.4fr 1fr; } }
.kid-card { display: grid; gap: 12px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.stat { background: var(--canvas); border-radius: var(--r-sm); padding: 10px; display: grid; gap: 2px; }
.stat b { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: 0.75rem; color: var(--text-2); }
.flag { display: grid; gap: 6px; padding: 14px 16px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line); }
.flag.high { background: var(--danger-soft); border-color: transparent; }
table.list { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
table.list td, table.list th { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.list th { font-size: 0.78rem; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.ref-box { font-family: var(--mono); font-size: 0.9rem; white-space: pre-wrap; background: var(--canvas); border-radius: var(--r-sm); padding: 12px; }
.photo-row { display: flex; gap: 8px; flex-wrap: wrap; }
.photo-row img { width: 140px; height: 140px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); }
.meter { height: 8px; border-radius: 999px; background: var(--canvas); overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--accent); transform-origin: left; }
.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); background: var(--text); color: var(--canvas); padding: 12px 18px; border-radius: 14px; font-weight: 600; z-index: 20; max-width: calc(100% - 32px); animation: rise 240ms ease-out both; }
.skeleton { border-radius: var(--r-md); background: linear-gradient(90deg, var(--surface) 0%, var(--line) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.3s linear infinite; }
.boot { height: 120px; }
.empty { text-align: left; display: grid; gap: 8px; padding: 18px; border-radius: var(--r-md); border: 1.5px dashed var(--line); color: var(--text-2); }
.footer-note { margin-top: 28px; font-size: 0.75rem; color: var(--text-3); text-align: center; }
.footer-note a { color: var(--text-3); }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(0.6); } to { opacity: 1; transform: none; } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}
