/*
 * styles.css — the look of the World Clock.
 *
 *   1. Design tokens (colours, sizes) for dark and light mode
 *   2. Base styles
 *   3. Buttons and small controls
 *   4. Top bar and shared-link banner
 *   5. Clock cards (sky, sun, moon, digits)
 *   6. Manage zones panel (search, list, presets, map)
 *   7. Wall mode
 *   8. Phones
 *   9. Reduced motion
 */

/* ================================================================
 * 1. Design tokens
 * ================================================================ */

/* Registering these lets the browser smoothly animate between sky colours. */
@property --sky-top { syntax: '<color>'; inherits: true; initial-value: #0A1330; }
@property --sky-bottom { syntax: '<color>'; inherits: true; initial-value: #16224A; }

:root {
  /* Dark mode is the default. */
  --bg: #0E1322;          /* Night ink */
  --surface: #161D33;
  --surface-2: #1F2742;   /* Dusk slate */
  --surface-3: #2A3354;
  --text: #E9EDF6;        /* Starlight */
  --muted: #8E96B0;       /* Haze */
  --accent: #F0B35C;      /* Lamp amber */
  --accent-ink: #1E1606;  /* text on amber */
  --line: rgba(233, 237, 246, 0.12);
  --map-sea: #141B30;
  --map-land: #313B5E;
  --map-night: rgba(2, 5, 16, 0.42);
  --backdrop: rgba(5, 8, 20, 0.55);

  --gutter: clamp(16px, 4vw, 48px);
  --radius-card: 24px;
  --radius-control: 12px;
  --ease-out: cubic-bezier(.2, .75, .25, 1);

  color-scheme: dark;
}

:root[data-theme='light'] {
  --bg: #EEF2F8;
  --surface: #FFFFFF;
  --surface-2: #E6ECF5;
  --surface-3: #D7DFEC;
  --text: #1A2033;
  --muted: #55607A;
  --accent: #F0B35C;
  --accent-ink: #1E1606;
  --line: rgba(26, 32, 51, 0.14);
  --map-sea: #DDE5F1;
  --map-land: #B3BFD4;
  --map-night: rgba(20, 30, 70, 0.2);
  --backdrop: rgba(26, 32, 51, 0.35);
  color-scheme: light;
}


/* ================================================================
 * 2. Base
 * ================================================================ */

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: 'Sora', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color .4s ease, color .4s ease;
}

h1, h2, h3, p { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { flex-shrink: 0; }

/* Keyboard focus is always clearly visible. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

/* Text only screen readers can hear. */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: var(--gutter);
  top: -60px;
  z-index: 50;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus { top: 12px; }

[hidden] { display: none !important; }


/* ================================================================
 * 3. Buttons and small controls
 * ================================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  font-size: .9rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color .2s ease, border-color .2s ease, transform .2s ease;
}
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.btn:active { transform: scale(.97); }

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #F6C57B; }

.btn-quiet { border-color: var(--line); }
.btn-quiet:hover { background: var(--surface-2); }
.btn-quiet.is-confirming { border-color: #E86F6F; color: #F49A9A; }
:root[data-theme='light'] .btn-quiet.is-confirming { color: #B42318; border-color: #B42318; }

.btn-small { height: 32px; padding: 0 12px; font-size: .8rem; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  transition: background-color .2s ease;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn-small { width: 34px; height: 34px; border-color: transparent; color: var(--muted); }
.icon-btn-small:hover { color: var(--text); }

/* Theme button: show the icon of the mode you'd switch to. */
#theme-toggle .i-moon { display: none; }
:root[data-theme='light'] #theme-toggle .i-sun { display: none; }
:root[data-theme='light'] #theme-toggle .i-moon { display: block; }

/* 24h / 12h switch */
.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
}
.seg {
  height: 32px;
  padding: 0 13px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: .85rem;
  font-weight: 500;
  transition: background-color .2s ease, color .2s ease;
}
.seg:hover { color: var(--text); }
.seg[aria-pressed='true'] { background: var(--surface-3); color: var(--text); }


/* ================================================================
 * 4. Top bar and shared-link banner
 * ================================================================ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1600px;
  margin: 0 auto;
  padding: 28px var(--gutter) 28px;
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.wordmark-icon { width: 26px; height: 26px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.wordmark-icon circle { fill: var(--accent); stroke: none; }

.toolbar { display: flex; align-items: center; gap: 10px; }

.shared-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  max-width: calc(1600px - 2 * var(--gutter));
  margin: -8px var(--gutter) 24px;
  padding: 12px 12px 12px 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  font-size: .9rem;
}
@media (min-width: 1700px) { .shared-banner { margin-inline: auto; } }
.shared-actions { display: flex; gap: 8px; flex-wrap: wrap; }


/* ================================================================
 * 5. Clock cards
 * ================================================================ */

.clocks {
  display: grid;
  /* As many 270–350px columns as fit, centred like clocks on a wall. */
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 318px));
  justify-content: center;
  gap: 18px;
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 var(--gutter) 64px;
  outline: none;
}

