/* Largato web app.
   E-Ink style: one ink, no color, no smooth animation. Weight, outline and pattern carry the
   hierarchy. One layout, the mobile one (ADR 0002): it fills a phone screen, and on a desktop it sits
   inside a phone-sized frame with a status bar. */

/* ---- Tokens: E-Ink Day (light) ----------------------------------------- */
.canvas {
  --bg-canvas: #e9e9e6;
  --bg-surface: #dfdfdb;
  --bg-surface-elevated: #f3f3f0;
  --text-primary: #121212;
  --text-secondary: #3a3a38;
  --text-tertiary: #5f5f5b;
  --accent-primary: #121212;
  --accent-highlight: rgba(18, 18, 18, 0.1);
  --border-hairline: #a6a6a1;
  --on-accent: #f3f3f0;

  --header-glass: #e9e9e6;
  --backdrop: rgba(18, 18, 18, 0.45);
  --outer-canvas: #d6d6d2;
  --device-shadow: 0 24px 60px -12px rgba(18, 18, 18, 0.18);
  --cover-bg: #f3f3f0;
  --cover-accent: #121212;
  --cover-ink: #121212;

  /* The page scanner is a camera view: always dark, whatever the theme */
  --camera-bg: #0d0d0d;
  --camera-panel: #151515;
  --camera-ink: #eeeeea;
  --camera-soft: #bebeb9;
  --camera-muted: #8c8c87;
  --camera-rule: rgba(255, 255, 255, 0.16);
  --camera-chip: rgba(255, 255, 255, 0.1);
  --camera-chip-border: rgba(255, 255, 255, 0.3);
  --camera-glow: radial-gradient(circle at center, rgba(255, 255, 255, 0.03) 0%, rgba(13, 13, 13, 0.85) 75%);
  --camera-glow-lit: radial-gradient(circle at center, rgba(255, 255, 255, 0.14) 0%, rgba(13, 13, 13, 0.78) 75%);
  --camera-shadow: 0 0 0 1.5px #eeeeea, 0 20px 50px rgba(0, 0, 0, 0.65);
  --paper: #e9e9e6;
  --paper-lit: #f3f3f0;
  --paper-ink: #121212;
  --paper-muted: #5f5f5b;
  --paper-rule: rgba(18, 18, 18, 0.14);
  --paper-mark: rgba(18, 18, 18, 0.08);

  --font-serif: "Literata", Georgia, serif;
  --font-sans: "Atkinson Hyperlegible", -apple-system, BlinkMacSystemFont, sans-serif;

  --radius-pill: 6px;
  --radius-card: 4px;
  --radius-sheet: 10px;
  --radius-book: 0px;
  --radius-device: 38px;

  color-scheme: light;
}

/* ---- Tokens: E-Ink Inverted (dark), chosen or following the device ----- */
.canvas[data-theme="dark"] {
  --bg-canvas: #0d0d0d;
  --bg-surface: #1a1a1a;
  --bg-surface-elevated: #131313;
  --text-primary: #eeeeea;
  --text-secondary: #bebeb9;
  --text-tertiary: #8c8c87;
  --accent-primary: #eeeeea;
  --accent-highlight: rgba(238, 238, 234, 0.14);
  --border-hairline: #4d4d4a;
  --on-accent: #0d0d0d;
  --header-glass: #0d0d0d;
  --backdrop: rgba(0, 0, 0, 0.7);
  --outer-canvas: #050505;
  --device-shadow: 0 24px 60px -12px rgba(0, 0, 0, 0.75);
  --cover-bg: #1a1a1a;
  --cover-accent: #eeeeea;
  --cover-ink: #eeeeea;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  .canvas[data-theme="system"] {
    --bg-canvas: #0d0d0d;
    --bg-surface: #1a1a1a;
    --bg-surface-elevated: #131313;
    --text-primary: #eeeeea;
    --text-secondary: #bebeb9;
    --text-tertiary: #8c8c87;
    --accent-primary: #eeeeea;
    --accent-highlight: rgba(238, 238, 234, 0.14);
    --border-hairline: #4d4d4a;
    --on-accent: #0d0d0d;
    --header-glass: #0d0d0d;
    --backdrop: rgba(0, 0, 0, 0.7);
    --outer-canvas: #050505;
    --device-shadow: 0 24px 60px -12px rgba(0, 0, 0, 0.75);
    --cover-bg: #1a1a1a;
    --cover-accent: #eeeeea;
    --cover-ink: #eeeeea;
    color-scheme: dark;
  }
}

