/* DocLock: a Typeform-like look. Light and dark themes are the variables.
   Colours: blue accent for controls and links; messages use only neutral
   (in progress), red (error), yellow (warning) and green (success). */
:root {
  --bg: #f5f3ef; --fg: #1d1d1f; --accent: #0445af; --on-accent: #fff;
  --error: #af0404; --error-bg: #f7e2e2; --warn: #8a5a00; --warn-bg: #f8edd5; --ok: #1d6b32; --ok-bg: #e0f1e4;
  --muted: color-mix(in srgb, var(--fg) 68%, var(--bg)); /* 4.5:1+ on --bg */
  --soft: color-mix(in srgb, var(--accent) 10%, var(--bg));
  --line: color-mix(in srgb, var(--accent) 30%, var(--bg));
  --font: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
  --ease: cubic-bezier(0.25, 0.9, 0.3, 1);
  color-scheme: light dark;
}
/* Dark: The device's setting (Auto), unless Light or Dark was chosen (data-theme, theme.js) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15161a; --fg: #f1f1f3; --accent: #8db3ff; --on-accent: #0b1430;
    --error: #ff9e9e; --error-bg: #3a1c1c; --warn: #f3cf7a; --warn-bg: #3a2f14; --ok: #86d89c; --ok-bg: #16301e;
  }
}
:root[data-theme="dark"] {
    --bg: #15161a; --fg: #f1f1f3; --accent: #8db3ff; --on-accent: #0b1430;
    --error: #ff9e9e; --error-bg: #3a1c1c; --warn: #f3cf7a; --warn-bg: #3a2f14; --ok: #86d89c; --ok-bg: #16301e;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
/* scrollbars: Just a slim rounded bar, no rail */
* { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--fg) 28%, transparent) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; background: transparent; }
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--fg) 28%, transparent); border: 3px solid transparent; border-radius: 999px; background-clip: padding-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 20px/1.4 var(--font); -webkit-font-smoothing: antialiased; display: flex; flex-direction: column; overflow: hidden; }
main { flex: 1; position: relative; min-height: 0; }
[hidden] { display: none !important; }
a { color: var(--accent); }
p { margin: 0; }

#progress { position: fixed; inset: 0 0 auto; height: 4px; background: var(--soft); z-index: 3; }
#progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.5s var(--ease); }

/* status snackbar, top centre */
.snackbar {
  position: fixed; top: 16px; left: 0; right: 0; margin: 0 auto; width: fit-content; z-index: 4; display: flex; align-items: center; gap: 8px;
  max-width: min(92vw, 40rem); font-size: 15px; line-height: 1.35; padding: 8px 8px 8px 14px; border-radius: 6px;
  background: color-mix(in srgb, var(--fg) 8%, var(--bg)); box-shadow: 0 4px 18px rgb(0 0 0 / 14%);
  opacity: 0; transform: translateY(-12px); pointer-events: none; transition: opacity 0.2s, transform 0.25s var(--ease);
}
.snackbar.show { opacity: 1; transform: none; pointer-events: auto; }
/* in the editor (and on phones, below) it sits at the bottom, clear of the editor's bar */
body:has(#step-editor:not([hidden])) .snackbar { top: auto; bottom: calc(12px + env(safe-area-inset-bottom)); }
.snackbar.err { background: var(--error-bg); color: var(--error); }
.snackbar.err #status-text::before { content: "⚠ "; }
#status-text .icon { width: 1.1em; height: 1.1em; vertical-align: -0.2em; margin-right: 0.35em; }
.snackbar.warn { background: var(--warn-bg); color: var(--warn); }
.snackbar.ok { background: var(--ok-bg); color: var(--ok); }
.snackbar.busy #status-text::before { /* spinner */
  content: ""; display: inline-block; width: 0.85em; height: 0.85em; margin-right: 8px; vertical-align: -0.1em;
  border: 2px solid; border-right-color: transparent; border-radius: 50%; animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#status-close { background: none; box-shadow: none; color: inherit; opacity: 0.6; font: 400 18px/1 var(--font); padding: 2px 6px; }
#status-close:hover { opacity: 1; }
.frozen { cursor: progress; }
.frozen a { pointer-events: none; opacity: 0.5; }

/* one question per screen */
.step {
  position: absolute; inset: 0; display: flex; flex-direction: column; overflow-y: auto;
  padding: 48px max(24px, calc(50% - 356px)) 12vh; animation: step-in 0.35s var(--ease) both; /* full width, so a scrollbar sits at the window's edge; content 712px max */
}
.step.leaving, #step-editor.leaving { animation: step-out 0.18s ease-in both; }
/* centred when it fits, scrollable from the top when it does not */
.step::before, .step::after { content: ""; flex: 1 0 0; }
/* forward: in from the right, out to the left; back (body.back): the other way */
@keyframes step-in { from { opacity: 0; transform: translateX(64px); } }
@keyframes step-out { to { opacity: 0; transform: translateX(-64px); } }
@keyframes step-in-back { from { opacity: 0; transform: translateX(-64px); } }
@keyframes step-out-back { to { opacity: 0; transform: translateX(64px); } }
body.back .step, body.back #step-editor { animation-name: step-in-back; }
body.back .step.leaving, body.back #step-editor.leaving { animation-name: step-out-back; }
.q { display: block; font-size: 24px; line-height: 1.35; margin-bottom: 8px; }
.desc { color: var(--muted); font-size: 18px; line-height: 1.6; margin-bottom: 28px; }
.desc strong:not(.promise) { color: var(--fg); font-weight: 600; }
/* setup guide */
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }
.kicker { font-size: 14px; color: var(--muted); margin: 0 0 8px; }
.copy { margin: 0 0 16px; }
.copy-label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.copy-row { display: flex; align-items: center; gap: 8px; }
.copy code { flex: 1; min-width: 0; overflow-wrap: anywhere; font: 15px/1.4 ui-monospace, Menlo, Consolas, monospace; background: var(--soft); border-radius: 4px; padding: 8px 10px; }

