:root {
  --bg: #fafaf7;
  --fg: #111;
  --muted: #666;
  --card: #fff;
  --border: #e6e6e0;
  --accent: #d33;
  --sea: #d8e6f2;
  --land: #f6f3ea;
  --land-stroke: #c8c4b6;
  --night: rgba(20, 24, 40, 0.55);
  --graticule: rgba(0, 0, 0, 0.06);
  --pin-fill: #d33;
  --pin-stroke: #fff;
  --slot-current-bg: #d33;
  --slot-current-fg: #fff;
  --slot-bad-bg:        #d33;
  --slot-bad-fg:        #fff;
  --slot-borderline-bg: hsl( 38, 95%, 55%);
  --slot-borderline-fg: #1a1300;
  --slot-good-bg:       hsl(140, 55%, 42%);
  --slot-good-fg:       #fff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e10;
    --fg: #f2f2f0;
    --muted: #8a8a88;
    --card: #18181b;
    --border: #27272a;
    --accent: #ff5555;
    --sea: #1a2232;
    --land: #2a2a2e;
    --land-stroke: #3f3f44;
    --night: rgba(0, 0, 0, 0.55);
    --graticule: rgba(255, 255, 255, 0.05);
    --pin-fill: #ff5555;
    --pin-stroke: #18181b;
    --slot-current-bg: #ff5555;
    --slot-current-fg: #18181b;
    --slot-bad-bg:        #ff5555;
    --slot-bad-fg:        #18181b;
    --slot-borderline-bg: hsl( 42, 90%, 60%);
    --slot-borderline-fg: #1a1300;
    --slot-good-bg:       hsl(140, 55%, 50%);
    --slot-good-fg:       #0d1b14;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-feature-settings: "tnum" 1, "lnum" 1;
}

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

/* Top hero row: local clock on the left third, world map on the right two
   thirds. Stacks vertically on narrow screens. */
.top {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.75rem 2rem;
  align-items: center;
  padding-bottom: 2rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}

/* Grid items default to min-width:auto, which would let the wide map push the
   clock column past its track; pin both to 0 so the 1fr/2fr split holds. */
.top > * { min-width: 0; }

@media (min-width: 760px) {
  .top { grid-template-columns: 1fr 2fr; }
  .local-time { font-size: clamp(2.25rem, 4.5vw, 4rem); }
}

.local {
  text-align: center;
}