/* ---- Base ---------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

/* Overscroll and the area around the app follow the theme */
html {
  background: #e9e9e6;
}
html:has(.canvas[data-theme="dark"]) {
  background: #0d0d0d;
}
@media (prefers-color-scheme: dark) {
  html:has(.canvas[data-theme="system"]) {
    background: #0d0d0d;
  }
}

.canvas {
  min-height: 100%;
  font-family: var(--font-sans);
  color: var(--text-primary);
  background: var(--bg-canvas);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1,
p,
blockquote {
  margin: 0;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

button:disabled {
  cursor: default;
}

a {
  color: inherit;
  text-decoration: none;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-tertiary);
  opacity: 1;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
}

:focus-visible {
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.icon {
  display: block;
  flex-shrink: 0;
}

.accent {
  display: inline-flex;
  color: var(--accent-primary);
}

.truncate {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.meta {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.meta--tertiary {
  color: var(--text-tertiary);
}

.label-caps {
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  line-height: 16px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.label-caps--sm,
.label-caps--xs {
  font-size: 10px;
}

.label-gap {
  margin-bottom: 8px;
}

/* ---- Device: full screen on a phone, a phone frame on a desktop --------- */
/* Phones: the app covers exactly the visible area. Safari on iOS doesn't resize the page for the
   on-screen keyboard (it covers the bottom and pans the page), so app.js keeps --app-height and
   --app-top in step with the visual viewport: the app shrinks above the keyboard instead. */
.device {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: var(--app-height, 100dvh);
  overflow: hidden;
  transform: translateY(var(--app-top, 0px));
  background: var(--bg-canvas);
  color: var(--text-primary);
}

.screen {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.status-bar {
  display: none;
}

/* Desktop: a wide window with a mouse or trackpad. Phones and tablets fill the screen. */
@media (min-width: 600px) and (hover: hover) and (pointer: fine) {
  .canvas {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    background: var(--outer-canvas);
  }

  html {
    background: #d6d6d2;
  }
  html:has(.canvas[data-theme="dark"]) {
    background: #050505;
  }

  .device {
    position: relative;
    top: auto;
    right: auto;
    left: auto;
    width: 100%;
    max-width: 412px;
    height: 844px;
    transform: none;
    max-height: 88vh;
    border: 1px solid var(--border-hairline);
    border-radius: var(--radius-device);
    box-shadow: var(--device-shadow);
  }

  .status-bar {
    display: flex;
  }
}

@media (min-width: 600px) and (hover: hover) and (pointer: fine) and (prefers-color-scheme: dark) {
  html:has(.canvas[data-theme="system"]) {
    background: #050505;
  }
}

/* ---- Status bar (desktop frame) ----------------------------------------- */
.status-bar {
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px 4px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  line-height: 16px;
  font-weight: 500;
  letter-spacing: 0.02em;
  user-select: none;
}

.status-time,
.status-right {
  flex: 1;
}

.status-right {
  display: flex;
  justify-content: flex-end;
}

.status-island {
  width: 80px;
  height: 16px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
}

.status-battery {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.battery {
  position: relative;
  display: block;
  width: 22px;
  height: 11px;
  padding: 1.5px;
  border: 1px solid currentColor;
  border-radius: 3px;
}

/* Battery terminal */
.battery::after {
  content: "";
  position: absolute;
  top: 2.5px;
  right: -3.5px;
  width: 2px;
  height: 4px;
  border-radius: 0 1px 1px 0;
  background: currentColor;
}

.battery-level {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 1px;
  background: currentColor;
}

.battery-bolt {
  display: inline-flex;
  margin-left: -2px;
}

/* ---- Header -------------------------------------------------------------- */
.app-header {
  position: relative;
  z-index: 20;
  flex-shrink: 0;
  padding: 8px 20px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border-hairline);
  background: var(--header-glass);
}

.app-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-header--sub .app-header-row {
  padding: 2px 0;
}

/* The Largato lizard, painted in the text colour through its shape (a mask), so it follows the
   theme. largato.svg is traced from the original artwork. */
.brand-mark {
  display: inline-block;
  flex-shrink: 0;
  height: 26px;
  aspect-ratio: 2405 / 1516;
  background: currentColor;
  -webkit-mask: url("largato.svg") center / contain no-repeat;
  mask: url("largato.svg") center / contain no-repeat;
}

.brand-mark--welcome {
  height: 76px;
  margin-bottom: 28px;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.app-title {
  font-family: var(--font-serif);
  font-size: 24px;
  line-height: 28px;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-label {
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  line-height: 16px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-pill);
  color: var(--accent-primary);
}

.icon-btn--sm {
  width: 32px;
  height: 32px;
  color: var(--text-primary);
}

.icon-btn--muted {
  color: var(--text-secondary);
}

.icon-btn--xs {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  color: var(--text-tertiary);
}

.icon-btn--round {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  background: var(--bg-surface);
  color: var(--text-secondary);
}

.icon-btn .dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 6px;
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--accent-primary);
}

/* ---- Scrolling content -------------------------------------------------- */
.screen-main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 20px 48px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-hairline) transparent;
}

.screen-main::-webkit-scrollbar {
  width: 4px;
}

.screen-main::-webkit-scrollbar-thumb {
  border-radius: 9999px;
  background: var(--border-hairline);
}

.screen-main--desk {
  padding-top: 0;
  padding-bottom: 112px;
}

.screen-main--bar {
  padding-bottom: 112px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.page-title {
  font-family: var(--font-serif);
  font-size: 28px;
  line-height: 34px;
  font-weight: 500;
  letter-spacing: -0.02em;
}

/* ---- Search ------------------------------------------------------------- */
.search-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  margin: 0 -20px;
  padding: 16px 20px;
  background: var(--bg-canvas);
}

.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-pill);
  background: var(--bg-surface-elevated);
  color: var(--text-tertiary);
}

.search-field:focus-within {
  border-color: var(--text-primary);
}

.search-field input {
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  font-size: 14px;
  line-height: 20px;
  color: var(--text-primary);
}

.search-clear {
  flex-shrink: 0;
  font-size: 12px;
  line-height: 16px;
  color: var(--text-tertiary);
}

.search-field:has(input:placeholder-shown) .search-clear {
  display: none;
}

/* ---- Cards and notes ---------------------------------------------------- */
.card {
  padding: 16px;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-card);
  background: var(--bg-surface-elevated);
}

