/* ============================================================== contract
   Structure only. Every colour, face and radius comes from a token that
   themes.css defines per theme; nothing here hard-codes a look.
   ====================================================================== */

:root {
  --radius: 10px;
  --gap: 14px;
  --font-ui: system-ui, sans-serif;
  --font-display: var(--font-ui);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-variant-numeric: lining-nums tabular-nums;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.app { display: flex; flex-direction: column; height: 100%; }

svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.gh-icon { fill: currentColor; stroke: none; }
.arrow { fill: currentColor; stroke: none; width: 12px; height: 12px; flex: 0 0 auto; }

/* ---------------------------------------------------------------- toolbar */
.toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
}
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--control-line);
  border-radius: 6px;
  background: var(--control-bg);
  color: var(--fg);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.small { width: 26px; height: 26px; border: 0; background: none; color: var(--fg-mute); }
.icon-btn:hover { background: var(--control-bg-hover); }
.icon-btn[aria-pressed="false"] { color: var(--fg-mute); }
.icon-btn[aria-pressed="false"] .rays { opacity: 0.35; }

.segmented { display: flex; padding: 2px; border-radius: 7px; background: var(--control-bg); }
.segmented button {
  min-width: 30px;
  padding: 3px 7px;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--fg-mute);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }

.text-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  padding: 0 9px;
  border: 1px solid var(--control-line);
  border-radius: 6px;
  background: var(--control-bg);
  color: var(--fg);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}
.text-btn:hover { background: var(--control-bg-hover); }
.text-btn svg { width: 13px; height: 13px; }

/* ----------------------------------------------------------- theme picker */
.picker { position: relative; }

.swatch {
  display: flex;
  width: 26px;
  height: 14px;
  overflow: hidden;
  border-radius: 3px;
  border: 1px solid var(--control-line);
}
.swatch i { flex: 1 1 auto; }

.picker-menu {
  position: absolute;
  top: calc(100% + 7px);
  right: 0;
  z-index: 40;
  min-width: 232px;
  padding: 5px;
  border: 1px solid var(--menu-line);
  border-radius: 10px;
  background: var(--menu-bg);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.35);
}
.picker-menu[hidden] { display: none; }

.picker-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 9px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.picker-menu button:hover { background: var(--control-bg-hover); }
.picker-menu button[aria-checked="true"] { background: var(--accent); color: var(--accent-fg); }
.picker-menu button[aria-checked="true"] .picker-blurb { color: var(--accent-fg); opacity: 0.8; }
.picker-name { font-weight: 500; }
.picker-blurb { display: block; color: var(--fg-mute); font-size: 11.5px; font-weight: 400; }

.settings-menu { min-width: 262px; padding: 11px 13px 13px; }
.settings-note { margin: 0 0 9px; color: var(--fg-mute); font-size: 11.5px; line-height: 1.4; }
.settings-rule { margin: 11px 0 9px; border: 0; border-top: 1px solid var(--menu-line); }

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
  font-size: 13px;
}
.settings-row select {
  min-width: 96px;
  padding: 3px 6px;
  border: 1px solid var(--control-line);
  border-radius: 5px;
  background: var(--control-bg);
  color: var(--fg);
  font: inherit;
  font-size: 12.5px;
}
.settings-check { justify-content: flex-start; }
.settings-check input { accent-color: var(--accent); }

/* Cities that share an offset sit together when sorted west to east. */
.strip[data-sort="offset"] .city[data-offset-break="true"] { box-shadow: inset 2px 0 0 var(--line); }

/* ------------------------------------------------------------ city strip */
.strip-wrap {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  padding: 0 var(--gap) var(--gap);
}

.strip {
  display: flex;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.strip::-webkit-scrollbar { display: none; }

.city { position: relative; cursor: grab; }
.city:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; z-index: 1; }
.city:focus:not(:focus-visible) { outline: none; }
.name-arrow[hidden], .band-sun[hidden] { display: none; }

/* The day caption always occupies its line so the strip cannot change height
   when a city crosses midnight; only its ink comes and goes. */
