/* ==========================================================================
   TickTimeTock — shared stylesheet
   Design tokens, layout primitives, and components used by every page.
   ========================================================================== */

/* ---------- Design tokens ---------- */
:root, :root[data-theme="dark"] {
  --bg: #0f1117;
  --bg-card: #181c26;
  --fg: #e2e8f0;
  --fg-dim: #8b93a7;
  --radius: 14px;
  --font-digits: "Cascadia Mono", "Consolas", "SF Mono", "Roboto Mono", monospace;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --accent: #22d3ee;
  --accent-glow: rgba(34, 211, 238, 0.35);
  /* Text-only variant of --accent. In dark theme it's identical to --accent;
     light theme overrides it below with darker, AA-passing values. Use this
     (not --accent) anywhere accent color is applied to text. */
  --accent-text: var(--accent);
}

:root[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-card: #ffffff;
  --fg: #1a2233;
  --fg-dim: #5b647a;
  --accent-glow: rgba(34, 211, 238, 0.25);
  --accent-text: #0a7382; /* cyan, ~5.1:1 on light bg */
}

:root[data-accent="mint"]  { --accent: #34d399; --accent-glow: rgba(52,211,153,.35); }
:root[data-accent="amber"] { --accent: #fbbf24; --accent-glow: rgba(251,191,36,.35); }
:root[data-accent="pink"]  { --accent: #f472b6; --accent-glow: rgba(244,114,182,.35); }

:root[data-theme="light"][data-accent="mint"]  { --accent-text: #187553; } /* ~5.2:1 */
:root[data-theme="light"][data-accent="amber"] { --accent-text: #855f03; } /* ~5.3:1 */
:root[data-theme="light"][data-accent="pink"]  { --accent-text: #c8106f; } /* ~5.2:1 */

/* ---------- Reset ---------- */
*, *::before, *::after {
  box-sizing: border-box;
}

/* Author rules elsewhere (e.g. `.btn { display: inline-flex; }`) have higher
   specificity than the browser's built-in `[hidden] { display: none }` rule,
   which silently defeats `hidden` on any element those rules also target.
   Force it with !important so `hidden` always actually hides, no matter what
   display value a more specific selector later assigns. */
[hidden] {
  display: none !important;
}

/* ---------- Accessibility utilities ---------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html, body {
  margin: 0;
  padding: 0;
}

/* ---------- Base ---------- */
body {
  font-family: var(--font-ui);
  background: var(--bg);
  background-image: radial-gradient(1200px 600px at 80% -10%, rgba(99, 102, 241, .15), transparent);
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: var(--fg);
  overflow-x: hidden;
  min-height: 100vh;
  /* Measured from the real, rendered nav (js/common.js syncNavHeight) and
     written to this custom property, because the nav wraps to a different
     number of rows at different widths — no fixed set of breakpoint
     guesses matches every case. 90px is the fallback for the instant
     before JS first runs. */
  padding-top: var(--nav-height, 90px);
  transition: background-color 200ms ease, color 200ms ease;
}

a {
  color: inherit;
}

/* ---------- Site nav ---------- */
.site-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  column-gap: 24px;
  row-gap: 8px;
  padding: 14px 24px;
  background: rgba(15, 17, 23, .8);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(255, 255, 255, .06);
}

:root[data-theme="light"] .site-nav {
  background: rgba(244, 246, 251, .85);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  min-width: 0;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.site-nav .brand {
  color: var(--accent-text);
  font-weight: 700;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.nav-link {
  color: var(--fg-dim);
  text-decoration: none;
  font-size: .95rem;
  padding: 6px 2px;
  border-bottom: 2px solid transparent;
  flex-shrink: 0;
  transition: color 150ms ease, border-color 150ms ease;
}

.nav-link:hover {
  color: var(--fg);
}

.nav-link.active {
  color: var(--accent-text);
  border-bottom: 2px solid var(--accent);
}

/* ---------- Accent picker ---------- */
.accent-swatches {
  display: flex;
  align-items: center;
  gap: 7px;
  padding-right: 10px;
  margin-right: 2px;
  border-right: 1px solid rgba(255, 255, 255, .12);
}

:root[data-theme="light"] .accent-swatches {
  border-right-color: rgba(0, 0, 0, .12);
}

.accent-swatch {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  background-color: var(--swatch);
  transition: transform 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}

.accent-swatch:hover {
  transform: scale(1.12);
}

.accent-swatch:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

.accent-swatch[aria-pressed="true"] {
  border-color: var(--fg);
  box-shadow: 0 0 0 2px var(--bg-card);
}

@media (max-width: 640px) {
  .site-nav {
    column-gap: 16px;
    row-gap: 10px;
    padding: 12px 16px;
  }
}

/* ---------- Display (giant clock digits) ---------- */
.display {
  font-family: var(--font-digits);
  font-variant-numeric: tabular-nums;
  font-size: clamp(3rem, 14vw, 9rem);
  text-shadow: 0 0 30px var(--accent-glow);
  color: var(--accent-text);
  text-align: center;
  line-height: 1.1;
  margin: 0;
}

.display span {
  transition: opacity 120ms ease;
}

.display-date {
  color: var(--fg-dim);
  text-align: center;
  font-size: clamp(0.9rem, 2.5vw, 1.25rem);
  margin: 8px 0 0;
}

@keyframes tt-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

.display.pulse {
  animation: tt-pulse 1s ease-in-out infinite;
}

/* ---------- Preset grid ---------- */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
}

.preset-btn {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, .06);
  border-radius: var(--radius);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 1rem;
  padding: 16px 10px;
  cursor: pointer;
  text-align: center;
  transition: transform 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}

.preset-btn:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 4px 16px var(--accent-glow);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 999px;
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: .95rem;
  padding: 10px 20px;
  cursor: pointer;
  transition: filter 150ms ease, transform 150ms ease, background-color 150ms ease;
}

.btn:hover {
  filter: brightness(1.15);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0f1117;
  font-weight: 600;
}

.btn-primary:hover {
  filter: brightness(1.1);
}

.btn[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
  color: var(--accent-text);
}

/* ---------- Card ---------- */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, .06);
  padding: 20px;
}

/* ---------- Tool layout ---------- */
.tool-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 24px;
  max-width: calc(1100px + 48px);
  margin: 0 auto;
  padding: 0 24px;
}

@media (max-width: 1024px) {
  .tool-layout {
    grid-template-columns: 1fr;
  }

  .tool-layout > aside {
    display: none;
  }
}

/* ---------- Ad slots ---------- */
.ad-slot {
  position: relative;
  border: 1px dashed rgba(139, 147, 167, .3);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-dim);
  overflow: hidden;
}