input.answer {
  width: 100%; font: 30px/1.3 var(--font); color: var(--accent); background: none; outline: none;
  border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 0 0 8px; transition: border-color 0.2s, box-shadow 0.2s;
}
input.answer::placeholder { color: var(--line); }
input.answer:focus { border-bottom-color: var(--accent); box-shadow: 0 1px 0 var(--accent); }
.field { position: relative; }
.field + .field { margin-top: 20px; }
.field input.answer { padding-right: 48px; }

button {
  font: 700 20px/1 var(--font); color: var(--on-accent); background: var(--accent); border: 0; border-radius: 4px;
  padding: 10px 16px; cursor: pointer; box-shadow: 0 3px 12px -2px rgb(0 0 0 / 20%); transition: filter 0.15s, transform 0.05s;
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: default; filter: none; }
#save.pop { animation: pop 0.3s var(--ease); }
@keyframes pop { from { transform: scale(0.85); opacity: 0.3; } }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
/* quieter buttons: ghost (outlined), and the plain ones without a box */
button.ghost { background: none; color: var(--accent); box-shadow: none; font-weight: 500; font-size: 16px; padding: 8px 12px; border: 1px solid var(--line); }
button.link, button.back, button.reveal, #recents button { background: none; box-shadow: none; filter: none; }
button.ghost:hover, button.back:hover, button.reveal:hover { background: var(--soft); filter: none; }
button.link { color: var(--muted); font-weight: 400; font-size: 15px; padding: 4px 0; text-decoration: underline; }
button.back { align-self: flex-start; color: var(--accent); font: 400 28px/1 var(--font); padding: 6px; margin: 0 0 20px -8px; }
button.reveal { position: absolute; right: 0; bottom: 10px; color: var(--accent); padding: 6px; font-size: 24px; line-height: 0; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 24px; }
.actions button { white-space: nowrap; }

/* icons (Material Symbols, in index.html) */
.sprite { position: absolute; width: 0; height: 0; }
.icon { width: 1.2em; height: 1.2em; flex: none; fill: currentColor; }
button.reveal .icon, button.back .icon { width: 1em; height: 1em; }
button:has(> .icon) { display: inline-flex; align-items: center; gap: 0.4em; }
button.icon-only { padding-left: 10px; padding-right: 10px; }
/* a bare icon, like the theme button: Reload */
/* theme: The same top-right corner on every screen (the editor's top bar leaves it free) */
/* bare icon buttons (Reload, theme): One fixed 40×40 circle, whatever the context */
.tools button.plain, button.plain, #theme { box-sizing: border-box; flex: none; width: 40px; height: 40px; min-width: 40px; padding: 0; margin: 0; border: 0; justify-content: center; background: none; box-shadow: none; color: var(--muted); border-radius: 50%; filter: none; }
button.plain:hover, #theme:hover { background: var(--soft); color: var(--accent); }
#theme { position: fixed; top: 10px; right: 10px; z-index: 3; }