.city-dayoff.is-empty { visibility: hidden; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.city.dragging { opacity: 0.4; }
.city.drop-target { box-shadow: inset 3px 0 0 var(--accent); }

.city-remove {
  position: absolute;
  top: 6px;
  left: 6px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: inherit;
  opacity: 0;
  cursor: pointer;
  transition: opacity 0.12s ease;
}
.city-remove svg { width: 11px; height: 11px; stroke-width: 1.9; }
.city:hover .city-remove,
.city:focus-visible .city-remove { opacity: 0.7; }
.city-remove:hover { opacity: 1; }

.city-name { display: flex; align-items: center; gap: 5px; }
.city-sub { position: relative; }
.city-sub .sub-offset { display: none; }
.city:hover .city-sub .sub-country,
.city:focus-visible .city-sub .sub-country { display: none; }
.city:hover .city-sub .sub-offset,
.city:focus-visible .city-sub .sub-offset { display: inline; }

.clock { display: inline-flex; align-items: flex-start; }
.clock .meridiem { font-size: 0.32em; font-weight: 400; opacity: 0.75; margin: 0.22em 0 0 0.12em; }

.strip-empty { margin: 28px 0; color: var(--fg-mute); font-size: 14px; }
.strip-empty kbd {
  padding: 1px 6px;
  border: 1px solid var(--control-line);
  border-radius: 4px;
  font-family: inherit;
}

/* ------------------------------------------------------- the sunlight band */
.band {
  position: relative;
  overflow: hidden;
  border-radius: 3px;
}
.band-now {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  margin-left: -1px;
  background: var(--band-now);
  box-shadow: 0 0 0 1px var(--band-now-halo);
}
.band-sun {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--band-sun);
}

/* ------------------------------------------------------------------- map */
.map-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: var(--map-ocean);
  cursor: grab;
  touch-action: pan-y;
}
.map-wrap.scrubbing { cursor: grabbing; }
.map-wrap.scrubbing .pin { transition: none; }

.map-canvas { display: block; width: 100%; height: 100%; }
.pin-layer { position: absolute; inset: 0; pointer-events: none; }

.pin { position: absolute; width: 0; height: 0; transition: opacity 0.15s ease; }
.pin-dot {
  position: absolute;
  left: -4px;
  top: -4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--pin-dim);
}
.pin-arrow { position: absolute; left: -6px; top: -6px; width: 12px; height: 12px; color: var(--pin-dim); }
.pin-arrow svg { width: 100%; height: 100%; fill: currentColor; stroke: none; }

.pin-label { position: absolute; left: 12px; line-height: 1.2; text-align: left; white-space: nowrap; }
.pin.flip .pin-label { left: auto; right: 12px; text-align: right; }

.pin-time { font-size: 15px; color: var(--pin-dim); }
.pin-city { font-size: 11.5px; font-weight: 500; color: var(--pin-city); }
.pin-country { font-size: 11px; color: var(--pin-country); }

.pin[data-state="work"] .pin-dot { background: var(--pin-work); }
.pin[data-state="work"] .pin-arrow { color: var(--pin-work); }
.pin[data-state="work"] .pin-time { color: var(--pin-work); }
.pin[data-state="awake"] .pin-dot { background: var(--pin-awake); }
.pin[data-state="awake"] .pin-arrow { color: var(--pin-awake); }
.pin[data-state="awake"] .pin-time { color: var(--pin-awake); }

.pin.off-map { opacity: 0.6; }
.pin.off-map .pin-dot { border-radius: 2px; }
.pin.is-hot { filter: drop-shadow(0 0 7px var(--pin-glow)); }
.pin.is-cold { opacity: 0.38; }

.share-btn {
  position: absolute;
  bottom: 18px;
  left: 50%;
  display: grid;
  place-items: center;
  width: 42px;
  height: 34px;
  transform: translateX(-50%);
  padding: 0;
  border: 1px solid var(--control-line);
  border-radius: 8px;
  background: var(--float-bg);
  color: var(--fg);
  cursor: pointer;
  transition: opacity 0.16s ease;
}
.share-btn svg { width: 19px; height: 19px; }

/* -------------------------------------------------------------- time bar */
.timebar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0 0 4px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.16s ease, transform 0.16s ease;
  pointer-events: none;
}
.map-wrap.reveal .timebar,
.timebar[data-travelling="true"] { opacity: 1; transform: none; pointer-events: auto; }
.map-wrap.reveal .share-btn,
.map-wrap:has(.timebar[data-travelling="true"]) .share-btn { opacity: 0; pointer-events: none; }

.timebar-actions { display: flex; justify-content: center; gap: 8px; margin-bottom: 8px; }

.tb-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 13px;
  border: 1px solid var(--control-line);
  border-radius: 7px;
  background: var(--float-bg);
  color: var(--fg);
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
}
.tb-btn:hover:not(:disabled) { background: var(--control-bg-hover); }
.tb-btn:disabled { opacity: 0.4; cursor: default; }
.tb-btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-fg); }
.tb-icon { width: 14px; height: 14px; }

.ruler {
  position: relative;
  height: 40px;
  margin: 0 8px;
  border-radius: 6px;
  background: var(--ruler-bg);
  cursor: ew-resize;
  touch-action: none;
  outline: none;
}
.ruler:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.ruler-ticks { position: absolute; inset: 0; overflow: hidden; }