.card {
  /* Text colour flips to dark on bright skies (set by app.js). */
  --ink: #F6F8FD;
  --ink-soft: rgba(246, 248, 253, .8);
  --ring: inset 0 0 0 1px rgba(255, 255, 255, .07);

  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--radius-card);
  color: var(--ink);
  background:
    radial-gradient(130% 60% at var(--sun-x, 50%) 34%, rgba(255, 196, 140, calc(var(--glow, 0) * .5)), transparent 62%),
    linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bottom) 100%);
  box-shadow: var(--ring);
  transition: --sky-top 3s ease, --sky-bottom 3s ease, transform .35s var(--ease-out), box-shadow .35s ease;
}
.card.on-light {
  --ink: #12203B;
  --ink-soft: rgba(18, 32, 59, .78);
}
.card.is-you { --ring: inset 0 0 0 1.5px var(--accent); }

@media (hover: hover) {
  .card:hover {
    transform: translateY(-4px);
    box-shadow: var(--ring), 0 22px 44px -22px var(--sky-bottom);
  }
}

/* Page-load entrance: fade and rise, one card after another. */
.card.is-entering { animation: card-in .75s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 80ms); }
@keyframes card-in {
  from { opacity: 0; transform: translateY(20px) scale(.98); }
}

.card.dragging {
  z-index: 10;
  cursor: grabbing;
  transition: box-shadow .2s ease;
  box-shadow: var(--ring), 0 30px 60px -20px rgba(0, 0, 0, .55);
}
body.is-dragging { cursor: grabbing; user-select: none; -webkit-user-select: none; }

/* --- The sky strip at the top of each card --- */

.sky { position: relative; height: 96px; flex-shrink: 0; }

