@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/static/fonts/inter-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/static/fonts/inter-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --bg: #f4f2ed;
  --paper: #fffefb;
  --ink: #1c1d1b;
  --ink-soft: #4a4c47;
  --muted: #8a8b84;
  --line: #e4e1d9;
  --line-strong: #d3cfc4;
  --accent: #2b7a50;
  --accent-ink: #ffffff;
  --accent-soft: #e2f0e7;
  --warn: #c2772a;
  --danger: #b4412f;
  --chrome: rgba(244, 242, 237, 0.82);
  --shadow-page: 0 1px 2px rgba(28, 29, 27, 0.04), 0 8px 24px rgba(28, 29, 27, 0.06), 0 30px 60px -20px rgba(28, 29, 27, 0.12);
  --shadow-pop: 0 10px 40px rgba(28, 29, 27, 0.14), 0 2px 6px rgba(28, 29, 27, 0.06);
  --radius: 14px;
  --font: "Inter", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121412;
    --paper: #1b1e1b;
    --ink: #ebe9e3;
    --ink-soft: #bdbbb4;
    --muted: #7f817a;
    --line: #2a2e2a;
    --line-strong: #3a3f3a;
    --accent: #5cbf88;
    --accent-ink: #0d1f15;
    --accent-soft: #1f3327;
    --warn: #e0a057;
    --danger: #e3735f;
    --chrome: rgba(18, 20, 18, 0.8);
    --shadow-page: 0 1px 2px rgba(0, 0, 0, 0.4), 0 20px 50px -20px rgba(0, 0, 0, 0.6);
    --shadow-pop: 0 10px 40px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  font-size: 17px;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
}
.brand img { width: 28px; height: 28px; border-radius: 8px; }

/* ---------- Sheet typography (shared by the editor, the measurer and the landing preview) ---------- */

.sheet-content {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  overflow-wrap: anywhere;
  font-feature-settings: "cv11", "ss01";
}
.sheet-content > :first-child { margin-top: 0; }
.sheet-content > :last-child { margin-bottom: 0; }
.sheet-content p, .sheet-content div { margin: 0 0 0.55em; }
.sheet-content h1 {
  font-size: 30px;
  line-height: 1.18;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin: 0.2em 0 0.45em;
}
.sheet-content h2 {
  font-size: 18px;
  line-height: 1.3;
  font-weight: 650;
  letter-spacing: -0.012em;
  margin: 1.1em 0 0.35em;
}
.sheet-content ul, .sheet-content ol { margin: 0 0 0.6em; padding-left: 1.4em; }
.sheet-content li { margin: 0.12em 0; padding-left: 0.15em; }
.sheet-content li::marker { color: var(--muted); }
.sheet-content blockquote {
  margin: 0 0 0.6em;
  padding-left: 0.9em;
  border-left: 3px solid var(--accent);
  color: var(--ink-soft);
}
.sheet-content hr { border: 0; border-top: 1px solid var(--line-strong); margin: 1em 0; }
.sheet-content strong, .sheet-content b { font-weight: 650; }

.sheet-content ul.checklist { list-style: none; padding-left: 0; }
.sheet-content ul.checklist > li { position: relative; padding-left: 1.75em; }
.sheet-content ul.checklist > li::before {
  content: "";
  position: absolute;
  left: 0.1em;
  top: 0.28em;
  width: 1.05em;
  height: 1.05em;
  border-radius: 0.32em;
  border: 1.5px solid var(--line-strong);
  background: var(--paper);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.sheet-content ul.checklist > li[data-checked="true"] { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line-strong); }
.sheet-content ul.checklist > li[data-checked="true"]::before {
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 8.4l2.6 2.6L12 5.6' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 80% no-repeat;
  border-color: var(--accent);
}

/* ---------- Landing ---------- */

.landing { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; overflow-x: hidden; }

.landing-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: max(20px, env(safe-area-inset-top)) clamp(16px, 5vw, 56px) 20px;
}

.landing-main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: clamp(32px, 6vw, 96px);
  align-items: center;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
  padding: clamp(16px, 4vw, 48px) clamp(16px, 5vw, 56px) 48px;
}

.hero h1 {
  font-size: clamp(42px, 6.4vw, 76px);
  line-height: 1.02;
  letter-spacing: -0.045em;
  font-weight: 700;
  margin: 0 0 22px;
}
.hero h1 span { color: var(--accent); }
.hero p.lede {
  font-size: clamp(17px, 1.6vw, 19px);
  line-height: 1.55;
  color: var(--ink-soft);
  max-width: 30em;
  margin: 0 0 36px;
}

