/* Charlotte · cozy coloring. Paper on a table, one copper accent, the artwork is the only loud thing. */
:root {
  --bg: #F4EDE1; --surface: #FBF7EF; --raised: #FFFDF8; --paper: #FFFDF8;
  --ink: #2E2A25; --ink-2: #6F665B; --ink-3: #9C9285; --line: #E3D9C8;
  --accent: #A8541F; --on-accent: #FFFFFF; --sel: #F0DFCB; --danger: #B23A2E;
  --shadow-page: 0 1px 2px rgba(46,42,37,.08), 0 8px 24px rgba(46,42,37,.10);
  --shadow-pop: 0 4px 16px rgba(46,42,37,.14), 0 1px 3px rgba(46,42,37,.08);
  --r-ctl: 10px; --r-card: 14px; --r-sheet: 20px;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --top: 56px; --rail: 76px; --tray: 148px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1F1B17; --surface: #2A2520; --raised: #352F29; --ink: #F1E8DA; --ink-2: #A99E8F; --ink-3: #7E7468; --line: #40382F;
    --accent: #E0A458; --on-accent: #2A1E12; --sel: #3E3329; --danger: #E57A6B;
    --shadow-page: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35); --shadow-pop: 0 6px 22px rgba(0,0,0,.45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1F1B17; --surface: #2A2520; --raised: #352F29; --ink: #F1E8DA; --ink-2: #A99E8F; --ink-3: #7E7468; --line: #40382F;
  --accent: #E0A458; --on-accent: #2A1E12; --sel: #3E3329; --danger: #E57A6B;
  --shadow-page: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35); --shadow-pop: 0 6px 22px rgba(0,0,0,.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink); font: 500 15px/1.4 var(--font);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible, input:focus-visible, .card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
.ico { width: 24px; height: 24px; flex: none; }

.screen { position: fixed; inset: 0; display: none; }
.screen.is-active { display: flex; }