.ad-slot::after {
  content: attr(data-label);
  color: var(--fg-dim);
  opacity: .5;
  font-size: .8rem;
  text-align: center;
  padding: 0 8px;
}

.ad-slot--leaderboard {
  max-width: 728px;
  width: calc(100% - 48px);
  height: 90px;
  margin: 0 auto;
}

.ad-slot--rect {
  width: 300px;
  height: 250px;
  margin: 0 auto;
}

.ad-slot--side {
  width: 300px;
  height: 250px;
  position: sticky;
  top: 90px;
}

:fullscreen .ad-slot {
  display: none;
}

/* ---------- How-to section ---------- */
.howto {
  max-width: 720px;
  margin: 0 auto;
}

.howto h2 {
  color: var(--fg);
  font-size: 1.4rem;
  margin-top: 2em;
  margin-bottom: .5em;
}

.howto p {
  color: var(--fg-dim);
  line-height: 1.7;
}

/* ---------- Footer ---------- */
.site-footer {
  text-align: center;
  color: var(--fg-dim);
  font-size: .85rem;
  padding: 24px 24px 40px;
}

.footer-links {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 10px;
}

.footer-links a {
  color: var(--fg-dim);
  text-decoration: none;
  font-size: .85rem;
}

.footer-links a:hover {
  color: var(--fg);
  text-decoration: underline;
}

/* ---------- Content pages (privacy / about / contact) ---------- */
.content-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 24px 40px;
}

.content-page h1 {
  color: var(--fg);
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  margin: 0 0 .3em;
}

.content-page .lede {
  color: var(--fg-dim);
  font-size: 1.05rem;
  line-height: 1.6;
  margin: 0 0 1.5em;
}

