/* Friday — paper, ink and a red pen. */
:root {
  --paper: #F7F2E8; --paper-2: #EFE7D6; --paper-3: #E6DCC6;
  --ink: #1C2433; --ink-2: #4A5468; --ink-3: #8A92A3;
  --red: #D6283A; --red-ink: #B51F2E; --red-soft: rgba(214, 40, 58, .14);
  --green: #2E7D5B; --green-soft: rgba(46, 125, 91, .14);
  --amber: #C98A1B; --amber-soft: rgba(201, 138, 27, .16);
  --blue: #2F5FA8; --blue-soft: rgba(47, 95, 168, .14);
  --line: rgba(28, 36, 51, .12); --shadow: 0 1px 2px rgba(28, 36, 51, .06), 0 8px 24px rgba(28, 36, 51, .08);
  --radius: 14px; --font: 'Inter', system-ui, -apple-system, sans-serif; --serif: 'Fraunces', Georgia, serif; --hand: 'Caveat', cursive;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --paper: #171A21; --paper-2: #1F232C; --paper-3: #2A2F3A;
  --ink: #F1ECE0; --ink-2: #B8B3A6; --ink-3: #7E8290;
  --red: #FF5A6A; --red-ink: #FF8A95; --red-soft: rgba(255, 90, 106, .18);
  --green: #5CC396; --green-soft: rgba(92, 195, 150, .16);
  --amber: #E8B04B; --amber-soft: rgba(232, 176, 75, .18);
  --blue: #7FA6E8; --blue-soft: rgba(127, 166, 232, .16);
  --line: rgba(241, 236, 224, .12); --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
} }
:root[data-theme="dark"] {
  --paper: #171A21; --paper-2: #1F232C; --paper-3: #2A2F3A;
  --ink: #F1ECE0; --ink-2: #B8B3A6; --ink-3: #7E8290;
  --red: #FF5A6A; --red-ink: #FF8A95; --red-soft: rgba(255, 90, 106, .18);
  --green: #5CC396; --green-soft: rgba(92, 195, 150, .16);
  --amber: #E8B04B; --amber-soft: rgba(232, 176, 75, .18);
  --blue: #7FA6E8; --blue-soft: rgba(127, 166, 232, .16);
  --line: rgba(241, 236, 224, .12); --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.45;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
  background-image: radial-gradient(1200px 500px at 50% -200px, rgba(214,40,58,.05), transparent 70%);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
h1, h2, h3 { margin: 0; font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 17px; }
p { margin: 0; }
.muted { color: var(--ink-2); } .small { font-size: 13px; } .grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; } .gap { gap: 10px; } .wrap { flex-wrap: wrap; }
[hidden] { display: none !important; }

/* screens */
.screen { display: none; min-height: 100%; padding: calc(var(--sat) + 18px) 16px calc(var(--sab) + 92px); max-width: 1100px; margin: 0 auto; }
body[data-screen="home"] #s-home, body[data-screen="scan"] #s-scan, body[data-screen="review"] #s-review,
body[data-screen="students"] #s-students, body[data-screen="settings"] #s-settings { display: block; }
body[data-screen="scan"] #s-scan { padding: 0; max-width: none; }
body[data-screen="scan"] .tabs, body[data-screen="review"] .tabs { display: none; }
body[data-screen="review"] #s-review { padding-bottom: calc(var(--sab) + 24px); }

