:root {
  --bg: #f2f2f7;
  --bg-glow-1: rgba(120, 170, 255, 0.35);
  --bg-glow-2: rgba(255, 160, 200, 0.28);
  --bg-glow-3: rgba(140, 230, 200, 0.25);
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #ffffff;
  --surface-2: rgba(118, 118, 128, 0.12);
  --border: rgba(60, 60, 67, 0.12);
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #8e8e93;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-text: #ffffff;
  --danger: #ff3b30;
  --success: #34c759;
  --yellow: #c99700; --orange: #e67e00; --teal: #0a8f92;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.18);
  --radius: 18px;
  --radius-sm: 10px;
  /* Motion: Apple-like curves. Spring overshoots a little, ease-out settles softly. */
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-spring: cubic-bezier(.34, 1.36, .64, 1);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
  color-scheme: light dark;
}

/* Dark: chosen explicitly (data-theme="dark", set by js/theme.js) or by the system while the
   choice is "System" (no data-theme). Both rules carry the same tokens. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --bg-glow-1: rgba(40, 90, 200, 0.35);
    --bg-glow-2: rgba(160, 50, 120, 0.25);
    --bg-glow-3: rgba(20, 130, 110, 0.22);
    --surface: rgba(28, 28, 30, 0.72);
    --surface-solid: #1c1c1e;
    --surface-2: rgba(118, 118, 128, 0.24);
    --border: rgba(84, 84, 88, 0.45);
    --text: #f5f5f7;
    --text-2: #a1a1a6;
    --text-3: #8e8e93;
    --accent: #0a84ff;
    --accent-hover: #409cff;
    --danger: #ff453a;
    --success: #30d158;
    --yellow: #ffd60a; --orange: #ff9f0a; --teal: #64d2ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="dark"] {
  --bg: #000000;
  --bg-glow-1: rgba(40, 90, 200, 0.35);
  --bg-glow-2: rgba(160, 50, 120, 0.25);
  --bg-glow-3: rgba(20, 130, 110, 0.22);
  --surface: rgba(28, 28, 30, 0.72);
  --surface-solid: #1c1c1e;
  --surface-2: rgba(118, 118, 128, 0.24);
  --border: rgba(84, 84, 88, 0.45);
  --text: #f5f5f7;
  --text-2: #a1a1a6;
  --text-3: #8e8e93;
  --accent: #0a84ff;
  --accent-hover: #409cff;
  --danger: #ff453a;
  --success: #30d158;
  --yellow: #ffd60a; --orange: #ff9f0a; --teal: #64d2ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
}
/* Dusk: between light and dark. A mid-tone indigo slate with stronger, more colorful glows;
   glass surfaces are white at low opacity so the colors shine through. */
