/* ==========================================================================
   Chronos — style.css
   Design tokens, base styles, components and views.
   Layout breakpoints live in responsive.css.
   ========================================================================== */

/* ---------- 1. Design tokens ---------- */
:root {
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 20px;
  --radius-sm: 12px;
  --sidebar-w: 272px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --t: .25s;
  --clock-scale: 1;
  --clock-bg: linear-gradient(135deg, #1d1a4d 0%, #5b3df5 50%, #c04df0 100%);
  --clock-fg: #fff;
  --clock-glass: 255 255 255;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* Colour modes */
html[data-mode="dark"] {
  color-scheme: dark;
  --bg: #080a12;
  --card: #12151f;
  --card-2: #181c29;
  --input-bg: #0d1019;
  --border: rgba(255, 255, 255, .08);
  --border-strong: rgba(255, 255, 255, .18);
  --text: #eef0f7;
  --muted: #9097ad;
  --shadow: 0 12px 40px rgba(0, 0, 0, .45);
  --glow: .30;
  --accent-text: var(--accent-dk);
}
html[data-mode="light"] {
  color-scheme: light;
  --bg: #f1f3fa;
  --card: #ffffff;
  --card-2: #f5f6fc;
  --input-bg: #f4f5fb;
  --border: rgba(20, 24, 60, .10);
  --border-strong: rgba(20, 24, 60, .22);
  --text: #141833;
  --muted: #5b6282;
  --shadow: 0 12px 32px rgba(30, 40, 100, .10);
  --glow: .20;
  --accent-text: var(--accent);
}

/* Colour themes. --accent is dark enough for white text; -dk is the lighter tint used for text on dark. */
html[data-theme="violet"]  { --accent-3: #9c2fd0; --accent: #6a4bf0; --accent-2: #b24df0; --accent-dk: #a995ff; --accent-rgb: 106 75 240;  --accent-2-rgb: 178 77 240; }
html[data-theme="ocean"]   { --accent-3: #0a8aa6; --accent: #1a66d9; --accent-2: #14b8d4; --accent-dk: #7db4ff; --accent-rgb: 26 102 217;  --accent-2-rgb: 20 184 212; }
html[data-theme="emerald"] { --accent-3: #0a6f86; --accent: #0b8a62; --accent-2: #5fd08a; --accent-dk: #4fdca8; --accent-rgb: 11 138 98;   --accent-2-rgb: 95 208 138; }
html[data-theme="sunset"]  { --accent-3: #c2255c; --accent: #d9480f; --accent-2: #ffa94d; --accent-dk: #ff9a6b; --accent-rgb: 217 72 15;   --accent-2-rgb: 255 169 77; }
html[data-theme="rose"]    { --accent-3: #8e24aa; --accent: #d6246a; --accent-2: #ff7eb0; --accent-dk: #ff8fb8; --accent-rgb: 214 36 106;  --accent-2-rgb: 255 126 176; }

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

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--t), color var(--t);
}

/* Soft accent glow behind the whole app */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(55vmax 40vmax at 100% -10%, rgb(var(--accent-rgb) / var(--glow)), transparent 60%),
    radial-gradient(45vmax 35vmax at -10% 110%, rgb(var(--accent-2-rgb) / calc(var(--glow) * .7)), transparent 60%);
}

body.modal-open, body.clock-fs { overflow: hidden; }

[hidden] { display: none !important; }

h1, h2, h3, p, ul, dl, dd { margin: 0; }
ul { padding: 0; list-style: none; }
h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; }
h2 { font-size: 1.6rem; font-weight: 700; letter-spacing: -.025em; }
h3 { font-size: 1rem; font-weight: 600; display: flex; align-items: center; gap: .55rem; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
kbd {
  display: inline-block; min-width: 1.6em; padding: .1em .45em; text-align: center;
  font: 600 .75rem/1.5 var(--font); border-radius: 6px;
  background: var(--card-2); border: 1px solid var(--border); color: var(--muted);
}
.muted { color: var(--muted); }
.link { color: var(--accent-text); font-size: .85rem; font-weight: 600; }
.link:hover { text-decoration: underline; }

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

:focus-visible { outline: 3px solid rgb(var(--accent-rgb) / .75); outline-offset: 2px; }
html[data-mode="dark"] :focus-visible { outline-color: var(--accent-dk); }

.skip-link {
  position: fixed; left: 1rem; top: -4rem; z-index: 500;
  padding: .7rem 1rem; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 600;
  transition: top var(--t) var(--ease);
}
.skip-link:focus { top: 1rem; }

.icon {
  width: 1.25em; height: 1.25em; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.icon-fill { fill: currentColor; }

/* ---------- 3. Loader ---------- */
.loader {
  position: fixed; inset: 0; z-index: 1000;
  display: grid; place-content: center; justify-items: center; gap: 1.2rem;
  background: var(--bg); color: var(--muted); font-weight: 500;
  transition: opacity .5s var(--ease), visibility .5s;
}
.loader.is-done { opacity: 0; visibility: hidden; }
.loader-ring {
  width: 56px; height: 56px; border-radius: 50%;
  border: 4px solid var(--border-strong); border-top-color: var(--accent-text);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 4. App shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }

.sidebar {
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; gap: 1.5rem;
  padding: 1.5rem 1.1rem calc(1.5rem + var(--safe-bottom));
  background: var(--card);
  border-right: 1px solid var(--border);
  z-index: 60;
}

.brand { display: flex; align-items: center; gap: .8rem; padding: 0 .4rem; }
.brand-mark {
  display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 20px -6px rgb(var(--accent-rgb) / .7);
}
.brand-mark .icon { width: 22px; height: 22px; }
.brand-text { display: grid; line-height: 1.2; min-width: 0; }
.brand-text strong { font-size: 1.1rem; letter-spacing: -.02em; }
.brand-text small { color: var(--muted); font-size: .75rem; }
.sidebar .sidebar-close { display: none; margin-left: auto; }

.nav { display: grid; gap: .25rem; }
.nav-link {
  position: relative; display: flex; align-items: center; gap: .85rem;
  min-height: 46px; padding: 0 .9rem; border-radius: 14px;
  color: var(--muted); font-weight: 500;
  transition: background var(--t), color var(--t);
}
.nav-link span { flex: 1; }
.nav-link kbd { opacity: .7; }
.nav-link:hover { background: var(--card-2); color: var(--text); }
.nav-link[aria-current="page"] { background: rgb(var(--accent-rgb) / .16); color: var(--accent-text); font-weight: 600; }
.nav-link[aria-current="page"]::before {
  content: ""; position: absolute; left: -1.1rem; top: 10px; bottom: 10px; width: 4px;
  border-radius: 0 4px 4px 0; background: var(--accent-text);
}

.sidebar-foot { margin-top: auto; }
.mini-clock {
  display: grid; gap: .15rem; padding: 1rem; border-radius: 16px;
  background: var(--card-2); border: 1px solid var(--border);
}
.mini-clock span { font-size: 1.5rem; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.mini-clock small { color: var(--muted); font-size: .75rem; overflow-wrap: anywhere; }

.backdrop {
  position: fixed; inset: 0; z-index: 55; background: rgba(4, 6, 14, .6);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  animation: fade .25s var(--ease);
}
@keyframes fade { from { opacity: 0; } }

.content { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: .8rem;
  padding: .9rem clamp(1rem, 3vw, 2.25rem);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
@supports not (background: color-mix(in srgb, red, blue)) { .topbar { background: var(--bg); } }
.topbar h1 { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: .4rem; }
.topbar .menu-btn { display: none; }

main { padding: clamp(1rem, 3vw, 2.25rem); padding-bottom: calc(clamp(1rem, 3vw, 2.25rem) + var(--safe-bottom)); outline: none; flex: 1; width: 100%; max-width: 1280px; margin-inline: auto; }

.view { animation: viewIn .4s var(--ease); }
@keyframes viewIn { from { opacity: 0; transform: translateY(10px); } }

.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.4rem; }
.section-head p { margin-top: .25rem; }

/* ---------- 5. Components ---------- */

/* Cards */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.35rem; box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .8rem; margin-bottom: 1.1rem; }
.card-head h3 .icon { color: var(--accent-text); }

.pill {
  display: inline-flex; align-items: center; gap: .5rem; padding: .35rem .8rem; border-radius: 999px;
  background: rgb(var(--clock-glass, 255 255 255) / .14); border: 1px solid rgb(var(--clock-glass, 255 255 255) / .22);
  font-size: .78rem; font-weight: 600; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.chip {
  display: inline-flex; align-items: center; justify-content: center; min-width: 2rem; padding: .15rem .7rem;
  border-radius: 999px; background: rgb(var(--accent-rgb) / .15); color: var(--accent-text);
  font-size: .8rem; font-weight: 700; font-variant-numeric: tabular-nums;
}
.pulse { width: 8px; height: 8px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 0 rgba(74, 222, 128, .7); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(74, 222, 128, 0); } 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); } }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .55rem;
  min-height: 44px; padding: 0 1.2rem; border-radius: 999px; border: 1px solid transparent;
  font-weight: 600; font-size: .92rem; line-height: 1; white-space: nowrap; text-align: center;
  transition: transform var(--t) var(--ease), background var(--t), border-color var(--t), box-shadow var(--t), opacity var(--t), filter var(--t);
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 10px 24px -10px rgb(var(--accent-rgb) / .9); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.1); }
.btn-ghost { background: var(--card-2); border-color: var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { border-color: var(--border-strong); }
.btn-danger { background: rgba(239, 68, 68, .12); border-color: rgba(239, 68, 68, .35); color: #ef4444; }
html[data-mode="dark"] .btn-danger { color: #ff8a8a; }
.btn-danger:hover:not(:disabled) { background: rgba(239, 68, 68, .2); }
.btn-glass { background: rgba(255, 255, 255, .16); border-color: rgba(255, 255, 255, .25); color: inherit; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.btn-glass:hover { background: rgba(255, 255, 255, .26); }
.btn-lg { min-height: 58px; padding: 0 1.8rem; font-size: 1.02rem; }
.btn-sm { min-height: 38px; padding: 0 1rem; font-size: .85rem; }

.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  border-radius: 14px; border: 1px solid var(--border); background: var(--card-2); color: var(--text);
  transition: background var(--t), border-color var(--t), transform var(--t) var(--ease), color var(--t);
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { border-color: var(--border-strong); }
.icon-btn:active { transform: scale(.94); }
.icon-btn.danger:hover { color: #ef4444; border-color: rgba(239, 68, 68, .5); }
.icon-btn-sm { width: 40px; height: 40px; border-radius: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; }
.chip-btn {
  min-height: 40px; padding: 0 1rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--card-2); font-weight: 600; font-size: .85rem; transition: all var(--t);
}
.chip-btn:hover:not(:disabled) { border-color: var(--accent-text); color: var(--accent-text); }
.chip-btn:disabled { opacity: .45; cursor: not-allowed; }

/* Forms */
.field { display: grid; gap: .4rem; min-width: 0; }
.field-label { font-size: .8rem; font-weight: 600; color: var(--muted); }
input[type="text"], input[type="time"], input[type="number"], select {
  width: 100%; min-height: 46px; padding: 0 .9rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--input-bg); color: var(--text);
  transition: border-color var(--t), box-shadow var(--t);
}
select { appearance: none; -webkit-appearance: none; padding-right: 2.2rem; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
input:focus, select:focus { outline: none; border-color: var(--accent-text); box-shadow: 0 0 0 3px rgb(var(--accent-rgb) / .25); }
input[aria-invalid="true"] { border-color: #ef4444; }
input::placeholder { color: var(--muted); opacity: .7; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button, input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.setting select { width: auto; min-width: 150px; }

.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; gap: 1rem; align-items: end; margin-bottom: 1.4rem; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; align-items: end; }
.stack { display: grid; gap: 1rem; }
.form-actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.form-actions-end { justify-content: flex-end; }

/* Switch */
.switch { position: relative; display: inline-block; width: 52px; height: 30px; flex: none; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 1; }
.switch .track { position: absolute; inset: 0; border-radius: 999px; background: var(--border-strong); transition: background var(--t); }
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .3); transition: transform var(--t) var(--ease);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(22px); }
.switch input:focus-visible + .track { outline: 3px solid rgb(var(--accent-rgb) / .75); outline-offset: 2px; }

/* Segmented control */
.segmented { display: inline-flex; padding: 4px; gap: 2px; border-radius: 999px; background: var(--card-2); border: 1px solid var(--border); }
.segmented button {
  min-height: 38px; padding: 0 1rem; border: 0; border-radius: 999px; background: transparent; color: var(--muted);
  font-weight: 600; font-size: .86rem; transition: background var(--t), color var(--t);
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] { background: var(--accent); color: #fff; box-shadow: 0 4px 12px -4px rgb(var(--accent-rgb) / .8); }
.segmented-on-clock { background: rgba(255, 255, 255, .14); border-color: rgba(255, 255, 255, .22); }
.segmented-on-clock button { color: inherit; opacity: .8; }
.segmented-on-clock button:hover { opacity: 1; color: inherit; }
.segmented-on-clock button[aria-pressed="true"] { background: rgba(255, 255, 255, .95); color: #1a1530; opacity: 1; box-shadow: none; }

/* Swatches */
.swatches { display: flex; flex-wrap: wrap; gap: .7rem; align-items: center; }
.swatch {
  position: relative; width: 42px; height: 42px; border-radius: 50%; border: 3px solid transparent; padding: 0;
  box-shadow: 0 0 0 1px var(--border-strong); transition: transform var(--t) var(--ease), box-shadow var(--t);
  background-clip: padding-box;
}
.swatch:hover { transform: scale(1.08); }
.swatch[aria-pressed="true"], .swatch.is-active { box-shadow: 0 0 0 3px var(--accent-text); }
.swatch[aria-pressed="true"]::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 14px; height: 8px;
  border-left: 3px solid #fff; border-bottom: 3px solid #fff; transform: translateY(-2px) rotate(-45deg);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .5));
}
.swatch-custom {
  display: block; overflow: hidden; cursor: pointer;
  background: conic-gradient(from 0deg, #ff4d4d, #ffd24d, #4dff88, #4dc3ff, #a64dff, #ff4d4d);
}
.swatch-custom input { position: absolute; inset: -8px; width: 70px; height: 70px; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.swatch-custom:focus-within { outline: 3px solid rgb(var(--accent-rgb) / .75); outline-offset: 2px; }

/* Range */
.range-row { display: flex; align-items: center; gap: 1rem; }
.range-out { min-width: 3.2rem; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
input[type="range"] { flex: 1; min-width: 0; height: 30px; margin: 0; background: transparent; -webkit-appearance: none; appearance: none; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 99px; background: var(--border-strong); }
input[type="range"]::-moz-range-track { height: 6px; border-radius: 99px; background: var(--border-strong); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; margin-top: -8px; border-radius: 50%; background: var(--accent); border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .35); }
input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--accent); border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .35); }

/* Lists */
.list { display: grid; gap: .75rem; }
.list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1rem 1.1rem; border-radius: 16px; background: var(--card-2); border: 1px solid var(--border);
  transition: opacity var(--t), border-color var(--t);
}
.list-item.is-off { opacity: .55; }
.list-item.is-editing { border-color: var(--accent-text); }
.empty { padding: 1.6rem 1rem; text-align: center; color: var(--muted); border: 1px dashed var(--border-strong); border-radius: 16px; }
.item-actions { display: flex; align-items: center; gap: .5rem; flex: none; }

.mini-list { display: grid; gap: .55rem; }
.mini-list li { display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; padding: .55rem .8rem; border-radius: 12px; background: var(--card-2); }
.mini-list .mini-time { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mini-list .mini-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Toasts */
.toasts {
  position: fixed; right: 1.25rem; bottom: calc(1.25rem + var(--safe-bottom)); z-index: 900;
  display: grid; gap: .6rem; width: min(380px, calc(100vw - 2rem)); pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: .75rem; padding: .8rem .9rem .8rem 1rem;
  border-radius: 16px; background: var(--card); border: 1px solid var(--border-strong); box-shadow: var(--shadow);
  animation: toastIn .35s var(--ease);
}
.toast.leaving { opacity: 0; transform: translateY(8px); transition: all .2s ease; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(.96); } }
.toast .icon { color: var(--accent-text); }
.toast-success .icon { color: #22c55e; }
.toast-error .icon { color: #ef4444; }
.toast-warning .icon { color: #f59e0b; }
.toast-msg { flex: 1; min-width: 0; font-size: .9rem; font-weight: 500; overflow-wrap: anywhere; }
.toast-action { border: 0; background: transparent; color: var(--accent-text); font-weight: 700; padding: .5rem .6rem; border-radius: 10px; min-height: 36px; }
.toast-action:hover { background: rgb(var(--accent-rgb) / .14); }
.toast-close { display: grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); }
.toast-close:hover { background: var(--card-2); }

/* Modals */
.modal {
  position: fixed; inset: 0; z-index: 800; display: grid; place-items: center; padding: 1rem;
  background: rgba(4, 6, 14, .66); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fade .25s var(--ease);
}
.modal-alert { z-index: 850; }
.modal-card {
  width: min(480px, 100%); max-height: calc(100dvh - 2rem); overflow: auto;
  padding: 1.6rem; border-radius: 24px; background: var(--card); border: 1px solid var(--border-strong);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .5); animation: pop .35s var(--ease);
}
@keyframes pop { from { opacity: 0; transform: translateY(16px) scale(.95); } }
.modal-actions { display: flex; gap: .8rem; margin-top: 1.5rem; }
.modal-actions .btn { flex: 1; }

.ring-card { text-align: center; }
.ring-icon {
  width: 84px; height: 84px; margin: .3rem auto 1rem; display: grid; place-items: center; border-radius: 50%;
  color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  animation: ringShake 1s ease-in-out infinite; box-shadow: 0 0 0 0 rgb(var(--accent-rgb) / .6);
}
.ring-icon .icon { width: 38px; height: 38px; }
@keyframes ringShake {
  0%, 100% { transform: rotate(0); box-shadow: 0 0 0 0 rgb(var(--accent-rgb) / .55); }
  10%, 30%, 50% { transform: rotate(-14deg); }
  20%, 40%, 60% { transform: rotate(14deg); }
  70% { transform: rotate(0); box-shadow: 0 0 0 26px rgb(var(--accent-rgb) / 0); }
}
.ring-time { font-size: 3.2rem; font-weight: 300; letter-spacing: -.04em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.ring-card h2 { margin-top: .2rem; }

.shortcut-list { display: grid; gap: .4rem; }
.shortcut-list > div { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .6rem .2rem; border-bottom: 1px solid var(--border); }
.shortcut-list > div:last-child { border: 0; }
.shortcut-list dt { white-space: nowrap; }
.shortcut-list dd { color: var(--muted); text-align: right; }

.noscript { padding: 2rem; text-align: center; }

/* ---------- 6. Dashboard ---------- */
.dash-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.25rem; }

.clock-card {
  grid-column: 1 / -1; position: relative; overflow: hidden; container-type: inline-size;
  padding: clamp(1.25rem, 4cqw, 2.5rem); border-radius: 28px; color: var(--clock-fg);
  background: var(--clock-bg); box-shadow: 0 24px 60px -24px rgb(var(--accent-rgb) / .75);
  display: flex; flex-direction: column; align-items: center; gap: clamp(.6rem, 2cqw, 1.2rem); text-align: center;
  transition: background var(--t);
}
.clock-card::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(60% 80% at 85% 0%, rgba(255, 255, 255, .20), transparent 60%),
    radial-gradient(50% 60% at 0% 100%, rgba(0, 0, 0, .22), transparent 60%);
}
.clock-card > * { position: relative; }
.clock-top { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: .6rem; flex-wrap: wrap; }
.greeting { font-size: clamp(1rem, 2.4cqw, 1.35rem); font-weight: 500; opacity: .92; }

.clock {
  display: flex; align-items: center; justify-content: center; gap: .08em;
  font-size: clamp(2.75rem, min(calc(19cqw * var(--clock-scale)), 27cqw), 16rem);
  font-weight: 300; line-height: 1; letter-spacing: -.04em; font-variant-numeric: tabular-nums;
  padding: .05em 0;
}
.clock-hm { display: inline-flex; align-items: baseline; }
.colon { padding: 0 .02em; opacity: .75; transform: translateY(-.06em); animation: blink 1s steps(2, jump-none) infinite; }
@keyframes blink { 0% { opacity: .85; } 50% { opacity: .25; } }
.clock-side { display: flex; flex-direction: column; align-items: flex-start; gap: .12em; font-size: .38em; letter-spacing: 0; margin-left: .15em; }
.clock-side .seconds { font-weight: 400; opacity: .95; line-height: 1; }
.period {
  font-size: .5em; font-weight: 700; letter-spacing: .12em; padding: .15em .5em; border-radius: .5em;
  background: rgba(255, 255, 255, .18); line-height: 1.3;
}
.digit { display: inline-block; }
.digit.tick { animation: tickIn .38s var(--ease); }
@keyframes tickIn { from { opacity: 0; transform: translateY(.14em); } }

.date-line { font-size: clamp(1rem, 2.6cqw, 1.5rem); font-weight: 500; opacity: .92; }
.clock-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .8rem; margin-top: .4rem; }

/* Full-screen clock (real Fullscreen API or fallback overlay) */
.clock-card.is-fullscreen {
  position: fixed; inset: 0; z-index: 700; width: 100%; height: 100%; max-width: none; margin: 0;
  border-radius: 0; justify-content: center; gap: 2.5vh; padding: 3rem 2rem;
}
.clock-card.is-fullscreen .clock { font-size: min(calc(22cqw * var(--clock-scale)), 28cqw, 38vh); }
.clock-card.is-fullscreen .clock-top { position: absolute; top: 1.5rem; left: 1.5rem; right: 1.5rem; width: auto; }
.clock-card.is-fullscreen .clock-actions { position: absolute; bottom: calc(1.5rem + var(--safe-bottom)); }
.clock-card.is-fullscreen .greeting { font-size: clamp(1.2rem, 3vh, 2rem); }
.clock-card.is-fullscreen .date-line { font-size: clamp(1.2rem, 3.6vh, 2.4rem); }

.info-card { display: flex; flex-direction: column; }
.info-card .card-head { margin-bottom: .9rem; }
.info-big { font-size: 2.3rem; font-weight: 600; letter-spacing: -.03em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.info-big small { font-size: .9rem; font-weight: 600; color: var(--muted); letter-spacing: 0; margin-left: .25rem; }

/* ---------- 7. World clock ---------- */
.world-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.world-card {
  position: relative; display: grid; gap: .9rem; padding: 1.2rem 1.25rem; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow);
  transition: transform var(--t) var(--ease), border-color var(--t);
  animation: viewIn .4s var(--ease) backwards;
}
.world-card:hover { border-color: var(--border-strong); transform: translateY(-2px); }
.wc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .6rem; }
.wc-city { font-size: 1.1rem; font-weight: 600; overflow-wrap: anywhere; }
.wc-region { color: var(--muted); font-size: .82rem; overflow-wrap: anywhere; }
.wc-time { display: flex; align-items: baseline; gap: .2rem; font-size: 2.6rem; font-weight: 300; letter-spacing: -.04em; line-height: 1; font-variant-numeric: tabular-nums; }
.wc-sec { font-size: 1.25rem; color: var(--muted); font-weight: 400; }
.wc-period { margin-left: .35rem; font-size: .8rem; font-weight: 700; letter-spacing: .08em; color: var(--accent-text); }
.wc-foot { display: flex; align-items: center; gap: .6rem; color: var(--muted); font-size: .82rem; flex-wrap: wrap; }
.wc-foot > :first-child { flex-basis: 100%; }
.wc-foot .wc-icon { margin-left: auto; display: inline-flex; color: var(--accent-text); }
.wc-badge { padding: .1rem .55rem; border-radius: 99px; background: var(--card-2); border: 1px solid var(--border); font-weight: 600; font-size: .75rem; }
.wc-day-diff { color: var(--text); font-weight: 600; }

/* ---------- 8. Alarms ---------- */
.two-col { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 1.25rem; align-items: start; }
.alarm-main { display: flex; align-items: center; gap: 1rem; min-width: 0; }
.alarm-time { font-size: 2rem; font-weight: 300; letter-spacing: -.03em; line-height: 1; font-variant-numeric: tabular-nums; white-space: nowrap; }
.alarm-time small { font-size: .8rem; font-weight: 700; color: var(--accent-text); margin-left: .2rem; letter-spacing: .06em; }
.alarm-meta { display: grid; gap: .1rem; min-width: 0; }
.alarm-meta strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alarm-meta span { font-size: .8rem; color: var(--muted); }
.alarm-next { color: var(--accent-text) !important; font-weight: 600; }
.is-off .alarm-next { visibility: hidden; }

/* ---------- 9. Stopwatch + Timer ---------- */
.center-card { display: grid; justify-items: center; gap: 1.8rem; padding: clamp(1.5rem, 4vw, 2.5rem) 1.25rem; }
.big-display {
  font-size: clamp(2.6rem, 11vw, 5.2rem); font-weight: 300; letter-spacing: -.04em; line-height: 1;
  font-variant-numeric: tabular-nums; text-align: center; white-space: nowrap;
}
.control-row { display: flex; flex-wrap: wrap; justify-content: center; gap: .9rem; }
.hint { color: var(--muted); font-size: .82rem; text-align: center; }
.btn[data-state="running"] { background: rgba(239, 68, 68, .14); border-color: rgba(239, 68, 68, .45); color: #ef4444; box-shadow: none; }
html[data-mode="dark"] .btn[data-state="running"] { color: #ff8a8a; }
.btn[data-state="finished"] { background: #ef4444; color: #fff; animation: pulseBtn 1s infinite; }
@keyframes pulseBtn { 50% { box-shadow: 0 0 0 10px rgba(239, 68, 68, .0), 0 0 22px rgba(239, 68, 68, .6); } }

.table-wrap { max-height: 420px; overflow: auto; border-radius: 14px; border: 1px solid var(--border); }
.laps { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.laps th, .laps td { padding: .7rem 1rem; text-align: left; }
.laps th { position: sticky; top: 0; background: var(--card-2); font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.laps td { border-top: 1px solid var(--border); font-weight: 500; }
.laps td:nth-child(2), .laps th:nth-child(2) { text-align: center; }
.laps td:last-child, .laps th:last-child { text-align: right; color: var(--muted); }
.laps tr.best td:nth-child(2) { color: #22c55e; font-weight: 700; }
.laps tr.worst td:nth-child(2) { color: #ef4444; font-weight: 700; }

.timer-card { display: grid; justify-items: center; gap: 1.6rem; max-width: 640px; margin-inline: auto; padding: clamp(1.4rem, 4vw, 2.4rem); }
.timer-ring { position: relative; width: min(340px, 82%); aspect-ratio: 1; }
.timer-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--border-strong); stroke-width: 7; }
.ring-bar { fill: none; stroke: url(#tmGrad); stroke-width: 7; stroke-linecap: round; stroke-dasharray: 339.292; stroke-dashoffset: 0; transition: stroke-dashoffset .25s linear; }
.timer-center { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: .4rem; }
.timer-center .big-display { font-size: clamp(1.9rem, 8vw, 3rem); }
.timer-inputs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; width: 100%; }
.timer-inputs input { text-align: center; font-size: 1.25rem; font-weight: 600; min-height: 54px; }
.timer-inputs input:disabled { opacity: .55; }

/* ---------- 10. Calendar ---------- */
.cal-layout { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 4fr); gap: 1.25rem; align-items: start; }
.cal-head { display: flex; align-items: center; gap: .6rem; margin-bottom: 1.1rem; }
.cal-head h3 { flex: 1; justify-content: center; font-size: 1.2rem; letter-spacing: -.01em; }
.cal-weekdays, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-weekdays { margin-bottom: 6px; }
.cal-weekdays span { text-align: center; font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: .35rem 0; }
.cal-day {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 62px; padding: 6px 2px; border-radius: 14px; border: 1px solid transparent; background: var(--card-2);
  font-weight: 600; font-variant-numeric: tabular-nums; transition: background var(--t), border-color var(--t), transform var(--t) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.cal-day:hover { border-color: var(--border-strong); }
.cal-day:active { transform: scale(.96); }
.cal-day.is-outside { color: var(--muted); background: transparent; font-weight: 500; opacity: .65; }
.cal-day.is-today { border-color: var(--accent-text); color: var(--accent-text); }
.cal-day.is-selected { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 8px 20px -8px rgb(var(--accent-rgb) / .9); opacity: 1; }
.cal-day .dots { display: flex; gap: 3px; height: 6px; }
.cal-day .dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent-2); }
.cal-day.is-selected .dots i { background: #fff; }
.events-card .list-item { align-items: flex-start; }
.event-main { display: grid; gap: .15rem; min-width: 0; }
.event-main strong { overflow-wrap: anywhere; }
.event-main span { color: var(--accent-text); font-size: .8rem; font-weight: 600; }
.events-card .list { margin-top: 1.1rem; }
.events-card .empty { margin-top: 1.1rem; }

/* ---------- 11. Settings ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; align-items: start; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 0; border-top: 1px solid var(--border); }
.setting:first-of-type { border-top: 0; padding-top: 0; }
.card-head + .setting { border-top: 0; padding-top: 0; }
.setting-stack { flex-direction: column; align-items: stretch; }
.setting-text { display: grid; gap: .1rem; min-width: 0; }
.setting-text strong { font-weight: 600; }
.setting-text .muted { font-size: .82rem; }
.file-btn { position: relative; cursor: pointer; }
.file-btn input { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; }
.file-btn:focus-within { outline: 3px solid rgb(var(--accent-rgb) / .75); outline-offset: 2px; }
.data-note { margin-bottom: 1.1rem; }

/* ---------- 12. Motion preference ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
  .colon { animation: none; }
}