/* ---------- shared controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 14px; border-radius: var(--r-ctl);
  font-weight: 600; transition: background-color 140ms var(--ease), color 140ms var(--ease), opacity 140ms var(--ease), transform 140ms var(--ease); }
.btn:active { transform: scale(.96); }
.btn.icon { width: 48px; padding: 0; }
.btn.icon.sm { width: 44px; min-height: 40px; }
.btn.ghost:hover, .btn.icon:hover { background: var(--sel); }
.btn:disabled { opacity: .32; pointer-events: none; }
.btn.soft { background: var(--sel); }
.btn.soft:hover { filter: brightness(.97); }
.btn.accent { background: var(--accent); color: var(--on-accent); }
.btn.danger { background: var(--danger); color: #fff; }

.seg { display: inline-flex; background: color-mix(in srgb, var(--ink) 6%, transparent); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { min-height: 38px; padding: 0 14px; border-radius: 9px; color: var(--ink-2); font-weight: 600; white-space: nowrap; transition: background-color 140ms var(--ease), color 140ms var(--ease), box-shadow 140ms var(--ease); }
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--raised); color: var(--ink); box-shadow: 0 1px 2px rgba(46,42,37,.12), 0 0 0 .5px rgba(46,42,37,.06); }
.seg.small button { min-height: 34px; padding: 0 11px; font-size: 14px; }
.seg.full { display: flex; } .seg.full button { flex: 1; padding: 0 6px; }

input[type=range] { -webkit-appearance: none; appearance: none; background: transparent; height: 32px; margin: 0; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--line); }
input[type=range]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--line); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; margin-top: -9px; border-radius: 50%; background: var(--raised); border: 2px solid var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
input[type=range]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: var(--raised); border: 2px solid var(--ink); }

/* ---------- HOME ---------- */
#home { flex-direction: column; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: max(28px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) 48px max(24px, env(safe-area-inset-left)); }
#home > * { width: 100%; max-width: 1240px; margin-left: auto; margin-right: auto; }
.home-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 36px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { width: 54px; height: 54px; fill: var(--sel); stroke: var(--ink); stroke-width: 4.5; }
.brand-mark .dot { fill: var(--ink); stroke: none; } .brand-mark .blush { fill: #F2B8B0; stroke: none; } .brand-mark .smile { fill: none; stroke-width: 3; stroke-linecap: round; }
.brand h1 { font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1; }
.brand .tag { color: var(--ink-2); margin-top: 4px; }
#home h2 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }

.shelf { margin-bottom: 40px; }
.shelf h2 { margin-bottom: 14px; }
.shelf-row { display: flex; gap: 18px; overflow-x: auto; padding: 4px 4px 14px; margin: -4px -4px 0; scroll-snap-type: x proximity; scrollbar-width: none; }
.shelf-row::-webkit-scrollbar { display: none; }
.shelf-row .card { width: 172px; flex: none; scroll-snap-align: start; }
.empty { display: flex; align-items: center; gap: 18px; color: var(--ink-2); padding: 18px 20px; border: 1.5px dashed var(--line); border-radius: var(--r-card); max-width: 560px; }
.empty-art { width: 96px; flex: none; fill: none; stroke: var(--ink-3); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.empty-art .dot { fill: var(--ink-3); stroke: none; }

.library-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 26px 22px; }

.card { display: flex; flex-direction: column; gap: 10px; text-align: left; cursor: pointer; border-radius: var(--r-card); position: relative; }
.card .thumb { position: relative; aspect-ratio: 4 / 5; background: var(--paper); border-radius: var(--r-card); box-shadow: var(--shadow-page); overflow: hidden;
  transition: transform 260ms var(--ease), box-shadow 260ms var(--ease); }
.card:hover .thumb { transform: translateY(-3px) rotate(-.4deg); box-shadow: 0 2px 4px rgba(46,42,37,.08), 0 14px 32px rgba(46,42,37,.14); }
.card:active .thumb { transform: scale(.98); }
.card .thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.card .thumb .bar { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--accent); border-radius: 0 2px 2px 0; transition: width 400ms var(--ease); }
.card .meta { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 0 2px; }
.card .name { font-weight: 700; font-size: 15px; line-height: 1.25; }
.card .sub { color: var(--ink-2); font-size: 13px; white-space: nowrap; }
.card .flag { position: absolute; top: 10px; left: 10px; font-size: 11px; font-weight: 700; letter-spacing: .04em; padding: 3px 7px; border-radius: 7px;
  background: color-mix(in srgb, var(--paper) 88%, transparent); color: #6F665B; box-shadow: 0 0 0 1px rgba(46,42,37,.08); }
.card .mini-stamp { position: absolute; right: 10px; bottom: 12px; width: 46px; height: 46px; border-radius: 50%; border: 2.5px solid var(--accent); color: var(--accent);
  display: grid; place-items: center; font-size: 10px; font-weight: 800; transform: rotate(-12deg); background: color-mix(in srgb, var(--paper) 70%, transparent); }
.card .menu-dot { position: absolute; top: 6px; right: 6px; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: #6F665B; opacity: 0; transition: opacity 140ms; background: color-mix(in srgb, var(--paper) 85%, transparent); }
.card:hover .menu-dot, .card .menu-dot:focus-visible { opacity: 1; }
@media (hover: none) { .card .menu-dot { opacity: 1; } }
.card .menu-dot .ico { width: 20px; height: 20px; }

/* ---------- EDITOR ---------- */
#editor { flex-direction: column; }
.topbar { height: calc(var(--top) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; background: var(--surface); border-bottom: 1px solid var(--line); flex: none; z-index: 5; }
.tb-left { display: flex; align-items: center; gap: 6px; min-width: 0; }
.tb-right { display: flex; align-items: center; justify-content: flex-end; gap: 4px; }
.back { padding: 0 12px 0 6px; color: var(--ink-2); } .back:hover { color: var(--ink); }
.page-title { font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 6px; border-left: 1px solid var(--line); }
.btn.undo { width: 56px; background: var(--sel); }
.tb-sep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }

.workspace { flex: 1; display: grid; grid-template-columns: var(--rail) 1fr var(--tray); min-height: 0; position: relative; }
body.lefty .workspace { grid-template-columns: var(--tray) 1fr var(--rail); }
body.lefty .rail { order: 3; border-left: 1px solid var(--line); border-right: 0; }
body.lefty .tray { order: 1; border-right: 1px solid var(--line); border-left: 0; }
body.lefty .stage { order: 2; }

.rail { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); z-index: 3; }
.tool { width: 62px; min-height: 62px; border-radius: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--ink-2);
  font-size: 11.5px; font-weight: 600; transition: background-color 140ms var(--ease), color 140ms var(--ease); }