.content-page h2 {
  color: var(--fg);
  font-size: 1.25rem;
  margin-top: 1.8em;
  margin-bottom: .5em;
}

.content-page p,
.content-page li {
  color: var(--fg-dim);
  line-height: 1.7;
}

.content-page ul {
  padding-left: 1.2em;
}

.content-page a {
  color: var(--accent-text);
}

.content-page .updated {
  color: var(--fg-dim);
  font-size: .85rem;
  margin-top: 2.5em;
}

.content-page .placeholder {
  background: var(--bg-card);
  border: 1px dashed rgba(139, 147, 167, .4);
  border-radius: 8px;
  padding: 2px 8px;
  font-family: var(--font-digits);
  font-size: .95em;
}

/* ---------- Fullscreen mode (desk-clock view) ---------- */
/* Hide every child of main, then restore the few that belong on a desk
   clock. A blocklist would silently break every time a page gains a
   section, which is how the first version ended up showing the whole
   page behind the clock. */
:fullscreen {
  background: var(--bg);
}

:fullscreen .site-nav,
:fullscreen .site-footer,
:fullscreen .ad-slot,
:fullscreen .tool-layout > aside {
  display: none;
}

:fullscreen body,
body:fullscreen {
  padding-top: 0;
}

:fullscreen .tool-layout {
  display: block;
  max-width: none;
  margin: 0;
  padding: 0;
}

:fullscreen main > * {
  display: none;
}

:fullscreen main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 100vh;
}

:fullscreen main > .display {
  display: block;
  font-size: clamp(3rem, 12vw, 11rem);
}

:fullscreen main > .display-date {
  display: block;
  font-size: clamp(1rem, 2.5vw, 1.75rem);
}

/* The timer's digits sit absolutely inside .ring-wrap, so the ring is what
   has to grow — the display itself is never a child of main on that page. */
:fullscreen main > .ring-wrap {
  display: block;
  width: min(68vmin, 620px);
  height: min(68vmin, 620px);
}

:fullscreen main > .timer-controls {
  display: flex;
  margin: 0;
}

/* ---------- Alarm inputs ---------- */
.alarm-inputs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.alarm-inputs input[type="time"],
.alarm-inputs select {
  background: var(--bg);
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 8px;
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 1rem;
  padding: 9px 12px;
}

/* ---------- Alarm list ---------- */
#alarm-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#alarm-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg);
  border: 1px solid rgba(255, 255, 255, .06);
  border-radius: 10px;
  padding: 10px 14px;
}

#alarm-list .alarm-time {
  font-family: var(--font-digits);
  font-variant-numeric: tabular-nums;
  font-size: 1.1rem;
  color: var(--accent-text);
}

#alarm-list .alarm-tone {
  color: var(--fg-dim);
  font-size: .9rem;
  text-transform: capitalize;
  margin-right: auto;
}

#alarm-list li .btn {
  padding: 6px 14px;
  font-size: .85rem;
}

/* ---------- Timer ring ---------- */
.ring-wrap {
  position: relative;
  width: min(70vw, 420px);
  height: min(70vw, 420px);
  margin: 0 auto;
}

.ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
  /* The ring's glow is a filter in SVG user units, so it scales with the
     rendered size. An <svg> clips to its viewport by default, which cut the
     glow off as a hard square once the ring grew for fullscreen. */
  overflow: visible;
}

.ring-bg {
  stroke: var(--bg-card);
  stroke-width: 8;
  fill: none;
}

.ring-fg {
  stroke: var(--accent);
  stroke-width: 8;
  fill: none;
  stroke-linecap: round;
  stroke-dasharray: 565.49;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 300ms linear;
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

.display--timer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(2.5rem, 10vw, 5rem);
  margin: 0;
}

.timer-controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 20px 0 28px;
}

.timer-inputs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.timer-inputs input[type="number"] {
  width: 4.5em;
  background: var(--bg);
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 8px;
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 1rem;
  padding: 9px 10px;
}

.timer-inputs select {
  background: var(--bg);
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 8px;
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 1rem;
  padding: 9px 12px;
}

/* ---------- Stopwatch lap table ---------- */
#sw-laps {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-digits);
  font-variant-numeric: tabular-nums;
}

#sw-laps th,
#sw-laps td {
  text-align: right;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, .06);
}

