:root {
  --background: #f8fafc;
  --foreground: #0f172a;

  --brand-blue: #2563eb;
  --brand-blue-dark: #1d4ed8;
  --brand-teal: #0d9488;
  --brand-green: #16a34a;
  --brand-gradient: linear-gradient(135deg, var(--brand-blue) 0%, var(--brand-teal) 55%, var(--brand-green) 100%);

  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --surface-3: #e8edf5;
  --border-subtle: #e2e8f0;
  --muted: #64748b;
  --muted-2: #94a3b8;

  --day-color: #fef3c7;
  --day-color-strong: #fde68a;
  --night-color: #1e293b;
  --night-color-2: #0f172a;
  --dst-color: #16a34a;
  --danger: #ef4444;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.10);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.16);
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #0b0f19;
    --foreground: #e5e9f0;
    --surface: #131826;
    --surface-2: #182033;
    --surface-3: #1e2740;
    --border-subtle: #232b3d;
    --muted: #8b93a7;
    --muted-2: #5c6478;
    --brand-blue: #3b82f6;
    --brand-teal: #14b8a6;
    --night-color: #060911;
    --night-color-2: #020305;
    --day-color: #3a3320;
    --day-color-strong: #4a4128;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.55);
  }
}

/* Explicit theme toggle overrides — win over prefers-color-scheme because the
   attribute selector below is more specific than a bare :root inside a media query. */
:root[data-theme="dark"] {
  --background: #0b0f19;
  --foreground: #e5e9f0;
  --surface: #131826;
  --surface-2: #182033;
  --surface-3: #1e2740;
  --border-subtle: #232b3d;
  --muted: #8b93a7;
  --muted-2: #5c6478;
  --brand-blue: #3b82f6;
  --brand-teal: #14b8a6;
  --night-color: #060911;
  --night-color-2: #020305;
  --day-color: #3a3320;
  --day-color-strong: #4a4128;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.55);
}

:root[data-theme="light"] {
  --background: #f8fafc;
  --foreground: #0f172a;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --surface-3: #e8edf5;
  --border-subtle: #e2e8f0;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --brand-blue: #2563eb;
  --brand-teal: #0d9488;
  --night-color: #1e293b;
  --night-color-2: #0f172a;
  --day-color: #fef3c7;
  --day-color-strong: #fde68a;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.10);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.16);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.icon { width: 16px; height: 16px; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border-bottom: 1px solid var(--border-subtle);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}

.brand-mark { height: 28px; width: auto; }

.brand-name {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.brand-accent {
  background-image: var(--brand-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

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

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { color: var(--brand-blue); border-color: var(--brand-blue); }
.icon-btn .icon { width: 18px; height: 18px; }
.icon-btn .icon-moon { display: none; }
:root[data-theme="dark"] .icon-btn .icon-sun { display: none; }
:root[data-theme="dark"] .icon-btn .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-btn .icon-sun { display: none; }
  :root:not([data-theme="light"]) .icon-btn .icon-moon { display: block; }
}

.live-clock {
  display: flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 0.92rem;
  padding: 7px 12px;
  border-radius: 999px;
  background-image: var(--brand-gradient);
  color: white;
}
.live-clock-label {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  opacity: 0.85;
}

/* ---------- Main ---------- */
.main {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 20px 60px;
}

.hero {
  text-align: center;
  margin-bottom: 26px;
}

.hero h1 {
  font-size: clamp(1.6rem, 3.6vw, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 10px;
  line-height: 1.15;
}

.hero p {
  color: var(--muted);
  max-width: 640px;
  margin: 0 auto;
  line-height: 1.55;
}

/* ---------- Controls ---------- */
.controls {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--muted-2);
  pointer-events: none;
}

#citySearch {
  width: 100%;
  padding: 13px 14px 13px 40px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: var(--surface);
  color: var(--foreground);
  font-size: 0.96rem;
  font-family: inherit;
  box-shadow: var(--shadow-sm);
}

#citySearch:focus {
  outline: none;
  border-color: var(--brand-blue);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-blue) 20%, transparent);
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  max-height: 360px;
  overflow-y: auto;
  z-index: 30;
}

.search-result-item {
  padding: 11px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border-subtle);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover, .search-result-item.active { background: var(--surface-2); }

.search-result-country {
  background: color-mix(in srgb, var(--brand-blue) 7%, transparent);
}

.search-result-globe {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--brand-blue);
}

.search-result-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}

