:root {
  --ink: oklch(0.19 0.04 268); --muted: oklch(0.554 0.046 257);
  --line: oklch(0.929 0.013 255); --input-line: oklch(0.929 0.013 255);
  --surface: oklch(1 0 0);
  --wash: oklch(0.988 0.006 285); --muted-bg: oklch(0.968 0.007 248);
  --ghost: oklch(0.72 0.015 265); --accent: #2145f3;
  --accent-ink: oklch(0.99 0 0);
  --shadow: 0 24px 60px -20px oklch(0.2 0.06 265 / .28),
            0 4px 14px -6px oklch(0.2 0.06 265 / .12);
  --radius: 1.25rem; --radius-card: 28px; --radius-photo: 24px;
  --radius-button: 16px; --radius-chip: 999px; --radius-toast: 12px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-hand: "Segoe Script", "Bradley Hand", "Snell Roundhand", cursive;
  --text-xs: 12px; --text-sm: 14px; --text-base: 15px; --text-body: 16px;
  --warn-bg: #fff3e6; --warn-ink: #8a4b04;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: oklch(0.97 0.005 260); --muted: oklch(0.704 0.04 257);
    --line: oklch(1 0 0 / 10%); --input-line: oklch(1 0 0 / 15%);
    --surface: oklch(0.22 0.03 266);
    --wash: oklch(0.16 0.025 266); --muted-bg: oklch(0.279 0.041 260);
    --ghost: oklch(0.52 0.02 265); --accent: #2145f3;
    --accent-ink: oklch(0.99 0 0);
    --shadow: 0 24px 60px -20px oklch(0.2 0.06 265 / .28),
              0 4px 14px -6px oklch(0.2 0.06 265 / .12);
    --radius: 1.25rem; --radius-card: 28px; --radius-photo: 24px;
    --radius-button: 16px; --radius-chip: 999px; --radius-toast: 12px;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
    --font-hand: "Segoe Script", "Bradley Hand", "Snell Roundhand", cursive;
    --text-xs: 12px; --text-sm: 14px; --text-base: 15px; --text-body: 16px;
    --warn-bg: #2a1f10; --warn-ink: #f0b878;
  }
}
:root[data-theme="light"] {
  --ink: oklch(0.19 0.04 268); --muted: oklch(0.554 0.046 257);
  --line: oklch(0.929 0.013 255); --input-line: oklch(0.929 0.013 255);
  --surface: oklch(1 0 0);
  --wash: oklch(0.988 0.006 285); --muted-bg: oklch(0.968 0.007 248);
  --ghost: oklch(0.72 0.015 265); --accent: #2145f3;
  --accent-ink: oklch(0.99 0 0);
  --shadow: 0 24px 60px -20px oklch(0.2 0.06 265 / .28),
            0 4px 14px -6px oklch(0.2 0.06 265 / .12);
  --radius: 1.25rem; --radius-card: 28px; --radius-photo: 24px;
  --radius-button: 16px; --radius-chip: 999px; --radius-toast: 12px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-hand: "Segoe Script", "Bradley Hand", "Snell Roundhand", cursive;
  --text-xs: 12px; --text-sm: 14px; --text-base: 15px; --text-body: 16px;
  --warn-bg: #fff3e6; --warn-ink: #8a4b04;
}
:root[data-theme="dark"] {
  --ink: oklch(0.97 0.005 260); --muted: oklch(0.704 0.04 257);
  --line: oklch(1 0 0 / 10%); --input-line: oklch(1 0 0 / 15%);
  --surface: oklch(0.22 0.03 266);
  --wash: oklch(0.16 0.025 266); --muted-bg: oklch(0.279 0.041 260);
  --ghost: oklch(0.52 0.02 265); --accent: #2145f3;
  --accent-ink: oklch(0.99 0 0);
  --shadow: 0 24px 60px -20px oklch(0.2 0.06 265 / .28),
            0 4px 14px -6px oklch(0.2 0.06 265 / .12);
  --radius: 1.25rem; --radius-card: 28px; --radius-photo: 24px;
  --radius-button: 16px; --radius-chip: 999px; --radius-toast: 12px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-hand: "Segoe Script", "Bradley Hand", "Snell Roundhand", cursive;
  --text-xs: 12px; --text-sm: 14px; --text-base: 15px; --text-body: 16px;
  --warn-bg: #2a1f10; --warn-ink: #f0b878;
}

* { box-sizing: border-box; }
/* Author display rules (flex on .row etc.) beat the UA stylesheet's [hidden] —
   without this, "hidden" elements with an explicit display keep showing. */