/* welcome */
#step-signin { text-align: center; align-items: center; padding-top: 24px; padding-bottom: 16px; } /* the footer is the bottom margin */
#step-signin h1 { font-size: 44px; font-weight: 400; letter-spacing: -0.01em; margin: 0 0 12px; }
#step-signin .desc { max-width: 28em; }
#setup-note { color: var(--fg); } /* the one thing to read on an unconfigured copy */
.promise { display: inline-block; margin-bottom: 6px; color: var(--accent); font-weight: 600; }
#step-signin .actions { justify-content: center; }
.lock-mark { width: auto; height: 78px; margin-bottom: 8px; }
.who { display: flex; flex-direction: column; align-items: center; gap: 4px; margin: 4px 0 20px; }
#who-pic { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; background: var(--soft); box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--line); margin-bottom: 8px; }
#who-name { font-size: 22px; }
#who-email { font-size: 12px; color: var(--muted); }
#account-links { margin-top: 16px; }
/* small print at the bottom of the welcome screen */
#step-signin .specs { order: 1; max-width: 40em; margin-top: 24px; font-size: 12px; line-height: 1.5; color: var(--muted); }

/* recent docs: chips with a remove × */
#recents { list-style: none; padding: 0; margin: 32px 0 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
#recents .label { flex-basis: 100%; font-size: 15px; color: var(--muted); margin-bottom: 2px; }
#recents .item { display: inline-flex; align-items: center; max-width: 100%; background: var(--soft); border-radius: 999px; transition: background 0.15s; }
#recents .item:hover { background: color-mix(in srgb, var(--accent) 18%, var(--bg)); }
#recents button { color: var(--accent); font-weight: 400; font-size: 16px; }
#recents .choice { min-width: 0; padding: 7px 4px 7px 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 22rem; }
#recents .forget { line-height: 1; padding: 7px 12px 7px 6px; color: var(--muted); }
#recents .forget:hover { color: var(--fg); }

/* editor: a full-screen writing surface */
#step-editor { position: absolute; inset: 0; display: flex; flex-direction: column; overflow: hidden; padding-top: 10px; animation: step-in 0.35s var(--ease) both; --side: 24px; }
/* the text and what belongs to it: A readable column; the top bar: Full width, clear of the theme corner */
/* Pinned: The top bar (full width, clear of the theme corner) and the formatting bar.
   Only the text scrolls: The text box spans the width, so its scrollbar is at the
   window's edge, and its padding keeps the text in a centred 760px column. */
#step-editor > * { width: calc(100% - 2 * var(--side)); max-width: 760px; margin: 0 auto 12px; flex: none; }
#step-editor > .bar { max-width: none; width: auto; min-height: 40px; margin: 0 calc(var(--side) + 36px) 12px var(--side); }
#step-editor > #editor, #step-editor > #preview { flex: 1; width: 100%; max-width: none; min-height: 0; margin: 0; overflow-y: auto;
  padding: 16px max(var(--side), calc((100% - 760px) / 2)) 24px; }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.bar > * { flex-shrink: 0; }