.stars {
  position: absolute;
  inset: 0;
  opacity: var(--stars, 0);
  transition: opacity 3s ease;
  background-image:
    radial-gradient(1px 1px at 12% 22%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 27% 58%, rgba(255,255,255,.7) 50%, transparent 51%),
    radial-gradient(1.4px 1.4px at 41% 18%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 56% 44%, rgba(255,255,255,.6) 50%, transparent 51%),
    radial-gradient(1px 1px at 68% 14%, #fff 50%, transparent 51%),
    radial-gradient(1.4px 1.4px at 83% 36%, rgba(255,255,255,.8) 50%, transparent 51%),
    radial-gradient(1px 1px at 92% 12%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 6% 48%, rgba(255,255,255,.5) 50%, transparent 51%),
    radial-gradient(1px 1px at 74% 62%, rgba(255,255,255,.5) 50%, transparent 51%);
}

.sun-path { position: absolute; inset: 0; width: 100%; height: 100%; overflow: hidden; }
.path-line { fill: none; stroke: var(--ink); stroke-opacity: .32; stroke-width: 1; stroke-dasharray: 2 4; }
.horizon { stroke: var(--ink); stroke-opacity: .28; stroke-width: 1; }

.celestial {
  position: absolute;
  width: 30px;
  height: 30px;
  transform: translate(-50%, -50%);
  transition: left 1.2s var(--ease-out), top 1.2s var(--ease-out), opacity .8s ease;
}
.card:not(.is-day) .sun, .card.is-day .moon { opacity: 0; }

.sun svg { width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 0 6px rgba(255, 210, 130, .8)); }
.sun circle { fill: #FFD98F; }
.sun .rays { stroke: #FFD98F; stroke-width: 2.2; stroke-linecap: round; transform-origin: 20px 20px; animation: spin 60s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Crescent moon: a circle with its shadow cut out. */
.moon span {
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  box-shadow: inset -6px 3px 0 0 #F2EEDF;
  transform: rotate(-12deg);
  filter: drop-shadow(0 0 6px rgba(242, 238, 223, .45));
  animation: drift 7s ease-in-out infinite;
}
@keyframes drift { 50% { transform: rotate(-12deg) translateY(-2px); } }

/* --- Text and digits --- */

.card-body { display: flex; flex-direction: column; flex: 1; padding: 6px 24px 22px; }

.card-head { display: flex; align-items: center; gap: 10px; min-height: 34px; }

.card-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1.375rem;
  font-weight: 500;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

.you-badge {
  flex-shrink: 0;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: .75rem;
  font-weight: 600;
  line-height: 1.6;
}

.card-grip {
  margin-left: auto;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  margin-right: -8px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  opacity: 0;
  cursor: grab;
  touch-action: none; /* lets touch dragging work instead of scrolling */
  transition: opacity .2s ease, background-color .2s ease;
}
.card-grip svg { width: 18px; height: 18px; fill: currentColor; }
/* Fixed-list pages (clients.html) can't be reordered. */
.fixed-set .card-grip { display: none; }
.card:hover .card-grip, .card-grip:focus-visible, .card.dragging .card-grip { opacity: .7; }
.card-grip:hover { background: rgba(255, 255, 255, .12); opacity: 1; }
@media (hover: none) { .card-grip { opacity: .55; } }

.card-place {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-soft);
  font-size: .875rem;
}

.time {
  display: flex;
  align-items: flex-start;
  margin-top: 14px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.hm {
  display: inline-flex;
  font-size: clamp(3.5rem, 2.9rem + 1.6vw, 4.6rem);
  font-weight: 200;
  letter-spacing: -0.03em;
}

/* Each digit sits in a fixed-width slot, so digits never shift around. */
.slot {
  position: relative;
  display: inline-block;
  width: 0.64em;
  height: 1.08em;
  overflow: hidden;
  text-align: center;
}
.glyph { display: block; line-height: 1.08em; }
.glyph.enter { animation: roll-in .5s var(--ease-out) both; }
.glyph.leave { position: absolute; inset: 0; animation: roll-out .5s var(--ease-out) both; }
@keyframes roll-in { from { transform: translateY(65%); opacity: 0; filter: blur(2px); } }
@keyframes roll-out { to { transform: translateY(-65%); opacity: 0; filter: blur(2px); } }

.colon { display: inline-block; width: .28em; text-align: center; line-height: 1.08em; opacity: .55; transform: translateY(-.05em); }

.time-side {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-left: .55rem;
  padding-top: .55rem;
  color: var(--ink-soft);
}
.time-side .sec { display: inline-flex; font-size: 1.3rem; font-weight: 400; }
.time-side .sec .slot { width: .66em; }
.ampm { font-size: .72rem; font-weight: 600; letter-spacing: .04em; line-height: 1; }
.ampm:empty { display: none; }

.card-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 16px;
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid color-mix(in srgb, var(--ink) 20%, transparent);
  font-size: .875rem;
  font-variant-numeric: tabular-nums;
}
.time + .card-meta { margin-top: 18px; }
/* On wider screens: date on one line, offsets on the next, so all cards line up. */
@media (min-width: 641px) { .card-meta { flex-direction: column; } }
.card-day, .card-offset { display: flex; gap: .5em; white-space: nowrap; }
.rel, .diff { font-weight: 600; }
.date, .utc { color: var(--ink-soft); }

/* Shown when only your own clock is left. */
.card-empty {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 18px;
  min-height: 300px;
  padding: 28px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius-card);
  color: var(--muted);
  animation: card-in .6s var(--ease-out) both;
}
.card-empty p { max-width: 26ch; }


/* ================================================================
 * 6. Manage zones panel
 * ================================================================ */