.local-label {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.local-time {
  font-size: clamp(2.75rem, 11vw, 5rem);
  font-weight: 200;
  line-height: 1;
  letter-spacing: -0.02em;
}

.local-time .sec {
  color: var(--muted);
  font-weight: 200;
  font-size: 0.5em;
  vertical-align: 0.35em;
  letter-spacing: 0;
  margin-left: 0.05em;
}

.local-meta {
  margin-top: 0.75rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.cities {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .cities { grid-template-columns: 1fr 1fr; }
}

.city {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.25rem 1.4rem;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.5rem 1rem;
  cursor: pointer;
}

/* Whole-tile link to the city's detail page (stretched-link pattern). */
.city-link {
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: inherit;
}
.city-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.city:hover {
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.09);
}

.city-name {
  font-size: 1.05rem;
  font-weight: 600;
}

.city-zone {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 400;
  margin-top: 0.15rem;
}

.city-time {
  font-size: 2rem;
  font-weight: 300;
  letter-spacing: -0.01em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.city-time .sec {
  color: var(--muted);
  font-weight: 300;
  font-size: 0.6em;
  vertical-align: 0.3em;
  margin-left: 0.05em;
}

.city-date {
  font-size: 0.85rem;
  color: var(--muted);
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  border-top: 1px dashed var(--border);
  padding-top: 0.6rem;
  margin-top: 0.2rem;
}

.city-offset {
  font-variant-numeric: tabular-nums;
}

/* Sun times + weather row. Sits below the date row, full width. */
.city-extra {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.2rem 1rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.city-sun {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem 0.7rem;
  font-variant-numeric: tabular-nums;
}

.sun-ev {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.sun-daylight {
  opacity: 0.8;
}

.sun-ico {
  width: 1.05em;
  height: 1.05em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
  opacity: 0.85;
}

.city-weather {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Meeting-quality tint on each city tile. Mirrors the slot table's
   traffic-light bands (red = asleep, amber = edge of day, green = work day)
   so you can tell at a glance which cities are a reasonable hour to meet.
   The colour is recomputed every tick, so it tracks the time-shift slider. */
.city {
  transition: background 0.2s ease, border-color 0.2s ease;
}
.city[data-quality="good"] {
  background: color-mix(in srgb, var(--slot-good-bg) 14%, var(--card));
  border-color: color-mix(in srgb, var(--slot-good-bg) 45%, var(--border));
}
.city[data-quality="borderline"] {
  background: color-mix(in srgb, var(--slot-borderline-bg) 16%, var(--card));
  border-color: color-mix(in srgb, var(--slot-borderline-bg) 50%, var(--border));
}
.city[data-quality="bad"] {
  background: color-mix(in srgb, var(--slot-bad-bg) 13%, var(--card));
  border-color: color-mix(in srgb, var(--slot-bad-bg) 40%, var(--border));
}
/* Weekend overrides the band — same rule as the slot table: a good hour on a
   Saturday is still a poor time to ask for a work meeting. */
.city.is-weekend {
  background: color-mix(in srgb, var(--muted) 10%, var(--card));
  border-color: var(--border);
}

/* Legend explaining the tile colours. */
.cities-legend {
  margin: 0.9rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem 1rem;
}
.cities-legend .key {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
}
.cities-legend .dot {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  flex: none;
}
.cities-legend .dot-good       { background: var(--slot-good-bg); }
.cities-legend .dot-borderline { background: var(--slot-borderline-bg); }
.cities-legend .dot-bad        { background: var(--slot-bad-bg); }
.cities-legend .dot-weekend    { background: color-mix(in srgb, var(--muted) 45%, transparent); }

/* Time shift slider — full width, centre-out fill, modern thumb */

.time-shift {
  width: 100%;
  margin: 0 0 2.25rem;
}

.slider-rail {
  position: relative;
  height: 32px;
  width: 100%;
}

.slider-track,
.slider-fill {
  position: absolute;
  top: 50%;
  height: 6px;
  border-radius: 999px;
  transform: translateY(-50%);
  pointer-events: none;
}

.slider-track {
  left: 0;
  right: 0;
  background: linear-gradient(
    to right,
    color-mix(in srgb, var(--border) 60%, transparent) 0%,
    var(--border) 50%,
    color-mix(in srgb, var(--border) 60%, transparent) 100%
  );
}

.slider-fill {
  background: linear-gradient(
    to right,
    color-mix(in srgb, var(--accent) 70%, transparent),
    var(--accent),
    color-mix(in srgb, var(--accent) 70%, transparent)
  );
  left: var(--fill-left, 50%);
  width: var(--fill-width, 0%);
  transition: left 0.06s ease, width 0.06s ease;
  z-index: 1;
}

.slider-zero {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 14px;
  background: var(--muted);
  opacity: 0.55;
  transform: translate(-50%, -50%);
  border-radius: 1px;
  pointer-events: none;
  z-index: 2;
}

#time-slider {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  margin: 0;
  cursor: grab;
  z-index: 3;
}
#time-slider:active { cursor: grabbing; }

#time-slider::-webkit-slider-runnable-track {
  height: 32px;
  background: transparent;
  border: none;
}
#time-slider::-moz-range-track {
  height: 32px;
  background: transparent;
  border: none;
}

#time-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--card);
  border: 2px solid var(--accent);
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.08),
    0 4px 12px rgba(0, 0, 0, 0.10);
  margin-top: 5px;
  transition: transform 0.12s ease, box-shadow 0.15s ease;
  cursor: grab;
}
#time-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--card);
  border: 2px solid var(--accent);
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.08),
    0 4px 12px rgba(0, 0, 0, 0.10);
  transition: transform 0.12s ease, box-shadow 0.15s ease;
  cursor: grab;
}
#time-slider:hover::-webkit-slider-thumb { transform: scale(1.08); }
#time-slider:hover::-moz-range-thumb     { transform: scale(1.08); }
#time-slider:active::-webkit-slider-thumb {
  transform: scale(1.18);
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.10),
    0 6px 18px rgba(0, 0, 0, 0.18),
    0 0 0 8px color-mix(in srgb, var(--accent) 18%, transparent);
  cursor: grabbing;
}
#time-slider:active::-moz-range-thumb {
  transform: scale(1.18);
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.10),
    0 6px 18px rgba(0, 0, 0, 0.18),
    0 0 0 8px color-mix(in srgb, var(--accent) 18%, transparent);
  cursor: grabbing;
}
#time-slider:focus-visible::-webkit-slider-thumb {
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.08),
    0 4px 12px rgba(0, 0, 0, 0.10),
    0 0 0 4px color-mix(in srgb, var(--accent) 35%, transparent);
}
#time-slider:focus-visible::-moz-range-thumb {
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.08),
    0 4px 12px rgba(0, 0, 0, 0.10),
    0 0 0 4px color-mix(in srgb, var(--accent) 35%, transparent);
}
#time-slider:focus { outline: none; }