.card--archived {
  opacity: 0.62;
}

.card--warm {
  border-color: var(--accent-primary);
}

.card--faded {
  opacity: 0.55;
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.card-top--review {
  margin-bottom: 12px;
}

.card-top--review .label-caps {
  flex-shrink: 0;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border-hairline);
}

/* Meta and the edit button, at the end of a card's top or footer row */
.card-end {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 2px;
  margin-right: -6px;
}

.card-meta {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 8px;
  color: var(--text-tertiary);
}

.chip {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  max-width: 215px;
  padding: 4px 10px;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-pill);
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  color: var(--text-secondary);
}

.page-badge {
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--accent-highlight);
  color: var(--accent-primary);
}

/* The quote's dotted underline sits below its last line. Safari on iOS draws it lower than other
   browsers, so the clamp below cut it off: the padding gives it room (and the gap to the marginalia
   below is smaller by as much). */
.quote {
  --lh: 27px;
  padding-bottom: 8px;
  font-family: var(--font-serif);
  font-size: 17px;
  line-height: var(--lh);
  color: var(--text-primary);
  text-decoration: underline dotted 1.5px;
  text-underline-offset: 6px;
}

.marginalia {
  --lh: 22px;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: var(--lh);
  white-space: pre-line;
  color: var(--text-secondary);
}

.marginalia--after {
  margin-top: 2px;
}

.note-body--lg .quote {
  --lh: 29px;
  font-size: 18px;
}

.note-body--lg .marginalia {
  --lh: 21px;
  font-size: 14px;
}

.note-body--lg .marginalia--after {
  margin-top: 4px;
}

/* Long notes: the quote clamps at 4 lines and the marginalia at 3 */
.note-body:not(.is-open) [data-clamp] {
  overflow: hidden;
}

/* The quote's 4 lines plus its underline's room (its padding); a longer quote fades out there */
.note-body:not(.is-open) [data-clamp="4"] {
  max-height: calc(var(--lh) * 4 + 8px);
}

.note-body:not(.is-open) [data-clamp="3"] {
  max-height: calc(var(--lh) * 3);
}

/* Only the parts that are actually cut off fade out */
.note-body:not(.is-open) .is-clipped {
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 1.4em), transparent);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 1.4em), transparent);
}

.show-more {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  font-size: 12px;
  line-height: 16px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
  color: var(--text-primary);
}

.show-more[aria-expanded="true"] .icon,
.picker-toggle .icon,
.manual[open] summary .icon {
  transform: rotate(180deg);
}

.empty {
  padding: 32px;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-card);
  background: var(--bg-surface);
  text-align: center;
}

.empty p {
  font-family: var(--font-serif);
  font-size: 17px;
  color: var(--text-secondary);
}

.empty .empty-small {
  font-size: 16px;
}

.empty .btn {
  margin-top: 12px;
}