#sw-laps th:first-child,
#sw-laps td:first-child {
  text-align: left;
  color: var(--fg-dim);
  font-family: var(--font-ui);
  width: 2.5em;
}

#sw-laps th {
  color: var(--fg-dim);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .02em;
}

#sw-laps tbody tr:last-child td {
  border-bottom: none;
}

#sw-laps tr.lap-fastest td {
  color: var(--accent-text);
}

#sw-laps tr.lap-slowest td {
  color: var(--fg-dim);
}

#sw-laps tr.lap-fastest.lap-slowest td {
  color: var(--fg);
}

/* ---------- World clock city grid ---------- */
.city-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.city-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, .06);
  padding: 18px 20px;
}

.city-name {
  color: var(--fg-dim);
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.city-time {
  font-family: var(--font-digits);
  font-variant-numeric: tabular-nums;
  font-size: 1.6rem;
  color: var(--accent-text);
  margin-top: 6px;
}

.city-date {
  color: var(--fg-dim);
  font-size: .85rem;
  margin-top: 4px;
}

/* ---------- Long-tail landing pages (generated) ---------- */
/* These pages have no <aside>, so the grid's second (300px) track would
   otherwise sit empty at desktop widths. */
.tool-layout--single {
  grid-template-columns: minmax(0, 760px);
  justify-content: center;
}

.longtail-page {
  max-width: 760px;
  margin: 0 auto;
}

.longtail-page h1 {
  color: var(--fg);
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  margin: 0 0 .3em;
  text-align: center;
}

.longtail-intro p {
  color: var(--fg-dim);
  font-size: 1.05rem;
  line-height: 1.6;
  text-align: center;
  margin: 0 0 1.5em;
}

.longtail-tool {
  margin: 0 0 2em;
}

.longtail-sections h2 {
  color: var(--fg);
  font-size: 1.25rem;
  margin-top: 1.8em;
  margin-bottom: .5em;
}

.longtail-sections p {
  color: var(--fg-dim);
  line-height: 1.7;
}

.longtail-table {
  width: 100%;
  border-collapse: collapse;
  margin: .5em 0 1em;
}

.longtail-table caption {
  caption-side: top;
  text-align: left;
  color: var(--fg-dim);
  font-size: .85rem;
  margin-bottom: 8px;
}

.longtail-table th,
.longtail-table td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, .06);
  color: var(--fg-dim);
}

.longtail-table th {
  color: var(--fg);
  font-weight: 600;
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .02em;
}

.longtail-table tbody tr:last-child td {
  border-bottom: none;
}

.related-links {
  margin-top: 2em;
  padding-top: 1.2em;
  border-top: 1px solid rgba(255, 255, 255, .06);
}

.related-links h2 {
  color: var(--fg);
  font-size: 1.1rem;
  margin: 0 0 .6em;
}

.related-links ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
}

.related-links a {
  color: var(--accent-text);
  text-decoration: none;
}

.related-links a:hover {
  text-decoration: underline;
}

/* Hub-page lists linking out to the per-time and per-duration landing
   pages. Plain markup rather than JS-built like the preset grid, so
   crawlers see the links without executing anything. */
.section-lede {
  color: var(--fg-dim);
  margin: 0 0 1em;
}

.link-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px 20px;
}

.link-list a {
  color: var(--accent-text);
  text-decoration: none;
}

.link-list a:hover {
  text-decoration: underline;
}

/* ---------- Alarm overlay ---------- */
/* The narrow #alarm-overlay[hidden] override that used to live here is no
   longer needed: the global [hidden] rule in the reset section now forces
   display:none with !important, which already beats this element's own
   unconditional `display: flex` below. */
#alarm-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  /* Opaque, not opacity: .97 — element opacity also dims the overlay's own
     text, and the glowing clock behind it bleeds through at fullscreen size. */
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

#alarm-overlay .overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

#alarm-overlay .overlay-time {
  font-family: var(--font-digits);
  font-variant-numeric: tabular-nums;
  font-size: clamp(3rem, 14vw, 9rem);
  color: var(--accent-text);
  text-shadow: 0 0 30px var(--accent-glow);
  animation: tt-pulse 1s ease-in-out infinite;
}

#alarm-overlay .overlay-inner .btn {
  margin: 0 8px;
}
