:root {
  --bg: #efece5;
  --panel: #faf9f6;
  --field: #ffffff;
  --line: #e2ddd3;
  --line-strong: #cfc8bb;
  --text: #1f1d1a;
  --muted: #7a746a;
  --ink: #1c2a6b;
  --ink-soft: rgba(28, 42, 107, 0.10);
  --chip: #f0ede6;
  --seg: #ece8e0;
  --sample: #fbfaf7;
  --shadow: rgba(40, 30, 10, .18);
  --radius: 8px;
}
[data-theme="dark"] {
  --bg: #141416;
  --panel: #1c1c1f;
  --field: #232327;
  --line: #2e2e33;
  --line-strong: #3e3e45;
  --text: #ecebe7;
  --muted: #9a978f;
  --ink: #8ea2ff;
  --ink-soft: rgba(142, 162, 255, 0.16);
  --chip: #2a2a2f;
  --seg: #2a2a2f;
  --sample: #f4f2ec;
  --shadow: rgba(0, 0, 0, .6);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141416; --panel: #1c1c1f; --field: #232327; --line: #2e2e33; --line-strong: #3e3e45;
    --text: #ecebe7; --muted: #9a978f; --ink: #8ea2ff; --ink-soft: rgba(142, 162, 255, 0.16);
    --chip: #2a2a2f; --seg: #2a2a2f; --sample: #f4f2ec; --shadow: rgba(0, 0, 0, .6);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 13px/1.45 Inter, system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
a { color: var(--ink); }
#app { display: grid; grid-template-columns: 380px 1fr; height: 100%; }

/* ---------- panel ---------- */
#panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-height: 0;
}
.brand { display: flex; align-items: baseline; gap: 10px; padding: 18px 20px 6px; }
.wordmark { font-family: Caveat, cursive; font-weight: 600; font-size: 30px; line-height: 1; color: var(--ink); letter-spacing: -0.01em; }
.tagline { color: var(--muted); font-size: 12px; }
.theme {
  margin-left: auto; align-self: center; background: none; border: 1px solid transparent; border-radius: 6px;
  width: 30px; height: 30px; display: grid; place-items: center; color: var(--muted); cursor: pointer;
}
.theme:hover { color: var(--text); border-color: var(--line); background: var(--field); }
.theme .moon { display: none; }
[data-theme="dark"] .theme .sun { display: none; }
[data-theme="dark"] .theme .moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme .sun { display: none; }
  :root:not([data-theme="light"]) .theme .moon { display: block; }
}

.tabs { display: flex; gap: 2px; padding: 8px 20px 0; border-bottom: 1px solid var(--line); }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px;
  padding: 8px 10px 9px; color: var(--muted); font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 7px;
}
.tabs button b {
  font-weight: 600; font-size: 10.5px; width: 17px; height: 17px; border-radius: 50%; display: grid; place-items: center;
  background: var(--chip); color: var(--muted);
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--text); border-bottom-color: var(--ink); }
.tabs button.active b { background: var(--ink); color: #fff; }

.tab { padding: 16px 20px; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.tab[hidden] { display: none; }
.lead { margin: 0 0 12px; color: var(--muted); }

.drop {
  display: block; border: 1px dashed var(--line-strong); border-radius: var(--radius);
  padding: 14px 12px; text-align: center; color: var(--muted); cursor: pointer; background: var(--field);
  transition: border-color .15s, background .15s, color .15s;
}
.drop:hover, .drop.over { border-color: var(--ink); background: var(--ink-soft); color: var(--text); }
textarea {
  display: block; width: 100%; min-height: 300px; resize: vertical; margin-top: 10px;
  background: var(--field); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; font: 13px/1.5 Inter, system-ui, sans-serif;
}
textarea:focus, input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px var(--ink-soft); }
.tips { margin: 8px 0 12px; font-size: 12px; color: var(--muted); }
.tips summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 6px; user-select: none; }
.tips summary::-webkit-details-marker { display: none; }
.tips summary::before { content: ''; width: 5px; height: 5px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); transition: transform .15s; }
.tips[open] summary::before { transform: rotate(45deg); }
.tips summary:hover { color: var(--text); }
.tips ul { margin: 8px 0 0; padding-left: 18px; line-height: 1.6; }
.tips code { font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--chip); padding: 2px 4px; border-radius: 4px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
input[type=text], input[type=number] {
  width: 100%; background: var(--field); color: var(--text); border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 9px; font: inherit;
}
input::placeholder { color: var(--muted); opacity: .8; }

