/* Palette as tokens. Light by default, dark via prefers-color-scheme. An alert only recolours the status card
   (.status--alert); the page and its other components keep their normal palette. */
:root {
  color-scheme: light dark;
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #eceff5;
  --border: #d3d9e4;
  --fg: #141a23;
  --muted: #546070;
  --accent: #2154d4;
  --on-accent: #ffffff;
  --accent-soft: #e3ebfd;
  --focus: #0b57d0;
  --error: #b3261e;
  --on-error: #ffffff;
  --ok-bg: #d9f3e2;
  --ok-fg: #0b4422;
  --warn-bg: #fbe6c2;
  --warn-fg: #5c3300;
  --neutral-bg: #e3e7ee;
  --neutral-fg: #2b3440;
  --alert-card: #b71c1c;
  --logo-nail: #f2f6ff;
  --logo-ok: #2fb36b;
  --logo-alert: #e5484d;
  --shadow: 0 1px 2px rgba(20, 26, 35, 0.08), 0 6px 20px rgba(20, 26, 35, 0.08);
  --radius: 18px;
  --radius-sm: 12px;
  --tile-w: 76px; /* the stats tile next to the status card */
  --row-gap: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1217;
    --surface: #181e26;
    --surface-2: #232b36;
    --border: #323c49;
    --fg: #e9edf3;
    --muted: #a6b0bd;
    --accent: #7ba6ff;
    --on-accent: #0a1426;
    --accent-soft: #1d2b49;
    --focus: #9ec0ff;
    --error: #ff9a92;
    --on-error: #3a0a07;
    --ok-bg: #12351f;
    --ok-fg: #c8f1d6;
    --warn-bg: #46300a;
    --warn-fg: #ffe1ad;
    --neutral-bg: #2a323d;
    --neutral-fg: #e1e6ee;
    --alert-card: #c62828;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
  transition: background-color 0.15s;
}

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

h1, h2, h3, p { margin-top: 0; }

/* ---------- layout ---------- */

.app {
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 600px;
  margin: 0 auto;
  padding: 12px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 48px;
}
.brand { display: flex; align-items: center; gap: clamp(8px, 2vw, 14px); min-width: 0; }
/* Fluid: 44 px logo at 360 px wide, the full 72 px from about 700 px up. */
.brand__logo { flex: none; display: inline-flex; width: clamp(44px, 8vw + 15px, 72px); height: clamp(44px, 8vw + 15px, 72px); }
.brand__logo svg { width: 100%; height: 100%; }
.logo__finger { fill: var(--accent); }
.logo__nail { fill: var(--logo-nail); }
.logo__shield { fill: var(--logo-ok); }
.logo__bang { opacity: 0; }
/* Alert variant (red shield with "!"), toggled by main.js together with the favicon. Colour and opacity only. */
.brand__logo.is-alert .logo__shield { fill: var(--logo-alert); }
.brand__logo.is-alert .logo__check { opacity: 0; }
.brand__logo.is-alert .logo__bang { opacity: 1; }
@media (prefers-reduced-motion: no-preference) {
  .logo__shield { transition: fill 0.25s; }
  .logo__check, .logo__bang { transition: opacity 0.25s; }
}
.brand__title { margin: 0; min-width: 0; font-size: clamp(2.4rem, 5vw, 3.6rem); font-weight: 800; letter-spacing: -0.02em; line-height: 1.05; white-space: nowrap; }
/* Narrow screens: "The" sits above "Nail Biter" so the larger name still fits next to the logo and the three icons. */
@media (max-width: 719px) {
  .brand__title { font-size: clamp(1.5rem, 8vw, 2.4rem); }
  .brand__the { display: block; font-size: 0.5em; line-height: 1; letter-spacing: 0; }
  .brand__accent { display: block; }
}
.brand__accent { color: var(--accent); }
.topbar__actions { display: flex; gap: 4px; }