[hidden] { display: none !important; }
html, body { min-height: 100%; margin: 0; background: var(--wash); color: var(--ink); }
body {
  font: var(--text-body)/1.55 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

.bar {
  position: sticky; top: 0; z-index: 30;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
  background: color-mix(in srgb, var(--wash) 85%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.bar-inner {
  width: 100%; max-width: 420px; min-height: 54px; margin: 0 auto; padding: 10px 20px;
  display: flex; align-items: center; gap: 8px;
}
.brand { font-weight: 800; font-size: var(--text-base); letter-spacing: -.02em; }
.bar .ghost, .bar .edit-chip { margin-left: auto; }

main { width: 100%; max-width: 420px; margin: 0 auto; padding: 24px 20px 64px; }

/* ---- the card, and the invisible tap targets sitting on top of it ---- */
.stage {
  position: relative; aspect-ratio: 3 / 4; overflow: hidden;
  border-radius: var(--radius-card); background: var(--surface); box-shadow: var(--shadow);
}
#preview { display: block; width: 100%; height: 100%; touch-action: none; }
#preview.reveal { animation: settle-in .7s cubic-bezier(.16, 1, .3, 1) both; }
@keyframes settle-in {
  from { opacity: 0; transform: scale(1.06) translateY(8px); filter: blur(6px); }
  to   { opacity: 1; transform: scale(1) translateY(0); filter: blur(0); }
}

.hits { position: absolute; inset: 0; }
.hit {
  position: absolute; min-width: 0; min-height: 0; padding: 0; margin: 0;
  background: transparent; border: 1.5px solid transparent; border-radius: var(--radius-toast);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: background-color .16s ease, border-color .16s ease;
}
.hit:hover, .hit:focus-visible {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-color: var(--accent);
  outline: none;
}
.hit.hit-flash {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border-color: var(--accent);
}
.photo-drag-hint {
  position: absolute; left: 50%; z-index: 2; width: max-content; max-width: calc(100% - 40px);
  padding: 8px 12px; border: 1px solid color-mix(in srgb, var(--surface) 45%, transparent);
  border-radius: var(--radius-chip); background: color-mix(in srgb, var(--ink) 82%, transparent);
  color: var(--accent-ink); font-size: var(--text-xs); font-weight: 600; line-height: 1.35;
  text-align: center; pointer-events: none; transform: translate(-50%, -100%);
}
.photo-drag-hint.is-showing { animation: photo-drag-hint-life 2.5s ease both; }
@keyframes photo-drag-hint-life {
  0% { opacity: 0; }
  10%, 84% { opacity: 1; }
  100% { opacity: 0; }
}

.note-inline-row { display: flex; align-items: center; gap: 8px; margin-top: 16px; }
.note-inline-row #noteInline {
  width: 100%; min-width: 0; min-height: 46px; flex: 1; padding: 10px 14px;
  border: 1px solid var(--input-line); border-radius: var(--radius-button); background: var(--muted-bg);
  color: var(--ink); font: inherit; line-height: 24px;
}
.single-line-editable {
  overflow-x: auto; overflow-y: hidden; white-space: nowrap;
  caret-color: var(--ink); -webkit-user-select: text; user-select: text;
}
.single-line-editable:empty::before {
  content: attr(data-placeholder); color: var(--muted); pointer-events: none;
}
.single-line-editable:focus {
  border-color: var(--accent); outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent);
}
.chip {
  width: auto; min-height: 34px; padding: 6px 12px; border: 1px solid var(--line);
  border-radius: var(--radius-chip); background: transparent; color: var(--muted);
  font-size: var(--text-xs); font-weight: 600;
}
.edit-chip::before { content: "✎"; margin-right: 4px; }
.bar button.ghost {
  width: auto; min-height: 34px; max-width: 190px; padding: 6px 8px;
  overflow: hidden; border: 0; background: transparent; color: var(--muted);
  font-size: var(--text-xs); font-weight: 600; text-overflow: ellipsis; white-space: nowrap;
}

.warn { margin: 16px 0 0; padding: 12px 14px; border-radius: var(--radius-button);
        background: var(--warn-bg); color: var(--warn-ink); font-size: var(--text-sm); }

.actions { display: flex; flex-direction: column; gap: 12px; margin-top: 24px; }
.row { display: flex; gap: 12px; align-items: center; }
.row > * { flex: 1; }

button {
  min-height: 44px; padding: 14px 18px; border: 1px solid var(--line);
  border-radius: var(--radius-button); background: var(--surface); color: var(--ink);
  font: inherit; font-size: var(--text-sm); font-weight: 500; cursor: pointer;
  transition: opacity .16s ease, transform .16s ease;
}
button:active { opacity: .7; transform: scale(.98); }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button.primary {
  width: 100%; padding: 16px 20px; border-color: transparent;
  background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow);
  font-size: var(--text-base); font-weight: 600;
}
button.primary:active { opacity: .85; }
button.primary.compact {
  width: auto; min-height: 46px; padding: 12px 20px; flex: 0 0 auto;
  font-size: var(--text-sm); box-shadow: none;
}
.linklike { background: none; border: none; padding: 0; color: inherit;
            font-weight: 700; text-decoration: underline; cursor: pointer; }