/* hands */
.hands { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hand {
  display: block; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--sample);
  overflow: hidden; cursor: pointer; text-align: left; transition: border-color .12s, box-shadow .12s;
}
.hand:hover { border-color: var(--line-strong); }
.hand.active { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink-soft); }
.hand canvas { display: block; width: 100%; height: auto; }
.hand span { display: block; padding: 5px 9px 7px; font-size: 12px; font-weight: 500; border-top: 1px solid var(--line); background: var(--field); color: var(--text); }
.hand.mine span::after { content: ' · yours'; color: var(--muted); font-weight: 400; }
.handbar { display: flex; gap: 6px; margin: 10px 0 14px; }
.handbar input { flex: 1; min-width: 0; }

.tune { border-top: 1px solid var(--line); }
.tune > summary {
  list-style: none; cursor: pointer; user-select: none; padding: 11px 0;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted);
  display: flex; align-items: center; gap: 8px;
}
.tune > summary::-webkit-details-marker { display: none; }
.tune > summary::before { content: ''; width: 5px; height: 5px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); transition: transform .15s; }
.tune[open] > summary::before { transform: rotate(45deg); }
.tune > summary:hover { color: var(--text); }
.tune > div { padding-bottom: 6px; }

.row { display: grid; grid-template-columns: 150px 1fr 40px; align-items: center; gap: 10px; min-height: 28px; }
.row label { color: var(--text); font-size: 12.5px; line-height: 1.25; }
.row output { color: var(--muted); font-size: 11.5px; text-align: right; font-variant-numeric: tabular-nums; }
.row input[type=text] { grid-column: 2 / 4; }
.row .fontpick { grid-column: 2 / 4; }
.row .swatches { grid-column: 2 / 4; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 20px; background: none; margin: 0; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 3px; background: var(--line-strong); border-radius: 2px; }
input[type=range]::-moz-range-track { height: 3px; background: var(--line-strong); border-radius: 2px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5.5px; border-radius: 50%; background: var(--field); border: 1.5px solid var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.15); }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--field); border: 1.5px solid var(--ink); }
input[type=range]:focus { outline: none; }
input[type=range]:focus::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--ink-soft); }

.fontpick {
  text-align: left; background: var(--field); border: 1px solid var(--line); border-radius: 6px; padding: 4px 9px;
  font-size: 17px; line-height: 1.3; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fontpick:hover { border-color: var(--line-strong); }
.fontmenu {
  position: fixed; z-index: 50; max-height: 360px; overflow-y: auto;
  background: var(--field); border: 1px solid var(--line-strong); border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0,0,0,.2); padding: 4px;
}
.fontmenu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 5px 10px; font-size: 18px; border-radius: 5px; cursor: pointer; }
.fontmenu button:hover { background: var(--chip); }
.fontmenu button.active { background: var(--ink-soft); }