/* ---- Onboarding: Welcome, first source, first note ---------------------- */
.onboarding {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.onboarding-top {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  padding-top: max(8px, env(safe-area-inset-top));
}

.steps {
  display: flex;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.step {
  width: 28px;
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--border-hairline);
}

.step.is-on {
  background: var(--text-primary);
}

.skip {
  min-width: 32px;
  padding: 8px 4px;
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  text-align: right;
  color: var(--text-tertiary);
}

.onboarding-main {
  padding: 12px 24px 24px;
}

/* The Welcome sits in the middle of the screen; auto margins (not justify-content) keep it
   scrollable when the screen is short */
.onboarding-main--center {
  display: flex;
  flex-direction: column;
}

.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: auto 0;
  text-align: center;
}

.welcome-start {
  margin-top: 28px;
}

.welcome-mark {
  margin: 0 0 12px;
  font-size: 11px;
  line-height: 16px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.onboarding-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 30px;
  line-height: 36px;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.onboarding-text {
  margin-top: 10px;
  font-size: 15px;
  line-height: 23px;
  color: var(--text-secondary);
}

.onboarding-text strong {
  color: var(--text-primary);
}

.onboarding-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 24px 0 0;
}

/* 16px keeps iOS from zooming into the field */
.field--lg {
  padding: 12px 14px;
  font-size: 16px;
  line-height: 22px;
}

.onboarding-form:has(#source-draft[data-paged="false"]) .pages-field {
  display: none;
}

.onboarding-note {
  margin-top: 24px;
  outline: none;
}

.onboarding-fields {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modes--flush {
  padding: 16px 0 0;
}

.onboarding-footer {
  display: flex;
  flex-shrink: 0;
  flex-direction: column;
  gap: 4px;
  padding: 16px 24px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border-hairline);
  background: var(--header-glass);
}

/* ---- Zero states: what a screen shows before there's anything on it ------ */
.zero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 56px 12px 24px;
  text-align: center;
}

.zero-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  margin-bottom: 8px;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-card);
  background: var(--bg-surface-elevated);
  color: var(--text-secondary);
}

.zero-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 22px;
  line-height: 28px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.zero-text {
  max-width: 290px;
  font-size: 14px;
  line-height: 21px;
  color: var(--text-secondary);
}

.zero .btn {
  margin-top: 12px;
}

/* ---- Buttons ------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
}

.btn:disabled {
  opacity: 0.4;
}

.btn-pill {
  border: 1px solid var(--border-hairline);
  background: var(--bg-surface);
  color: var(--text-primary);
}

.btn-primary {
  padding: 4px 12px;
  background: var(--accent-primary);
  color: var(--on-accent);
}

.btn-ghost {
  padding: 4px 10px;
  color: var(--text-secondary);
}

.btn-lg {
  padding: 10px 20px;
  font-size: 14px;
  line-height: 20px;
}

.btn-ghost.btn-lg {
  padding: 8px 16px;
}

.btn-block {
  width: 100%;
  padding: 12px 20px;
  font-size: 14px;
  line-height: 20px;
}

.btn-warm {
  padding: 6px 14px;
  background: var(--accent-highlight);
  color: var(--accent-primary);
}

.btn-warm.is-on {
  background: var(--accent-primary);
  color: var(--on-accent);
}

.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 12px;
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  color: var(--text-tertiary);
}

.row-end {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.fab-wrap {
  position: absolute;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  z-index: 20;
  transform: translateX(-50%);
}

.fab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius-pill);
  background: var(--accent-primary);
  color: var(--on-accent);
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
}

/* ---- Source detail ------------------------------------------------------- */
.source-head {
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-hairline);
}

.source-head-row {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.source-head-text {
  flex: 1;
  min-width: 0;
}

.source-head-row > .icon-btn {
  margin: -2px -6px 0 0;
}

.byline {
  margin-top: 4px;
  font-size: 14px;
  line-height: 20px;
  color: var(--text-secondary);
}

.progress {
  margin-top: 20px;
  padding: 14px;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-card);
  background: var(--bg-surface);
}

.progress-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.stepper {
  display: flex;
  gap: 6px;
}

.step-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-pill);
  background: var(--bg-surface-elevated);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
}

.progress input[type="range"] {
  width: 100%;
  margin: 0;
  accent-color: var(--text-primary);
  cursor: pointer;
}

.web-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 16px;
}

.section-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 16px 0;
}

.segmented {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
}

.segment {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  line-height: 16px;
  font-weight: 500;
  color: var(--text-secondary);
}

.segment[aria-current="true"],
.segment[aria-checked="true"] {
  background: var(--text-primary);
  color: var(--bg-canvas);
}