input[type="text"], input[type="email"], input[type="tel"], select {
  width: 100%; padding: 12px 14px; border: 1px solid var(--input-line);
  border-radius: var(--radius-button); background: var(--muted-bg); color: var(--ink); font: inherit;
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }

.status-slot { min-height: 20px; margin-top: 16px; }
.status {
  margin: 0; padding: 10px 14px; border-radius: var(--radius-toast);
  background: var(--muted-bg); color: var(--muted); font-size: var(--text-xs); text-align: center;
  animation: toast-life 3.2s ease both;
}
@keyframes toast-life {
  0% { opacity: 0; transform: translateY(3px); }
  8%, 88% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-2px); }
}
.sub { margin: 8px 2px 0; font-size: var(--text-xs); color: var(--muted); }

.backup { margin-top: 20px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-button); }
.backup summary {
  display: flex; align-items: center; gap: 9px; min-height: 48px; padding: 12px 16px;
  color: var(--ink); font-size: var(--text-sm); font-weight: 500; cursor: pointer; list-style: none;
}
.backup summary::-webkit-details-marker { display: none; }
.backup summary::before {
  content: "✓"; display: grid; width: 15px; height: 15px; place-items: center;
  border: 1px solid var(--muted); border-radius: 6px; color: var(--muted); font-size: 9px;
}
.backup summary::after {
  content: "⌄"; margin-left: auto; color: var(--muted);
  transition: transform .2s ease;
}
.backup[open] summary::after { transform: rotate(180deg); }
.backup-body { padding: 14px 16px 16px; border-top: 1px solid var(--line); }
.backup p { margin: 0 0 12px; color: var(--muted); font-size: var(--text-xs); line-height: 1.6; }
.backup .row button { padding: 10px 8px; border-radius: var(--radius-toast); font-size: var(--text-xs); }

/* ---- docked editor: rises over the keyboard, card stays visible above it ---- */
.dock-scrim {
  position: fixed; inset: -60%; z-index: 40;
  background: color-mix(in srgb, var(--ink) 25%, transparent);
}
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  padding: 24px 20px calc(52px + env(safe-area-inset-bottom));
  border: 1px solid var(--line); border-bottom: 0; border-radius: 28px 28px 0 0;
  background: var(--surface); box-shadow: var(--shadow);
  animation: dock-in .3s cubic-bezier(.16, 1, .3, 1) both;
}
.dock::after {
  content: ""; position: absolute; top: 100%; left: -1px; right: -1px; height: 160px;
  background: var(--surface); pointer-events: none;
}
@keyframes dock-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.dock-handle {
  position: absolute; top: 0; left: 50%; width: 88px; min-height: 24px; padding: 0;
  border: 0; border-radius: 0; background: transparent; transform: translateX(-50%);
  touch-action: none; cursor: grab;
}
.dock-handle::after {
  content: ""; position: absolute; top: 8px; left: 50%; width: 40px; height: 4px;
  border-radius: var(--radius-chip); background: var(--line); transform: translateX(-50%);
}
.dock-handle:active { opacity: 1; transform: translateX(-50%); cursor: grabbing; }
.dock-inner { max-width: 420px; margin: 0 auto; }
.dock label {
  display: block; margin: 0 2px 8px; color: var(--muted);
  font-size: 11px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase;
}
.dock #dockInput {
  width: 100%; min-width: 0; min-height: 46px; padding: 10px 14px;
  border: 1px solid var(--input-line); border-radius: var(--radius-button); background: var(--surface);
  color: var(--ink); caret-color: var(--ink); font: inherit; font-size: 16px; line-height: 24px;
}
.dock #dockTest { margin-top: 12px; color: var(--accent); }

/* ---- first-save restore insurance ---- */
.save-modal {
  position: fixed; inset: 0; z-index: 80; display: grid; place-items: center;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--ink) 42%, transparent);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.save-modal-panel {
  width: min(100%, 420px); max-height: 100%; overflow-y: auto; padding: 24px;
  border: 1px solid var(--line); border-radius: 28px; background: var(--surface);
  box-shadow: var(--shadow); text-align: center;
}
.save-modal h2 { margin: 0; font-size: 24px; line-height: 1.2; letter-spacing: -.02em; }
.save-modal #saveModalBody { margin: 10px 0 18px; color: var(--muted); font-size: var(--text-sm); }
.save-modal canvas {
  display: block; width: min(100%, 320px); height: auto; margin: 0 auto;
  border-radius: var(--radius-button); background: #fff;
}
.save-modal-foot { margin: 10px 0 18px; color: var(--muted); font-size: var(--text-xs); }

@media (max-width: 360px) {
  .bar button.ghost { max-width: 132px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  button:active { transform: none; }
}