.swatches { display: flex; gap: 7px; align-items: center; }
.swatches button, .swatches .custom {
  width: 20px; height: 20px; border-radius: 50%; border: 2px solid transparent; background: var(--c); cursor: pointer; padding: 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
}
.swatches button.active { border-color: var(--panel); box-shadow: 0 0 0 1.5px var(--ink); }
.swatches .custom { position: relative; background: conic-gradient(#e33, #ec3, #3c6, #39e, #a3e, #e33); }
.swatches .custom::after { content: ''; position: absolute; inset: 3px; border-radius: 50%; background: var(--c); }
.swatches .custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

.manage { margin-top: 12px; color: var(--muted); font-size: 12px; }
.manage .dot { margin: 0 4px; }
.link { background: none; border: 0; padding: 0; color: var(--muted); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link:hover { color: var(--text); }

/* paper */
.paperstyles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ps { background: none; border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; cursor: pointer; text-align: center; }
.ps:hover { border-color: var(--line-strong); }
.ps.active { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink-soft); }
.ps i { display: block; height: 56px; border-radius: 4px; background: #fbfaf7; border: 1px solid #e2ddd3; position: relative; overflow: hidden; }
.ps.ruled i { background-image: repeating-linear-gradient(to bottom, transparent 0 9px, #c5d3e8 9px 10px); }
.ps.margin i::after { content: ''; position: absolute; left: 12px; top: 0; bottom: 0; width: 1px; background: #e8a0a0; }
.ps.squared i { background-image: linear-gradient(to right, #d3ddec 1px, transparent 1px), linear-gradient(to bottom, #d3ddec 1px, transparent 1px); background-size: 7px 7px; }
.ps span { display: block; font-size: 11px; margin-top: 5px; color: var(--muted); }
.ps.active span { color: var(--text); }

.switches { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 14px 0 10px; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 12.5px; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch i { width: 30px; height: 18px; border-radius: 9px; background: var(--line-strong); position: relative; transition: background .15s; flex: none; }
.switch i::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked + i { background: var(--ink); }
.switch input:checked + i::after { transform: translateX(12px); }
.switch input:focus-visible + i { box-shadow: 0 0 0 3px var(--ink-soft); }

#tab-paper h3 { margin: 16px 0 8px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.segmented { display: inline-flex; background: var(--seg); border-radius: 7px; padding: 2px; margin-bottom: 8px; }
.segmented button { background: none; border: 0; padding: 5px 12px; border-radius: 5px; cursor: pointer; color: var(--muted); font-weight: 500; }
.segmented button.active { background: var(--field); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

.foot { border-top: 1px solid var(--line); padding: 12px 20px 14px; }
.footrow { display: flex; align-items: center; gap: 8px; }
.footrow .btn { display: inline-flex; align-items: center; gap: 6px; }
.footrow .link { margin-left: auto; text-decoration: none; }
.fine { margin: 10px 0 0; color: var(--muted); font-size: 11.5px; }
.fine a { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
.fine a:hover { color: var(--text); }

/* buttons */
.btn {
  background: var(--field); border: 1px solid var(--line-strong); border-radius: 6px; padding: 7px 12px;
  font-weight: 500; cursor: pointer; white-space: nowrap; color: var(--text);
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
[data-theme="dark"] .btn.primary { color: #0e1230; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn.icon { padding: 5px 10px; font-size: 16px; line-height: 1; }
.btn:disabled { opacity: .45; cursor: default; }

/* ---------- stage ---------- */
#stage { display: grid; grid-template-rows: auto 1fr auto; min-width: 0; min-height: 0; }
.toolbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 18px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.pager { display: flex; align-items: center; gap: 6px; }
#pageinfo { color: var(--muted); min-width: 44px; text-align: center; font-variant-numeric: tabular-nums; }
.actions { display: flex; align-items: center; gap: 8px; }
#status { color: var(--muted); font-size: 12px; margin-right: 6px; }
.desk {
  overflow: auto; display: flex; justify-content: center; align-items: flex-start; padding: 28px; min-height: 0;
  background: radial-gradient(1000px 500px at 50% 0%, color-mix(in srgb, var(--bg) 85%, var(--panel)) 0%, var(--bg) 70%);
}
#view {
  max-width: 100%; max-height: calc(100vh - 118px); width: auto; height: auto; cursor: zoom-in;
  box-shadow: 0 30px 60px var(--shadow), 0 2px 8px var(--shadow); border-radius: 2px; background: #fff;
}
.desk.actual #view { max-width: none; max-height: none; cursor: zoom-out; }
.filmstrip { display: flex; gap: 10px; padding: 10px 18px; border-top: 1px solid var(--line); background: var(--panel); overflow-x: auto; }
.filmstrip[hidden] { display: none; }
.filmstrip canvas { width: 62px; height: 88px; border-radius: 2px; box-shadow: 0 1px 3px rgba(0,0,0,.3); cursor: pointer; opacity: .75; }
.filmstrip canvas:hover { opacity: 1; }
.filmstrip canvas.active { opacity: 1; outline: 2px solid var(--ink); outline-offset: 2px; }

/* ---------- privacy page ---------- */
body.doc { height: auto; }
.docwrap { max-width: 640px; margin: 0 auto; padding: 40px 24px 80px; font-size: 15px; line-height: 1.6; }
.docwrap h1 { font-size: 28px; margin: 12px 0 4px; }
.docwrap h2 { font-size: 16px; margin: 28px 0 6px; }
.docwrap p { margin: 0 0 12px; }
.docwrap .updated { color: var(--muted); font-size: 13px; }
.docwrap .back { text-decoration: none; color: var(--muted); }
.docwrap .back:hover { color: var(--text); }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; min-height: 100%; }
  #stage { order: -1; grid-template-rows: auto auto auto; }
  #panel { border-right: 0; border-top: 1px solid var(--line); }
  .tab { overflow: visible; }
  .desk { padding: 14px; }
  #view { max-height: 70vh; }
  .toolbar { padding: 8px 12px; gap: 8px; }
  .actions #status { display: none; }
  .actions .btn, .pager .btn { padding: 6px 9px; font-size: 12px; }
  #zoom { display: none; }
  .row { grid-template-columns: 130px 1fr 36px; }
  textarea { min-height: 180px; }
}

.segmented.tight { margin: 0; grid-column: 2 / 4; justify-self: start; }
.segmented.tight button { padding: 4px 10px; font-size: 12px; }
.bgblock { margin-top: 8px; }
.bgblock > label { display: block; font-size: 12.5px; margin-bottom: 6px; }
.bg { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.bg img { width: 44px; height: 33px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); }
.bg span { color: var(--muted); font-size: 12.5px; }
.hint { margin: 4px 0 0; color: var(--muted); font-size: 11.5px; line-height: 1.45; }