.segmented--full {
  display: flex;
  padding: 4px;
}

.segmented--full .segment {
  flex: 1;
  padding: 8px 0;
  font-size: 12px;
}

.bottom-bar {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border-hairline);
  background: var(--header-glass);
}

.add-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 16px;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-pill);
  background: var(--bg-surface-elevated);
  font-size: 12px;
  line-height: 16px;
  text-align: left;
  color: var(--text-secondary);
}

.add-note strong {
  color: var(--text-primary);
}

.add-note-plus {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  margin-left: 8px;
  border-radius: var(--radius-pill);
  background: var(--accent-primary);
  color: var(--on-accent);
}

/* Source thumbnails */
.thumb {
  flex-shrink: 0;
  user-select: none;
}

.thumb--book {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 40px;
  height: 52px;
  padding: 4px;
  border: 1.5px solid var(--cover-accent);
  border-left-width: 3.5px;
  border-radius: var(--radius-book);
  background: var(--cover-bg);
}

.thumb--book.thumb--lg {
  width: 56px;
  height: 80px;
  padding: 8px;
  border-left-width: 5px;
}

.thumb-spine {
  font-family: var(--font-serif);
  font-size: 6.5px;
  line-height: 7.5px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--cover-ink);
}

.thumb--lg .thumb-spine {
  font-size: 9px;
  line-height: 10px;
}

.thumb-author {
  font-size: 7.5px;
  text-transform: uppercase;
  color: var(--cover-ink);
  opacity: 0.7;
}

.thumb--doc {
  --fold: 10px;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  width: 40px;
  height: 52px;
  padding: 0 5px 5px;
  border: 1.5px solid var(--cover-accent);
  background: var(--bg-surface-elevated);
  clip-path: polygon(0 0, calc(100% - var(--fold)) 0, 100% var(--fold), 100% 100%, 0 100%);
}

.thumb--doc.thumb--lg {
  --fold: 13px;
  width: 56px;
  height: 72px;
  padding: 0 7px 7px;
}

.thumb-fold {
  position: absolute;
  top: -1.5px;
  right: -1.5px;
  width: var(--fold);
  height: var(--fold);
  border-bottom: 1px solid var(--cover-accent);
  border-left: 1px solid var(--cover-accent);
  background: linear-gradient(
    to bottom left,
    transparent calc(50% - 0.75px),
    var(--cover-accent) calc(50% - 0.75px),
    var(--cover-accent) calc(50% + 0.75px),
    var(--bg-surface) calc(50% + 0.75px)
  );
}

.thumb-lines {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.thumb--lg .thumb-lines {
  gap: 3px;
}

.thumb-lines span {
  height: 1.5px;
  background: var(--text-tertiary);
  opacity: 0.6;
}

.thumb-kind {
  margin-top: 4px;
  font-size: 6px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--cover-ink);
}

.thumb--lg .thumb-kind {
  margin-top: 5px;
  font-size: 8px;
}

.thumb--web {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-card);
  background: var(--bg-surface);
  font-family: var(--font-serif);
  font-size: 12px;
  font-weight: 500;
  color: var(--accent-primary);
}

.thumb--web.thumb--lg {
  width: 56px;
  height: 56px;
  font-size: 18px;
}

/* ---- Loading (handing the browser's saved data to the server) ----------- */
.loading-error {
  font-family: var(--font-serif);
  font-size: 17px;
  line-height: 26px;
  color: var(--text-secondary);
}

/* ---- Daily Review -------------------------------------------------------- */
.intro {
  margin-bottom: 20px;
}

.intro-text {
  font-size: 12px;
  line-height: 1.625;
  color: var(--text-secondary);
}

.append-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-hairline);
}

.textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-card);
  outline: none;
  background: var(--bg-surface);
  font-size: 12px;
  line-height: 16px;
  color: var(--text-primary);
  resize: none;
}

.textarea:focus {
  border-color: var(--text-primary);
}

.review-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border-hairline);
}

/* ---- Settings ------------------------------------------------------------ */
.settings-section {
  margin-top: 32px;
}

.hint--lead {
  margin: 0 0 12px;
}

.data-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

/* Opening a share link */
.import .page-title {
  margin-top: 8px;
}

.import-form {
  margin: 0;
}

.import-notes {
  margin-top: 20px;
}

/* A note to import: the whole card toggles its checkbox; an unticked one fades */
.card-choice {
  display: block;
  cursor: pointer;
}

.card-choice:not(:has(input:checked)) .card {
  opacity: 0.5;
}

.card-choice:has(input:focus-visible) .card {
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
}

