/* WillyChina Lesson Notebook. Tokens are the WillyChina core set. */
:root {
  --red: #C8102E; --red-dark: #9B0C23; --red-soft: #F4D5D9; --gold: #F5C842;
  --cream: #FFF9F0; --cream-deep: #FFF5EC; --ink: #1A1A1A; --body: #4A4A4A; --muted: #6A6A6A; --line: #E9DDC9;
  --blue: #21618C; --blue-soft: #EAF1F7; --green: #1E7E34;
  --t1: #B03A2E; --t2: #8A5A00; --t3: #1E7E34; --t4: #21618C; --t0: #5A6268;
  --serif: 'Playfair Display', Georgia, serif;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --han: 'Noto Serif SC', 'Songti SC', serif;
  --note: 'Inter', 'Noto Serif SC', -apple-system, sans-serif;
  --radius: 16px; --shadow: 0 10px 40px rgba(200, 16, 46, .08); --lift: 0 6px 24px rgba(26, 26, 26, .12);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
#root { min-height: 100%; height: 100%; }
.page.hero { min-height: 100%; }
body { background: var(--cream); color: var(--ink); font: 16px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
[hidden] { display: none !important; }
[lang|="zh"] { font-family: var(--han); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 18px; border-radius: 999px; border: 1px solid var(--line); background: #fff; font-weight: 600; font-size: 15px; white-space: nowrap; transition: background .15s, border-color .15s, transform .1s; }
a.btn { text-decoration: none; }
.btn:hover { border-color: #d9c8ad; background: var(--cream-deep); }
.btn:active { transform: translateY(1px); }
.btn.gold { background: var(--gold); border-color: var(--gold); color: var(--ink); font-weight: 700; }
.btn.gold:hover { background: #f0bd25; }
.btn.red { background: var(--red); border-color: var(--red); color: #fff; }
.btn.red:hover { background: var(--red-dark); }
.btn.ghost-light { background: transparent; border-color: rgba(255,255,255,.55); color: #fff; }
.btn.ghost-light:hover { background: rgba(255,255,255,.12); }
.btn.small { height: 36px; padding: 0 14px; font-size: 14px; }
.btn svg { flex-shrink: 0; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid transparent; background: transparent; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: var(--cream-deep); border-color: var(--line); }

/* ---------- app shell ---------- */
.app { display: grid; grid-template-rows: auto 1fr; height: 100%; }
/* Header matches willychina.com: white bar, the envelope mark bare on it, Willy (red) China (orange). */
.topbar { display: flex; align-items: center; gap: 14px; padding: 0 20px; min-height: 72px; padding-top: env(safe-area-inset-top, 0px); background: #fff; color: var(--ink); border-bottom: 1px solid var(--line); position: relative; z-index: 5; }
.brand { display: inline-flex; align-items: center; gap: 12px; text-decoration: none; white-space: nowrap; }
.brand img { width: 44px; height: 44px; display: block; }
.brand span { font: 700 20px/1 'Playfair Display', Georgia, serif; color: #C8102E; }
.brand em { font-style: normal; color: #F97316; }
.crumb { font-size: 15px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; padding-left: 14px; border-left: 1px solid var(--line); }
.topbar .spacer { flex: 1; }
.presence { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; white-space: nowrap; }
.presence { color: var(--body); }
.presence .dot { width: 9px; height: 9px; border-radius: 50%; background: #CFC3AE; }
.presence.on .dot { background: var(--green); box-shadow: 0 0 0 4px rgba(30,126,52,.15); }
.pill { display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 12px; border-radius: 999px; font-size: 14px; background: var(--cream-deep); color: var(--body); white-space: nowrap; border: 1px solid var(--line); }
.pill svg { color: var(--green); }
.pill.warn { background: #FFF3D6; border-color: #F0DDA8; color: var(--ink); font-weight: 600; }
.pill.warn svg { color: #8A5A00; }
.pill.bad { background: var(--red-soft); border-color: #EBB8C0; color: var(--red-dark); font-weight: 600; }
.pill.bad svg { color: var(--red-dark); }
.pill .spin { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--red); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.workspace { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: 0; }
.sidebar { border-right: 1px solid var(--line); background: var(--cream-deep); display: flex; flex-direction: column; min-height: 0; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 16px 10px; }
.sidebar-head h2 { margin: 0; font: 700 13px/1 var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.lessons { list-style: none; margin: 0; padding: 0 10px 12px; overflow-y: auto; flex: 1; }
.lessons a { display: block; padding: 11px 12px; border-radius: 12px; text-decoration: none; color: var(--body); border: 1px solid transparent; }
.lessons a:hover { background: rgba(255,255,255,.7); }
.lessons a[aria-current="page"] { background: #fff; border-color: var(--line); color: var(--ink); box-shadow: 0 1px 0 rgba(0,0,0,.02); }
.lessons .l-title { display: block; font-weight: 600; font-size: 15px; line-height: 1.3; }
.lessons .l-meta { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); margin-top: 3px; }
.lessons .live-tag { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--red); }
.sidebar-foot { border-top: 1px solid var(--line); padding: 10px; display: grid; gap: 4px; }
.side-link { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--red-dark); font-weight: 600; font-size: 14px; background: none; border: none; text-align: left; width: 100%; }
.side-link:hover { background: rgba(255,255,255,.7); }

.main { display: grid; grid-template-rows: auto auto 1fr; min-height: 0; min-width: 0; }
.lesson-head { display: flex; align-items: flex-end; gap: 16px; padding: 18px 24px 12px; flex-wrap: wrap; }
.lesson-title { margin: 0; font: 800 30px/1.15 var(--serif); outline: none; border-radius: 8px; padding: 2px 6px; margin-left: -6px; min-width: 120px; }
.lesson-title[contenteditable]:hover { background: rgba(255,255,255,.7); }
.lesson-title[contenteditable]:focus { background: #fff; box-shadow: 0 0 0 2px var(--line); }
.lesson-date { color: var(--muted); font-size: 14px; padding-bottom: 6px; }
.tabs { display: inline-flex; gap: 4px; padding: 4px; background: #fff; border: 1px solid var(--line); border-radius: 999px; margin-left: auto; }
.tab { height: 36px; padding: 0 16px; border-radius: 999px; border: none; background: transparent; font-weight: 600; font-size: 14px; color: var(--body); white-space: nowrap; }
.tab[aria-selected="true"] { background: var(--ink); color: #fff; }
.tab .count { display: inline-block; min-width: 20px; height: 20px; line-height: 20px; border-radius: 10px; font-size: 12px; background: var(--gold); color: var(--ink); margin-left: 6px; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; align-items: center; gap: 6px; padding: 8px 24px 10px; flex-wrap: wrap; }
.toolgroup { display: inline-flex; align-items: center; gap: 2px; padding: 4px; background: #fff; border: 1px solid var(--line); border-radius: 14px; }
.tool { display: inline-flex; align-items: center; gap: 7px; height: 40px; padding: 0 12px; border-radius: 10px; border: none; background: transparent; font-weight: 600; font-size: 14px; color: var(--body); white-space: nowrap; }
.tool:hover { background: var(--cream-deep); color: var(--ink); }
.tool[aria-pressed="true"] { background: var(--red); color: #fff; }
.tool:disabled { opacity: .4; cursor: default; background: transparent; }
.tool kbd { font: 600 11px/1 var(--sans); color: inherit; opacity: .55; border: 1px solid currentColor; border-radius: 4px; padding: 2px 4px; }
.swatch { width: 40px; height: 40px; border-radius: 10px; border: none; background: transparent; display: inline-flex; align-items: center; justify-content: center; }
.swatch span { width: 20px; height: 20px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,.1); }
.swatch[aria-pressed="true"] { background: var(--cream-deep); box-shadow: inset 0 0 0 2px var(--ink); }
.toolbar .grow { flex: 1; }
.zoom { font-variant-numeric: tabular-nums; }
.textstyle { display: inline-flex; }

/* ---------- board ---------- */
.board-wrap { position: relative; min-height: 0; border-top: 1px solid var(--line); background: #F7EFE3; }
.board-viewport { position: absolute; inset: 0; overflow: auto; overscroll-behavior: contain; padding: 20px 24px 40px; }
@media (max-width: 700px) { .board-viewport { padding: 12px 8px 32px; } }
.board-sizer { margin: 0 auto; position: relative; }
.board-surface { position: absolute; left: 0; top: 0; width: 1200px; transform-origin: 0 0; background-color: var(--cream); background-image: radial-gradient(#E3D5BF 1.3px, transparent 1.4px); background-size: 30px 30px; border-radius: 4px; box-shadow: 0 1px 0 var(--line), 0 0 0 1px var(--line), 0 18px 50px rgba(155, 12, 35, .06); }
.board-surface.editable[data-tool="type"], .board-surface.editable[data-tool="big"] { cursor: text; }
.board-surface.editable[data-tool="pen"] { cursor: crosshair; touch-action: none; }
.board-surface.editable[data-tool="erase"] { cursor: cell; touch-action: none; }
.board-surface[data-tool="pen"] .item, .board-surface[data-tool="erase"] .item { pointer-events: none; }
.board-ink { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.board-items { position: absolute; inset: 0; z-index: 1; }
.board-empty { position: absolute; left: 50%; top: 200px; transform: translateX(-50%); text-align: center; color: var(--muted); pointer-events: none; width: 560px; }
.board-empty strong { display: block; font: 800 30px/1.2 var(--serif); color: var(--ink); margin-bottom: 10px; }
.board-empty p { margin: 6px 0; font-size: 17px; }
.board-empty code { font: 600 15px var(--sans); background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 2px 7px; color: var(--ink); }

/* items */
.item { position: absolute; border-radius: 12px; }
.item .grip, .item .del { position: absolute; width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--muted); display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity .12s; z-index: 3; box-shadow: 0 2px 6px rgba(0,0,0,.06); padding: 0; }
.item .grip { left: -38px; top: 2px; cursor: grab; touch-action: none; }
.item .del { right: -10px; top: -14px; }
.item .del:hover { color: var(--red); border-color: var(--red-soft); }
.item:hover .grip, .item:hover .del, .item.sel .grip, .item.sel .del, .item:focus-within .grip, .item:focus-within .del { opacity: 1; }
.item.dragging { box-shadow: var(--lift); z-index: 10; }
.item.dragging .grip { cursor: grabbing; }
.f { outline: none; white-space: pre-wrap; word-break: break-word; }
.f[contenteditable]:empty::before { content: attr(data-placeholder); color: #B9AC97; pointer-events: none; }
.f[contenteditable] { cursor: text; }

.item.text { padding: 4px 8px; max-width: 760px; min-width: 40px; border: 1.5px solid transparent; }
.board-surface.editable .item.text:hover { border-color: rgba(233, 221, 201, .9); }
.item.text.sel, .item.text:focus-within { border-color: var(--line); background: rgba(255,255,255,.55); }
.item.text .f { font-family: var(--note); }
.item.text.size-s .f { font-size: 17px; line-height: 1.5; }
.item.text.size-m .f { font-size: 22px; line-height: 1.45; }
.item.text.size-l .f { font-family: var(--han); font-weight: 700; font-size: 52px; line-height: 1.25; }

.item.word, .item.sentence, .item.question { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px 16px; box-shadow: 0 2px 0 rgba(233,221,201,.6); }
.item.word { width: 230px; }
.item.sentence, .item.question { width: 540px; }
.item.sel:not(.text), .item:not(.text):focus-within { border-color: #d9c8ad; box-shadow: var(--shadow); }
.kicker { display: block; font: 700 12px/1 var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.question .kicker { color: var(--blue); }
.w-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.hz { font-family: var(--han); font-weight: 700; font-size: 38px; line-height: 1.25; min-width: 60px; flex: 1; }
.sentence .hz { font-size: 28px; font-weight: 600; line-height: 1.45; }
.pinyin { font-size: 19px; font-weight: 600; margin-top: 2px; }
.sentence .pinyin { font-size: 18px; font-weight: 500; }
.meaning { font-size: 16px; color: var(--body); margin-top: 4px; }
.prompt { font-size: 19px; line-height: 1.45; }
.t1 { color: var(--t1); } .t2 { color: var(--t2); } .t3 { color: var(--t3); } .t4 { color: var(--t4); } .t0 { color: var(--t0); }
.say { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--cream); color: var(--red); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; padding: 0; }
.say:hover { background: var(--red-soft); }
.say.playing { background: var(--red); color: #fff; border-color: var(--red); }
.q-answer { margin-top: 12px; background: var(--blue-soft); border-radius: 12px; padding: 10px 14px; }
.a-label { display: block; font-size: 13px; font-weight: 700; color: var(--blue); margin-bottom: 2px; }
.a-label.muted { color: var(--muted); font-weight: 500; margin: 0; }
.a-body { font-size: 20px; min-height: 30px; font-family: var(--note); }
.a-body[contenteditable] { background: #fff; border-radius: 8px; padding: 6px 10px; border: 1px solid #c9d8e6; }

/* ---------- dialogs, drawers, toasts ---------- */
.scrim { position: fixed; inset: 0; background: rgba(26, 26, 26, .35); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.dialog { background: #fff; border-radius: 20px; padding: 26px; width: min(480px, 100%); box-shadow: 0 30px 80px rgba(0,0,0,.25); }
.dialog h2 { margin: 0 0 8px; font: 800 24px/1.2 var(--serif); }
.dialog p { margin: 0 0 18px; color: var(--body); }
.dialog .actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100%); background: #fff; z-index: 40; box-shadow: -20px 0 60px rgba(0,0,0,.15); display: flex; flex-direction: column; }
.drawer header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.drawer h2 { margin: 0; font: 800 22px var(--serif); }
.drawer .list { overflow-y: auto; padding: 8px 0; }
.version { display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid #f2e9da; }
.version .v-main { flex: 1; min-width: 0; }
.version strong { display: block; font-size: 15px; }
.version span { font-size: 13px; color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 60; box-shadow: var(--lift); font-size: 15px; max-width: calc(100% - 32px); }
.banner { display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: #FFF3D6; border-bottom: 1px solid #F0DDA8; font-size: 15px; flex-wrap: wrap; }
.banner.blue { background: var(--blue-soft); border-color: #cfdeeb; }

/* ---------- gate + dashboard ---------- */
.page { min-height: 100%; display: flex; flex-direction: column; }
.hero { background: radial-gradient(120% 120% at 50% -10%, #FFF3E6 0%, #FFF9F0 45%, #FCEFE0 100%); border-bottom: 1px solid var(--line); position: relative; overflow: hidden; }
.hero::before { content: "学"; position: absolute; right: -2%; top: -30%; font: 900 22rem/1 var(--han); color: rgba(200,16,46,.04); pointer-events: none; }
.wrap { width: min(1080px, 100%); margin: 0 auto; padding-inline: 20px; }
.gate { max-width: 440px; margin: 10vh auto; background: #fff; border: 1px solid var(--line); border-radius: 20px; padding: 32px; box-shadow: var(--shadow); }
.gate h1 { font: 800 30px/1.15 var(--serif); margin: 0 0 8px; }
.field-label { display: block; font-weight: 600; font-size: 14px; margin: 16px 0 6px; }
.input { width: 100%; height: 48px; border-radius: 12px; border: 1px solid var(--line); padding: 0 14px; font: inherit; background: var(--cream); color: var(--ink); }
.input:focus { outline: none; border-color: #d9c8ad; box-shadow: 0 0 0 3px rgba(245,200,66,.45); background: #fff; }
.error { color: var(--red-dark); font-size: 14px; margin-top: 8px; }
.students { display: grid; gap: 12px; margin: 22px 0 60px; }
.student { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1.6fr) auto; gap: 18px; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 16px 20px; }
.student h3 { margin: 0; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.student .meta { font-size: 14px; color: var(--muted); }
.student .acts { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.here { font-size: 12px; font-weight: 700; color: var(--green); background: #E6F2E9; padding: 3px 8px; border-radius: 999px; }
.empty-state { text-align: center; padding: 60px 20px; background: #fff; border: 1px dashed var(--line); border-radius: 20px; margin: 22px 0; }
.empty-state h2 { font: 800 26px var(--serif); margin: 0 0 8px; }

/* ---------- reading view (phones) ---------- */
.reading { padding: 16px; display: grid; gap: 12px; max-width: 640px; margin: 0 auto; }
.reading .r-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; }
.reading .r-text { font: 19px/1.5 var(--note); white-space: pre-wrap; padding: 2px 4px; }
.reading .r-text.size-l { font: 700 40px/1.25 var(--han); }
.reading .r-ink-note { font-size: 14px; color: var(--muted); text-align: center; padding: 8px; }

/* ---------- responsive ---------- */
.only-narrow { display: none; }
@media (max-width: 900px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 72px auto 0 0; width: min(300px, 86vw); z-index: 30; transform: translateX(-102%); visibility: hidden; transition: transform .2s, visibility .2s; }
  .sidebar.open { transform: none; visibility: visible; box-shadow: 20px 0 60px rgba(0,0,0,.12); }
  .only-narrow { display: inline-flex; }
  .hide-narrow { display: none !important; }
  .lesson-head { padding: 14px 16px 8px; }
  .lesson-title { font-size: 24px; }
  .toolbar { padding: 6px 16px 8px; }
  .tabs { margin-left: 0; }
  .student { grid-template-columns: minmax(0, 1fr); }
  .student .acts { justify-content: flex-start; }
}
@media (max-width: 560px) {
  .topbar { gap: 8px; padding-inline: 12px; }
  .crumb { display: none; }
  .tool .label { display: none; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* ---------- print (lesson notes PDF) ---------- */
#print-root { display: none; }
@media print {
  @page { size: A4 landscape; margin: 12mm; }
  body { background: #fff; }
  #root, .scrim, .drawer, .toast { display: none !important; }
  #print-root { display: block; }
  .p-page { page-break-after: always; break-after: page; position: relative; }
  .p-page:last-child { page-break-after: auto; break-after: auto; }
  .p-head { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 2px solid var(--red); padding-bottom: 6px; margin-bottom: 10px; }
  .p-head strong { font: 800 18pt var(--serif); }
  .p-head span { font-size: 10pt; color: var(--muted); }
  .p-board { position: relative; overflow: hidden; background: var(--cream); border-radius: 6px; }
  .p-board .board-items, .p-board .board-ink { position: absolute; left: 0; top: 0; }
  .say { display: none !important; }
  .p-foot { font-size: 9pt; color: var(--muted); margin-top: 6px; display: flex; justify-content: space-between; }
  .item .grip, .item .del { display: none !important; }
  .f:empty::before { content: none; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---------- built-in Chinese typing ---------- */
.ime-panel { position: fixed; left: 0; top: 0; z-index: 70; background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 14px 40px rgba(26,26,26,.16); padding: 8px; max-width: min(640px, calc(100vw - 16px)); }
.ime-top { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; padding: 2px 6px 6px; }
.ime-buf { font: 600 15px var(--sans); color: var(--blue); text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 4px; }
.ime-hint { font-size: 12px; color: var(--muted); white-space: nowrap; }
.ime-row { display: flex; gap: 4px; flex-wrap: wrap; align-items: stretch; }
.ime-c { display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto; column-gap: 5px; align-items: baseline; padding: 6px 10px; min-height: 44px; border-radius: 10px; border: 1px solid transparent; background: transparent; text-align: left; }
.ime-c:hover, .ime-c.first { background: var(--cream-deep); border-color: var(--line); }
.ime-n { grid-row: 1 / span 2; font: 600 12px var(--sans); color: var(--muted); align-self: center; }
.ime-s { font: 600 22px/1.2 var(--han); color: var(--ink); }
.ime-p { grid-column: 2; font-size: 11px; color: var(--muted); line-height: 1.2; }
.ime-nav { min-width: 36px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-size: 18px; color: var(--body); }
.ime-none { font-size: 14px; color: var(--muted); padding: 8px; }
@media (max-width: 700px) { .ime-hint { display: none; } .ime-s { font-size: 24px; } }
.ime-panel.docked { left: 0; right: 0; width: 100%; max-width: none; border-radius: 14px 14px 0 0; padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
.tool.tone { font: 600 17px var(--sans); min-width: 40px; justify-content: center; padding: 0 8px; }
.toolgroup.typing .tool[aria-pressed="true"] { background: var(--ink); color: #fff; }
.dialog.wide { width: min(760px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; }
.howto { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.howto section { background: var(--cream); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.howto h3 { margin: 0 0 6px; font-size: 16px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.howto p, .howto li { font-size: 14px; color: var(--body); margin: 6px 0; }
.howto ul { padding-left: 18px; margin: 6px 0; }
.howto kbd, .dialog kbd { font: 600 13px var(--sans); background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; color: var(--ink); }
.chip { font: 700 12px var(--sans); background: var(--ink); color: #fff; border-radius: 999px; padding: 3px 9px; }
.muted { color: var(--muted); }
@media (max-width: 760px) { .howto { grid-template-columns: minmax(0, 1fr); } }

/* ---------- drawing rail ---------- */
.rail { position: absolute; left: 12px; top: 16px; z-index: 6; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px; background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 8px 24px rgba(26,26,26,.08); }
.rtool { position: relative; width: 44px; height: 44px; border-radius: 12px; border: none; background: transparent; color: var(--body); display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.rtool:hover { background: var(--cream-deep); color: var(--ink); }
.rtool[aria-pressed="true"]:not(.swatch) { background: var(--red); color: #fff; }
.rtool.swatch span { width: 20px; height: 20px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,.1); }
.rtool.swatch[aria-pressed="true"] { background: var(--cream-deep); box-shadow: inset 0 0 0 2px var(--ink); }
.rsep { width: 26px; height: 1px; background: var(--line); margin: 4px 0; }
.rtool[data-tip]:hover::after, .rtool[data-tip]:focus-visible::after { content: attr(data-tip); position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%); background: var(--ink); color: #fff; font: 600 13px var(--sans); padding: 6px 10px; border-radius: 8px; white-space: nowrap; pointer-events: none; }
.board-wrap:has(.rail:not([hidden])) .board-viewport { padding-left: 80px; }
.group-label { font: 700 11px var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 0 6px 0 8px; }
/* Tones stay put (a toolbar that shifts under the mouse eats clicks); they just dim when you're not typing. */
.toolgroup.typing .tones { display: inline-flex; opacity: .45; transition: opacity .15s; }
.typing-now .toolgroup.typing .tones { opacity: 1; }
.toolgroup.typing .tool.help { min-width: 36px; justify-content: center; }
@media (max-width: 900px) {
  .rail { top: auto; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); flex-direction: row; }
  .rsep { width: 1px; height: 26px; margin: 0 4px; }
  .rtool[data-tip]:hover::after { display: none; }
  .board-wrap:has(.rail:not([hidden])) .board-viewport { padding-left: 8px; padding-bottom: 90px; }
}
@media (max-width: 560px) {
  .toolgroup.typing .group-label { display: none; }
  .tool.tone { min-width: 34px; padding: 0 4px; }
  .toolgroup.typing .tool { padding: 0 9px; }
  .toolbar { gap: 6px; }
  .toolbar .toolgroup { max-width: 100%; }
}

/* pinyin bar: each choice is a word — pinyin, characters, meaning */
.py-c { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto auto; column-gap: 7px; align-items: baseline; text-align: left; max-width: 200px; }
.py-c .ime-n { grid-row: 1 / span 2; align-self: center; }
.py-top { display: inline-flex; align-items: baseline; gap: 6px; }
.py-s { font: 600 18px var(--sans); color: var(--ink); }
.py-hz { font: 600 17px var(--han); color: var(--red-dark); }
.py-g { grid-column: 2; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.ime-p { max-width: 190px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