.principles { display: flex; flex-wrap: wrap; gap: 10px 22px; margin: 0; padding: 0; list-style: none; }
.principles li { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-soft); font-size: 14px; }
.principles svg { width: 18px; height: 18px; color: var(--accent); flex: none; }

.auth-stage { position: relative; display: flex; justify-content: center; }

.preview-sheet {
  position: absolute;
  width: 78%;
  aspect-ratio: 210 / 297;
  top: 50%;
  left: 50%;
  translate: -20% -54%;
  rotate: 5deg;
  background: var(--paper);
  border-radius: 6px;
  box-shadow: var(--shadow-page);
  padding: 9% 9%;
  overflow: hidden;
  pointer-events: none;
  opacity: 0.9;
}
.preview-sheet .sheet-content { font-size: 11px; }
.preview-sheet .sheet-content h1 { font-size: 21px; }
.preview-sheet .sheet-content h2 { font-size: 13px; }

.auth-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow-pop);
  padding: 30px 28px 26px;
}
.auth-card h2 { margin: 0 0 4px; font-size: 21px; letter-spacing: -0.02em; }
.auth-card .sub { margin: 0 0 22px; color: var(--muted); font-size: 14px; }

.provider-buttons { display: grid; gap: 10px; }
.provider-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 46px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--paper);
  font-weight: 550;
  text-decoration: none;
  color: var(--ink);
  transition: transform 0.08s, background 0.15s;
}
.provider-button:hover { background: var(--bg); }
.provider-button:active { transform: scale(0.985); }
.provider-button svg { width: 18px; height: 18px; }
.provider-button.apple { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.provider-button.apple:hover { opacity: 0.9; background: var(--ink); }

.divider { display: flex; align-items: center; gap: 12px; margin: 20px 0; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; font-weight: 550; color: var(--ink-soft); margin-bottom: 6px; }
.field input {
  width: 100%;
  height: 46px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--bg);
  padding: 0 14px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); background: var(--paper); }

.primary-button {
  width: 100%;
  height: 48px;
  margin-top: 6px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  font-size: 15px;
  transition: filter 0.15s, transform 0.08s;
}
.primary-button:hover { filter: brightness(1.06); }
.primary-button:active { transform: scale(0.985); }
.primary-button:disabled { opacity: 0.6; cursor: progress; }

.form-error { min-height: 20px; margin: 10px 0 0; color: var(--danger); font-size: 13.5px; }
.switch-mode { margin: 14px 0 0; text-align: center; font-size: 14px; color: var(--muted); }
.link-button { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; }

.landing-footer { text-align: center; padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); color: var(--muted); font-size: 13px; }

@media (max-width: 880px) {
  .landing-main { grid-template-columns: 1fr; gap: 36px; padding-top: 8px; }
  .hero { text-align: left; }
  .preview-sheet { display: none; }
  .auth-card { max-width: none; padding: 26px 20px 22px; }
}

/* ---------- Landing: marketing sections ---------- */

.landing-nav { display: flex; align-items: center; gap: 26px; font-size: 14.5px; }
.landing-nav a { color: var(--ink-soft); text-decoration: none; transition: color 0.15s; }
.landing-nav a:hover { color: var(--ink); }
.landing-nav .nav-cta {
  color: var(--accent-ink);
  background: var(--accent);
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 600;
}
.landing-nav .nav-cta:hover { color: var(--accent-ink); filter: brightness(1.06); }

.section { max-width: 1180px; margin: 0 auto; padding: clamp(64px, 9vw, 120px) clamp(16px, 5vw, 56px); }
.section-tinted { max-width: none; background: var(--paper); border-block: 1px solid var(--line); }
.section-tinted > * { max-width: 1068px; margin-left: auto; margin-right: auto; }

