:root {
  /* palette: #2D3250 navy, #424769 slate, #7077A1 periwinkle, #F6B17A apricot */
  --desk: #e6e7f0;
  --paper: #ffffff;
  --ink: #2d3250;
  --muted: #5c628c; /* periwinkle, darkened enough to read as text on white */
  --line: #c9cbe0;
  --accent: #2d3250;
  --accent-ink: #ffffff;
  --highlight: #f6b17a;
  --shadow: 0 1px 2px rgb(45 50 80 / 8%), 0 8px 24px rgb(45 50 80 / 10%);
  --lift: drop-shadow(0 1px 1px rgb(45 50 80 / 10%)) drop-shadow(0 12px 20px rgb(45 50 80 / 12%)); /* follows the folded corner, unlike box-shadow */
  --paper-1: #f3f4f9; /* sheets under the drop target */
  --paper-2: #ebecf4;
  /* Lighter than the desk, darker than the paper. Samsung Internet's dark mode keeps that order, so the fold
     stays visible; a fold darker than the desk turned into a black hole there. */
  --fold: color-mix(in srgb, var(--desk) 55%, var(--paper));
  --panel: color-mix(in srgb, var(--paper) 45%, var(--desk));
  --serif: Charter, "Bitstream Charter", "Iowan Old Style", "Sitka Text", Cambria, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bar-h: 56px;
  --vv-top: 0px; /* set by app.js: how far the iPhone keyboard has scrolled the screen */
}
@media (prefers-color-scheme: dark) {
  :root {
    --desk: #24283f;
    --paper: #2d3250;
    --ink: #ececf4;
    --muted: #a5aacb;
    --line: #424769;
    --accent: #f6b17a; /* apricot buttons stand out on navy */
    --accent-ink: #2d3250;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 30%);
    --lift: drop-shadow(0 1px 1px rgb(0 0 0 / 40%)) drop-shadow(0 12px 20px rgb(0 0 0 / 35%));
    --paper-1: #353a5c;
    --paper-2: #3c4166;
    --fold: color-mix(in srgb, var(--line) 70%, var(--paper));
  }
}

