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

:root {
  --a:        #2563eb;
  --b:        #059669;
  --overlap:  #7c3aed;
  --none:     #dc2626;
  /* theme tokens */
  --bg:       #f8fafc;
  --card:     #ffffff;
  --border:   #e2e8f0;
  --text:     #0f172a;
  --muted:    #64748b;
  --track-bg: #f1f5f9;
  --hover-bg: #f1f5f9;
  --radius:   12px;
  --shadow:   0 1px 2px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:       #0f172a;
    --card:     #1e293b;
    --border:   #334155;
    --text:     #f1f5f9;
    --muted:    #94a3b8;
    --track-bg: #111827;
    --hover-bg: #2d3f55;
    --shadow:   0 1px 2px rgba(0,0,0,.4), 0 4px 12px rgba(0,0,0,.3);
  }
}

[data-theme="light"] {
  --bg:       #f8fafc;
  --card:     #ffffff;
  --border:   #e2e8f0;
  --text:     #0f172a;
  --muted:    #64748b;
  --track-bg: #f1f5f9;
  --hover-bg: #f1f5f9;
  --shadow:   0 1px 2px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.06);
}

[data-theme="dark"] {
  --bg:       #0f172a;
  --card:     #1e293b;
  --border:   #334155;
  --text:     #f1f5f9;
  --muted:    #94a3b8;
  --track-bg: #111827;
  --hover-bg: #2d3f55;
  --shadow:   0 1px 2px rgba(0,0,0,.4), 0 4px 12px rgba(0,0,0,.3);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

#app {
  max-width: 680px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 3rem;
}

/* ── Header ── */

header {
  text-align: center;
  margin-bottom: 2.25rem;
}

.header-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

#github-link {
  display: flex;
  align-items: center;
  padding: 0.3rem 0.4rem;
  color: var(--muted);
  border: 1.5px solid var(--border);
  border-radius: 7px;
  text-decoration: none;
  transition: border-color 0.12s, color 0.12s;
}

#github-link:hover {
  border-color: var(--a);
  color: var(--a);
}

#theme-btn {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  padding: 0.3rem 0.5rem;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  transition: border-color 0.12s, color 0.12s;
}

#theme-btn:hover {
  border-color: var(--a);
  color: var(--a);
}

h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.tagline {
  color: var(--muted);
  font-size: 0.875rem;
  margin-top: 0.3rem;
}

/* ── Pickers ── */

.pickers {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.picker {
  flex: 1;
  position: relative;
}

.picker label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.picker input {
  width: 100%;
  padding: 0.55rem 0.8rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: var(--card);
  color: var(--text);
  outline: none;
  transition: border-color 0.12s;
}

.picker input:focus {
  border-color: var(--a);
}

.picker-list {
  position: absolute;
  top: calc(100% + 3px);
  left: 0;
  right: 0;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  list-style: none;
  z-index: 200;
  overflow: hidden;
}

.picker-list[hidden] { display: none; }

.picker-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
  font-size: 0.85rem;
  gap: 0.5rem;
}

.picker-list li:hover,
.picker-list li.active { background: var(--hover-bg); }

.picker-list li.ac-group-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0.4rem 0.8rem 0.2rem;
  cursor: default;
  pointer-events: none;
}

.city-label { flex: 1; }

.city-country {
  font-size: 0.75rem;
  color: var(--muted);
  margin-left: 0.35rem;
}

.city-offset {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

#swap-btn {
  flex-shrink: 0;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  font-size: 1rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  transition: border-color 0.12s, color 0.12s;
  margin-bottom: 1px;
}

#swap-btn:hover {
  border-color: var(--a);
  color: var(--a);
}

/* ── Extra pickers ── */

#extra-pickers { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 0.25rem; }

.extra-picker-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}

.extra-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-bottom: 10px;
}

.extra-picker-input input {
  width: 100%;
  padding: 0.55rem 0.8rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: var(--card);
  color: var(--text);
  outline: none;
  transition: border-color 0.12s;
}

.extra-picker-input input:focus { border-color: var(--a); }

.move-btns {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
  margin-bottom: 1px;
}

.move-btn {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 5px;
  padding: 0 0.35rem;
  font-size: 0.65rem;
  line-height: 1.6;
  cursor: pointer;
  color: var(--muted);
  transition: border-color 0.12s, color 0.12s;
}

.move-btn:hover:not(:disabled) { border-color: var(--a); color: var(--a); }
.move-btn:disabled { opacity: 0.25; cursor: default; }

.remove-city-btn {
  flex-shrink: 0;
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  margin-bottom: 1px;
  transition: border-color 0.12s, color 0.12s;
}

.remove-city-btn:hover { border-color: var(--none); color: var(--none); }

.picker-footer { margin-bottom: 1rem; }

.add-city-btn {
  background: none;
  border: 1.5px dashed var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.85rem;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--muted);
  transition: border-color 0.12s, color 0.12s;
}

.add-city-btn:hover { border-color: var(--a); color: var(--a); }

/* ── View toggle ── */

.view-toggle {
  display: flex;
  gap: 2px;
  background: var(--track-bg);
  border-radius: 8px;
  padding: 3px;
  width: fit-content;
  margin-bottom: 1rem;
}

.view-btn {
  background: none;
  border: none;
  border-radius: 6px;
  padding: 0.3rem 0.85rem;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--muted);
  transition: background 0.12s, color 0.12s;
}

.view-btn.active {
  background: var(--card);
  color: var(--text);
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

/* ── Settings popover ── */

.settings-wrap {
  position: relative;
}

#settings-btn {
  display: flex;
  align-items: center;
  padding: 0.3rem 0.4rem;
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
  color: var(--muted);
  transition: border-color 0.12s, color 0.12s;
}