.tick { position: absolute; bottom: 0; width: 1px; height: 6px; background: var(--tick); }
.tick.mid { height: 9px; background: var(--tick-strong); }
.tick.major { height: 40px; background: var(--tick-day); }

.tick-label {
  position: absolute;
  bottom: 7px;
  transform: translateX(-50%);
  color: var(--fg-mute);
  font-size: 10.5px;
  white-space: nowrap;
}
.tick-dayedge { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--tick-strong); }
.tick-dayname {
  position: absolute;
  top: 1px;
  margin-left: 5px;
  color: var(--fg-mute);
  font-size: 10px;
  white-space: nowrap;
}

.ruler-line { position: absolute; bottom: 12px; height: 2px; border-radius: 1px; pointer-events: none; }
.ruler-line[data-dir="future"] { background: var(--accent); }
.ruler-line[data-dir="past"] { background: var(--past); }
.ruler-line[data-dir="none"] { background: none; }

.ruler-handle {
  position: absolute;
  bottom: 4px;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 18px;
  padding: 0 3px 0 7px;
  border-radius: 9px;
  background: var(--handle-bg);
  color: var(--handle-fg);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  transform: translateX(-50%);
  pointer-events: none;
}
.ruler-handle[data-dir="future"] { background: var(--accent); color: var(--accent-fg); }
.ruler-handle[data-dir="past"] { background: var(--past); color: var(--past-fg); }

.handle-clear {
  display: grid;
  place-items: center;
  width: 14px;
  height: 14px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.22);
  color: inherit;
  cursor: pointer;
  pointer-events: auto;
}
.handle-clear svg { width: 8px; height: 8px; stroke-width: 2.4; }
.ruler-handle[data-dir="none"] .handle-clear { display: none; }

.share-btn, .tb-btn, .handle-clear, .icon-btn, .segmented button { cursor: pointer; }

/* --------------------------------------------------------------- overlay */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
  background: var(--scrim);
  z-index: 50;
}
.overlay[hidden] { display: none; }

.search-panel {
  width: min(520px, calc(100% - 32px));
  overflow: hidden;
  border: 1px solid var(--menu-line);
  border-radius: 12px;
  background: var(--menu-bg);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.search-input-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 12px;
  border-bottom: 1px solid var(--menu-line);
}
.search-icon { width: 17px; height: 17px; flex: 0 0 auto; color: var(--fg-mute); }

#search-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: none;
  color: var(--fg);
  font: inherit;
  font-size: 15.5px;
  outline: none;
}
#search-input::placeholder { color: var(--fg-mute); }
#search-input::-webkit-search-cancel-button { display: none; }

.search-results {
  max-height: min(48vh, 360px);
  margin: 0;
  padding: 5px;
  overflow-y: auto;
  list-style: none;
}
.search-results:empty { display: none; }
.search-results li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
}
.search-results li[aria-selected="true"] { background: var(--accent); }
.search-results li[aria-selected="true"] .res-country,
.search-results li[aria-selected="true"] .res-time,
.search-results li[aria-selected="true"] .res-name { color: var(--accent-fg); }

.res-name { font-size: 14.5px; font-weight: 500; color: var(--fg); }
.res-country { flex: 1 1 auto; font-size: 12.5px; color: var(--fg-mute); }
.res-time { font-size: 13.5px; color: var(--fg-mute); }
.res-added { font-size: 12px; color: var(--accent); }
.search-hint { margin: 0; padding: 9px 13px 11px; color: var(--fg-mute); font-size: 12.5px; }

/* ----------------------------------------------------------------- toast */
.toast {
  position: fixed;
  bottom: 62px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 15px;
  border-radius: 8px;
  background: var(--menu-bg);
  border: 1px solid var(--menu-line);
  color: var(--fg);
  font-size: 13px;
  z-index: 60;
}
.toast[hidden] { display: none; }

/* ----------------------------------------------------------- small width */
@media (max-width: 760px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100%; }
  .strip-wrap { padding: 0 10px 12px; }
  .map-wrap { flex: 0 0 auto; height: auto; overflow: visible; background: none; }
  .map-canvas { height: 50vw; min-height: 170px; }
  .pin-country { display: none; }
  .pin-city { font-size: 10.5px; }
  .pin-time { font-size: 13px; }
  .share-btn { display: none; }
  .timebar { position: static; padding: 12px 0 16px; opacity: 1; transform: none; pointer-events: auto; }
  .ruler { height: 44px; }
  .picker-menu { right: auto; left: 50%; transform: translateX(-50%); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