.search-result-item:not(.search-result-country) {
  display: flex;
  justify-content: space-between;
}

.search-result-city { font-weight: 600; font-size: 0.9rem; }
.search-result-meta { font-size: 0.78rem; color: var(--muted); }
.search-result-empty { padding: 16px; color: var(--muted); font-size: 0.88rem; text-align: center; }

.control-actions { display: flex; gap: 8px; flex-shrink: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 11px 16px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: var(--surface);
  color: var(--foreground);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}
.btn .icon { width: 15px; height: 15px; }
.btn:hover { border-color: var(--brand-blue); }

.btn-primary {
  background-image: var(--brand-gradient);
  color: white;
  border-color: transparent;
}
.btn-primary:hover { filter: brightness(1.06); border-color: transparent; }

.btn-ghost { background: var(--surface-2); }
.btn-ghost[aria-pressed="true"] {
  background-image: var(--brand-gradient);
  color: white;
  border-color: transparent;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-icon svg { width: 16px; height: 16px; }
.btn-icon:hover { border-color: var(--brand-blue); color: var(--brand-blue); }

/* ---------- Date row ---------- */
.date-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 22px;
}

.selected-date {
  font-weight: 700;
  font-size: 1rem;
  min-width: 220px;
  text-align: center;
}

/* ---------- Home row (pinned) ---------- */
.home-row-wrap { margin-bottom: 20px; }

/* ---------- Rows ---------- */
.rows-wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 30px 16px;
  border: 1.5px dashed var(--border-subtle);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.tz-row {
  display: grid;
  grid-template-columns: 1fr 128px 270px 34px;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
  user-select: none;
}

.tz-row:hover { box-shadow: var(--shadow-md); }

.tz-row.is-home {
  grid-template-columns: 1fr 128px 270px;
  border: none;
  box-shadow: var(--shadow-md);
  background-image: var(--brand-gradient);
  color: white;
  padding: 18px 20px;
}
.tz-row.is-home .tz-country,
.tz-row.is-home .tz-dot,
.tz-row.is-home .tz-abbr,
.tz-row.is-home .tz-offset,
.tz-row.is-home .tz-date { color: rgba(255, 255, 255, 0.85); }
.tz-row.is-home .tz-dst-note { color: rgba(255, 255, 255, 0.92); }

.tz-home-badge {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  color: white;
}

.tz-row.is-group-child {
  grid-template-columns: 1fr 128px 270px 34px;
  border: none;
  box-shadow: none;
  background: transparent;
  border-radius: 0;
  padding: 14px 4px;
}
.tz-row.is-group-child:hover { box-shadow: none; }

.tz-row-info { min-width: 0; }

.tz-row-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tz-city { font-weight: 700; font-size: 1.02rem; }

.tz-row-sub {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 2px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.tz-dot { color: var(--muted-2); }
.tz-sub-chip { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }

.tz-dst-note {
  margin-top: 5px;
  font-size: 0.76rem;
  color: var(--muted);
  font-weight: 600;
  min-height: 1em;
}
.tz-dst-note.is-active { color: var(--brand-green); }
.tz-dst-note.is-upcoming { color: var(--brand-blue); }
.tz-dst-note:empty { display: none; }
.tz-row.is-home .tz-dst-note.is-active,
.tz-row.is-home .tz-dst-note.is-upcoming { color: rgba(255,255,255,0.92); }

.tz-row-time { text-align: right; }
.tz-time { font-size: 1.55rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.tz-date { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }
.tz-day-diff {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--brand-blue) 15%, transparent);
  color: var(--brand-blue);
  vertical-align: middle;
}
.tz-ist-caption {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--brand-blue);
  margin-top: 4px;
}
.tz-ist-caption:empty { display: none; }

/* ---------- Slider ---------- */
.tz-row-slider { width: 270px; }

.slider-track {
  position: relative;
  height: 38px;
  border-radius: 999px;
  background: var(--night-color);
  overflow: visible;
  cursor: grab;
  border: 1px solid var(--border-subtle);
}
.tz-row.is-home .slider-track { border-color: rgba(255, 255, 255, 0.35); }
.slider-track:active { cursor: grabbing; }

.slider-fill {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  overflow: hidden;
  background: linear-gradient(
    90deg,
    var(--night-color-2) 0%,
    var(--night-color) 22%,
    var(--day-color) 27%,
    var(--day-color-strong) 50%,
    var(--day-color) 73%,
    var(--night-color) 78%,
    var(--night-color-2) 100%
  );
}