* { box-sizing: border-box; }
html { background: var(--desk); }
body { margin: 0; min-height: 100vh; min-height: 100dvh; background: var(--desk); color: var(--ink); font: 15px/1.5 var(--sans); }
::selection { background: color-mix(in srgb, var(--highlight) 60%, transparent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Top bar */
.bar {
  position: sticky; top: var(--vv-top); z-index: 100; height: var(--bar-h);
  display: flex; align-items: center; gap: 16px; padding: 0 16px;
  background: var(--desk); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font: 600 17px var(--serif); }
.doc { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.name {
  min-width: 0; width: 100%; max-width: 360px; padding: 5px 8px; border: 1px solid transparent; border-radius: 6px;
  background: transparent; color: var(--ink); font: 500 15px var(--sans); text-overflow: ellipsis;
}
.name:hover { border-color: var(--line); }
.name:focus { border-color: var(--accent); background: var(--paper); outline: none; }
.status {
  flex: none; display: inline-flex; align-items: center; gap: 7px; padding: 4px 11px 4px 9px;
  border-radius: 999px; background: var(--paper); border: 1px solid var(--line);
  color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums;
}
.status:empty { display: none; }
/* saved: a small check; unsaved: a yellow dot */
.status::before {
  content: ""; flex: none; width: 4px; height: 8px; margin: 0 2px 2px 3px;
  border: solid var(--accent); border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.status.dirty { color: var(--ink); }
.status.dirty::before, .status.pending::before { width: 7px; height: 7px; margin: 0; border: 0; border-radius: 50%; background: var(--highlight); transform: none; }
/* backed up but not downloaded: warm tint so it reads as "to do", not "done" */
.status.pending {
  color: var(--ink); font-weight: 500;
  background: color-mix(in srgb, var(--highlight) 16%, var(--paper)); border-color: color-mix(in srgb, var(--highlight) 60%, var(--line));
}
.status small { padding-left: 8px; border-left: 1px solid color-mix(in srgb, var(--highlight) 60%, var(--line)); color: var(--muted); font-size: 12px; font-weight: 400; }
.actions { display: flex; gap: 8px; margin-left: auto; }

button { font: 500 14px var(--sans); color: var(--ink); cursor: pointer; }
.actions button {
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--paper);
  transition: background-color .15s, border-color .15s;
}
.actions button:hover { border-color: var(--muted); }
.actions .ghost { background: transparent; border-color: transparent; }
.actions .ghost:hover { background: var(--paper); border-color: var(--line); }
.actions button { display: inline-flex; align-items: center; gap: 6px; }
.actions #delete:hover { color: #b42318; }
.actions .primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.actions .primary:hover { filter: brightness(1.1); border-color: var(--accent); }

/* Welcome / empty state */
/* The start screen fits one screen, so there's nothing to scroll: the sheet's height scales with the viewport.
   min-height (not height) means a screen too small to fit everything scrolls instead of clipping content. */
.welcome {
  display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 680px); justify-content: center; align-content: center; gap: clamp(32px, 5vw, 72px);
  min-height: calc(100vh - var(--bar-h)); min-height: calc(100dvh - var(--bar-h));
  padding: clamp(16px, 4vh, 56px) 16px clamp(8px, 3vh, 32px);
}
/* Full-width row under the start screen; min-height holds the space so the page doesn't jump when the ad loads */
.ad { grid-column: 1 / -1; order: 2; min-height: 100px; }
.privacy a { color: inherit; font-size: 14px; }
.start { display: flex; flex-direction: column; min-width: 0; align-self: stretch; }

/* Left panel: a quick tour of the product */
.tour { display: flex; flex-direction: column; padding: 24px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.tour h2 { margin: 0 0 20px; font: 600 20px var(--serif); }
.steps { margin: 0 0 24px; padding: 0; list-style: none; counter-reset: step; }
.steps li { position: relative; padding-left: 40px; color: var(--muted); font-size: 14px; line-height: 1.55; counter-increment: step; }
.steps li + li { margin-top: 18px; }
/* a thin rail joins the numbers, so the steps read as one sequence */
.steps li:not(:last-child)::after { content: ""; position: absolute; left: 13px; top: 32px; bottom: -14px; width: 1px; background: var(--line); }
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: 0; width: 27px; height: 27px; display: grid; place-items: center;
  border-radius: 50%; background: var(--accent); color: var(--accent-ink); font: 600 13px var(--sans);
}
.steps strong { display: block; margin-bottom: 2px; padding-top: 3px; color: var(--ink); font-size: 15px; }
.steps code, .peek pre { font-size: 12.5px; }
.steps code, kbd { padding: 1px 5px; border-radius: 4px; background: var(--paper); color: var(--ink); }
kbd { font: 500 12px var(--sans); border: 1px solid var(--line); border-bottom-width: 2px; }
.peek { display: grid; gap: 1px; margin: auto 0 16px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--line); } /* auto margin soaks up spare height, so the card ends level with the privacy list */
.peek div { padding: 10px 14px; background: var(--paper); }
.peek small { display: block; margin-bottom: 2px; color: var(--muted); font-size: 12px; }
.peek p { margin: 0; font: 16px var(--serif); }
.peek u { color: var(--accent); text-underline-offset: 2px; }
.peek pre { margin: 0; white-space: pre-wrap; color: var(--ink); }
.try {
  width: 100%; padding: 10px 14px; border-radius: 8px; border: 1px solid var(--accent); background: transparent; color: var(--accent);
  transition: background-color .15s, color .15s;
}
.try:hover { background: var(--accent); color: var(--accent-ink); }

.welcome h1 { margin: 0 0 clamp(8px, 1.5vh, 16px); font: 700 clamp(28px, min(6vw, 6vh), 52px)/1.08 var(--serif); letter-spacing: -0.02em; text-wrap: balance; }
.lede { margin: 0 0 clamp(20px, 4vh, 40px); max-width: 34em; color: var(--muted); font-size: 18px; line-height: 1.55; text-wrap: pretty; }
.lede code { font-size: .9em; padding: 1px 5px; border-radius: 4px; background: var(--paper); color: var(--ink); }
.restore {
  /* floats over the page so the drop sheet keeps its size */
  position: fixed; z-index: 20; left: 50%; bottom: 24px; transform: translateX(-50%); width: min(640px, calc(100% - 32px));
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 14px 16px;
  border-radius: 8px; background: var(--paper); border-left: 4px solid var(--highlight); box-shadow: var(--shadow);
}
.restore p { flex: 1 1 260px; margin: 0; }
.restore-actions { display: flex; gap: 8px; }
.restore button { padding: 7px 14px; border-radius: 8px; border: 1px solid transparent; background: transparent; }
.restore .ghost:hover { border-color: var(--line); }
.restore .primary { background: var(--accent); color: var(--accent-ink); }
.restore .primary:hover { filter: brightness(1.1); }

/* The drop target is a small pile of paper; the sheets underneath fan out when a file is on its way. */
.pile {
  position: relative; display: flex; flex: none; height: clamp(150px, 34vh, 360px); margin: 0 6px clamp(20px, 4vh, 40px);
  filter: var(--lift);
}
.pile::before, .pile::after {
  content: ""; position: absolute; inset: 0; border-radius: 4px; transition: transform .3s cubic-bezier(.2, .8, .2, 1);
}
.pile::before { background: var(--paper-2); transform: rotate(-1.8deg) translate(-4px, 6px); }
.pile::after { background: var(--paper-1); transform: rotate(1.2deg) translate(4px, 3px); }
.pile:hover::before, body.dragging .pile::before { transform: rotate(-3.5deg) translate(-12px, 10px); }
.pile:hover::after, body.dragging .pile::after { transform: rotate(2.4deg) translate(10px, 4px); }
.sheet {
  position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  flex: 1; width: 100%; padding: 24px; border: 0; border-radius: 4px;
  background: var(--paper); text-align: center;
  clip-path: polygon(0 0, calc(100% - 36px) 0, 100% 36px, 100% 100%, 0 100%);
  transition: transform .3s cubic-bezier(.2, .8, .2, 1);
}
/* folded corner */
.sheet::after {
  content: ""; position: absolute; top: 0; right: 0; width: 36px; height: 36px;
  background: linear-gradient(225deg, transparent 50%, var(--fold) 50%);
}
.sheet::before {
  content: ""; position: absolute; inset: 16px; border: 2px dashed var(--line); border-radius: 6px; transition: border-color .2s, background-color .2s;
}
.sheet:hover, body.dragging .sheet { transform: translateY(-3px); }
.sheet:hover::before, .sheet:focus-visible::before, body.dragging .sheet::before {
  border-color: var(--accent); background: color-mix(in srgb, var(--accent) 4%, transparent);
}
.sheet > span, .sheet > svg { position: relative; } /* above the dashed fill */
.sheet-icon { margin-bottom: 8px; color: var(--accent); }
.sheet-main { font: 600 22px var(--serif); }
.sheet-btn {
  margin: 12px 0 8px; padding: 9px 20px; border-radius: 8px; background: var(--accent); color: var(--accent-ink);
  font: 500 15px var(--sans); transition: filter .15s;
}
.sheet:hover .sheet-btn { filter: brightness(1.1); }
.sheet-sub { color: var(--muted); font-size: 13px; }

/* pinned to the bottom so it lines up with the bottom of the tour card */
.privacy { flex: none; margin: auto 0 0; padding-top: clamp(12px, 2.5vh, 24px); border-top: 1px solid var(--line); }
.privacy h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; font: 600 17px var(--serif); }
.privacy h2 svg { flex: none; color: var(--accent); }
.privacy ul { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 0; padding: 0; list-style: none; }
.privacy li { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.privacy li::before {
  content: ""; flex: none; width: 5px; height: 9px; margin: 0 2px 3px 4px;
  border: solid var(--accent); border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.privacy strong { font-weight: 500; }
.privacy li:has(a)::before { display: none; }
/* Stacked: the main action first, the tour below it. */
@media (max-width: 900px) {
  .welcome { grid-template-columns: minmax(0, 680px); }
  .tour { order: 1; }
}
@media (max-width: 640px) {
  .privacy ul { flex-direction: column; gap: 6px; }
  .lede { font-size: 16px; margin-bottom: clamp(16px, 2.5vh, 32px); }
  .welcome { padding-top: clamp(12px, 3vh, 40px); padding-bottom: clamp(16px, 3vh, 32px); }
  .tour { padding: 20px 16px; }
  .pile { height: 200px; }
  .sheet-icon { display: none; }
  /* in the page flow, above the drop target: floating, it covered the buttons below it */
  .restore { position: static; transform: none; width: auto; margin-bottom: 16px; gap: 10px; padding: 10px 12px; font-size: 14px; }
  .restore button { padding: 6px 12px; }
}

/* Paper + editor */
/* The "Start writing…" hint inside an empty code block swallows typing, so hide it there. */
.toastui-editor-ww-code-block .placeholder { display: none; }
.paper { max-width: 860px; margin: 32px auto 96px; background: var(--paper); box-shadow: var(--shadow); border-radius: 4px; }
.paper .toastui-editor-defaultUI { border: 0; border-radius: 4px; }
.paper .toastui-editor-toolbar { position: sticky; top: calc(var(--vv-top) + var(--bar-h)); z-index: 20; background: var(--paper); border-radius: 4px 4px 0 0; }
.paper .toastui-editor-main { position: relative; z-index: 0; } /* keep document text below the sticky toolbar */
.paper .toastui-editor-contents th p { color: inherit; } /* header cells: keep Toast's white text on its dark fill */
.paper .toastui-editor-toolbar .history { background: none; color: var(--ink); }
.paper .toastui-editor-toolbar .history::before {
  content: ''; display: block; width: 18px; height: 18px; margin: auto; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 14 4 9l5-5'/%3E%3Cpath d='M4 9h10.5a5.5 5.5 0 0 1 0 11H11'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 14 4 9l5-5'/%3E%3Cpath d='M4 9h10.5a5.5 5.5 0 0 1 0 11H11'/%3E%3C/svg%3E") center / contain no-repeat;
}
.paper .toastui-editor-toolbar .redo::before { transform: scaleX(-1); }
.paper .toastui-editor-defaultUI-toolbar { border-radius: 4px 4px 0 0; background: var(--paper); border-bottom: 1px solid var(--line); }
/* app.js tells Toast every button fits, so on desktop the row must really fit (or wrap) or the last ones spill out. */
.paper .toastui-editor-defaultUI-toolbar { flex-wrap: wrap; height: auto; padding: 0 12px; }
.paper .toastui-editor-toolbar-divider { margin: 14px 6px; }
.paper .toastui-editor-defaultUI,
.paper .toastui-editor-main,
.paper .toastui-editor-main-container,
.paper .toastui-editor-ww-container,
.paper .toastui-editor-md-container { overflow: visible !important; }
.paper .toastui-editor-ww-container .toastui-editor-contents { padding: 48px 72px 72px; }
.paper .ProseMirror { min-height: 70vh; } /* Toast's minHeight is ignored with height: auto */
.paper .toastui-editor-contents { font: 17px/1.65 var(--serif); color: var(--ink); }
.paper .toastui-editor-contents p,
.paper .toastui-editor-contents li { font-size: 17px; line-height: 1.65; color: var(--ink); }
/* Toast pins the dot 6px down (sized for 13px text); center it on our first line instead */
.paper .toastui-editor-contents ul > li:not(.task-list-item)::before { margin-top: calc(1.65em / 2 - 2.5px); }
.paper .toastui-editor-contents h1,
.paper .toastui-editor-contents h2,
.paper .toastui-editor-contents h3,
.paper .toastui-editor-contents h4 { font-family: var(--serif); color: var(--ink); border-color: var(--line); }
.paper .toastui-editor-contents code,
.paper .toastui-editor-contents pre { font-size: 14px; }
.paper .toastui-editor-contents blockquote { border-left-color: var(--highlight); color: var(--muted); }
.paper .toastui-editor-contents blockquote p { color: var(--muted); }
.paper .toastui-editor-dark.toastui-editor-defaultUI,
.paper .toastui-editor-dark .toastui-editor-ww-container { background: var(--paper); }
/* Toast's own greys and blues, moved onto the palette */
.paper .toastui-editor-toolbar-icons, .paper .toastui-editor-toolbar .history { border-color: transparent; }
.paper .toastui-editor-toolbar-icons:not(:disabled):hover,
.paper .toastui-editor-toolbar .history:not(:disabled):hover { border-color: var(--line); background-color: var(--paper-1); }
/* Toast marks the active button with a bright blue icon; mute it toward the palette's slate */
.paper .toastui-editor-toolbar-icons.active { filter: saturate(.35) brightness(.75); background-color: var(--paper-2); }
.paper .toastui-editor-dark .toastui-editor-toolbar-icons.active { filter: saturate(.35) brightness(1.25); }
.paper .toastui-editor-contents th, .paper .toastui-editor-dark .toastui-editor-contents th { background: #424769; border-color: #424769; }
.paper .toastui-editor-contents td { border-color: var(--line); }

/* Drag overlay */
.dropzone {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; pointer-events: none;
  background: color-mix(in srgb, var(--accent) 14%, transparent); border: 3px dashed var(--accent);
  opacity: 0; transition: opacity .15s;
}
.dropzone p { padding: 14px 24px; border-radius: 8px; background: var(--paper); box-shadow: var(--shadow); font: 600 20px var(--serif); }
body.dragging .dropzone { opacity: 1; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 60; max-width: calc(100% - 32px);
  padding: 10px 16px; border-radius: 8px; background: var(--ink); color: var(--paper); font-size: 14px;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Confirm dialog (replaces the browser's own confirm box) */
.ask {
  width: min(440px, calc(100% - 32px)); padding: 24px; border: 0; border-radius: 12px;
  background: var(--paper); color: var(--ink); box-shadow: var(--shadow);
}
.ask::backdrop { background: rgb(36 40 63 / 50%); }
.ask[open] { animation: ask-in .15s ease-out; }
@keyframes ask-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@media (prefers-reduced-motion: reduce) { .ask[open] { animation: none; } }
.ask p { margin: 0 0 20px; font-size: 16px; line-height: 1.5; }
.ask-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.ask button { padding: 8px 16px; border-radius: 8px; border: 1px solid var(--line); background: transparent; }
.ask .ghost:hover { background: var(--desk); }
.ask .primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.ask .primary:hover { filter: brightness(1.1); }

@media (max-width: 640px) {
  .bar { gap: 8px; padding: 0 12px; }
  .brand span { display: none; }
  .status { display: none; }
  .actions button { padding: 7px 10px; }
  #delete span { display: none; } /* icon only on phones; aria-label keeps it named */
  .paper { margin: 0 0 64px; border-radius: 0; box-shadow: none; }
  .paper .toastui-editor-ww-container .toastui-editor-contents { padding: 24px 16px 48px; }
  /* All buttons stay in one row that swipes sideways (app.js stops Toast's "more" menu). Only the row
     scrolls: iPhone Safari doesn't draw the fixed popups if they sit inside a scrolling box.
     Adding overscroll-behavior or scrollbar-width here crashed iPhone Safari (iOS 26.3 simulator). */
  .paper .toastui-editor-defaultUI-toolbar { overflow-x: auto; flex-wrap: nowrap; height: 45px; }
  .paper .toastui-editor-toolbar-group { flex-shrink: 0; }
  /* Popups (link, table, heading) open under their button, which can be off-screen; pin them under the toolbar. */
  .paper .toastui-editor-popup {
    position: fixed; top: calc(var(--vv-top) + var(--bar-h) + 52px) !important; left: 8px !important; right: 8px; width: auto !important; max-width: none; margin: 0;
  }
}
/* Hover labels can't work by touch and stay stuck on screen after a tap. */
@media (hover: none) {
  .toastui-editor-tooltip { display: none !important; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