.select-box {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin: 0 6px 0 6px;
  border: 1.5px solid var(--text-primary);
  border-radius: var(--radius-card);
  color: transparent;
}

.card-choice:has(input:checked) .select-box {
  background: var(--text-primary);
  color: var(--bg-canvas);
}

/* Stays in reach while the list scrolls */
.import-actions {
  position: sticky;
  bottom: -48px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 16px -20px -48px;
  padding: 12px 20px 48px;
  border-top: 1px solid var(--border-hairline);
  background: var(--bg-canvas);
}

/* Asking before something can't be undone */
.confirm {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--text-primary);
  border-radius: var(--radius-card);
  background: var(--bg-surface-elevated);
}

.confirm-text {
  font-size: 13px;
  line-height: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.hint {
  margin-top: 8px;
  font-size: 12px;
  line-height: 16px;
  color: var(--text-tertiary);
}

.when-dark {
  display: none;
}

@media (prefers-color-scheme: dark) {
  .when-dark {
    display: inline;
  }
  .when-light {
    display: none;
  }
}

/* ---- Layers: capture sheet and scanner, inside the device ---------------- */
.layer {
  position: absolute;
  inset: 0;
  z-index: 30;
}

.layer--top {
  z-index: 40;
}

.layer:empty {
  display: none;
}

.sheet-layer {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.backdrop {
  position: absolute;
  inset: 0;
  background: var(--backdrop);
}

/* An ink top rule stands in for the shadow */
.sheet {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  max-height: 92%;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1.5px solid var(--text-primary);
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  outline: none;
  background: var(--bg-surface-elevated);
}

.sheet-handle {
  display: flex;
  flex-shrink: 0;
  justify-content: center;
  padding: 12px 0 8px;
}

.sheet-handle span {
  width: 40px;
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--border-hairline);
}

.picker {
  flex-shrink: 0;
  padding: 0 20px 12px;
}

.picker-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.picker-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  max-width: 270px;
  padding: 6px 12px;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  color: var(--text-primary);
}

.picker-pill > .icon {
  color: var(--text-tertiary);
}

.picker-pill-main,
.picker-item-main {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.picker-item-main {
  gap: 8px;
  font-weight: 500;
}

.picker-page {
  white-space: nowrap;
  color: var(--text-tertiary);
}

.picker-intro {
  margin: 0 0 4px;
  font-size: 12px;
  line-height: 18px;
  color: var(--text-secondary);
}

.picker-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 0;
}

.picker-panel {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 280px;
  margin-top: 8px;
  padding: 8px;
  overflow-y: auto;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-card);
  background: var(--bg-surface);
}

.picker-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-card);
  font-size: 12px;
  line-height: 16px;
  text-align: left;
  color: var(--text-primary);
}

.picker-item.is-selected {
  background: var(--bg-surface-elevated);
}

.picker-add {
  justify-content: flex-start;
  font-weight: 500;
  color: var(--accent-primary);
}

.new-source {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 8px;
}

.field {
  width: 100%;
  padding: 6px 12px;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-card);
  outline: none;
  background: var(--bg-surface-elevated);
  font-size: 12px;
  line-height: 16px;
  color: var(--text-primary);
}

.field:focus {
  border-color: var(--text-primary);
}

.draft-slot:empty {
  display: none;
}

.draft-card {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 12px;
  border: 1px dashed var(--border-hairline);
  border-radius: var(--radius-card);
  background: var(--bg-surface-elevated);
}

.draft-icon {
  padding-top: 2px;
}

.draft-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}

.draft-title {
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
}

.draft-meta {
  font-size: 11px;
  line-height: 16px;
  color: var(--text-tertiary);
}

.manual summary {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  line-height: 16px;
  text-decoration: underline;
  text-underline-offset: 3px;
  color: var(--text-secondary);
  list-style: none;
  cursor: pointer;
}

.manual summary::-webkit-details-marker {
  display: none;
}

.manual-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

/* Pages only make sense for paged sources (book, PDF, research paper) */
.new-source:has(#source-draft[data-paged="false"]) .pages-field {
  display: none;
}

.sheet-fields {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  padding: 8px 20px;
  overflow-y: auto;
}

.field-label {
  display: block;
  margin-bottom: 4px;
}

.quote-field {
  padding-left: 14px;
  border-left: 2.5px solid var(--accent-primary);
}

.marginalia-field {
  padding-top: 12px;
  border-top: 1px solid var(--border-hairline);
}

/* Editing a note: each evolving thought is its own field */
.thought-field {
  padding-top: 12px;
  border-top: 1px solid var(--border-hairline);
}

