:root {
  --bg: #0b0d12;
  --fg: #f4f6fb;
  --muted: #8b93a7;
  --accent: #4f8cff;
  --warn: #ffb020;   /* final-minute warning (ring + digits) */
  --ring-track: rgba(255, 255, 255, 0.08);
  --btn: rgba(255, 255, 255, 0.06);
  --btn-hover: rgba(255, 255, 255, 0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* The `hidden` attribute must win over any element's explicit `display` (e.g.
   `.bg-btn{display:grid}`), otherwise Pro-only controls stay visible to everyone. */
[hidden] { display: none !important; }

/* Keyboard accessibility: a visible focus ring on every interactive element,
   but only for keyboard navigation (:focus-visible), never on mouse/touch. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  /* Custom background hook for logged-in users gets set on body via inline style */
  background-size: cover;
  background-position: center;
}

/* Body is a flex column: timer area fills, footer sits below — never overlap. */
body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(1rem, 3vh, 2.6rem);
  padding: calc(env(safe-area-inset-top) + 1rem) env(safe-area-inset-right)
           1rem env(safe-area-inset-left);
  transition: background 0.4s ease;
  /* Own stacking context so the timer + end message sit above the flash overlay. */
  position: relative;
  z-index: 1;
}

/* ---- Timer + progress ring ---- */
.timer {
  position: relative;
  /* 60vh (not 78) so the controls + preset chips + footer below the ring have
     room on short/landscape viewports; portrait is still capped by 78vw. */
  width: min(78vw, 60vh, 560px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}

.ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-track {
  fill: none;
  stroke: var(--ring-track);
  stroke-width: 1.5;
}

.ring-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-dasharray: 289.027;   /* 2 * PI * 46 */
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.3s linear, stroke 0.3s ease;
}

.display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  z-index: 1;
}

/* Sequence (Pomodoro) phase indicator — sits above the time, only when a plan is active */
.phase {
  min-height: 1.1rem;
  font-size: clamp(0.8rem, 3.2vw, 1rem);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.3s;
}
body.has-phases .phase { opacity: 0.85; }

.time {
  font-size: clamp(3.2rem, 17vw, 11rem);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  line-height: 1;
  font-feature-settings: "tnum";
  white-space: nowrap;   /* never wrap; JS shrinks long values (e.g. 2:05:00) to fit */
}

.custom {
  height: 1.6rem;
}

.custom-input {
  width: 9rem;
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  color: var(--muted);
  text-align: center;
  font-size: 1rem;
  padding: 0.2rem 0;
  outline: none;
  transition: border-color 0.2s, color 0.2s;
}

.custom-input::placeholder { color: var(--muted); opacity: 0.6; }
.custom-input:focus {
  color: var(--fg);
  border-bottom-color: var(--accent);
}

/* ---- Controls ---- */
.controls {
  display: flex;
  align-items: center;
  gap: clamp(1rem, 4vw, 1.8rem);
}

.btn {
  display: grid;
  place-items: center;
  border: none;
  cursor: pointer;
  border-radius: 50%;
  background: var(--btn);
  color: var(--fg);
  transition: background 0.15s, transform 0.05s;
}
.btn:hover { background: var(--btn-hover); }
.btn:active { transform: scale(0.94); }
.btn svg { width: 46%; height: 46%; fill: currentColor; }