.main { display: flex; flex-direction: column; gap: 12px; flex: 1 1 auto; }

.footer { text-align: center; font-size: 0.85rem; color: var(--muted); }
.footer p { margin: 0 0 4px; }
.link-btn {
  font: inherit;
  padding: 4px 2px;
  border: 0;
  background: none;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
  transition: filter 0.12s;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn__icon { display: inline-flex; }
.btn__icon svg { width: 20px; height: 20px; }
.btn--secondary { background: var(--surface); color: var(--fg); border-color: var(--border); box-shadow: var(--shadow); }
.btn--primary.is-running { background: var(--neutral-fg); color: var(--bg); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn[aria-pressed="true"] { color: var(--error); }

/* ---------- status card ---------- */

.status {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 92px;
  padding: 16px 18px;
  border-radius: var(--radius);
  background: var(--neutral-bg);
  color: var(--neutral-fg);
  box-shadow: var(--shadow);
  overflow-wrap: anywhere;
}
.status__icon { flex: none; display: inline-flex; }
.status__icon svg { width: 40px; height: 40px; }
/* Live text and invisible copies of every state's text share one grid cell: the card is as tall as the tallest state
   (alert title wraps, hints differ), whichever state is shown, at every width and in the PiP window. */
.status__text { min-width: 0; flex: 1 1 auto; display: grid; grid-template-columns: minmax(0, 1fr); }
.status__text > * { grid-area: 1 / 1; min-width: 0; }
.status__live { align-self: center; }
.status__sizer { visibility: hidden; pointer-events: none; user-select: none; }
.status__title { margin: 0; font-size: clamp(1.25rem, 5.5vw, 1.75rem); font-weight: 700; line-height: 1.2; }
.status__hint { margin: 2px 0 0; font-size: 0.95rem; opacity: 0.9; }
.status--ok { background: var(--ok-bg); color: var(--ok-fg); }
.status--hint, .status--paused { background: var(--warn-bg); color: var(--warn-fg); }
.status--alert { background: var(--alert-card); color: #ffffff; outline: 3px solid #ffffff; outline-offset: -3px; }
/* One gentle pulse when the card turns into an alert (the class is set on entry), not a continuous blink. */
.status--alert { animation: alert-pulse 0.7s ease-out 1; }
@keyframes alert-pulse {
  /* transform and shadow only: nothing here may change the card's layout size */
  40% { transform: scale(1.03); box-shadow: 0 0 0 6px rgba(183, 28, 28, 0.35); }
}
@media (prefers-reduced-motion: reduce) {
  .status--alert { animation: none; }
}

/* The status card and the daily stats tile share one row; the tile stretches to the card's height, so it never makes the row taller. */
.status-row { display: grid; grid-template-columns: minmax(0, 1fr) var(--tile-w); gap: var(--row-gap); align-items: stretch; }
.stats-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  padding: 6px 4px;
  font: inherit;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.stats-tile:hover { background: var(--surface-2); }
.stats-tile__icon { display: inline-flex; color: var(--accent); }
.stats-tile__icon svg { width: 22px; height: 22px; }
.stats-tile__label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.78rem; font-weight: 600; color: var(--muted); }
.stats-tile__count { font-size: 1.75rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }

.message { margin: 0; color: var(--error); font-size: 0.95rem; font-weight: 600; }

/* ---------- camera stage ---------- */

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.stage__layer { position: absolute; inset: 0; width: 100%; height: 100%; }
/* cover on both layers: when the stage is not the video's shape (two-column layout) the picture is cropped at the
   sides, and the overlay canvas (same size as the video frame) is cropped identically, so landmarks keep lining up. */
.stage__layer { object-fit: cover; }
.mirror { transform: scaleX(-1); }

.stage__empty {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  text-align: center;
}
.stage__empty-icon svg { width: 44px; height: 44px; }
.stage.is-off .stage__empty { display: flex; }

.pip-placeholder {
  margin: 0;
  padding: 28px 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px dashed var(--border);
  text-align: center;
  color: var(--muted);
}

/* Two texts in one cell, one visible (js/ui/shell.js swapText): the box has the size of the larger. */
.swap { display: grid; }
.swap > * { grid-area: 1 / 1; min-width: 0; }
.swap > .is-inactive { visibility: hidden; }

/* ---------- actions and model loading ---------- */

.actions { display: flex; }
.actions__main { flex: 1 1 auto; font-size: 1.1rem; min-height: 52px; }

.pip-section { display: flex; flex-direction: column; gap: 8px; }
.pip-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  text-align: left;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.pip-card:hover { background: var(--surface-2); }
.pip-card.is-open { background: var(--ok-bg); color: var(--ok-fg); border-color: transparent; }
.pip-card__icon { flex: none; display: inline-flex; color: var(--accent); }
.pip-card.is-open .pip-card__icon { color: inherit; }
.pip-card__icon svg { width: 28px; height: 28px; }
.pip-card__text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.pip-card__title { font-weight: 700; }
.pip-card__desc { font-size: 0.85rem; color: var(--muted); }
.pip-card.is-open .pip-card__desc { color: inherit; opacity: 0.85; }
.pip-card__action { flex: none; font-weight: 700; font-size: 0.9rem; color: var(--accent); }
.pip-card.is-open .pip-card__action { color: inherit; text-decoration: underline; }
@media (max-width: 420px) {
  .pip-card:not(.is-open) .pip-card__action { display: none; }
}

.pip-note { margin: 0; padding: 12px 14px; font-size: 0.9rem; color: var(--warn-fg); background: var(--warn-bg); border-radius: var(--radius-sm); }

.models { display: flex; flex-direction: column; gap: 6px; }
.models__status { margin: 0; font-size: 0.9rem; color: var(--error); font-weight: 600; text-align: center; }
.models__bar { height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.models__bar span {
  display: block;
  width: 40%;
  height: 100%;
  border-radius: 2px;
  background: var(--accent);
  animation: slide 1.2s ease-in-out infinite;
}
@keyframes slide {
  from { transform: translateX(-100%); }
  to { transform: translateX(250%); }
}
@media (prefers-reduced-motion: reduce) {
  .models__bar span { animation: none; width: 100%; opacity: 0.5; }
}

/* ---------- advanced / debug (unchanged in function, restyled with tokens) ---------- */

.debug-toggle { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
.debug-toggle input { width: 1.2rem; height: 1.2rem; accent-color: var(--accent); }

.debug-panel { display: flex; flex-direction: column; gap: 10px; }
.debug-panel h2 { margin: 6px 0 0; font-size: 1.05rem; }

.debug-info {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  font: 0.8rem/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.config-panel { display: flex; flex-direction: column; gap: 10px; }

.field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
}
.field__label { font-size: 0.92rem; }
.field__label code {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
.field__control { display: flex; align-items: center; gap: 10px; }
.field__control input[type="range"] { flex: 1 1 auto; min-width: 0; accent-color: var(--accent); }
.field__value { min-width: 3.2em; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.field input[type="checkbox"] { align-self: flex-start; width: 1.2rem; height: 1.2rem; accent-color: var(--accent); }

.recorder {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
}
.recorder__label { font-size: 0.92rem; }
.select {
  font: inherit;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--fg);
}
.select:disabled { opacity: 0.6; }
.recorder__status { margin: 0; min-height: 1.4em; font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.recorder__link { font-size: 0.85rem; color: var(--accent); overflow-wrap: anywhere; }

/* ---------- quick settings card (every layout) ---------- */

.quick {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.quick__heading { margin: 0; font-size: 1.05rem; }
.quick__toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 36px;
  padding: 0;
  font: inherit;
  font-weight: 700;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}
.quick__chevron { display: inline-flex; transition: transform 0.15s; }
.quick__chevron svg { width: 22px; height: 22px; }
.quick:not(.is-collapsed) .quick__chevron { transform: rotate(180deg); }
@media (prefers-reduced-motion: reduce) { .quick__chevron { transition: none; } }
.quick { position: relative; }
.quick__body { display: flex; flex-direction: column; gap: 10px; }
.quick.is-collapsed .quick__body { display: none; }
.quick__more { align-self: flex-start; color: var(--accent); font-weight: 600; }
.quick .field { padding: 8px 10px; background: var(--surface-2); border: 0; }
.quick .field__control .icon-btn { flex: none; width: 40px; height: 40px; margin-left: -6px; }
.quick .field__control .icon-btn[aria-pressed="true"] { color: var(--error); }
/* Muted: the volume stays adjustable, just visibly inactive. */
.field.is-muted input[type="range"], .field.is-muted .field__value { opacity: 0.45; }

/* ---------- two-column desktop layout ---------- */

@media (min-width: 1024px) {
  .app { max-width: 1400px; padding: 16px 32px; }
  .main {
    flex: 0 1 auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(340px, 30vw, 420px);
    grid-template-rows: repeat(7, auto);
    column-gap: 24px;
    row-gap: 0;
    align-items: start;
  }
  .main > * { grid-column: 2; margin-bottom: 12px; }
  /* The card is 76px + a gap narrower than when it had the column to itself: slightly smaller type keeps its height. */
  .status { padding: 14px 16px; gap: 12px; }
  .status__icon svg { width: 36px; height: 36px; }
  .status__title { font-size: 1.4rem; }
  .status__hint { font-size: 0.9rem; line-height: 1.35; }
  /* The preview column is exactly as tall as the right column (rows 1-5, ending at the last card, with no margin
     below it): it stretches over them and takes its height from the grid, not from the video. */
  .main > .stage, .main > .pip-placeholder { grid-column: 1; grid-row: 1 / 6; margin-bottom: 0; align-self: stretch; }
  .main > .pip-placeholder { display: flex; align-items: center; justify-content: center; }
  .main > .status-row { grid-row: 1; }
  .main > .message { grid-row: 2; }
  .main > .actions { grid-row: 3; }
  .main > .pip-section { grid-row: 4; }
  .main > .quick { grid-row: 5; margin-bottom: 0; }
  .main > .models { grid-row: 6; margin: 12px 0 0; }
  .main > .debug-info { grid-column: 1 / -1; grid-row: 7; margin: 12px 0 0; }
  /* The video ratio is set inline by main.js for the single column; here the height is dictated by the column. */
  .stage { aspect-ratio: auto !important; min-height: 360px; }
  /* The quick card's row is always as tall as the card would be expanded (--quick-full-h, measured in settings.js), so
     collapsing it shortens only the card, not the preview. An invisible grid item shares the card's cell to hold the
     height; the card is top-aligned and the collapsed body stays laid out (out of flow, invisible) to be measured. */
  .main::after {
    content: "";
    grid-column: 2;
    grid-row: 5;
    height: var(--quick-full-h, 0px);
    pointer-events: none;
  }
  .quick.is-collapsed .quick__body {
    display: flex;
    position: absolute;
    left: 14px;
    right: 14px;
    visibility: hidden;
    pointer-events: none;
  }
}

/* ---------- single column (phone, narrow window): no page scrolling ---------- */

.pip-note__short, .footer__privacy .short { display: none; }

@media (max-width: 1023.98px) {
  /* The page is exactly one viewport tall: the preview takes whatever the other rows leave, so Start is always visible. */
  .app {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    padding: calc(8px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) calc(16px + env(safe-area-inset-left, 0px));
    gap: 8px;
  }
  .topbar { flex: none; }
  .main { flex: 1 1 auto; min-height: 0; gap: 8px; }
  /* The card shares its row with the stats tile, so it is narrower: tighter padding and type keep it as short as before. */
  .status { min-height: 84px; gap: 10px; padding: 10px 12px; }
  .status__icon svg { width: 32px; height: 32px; }
  .status__title { font-size: 1.1rem; }
  .status__hint { margin-top: 1px; font-size: 0.85rem; line-height: 1.3; }
  .main > * { flex: none; }
  /* Both layers share object-fit: cover, so the overlay still lines up when the box is not the video's shape. */
  .main > .stage { flex: 1 1 0; min-height: 120px; aspect-ratio: auto !important; }
  /* Takes the preview's place at the preview's size, so opening the PiP window moves nothing else on the page. */
  .main > .pip-placeholder { flex: 1 1 0; min-height: 120px; padding: 10px 12px; display: flex; align-items: center; justify-content: center; }
  .main > .debug-info { max-height: 5rem; overflow: auto; margin: 0; }
  .actions__main { min-height: 48px; }

  /* Compact background-window card and note: one line each. */
  .pip-card { padding: 8px 12px; gap: 10px; }
  .pip-card__desc { display: none; }
  /* One line in both states (open title is long): the card must not change height when the window opens. */
  .pip-card__title > *, .pip-card__action > * { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .pip-card__icon svg { width: 24px; height: 24px; }
  .pip-note { padding: 8px 12px; font-size: 0.82rem; }
  .pip-note__long, .footer__privacy .long { display: none; }
  .pip-note__short, .footer__privacy .short { display: inline; }

  .footer { flex: none; display: flex; justify-content: center; align-items: center; gap: 4px 10px; flex-wrap: wrap; font-size: 0.78rem; }
  .footer p { margin: 0; }
  .footer .link-btn { padding: 2px; }

  /* Last resort for very short viewports (phone in landscape): the page may scroll, the preview keeps a usable size. */
  @media (max-height: 519px) {
    .app { height: auto; min-height: 100vh; min-height: 100dvh; }
    .main > .stage, .main > .pip-placeholder { flex: none; height: 180px; }
  }
}

/* The quick settings as the first section of the settings drawer (single column only, see settings.js placeQuick). */
.quick.in-drawer { padding: 0; border: 0; box-shadow: none; background: none; gap: 10px; }
.quick.in-drawer .quick__heading { font-size: 1.05rem; }
.quick.in-drawer .quick__toggle { pointer-events: none; min-height: 0; cursor: default; }
.quick.in-drawer .quick__chevron, .quick.in-drawer .quick__more { display: none; }
.quick.in-drawer.is-collapsed .quick__body { display: flex; position: static; visibility: visible; pointer-events: auto; }

/* ---------- Document Picture-in-Picture window (about 320x244 inside) ---------- */

body.pip { margin: 0; height: 100vh; overflow: hidden; }
.pip-root {
  height: 100%;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.pip-root .status {
  flex: 0 0 auto;
  min-height: 0;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 12px;
  box-shadow: none;
}
.pip-root .status__icon svg { width: 26px; height: 26px; }
.pip-root .status__title { font-size: clamp(0.95rem, 5.4vw, 1.2rem); }
.pip-root .status__hint { display: none; }
.status__min { flex: none; margin-left: auto; color: inherit; }
.status__min:hover { background: rgba(127, 127, 127, 0.25); }
.pip-root .status__min { width: 34px; height: 34px; }
.pip-root .status__min svg { width: 20px; height: 20px; }
.pip-root .stage {
  flex: 1 1 0;
  min-height: 0;
  width: auto;
  max-width: 100%;
  align-self: center;
  border-radius: 12px;
  box-shadow: none;
}

/* Minimized (button) or a window shrunk to strip height by hand (keep 120px in sync with PIP_STRIP_MAX_HEIGHT in
   js/pipSize.js): only the status strip shows. The <video> must stay laid out and decoding, because detection reads
   it, so it is moved out of view instead of hidden (display:none / visibility:hidden would stop the frames). */
body.pip--min .pip-root .stage {
  position: absolute;
  left: -10000px;
  top: 0;
  width: 320px;
  height: auto;
  flex: none;
  pointer-events: none;
}
@media (max-height: 120px) {
  body.pip .pip-root .stage {
    position: absolute;
    left: -10000px;
    top: 0;
    width: 320px;
    height: auto;
    flex: none;
    pointer-events: none;
  }
  body.pip .pip-root .status__title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}
body.pip--min .pip-root .status__title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- modals (native <dialog>) ---------- */

.modal {
  width: min(560px, calc(100% - 24px));
  max-height: min(90vh, 90dvh);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--fg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}
.modal[open] { display: flex; flex-direction: column; }
.modal::backdrop { background: rgba(8, 12, 18, 0.62); }

.modal__header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 12px 8px 20px;
}
.modal__title { margin: 0; font-size: 1.25rem; }
.modal__actions { display: flex; gap: 4px; }
.modal__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 20px 12px;
}
.modal__lead { color: var(--muted); }
.modal__footer {
  flex: none;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
}
.modal__footer--stack { flex-direction: column; align-items: stretch; }
.modal__hint { margin: 0; font-size: 0.85rem; color: var(--muted); }

.check { display: flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; }
.check input { width: 1.4rem; height: 1.4rem; accent-color: var(--accent); flex: none; }

.terms-list { margin: 0; padding-left: 1.3rem; display: flex; flex-direction: column; gap: 10px; }

/* ---------- guided tour (coachmarks) ---------- */

.coach {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--fg);
  overflow: hidden;
}
.coach::backdrop { background: transparent; }
.coach__shield { position: fixed; inset: 0; }
/* The dimming is the huge shadow around the highlighted element, so the element itself stays bright. */
.coach__spot {
  position: fixed;
  border-radius: 14px;
  box-shadow: 0 0 0 3px #ffffff, 0 0 0 200vmax rgba(8, 12, 18, 0.7);
  pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
  .coach__spot { transition: left 0.18s, top 0.18s, width 0.18s, height 0.18s; }
  .coach__bubble { transition: left 0.18s, top 0.18s; }
}
.coach__bubble {
  position: fixed;
  width: min(340px, calc(100vw - 24px));
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
/* Scrolls on its own, so the arrow (which sticks out of the bubble) never causes a scrollbar. */
.coach__body { max-height: calc(100dvh - 24px); overflow-y: auto; padding: 14px 16px 12px; border-radius: var(--radius); }
.coach__counter { margin: 0 0 2px; font-size: 0.8rem; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.coach__title { margin: 0 0 4px; font-size: 1.15rem; }
.coach__text { margin: 0 0 12px; font-size: 0.95rem; }
.coach__buttons { display: flex; align-items: center; gap: 8px; }
.coach__buttons .btn { min-height: 44px; padding: 8px 14px; }
.coach__spacer { flex: 1 1 auto; }
.btn--ghost { background: transparent; color: var(--muted); border-color: transparent; }
.coach__skip { padding-left: 4px; padding-right: 4px; text-decoration: underline; }

/* The arrow is a rotated square on the bubble edge that faces the element; --arrow is its offset along that edge. */
.coach__arrow {
  position: absolute;
  width: 14px;
  height: 14px;
  background: var(--surface);
  border: 0 solid var(--border);
  transform: rotate(45deg);
}
.coach__bubble[data-side="center"] .coach__arrow,
.coach__bubble[data-side="overlay"] .coach__arrow { display: none; }
.coach__bubble[data-side="bottom"] .coach__arrow { top: -8px; left: calc(var(--arrow, 24px) - 7px); border-width: 1px 0 0 1px; }
.coach__bubble[data-side="top"] .coach__arrow { bottom: -8px; left: calc(var(--arrow, 24px) - 7px); border-width: 0 1px 1px 0; }
.coach__bubble[data-side="right"] .coach__arrow { left: -8px; top: calc(var(--arrow, 24px) - 7px); border-width: 0 0 1px 1px; }
.coach__bubble[data-side="left"] .coach__arrow { right: -8px; top: calc(var(--arrow, 24px) - 7px); border-width: 1px 1px 0 0; }

/* ---------- settings drawer ---------- */

.settings__body { display: flex; flex-direction: column; gap: 22px; padding-bottom: 20px; }
.settings__section { display: flex; flex-direction: column; gap: 10px; }
.settings__heading { margin: 0; font-size: 1.05rem; }
.field__help { margin: 0; font-size: 0.85rem; color: var(--muted); }
.field.check { flex-direction: row; align-items: center; }
.fieldset { margin: 0; min-inline-size: 0; gap: 8px; }
.fieldset legend { padding: 0 4px; }
.field .select { flex: 1 1 auto; min-width: 0; }
.field__control input[type="range"]:disabled { opacity: 0.45; }

@media (min-width: 720px) {
  .modal--drawer {
    width: 420px;
    max-width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    margin: 0 0 0 auto;
    border-radius: var(--radius) 0 0 var(--radius);
  }
  .modal--drawer::backdrop { background: rgba(8, 12, 18, 0.35); }
}
@media (max-width: 719px) {
  .modal--drawer {
    width: 100%;
    max-width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border: 0;
    border-radius: 0;
  }
}

/* ---------- advanced section (inside the settings drawer) ---------- */

.advanced { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.advanced__summary { padding: 12px 14px; font-weight: 600; cursor: pointer; border-radius: var(--radius-sm); }
.advanced__body { display: flex; flex-direction: column; gap: 12px; padding: 4px 12px 14px; }

.btn--danger { background: var(--error); color: var(--on-error); }
.confirm { padding: 12px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--error); }
.confirm__text { margin: 0 0 10px; }
.confirm__buttons { display: flex; flex-wrap: wrap; gap: 10px; }
.confirm__buttons .btn { flex: 1 1 140px; }

/* ---------- account section (settings drawer) ---------- */

.account { display: flex; flex-direction: column; gap: 10px; }
.account .btn { text-decoration: none; }
.account__email { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.account__pro { margin: 0; color: var(--muted); }
.account__buttons { display: flex; flex-wrap: wrap; gap: 10px; }
.account__buttons .btn { flex: 1 1 140px; }
.account__error { margin: 0; color: var(--error); font-size: 0.9rem; }

/* ---------- daily stats dialog ---------- */

.modal--stats { width: min(480px, calc(100% - 24px)); }
.stats { display: flex; flex-direction: column; gap: 16px; }
.stats__summary { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px; }
.stats__big { margin: 0; font-size: 1.6rem; font-weight: 800; line-height: 1.2; }
.stats__active { margin: 0; color: var(--muted); font-weight: 600; }
.stats__heading { margin: 0 0 6px; font-size: 0.95rem; color: var(--muted); }
.stats__empty { margin: 0; padding: 16px; border-radius: var(--radius-sm); background: var(--ok-bg); color: var(--ok-fg); font-weight: 600; text-align: center; }
.stats__section { margin: 0; }
.chart { display: block; width: 100%; height: auto; }
.chart__axis { stroke: var(--border); stroke-width: 1; }
.chart__bar { fill: var(--accent); }
.chart__value { fill: var(--fg); font-size: 7px; font-weight: 700; }
.chart__label { fill: var(--muted); font-size: 8px; }
.stats__list { margin: 0; padding: 0; list-style: none; max-height: 11rem; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.stats__item { display: flex; justify-content: space-between; gap: 12px; padding: 8px 12px; font-variant-numeric: tabular-nums; }
.stats__item + .stats__item { border-top: 1px solid var(--border); }
.stats__item span { color: var(--muted); }
.stats__footer { justify-content: flex-start; }