.slider-ticks {
  position: relative;
  height: 1.4rem;
  margin-top: 0.4rem;
}
.slider-ticks span {
  position: absolute;
  transform: translateX(-50%);
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
  letter-spacing: 0.04em;
}
.slider-ticks span::before {
  content: "";
  display: block;
  width: 1px;
  height: 5px;
  background: var(--border);
  margin: 0 auto 3px;
}

.time-shift-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 0.6rem;
  font-size: 0.9rem;
  flex-wrap: wrap;
  min-height: 1.8rem;
}

.time-shift-value {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: var(--muted);
}

.time-shift-value.is-shifted {
  color: var(--accent);
  font-weight: 600;
}

.time-shift-reset {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s, color 0.15s;
}

.time-shift-reset:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* World map */

.world {
  margin-top: 0;
}

.world h2,
.slots h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 500;
  margin: 0 0 0.75rem;
}

.world-map {
  width: 100%;
  height: auto;
  display: block;
  background: var(--sea);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.world-map .sea       { fill: var(--sea); }
.world-map .land      { fill: var(--land); stroke: var(--land-stroke); stroke-width: 0.4; vector-effect: non-scaling-stroke; }
.world-map .night     { fill: var(--night); pointer-events: none; }

/* Meeting-quality bands: translucent full-height stripes by local civil time
   (same traffic-light bands as the slot table and city tiles). They sweep west
   with the slider, so you can see at a glance which longitudes are in work
   hours. The "asleep" band is omitted — the night terminator already shows it. */
.world-map .quality-bands rect { pointer-events: none; }
.world-map .quality-bands rect[data-quality="good"]       { fill: var(--slot-good-bg);       opacity: 0.20; }
.world-map .quality-bands rect[data-quality="borderline"] { fill: var(--slot-borderline-bg); opacity: 0.22; }
.world-map .quality-bands rect[data-quality="weekend"]    { fill: var(--muted);              opacity: 0.22; }
.world-map .graticule line { stroke: var(--graticule); stroke-width: 0.5; vector-effect: non-scaling-stroke; }

.world-map .pins circle {
  fill: var(--pin-fill);
  stroke: var(--pin-stroke);
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
}

.world-map .pins text {
  font-size: 9px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 600;
  fill: var(--fg);
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 3;
  stroke-linejoin: round;
}

.world-meta {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

/* Slot table */

.slots {
  margin-top: 2.5rem;
}

.slots-scroll {
  overflow-x: auto;
}

.slot-table {
  border-collapse: collapse;
  width: 100%;
  min-width: 560px;
  font-variant-numeric: tabular-nums;
}

.slot-table th,
.slot-table td {
  padding: 0.55rem 0.6rem;
  text-align: center;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}

.slot-table th:first-child,
.slot-table td:first-child {
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
}

.slot-table th {
  font-weight: 500;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
}

.slot-table td.is-current {
  background: var(--slot-current-bg);
  color: var(--slot-current-fg);
  font-weight: 600;
  border-radius: 4px;
}

/* "Bad" slots (00–03, 03–06) keep a subtle greyed-out background so the
   sleep windows are visually distinct even before the highlight lands
   there. */
.slot-table th[data-quality="bad"],
.slot-table td[data-quality="bad"] {
  color: color-mix(in srgb, var(--muted) 80%, transparent);
  background: color-mix(in srgb, var(--muted) 8%, transparent);
}

/* The moving highlight is what signals meeting quality. As the slider
   scrubs the time, the lit cell travels across each row and changes
   colour with the underlying slot: red = sleep, amber = edge of day,
   green = work day. */
.slot-table td[data-quality="bad"].is-current {
  background: var(--slot-bad-bg);
  color: var(--slot-bad-fg);
  font-weight: 600;
}
.slot-table td[data-quality="borderline"].is-current {
  background: var(--slot-borderline-bg);
  color: var(--slot-borderline-fg);
  font-weight: 600;
}
.slot-table td[data-quality="good"].is-current {
  background: var(--slot-good-bg);
  color: var(--slot-good-fg);
  font-weight: 600;
}

/* Day-of-week column. */
.slot-table .city-dow {
  font-weight: 500;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* User's own city — bold so it stands out as a reference row. Detected
   from Intl.DateTimeFormat().resolvedOptions().timeZone matching one of
   the city zones exactly. */
.slot-table tr.is-user th[scope="row"],
.slot-table tr.is-user .city-dow {
  font-weight: 700;
  color: var(--fg);
}

.slot-table tr.is-user th[scope="row"] {
  border-left: 3px solid var(--accent);
  padding-left: calc(0.6rem - 3px);
}

.you-tag {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.05rem 0.4rem;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--bg);
  background: var(--accent);
  border-radius: 999px;
  vertical-align: 1px;
}

/* Weekend rows: when the city's local day is Sat or Sun, the whole row
   is greyed out — overrides the traffic-light tint, since "good slot
   on a Saturday" is still a bad time to ask for a meeting. */
.slot-table tr.is-weekend th[scope="row"],
.slot-table tr.is-weekend td {
  color: color-mix(in srgb, var(--muted) 80%, transparent);
  background: color-mix(in srgb, var(--muted) 9%, transparent);
}

.slot-table tr.is-weekend .city-dow {
  color: var(--muted);
  font-weight: 600;
}

/* Weekend + bad slot is the most muted state. */
.slot-table tr.is-weekend td[data-quality="bad"] {
  background: color-mix(in srgb, var(--muted) 14%, transparent);
}

/* Highlight on a weekend row is always dimmed regardless of slot quality. */
.slot-table tr.is-weekend td.is-current,
.slot-table tr.is-weekend td[data-quality="bad"].is-current,
.slot-table tr.is-weekend td[data-quality="borderline"].is-current,
.slot-table tr.is-weekend td[data-quality="good"].is-current {
  background: color-mix(in srgb, var(--accent) 30%, transparent);
  color: color-mix(in srgb, var(--slot-current-fg) 75%, transparent);
  font-weight: 500;
}

footer {
  margin-top: 3rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
}

footer .muted { margin-top: 0.4rem; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.85em;
}