.btn-secondary { width: clamp(3rem, 12vw, 4rem); height: clamp(3rem, 12vw, 4rem); }
.btn-primary {
  width: clamp(4.2rem, 17vw, 5.5rem);
  height: clamp(4.2rem, 17vw, 5.5rem);
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: #3f7bf0; }

/* ---- Quick-start presets (homepage) ---- */
.quickstart { display: flex; justify-content: center; }
.presets {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; max-width: 34rem;
}
/* Light outline chips — the active one fills with the accent. */
.preset {
  padding: 0.45rem 0.95rem; border-radius: 999px; font-family: inherit;
  border: 1px solid rgba(255, 255, 255, 0.16); background: transparent;
  color: var(--muted); font-size: 0.9rem; font-weight: 600; cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.preset:hover { color: var(--fg); background: rgba(255, 255, 255, 0.07); }
.preset.active { color: #fff; background: var(--accent); border-color: transparent; }

/* Pomodoro = one outlined pill: the label + the settings gear share the border,
   with a hairline divider between them. */
.pomo-chip {
  display: inline-flex; align-items: stretch; overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16); border-radius: 999px;
  transition: background 0.15s, border-color 0.15s;
}
.pomo-chip .preset { border: none; border-radius: 0; background: transparent; }
.pomo-chip .preset:hover { background: rgba(255, 255, 255, 0.07); }
.pomo-chip .preset.active { background: transparent; }   /* the pill shows active, not the label */
.pomo-gear {
  display: inline-grid; place-items: center; width: 2.3rem;
  border: none; border-left: 1px solid rgba(255, 255, 255, 0.14);
  background: transparent; color: var(--muted); cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.pomo-gear:hover { color: var(--fg); background: rgba(255, 255, 255, 0.07); }
.pomo-gear svg { width: 17px; height: 17px; fill: currentColor; }
.pomo-chip:has(.preset.active) { background: var(--accent); border-color: transparent; }
.pomo-chip:has(.preset.active) .preset { color: #fff; }
.pomo-chip:has(.preset.active) .preset:hover,
.pomo-chip:has(.preset.active) .pomo-gear:hover { background: rgba(255, 255, 255, 0.12); }
.pomo-chip:has(.preset.active) .pomo-gear { color: #fff; border-left-color: rgba(255, 255, 255, 0.35); }

/* play/pause icon swap driven by body.running */
.ic-pause, .ic-stop { display: none; }
body.running .ic-play { display: none; }
body.running .ic-pause { display: block; }

/* When the alarm is ringing (finished), the primary button becomes a Stop button. */
body.finished .ic-play,
body.finished .ic-pause { display: none; }
body.finished .ic-stop { display: block; }
body.finished .btn-primary { background: #ff6b6b; color: #fff; }
body.finished .btn-primary:hover { background: #ff5252; }

/* ---- Per-run project picker (Pro) ---- */
.project-select {
  margin-top: 0.5rem; max-width: 70vw;
  /* Drop the classic native chevron for a custom rounded pill look. */
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  background-color: rgba(255, 255, 255, 0.06); color: var(--fg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b93a7' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 999px;
  padding: 0.42rem 1.95rem 0.42rem 0.95rem;
  font-size: 0.82rem; font-weight: 600; line-height: 1.2; cursor: pointer;
  transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}
.project-select:hover {
  background-color: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.24);
}
.project-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Chromium paints the open dropdown with the select's own colours, so with the
   translucent bg + muted text above the options were nearly unreadable. Give the
   popup options a solid, legible background/foreground. */
.project-select option {
  background: #141821;
  color: var(--fg);
}
body.immersive .project-select { opacity: 0; transition: opacity 0.4s; }
body.immersive.show-ui .project-select { opacity: 1; }

/* Project picker + background chooser sit on one centred row (both Pro-only). */
.project-row { display: flex; align-items: center; justify-content: center; gap: 0.5rem; }
.project-row .project-select { max-width: 60vw; }
.bg-btn {
  margin-top: 0.5rem; flex: none; display: grid; place-items: center;
  width: 2.1rem; height: 2.1rem; border-radius: 999px;
  background: rgba(255, 255, 255, 0.05); color: var(--muted);
  border: 1px solid rgba(255, 255, 255, 0.12); cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.bg-btn:hover { color: var(--fg); background: rgba(255, 255, 255, 0.09); }
.bg-btn svg { width: 58%; height: 58%; fill: currentColor; }
body.immersive .bg-btn { opacity: 0; transition: opacity 0.4s; }
body.immersive.show-ui .bg-btn { opacity: 1; }

/* Ticking toggle (free, shown for everyone). Shares the round bg-btn look; the
   "on" state glows in the accent colour. */
.tick-btn {
  margin-top: 0.5rem; flex: none; display: grid; place-items: center;
  width: 2.1rem; height: 2.1rem; border-radius: 999px;
  background: rgba(255, 255, 255, 0.05); color: var(--muted);
  border: 1px solid rgba(255, 255, 255, 0.12); cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.tick-btn:hover { color: var(--fg); background: rgba(255, 255, 255, 0.09); }
.tick-btn svg { width: 62%; height: 62%; fill: currentColor; }
.tick-btn.on {
  color: var(--accent); border-color: var(--accent);
  background: rgba(255, 255, 255, 0.09);
}
body.immersive .tick-btn { opacity: 0; transition: opacity 0.4s; }
body.immersive.show-ui .tick-btn { opacity: 1; }

/* Minimalistic "upgrade to Pro" pill — logged-in non-Pro users only. */
.pro-btn {
  margin-top: 0.5rem; flex: none;
  display: inline-flex; align-items: center; gap: 0.32rem;
  padding: 0.34rem 0.8rem 0.34rem 0.62rem; border-radius: 999px;
  font-size: 0.78rem; font-weight: 700; letter-spacing: 0.02em;
  text-decoration: none; white-space: nowrap;
  color: var(--accent); border: 1px solid var(--accent);
  background: rgba(79, 140, 255, 0.08);
  transition: background 0.15s, color 0.15s;
}
.pro-btn svg { width: 1.05em; height: 1.05em; flex: none; }
.pro-btn:hover { background: var(--accent); color: #fff; }
body.immersive .pro-btn { opacity: 0; transition: opacity 0.4s; }
body.immersive.show-ui .pro-btn { opacity: 1; }

/* ---- Brand footer ---- */
.brand {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  text-align: center;
  padding: 0.6rem 1rem max(0.6rem, env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: clamp(0.68rem, 2.3vw, 0.76rem);
  letter-spacing: 0.02em;
  line-height: 1.5;
  opacity: 0.6;
  transition: opacity 0.2s;
}
.brand:hover { opacity: 1; }
.brand a, .brand a:visited { color: inherit; text-decoration: none; white-space: nowrap; }
.brand a:hover { color: var(--fg); text-decoration: underline; }

/* ---- Cookie notice (informational only — strictly-necessary cookies, no consent gate) ---- */
.cookie-note {
  display: none;
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(0.7rem, env(safe-area-inset-bottom));
  z-index: 50;
  max-width: min(92vw, 640px);
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.7rem 0.6rem 1rem;
  background: rgba(20, 24, 33, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
  backdrop-filter: blur(6px);
}
.cookie-note.show { display: flex; }
.cookie-note a { color: var(--accent); text-decoration: none; white-space: nowrap; }
.cookie-note a:hover { text-decoration: underline; }
.cookie-note-ok {
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: var(--fg);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s;
}
.cookie-note-ok:hover { background: rgba(255, 255, 255, 0.12); }
/* Fade out with the rest of the UI while a countdown is running. */
body.immersive .cookie-note { opacity: 0; pointer-events: none; transition: opacity 0.4s; }

/* ---- Language switch (SK / EN) ---- */
.lang-switch { margin-left: 0.5rem; white-space: nowrap; }
.lang-switch a {
  color: var(--muted); text-decoration: none; padding: 0 0.25rem; font-weight: 600;
}
.lang-switch a:hover { color: var(--fg); }
.lang-switch a.on { color: var(--accent); }

/* Small SEO cross-links to the landing pages, under the homepage footer line. */
.home-landing-nav { display: block; margin-top: 0.35rem; font-size: 0.82rem; opacity: 0.85; }
.home-landing-nav a { margin: 0 0.1rem; }

/* ---- Shared card chrome (brand mark + footer), used by every page so the
   header/footer look identical on account, zaznam, admin, legal, etc. ---- */
.card-logo {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 1.2rem 0 0.4rem;
}
.card-logo img { width: 34px; height: 34px; }
.card-logo span { font-weight: 700; letter-spacing: 0.02em; font-size: 1.05rem; }

.card-footer { margin-top: 1.6rem; text-align: center; }
.card-footer a { color: var(--muted); font-size: 0.82rem; text-decoration: none; }
.card-footer a:hover { color: var(--fg); text-decoration: underline; }

/* ---- Top-right actions (share + account) ---- */
.top-actions {
  position: fixed;
  top: max(0.9rem, env(safe-area-inset-top));
  right: max(0.9rem, env(safe-area-inset-right));
  display: flex; align-items: center; gap: 0.5rem; z-index: 2;
}
.top-icon {
  width: 2.4rem; height: 2.4rem; display: grid; place-items: center;
  border: none; border-radius: 50%; cursor: pointer; text-decoration: none;
  color: var(--muted); background: rgba(255, 255, 255, 0.04);
  transition: color 0.15s, background 0.15s;
}
.top-icon:hover { color: var(--fg); background: rgba(255, 255, 255, 0.1); }
.top-icon svg { width: 55%; height: 55%; fill: currentColor; }
.share-hint {
  position: absolute; top: 100%; right: 0; margin-top: 0.45rem;
  background: rgba(20, 24, 34, 0.96); border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--accent); font-size: 0.78rem; font-weight: 600;
  padding: 0.3rem 0.6rem; border-radius: 8px; white-space: nowrap; pointer-events: none;
}
.share-hint:empty { display: none; }
body.immersive .top-actions { opacity: 0; transition: opacity 0.4s; }
body.immersive.show-ui .top-actions { opacity: 1; }

/* Darken custom background for legibility */
body.has-bg::before {
  content: "";
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 0;
  pointer-events: none;
}
body.has-bg .stage { position: relative; z-index: 1; }

/* ---- Final-minute warning (last 60 s of runs ≥3 min): recolour, no sound ---- */
body.warn .time { color: var(--warn); }
body.warn .ring-progress { stroke: var(--warn); }

/* ---- Finished state: flash ---- */
@keyframes flash {
  0%, 100% { background-color: var(--bg); }
  50% { background-color: #2a1416; }
}
body.finished .time { color: #ff6b6b; }
body.finished .ring-progress { stroke: #ff6b6b; }
body.finished { animation: flash 0.7s ease-in-out 4; }

/* ---- Big end-of-countdown message (classroom mode) ---- */
.end-msg {
  display: none;
  max-width: min(92vw, 900px);
  text-align: center;
  font-size: clamp(1.6rem, 7vw, 5rem);
  font-weight: 700;
  line-height: 1.1;
  color: var(--fg);
  overflow-wrap: break-word;
}
/* Shown only once the countdown reaches zero, and only when non-empty. */
body.finished .end-msg:not(:empty) { display: block; }

/* ---- Bigger end flash: full-viewport pulse, prominent in fullscreen ---- */
@keyframes flash-pulse {
  0%, 100% { opacity: 0; }
  25%, 75% { opacity: 0.5; }
}
.flash-overlay {
  position: fixed;
  inset: 0;
  z-index: 0;              /* behind .stage (z-index:1) so digits stay readable */
  background: #ff6b6b;
  opacity: 0;
  pointer-events: none;
}
/* Only escalate to the full-viewport pulse in fullscreen; windowed keeps the
   subtler body flash above. Reduced-motion (below) freezes this at opacity 0. */
body.finished.immersive .flash-overlay { animation: flash-pulse 0.7s ease-in-out 4; }

/* ---- Embed (iframe) view ---- */
body.embed .stage { padding: 0.8rem; gap: clamp(0.8rem, 4vh, 2.2rem); }
/* Pinned top-left so it never collides with the centered bottom controls
   (the fullscreen button used to overlap it in small iframes). Reads like a
   small header / logo and stays out of the way. */
.embed-brand {
  position: fixed;
  top: max(0.55rem, env(safe-area-inset-top));
  left: max(0.55rem, env(safe-area-inset-left));
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.28rem 0.55rem 0.28rem 0.4rem; border-radius: 999px;
  background: rgba(255, 255, 255, 0.07); color: var(--muted);
  font-size: 0.78rem; font-weight: 600; letter-spacing: 0.02em;
  text-decoration: none; z-index: 5; backdrop-filter: blur(4px);
  transition: color 0.15s, background 0.15s;
}
.embed-brand:hover { color: var(--fg); background: rgba(255, 255, 255, 0.14); }
.embed-brand img { width: 15px; height: 15px; }
body.embed.immersive .embed-brand { opacity: 0; transition: opacity 0.4s; }
body.embed.immersive.show-ui .embed-brand { opacity: 1; }

/* ---- "Embed on your site" dialog ---- */
.embed-dialog {
  /* margin:auto centers the modal in the viewport — the global `* {margin:0}`
     reset otherwise pins it to the top-left corner. */
  margin: auto;
  border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 14px;
  background: #141822; color: var(--fg); max-width: 480px; width: 90vw;
  padding: 1.2rem 1.3rem; box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  /* Never taller than the viewport (small landscape phones) — scroll inside. */
  max-height: calc(100dvh - 2rem); overflow-y: auto;
}
.embed-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.embed-dialog h2 { font-size: 1.1rem; margin: 0 0 0.5rem; }
.embed-dialog p { color: var(--muted); font-size: 0.9rem; margin: 0 0 0.7rem; line-height: 1.5; }
.embed-dialog textarea {
  width: 100%; background: var(--bg); color: var(--fg);
  border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 8px; padding: 0.6rem;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.82rem; resize: vertical;
}
.embed-dialog input[type="text"] {
  width: 100%; background: var(--bg); color: var(--fg);
  border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 8px; padding: 0.6rem;
  font-family: inherit; font-size: 1rem;
}
.embed-actions { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.8rem; flex-wrap: wrap; }
.embed-btn {
  padding: 0.5rem 0.95rem; border-radius: 8px; border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.05); color: var(--fg);
  font-size: 0.9rem; font-weight: 600; cursor: pointer;
}
.embed-btn:hover { background: rgba(255, 255, 255, 0.1); }
.embed-btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.embed-btn.primary:hover { background: #3f7bf0; }
.embed-hint { color: var(--accent); font-size: 0.85rem; }

/* Project-confirm dialog: its own select style (not .project-select, which the
   immersive rules would fade out). 1rem font keeps iOS from auto-zooming.
   Custom rounded look + chevron to match the homepage project pill. */
.project-confirm select,
.pomo-project select {
  width: 100%; margin-top: 0.2rem;
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  background-color: var(--bg); color: var(--fg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238b93a7' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.8rem center;
  border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 10px;
  padding: 0.6rem 2.2rem 0.6rem 0.8rem; font-size: 1rem; cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}
.project-confirm select:hover,
.pomo-project select:hover { border-color: rgba(255, 255, 255, 0.26); }
.project-confirm select:focus-visible,
.pomo-project select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.project-confirm select option,
.pomo-project select option { background: #141821; color: var(--fg); }
/* Inline project picker inside the Pomodoro dialog (Pro). */
.pomo-project { display: block; margin: 0 0 0.7rem; font-size: 0.9rem; color: var(--muted); }

/* ---- Timer-background chooser dialog (Pro) ----
   Self-contained here because the homepage loads only style.css (the account
   page has equivalents in account.css). */
.bg-dialog .upload { display: flex; gap: 0.6rem; align-items: center; }
.bg-dialog .file-label {
  flex: 1; border: 1px dashed rgba(255, 255, 255, 0.2); border-radius: 10px;
  padding: 0.75rem; text-align: center; color: var(--muted); cursor: pointer; font-size: 0.9rem;
}
.bg-dialog .file-label:hover { border-color: var(--accent); color: var(--fg); }
.bg-dialog .embed-btn:disabled { opacity: 0.5; cursor: default; }

.bg-dialog .gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; margin-top: 1rem; }
.bg-dialog .thumb {
  aspect-ratio: 1; border-radius: 10px; background-size: cover; background-position: center;
  cursor: pointer; border: 2px solid transparent; position: relative;
}
.bg-dialog .thumb.selected { border-color: var(--accent); }
.bg-dialog .thumb.contain {  /* project (SVG) watermarks: show the whole 16:9, don't crop */
  background-size: contain; background-repeat: no-repeat; background-color: #0b0d12;
}
.bg-dialog .thumb.none {
  background: rgba(0, 0, 0, 0.3); display: grid; place-items: center;
  color: var(--muted); font-size: 0.8rem;
}
.bg-dialog .thumb-del {
  position: absolute; top: 4px; right: 4px; width: 1.4rem; height: 1.4rem;
  border-radius: 50%; border: none; cursor: pointer; background: rgba(0, 0, 0, 0.55);
  color: #fff; font-size: 1rem; line-height: 1; display: grid; place-items: center;
  opacity: 0; transition: opacity 0.15s;
}
.bg-dialog .thumb:hover .thumb-del { opacity: 1; }
.bg-dialog .thumb-del:hover { background: #ff6b6b; }
@media (hover: none) { .bg-dialog .thumb-del { opacity: 1; } }

.bg-dialog .pexels-search { display: flex; gap: 0.5rem; margin-top: 0.9rem; }
.bg-dialog .pexels-search input {
  flex: 1; min-width: 0; background: var(--bg); color: var(--fg);
  border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 10px; padding: 0.6rem 0.8rem;
  font-size: 1rem;  /* ≥16px so iOS Safari doesn't auto-zoom on focus */
}
.bg-dialog .pexels-results { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; margin-top: 0.7rem; }
.bg-dialog .pexels-item {
  position: relative; aspect-ratio: 1; border-radius: 10px; cursor: pointer;
  background-size: cover; background-position: center; border: 2px solid transparent;
  transition: border-color 0.15s, transform 0.05s;
}
.bg-dialog .pexels-item:hover { border-color: var(--accent); }
.bg-dialog .pexels-item:active { transform: scale(0.97); }
.bg-dialog .pexels-item.adding { opacity: 0.5; pointer-events: none; }
.bg-dialog .pexels-by {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 0.45rem 0.4rem 0.25rem;
  font-size: 0.68rem; color: #e6e9f0; text-decoration: none;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  border-bottom-left-radius: 8px; border-bottom-right-radius: 8px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bg-dialog .pexels-by:hover { text-decoration: underline; }
.bg-dialog .pexels-more { margin-top: 0.7rem; text-align: center; }
.bg-dialog .pexels-credit { margin-top: 0.6rem; font-size: 0.78rem; color: var(--muted); }
.bg-dialog .pexels-credit a { color: var(--muted); }
.bg-dialog .pexels-credit a:hover { color: var(--fg); }
.bg-dialog .msg { margin-top: 1rem; font-size: 0.9rem; min-height: 1.2em; }
.bg-dialog .msg.error { color: #ff6b6b; }
.bg-dialog .msg.ok { color: #5fd38a; }

/* ---- Pomodoro settings dialog ---- */
.pomo-fields { display: flex; flex-direction: column; gap: 0.7rem; margin: 0.2rem 0 0.7rem; }
.pomo-fields label {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.8rem; color: var(--fg); font-size: 0.95rem;
}
.pomo-fields label > span:last-child { color: var(--muted); display: inline-flex; align-items: center; gap: 0.4rem; }
.pomo-fields input {
  width: 4.2rem; padding: 0.45rem 0.5rem; border-radius: 8px; text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.15); background: var(--bg); color: var(--fg);
  font-family: inherit; font-size: 1rem; font-weight: 600;
}
.pomo-preview { color: var(--accent) !important; font-size: 0.92rem !important; margin: 0 !important; }

/* Hide controls/brand/input in immersive fullscreen until pointer moves */
body.immersive .controls,
body.immersive .quickstart,
body.immersive .brand,
body.immersive .custom { opacity: 0; transition: opacity 0.4s; }
body.immersive.show-ui .controls,
body.immersive.show-ui .quickstart,
body.immersive.show-ui .brand,
body.immersive.show-ui .custom { opacity: 1; }

/* =====================================================================
   Responsive breakpoints (shared system across all pages):
   ≤900px tablet · ≤720px small tablet / large phone · ≤560/480px phone
   (pointer:coarse) touch devices · (max-height:460px) phone landscape
   ===================================================================== */

/* Touch devices: comfortable ≥44px tap targets (Apple/Android HIG). */
@media (pointer: coarse) {
  .top-icon { width: 2.75rem; height: 2.75rem; }
  .preset { padding: 0.55rem 1.05rem; }
  .pomo-gear { width: 2.6rem; }
  .cookie-note-ok { padding: 0.5rem 1rem; }
}

/* Phones: tuck the presets in, keep the cookie note off the footer. */
@media (max-width: 480px) {
  .presets { gap: 0.45rem; padding: 0 0.75rem; }
  .embed-dialog { width: calc(100vw - 1.6rem); padding: 1rem 1.05rem; }
  .cookie-note {
    flex-wrap: wrap; justify-content: flex-end;
    max-width: calc(100vw - 1.2rem); font-size: 0.78rem;
  }
}

/* Phone landscape / very short viewports: shrink the ring + controls so the
   timer, controls, presets and footer all fit without clipping (the body is
   overflow:hidden, so anything that doesn't fit would simply be cut off). */
@media (max-height: 460px) {
  .stage { gap: 0.55rem; padding-top: calc(env(safe-area-inset-top) + 0.4rem); }
  .timer { width: min(70vw, 52vh, 560px); }
  .btn-primary { width: 3.4rem; height: 3.4rem; }
  .btn-secondary { width: 2.6rem; height: 2.6rem; }
  .custom { height: 1.3rem; }
  .custom-input { font-size: 0.9rem; }
  .brand { padding-top: 0.25rem; padding-bottom: max(0.35rem, env(safe-area-inset-bottom)); }
}
/* Ultra-short (e.g. 320px-high embeds/landscape): drop the preset chips. */
@media (max-height: 350px) {
  .quickstart { display: none; }
}

/* Users who prefer reduced motion: kill decorative animation/transitions.
   (The finished state still signals via the red time + ring colour.) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