.thought-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.thought-remove {
  font-size: 11px;
  line-height: 16px;
  text-decoration: underline;
  text-underline-offset: 3px;
  color: var(--text-tertiary);
}

.thought-field textarea {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  resize: none;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 22px;
  color: var(--text-secondary);
}

/* Editing a source */
.sheet-head {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px 12px;
}

.sheet-head h2 {
  margin: 0;
}

.sheet-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  margin: 0;
  padding: 4px 20px 16px;
  overflow-y: auto;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-row .field {
  padding: 8px 12px;
  font-size: 14px;
  line-height: 20px;
}

select.field {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-tertiary) 50%),
    linear-gradient(135deg, var(--text-tertiary) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

/* Web sources have no pages */
.sheet-form:has(select[name="type"] option[value="web"]:checked) .pages-row {
  display: none;
}

.sheet-footer--confirm {
  gap: 12px;
}

.modes {
  display: flex;
  flex-shrink: 0;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
}

.modes .btn .icon {
  color: var(--accent-primary);
}

.page-chip {
  display: inline-flex;
  align-items: center;
  margin-left: auto;
  padding: 4px 10px;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
}

.page-chip:focus-within {
  border-color: var(--text-primary);
}

.page-input {
  width: 64px;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  text-align: center;
  color: var(--text-secondary);
}

.sheet-footer {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-top: 1px solid var(--border-hairline);
}

/* ---- Marginalia writer: the whole screen for the reader's thought ------- */
.writer-preview {
  display: -webkit-box;
  width: 100%;
  min-height: 44px;
  padding: 0;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 22px;
  text-align: left;
  white-space: pre-line;
  color: var(--text-secondary);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
}

/* The quote's preview keeps the serif quote style */
.writer-preview--quote {
  min-height: 60px;
  font-family: var(--font-serif);
  font-size: 20px;
  line-height: 30px;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.writer-preview[data-empty] {
  color: var(--text-tertiary);
}

/* Inside a sheet it covers the whole device; in the onboarding, the whole screen */
.writer {
  position: absolute;
  inset: 0;
  z-index: 45;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  background: var(--bg-surface-elevated);
}

.writer-head {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-hairline);
}

.writer-quote {
  display: -webkit-box;
  flex-shrink: 0;
  margin: 16px 20px 0;
  padding-left: 14px;
  overflow: hidden;
  border-left: 2.5px solid var(--accent-primary);
  font-family: var(--font-serif);
  font-size: 15px;
  line-height: 22px;
  color: var(--text-tertiary);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

/* Fills what's left above the keyboard; long text scrolls inside it, the page never moves.
   17px also keeps iOS from zooming in. */
.writer-text {
  flex: 1;
  width: 100%;
  min-height: 0;
  padding: 16px 20px;
  border: 0;
  outline: none;
  background: transparent;
  resize: none;
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 26px;
  color: var(--text-primary);
}

.writer-text--quote {
  font-family: var(--font-serif);
  font-size: 20px;
  line-height: 30px;
  letter-spacing: -0.01em;
}

/* ---- Page scanner (simulated camera) ------------------------------------ */
.scan {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  outline: none;
  background: var(--camera-bg);
  color: var(--camera-ink);
}

.scan-hud {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 16px 20px 12px;
  padding-top: max(16px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--camera-rule);
  background: var(--camera-bg);
}

.scan-chip {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: var(--radius-pill);
  background: var(--camera-chip);
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  color: var(--camera-ink);
  cursor: pointer;
}

.scan-torch:focus-within {
  outline: 2px solid var(--camera-ink);
  outline-offset: 2px;
}

.scan-torch:has(input:checked) {
  background: var(--camera-ink);
  color: var(--camera-bg);
}

.scan-torch .torch-on,
.scan-torch:has(input:checked) .torch-off {
  display: none;
}

.scan-torch:has(input:checked) .torch-on {
  display: inline;
}

.scan-title {
  color: var(--camera-soft);
}

.scan-view {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 20px;
  overflow: hidden;
  user-select: none;
}

.scan-glow {
  position: absolute;
  inset: 0;
  background: var(--camera-glow);
  pointer-events: none;
}

.scan:has([data-torch]:checked) .scan-glow {
  background: var(--camera-glow-lit);
}

.scan-tip {
  position: relative;
  z-index: 1;
  margin-bottom: 12px;
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--camera-muted);
}

.scan-page {
  position: relative;
  z-index: 1;
  width: 100%;
  padding: 20px;
  border-radius: var(--radius-card);
  background: var(--paper);
  box-shadow: var(--camera-shadow);
  color: var(--paper-ink);
}

.scan:has([data-torch]:checked) .scan-page {
  background: var(--paper-lit);
}

.scan-page-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--paper-rule);
  font-family: var(--font-sans);
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--paper-muted);
}

