:root {
  --bg: #0d1220;
  --bg-deep: #0a0e1a;
  --surface: #1a2033;
  --surface-2: #222a40;
  --surface-3: #2c3550;
  --border: #2b3349;
  --text: #ffffff;
  --muted: #a2a9ba;
  --faint: #6f7790;
  --accent: #8b8cf6;
  --accent-2: #a5a7ff;
  --accent-soft: rgba(139, 140, 246, 0.16);

  /* Timeline cells */
  --cell-night: #131a2c;
  --cell-day: #222a40;
  --cell-work: #2f3a5c;

  --radius: 14px;
  --container: 1200px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { background: var(--bg); scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: "Geist", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

main { flex: 1; }

.container {
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 24px;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.skip {
  position: absolute; left: 16px; top: -48px; z-index: 50;
  background: var(--accent); color: var(--bg); padding: 8px 14px; border-radius: 8px;
  font-weight: 600; text-decoration: none;
}
.skip:focus { top: 12px; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(13, 18, 32, 0.88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; gap: 32px; height: 64px; }

.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; flex: none;
  background: linear-gradient(140deg, #9a9bfa, #7c7df0);
  display: grid; place-items: center;
}
.brand-mark svg { width: 19px; height: 19px; fill: none; stroke: #fff; stroke-width: 2.2; stroke-linecap: round; }
.brand-mark.small { width: 24px; height: 24px; border-radius: 7px; }
.brand-mark.small svg { width: 14px; height: 14px; }
.brand-name { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }

.main-nav { display: flex; gap: 4px; }
.main-nav a {
  color: var(--muted); text-decoration: none; font-size: 15px;
  padding: 8px 12px; border-radius: 8px;
}
.main-nav a:hover { color: var(--text); background: var(--surface); }

.header-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }

.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
.segmented button {
  font: inherit; font-size: 13px; font-weight: 500; color: var(--muted);
  background: none; border: 0; border-radius: 7px; padding: 5px 10px; cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); }

.nav-toggle { display: none; background: none; border: 0; padding: 10px 6px; cursor: pointer; gap: 6px; flex-direction: column; align-items: flex-end; }
.nav-toggle span { display: block; height: 2px; border-radius: 2px; background: var(--muted); transition: transform .2s; }
.nav-toggle span:first-child { width: 22px; }
.nav-toggle span:last-child { width: 15px; }
.nav-toggle[aria-expanded="true"] span:first-child { transform: translateY(4px) rotate(45deg); width: 20px; }
.nav-toggle[aria-expanded="true"] span:last-child { transform: translateY(-4px) rotate(-45deg); width: 20px; }

/* ---------- Intro ---------- */
.intro { padding-top: 48px; padding-bottom: 28px; }
h1 { margin: 0 0 10px; font-size: clamp(30px, 4vw, 42px); line-height: 1.1; font-weight: 700; letter-spacing: -0.025em; }
.intro p { margin: 0; color: var(--muted); font-size: 17px; max-width: 60ch; }

/* ---------- Toolbar ---------- */
.toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 170px 140px auto;
  gap: 12px; align-items: end;
  margin-bottom: 16px;
}
.field { display: grid; gap: 6px; min-width: 0; }
.field label { font-size: 13px; color: var(--muted); }

.field input {
  font: inherit; font-size: 15px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  height: 44px; padding: 0 12px; width: 100%;
  font-variant-numeric: tabular-nums;
}
.field input:hover { border-color: var(--surface-3); }
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field input::-webkit-calendar-picker-indicator { filter: invert(.75); cursor: pointer; }

.search { position: relative; }
.search input { padding-left: 38px; }
.search-icon { position: absolute; left: 12px; top: 13px; width: 18px; height: 18px; fill: none; stroke: var(--faint); stroke-width: 2; stroke-linecap: round; pointer-events: none; }

.results {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 30;
  list-style: none; margin: 0; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, .45);
  max-height: 320px; overflow-y: auto;
}
.results[hidden] { display: none; }
.results li {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 9px 10px; border-radius: 8px; cursor: pointer;
}
.results li[aria-selected="true"] { background: var(--accent-soft); }
.results .r-name { font-weight: 500; }
.results .r-country { color: var(--muted); font-size: 14px; margin-left: 6px; }
.results .r-time { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.results .r-empty { color: var(--muted); cursor: default; }

.toolbar-buttons { display: flex; gap: 8px; }
.btn {
  font: inherit; font-size: 15px; font-weight: 500; color: var(--text);
  height: 44px; padding: 0 16px; border-radius: 10px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border);
  display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
}
.btn:hover { border-color: var(--surface-3); background: var(--surface-2); }
.btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #0d1220; }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }

.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.btn.is-live .live-dot { background: #4ade80; box-shadow: 0 0 0 3px rgba(74, 222, 128, .18); }

/* ---------- Timeline board ---------- */
.board-wrap {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}
.board { min-width: 1080px; }

.row {
  display: grid;
  grid-template-columns: 300px repeat(24, minmax(30px, 1fr));
  align-items: stretch;
  border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: 0; }

.city {
  position: sticky; left: 0; z-index: 2;
  background: var(--surface);
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; align-items: center;
  padding: 14px 16px 14px 18px;
  border-right: 1px solid var(--border);
}
.city-name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.city-sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.city-time { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; text-align: right; font-variant-numeric: tabular-nums; line-height: 1.15; }
.city-time small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.city-date { color: var(--muted); font-size: 13px; text-align: right; white-space: nowrap; }
.city-date.shift { color: var(--accent-2); }

.city-actions { grid-column: 1 / -1; display: flex; gap: 4px; margin-top: 6px; }
.city-actions button, .home-badge {
  font: inherit; font-size: 12px; color: var(--faint);
  background: none; border: 1px solid transparent; border-radius: 6px; padding: 2px 7px; cursor: pointer;
}
.city-actions button:hover { color: var(--text); border-color: var(--border); }
.home-badge { color: var(--accent-2); background: var(--accent-soft); cursor: default; }

.cell {
  font: inherit; color: var(--muted); border: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  margin: 8px 1px; border-radius: 6px; min-height: 48px; padding: 0;
  font-size: 13px; font-variant-numeric: tabular-nums; position: relative;
  background: var(--cell-day);
}
.cell.night { background: var(--cell-night); color: var(--faint); }
.cell.work { background: var(--cell-work); color: var(--text); }
.cell .ampm { font-size: 9px; text-transform: lowercase; opacity: .75; line-height: 1; }
.cell .mins { font-size: 9px; opacity: .8; line-height: 1; }
.cell .day-mark {
  position: absolute; top: -8px; left: 50%; transform: translateX(-50%);
  font-size: 9px; line-height: 1; padding: 2px 4px; border-radius: 4px;
  background: var(--bg); color: var(--accent-2); white-space: nowrap;
}
.cell.hover { box-shadow: inset 0 0 0 1px var(--accent); color: var(--text); }
.cell.sel { background: var(--accent); color: #0d1220; font-weight: 600; }
.cell.sel .day-mark { color: var(--accent-2); }

.board-foot { display: flex; justify-content: space-between; gap: 16px 32px; flex-wrap: wrap; margin-top: 14px; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: 13px; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 7px; }
.sw { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.sw.night { background: var(--cell-night); box-shadow: inset 0 0 0 1px var(--border); }
.sw.day { background: var(--cell-day); }
.sw.work { background: var(--cell-work); }
.sw.sel { background: var(--accent); }
.hint { margin: 0; font-size: 13px; color: var(--faint); max-width: 62ch; }

.summary { margin: 22px 0 0; font-size: 17px; color: var(--muted); max-width: 75ch; }
.summary strong { color: var(--text); font-weight: 600; }

/* ---------- Sections ---------- */
.section { padding-top: 72px; }
h2 { font-size: 24px; font-weight: 600; letter-spacing: -0.015em; margin: 0 0 20px; }

.popular {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  border-top: 1px solid var(--border);
}
.popular a {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 14px 4px; border-bottom: 1px solid var(--border);
  color: var(--text); text-decoration: none;
}
.popular li:nth-child(odd) a { margin-right: 12px; }
.popular a:hover .p-title { color: var(--accent-2); }
.p-title { font-weight: 500; white-space: nowrap; }
.p-cities { color: var(--muted); font-size: 14px; text-align: right; }

.guide { display: grid; grid-template-columns: repeat(3, 1fr); gap: 32px; }
.guide h3 { margin: 0 0 8px; font-size: 17px; font-weight: 600; }
.guide p { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.6; }
.guide em { color: var(--text); font-style: normal; }

/* ---------- Footer ---------- */
.site-footer { margin-top: 96px; border-top: 1px solid var(--border); background: var(--bg-deep); }
.footer-inner { display: flex; align-items: center; gap: 24px; padding-top: 28px; padding-bottom: 28px; flex-wrap: wrap; }
.footer-brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.footer-inner p { margin: 0; color: var(--faint); font-size: 14px; }
.copyright { margin-left: auto !important; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--surface-3); color: var(--text); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .toolbar { grid-template-columns: 1fr 1fr; }
  .search-field { grid-column: 1 / -1; }
  .toolbar-buttons { grid-column: 1 / -1; }
  .toolbar-buttons .btn { flex: 1; justify-content: center; }
  .guide { grid-template-columns: 1fr; gap: 24px; }
}

@media (max-width: 760px) {
  .container { padding-left: 16px; padding-right: 16px; }
  .header-inner { gap: 12px; }
  .nav-toggle { display: flex; }
  .main-nav {
    display: none; position: absolute; left: 0; right: 0; top: 64px;
    flex-direction: column; padding: 8px 16px 16px;
    background: var(--bg); border-bottom: 1px solid var(--border);
  }
  .main-nav.open { display: flex; }
  .main-nav a { padding: 12px; }
  .intro { padding-top: 32px; }
  .intro p { font-size: 16px; }

  .board { min-width: 0; width: max-content; }
  .row { grid-template-columns: 150px repeat(24, 40px); }
  .city { grid-template-columns: 1fr; padding: 12px; }
  .city-time, .city-date { text-align: left; }
  .city-time { font-size: 20px; }
  .city-sub { display: none; }
  .city-actions { gap: 2px; }
  .city-actions button, .home-badge { white-space: nowrap; padding: 2px 4px; }
  .copyright { margin-left: 0 !important; }
}

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