.tool:hover { color: var(--ink); background: color-mix(in srgb, var(--sel) 60%, transparent); }
.tool.on { background: var(--sel); color: var(--accent); }
.tool.on .ico { stroke-width: 2.3; }
.tool span { line-height: 1.1; text-align: center; max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-spacer { flex: 1; }
.zoom { display: flex; flex-direction: column; gap: 2px; color: var(--ink-2); }

.stage { position: relative; overflow: hidden; touch-action: none; background: var(--bg); cursor: crosshair; }
.stage.tool-hand, .stage.panning { cursor: grab; } .stage.panning { cursor: grabbing; }
.stage.tool-fill { cursor: pointer; }
.stage.tool-brush, .stage.tool-eraser.erase-free { cursor: none; }
.sheet { position: absolute; left: 0; top: 0; width: 1600px; height: 2000px; transform-origin: 0 0; background: var(--paper); box-shadow: var(--shadow-page); border-radius: 6px; }
body.finishing .sheet { transition: transform 600ms var(--ease), box-shadow 600ms var(--ease); }
.layer { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.layer-lines { mix-blend-mode: multiply; }
.layer-lines svg { display: block; width: 100%; height: 100%; }
.cursor { position: absolute; left: 0; top: 0; border-radius: 50%; pointer-events: none; border: 1.5px solid rgba(46,42,37,.75); box-shadow: 0 0 0 1px rgba(255,255,255,.8); display: none; transform: translate(-50%, -50%); }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-2); background: var(--bg); transition: opacity 260ms var(--ease); }
.loading.gone { opacity: 0; pointer-events: none; }

.options { position: absolute; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; align-items: center; gap: 14px;
  background: var(--surface); border-radius: 18px; padding: 8px 14px; box-shadow: var(--shadow-pop); border: 1px solid var(--line); max-width: calc(100% - 24px); z-index: 4;
  animation: rise 260ms var(--ease); }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }
.opt-slider { display: flex; align-items: center; gap: 10px; position: relative; }
.opt-slider input { width: 130px; }
.opt-slider .lbl { position: absolute; left: 34px; top: -10px; font-size: 10.5px; color: var(--ink-3); font-weight: 600; }
.size-dot, .op-dot { width: 26px; height: 26px; flex: none; display: grid; place-items: center; }
.size-dot::after { content: ""; width: var(--d, 12px); height: var(--d, 12px); border-radius: 50%; background: var(--cur, var(--ink)); box-shadow: 0 0 0 1px rgba(46,42,37,.15); }
.op-dot::after { content: ""; width: 20px; height: 20px; border-radius: 50%; background: var(--cur, var(--ink)); opacity: var(--o, 1); box-shadow: 0 0 0 1px rgba(46,42,37,.15); }