.eyebrow {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
.section-title {
  margin: 0 0 clamp(32px, 4vw, 52px);
  font-size: clamp(30px, 4.2vw, 48px);
  line-height: 1.08;
  letter-spacing: -0.035em;
  font-weight: 700;
  max-width: 18em;
}

.band { text-align: center; padding: clamp(72px, 10vw, 128px) clamp(16px, 5vw, 56px); }
.band-quote { background: var(--ink); color: var(--paper); }
.big-statement {
  margin: 0 auto 18px;
  font-size: clamp(30px, 4.6vw, 56px);
  line-height: 1.1;
  letter-spacing: -0.035em;
  font-weight: 700;
  max-width: 16em;
}
.big-statement span { color: color-mix(in srgb, var(--paper) 55%, transparent); }
.band-sub { margin: 0 auto; max-width: 34em; font-size: 18px; color: color-mix(in srgb, var(--paper) 72%, transparent); }

.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: clamp(20px, 3vw, 40px); }
.steps li { position: relative; }
.step-number {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 18px;
}
.steps h3, .benefits h3, .persona h3 { margin: 0 0 8px; font-size: 19px; letter-spacing: -0.015em; }
.steps p, .benefits p, .persona p { margin: 0; color: var(--ink-soft); font-size: 15.5px; line-height: 1.6; }

.benefits { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.benefits article { background: var(--paper); padding: clamp(24px, 3vw, 36px); }

.personas { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.persona {
  padding: 28px 26px;
  border-radius: 18px;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(28, 29, 27, 0.03);
}

.features { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 34px 40px; }
.features li { display: flex; flex-direction: column; gap: 6px; padding-left: 18px; border-left: 2px solid var(--accent); }
.features strong { font-size: 16.5px; letter-spacing: -0.01em; }
.features span { color: var(--ink-soft); font-size: 15px; line-height: 1.55; }
.features code { font-size: 0.92em; background: var(--accent-soft); color: var(--accent); padding: 1px 5px; border-radius: 5px; }

.mac-band { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: clamp(32px, 6vw, 80px); align-items: center; }
.mac-copy p { color: var(--ink-soft); font-size: 17px; line-height: 1.6; margin: 0 0 26px; }
.mac-copy .section-title { margin-bottom: 18px; }
.mac-download { display: inline-flex; align-items: center; justify-content: center; gap: 10px; width: auto; padding: 0 24px; text-decoration: none; }
.mac-download svg { width: 18px; height: 18px; }
.mac-copy .fine-print { margin: 14px 0 0; font-size: 13px; color: var(--muted); }

.mac-window {
  border-radius: 14px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-pop), 0 40px 80px -30px rgba(28, 29, 27, 0.35);
}
.mac-titlebar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.mac-titlebar span { width: 12px; height: 12px; border-radius: 50%; background: #ff5f57; }
.mac-titlebar span:nth-child(2) { background: #febc2e; }
.mac-titlebar span:nth-child(3) { background: #28c840; }
.mac-titlebar em { margin: 0 auto; font-style: normal; font-size: 12.5px; font-weight: 600; color: var(--muted); letter-spacing: 0.02em; }
.mac-sheet {
  margin: 26px auto 0;
  width: 78%;
  aspect-ratio: 210 / 230;
  background: var(--paper);
  border-radius: 4px 4px 0 0;
  box-shadow: var(--shadow-page);
  padding: 9% 10% 0;
  font-size: 12px;
}
.mac-sheet.sheet-content h1 { font-size: 24px; }
.mac-sheet.sheet-content h2 { font-size: 14px; }

.faq { display: grid; gap: 10px; max-width: 760px; }
.faq details { border: 1px solid var(--line); border-radius: 14px; background: var(--paper); padding: 0 22px; }
.faq summary {
  cursor: pointer;
  list-style: none;
  padding: 18px 0;
  font-weight: 600;
  font-size: 16.5px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; color: var(--muted); font-weight: 400; font-size: 20px; line-height: 1; transition: rotate 0.2s; }
.faq details[open] summary::after { rotate: 45deg; }
.faq details p { margin: 0 0 18px; color: var(--ink-soft); line-height: 1.6; }

.band-cta { background: var(--accent-soft); }
.band-cta h2 { margin: 0 0 10px; font-size: clamp(30px, 4.2vw, 46px); letter-spacing: -0.035em; }
.band-cta p { margin: 0 0 28px; color: var(--ink-soft); font-size: 17px; }
.cta-button { display: inline-grid; place-items: center; width: auto; padding: 0 30px; text-decoration: none; }

.landing-footer a { color: var(--ink-soft); }

@media (max-width: 880px) {
  .landing-nav a:not(.nav-cta) { display: none; }
  .steps, .personas, .features, .benefits, .mac-band { grid-template-columns: 1fr; }
  .features { gap: 24px; }
}

/* ---------- Editor app ---------- */

.app-body { min-height: 100vh; min-height: 100dvh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: var(--chrome);
  -webkit-backdrop-filter: saturate(1.6) blur(16px);
  backdrop-filter: saturate(1.6) blur(16px);
}
.topbar-right { display: flex; align-items: center; gap: 6px; }

.save-status { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; padding: 0 6px; white-space: nowrap; }
.save-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); transition: background 0.2s; }
.save-status[data-state="saving"]::before { background: var(--muted); }
.save-status[data-state="offline"]::before { background: var(--warn); }

.fill-meter { display: inline-flex; align-items: center; gap: 7px; padding: 6px 10px; border-radius: 999px; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.fill-meter svg { width: 20px; height: 20px; rotate: -90deg; }
.fill-meter .track { stroke: var(--line-strong); }
.fill-meter .value { stroke: var(--accent); transition: stroke-dashoffset 0.3s ease, stroke 0.3s; }
.fill-meter[data-level="high"] .value { stroke: var(--warn); }
.fill-meter[data-level="full"] .value { stroke: var(--danger); }

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-soft);
  transition: background 0.15s, color 0.15s;
}
.icon-button:hover { background: var(--line); color: var(--ink); }
.icon-button svg { width: 20px; height: 20px; }

.menu {
  position: absolute;
  top: calc(100% - 4px);
  right: max(12px, env(safe-area-inset-right));
  min-width: 240px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-pop);
  padding: 6px;
  z-index: 30;
}
.menu[hidden] { display: none; }
.menu .menu-email { padding: 10px 12px 8px; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: 0;
  border-radius: 9px;
  background: none;
  font-size: 14.5px;
}
.menu button:hover { background: var(--bg); }
.menu button svg { width: 18px; height: 18px; color: var(--muted); }
.menu button.danger { color: var(--danger); }
.menu button.danger svg { color: var(--danger); }