/* Dragging across lines selects them, so the page mustn't scroll under the finger */
.scan-lines {
  display: flex;
  flex-direction: column;
  gap: 6px;
  touch-action: none;
}

.scan-line {
  display: block;
  padding: 4px 8px;
  border-left: 3px solid transparent;
  border-radius: var(--radius-card);
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 22px;
  cursor: pointer;
}

.scan-line:has(input:checked) {
  border-left-color: var(--paper-ink);
  background: var(--paper-mark);
  text-decoration: underline dotted 1.5px;
  text-underline-offset: 5px;
}

.scan-line:has(input:focus-visible) {
  outline: 2px solid var(--paper-ink);
  outline-offset: 1px;
}

.scan-next {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 16px;
  padding: 6px 14px;
  border: 1px solid var(--camera-chip-border);
  border-radius: var(--radius-pill);
  background: var(--camera-chip);
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  color: var(--camera-ink);
}

.scan-bottom {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--camera-rule);
  background: var(--camera-panel);
}

.scan-preview-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.scan-preview-head .meta {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--camera-muted);
}

.scan-preview-head .scan-count {
  text-transform: none;
  color: var(--camera-soft);
}

.scan-preview {
  display: -webkit-box;
  min-height: 40px;
  overflow: hidden;
  font-family: var(--font-serif);
  font-size: 15px;
  line-height: 20px;
  color: var(--camera-ink);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.scan-preview.is-empty {
  color: var(--camera-muted);
}

.scan-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 4px;
}

.scan-clear {
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--camera-soft);
}

.scan-use {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  background: var(--camera-ink);
  font-size: 12px;
  font-weight: 500;
  color: var(--camera-bg);
}

.scan-use:disabled {
  opacity: 0.4;
}

.scan :focus-visible {
  outline-color: var(--camera-ink);
}

/* ---- Toast --------------------------------------------------------------- */
.toast {
  position: absolute;
  top: calc(96px + env(safe-area-inset-top));
  left: 50%;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100% - 32px);
  padding: 6px 14px;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-pill);
  background: var(--bg-surface-elevated);
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  white-space: nowrap;
  color: var(--text-primary);
  transform: translateX(-50%);
}

.toast-dot {
  flex-shrink: 0;
  width: 6px;
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--accent-primary);
}

.toast-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Touch devices: no zoom on focus ------------------------------------
   Safari on iOS zooms into any field with text under 16px, and doesn't zoom back out. Touch devices
   get 16px fields; blocking zoom instead (maximum-scale) would stop pinch-zoom on Android. The
   selectors match the specificity of the rules they override. */
@media (hover: none) and (pointer: coarse) {
  .search-field input,
  .field,
  .form-row .field,
  .textarea,
  .page-input,
  .thought-field textarea {
    font-size: 16px;
    line-height: 22px;
  }

  .page-input {
    width: 76px;
  }
}

/* ---- E-ink rendering ------------------------------------------------------
   An e-ink panel never animates smoothly: each change is drawn in one step, with a refresh. Big
   screen changes get a full refresh (a faint grey wash, blank paper, then the new frame settling in
   two steps); a tap gets a quick partial refresh of the region it changed. */
.canvas,
.canvas *,
.canvas *::before,
.canvas *::after {
  transition: none !important;
}

/* Pressed controls invert, like a tap on an e-reader */
.canvas button:active:not(:disabled),
.canvas a:active,
.canvas .scan-chip:active {
  filter: invert(1);
}

.eink-refresh {
  position: absolute;
  inset: 0;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  animation: eink-full-refresh 0.4s step-end;
}

@keyframes eink-full-refresh {
  0% {
    opacity: 1;
    background: color-mix(in srgb, var(--text-primary) 16%, var(--bg-canvas));
  }
  15% {
    opacity: 1;
    background: var(--bg-canvas);
  }
  45% {
    opacity: 0.55;
    background: var(--bg-canvas);
  }
  70% {
    opacity: 0.2;
    background: var(--bg-canvas);
  }
  100% {
    opacity: 0;
  }
}

.eink-partial,
.eink-enter {
  animation: eink-partial-refresh 0.3s step-end;
}

@keyframes eink-partial-refresh {
  0% {
    filter: invert(1);
  }
  40% {
    filter: none;
    opacity: 0.45;
  }
  70% {
    filter: none;
    opacity: 0.8;
  }
  100% {
    filter: none;
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .eink-refresh {
    display: none;
  }
  .eink-partial,
  .eink-enter {
    animation: none;
  }
}