.slider-ticks { position: absolute; inset: 0; pointer-events: none; }
.slider-tick {
  position: absolute;
  top: 6px;
  bottom: 6px;
  width: 1px;
  background: rgba(255, 255, 255, 0.22);
  transform: translateX(-0.5px);
}
.slider-tick-major { background: rgba(255, 255, 255, 0.4); width: 1.5px; }

.slider-now-line {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  background: var(--brand-green);
  box-shadow: 0 0 6px rgba(22, 163, 74, 0.7);
  pointer-events: none;
  transform: translateX(-1px);
}

.slider-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  background: var(--foreground);
  color: var(--background);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}
.slider-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--foreground);
}
.slider-track.is-dragging .slider-tooltip { opacity: 1; }

.slider-handle {
  position: absolute;
  top: 50%;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: white;
  border: 3px solid var(--brand-blue);
  transform: translate(-50%, -50%);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  cursor: grab;
}
.slider-track.is-dragging .slider-handle { cursor: grabbing; box-shadow: 0 0 0 6px color-mix(in srgb, var(--brand-blue) 25%, transparent); }

/* While scrubbing any slider, every element on the page skips its transitions.
   Without this, sibling rows (which never get .is-dragging themselves) still
   run their own hover/shadow transitions on every mousemove during a drag —
   dozens of overlapping animations a second — which is what produced visible
   ghosting/smearing across the page while dragging. */
html.is-scrubbing, html.is-scrubbing * {
  transition: none !important;
}
.slider-handle:focus-visible { outline: 2px solid var(--brand-teal); outline-offset: 3px; }

.slider-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.66rem;
  color: var(--muted-2);
  margin-top: 5px;
  padding: 0 2px;
}
.tz-row.is-home .slider-scale { color: rgba(255, 255, 255, 0.75); }

.tz-remove {
  border: none;
  background: transparent;
  color: var(--muted-2);
  cursor: pointer;
  border-radius: 8px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tz-remove svg { width: 15px; height: 15px; }
.tz-remove:hover { color: var(--danger); background: var(--surface-2); }

/* ---------- Country group ---------- */
.tz-group {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow 0.15s ease;
  user-select: none;
}
.tz-group:hover { box-shadow: var(--shadow-md); }

.tz-group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-subtle);
}

.tz-group-title { font-weight: 800; font-size: 0.95rem; }
.tz-group-count {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--brand-blue);
  background: color-mix(in srgb, var(--brand-blue) 12%, transparent);
  padding: 3px 9px;
  border-radius: 999px;
}
.tz-group-remove {
  margin-left: auto;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.tz-group-remove:hover { color: var(--danger); background: var(--surface); }

.tz-group-rows {
  padding: 2px 16px;
}
.tz-group-rows .tz-row.is-group-child + .tz-row.is-group-child { border-top: 1px solid var(--border-subtle); }

/* ---------- Legend ---------- */
.legend {
  display: flex;
  gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 26px;
  color: var(--muted);
  font-size: 0.82rem;
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }
.swatch-day { background: var(--day-color-strong); }
.swatch-night { background: var(--night-color); }
.swatch-dst { background: var(--brand-green); }

/* ---------- About ---------- */
.about {
  margin-top: 40px;
  padding: 22px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border-subtle);
}
.about h2 { font-size: 1.05rem; margin: 0 0 8px; }
.about p { color: var(--muted); line-height: 1.65; margin: 0; font-size: 0.9rem; }
.about strong { color: var(--foreground); }

/* ---------- Footer ---------- */
.footer {
  border-top: 1px solid var(--border-subtle);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}
.footer-mark { height: 16px; width: auto; opacity: 0.7; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .controls { flex-wrap: wrap; }
  .control-actions { width: 100%; justify-content: stretch; }
  .control-actions .btn { flex: 1; justify-content: center; }

  .tz-row {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "info time"
      "slider slider";
    row-gap: 12px;
    position: relative;
  }
  .tz-row.is-home { grid-template-columns: 1fr auto; }
  .tz-row.is-group-child { grid-template-columns: 1fr auto; }

  .tz-row-info { grid-area: info; padding-right: 26px; }
  .tz-row-time { grid-area: time; }
  .tz-row-slider { grid-area: slider; width: 100%; }
  .tz-remove { position: absolute; top: 10px; right: 10px; }

  .tz-group-rows { padding: 2px 12px; }
}