.bar button.back { margin: 0 -4px 0 -6px; font-size: 24px; }
#doc-title { flex: 1 1 8em; max-width: max-content; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 22px; color: var(--fg); text-decoration: none; }
#doc-title:hover { text-decoration: underline; }
#doc-state { font-size: 14px; color: var(--muted); }
.tools { margin-left: auto; display: flex; gap: 8px; }
.tools button { font-size: 16px; padding: 8px 14px; }
.notice { font-size: 15px; padding: 8px 12px; border-radius: 4px; background: var(--warn-bg); color: var(--warn); display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.notice button { font-size: 14px; padding: 6px 10px; }
textarea { display: block; width: 100%; font: 17px/1.6 var(--font); color: var(--fg); background: none; border: 0; border-top: 1px solid var(--line); padding: 16px 0; outline: none; resize: none; }
/* formatting bar and Preview */
/* a band between the header and the text: Full width, a thin line on top (the text's own line below) */
/* a rounded pill the width of the text column, a little apart from the top bar */
/* the pill sticks out by --bleed on each side, so the first button's letter lines up with the text */
#step-editor > .mdbar { --bleed: 20px; align-self: center; width: calc(100% - 2 * var(--side) + 2 * var(--bleed)); max-width: calc(760px + 2 * var(--bleed)); margin-top: 6px; margin-bottom: 4px; padding: 4px 6px 4px 8px; background: var(--soft); border-radius: 999px; }
.mdbar { display: flex; align-items: center; gap: 6px; }
#md-actions { flex: 1 1 auto; min-width: 0; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; } /* one line; scrolls sideways on narrow screens */
#md-actions::-webkit-scrollbar { display: none; }
.mdbar button { background: none; box-shadow: none; color: var(--fg); font: 500 15px/1 var(--font); min-width: 34px; height: 32px; padding: 0 8px; border-radius: 4px; filter: none; }
.mdbar button:hover { background: color-mix(in srgb, var(--accent) 20%, var(--bg)); }
.mdbar button[data-md="quote"] { font-size: 22px; padding-top: 8px; }
#md-actions button { flex: none; }
/* Preview: An on/off switch */
.mdbar .switch { flex: none; margin-left: auto; display: inline-flex; align-items: center; gap: 8px; color: var(--muted); padding: 0 4px 0 8px; }
.switch .track { position: relative; width: 34px; height: 20px; border-radius: 10px; background: var(--line); transition: background 0.2s; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--bg); box-shadow: 0 1px 2px rgb(0 0 0 / 30%); transition: transform 0.2s var(--ease); }
.switch[aria-checked="true"] { color: var(--accent); }
.switch[aria-checked="true"] .track { background: var(--accent); }
.switch[aria-checked="true"] .track::after { transform: translateX(14px); }
#step-editor > #preview { overflow-wrap: anywhere; font: 17px/1.6 var(--font); }
#step-editor > #editor { border-top: 0; }
.md > :first-child { margin-top: 8px; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { line-height: 1.25; margin: 1em 0 0.4em; font-weight: 600; }
.md h1 { font-size: 1.7em; } .md h2 { font-size: 1.4em; } .md h3 { font-size: 1.2em; } .md h4, .md h5, .md h6 { font-size: 1em; }
.md p, .md ul, .md ol, .md blockquote, .md pre { margin: 0 0 0.8em; }
.md ul, .md ol { padding-left: 1.5em; }
.md li.task { list-style: none; margin-left: -1.3em; }
.md li.task input { margin: 0 0.35em 0 0; vertical-align: -0.1em; }
.md blockquote { margin-left: 0; padding-left: 14px; border-left: 3px solid var(--line); color: var(--muted); }
.md code { font: 0.9em ui-monospace, Menlo, Consolas, monospace; background: var(--soft); border-radius: 3px; padding: 0.1em 0.3em; }
.md pre { background: var(--soft); border-radius: 4px; padding: 10px 12px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
.md a { color: var(--accent); }
#theirs { height: 28vh; border: 1px solid var(--line); border-radius: 4px; padding: 12px; font: 15px/1.5 ui-monospace, Menlo, Consolas, monospace; }

/* phones, also held sideways */
@media (max-width: 600px), (max-height: 500px) {
  body { font-size: 18px; }
  .step { padding: 32px 20px 6vh; }
  .q { font-size: 20px; }
  .desc { font-size: 16px; margin-bottom: 20px; }
  input.answer { font-size: 24px; }
  button.back { margin-bottom: 12px; }
  #step-signin h1 { font-size: 34px; }
  #step-editor { --side: 20px; }
  #step-editor > * { margin-bottom: 8px; }
  #step-editor > .mdbar { --bleed: 14px; padding-left: 6px; }
  .mdbar button { min-width: 28px; padding: 0 6px; }
  #step-editor > .bar { margin-right: calc(var(--side) + 40px); }
  .bar { gap: 6px 10px; }
  #doc-title { font-size: 18px; }
  #doc-state { font-size: 12px; }
  /* two rows: ← title (the theme button beside it); then the count, and the buttons on the right */
  #step-editor > .bar::after { content: ""; order: 1; flex-basis: 100%; }
  #step-editor > .bar > #doc-state, #step-editor > .bar > .tools { order: 2; }
  #step-editor > .bar > .tools { margin-right: -40px; } /* below the theme button: The full width */
  .tools { gap: 6px; }
  .tools button { font-size: 14px; padding: 7px 10px; }
  textarea { font-size: 16px; } /* 16px+ keeps iOS from zooming in */
  /* the snackbar moves to the bottom, clear of the editor's buttons */
  .snackbar { top: auto; bottom: calc(12px + env(safe-area-inset-bottom)); transform: translateY(12px); }
}
/* short screens: a more compact welcome, so it fits without scrolling */
@media (max-height: 700px) {
  .lock-mark { height: 60px; margin-bottom: 4px; }
  #step-signin h1 { margin-bottom: 8px; }
  #who-pic { width: 56px; height: 56px; margin-bottom: 4px; }
  .who { margin-bottom: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .step, .step.leaving, #step-editor { animation-duration: 1ms; }
  .snackbar { transition: opacity 0.2s; transform: none; }
  .snackbar.busy #status-text::before { animation-duration: 2s; }
}