.toast { position: absolute; left: 50%; top: 16px; transform: translate(-50%, -8px); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity 260ms var(--ease), transform 260ms var(--ease); z-index: 6; white-space: nowrap; max-width: calc(100% - 24px); overflow: hidden; text-overflow: ellipsis; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* tray */
.tray { background: var(--surface); border-left: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); overflow-y: auto; z-index: 3; scrollbar-width: none; }
.tray::-webkit-scrollbar { display: none; }
.tray-tabs { display: flex; } .tray-tabs button { flex: 1; padding: 0 4px; font-size: 13px; }
.tab-panel { display: flex; flex-direction: column; gap: 10px; }
.tray h3 { font-size: 12px; font-weight: 700; color: var(--ink-3); margin-top: 4px; }
.palette-name { display: flex; align-items: center; justify-content: space-between; gap: 4px; min-height: 40px; padding: 0 6px 0 10px; border-radius: var(--r-ctl); font-weight: 700; font-size: 14px; background: color-mix(in srgb, var(--ink) 5%, transparent); }
.palette-name:hover { background: var(--sel); }
.palette-name .ico { width: 18px; height: 18px; color: var(--ink-2); }
.palette-name span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.swatches { display: grid; grid-template-columns: repeat(2, 56px); gap: 4px 8px; justify-content: center; }
.swatch { width: 56px; height: 56px; display: grid; place-items: center; border-radius: 50%; position: relative; }
.swatch i { width: 46px; height: 46px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1px rgba(46,42,37,.14); transition: transform 140ms var(--ease); }
.swatch:hover i { transform: scale(1.06); }
.swatch.on::before { content: ""; position: absolute; inset: 1px; border-radius: 50%; border: 3px solid var(--ink); }
.swatch.on i { transform: scale(.82); }
.swatch .ico { position: absolute; width: 20px; height: 20px; stroke-width: 3; opacity: 0; transition: opacity 140ms; }
.swatch.on .ico { opacity: 1; }
.swatch.custom i { background: conic-gradient(from 0deg, #e8695e, #f2c14e, #8fca6b, #5bb4d8, #8a7fd6, #e07fb8, #e8695e); display: grid; place-items: center; }
.swatch.custom i::after { content: ""; width: 26px; height: 26px; border-radius: 50%; background: var(--surface); }
.swatch.custom .plus { opacity: 1; color: var(--ink); width: 18px; height: 18px; stroke-width: 2.6; }
.recent .swatch { width: 56px; height: 44px; } .recent .swatch i { width: 34px; height: 34px; }
.recent .swatch.on::before { inset: 3px 9px; }

.current-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); font-weight: 600; }
.chip-dot { width: 22px; height: 22px; border-radius: 50%; background: var(--cur); box-shadow: inset 0 0 0 1px rgba(46,42,37,.15); }
.patterns { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.pat { aspect-ratio: 1; border-radius: 12px; background-color: #fff; background-size: 48px 48px; box-shadow: inset 0 0 0 1px rgba(46,42,37,.12); position: relative; overflow: hidden; }
.pat.on { box-shadow: 0 0 0 3px var(--ink), inset 0 0 0 1px rgba(46,42,37,.12); }
.pat span { position: absolute; left: 4px; right: 4px; bottom: 4px; font-size: 10px; font-weight: 700; background: rgba(255,253,248,.92); color: #2E2A25; border-radius: 6px; padding: 1px 4px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pat.custom-up { display: grid; place-items: center; }
.full-range { width: 100%; }
.upload { justify-content: flex-start; font-size: 13px; padding: 0 10px; }
.hint { font-size: 12px; color: var(--ink-3); line-height: 1.35; }

/* ---------- popovers ---------- */
.scrim { position: fixed; inset: 0; z-index: 20; background: transparent; }
.scrim.dim { background: rgba(31,27,23,.28); }
.popover { position: fixed; z-index: 21; background: var(--surface); border-radius: var(--r-card); box-shadow: var(--shadow-pop); border: 1px solid var(--line); padding: 14px; animation: pop 200ms var(--ease); }
@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(.98); } }
.picker-pop { width: 272px; display: flex; flex-direction: column; gap: 12px; }
.sv { position: relative; height: 180px; border-radius: 10px; overflow: hidden; touch-action: none; cursor: crosshair; }
.sv canvas { width: 100%; height: 100%; display: block; }
.sv-knob, .hue-knob { position: absolute; width: 22px; height: 22px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25), 0 2px 4px rgba(0,0,0,.2); transform: translate(-50%, -50%); pointer-events: none; }
.hue { position: relative; height: 22px; border-radius: 11px; touch-action: none; cursor: pointer;
  background: linear-gradient(90deg, #f00, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00); }
.hue-knob { top: 50%; }
.pick-row { display: flex; gap: 8px; align-items: center; }
.pick-preview { width: 40px; height: 40px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1px rgba(46,42,37,.15); }
#hexInput { flex: 1; min-width: 0; height: 40px; border-radius: var(--r-ctl); border: 1px solid var(--line); background: var(--raised); color: var(--ink); font: 600 15px var(--font); padding: 0 10px; text-transform: uppercase; -webkit-user-select: text; user-select: text; }

.sheet-panel { position: fixed; z-index: 21; right: 16px; top: 72px; bottom: 16px; width: min(360px, calc(100vw - 32px)); background: var(--surface); border-radius: var(--r-sheet); box-shadow: var(--shadow-pop);
  border: 1px solid var(--line); display: flex; flex-direction: column; animation: slide 260ms var(--ease); }
@keyframes slide { from { opacity: 0; transform: translateX(16px); } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 10px 6px 20px; }
.sheet-head h2 { font-size: 18px; font-weight: 700; }
.palette-list { overflow-y: auto; padding: 6px 12px 16px; display: flex; flex-direction: column; gap: 4px; }
.pal-row { display: flex; flex-direction: column; gap: 7px; padding: 10px; border-radius: 12px; text-align: left; }
.pal-row:hover { background: color-mix(in srgb, var(--sel) 60%, transparent); }
.pal-row.on { background: var(--sel); }
.pal-row b { font-size: 14px; }
.pal-strip { display: flex; height: 26px; border-radius: 8px; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(46,42,37,.1); }
.pal-strip i { flex: 1; }

.menu { width: 350px; display: flex; flex-direction: column; gap: 4px; padding: 10px; }
.menu-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 48px; padding: 0 8px; font-weight: 600; }
.menu-note { font-size: 12.5px; color: var(--ink-3); padding: 0 8px 4px; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }
.menu-item { display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 0 10px; border-radius: var(--r-ctl); font-weight: 600; text-align: left; }
.menu-item:hover { background: var(--sel); }
.menu-item.danger { color: var(--danger); }
.toggle { cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle i { width: 46px; height: 28px; border-radius: 14px; background: var(--line); position: relative; flex: none; transition: background-color 200ms var(--ease); }
.toggle i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform 200ms var(--ease); }
.toggle input:checked + i { background: var(--accent); }
.toggle input:checked + i::after { transform: translateX(18px); }
.toggle input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }

.dialog { position: fixed; z-index: 22; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(360px, calc(100vw - 32px)); background: var(--surface); border-radius: var(--r-sheet);
  box-shadow: var(--shadow-pop); padding: 22px; display: flex; flex-direction: column; gap: 18px; font-weight: 600; font-size: 16px; animation: pop 200ms var(--ease); }
.dlg-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- finished moment ---------- */
body.finishing .topbar, body.finishing .rail, body.finishing .tray { opacity: .4; transition: opacity 400ms var(--ease); }
.finish { position: fixed; z-index: 15; inset: 0; pointer-events: none; }
.finish .stamp { position: absolute; width: 132px; height: 132px; border-radius: 50%; border: 4px solid var(--accent); color: var(--accent); display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: color-mix(in srgb, #FFFDF8 80%, transparent); transform: rotate(-14deg); box-shadow: inset 0 0 0 5px color-mix(in srgb, #FFFDF8 80%, transparent), inset 0 0 0 7px var(--accent);
  animation: stamp 520ms var(--ease) both 300ms; }
.stamp-word { font-size: 24px; font-weight: 800; letter-spacing: .02em; }
.stamp-date { font-size: 12px; font-weight: 700; margin-top: 2px; }
@keyframes stamp { 0% { opacity: 0; transform: rotate(-14deg) scale(1.8); } 60% { opacity: 1; transform: rotate(-14deg) scale(.94); } 100% { transform: rotate(-14deg) scale(1); } }
.finish-actions { position: absolute; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; gap: 10px; pointer-events: auto; animation: rise 300ms var(--ease) both 700ms;
  background: var(--surface); padding: 8px; border-radius: 18px; box-shadow: var(--shadow-pop); }

/* ---------- iPad portrait / narrow: one bottom dock ---------- */
@media (max-width: 980px) and (orientation: portrait), (max-width: 760px) {
  .workspace, body.lefty .workspace { grid-template-columns: 1fr; grid-template-rows: 1fr auto auto; }
  .stage { order: 1 !important; }
  .tray { order: 2 !important; border: 0 !important; border-top: 1px solid var(--line) !important; flex-direction: row; align-items: center; overflow-x: auto; overflow-y: hidden; padding: 8px 12px; gap: 12px; }
  .rail { order: 3 !important; flex-direction: row; justify-content: center; border: 0 !important; border-top: 1px solid var(--line) !important; padding: 6px 12px calc(6px + env(safe-area-inset-bottom)); }
  .rail-spacer { flex: 0 0 18px; }
  .zoom { flex-direction: row; }
  .tray-tabs { flex-direction: column; flex: none; width: 92px; }
  .tray-tabs button { min-height: 32px; }
  .tab-panel { flex-direction: row; align-items: center; flex: none; }
  .tray h3 { display: none; }
  .palette-name { width: 120px; flex: none; }
  .swatches { display: flex; gap: 2px; }
  .recent { padding-left: 10px; border-left: 1px solid var(--line); }
  .recent .swatch { width: 44px; height: 56px; } .recent .swatch.on::before { inset: 6px 1px; }
  .patterns { display: flex; gap: 8px; }
  .pat { width: 64px; height: 64px; flex: none; }
  #patBg { width: 210px; flex: none; }
  .full-range { width: 120px; flex: none; }
  .upload { flex: none; } .hint { display: none; }
  .options { bottom: 12px; }
  .tb-mid .seg button { padding: 0 10px; }
  .back span { display: none; }
}
@media (max-width: 640px) {
  .page-title { display: none; }
  .tool { width: 54px; } .tool span { display: none; } .tool { min-height: 50px; }
  .opt-slider input { width: 90px; }
  .options { flex-wrap: wrap; justify-content: center; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 20px 14px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 80ms !important; transition-duration: 80ms !important; } }

/* ---------- my pages, photo dialog, footer ---------- */
.mine { margin-bottom: 40px; }
.mine h2 { margin-bottom: 14px; }
.add-card .thumb { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; background: transparent; box-shadow: none;
  border: 2px dashed color-mix(in srgb, var(--ink) 22%, transparent); color: var(--ink-2); text-align: center; padding: 14px; }
.add-card:hover .thumb { border-color: var(--accent); color: var(--accent); transform: translateY(-3px); box-shadow: none; }
.add-card .thumb .ico { width: 34px; height: 34px; }
.add-card .thumb b { font-size: 14px; color: var(--ink); line-height: 1.25; }
.add-card .thumb small { font-size: 12px; }
.photo-dlg { width: min(440px, calc(100vw - 24px)); padding: 6px 18px 18px; gap: 12px; max-height: calc(100vh - 24px); overflow: auto; }
.photo-dlg .sheet-head { padding: 8px 0 0; }
.photo-preview { position: relative; aspect-ratio: 4 / 5; height: min(52vh, 500px); margin: 0 auto; width: auto; background: #FFFDF8; border-radius: 12px; box-shadow: var(--shadow-page); overflow: hidden; display: grid; place-items: center; }
.photo-preview canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.photo-working { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: #6F665B; font-size: 14px; background: rgba(255,253,248,.82); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid #E3D9C8; border-top-color: #A8541F; animation: spin 900ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.photo-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-weight: 600; font-size: 15px; }
.home-foot { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; margin-top: 56px; }
.foot-card { border-top: 1px solid var(--line); padding-top: 18px; display: flex; flex-direction: column; gap: 8px; }
.foot-card h3 { font-size: 15px; font-weight: 700; }
.foot-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.foot-actions .btn { font-size: 14px; }
@media (display-mode: standalone) { #installCard { display: none; } }

/* settings from the home screen */
.head-actions { display: flex; align-items: center; gap: 8px; }
.menu.home .editor-only { display: none; }
.menu-note.version { font-size: 11px; opacity: .8; }

.recent-hint { margin-top: -6px; font-size: 11px; }
.recent:empty + .recent-hint, #recent:empty ~ .recent-hint { display: none; }
.menu .seg.small button { padding: 0 9px; font-size: 13px; }
@media (max-width: 980px) and (orientation: portrait), (max-width: 760px) { .recent-hint { display: none; } }

.btn.sync { position: relative; font-size: 14px; padding: 0 12px; }
.btn.sync .ico { width: 20px; height: 20px; }
.btn.sync.busy .ico { animation: spin 900ms linear infinite; }
.btn.sync.has-update { background: var(--accent); color: var(--on-accent); }
.sync-dot { position: absolute; top: 6px; right: 6px; width: 9px; height: 9px; border-radius: 50%; background: #E5484D; box-shadow: 0 0 0 2px var(--bg); }
@media (max-width: 640px) { .btn.sync span { display: none; } .home-head { flex-wrap: wrap; } }