.sheet {
  width: min(460px, 100vw);
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 0 0 auto;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sheet::backdrop { background: var(--backdrop); backdrop-filter: blur(2px); }
.sheet[open] { animation: sheet-in .42s var(--ease-out); }
.sheet[open]::backdrop { animation: fade-in .42s ease; }
.sheet.is-closing { animation: sheet-out .26s ease-in forwards; }
.sheet.is-closing::backdrop { animation: fade-in .26s ease-in reverse forwards; }
@keyframes sheet-in { from { transform: translateX(40px); opacity: 0; } }
@keyframes sheet-out { to { transform: translateX(40px); opacity: 0; } }
@keyframes fade-in { from { opacity: 0; } }

.sheet-inner { padding: 0 24px 40px; }

.sheet-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 -24px;
  padding: 20px 24px 16px;
  background: var(--surface);
}
.sheet-head h2 { font-size: 1.25rem; font-weight: 500; letter-spacing: -0.01em; }

.sheet-section { padding: 12px 0 20px; }
.sheet-section + .sheet-section { border-top: 1px solid var(--line); padding-top: 22px; }
.sheet-section h3 { font-size: 1rem; font-weight: 500; }

.section-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 32px; }

.field-label { display: block; margin-bottom: 8px; font-size: 1rem; font-weight: 500; }
.hint { margin-top: 6px; color: var(--muted); font-size: .8rem; line-height: 1.5; }

/* --- Search --- */

.search { position: relative; }
.search-icon {
  position: absolute; left: 14px; top: 50%;
  width: 19px; height: 19px;
  transform: translateY(-50%);
  fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round;
  pointer-events: none;
}

input[type='search'], input[type='text'] {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface-2);
  outline: none;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.search input { padding-left: 42px; }
input[type='search']::placeholder, input[type='text']::placeholder { color: var(--muted); opacity: 1; }
input[type='search']:focus, input[type='text']:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

.results {
  margin: 10px 0 0;
  padding: 4px;
  max-height: 344px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  list-style: none;
  animation: fade-in .2s ease;
}
.result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 10px;
  cursor: pointer;
}
.result[aria-selected='true'] { background: var(--surface-3); }
.result[aria-disabled='true'] { cursor: default; }
.result[aria-disabled='true'] .result-time { color: var(--muted); font-size: .8rem; }
.result-text { display: flex; flex-direction: column; min-width: 0; }
.result-name { font-weight: 500; }
.result-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: .8rem; }
.result-time { display: flex; flex-direction: column; align-items: flex-end; flex-shrink: 0; font-variant-numeric: tabular-nums; font-size: .95rem; }
.result-time small { color: var(--muted); font-size: .75rem; }
.result-empty { padding: 12px; color: var(--muted); font-size: .875rem; }

/* --- Your clocks list --- */

.zone-list { display: flex; flex-direction: column; gap: 8px; margin: 14px 0 0; padding: 0; list-style: none; }

.zone-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 62px;
  padding: 8px 8px 8px 4px;
  border-radius: 14px;
  background: var(--surface-2);
}
.zone-row.is-you { padding-left: 14px; padding-right: 14px; }
.zone-row.dragging { z-index: 5; background: var(--surface-3); box-shadow: 0 16px 36px -14px rgba(0, 0, 0, .5); }

.grip {
  display: grid;
  place-items: center;
  width: 30px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: grab;
  touch-action: none;
}
.grip:hover { color: var(--text); }
.grip svg { width: 18px; height: 18px; fill: currentColor; }

.swatch { flex-shrink: 0; width: 30px; height: 30px; border-radius: 9px; background: var(--surface-3); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08); }

.row-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.row-name { font-weight: 500; }
.zone-list .row-input {
  height: 32px;
  padding: 0 7px;
  margin-left: -7px;
  border-color: transparent;
  background: transparent;
  font-weight: 500;
}
.zone-list .row-input:hover { border-color: var(--line); }
.zone-list .row-input:focus { background: var(--surface); }
.row-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }

/* --- Presets --- */

.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.chip {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: transparent;
  text-align: left;
  transition: background-color .2s ease, border-color .2s ease;
}
.chip:hover { background: var(--surface-2); }
.chip-name { font-weight: 500; font-size: .95rem; }
.chip-sub { color: var(--muted); font-size: .75rem; line-height: 1.4; }

/* --- Map --- */