#settings-btn:hover,
#settings-btn[aria-expanded="true"] {
  border-color: var(--a);
  color: var(--a);
}

.settings-popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 0.85rem 1rem;
  z-index: 300;
  min-width: 220px;
}

.settings-popover[hidden] { display: none; }

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.settings-lbl {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.hours-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.hours-dash { color: var(--muted); font-size: 0.85rem; }

.hour-select {
  flex: 1;
  padding: 0.42rem 0.45rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.82rem;
  background: var(--card);
  color: var(--text);
  outline: none;
  cursor: pointer;
  transition: border-color 0.12s;
  font-family: inherit;
}

.hour-select:focus { border-color: var(--a); }

/* ── Simple view ── */

.simple-times-block {
  padding: 0 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.simple-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
}

.simple-city { font-weight: 500; min-width: 90px; }

.simple-tz {
  font-size: 0.72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  flex: 1;
}

.simple-time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.simple-bar-wrap {
  padding: 0 1.5rem 1.25rem;
}

.simple-bar-track {
  height: 12px;
  background: var(--track-bg);
  border-radius: 99px;
  position: relative;
  cursor: crosshair;
  user-select: none;
}

.simple-bar-fill {
  position: absolute;
  top: 0;
  height: 100%;
  background: var(--overlap);
  border-radius: 99px;
  opacity: 0.85;
}

.simple-ticks {
  position: relative;
  height: 14px;
  margin-top: 2px;
}

.simple-tick {
  position: absolute;
  font-size: 0.6rem;
  color: var(--muted);
  transform: translateX(-50%);
  white-space: nowrap;
  user-select: none;
}

/* ── Result ── */

.hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 3rem 0;
}

.card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.card-summary {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  gap: 2rem;
}

.current-times {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
}

.cur-city {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.cur-t {
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-weight: 500;
}

.overlap-num {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--overlap);
  margin-bottom: 0.6rem;
}

.no-overlap-num {
  font-size: 1rem;
  font-weight: 600;
  color: var(--none);
  margin-bottom: 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.no-overlap-num::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--none);
  opacity: 0.75;
  flex-shrink: 0;
}

.no-overlap-note {
  color: var(--muted);
  font-size: 0.82rem;
}

.overlap-times { display: flex; flex-direction: column; gap: 0.45rem; }

.ot-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.875rem;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-a { background: var(--a); }
.dot-b { background: var(--b); }

.ot-city { font-weight: 500; min-width: 90px; }

.ot-range {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ── Timeline ── */

.card-timeline { padding: 1rem 1.5rem 1.25rem; }

.timeline { display: flex; flex-direction: column; gap: 5px; }

.tl-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.tl-lbl {
  width: 88px;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
  text-align: right;
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
}

.tl-tz {
  font-size: 0.6rem;
  font-weight: 400;
  color: var(--muted);
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}

.tl-track {
  flex: 1;
  height: 26px;
  background: var(--track-bg);
  border-radius: 5px;
  position: relative;
  overflow: visible;
  cursor: crosshair;
  user-select: none;
}

.tl-bar {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 5px;
}

.bar-a       { background: var(--a); opacity: 0.25; }
.bar-b       { background: var(--b); opacity: 0.25; }
.bar-overlap { background: var(--overlap); opacity: 0.85; z-index: 2; }

.now-line {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  background: #ef4444;
  z-index: 10;
  transform: translateX(-1px);
  cursor: ew-resize;
}

/* wider grab target */
.now-line::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: -6px;
  right: -6px;
}

.now-dot {
  position: absolute;
  top: -3px;
  left: 50%;
  transform: translateX(-50%);
  width: 6px;
  height: 6px;
  background: #ef4444;
  border-radius: 50%;
}

.tl-hour-row .tl-track {
  background: transparent;
  height: 16px;
}

.tl-hours { position: relative; }

.h-lbl {
  position: absolute;
  font-size: 0.6rem;
  color: var(--muted);
  transform: translateX(-50%);
  top: 0;
  white-space: nowrap;
  user-select: none;
}

.tl-caption {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.4rem;
  text-align: right;
}

/* ── Card actions ── */

.card-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-top: 1px solid var(--border);
}

.action-btn {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  padding: 0.35rem 0.8rem;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--muted);
  transition: border-color 0.12s, color 0.12s;
}

.action-btn:hover { border-color: var(--a); color: var(--a); }

.action-btn--live { border-color: #ef4444; color: #ef4444; }
.action-btn--live:hover { border-color: #ef4444; color: #ef4444; opacity: 0.75; }

/* ── Legend ── */

.legend {
  display: flex;
  gap: 1rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.7rem;
  color: var(--muted);
}

.legend-swatch {
  width: 20px;
  height: 8px;
  border-radius: 3px;
}

.legend-tz {
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
}

.sw-a       { background: var(--a);       opacity: 0.4; }
.sw-overlap { background: var(--overlap); opacity: 0.85; }

.legend-now {
  display: inline-block;
  width: 2px;
  height: 10px;
  background: #ef4444;
  border-radius: 1px;
  vertical-align: middle;
}

/* ── Footer ── */

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

footer a { color: inherit; text-decoration: none; }
footer a:hover { color: var(--muted); }

/* ── Responsive ── */

@media (max-width: 520px) {
  .pickers { flex-wrap: wrap; }
  #swap-btn { order: 3; margin-top: 0.25rem; }
  .card-summary { flex-direction: column; gap: 0.75rem; }
  .tl-lbl { width: 70px; font-size: 0.65rem; }
  .current-times { flex-direction: row; gap: 1rem; }
}