:root[data-theme="dusk"] {
  --bg: #363c70;
  --bg-glow-1: rgba(110, 140, 255, 0.7);
  --bg-glow-2: rgba(255, 105, 175, 0.55);
  --bg-glow-3: rgba(60, 215, 195, 0.5);
  --surface: rgba(255, 255, 255, 0.11);
  --surface-solid: #444b80;
  --surface-2: rgba(255, 255, 255, 0.14);
  --border: rgba(255, 255, 255, 0.16);
  --text: #f5f6fb;
  --text-2: #c5c9df;
  --text-3: #a3a8c4;
  --accent: #5e7dff;
  --accent-hover: #7590ff;
  --danger: #ff6b6b;
  --success: #4cd98a;
  --yellow: #ffd60a; --orange: #ffad33; --teal: #7ee0ff;
  --shadow: 0 1px 2px rgba(10, 12, 40, 0.25), 0 8px 24px rgba(10, 12, 40, 0.3);
  --shadow-lg: 0 24px 64px rgba(10, 12, 40, 0.45);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"], :root[data-theme="dusk"] { color-scheme: dark; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: "";
  position: fixed;
  inset: -20vmax;
  z-index: -1;
  background:
    radial-gradient(40vmax 40vmax at 15% 10%, var(--bg-glow-1), transparent 70%),
    radial-gradient(35vmax 35vmax at 90% 20%, var(--bg-glow-2), transparent 70%),
    radial-gradient(45vmax 45vmax at 60% 100%, var(--bg-glow-3), transparent 70%);
  filter: blur(20px);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.02em; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 18px;
  border: 0; border-radius: 980px;
  font: inherit; font-weight: 500;
  color: var(--text); background: var(--surface-2);
  cursor: pointer; transition: background .2s var(--ease-out), transform .25s var(--ease-spring), opacity .2s;
}
.btn:hover { background: color-mix(in srgb, var(--surface-2) 100%, var(--text) 6%); }
.btn:active { transform: scale(.96); transition-duration: .08s; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { color: var(--accent-text); background: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.large { min-height: 48px; font-size: 17px; width: 100%; }
.btn.small { min-height: 30px; padding: 0 12px; font-size: 13px; }
.btn.link { background: none; color: var(--accent); padding: 0 4px; min-height: 0; }
.btn.link:hover { text-decoration: underline; }
.btn svg { width: 18px; height: 18px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; color: var(--text-2); }
.input {
  width: 100%; min-height: 44px; padding: 10px 14px;
  font: inherit; color: var(--text);
  background: var(--surface-solid);
  border: 1px solid var(--border); border-radius: 12px;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 20%, transparent); }
.input.code { font-size: 28px; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }
.check { display: flex; align-items: center; gap: 10px; color: var(--text-2); cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 0 10px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }

/* ---------- Auth pages ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 400px; padding: 40px 32px 32px;
  background: var(--surface); backdrop-filter: blur(30px) saturate(1.6); -webkit-backdrop-filter: blur(30px) saturate(1.6);
  border: 1px solid var(--border); border-radius: 28px; box-shadow: var(--shadow-lg);
  text-align: center;
  animation: card-in .5s var(--ease-out) both;
}
@keyframes card-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }
.auth-card form, .auth-card .left { text-align: left; }
.auth-card h1 { font-size: 26px; margin: 18px 0 6px; }
.auth-card .sub { color: var(--text-2); margin: 0 0 26px; }
.divider { display: flex; align-items: center; gap: 12px; margin: 22px 0; color: var(--text-3); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.logo { width: 64px; height: 64px; margin: 0 auto; display: block; }
.footer-note { margin-top: 22px; font-size: 12px; color: var(--text-3); display: flex; gap: 6px; align-items: center; justify-content: center; }
.footer-note svg { width: 14px; height: 14px; }

.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 18px 0; padding: 16px; background: var(--surface-2); border-radius: 14px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 14px; text-align: center; user-select: all; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  height: 56px; padding: 0 max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 60%, transparent);
  backdrop-filter: blur(20px) saturate(1.8); -webkit-backdrop-filter: blur(20px) saturate(1.8);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 600; font-size: 17px; letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.brand img { width: 28px; height: 28px; }
.topbar .actions { display: flex; align-items: center; gap: 10px; }
.topbar .page-actions { display: flex; align-items: center; gap: 10px; }

.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
  display: grid; place-items: center; color: var(--text-2); background: none;
  transition: background .2s var(--ease-out), color .2s, transform .25s var(--ease-spring);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(.92); transition-duration: .08s; }
.icon-btn svg { width: 20px; height: 20px; }

/* Segmented control (Appearance: System / Light / Dusk / Dark), like the macOS/iOS picker. */
.segmented { display: inline-flex; padding: 2px; gap: 2px; border-radius: 9px; background: var(--surface-2); }
.segmented button {
  min-height: 28px; padding: 0 14px; border: 0; border-radius: 7px;
  font: inherit; font-size: 13px; font-weight: 500; color: var(--text); background: none; cursor: pointer;
  transition: background .2s var(--ease-out), box-shadow .2s;
}
.segmented button[aria-checked="true"] { background: var(--surface-solid); box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .04); }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
  display: grid; place-items: center; font-weight: 600; font-size: 14px; color: #fff;
  background: linear-gradient(135deg, #8e8e93, #636366);
  transition: transform .25s var(--ease-spring), box-shadow .2s;
}
.avatar:active { transform: scale(.92); transition-duration: .08s; }
.avatar[aria-expanded="true"] { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
.menu {
  position: absolute; right: 16px; top: 52px; min-width: 220px; padding: 6px;
  background: var(--surface); backdrop-filter: blur(30px) saturate(1.6); -webkit-backdrop-filter: blur(30px) saturate(1.6);
  border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg);
  /* Closed: invisible and shrunk towards the avatar. Opens with a light spring. */
  transform-origin: top right;
  opacity: 0; transform: scale(.92) translateY(-6px); visibility: hidden;
  transition: opacity .16s ease, transform .2s var(--ease-out), visibility 0s linear .2s;
}
.menu.open {
  opacity: 1; transform: none; visibility: visible;
  transition: opacity .18s ease, transform .32s var(--ease-spring), visibility 0s;
}
.menu .who { padding: 10px 12px 8px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.menu .who strong { display: block; }
.menu a, .menu button {
  display: block; width: 100%; padding: 9px 12px; border: 0; border-radius: 8px;
  font: inherit; text-align: left; color: var(--text); background: none; cursor: pointer;
}
.menu a, .menu button { transition: background .12s; }
.menu a:hover, .menu button:hover { background: var(--accent); color: var(--accent-text); text-decoration: none; }

/* ---------- Home ---------- */
.home { max-width: 1080px; margin: 0 auto; padding: 48px 24px 80px; container-type: inline-size; }
.greeting { text-align: center; margin-bottom: 40px; }
.greeting h1 { font-size: clamp(28px, 5vw, 40px); }
.greeting p { margin: 6px 0 0; color: var(--text-2); font-size: 17px; }

.grid {
  /* Square cells: as many columns of at least 160px as fit (130px on phones). The column count
     is set by container queries (below) instead of auto-fill, so widgets can span exactly two
     cells and --cell (the height of one row) is known to their contents. */
  --cols: 1; --gap: 20px;
  --cell: calc((100cqi - (var(--cols) - 1) * var(--gap)) / var(--cols));
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-auto-rows: var(--cell);
  /* Small tiles fill the gaps next to large widgets, like on the iPhone. */
  grid-auto-flow: row dense;
}
@container (min-width: 340px) { .grid { --cols: 2; } }
@container (min-width: 520px) { .grid { --cols: 3; } }
@container (min-width: 700px) { .grid { --cols: 4; } }
@container (min-width: 880px) { .grid { --cols: 5; } }
.tile {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  min-width: 0; min-height: 0; padding: 18px; border-radius: 24px;
  color: var(--text); text-align: center;
  background: var(--surface); backdrop-filter: blur(24px) saturate(1.6); -webkit-backdrop-filter: blur(24px) saturate(1.6);
  border: 1px solid var(--border); box-shadow: var(--shadow);
  transition: transform .35s var(--ease-spring), box-shadow .3s var(--ease-out);
}
a.tile:hover { text-decoration: none; transform: translateY(-3px) scale(1.02); box-shadow: var(--shadow-lg); }
a.tile:active { transform: scale(.97); transition-duration: .1s; }

/* First appearance: tiles rise in one after another (home.js sets --i). */
.grid.enter > .tile { animation: tile-in .55s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 35ms); }
@keyframes tile-in { from { opacity: 0; transform: translateY(14px) scale(.96); } }
.greeting { animation: fade-up .5s var(--ease-out) both; }
@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } }
.tile .name { font-weight: 600; font-size: 15px; line-height: 1.2; }
.tile .desc { font-size: 12px; color: var(--text-2); line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile .lock { position: absolute; top: 12px; right: 12px; width: 14px; height: 14px; color: var(--text-3); }

.icon {
  width: 72px; height: 72px; flex: none; border-radius: 22.5%;
  display: grid; place-items: center; overflow: hidden;
  font-size: 38px; font-weight: 600; color: #fff;
  box-shadow: inset 0 0 0 .5px rgba(255,255,255,.25), 0 4px 12px rgba(0,0,0,.15);
}
.icon img { width: 100%; height: 100%; object-fit: cover; }
.icon.letter { font-size: 32px; }
.c-blue { background: linear-gradient(160deg, #5ac8fa, #007aff); }
.c-indigo { background: linear-gradient(160deg, #7d7aff, #3634a3); }
.c-purple { background: linear-gradient(160deg, #da8fff, #8944ab); }
.c-pink { background: linear-gradient(160deg, #ff8cc6, #ff2d55); }
.c-red { background: linear-gradient(160deg, #ff8a80, #d70015); }
.c-orange { background: linear-gradient(160deg, #ffc46b, #ff9500); }
.c-yellow { background: linear-gradient(160deg, #ffe066, #f5b800); }
.c-green { background: linear-gradient(160deg, #7ee08a, #28a745); }
.c-teal { background: linear-gradient(160deg, #6ee7e0, #0a9396); }
.c-graphite { background: linear-gradient(160deg, #a1a1a6, #48484a); }

/* Edit mode */
.editing .tile { cursor: grab; animation: jiggle .3s ease-in-out infinite alternate; }
.editing .tile:nth-child(2n) { animation-delay: -.15s; }
.editing .tile.placeholder { opacity: .25; animation: none; }
/* The tile under the pointer while dragging (a copy that follows it). */
.drag-ghost {
  position: fixed; left: 0; top: 0; z-index: 50; margin: 0; pointer-events: none;
  box-shadow: var(--shadow-lg); animation: none !important; transition: none; will-change: transform;
}
/* Touch and hold: no text selection or link preview popping up instead. */
.grid .tile { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.grid .tile input, .grid .tile textarea { -webkit-user-select: text; user-select: text; }
@keyframes jiggle { from { transform: rotate(-.6deg); } to { transform: rotate(.6deg); } }
@media (prefers-reduced-motion: reduce) { .editing .tile { animation: none; } }
.tile .badge {
  position: absolute; top: -8px; width: 28px; height: 28px; border-radius: 50%; border: 0;
  display: grid; place-items: center; cursor: pointer; color: #fff; font-size: 18px; line-height: 1;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.tile .badge.remove { left: -8px; background: #8e8e93; }
.tile .badge.edit { right: -8px; background: var(--accent); }
.tile .badge svg { width: 14px; height: 14px; }
.tile.add {
  border: 2px dashed var(--border); background: transparent; backdrop-filter: none; box-shadow: none;
  color: var(--text-2); cursor: pointer; font: inherit; animation: none !important;
}
.tile.add:hover { color: var(--accent); border-color: var(--accent); }
.tile.add .plus { font-size: 40px; font-weight: 300; line-height: 1; }

.empty { text-align: center; padding: 60px 20px; color: var(--text-2); }
.empty .icon { margin: 0 auto 16px; }

/* ---------- Widgets ---------- */
/* Sizes as on the iPhone: small = 1 cell, medium = 2 × 1, large = 2 × 2. */
.tile.w-medium { grid-column: span 2; }
.tile.w-large { grid-column: span 2; grid-row: span 2; }
.tile.widget { padding: 0; align-items: stretch; justify-content: stretch; gap: 0; text-align: left; }
.editing .tile.widget { animation-name: jiggle-wide; }
@keyframes jiggle-wide { from { transform: rotate(-.25deg); } to { transform: rotate(.25deg); } }
.wbody {
  flex: 1; min-height: 0; min-width: 0; display: flex; flex-direction: column;
  padding: 16px; overflow: hidden; border-radius: inherit; color: var(--text); font-size: 14px;
}
a.wbody:hover { text-decoration: none; }
.whead { display: flex; align-items: center; gap: 6px; min-height: 20px; font-size: 13px; font-weight: 600; flex: none; }
.whead svg { width: 16px; height: 16px; flex: none; }
.wtitle { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.tone-accent, .tone-blue { color: var(--accent); }
.tone-yellow { color: var(--yellow); }
.tone-orange { color: var(--orange); }
.tone-teal { color: var(--teal); }
.tone-green { color: var(--success); }
.tone-red { color: var(--danger); }
.empty-hint { color: var(--text-2); font-size: 13px; margin: 8px 0 0; }
.wbody .split { display: flex; gap: 14px; flex: 1; min-height: 0; }

/* Clock */
.clock { padding: 12px; }
.clock.analog { flex-direction: row; justify-content: space-around; align-items: center; gap: 8px; }
.clock .zone { display: flex; flex-direction: column; align-items: center; min-width: 0; flex: 1; }
.clock .face { width: 100%; max-width: calc(var(--cell) - 62px); aspect-ratio: 1; margin-bottom: 4px; }
.clock.n3 .face, .clock.n4 .face { max-width: calc(var(--cell) - 68px); }
.clock .city { font-size: 13px; font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clock .rel { font-size: 11px; color: var(--text-2); white-space: nowrap; }
.face .dial { fill: #fff; stroke: rgba(60, 60, 67, .18); stroke-width: .6; }
.face .num { fill: #1d1d1f; font: 600 11px var(--font); }
.face .hand { stroke: #1d1d1f; stroke-linecap: round; }
.face .hand.hour { stroke-width: 4; }
.face .hand.minute { stroke-width: 3; }
.face .hand.second { stroke: #ff9500; stroke-width: 1.2; }
.face .pin { fill: #1d1d1f; }
.face .pin-inner { fill: #ff9500; }
.face.night .dial { fill: #1c1c1e; stroke: rgba(255, 255, 255, .14); }
.face.night .num { fill: #f5f5f7; }
.face.night .hand:not(.second), .face.night .pin { stroke: #f5f5f7; fill: #f5f5f7; }
.clock.digital { justify-content: center; gap: 8px; padding: 16px; }
.clock.digital .zone { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.clock.digital .where { min-width: 0; }
.clock.digital .zone .city, .clock.digital .zone .rel { text-align: left; }
.clock.digital .time { font-size: 26px; font-weight: 500; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
/* Medium, several places: side by side, the time on top. */
.w-medium .clock.digital:not(.n1) { flex-direction: row; align-items: center; justify-content: space-around; gap: 8px; }
.w-medium .clock.digital:not(.n1) .zone { flex: 1; min-width: 0; flex-direction: column-reverse; align-items: flex-start; gap: 2px; }
.w-medium .clock.digital:not(.n1) .where { max-width: 100%; }
.w-medium .clock.digital.n3 .time, .w-medium .clock.digital.n4 .time { font-size: clamp(16px, calc(var(--cell) / 8), 24px); }
.w-small .clock.digital { justify-content: flex-end; }
.w-small .clock.digital .zone { flex-direction: column-reverse; align-items: flex-start; gap: 2px; }
.w-small .clock.digital .time { font-size: calc(var(--cell) / 4); line-height: 1; }

/* Calendar */
.calendar .summary { display: flex; flex-direction: column; min-width: 0; height: 100%; }
.calendar .weekday { color: var(--danger); font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: .02em; }
.calendar .big { font-size: calc(var(--cell) / 3.6); font-weight: 400; line-height: 1.05; letter-spacing: -0.03em; }
.calendar .sub { font-size: 12px; color: var(--text-2); }
.calendar .next { margin-top: auto; display: flex; align-items: center; gap: 6px; font-size: 12px; line-height: 1.25; }
.calendar .next span:last-child { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; }
.calendar .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--danger); flex: none; }
.w-medium .calendar .summary { flex: 0 0 38%; }
.calendar .month {
  flex: 1; display: grid; grid-template-columns: repeat(7, 1fr); align-content: space-between;
  font-size: max(8px, calc(var(--cell) / 17)); text-align: center; font-variant-numeric: tabular-nums;
}
.calendar .month.weeks { grid-template-columns: auto repeat(7, 1fr); font-size: max(10px, calc(var(--cell) / 13)); align-content: start; row-gap: 2px; margin: 10px 0; }
.calendar .dow { color: var(--text-3); font-weight: 600; }
.calendar .dow.weekend, .calendar .day.weekend { color: var(--text-2); }
.calendar .day { display: grid; place-items: center; width: 2em; height: 2em; margin: auto; border-radius: 50%; }
.calendar .day.holiday { color: var(--danger); font-weight: 600; }
.calendar .day.today { background: var(--danger); color: #fff; font-weight: 600; }
/* A day with entries from an app (events, due tasks): a small dot underneath the number */
.calendar .day.busy { position: relative; }
.calendar .day.busy::after { content: ""; position: absolute; left: 50%; bottom: 1px; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: var(--accent); }
.calendar .day.busy.today::after { background: #fff; }
.calendar .dot.k-event { background: var(--accent); }
.calendar .dot.k-task { background: var(--text-3); }
.calendar .holidays a.hname { color: inherit; text-decoration: none; }
.calendar .holidays a.hname:hover { text-decoration: underline; }
.calendar .wk { display: grid; place-items: center; padding-right: 6px; color: var(--text-3); font-size: .8em; }
.calendar .month-title { display: flex; align-items: baseline; gap: 8px; }
.calendar .month-title .right { margin-left: auto; }
.calendar .holidays { list-style: none; margin: auto 0 0; padding: 8px 0 0; border-top: 1px solid var(--border); display: grid; gap: 3px; font-size: 12px; }
.calendar .holidays li { display: flex; align-items: center; gap: 8px; }
.calendar .holidays .hname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.calendar .holidays .when { color: var(--text-2); }

/* Countdown: colored like an app icon (classes c-<color>). */
.countdown { color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, .18); }
.countdown .top { display: flex; align-items: center; gap: 6px; font-weight: 600; min-width: 0; }
.countdown .top .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.countdown .emoji { font-size: 20px; line-height: 1; text-shadow: none; }
.countdown .count { margin-top: auto; display: flex; flex-direction: column; }
.countdown .num { font-size: calc(var(--cell) / 3.4); font-weight: 700; line-height: 1; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.countdown .num.word { font-size: calc(var(--cell) / 5); }
.countdown .unit { font-size: 13px; opacity: .92; }
.countdown .when { font-size: 12px; opacity: .88; margin-top: 4px; }
.countdown .split { align-items: flex-end; }
.countdown .side { margin-left: auto; text-align: right; font-size: 13px; }
.countdown .side .when { font-size: 13px; margin: 0; }
.countdown .detail { opacity: .88; font-size: 12px; }

/* Notes */
.notes .note-text {
  flex: 1; width: 100%; min-height: 0; margin-top: 6px; padding: 0; resize: none;
  border: 0; outline: none; background: transparent; color: var(--text); font: inherit; font-size: 14px; line-height: 1.45;
}
.notes .note-text::placeholder { color: var(--text-3); }

/* To-do */
.todo .count { font-size: 20px; font-weight: 600; color: var(--accent); line-height: 1; }
.todo .clear { border: 0; padding: 0 4px; background: none; color: var(--accent); font: inherit; font-size: 12px; font-weight: 500; cursor: pointer; }
.todo .items { list-style: none; margin: 8px 0 0; padding: 0; flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: 2px; }
.todo .items li { display: flex; align-items: center; gap: 8px; min-height: 26px; }
.todo .items li.empty-hint { margin: 0; }
.todo .check {
  width: 19px; height: 19px; flex: none; padding: 0; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center; border: 1.5px solid var(--text-3); background: none;
  transition: background .15s, border-color .15s, transform .25s var(--ease-spring);
}
.todo .check:active { transform: scale(.85); }
.todo .done .check { background: var(--accent); border-color: var(--accent); }
.todo .done .check::after { content: ""; width: 8px; height: 4px; border: solid #fff; border-width: 0 0 2px 2px; transform: translateY(-1px) rotate(-45deg); }
.todo .text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.todo .done .text { color: var(--text-3); text-decoration: line-through; }
/* Kept in an app: the text opens the task there; overdue ones are red */
.todo a.text { color: inherit; text-decoration: none; }
.todo a.text:hover { text-decoration: underline; }
.todo a.text.overdue { color: var(--danger); }
.notes .note-open { margin-left: auto; font-size: 12px; font-weight: 500; color: var(--accent); text-decoration: none; }
.todo .add-input {
  flex: none; margin-top: 6px; padding: 8px 0 0; border: 0; border-top: 1px solid var(--border); border-radius: 0;
  outline: none; background: transparent; color: var(--text); font: inherit; font-size: 14px;
}
.todo .add-input::placeholder { color: var(--text-3); }

/* Links */
.links .link-items { flex: 1; min-height: 0; margin-top: 8px; }
.links.as-grid .link-items { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-content: space-evenly; gap: 6px; }
.w-medium .links.as-grid .link-items { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.links .link { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; color: var(--text); font-size: 11px; border-radius: 10px; }
.links .link:hover { text-decoration: none; }
.links .link:hover .lname { color: var(--accent); }
.links .glyph {
  width: clamp(28px, calc(var(--cell) * .24), 44px); aspect-ratio: 1; flex: none; border-radius: 22.5%;
  display: grid; place-items: center; color: #fff; font-weight: 600; font-size: clamp(14px, calc(var(--cell) * .11), 20px);
}
.links .label { display: flex; flex-direction: column; min-width: 0; max-width: 100%; }
.links .lname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.links.as-list .link-items { display: flex; flex-direction: column; gap: 6px; overflow: auto; }
.links.as-list .link { flex-direction: row; gap: 12px; font-size: 14px; }
.links.as-list .glyph { width: 34px; font-size: 16px; }
.links .host { color: var(--text-2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Security */
.security .lead { margin-top: auto; min-width: 0; }
.security .status { font-size: 19px; font-weight: 600; line-height: 1.2; }
.security .sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.w-medium .security .lead { flex: 1; }
.security .stats { flex: 1.3; display: grid; align-content: end; gap: 1px; font-size: 12px; }
.security .stat { display: flex; justify-content: space-between; gap: 10px; }
.security .stat span { color: var(--text-2); white-space: nowrap; }
.security .stat strong { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* App widget (data from an app's /api/widget) */
.whead .icon.mini { width: 18px; height: 18px; border-radius: 5px; font-size: 11px; box-shadow: none; }
.whead .icon.mini.letter { font-size: 10px; }
a.whead { color: var(--text); }
a.whead:hover { text-decoration: none; }
.appfeed .headline { display: flex; flex-direction: column; min-width: 0; }
.appfeed .headline .value { font-size: calc(var(--cell) / 4); font-weight: 600; line-height: 1.05; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.appfeed .headline .label { font-size: 12px; color: var(--text-2); }
.tone-danger { color: var(--danger); }
.tone-warn { color: var(--orange); }
.tone-info { color: var(--accent); }
.tone-good { color: var(--success); }
.fdot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: currentColor; margin-top: .45em; }
.appfeed .fsmall { flex: 1; display: flex; flex-direction: column; min-height: 0; color: var(--text); }
.appfeed .fsmall:hover { text-decoration: none; }
.appfeed .fsmall .headline { margin-top: auto; }
.appfeed .fline { display: flex; gap: 6px; margin-top: 6px; font-size: 12px; line-height: 1.3; }
.appfeed .fline span:last-child { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; }
.appfeed .split { margin-top: 8px; }
.appfeed .fleft { flex: 0 0 36%; min-width: 0; display: flex; flex-direction: column; justify-content: space-between; }
.appfeed .fstats { display: grid; gap: 2px; font-size: 12px; }
.appfeed .fstat { display: flex; justify-content: space-between; gap: 8px; min-width: 0; }
.appfeed .fstat span { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appfeed .fstat strong { font-weight: 600; white-space: nowrap; }
.w-medium .appfeed .fstat { flex-direction: column; gap: 0; }
.appfeed .fitems { flex: 1; min-width: 0; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: 4px; }
.appfeed .fitem { display: flex; gap: 8px; min-width: 0; color: var(--text); font-size: 13px; line-height: 1.3; padding: 3px 4px; margin: 0 -4px; border-radius: 8px; }
a.fitem:hover { text-decoration: none; background: var(--surface-2); }
.appfeed .ftext { display: flex; flex-direction: column; min-width: 0; }
.appfeed .ftitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.appfeed .fdetail { color: var(--text-2); font-size: 12px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; }
.appfeed .ftop { display: flex; gap: 16px; align-items: flex-end; margin: 8px 0 10px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.appfeed .ftop .headline { flex: 0 0 auto; }
.appfeed .ftop .fstats { flex: 1; grid-template-columns: 1fr 1fr; column-gap: 14px; }
.appfeed .ftop .fstat { flex-direction: column; gap: 0; }

/* Weather: the sky as background (sky-<day|night>-<clear|cloudy|fog|rain|snow|storm>). */
.weather { color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, .15); gap: 2px; }
.sky-day-clear { background: linear-gradient(180deg, #2f7fd6, #63a9ef); }
.sky-day-cloudy { background: linear-gradient(180deg, #5f7f9f, #91a9c1); }
.sky-day-fog { background: linear-gradient(180deg, #7f8b97, #aab4be); }
.sky-day-rain { background: linear-gradient(180deg, #43566c, #6d8096); }
.sky-day-snow { background: linear-gradient(180deg, #7896b5, #b4c6d8); }
.sky-day-storm { background: linear-gradient(180deg, #33384d, #5a5f78); }
.sky-night-clear { background: linear-gradient(180deg, #0b1633, #283766); }
.sky-night-cloudy, .sky-night-fog { background: linear-gradient(180deg, #1f2733, #444f5e); }
.sky-night-rain, .sky-night-storm { background: linear-gradient(180deg, #181f2b, #38445a); }
.sky-night-snow { background: linear-gradient(180deg, #27324a, #55657f); }
.weather .place { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.weather .temp { font-size: calc(var(--cell) / 3.6); font-weight: 300; line-height: 1; letter-spacing: -0.03em; }
.weather .summary { margin-top: auto; display: flex; flex-wrap: wrap; align-items: center; column-gap: 6px; font-size: 13px; font-weight: 500; }
.weather .summary .sym { font-size: 18px; text-shadow: none; }
.weather .summary .hl { flex-basis: 100%; font-weight: 500; opacity: .95; }
.weather .note { margin: auto 0 0; font-size: 13px; opacity: .9; }
.weather .top { display: flex; gap: 12px; }
.weather .top .now { flex: 1; min-width: 0; }
.weather .top .side { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.weather .top .summary { justify-content: flex-end; margin-top: 4px; }
.weather .top .summary .hl { text-align: right; }
.weather .extra { font-size: 12px; opacity: .85; margin-top: auto; }
.weather .hours { margin-top: auto; display: grid; grid-template-columns: repeat(6, 1fr); text-align: center; font-size: 13px; font-weight: 500; }
.weather .hour { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.weather .hour .label { font-size: 12px; opacity: .85; }
.weather .hour .sym { font-size: 18px; text-shadow: none; line-height: 1.2; }
.w-large .weather .hours { margin: 14px 0 10px; padding-bottom: 10px; border-bottom: 1px solid rgba(255, 255, 255, .25); }
.weather .days { display: grid; gap: 2px; font-size: 14px; font-weight: 500; flex: 1; align-content: space-evenly; }
.weather .day { display: grid; grid-template-columns: 3.4em 1.6em 2.6em 2.4em 1fr 2.4em; align-items: center; gap: 6px; }
.weather .day .sym { text-shadow: none; }
.weather .day .rain { font-size: 11px; color: #bfe3ff; }
.weather .day .min { opacity: .75; text-align: right; }
.weather .bar { position: relative; height: 4px; border-radius: 2px; background: rgba(0, 0, 0, .18); }
.weather .bar .fill { position: absolute; top: 0; bottom: 0; left: var(--from); right: calc(100% - var(--to)); border-radius: 2px; background: linear-gradient(90deg, #8fd3ff, #ffd36b, #ff9a5a); }

/* Exchange rates */
.rates .asof { font-size: 11px; font-weight: 500; color: var(--text-3); white-space: nowrap; }
.rates .rate-list { flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: space-evenly; margin-top: 4px; }
.rates .rate { display: flex; align-items: center; gap: 10px; min-width: 0; }
.rates .code { font-weight: 600; font-size: 14px; width: 2.6em; flex: none; }
.rates .cname { flex: 1; min-width: 0; font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rates .spark { width: 64px; height: 22px; flex: none; }
.rates .spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-linejoin: round; }
.rates .value { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; font-variant-numeric: tabular-nums; }
.rates .value strong { font-weight: 600; font-size: 14px; }
.rates .value small { font-size: 11px; color: var(--text-2); white-space: nowrap; }
.rates .value small.up { color: var(--success); }
.rates .value small.down { color: var(--danger); }
.w-small .rates .rate { justify-content: space-between; }
.currency-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (max-width: 480px) { .currency-grid { grid-template-columns: repeat(2, 1fr); } }

/* News */
.news .asof { font-size: 11px; color: var(--text-3); font-weight: 500; }
.news .headlines { flex: 1; min-height: 0; display: flex; flex-direction: column; margin-top: 6px; gap: 2px; overflow: hidden; }
.news .headline { display: flex; flex-direction: column; padding: 4px 6px; margin: 0 -6px; border-radius: 8px; color: var(--text); }
.news .headline:hover { text-decoration: none; background: var(--surface-2); }
.news .htitle { font-size: 14px; font-weight: 500; line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; }
.w-medium .news .htitle { -webkit-line-clamp: 1; line-clamp: 1; }
.w-small .news .headline { flex: 1; justify-content: flex-end; }
.w-small .news .htitle { font-size: 15px; font-weight: 600; -webkit-line-clamp: 4; line-clamp: 4; }
.news .htime { font-size: 11px; color: var(--text-3); }
.w-large .news .headline + .headline { border-top: 1px solid var(--border); border-radius: 0; }

/* Nextcloud */
.nextcloud .nc-items { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 2px; margin-top: 6px; overflow: hidden; }
.nextcloud .nc-item { display: flex; flex-direction: column; min-width: 0; padding: 4px 6px 4px 10px; margin: 0 -6px; border-radius: 8px; color: var(--text); position: relative; }
.nextcloud .nc-item::before { content: ""; position: absolute; left: 0; top: 7px; bottom: 7px; width: 3px; border-radius: 2px; background: var(--accent); }
a.nc-item:hover { text-decoration: none; background: var(--surface-2); }
.nextcloud .nc-title { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nextcloud .nc-sub { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-medium .nextcloud .nc-item { flex-direction: row; align-items: baseline; gap: 10px; }
.w-medium .nextcloud .nc-title { flex: 1; }
.w-medium .nextcloud .nc-sub { flex: none; max-width: 45%; }
.nc-account { justify-content: space-between; margin-bottom: 12px; }
.nc-settings .btn.primary { margin-top: 4px; }

/* Smart Stack: widgets side by side, snapping one at a time; dots show where you are. */
.tile.stack { overflow: hidden; }
.stack-pages {
  flex: 1; min-height: 0; display: flex; overflow-x: auto; overflow-y: hidden; border-radius: inherit;
  scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior-x: contain;
}
.stack-pages::-webkit-scrollbar { display: none; }
.stack-page { flex: 0 0 100%; min-width: 0; display: flex; scroll-snap-align: start; scroll-snap-stop: always; }
.stack-page > .wbody { border-radius: 0; }
.stack-dots { position: absolute; left: 50%; bottom: 5px; transform: translateX(-50%); display: flex; gap: 5px; padding: 3px 6px; border-radius: 980px; }
.stack-dots .sdot { width: 6px; height: 6px; padding: 0; border: 0; border-radius: 50%; cursor: pointer; background: color-mix(in srgb, var(--text) 25%, transparent); transition: background .2s, transform .2s; }
.stack-dots .sdot[aria-selected="true"] { background: color-mix(in srgb, var(--text) 70%, transparent); transform: scale(1.15); }
/* Larger tap targets for the dots on touch screens. */
@media (pointer: coarse) { .stack-dots { gap: 2px; } .stack-dots .sdot { width: 14px; height: 14px; background-clip: content-box; padding: 4px; } }
.stack-list { margin-bottom: 10px; }
.stack-member { gap: 8px; padding: 8px 10px; min-height: 48px; }
.stack-member .glyph { width: 30px; height: 30px; border-radius: 8px; }
.stack-member .glyph svg { width: 17px; height: 17px; }
.stack-member .icon-btn { width: 30px; height: 30px; font-size: 15px; }
.stack-member .icon-btn:disabled { opacity: .3; cursor: default; }
.stack-add { gap: 8px; }
.stack-add .input { flex: 1; min-width: 0; }

/* Phones: cells are smaller, so medium widgets show one row less. */
@media (max-width: 560px) {
  .w-medium .rates .rate:nth-child(n+4), .w-medium .news .headline:nth-child(n+3) { display: none; }
}

/* Place search in the weather settings */
.place-chosen { font-weight: 600; padding: 2px 0 4px; }
.place-results { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.place-option { display: flex; flex-direction: column; align-items: flex-start; padding: 8px 10px; border: 0; border-radius: 10px; background: var(--surface-2); color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.place-option:hover { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.place-option small { color: var(--text-2); }

/* "Add Widget" dialog: gallery, then settings with a live preview. */
dialog.wide { width: min(560px, calc(100vw - 32px)); }
.gallery { display: flex; flex-direction: column; gap: 2px; margin: 0 -10px; }
.gallery-item {
  display: flex; align-items: center; gap: 14px; padding: 10px; border: 0; border-radius: 12px;
  background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; transition: background .12s;
}
.gallery-item:hover { background: var(--surface-2); }
.gallery-item .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.gallery-item small { color: var(--text-2); font-size: 13px; }
.gallery-item > svg { width: 16px; height: 16px; color: var(--text-3); flex: none; }
.glyph { width: 40px; height: 40px; flex: none; border-radius: 10px; display: grid; place-items: center; color: #fff; }
.glyph svg { width: 22px; height: 22px; }
.widget-preview {
  --cell: 150px; --gap: 16px;
  display: flex; justify-content: center; align-items: center; padding: 20px; margin-bottom: 16px;
  border-radius: 18px; background: var(--bg); overflow: hidden;
}
.widget-preview .tile { flex: none; width: var(--cell); height: var(--cell); }
.widget-preview .tile.w-medium, .widget-preview .tile.w-large { width: calc(2 * var(--cell) + var(--gap)); }
.widget-preview .tile.w-large { height: calc(2 * var(--cell) + var(--gap)); }
.field small { font-size: 12px; }
.link-row { display: grid; grid-template-columns: 1fr 1.6fr auto; gap: 8px; align-items: center; }
.link-rows { display: flex; flex-direction: column; gap: 8px; }
@media (max-width: 420px) {
  .widget-preview { --cell: 132px; --gap: 12px; padding: 14px; }
}

/* ---------- Dialog ---------- */
dialog {
  width: min(480px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0;
  color: var(--text); background: var(--surface-solid);
  border: 1px solid var(--border); border-radius: 22px; box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(0,0,0,.35); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }

/* Dialogs grow in like a macOS sheet and fade out when closed. Browsers without
   @starting-style / allow-discrete simply show and hide them as before. */
dialog {
  opacity: 0; transform: scale(.94) translateY(10px);
  transition: opacity .2s ease, transform .3s var(--ease-out),
    overlay .3s allow-discrete, display .3s allow-discrete;
}
dialog[open] { opacity: 1; transform: none; transition: opacity .22s ease, transform .42s var(--ease-spring), overlay .3s allow-discrete, display .3s allow-discrete; }
@starting-style { dialog[open] { opacity: 0; transform: scale(.94) translateY(10px); } }
dialog::backdrop { opacity: 0; transition: opacity .25s ease, overlay .3s allow-discrete, display .3s allow-discrete; }
dialog[open]::backdrop { opacity: 1; }
@starting-style { dialog[open]::backdrop { opacity: 0; } }
dialog form { padding: 24px; }
dialog h2 { font-size: 20px; margin-bottom: 18px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.dialog-actions .spacer { flex: 1; }
.icon-editor { display: flex; gap: 18px; align-items: center; margin-bottom: 16px; }
.icon-editor .controls { flex: 1; display: flex; flex-direction: column; gap: 10px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 24px; height: 24px; border-radius: 50%; border: 0; cursor: pointer; padding: 0; }
.swatch[aria-checked="true"] { box-shadow: 0 0 0 2px var(--surface-solid), 0 0 0 4px var(--accent); }
.row { display: flex; gap: 10px; align-items: center; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.toggle-row small { display: block; color: var(--text-2); }
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 31px; background: var(--surface-2); transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: transform .35s var(--ease-spring); }
.switch input:checked + span { background: var(--success); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); }

/* ---------- Settings ---------- */
.settings { max-width: 720px; margin: 0 auto; padding: 32px 20px 80px; }
.settings > h1 { font-size: 32px; margin-bottom: 4px; }
.settings > p { margin: 0 0 28px; color: var(--text-2); }
.group { margin-bottom: 28px; }
.group > h2 { font-size: 13px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); margin: 0 0 8px 16px; }
.group > .note { font-size: 13px; color: var(--text-2); margin: 8px 16px 0; }
.settings .group { transition: opacity .35s var(--ease-out), transform .45s var(--ease-out); }
.settings:not(.ready) .group { opacity: 0; transform: translateY(8px); }
.settings.ready .group:nth-of-type(2) { transition-delay: 30ms; }
.settings.ready .group:nth-of-type(3) { transition-delay: 60ms; }
.settings.ready .group:nth-of-type(4) { transition-delay: 90ms; }
.settings.ready .group:nth-of-type(n+5) { transition-delay: 120ms; }
.card { background: var(--surface); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.item { display: flex; align-items: center; gap: 14px; padding: 14px 16px; min-height: 56px; }
.item + .item { border-top: 1px solid var(--border); }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.item .meta { font-size: 13px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; }
.item .glyph { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; flex: none; color: #fff; }
.item .glyph svg { width: 18px; height: 18px; }
/* Last row of a shortened list: link to the full list. */
.item.more { color: var(--accent); font-weight: 500; min-height: 48px; }
.item.more:hover { text-decoration: none; background: var(--surface-2); }
.item.more svg { width: 16px; height: 16px; flex: none; color: var(--text-3); }
/* Back link above the title of a sub-page (like a navigation bar's back button). */
.settings > .back { display: inline-flex; align-items: center; gap: 2px; margin: 0 0 10px -4px; font-size: 15px; }
.settings > .back::before { content: ""; width: 18px; height: 18px; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 6l-6 6 6 6'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 6l-6 6 6 6'/%3E%3C/svg%3E") center / contain no-repeat; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 980px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.pill.on { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }
.qr { display: block; margin: 0 auto 12px; border-radius: 12px; background: #fff; padding: 8px; }
.secret { font-family: ui-monospace, Menlo, monospace; font-size: 13px; word-break: break-all; text-align: center; color: var(--text-2); }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px); opacity: 0;
  padding: 12px 20px; border-radius: 980px; background: var(--text); color: var(--bg);
  font-weight: 500; box-shadow: var(--shadow-lg); transition: opacity .25s ease, transform .4s var(--ease-spring); pointer-events: none; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 560px) {
  .grid { --gap: 14px; }
  @container (min-width: 274px) { .grid { --cols: 2; } }
  @container (min-width: 418px) { .grid { --cols: 3; } }
  /* One column (very narrow screens): wide widgets become one cell wide. */
  @container (max-width: 273.98px) { .grid > .w-medium, .grid > .w-large { grid-column: auto; } }
  .icon { width: 60px; height: 60px; font-size: 32px; }
  .tile .desc { display: none; }
  .home { padding-top: 32px; }
  .auth-card { padding: 32px 22px 24px; }
}
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.row.center { justify-content: center; }
.mb { margin-bottom: 18px; }

/* ---------- Page transitions ---------- */
/* Moving between pages crossfades instead of flashing white. The top bar keeps its place;
   the content fades and rises slightly, like switching panes on macOS. */
@view-transition { navigation: auto; }
/* The old content leaves quickly and the new one follows a beat later, so the two pages
   never show through each other. Menu and toast animate on their own, not as part of a page. */
.topbar { view-transition-name: topbar; }
.menu { view-transition-name: menu; }
.toast { view-transition-name: toast; }
::view-transition-group(root) { animation-duration: .4s; }
::view-transition-old(root) { animation: .12s ease-in both vt-out; }
::view-transition-new(root) { animation: .34s var(--ease-out) .1s both vt-in; }
::view-transition-group(menu), ::view-transition-group(toast) { animation-duration: .2s; }
::view-transition-group(topbar) { animation-duration: .32s; animation-timing-function: var(--ease-out); }
@keyframes vt-out { to { opacity: 0; } }
@keyframes vt-in { from { opacity: 0; transform: translateY(6px); } }

/* Reduced motion: no movement anywhere, only instant changes. */
@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
  *, *::before, *::after, ::backdrop {
    animation-duration: .01ms !important; animation-delay: 0s !important;
    transition-duration: .01ms !important; transition-delay: 0s !important;
  }
}
.segmented button:disabled { opacity: .4; cursor: default; }