.map-wrap { margin-top: 12px; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; }
.map { display: block; width: 100%; height: auto; cursor: crosshair; touch-action: manipulation; }
.map:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 14px; }
.map-sea { fill: var(--map-sea); }
.map-land { fill: var(--map-land); }
.map-night { fill: var(--map-night); pointer-events: none; }
.map-dot { fill: var(--text); fill-opacity: .7; stroke: var(--map-sea); stroke-width: .6; }
.map-dot.is-you { fill: var(--accent); fill-opacity: 1; }
.map-pin { pointer-events: none; }
.map-pin-dot { fill: var(--accent); stroke: var(--map-sea); stroke-width: .7; }
.map-pin-halo { fill: var(--accent); opacity: .35; }

.pin-form { margin-top: 14px; }
.pin-result { display: flex; flex-direction: column; margin-bottom: 14px; font-size: .9rem; }
.pin-result span { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.pin-row { display: flex; gap: 8px; }
.pin-row .btn { height: 48px; flex-shrink: 0; }


/* ================================================================
 * 7. Wall mode: full screen, big digits, no controls
 * ================================================================ */

.wall-exit {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  display: none;
  background: var(--surface-2);
  border-color: var(--line);
}
body.wall .wall-exit { display: inline-flex; opacity: 0; pointer-events: none; transition: opacity .4s ease; }
body.wall.wall-awake .wall-exit { opacity: 1; pointer-events: auto; }
body.wall:not(.wall-awake) { cursor: none; }

body.wall .topbar,
body.wall .shared-banner,
body.wall .card-grip,
body.wall .card-empty { display: none !important; }

body.wall .clocks {
  min-height: 100vh;
  max-width: none;
  align-content: center;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
  gap: min(24px, 2.4vh);
  padding: min(32px, 3vh) 32px;
}
/* In wall mode the digits grow with each card's own width ("cqi" = 1% of it),
   so they're as big as possible without ever spilling out of the card. */
body.wall .card { container-type: inline-size; }
body.wall .card:hover { transform: none; box-shadow: var(--ring); }
body.wall .sky { height: min(120px, 9vh); }
body.wall .card-body { padding: 4px 28px min(28px, 2.6vh); }
body.wall .card-label { font-size: clamp(1.3rem, min(8cqi, 4vh), 2.4rem); }
/* Also limited by screen height ("vh"), so two rows still fit on a TV. */
body.wall .hm { font-size: clamp(3rem, min(22cqi, 10vh), 11rem); }
body.wall .time { margin-top: 1vh; }
body.wall .time + .card-meta { margin-top: 1.6vh; }
body.wall .time-side .sec { font-size: clamp(1.3rem, 6.5cqi, 3rem); }
body.wall .card-meta { font-size: 1rem; }


/* ================================================================
 * 8. Phones
 * ================================================================ */

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding-top: 20px; padding-bottom: 20px; }
  .toolbar { width: 100%; }
  .toolbar .btn-primary { margin-left: auto; }

  .clocks { grid-template-columns: 1fr; gap: 14px; }

  /* A shorter, wider card: sky strip, then name and time side by side. */
  .sky { height: 58px; }
  .card-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: 'head time' 'place time' 'meta meta';
    align-items: start;
    column-gap: 12px;
    padding: 0 18px 16px;
  }
  .card-head { grid-area: head; }
  .card-place { grid-area: place; }
  .card-meta { grid-area: meta; }
  .card-label { font-size: 1.15rem; }
  .card-grip { position: absolute; top: 10px; right: 12px; margin: 0; }
  .time { grid-area: time; margin-top: 0; align-self: center; }
  .hm { font-size: 2.9rem; }
  .time-side { margin-left: .35rem; padding-top: .35rem; }
  .time-side .sec { font-size: 1.05rem; }
  .time + .card-meta { margin-top: 12px; }
  .card-meta { padding-top: 10px; font-size: .82rem; }
  .card-empty { min-height: 180px; }

  .sheet { width: 100vw; border-left: 0; }
  .sheet-inner { padding: 0 16px 32px; }
  .sheet-head { margin: 0 -16px; padding: 16px 16px 12px; }
  .presets { grid-template-columns: 1fr; }
}

@media (max-width: 360px) {
  .seg { padding: 0 10px; }
  .toolbar { gap: 8px; }
}


/* ================================================================
 * 9. Reduced motion: no rolling, sliding, spinning or pulsing
 * ================================================================ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0s !important;
    transition-duration: .001ms !important;
  }
  .card:hover { transform: none; }
}
