:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --ink: #161616;
  --ink-2: #555;
  --ink-3: #8a8a8a;
  --line: #dddad2;
  --accent: #1a4fc4;
  --accent-soft: #e4e3df;
  --red: #d32f2f;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.14), 0 1px 3px rgba(0, 0, 0, 0.1);
  color-scheme: light;
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
#app { position: fixed; inset: 0; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:disabled { opacity: 0.35; cursor: default; }
.ic { width: 24px; height: 24px; flex: none; display: block; }
.ic.big { width: 56px; height: 56px; }
.primary { background: var(--ink); color: #fff; border-radius: 999px; padding: 9px 18px; font-weight: 600; }
.primary.big { padding: 13px 26px; font-size: 17px; }
.err { color: var(--red); }
.empty, .hint { color: var(--ink-3); padding: 0 16px; }
.hint { margin: 10px 0 0; font-size: 14px; }

/* ---- screens ------------------------------------------------------------ */
.center { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 6px; }
.center h1 { margin: 10px 0 0; font-size: 28px; letter-spacing: -0.01em; }
.center p { color: var(--ink-2); max-width: 340px; margin: 4px 0 18px; }
.hero { width: 96px; height: 96px; border-radius: 28px; background: var(--card); box-shadow: var(--shadow); display: grid; place-items: center; }
.page { height: 100%; display: flex; flex-direction: column; }
.bar { display: flex; align-items: center; gap: 4px; height: 52px; padding: 0 8px; background: var(--card); border-bottom: 1px solid var(--line); flex: none; }
.bar > button:not(.primary) { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 10px; }
.bar > button:not(.primary):active { background: var(--bg); }
.bar .title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 6px; }
.bar .pad, .bar .logo { width: 44px; display: grid; place-items: center; }
.bar .primary { padding: 7px 14px; font-size: 14px; }
.list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px 0 24px; }
.item { width: 100%; display: flex; align-items: center; gap: 14px; padding: 13px 18px; text-align: left; border-bottom: 1px solid var(--line); }
.item:active { background: #ecebe6; }
.item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item small { color: var(--ink-3); white-space: nowrap; }
.spin { width: 26px; height: 26px; margin: 30px auto; border: 2.5px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: rgba(20, 20, 20, 0.88); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; opacity: 0; transition: 0.2s; pointer-events: none; z-index: 50; max-width: calc(100% - 32px); text-align: center; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.authbar { position: fixed; left: 50%; top: calc(10px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 60; display: flex; gap: 10px; align-items: center; background: #fff3cd; border: 1px solid #e5c76b; padding: 10px 16px; border-radius: 999px; box-shadow: var(--shadow); font-size: 14px; max-width: calc(100% - 24px); }

.sheet-modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.3); z-index: 40; display: grid; place-items: center; padding: 16px; }
.sheet-modal .panel { background: var(--card); border-radius: 16px; box-shadow: var(--shadow); width: min(480px, 100%); max-height: 80vh; display: flex; flex-direction: column; overflow: hidden; }
.sheet-modal .panel.small { width: min(340px, 100%); padding-bottom: 14px; }
.sheet-modal header { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--line); }
.sheet-modal header button { width: 36px; height: 36px; display: grid; place-items: center; }
.sheet-modal .panel > p { padding: 0 18px; }
.sheet-modal input { margin: 16px 18px 6px; font: inherit; font-size: 20px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; -webkit-user-select: text; user-select: text; }
.sheet-modal .row { display: flex; justify-content: flex-end; gap: 10px; padding: 10px 18px 0; }
.sheet-modal .row button:not(.primary) { padding: 9px 14px; }
.sheet-modal .col { display: flex; flex-direction: column; padding: 4px 8px; }
.sheet-modal .col button { display: flex; gap: 12px; align-items: center; padding: 12px 10px; border-radius: 10px; text-align: left; }
.sheet-modal .col button:active { background: var(--bg); }
.toc-item { display: flex; width: 100%; gap: 12px; padding: 11px 16px; text-align: left; border-bottom: 1px solid var(--line); }
.toc-item span { flex: 1; }
.toc-item i { color: var(--ink-3); font-style: normal; font-variant-numeric: tabular-nums; }

/* ---- reader --------------------------------------------------------------- */
.reader { height: 100%; display: flex; flex-direction: column; }
.reader .pageno { width: auto !important; padding: 0 10px; font-variant-numeric: tabular-nums; font-size: 14px; color: var(--ink-2); }
.reader .body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.reader .stage { position: relative; flex: 1; min-height: 0; min-width: 0; overflow: hidden; background: #e9e7e1; touch-action: none; }
.reader .sheet { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.reader .sheet canvas { display: block; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18); }
.reader .loading { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--ink-2); gap: 4px; }
.reader .loading[hidden] { display: none; }
.reader .bubble { position: absolute; right: 16px; bottom: 16px; width: 52px; height: 52px; border-radius: 50%; background: #fff; border: 1.6px solid var(--ink); display: grid; place-items: center; box-shadow: var(--shadow); touch-action: none; z-index: 5; }
.reader .bubble.on { background: var(--ink); color: #fff; }
.reader .fitbtn { position: absolute; right: 16px; top: 38%; width: 52px; height: 52px; border-radius: 50%; background: #fff; border: 1.6px solid var(--ink); display: grid; place-items: center; box-shadow: var(--shadow); z-index: 5; }
.reader .fitbtn[hidden] { display: none; }
.reader .fitbtn .ic { width: 28px; height: 28px; }
.reader .notes-host { position: relative; flex: 1; min-height: 0; min-width: 0; border-top: 2px solid var(--ink); }
.reader .notes-host[hidden] { display: none; }
@media (orientation: landscape) {
  .reader .body { flex-direction: row; }
  .reader .notes-host { border-top: 0; border-left: 2px solid var(--ink); }
}

/* ---- notes panel ------------------------------------------------------------ */
.notes { position: absolute; inset: 0; overflow: hidden; background: #fffffc; }
.notes canvas.nb, .notes canvas.no { position: absolute; left: 0; top: 0; }
.notes canvas.no { touch-action: none; }
.notes .tb { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 5px; padding: 4px 6px; background: #fff; border-radius: 14px; box-shadow: var(--shadow); z-index: 3; max-width: calc(100% - 16px); }
.notes .tb button { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 9px; }
.notes .tb button.on { background: var(--accent-soft); color: var(--ink); }
.notes .tb button .dot { width: 20px; height: 20px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px rgba(0, 0, 0, 0.25); }
.notes .tb button .bar { width: 22px; height: 3px; background: var(--ink); border-radius: 4px; padding: 0; border: 0; }
.notes .tb .sync { width: 8px; height: 8px; border-radius: 50%; margin: 0 6px 0 4px; background: #7cb342; flex: none; }
.notes .tb .sync[data-state="busy"] { background: #f9a825; }
.notes .tb .sync[data-state="err"] { background: var(--red); }
.notes .zl { position: absolute; left: 8px; top: 60px; background: #fff; border-radius: 6px; padding: 2px 8px; font-size: 13px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); z-index: 2; pointer-events: none; }
.notes .zl[hidden] { display: none; }
.notes .flash { position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); background: rgba(20, 20, 20, 0.88); color: #fff; padding: 8px 14px; border-radius: 999px; font-size: 14px; z-index: 6; pointer-events: none; white-space: nowrap; }
.notes .flash[hidden] { display: none; }

.card { position: absolute; z-index: 5; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px 12px 12px; max-width: calc(100% - 16px); }
.card-t { font-weight: 600; font-size: 14px; color: var(--ink-2); padding: 0 2px 8px; }
.card .grid { display: grid; gap: 6px; }
.card .grid.shapes { grid-template-columns: repeat(4, 46px); }
.card .grid.colors { grid-template-columns: repeat(6, 40px); }
.card .grid button { height: 42px; display: grid; place-items: center; border-radius: 10px; }
.card .grid button.sel { background: var(--accent-soft); color: var(--ink); }
.card .grid.colors span { width: 26px; height: 26px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px rgba(0, 0, 0, 0.2); }
.card .grid.colors button.sel span { box-shadow: 0 0 0 2.5px #fff, 0 0 0 4.5px var(--ink); }
.size-prev { width: 260px; height: 70px; display: block; max-width: 100%; }
.size-slider { width: 260px; max-width: 100%; accent-color: var(--ink); }

.card.wide { padding: 10px 0 0; }
.card.wide .card-t { padding: 0 14px 6px; }
.more { display: grid; grid-template-columns: repeat(var(--cols, 2), 210px); border-top: 1px solid var(--line); overflow: hidden; }
.more section { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: 0 -1px -1px 0; padding: 6px 6px 8px; }
.more h4 { margin: 2px 6px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-3); }
.more .cells { display: flex; }
.more .cells { gap: 4px; }
.more .cells button { width: 62px; padding: 6px 2px; display: flex; flex-direction: column; align-items: center; gap: 4px; border-radius: 9px; font-size: 11.5px; color: var(--ink-2); }
.more .cells button.sel { background: var(--accent-soft); color: var(--ink); }
.more .cells button:active:not(:disabled) { background: var(--bg); }

.card.confirm { width: min(320px, calc(100% - 16px)); }
.card.confirm p { margin: 0 2px 10px; font-size: 14px; color: var(--ink-2); }
.card .row { display: flex; justify-content: flex-end; gap: 8px; align-items: center; }
.card .row button:not(.primary):not(.rb) { padding: 8px 12px; }

.card.audio canvas.wave { width: 100%; height: 56px; display: block; margin: 2px 0 10px; cursor: pointer; }
.card.audio .btns { justify-content: center; gap: 14px; }
.rb { width: 44px; height: 44px; border-radius: 50%; border: 1.6px solid var(--ink); display: grid; place-items: center; background: #fff; }
.rb.big { width: 54px; height: 54px; }
.rb.red { color: var(--red); border-color: var(--red); }
.rb.off { opacity: 0.35; pointer-events: none; }