.top { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 18px; }
.top.compact { align-items: center; margin-bottom: 10px; }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .14em; color: var(--red); font-weight: 600; }
.title { font-size: 40px; line-height: 1; font-weight: 700; }
.title .dot { color: var(--red); }
.sub { color: var(--ink-2); margin-top: 8px; max-width: 46ch; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--paper-2); color: var(--ink); border-radius: 999px; padding: 10px 16px; font-weight: 600; text-decoration: none; transition: transform .08s, background .15s; }
.btn:active { transform: scale(.98); }
.btn svg { width: 20px; height: 20px; }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: var(--red-soft); }
.btn.link { background: none; border: none; color: var(--red); padding: 6px 2px; text-decoration: underline; text-underline-offset: 3px; }
.btn.big { padding: 16px 20px; font-size: 16px; width: 100%; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--paper-2); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.mic.on { background: var(--red); color: #fff; border-color: var(--red); animation: pulse 1.2s infinite; }
#btnSpeakComment.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 var(--red-soft);} 50% { box-shadow: 0 0 0 8px transparent; } }
.actions-row { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; margin-bottom: 14px; }
@media (max-width: 560px) { .actions-row { grid-template-columns: 1fr; } }

/* toggle */
.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle span { width: 40px; height: 24px; border-radius: 999px; background: var(--paper-3); position: relative; transition: background .15s; flex: none; }
.toggle span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.toggle input:checked + span { background: var(--green); }
.toggle input:checked + span::after { transform: translateX(16px); }
.toggle em { font-style: normal; }
.toggle.small span { width: 34px; height: 20px; } .toggle.small span::after { width: 14px; height: 14px; } .toggle.small input:checked + span::after { transform: translateX(14px); }
.toggle.small em { font-size: 13px; }

/* cards & fields */
.card { background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head .chips { justify-content: flex-start; }
.card > h2 { margin-bottom: 6px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12px; color: var(--ink-2); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--paper); border-radius: 10px; padding: 10px 12px; outline: none; margin: 4px 0;
}
textarea { resize: vertical; min-height: 44px; }
input:focus, select:focus, textarea:focus { border-color: var(--ink-3); }
.inline-input { border: none; background: transparent; font-family: var(--serif); font-size: 22px; font-weight: 600; width: 100%; padding: 0; outline: none; }
.inline-input::placeholder { color: var(--ink-3); font-style: italic; }

/* pile */
.pile { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.copy { display: flex; gap: 12px; align-items: center; background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; text-align: left; box-shadow: var(--shadow); position: relative; }
.copy .thumb { width: 56px; height: 72px; border-radius: 6px; object-fit: cover; background: var(--paper-3); flex: none; border: 1px solid var(--line); }
.copy .name { font-weight: 600; } .copy .name.unnamed { color: var(--ink-3); font-style: italic; }
.copy .meta { font-size: 13px; color: var(--ink-2); }
.copy .grade { margin-left: auto; font-family: var(--serif); font-size: 22px; font-weight: 700; color: var(--red); flex: none; }
.copy .grade small { font-size: 12px; color: var(--ink-3); font-weight: 500; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.status.queued { background: var(--paper-3); color: var(--ink-2); }
.status.grading { background: var(--amber-soft); color: var(--amber); }
.status.review { background: var(--red-soft); color: var(--red); }
.status.done { background: var(--green-soft); color: var(--green); }
.status.error { background: var(--red-soft); color: var(--red); }
.pile-group { grid-column: 1 / -1; display: flex; align-items: baseline; justify-content: space-between; margin-top: 8px; }
.pile-group h3 { font-size: 15px; }
.batchbar { display: flex; align-items: center; gap: 10px; background: var(--amber-soft); color: var(--ink); border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; font-size: 14px; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--red); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 48px 16px; color: var(--ink-2); }
.empty-art { height: 90px; position: relative; margin-bottom: 16px; }
.empty-art .sheet { position: absolute; left: 50%; top: 10px; width: 64px; height: 80px; background: var(--paper-2); border: 1px solid var(--line); border-radius: 6px; transform: translateX(-50%) rotate(-8deg); box-shadow: var(--shadow); }
.empty-art .sheet:nth-child(2) { transform: translateX(-50%) rotate(3deg); top: 6px; }
.empty-art .sheet:nth-child(3) { transform: translateX(-50%) rotate(12deg); top: 2px; background-image: repeating-linear-gradient(transparent 0 11px, var(--line) 11px 12px); }

/* camera */
.cam { position: fixed; inset: 0; background: #000; color: #fff; overflow: hidden; }
.cam video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cam-guide { position: absolute; inset: 14% 8% 24%; pointer-events: none; }
.cam-guide .corner { position: absolute; width: 28px; height: 28px; border: 3px solid rgba(255,255,255,.9); border-radius: 4px; }
.cam-guide .tl { top: 0; left: 0; border-right: 0; border-bottom: 0; } .cam-guide .tr { top: 0; right: 0; border-left: 0; border-bottom: 0; }
.cam-guide .bl { bottom: 0; left: 0; border-right: 0; border-top: 0; } .cam-guide .br { bottom: 0; right: 0; border-left: 0; border-top: 0; }
.cam-guide.stable .corner { border-color: #7CFFB0; }
.cam-top { position: absolute; top: calc(var(--sat) + 12px); left: 12px; right: 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.cam-top .icon-btn { background: rgba(0,0,0,.45); border-color: rgba(255,255,255,.2); color: #fff; }
.cam-top .toggle { background: rgba(0,0,0,.45); border-radius: 999px; padding: 6px 10px 6px 6px; }
.cam-status { display: flex; align-items: center; gap: 8px; background: rgba(0,0,0,.45); border-radius: 999px; padding: 8px 12px; font-size: 13px; font-weight: 600; }
.cam-status .led { width: 8px; height: 8px; border-radius: 50%; background: #FFB21E; }
.cam-status.stable .led { background: #7CFFB0; }
.cam-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .25s; }
.cam-flash.on { opacity: .85; transition: none; }
.cam-bottom { position: absolute; left: 0; right: 0; bottom: calc(var(--sab) + 22px); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 24px; }
.cam-bottom .btn { justify-self: end; color: #fff; border-color: rgba(255,255,255,.3); }
.cam-count { justify-self: start; display: flex; flex-direction: column; align-items: center; line-height: 1; }
.cam-count b { font-family: var(--serif); font-size: 28px; } .cam-count small { font-size: 11px; opacity: .8; }
.shutter { position: relative; width: 78px; height: 78px; border-radius: 50%; border: none; background: transparent; justify-self: center; }
.shutter .core { position: absolute; inset: 8px; border-radius: 50%; background: #fff; transition: transform .1s; }
.shutter:active .core { transform: scale(.9); }
.shutter .ring { position: absolute; inset: 0; border-radius: 50%; border: 3px solid rgba(255,255,255,.5); }
.shutter .ring.go { border-color: #7CFFB0; box-shadow: 0 0 0 4px rgba(124,255,176,.3); }
.cam-thumbs { position: absolute; left: 12px; bottom: calc(var(--sab) + 118px); display: flex; gap: 6px; }
.cam-thumbs img { width: 38px; height: 50px; object-fit: cover; border-radius: 4px; border: 2px solid #fff; animation: pop .25s; }
@keyframes pop { from { transform: scale(.5); opacity: 0; } }
.cam-denied { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 24px; text-align: center; background: var(--paper); color: var(--ink); }

/* review */
.review { display: grid; gap: 14px; }
@media (min-width: 900px) { .review { grid-template-columns: minmax(0, 1.1fr) minmax(360px, .9fr); align-items: start; } .sheetpane { position: sticky; top: 12px; } }
.sheetwrap { position: relative; border-radius: var(--radius); overflow: hidden; background: var(--paper-3); box-shadow: var(--shadow); line-height: 0; }
.sheetwrap img { width: 100%; height: auto; display: block; }
.sheetwrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: manipulation; }
.sheet-tools { display: flex; align-items: center; gap: 12px; padding: 8px 4px; }
.state { text-align: center; padding: 32px 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.total { font-family: var(--serif); color: var(--red); } .total b { font-size: 30px; } .total span { font-size: 14px; color: var(--ink-3); }
.scores { display: flex; flex-direction: column; gap: 8px; }
.score { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.score .label { font-weight: 600; } .score .why { grid-column: 1 / -1; font-size: 13px; color: var(--ink-2); }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.stepper button { width: 32px; height: 32px; border: none; background: transparent; font-size: 18px; }
.stepper b { min-width: 46px; text-align: center; font-family: var(--serif); font-size: 15px; }
.stepper b small { color: var(--ink-3); font-size: 11px; font-weight: 400; }
.count { font-family: var(--font); font-size: 12px; color: var(--ink-3); font-weight: 500; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.chip { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); background: transparent; }
.chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.errors { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.err { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--paper); cursor: pointer; display: grid; gap: 4px; }
.err.on { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.err .line1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.err .quote { text-decoration: line-through; text-decoration-color: var(--red); color: var(--ink-2); }
.err .fix { color: var(--red-ink); font-weight: 600; }
.err .type { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; padding: 2px 7px; border-radius: 999px; margin-left: auto; }
.t-grammar { background: var(--red-soft); color: var(--red); } .t-spelling { background: var(--blue-soft); color: var(--blue); }
.t-vocabulary { background: var(--amber-soft); color: var(--amber); } .t-syntax { background: var(--red-soft); color: var(--red); }
.t-punctuation { background: var(--paper-3); color: var(--ink-2); } .t-calque { background: var(--green-soft); color: var(--green); }
.t-register { background: var(--blue-soft); color: var(--blue); } .t-other { background: var(--paper-3); color: var(--ink-2); }
.err .why { font-size: 13px; color: var(--ink-2); display: none; }
.err.on .why { display: block; }
.err .tools { display: none; gap: 6px; margin-top: 4px; }
.err.on .tools { display: flex; }
.err.dismissed { opacity: .45; } .err.dismissed .quote { text-decoration: none; }
.strengths { margin: 0; padding-left: 18px; color: var(--ink-2); }
.bank { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.bank button { font-size: 12px; border: 1px dashed var(--line); background: transparent; border-radius: 999px; padding: 4px 10px; color: var(--ink-2); }
.transcript pre { white-space: pre-wrap; font: 13px/1.5 var(--font); color: var(--ink-2); margin: 8px 0 0; }
.transcript summary { cursor: pointer; font-weight: 600; }
.review-actions { display: flex; gap: 10px; justify-content: flex-end; padding: 6px 0 20px; }
.review-actions .btn { flex: 1; }

/* students */
.students { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.student { background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.student h3 { font-size: 18px; display: flex; justify-content: space-between; align-items: baseline; }
.student h3 b { color: var(--red); }
.student .trend { display: flex; gap: 4px; align-items: flex-end; height: 34px; margin: 8px 0; }
.student .trend i { flex: 1; background: var(--red-soft); border-radius: 3px 3px 0 0; min-height: 3px; position: relative; }
.student .trend i::after { content: attr(data-v); position: absolute; top: -16px; left: 0; right: 0; text-align: center; font-size: 10px; color: var(--ink-3); font-style: normal; }
.student .recurring { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

/* settings */
.rubric { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.rubric .crit { display: grid; grid-template-columns: 1fr 70px 36px; gap: 6px; align-items: center; }
.rubric .crit input { margin: 0; }
.rubric .crit button { border: none; background: transparent; color: var(--ink-3); font-size: 18px; }

/* tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around; background: color-mix(in srgb, var(--paper) 85%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding: 6px 8px calc(var(--sab) + 6px); z-index: 20; }
.tabs button { flex: 1; max-width: 120px; display: flex; flex-direction: column; align-items: center; gap: 2px; border: none; background: transparent; color: var(--ink-3); font-size: 11px; font-weight: 600; padding: 6px 0; border-radius: 10px; }
.tabs button svg { width: 22px; height: 22px; }
.tabs button.on { color: var(--red); }

/* toast & menu */
.toast { position: fixed; left: 50%; bottom: calc(var(--sab) + 84px); transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 50; max-width: calc(100% - 32px); box-shadow: var(--shadow); }
.sheetmenu { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; display: flex; align-items: flex-end; justify-content: center; padding: 12px; }
.sheetmenu-card { background: var(--paper-2); border-radius: 16px; width: min(480px, 100%); overflow: hidden; box-shadow: var(--shadow); }
.menu-item { display: block; width: 100%; padding: 16px; border: none; border-bottom: 1px solid var(--line); background: transparent; font-weight: 600; }
.menu-item:last-child { border-bottom: none; color: var(--ink-3); }
#menuDelete { color: var(--red); }

/* ───────── first-launch guide ───────── */
.onb { position: fixed; inset: 0; z-index: 40; background: var(--paper); overflow-y: auto; padding: calc(var(--sat) + 24px) 16px calc(var(--sab) + 24px); display: flex; align-items: flex-start; justify-content: center; }
body.onb-open { overflow: hidden; }
.onb-card { width: 100%; max-width: 520px; margin: auto 0; }
.onb-dots { display: flex; gap: 6px; margin-bottom: 26px; }
.onb-dots i { height: 4px; flex: 1; border-radius: 2px; background: var(--paper-3); transition: background .2s; }
.onb-dots i.past { background: var(--ink-3); }
.onb-dots i.on { background: var(--red); }
.onb-step { animation: onb-in .28s ease-out both; }
@keyframes onb-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.onb-step h2 { font-family: var(--serif); font-size: 26px; font-weight: 500; letter-spacing: -.01em; margin: 6px 0 10px; }
.onb-step .title { font-size: 44px; }
.onb-lead { font-size: 17px; margin: 12px 0 10px; max-width: 46ch; }
.onb-step > .muted { max-width: 48ch; }
.onb-field { margin-top: 18px; }
.onb-status { min-height: 18px; margin-top: 4px; }
.onb-how { display: flex; gap: 14px; align-items: flex-start; padding: 14px 0; border-top: 1px solid var(--line); }
.onb-how:first-of-type { border-top: 0; }
.onb-how strong { display: block; margin-bottom: 2px; }
.onb-ico { width: 40px; height: 40px; border-radius: 50%; background: var(--red-soft); color: var(--red); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.onb-ico svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.onb-nav { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 28px; }
.onb-nav .btn { padding: 12px 20px; }

/* ───────── add to home screen ───────── */
.installbar { padding: 12px 14px; }
.installbar img { width: 40px; height: 40px; border-radius: 10px; flex: none; }
.installbar .icon-btn { width: 32px; height: 32px; }
.installbar .icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.installbar #installHow { margin-top: 10px; }
.install-steps { list-style: none; display: grid; gap: 8px; }
.install-steps li { display: flex; align-items: center; gap: 10px; }
.install-ico { width: 32px; height: 32px; border-radius: 8px; background: var(--paper-3); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.install-ico svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