.toolbar {
  position: sticky;
  top: calc(58px + env(safe-area-inset-top));
  z-index: 15;
  display: flex;
  justify-content: center;
  pointer-events: none;
  padding: 0 12px;
}
.toolbar-inner {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-pop);
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.toolbar-inner::-webkit-scrollbar { display: none; }
.tool {
  flex: none;
  height: 36px;
  min-width: 36px;
  padding: 0 9px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 600;
  transition: background 0.12s, color 0.12s;
}
.tool:hover { background: var(--bg); color: var(--ink); }
.tool[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.tool svg { width: 19px; height: 19px; }
.tool-separator { flex: none; width: 1px; height: 20px; background: var(--line); margin: 0 4px; }

.canvas { display: flex; flex-direction: column; align-items: center; padding: 28px 16px 120px; }

/* The A4 page: 210 x 297 mm at 96 dpi. */
.page {
  position: relative;
  width: 794px;
  min-height: 1123px;
  height: 1123px;
  padding: 76px 80px;
  background: var(--paper);
  border-radius: 4px;
  box-shadow: var(--shadow-page);
}
.page.shake { animation: shake 0.36s cubic-bezier(0.36, 0.07, 0.19, 0.97); }

.editor { outline: none; min-height: 100%; caret-color: var(--accent); }
.editor.is-empty::before {
  content: attr(data-placeholder);
  position: absolute;
  color: var(--muted);
  pointer-events: none;
  white-space: pre-line;
}

/* Hidden twin of the page, always at exact A4 geometry, used to decide whether content still fits. */
.measurer {
  position: absolute;
  top: 0;
  left: -10000px;
  width: calc(794px - 160px);
  visibility: hidden;
  display: flow-root;
  pointer-events: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  translate: -50% 20px;
  opacity: 0;
  background: var(--ink);
  color: var(--paper);
  padding: 11px 18px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-pop);
  transition: opacity 0.2s, translate 0.2s;
  pointer-events: none;
  z-index: 50;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.visible { opacity: 1; translate: -50% 0; }

@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

/* Phones and narrow windows: readable text that reflows; the A4 limit is still enforced by the measurer. */
@media (max-width: 860px) {
  .canvas { padding: 12px 12px calc(96px + env(safe-area-inset-bottom)); }
  .page {
    width: 100%;
    height: auto;
    min-height: calc((100vw - 24px) * 1.414);
    padding: 28px 22px 40px;
    border-radius: 10px;
  }
  .toolbar {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    background: var(--chrome);
    -webkit-backdrop-filter: saturate(1.6) blur(16px);
    backdrop-filter: saturate(1.6) blur(16px);
    border-top: 1px solid var(--line);
  }
  /* iOS zooms into any text field smaller than 16px when it gets focus. The hidden A4 measurer keeps 15px,
     so the one-page limit is unchanged. */
  .editor.sheet-content { font-size: 16px; }
  html.editing { scroll-padding-top: 72px; }
  html.editing .toolbar {
    top: 0;
    bottom: auto;
    z-index: 30;
    padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
    border-top: 0;
    border-bottom: 1px solid var(--line);
    transform: translateY(var(--viewport-top, 0px));
  }
  .toolbar-inner { box-shadow: none; border: 0; background: transparent; padding: 0; width: 100%; max-width: 480px; margin: 0 auto; justify-content: space-between; }
  .tool { height: 40px; min-width: 34px; padding: 0 4px; }
  .tool-separator { margin: 0 2px; }
  .save-status .label { display: none; }
}

@media print {
  @page { size: A4; margin: 0; }
  body { background: white; }
  .topbar, .toolbar, .toast, .menu { display: none !important; }
  .canvas { padding: 0; display: block; }
  .page { width: 210mm; height: 297mm; min-height: 0; padding: 76px 80px; box-shadow: none; border-radius: 0; background: white; }
  .sheet-content, .sheet-content * { color: black !important; }
  .editor.is-empty::before { content: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.auth-legal { margin: 12px 0 0; font-size: 12.5px; color: var(--muted); text-align: center; }
.auth-legal a { color: var(--ink-soft); }

/* ---------- Templates and History panels ---------- */
.template-hint {
  display: block;
  margin: 0 auto 16px;
  padding: 9px 18px;
  border: 1px dashed var(--line-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.template-hint:hover { background: var(--paper); color: var(--accent); border-color: var(--accent); }
.template-hint[hidden] { display: none; }

.panel {
  width: min(920px, calc(100vw - 32px));
  max-height: min(760px, calc(100dvh - 48px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--bg);
  color: var(--ink);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
}
.panel[open] { display: flex; flex-direction: column; }
.panel::backdrop { background: rgb(0 0 0 / 0.32); }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 14px 10px 22px; border-bottom: 1px solid var(--line); }
.panel-header h2 { margin: 0; font-size: 18px; letter-spacing: -0.01em; }
.panel-body { padding: 18px 22px 22px; overflow: auto; }
.panel-intro { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.panel-empty { color: var(--muted); font-size: 14px; padding: 8px 4px; list-style: none; }

/* A small, non-editable page: the real sheet styles, scaled down. */
.mini-sheet {
  position: relative;
  aspect-ratio: 210 / 297;
  overflow: hidden;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.mini-sheet .sheet-content {
  position: absolute;
  top: 0;
  left: 0;
  width: 794px;
  padding: 76px 80px;
  box-sizing: border-box;
  transform-origin: top left;
  transform: scale(var(--mini-scale, 0.25));
  pointer-events: none;
}

.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.template-card {
  display: grid;
  gap: 6px;
  padding: 10px 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.template-card:hover, .template-card:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); outline: none; }
.template-card strong { font-size: 14px; margin-top: 4px; }
.template-card span { font-size: 12.5px; color: var(--muted); line-height: 1.4; }

.history-layout { display: grid; grid-template-columns: minmax(220px, 300px) 1fr; gap: 18px; align-items: start; }
.history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: calc(min(760px, 100dvh - 48px) - 120px); overflow: auto; }
.history-item {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.history-item:hover { background: var(--paper); }
.history-list li.selected .history-item { background: color-mix(in srgb, var(--accent) 12%, var(--paper)); }
.history-item strong { font-size: 14px; }
.history-item span { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-preview { display: grid; gap: 14px; justify-items: center; }
.history-preview .mini-sheet { width: min(100%, 420px); }

@media (max-width: 860px) {
  .panel { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; border: 0; margin: 0; }
  .panel-header { padding-top: calc(10px + env(safe-area-inset-top)); }
  .panel-body { padding-bottom: calc(22px + env(safe-area-inset-bottom)); }
  .template-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .history-layout { grid-template-columns: 1fr; }
  .history-list { max-height: 34dvh; }
}
.history-preview .primary-button { width: auto; padding-left: 28px; padding-right: 28px; }
