/* ═══════════════════════════════════════════════════
   World Clock — style.css
   ═══════════════════════════════════════════════════ */

/* ── Reset & base ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Spacing */
  --toolbar-h: 52px;
  --edit-bar-h: 52px;

  /* Radius / shadow */
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,.35);

  /* Transitions */
  --t-fast: 150ms ease;
  --t-med:  280ms ease;

  /* Font */
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-num: ui-monospace, "SF Mono", "Cascadia Mono", "Consolas", monospace;
}

/* ── Dark theme (default) ─────────────────────────── */
.theme-dark {
  --bg:           #0f1117;
  --surface:      #1a1d27;
  --surface-2:    #22263a;
  --border:       rgba(255,255,255,.08);
  --text-pri:     #f0f2f8;
  --text-sec:     #8890a8;
  --text-muted:   #555e7a;
  --accent:       #4f8ef7;
  --accent-hover: #6ba3ff;
  --day-tint:     rgba(255,220,80,.045);
  --night-tint:   rgba(30,40,80,.55);
  --badge-dst:    rgba(255,180,0,.18);
  --badge-wkd:    rgba(100,200,120,.18);
  --badge-dst-txt:#f5c842;
  --badge-wkd-txt:#6fcf97;
  --toolbar-bg:   rgba(15,17,23,.88);
  --modal-bg:     #1a1d27;
  --overlay:      rgba(0,0,0,.65);
}

/* ── Light theme ──────────────────────────────────── */
.theme-light {
  --bg:           #f0f2f7;
  --surface:      #ffffff;
  --surface-2:    #e8eaf2;
  --border:       rgba(0,0,0,.09);
  --text-pri:     #1a1d2e;
  --text-sec:     #555e7a;
  --text-muted:   #9099b8;
  --accent:       #2563eb;
  --accent-hover: #1d4ed8;
  --day-tint:     rgba(255,220,80,.12);
  --night-tint:   rgba(30,40,80,.12);
  --badge-dst:    rgba(200,140,0,.14);
  --badge-wkd:    rgba(20,160,80,.12);
  --badge-dst-txt:#b45309;
  --badge-wkd-txt:#166534;
  --toolbar-bg:   rgba(240,242,247,.9);
  --modal-bg:     #ffffff;
  --overlay:      rgba(0,0,0,.4);
}

html, body {
  height: 100%;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text-pri);
  transition: background var(--t-med), color var(--t-med);
  overflow-x: hidden;
}

/* ── Toolbar ──────────────────────────────────────── */
.toolbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--toolbar-h);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--toolbar-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  transition: opacity var(--t-med), transform var(--t-med), background var(--t-med);
  gap: 8px;
}

.toolbar.hidden-toolbar {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-100%);
}

.app-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -.01em;
  color: var(--text-pri);
  white-space: nowrap;
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--text-sec);
  border-radius: 8px;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
  flex-shrink: 0;
}
.toolbar-btn:hover  { background: var(--surface-2); color: var(--text-pri); }
.toolbar-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.toolbar-btn.active { color: var(--accent); }
.toolbar-btn svg    { width: 18px; height: 18px; }

.format-btn { width: auto; padding: 0 10px; font-family: var(--font-num); font-size: .8rem; font-weight: 600; letter-spacing: .04em; }

/* ── Clock grid ───────────────────────────────────── */
.clock-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(180px, 100%), 1fr));
  gap: 12px;
  padding: calc(var(--toolbar-h) + 14px) 14px 14px;
  min-height: 100vh;
  align-content: start;
  transition: padding var(--t-med);
}

.clock-grid.edit-active { padding-bottom: calc(var(--edit-bar-h) + 14px); }

/* ── Clock tile ───────────────────────────────────── */
.clock-tile {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 14px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: background var(--t-med), border-color var(--t-med), box-shadow var(--t-fast), transform var(--t-fast);
  cursor: default;
  overflow: hidden;
  min-height: 130px;
}

/* day / night tint */
.clock-tile.is-day   { background: color-mix(in srgb, var(--surface) 100%, transparent); box-shadow: inset 0 0 0 200px var(--day-tint); }
.clock-tile.is-night { box-shadow: inset 0 0 0 200px var(--night-tint); }

.clock-tile.drag-over { outline: 2px dashed var(--accent); outline-offset: -2px; }
.clock-tile.dragging  { opacity: .45; transform: scale(.97); }

/* edit mode */
.edit-active .clock-tile { cursor: grab; }
.edit-active .clock-tile:active { cursor: grabbing; }

/* ── Tile header (city + country) ─────────────────── */
.tile-header {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  text-align: center;
}
.city-name {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-pri);
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.country-name {
  font-size: .68rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

/* ── Digital clock ────────────────────────────────── */
.digital-display {
  display: flex;
  align-items: baseline;
  gap: 4px;
  line-height: 1;
}
.digital-time {
  font-family: var(--font-num);
  font-size: clamp(1.6rem, 3.5vw, 2.6rem);
  font-weight: 300;
  color: var(--text-pri);
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.digital-ampm {
  font-family: var(--font-num);
  font-size: .7rem;
  font-weight: 500;
  color: var(--text-sec);
  letter-spacing: .04em;
  align-self: flex-end;
  margin-bottom: .2em;
}

/* ── Analog clock ─────────────────────────────────── */
.analog-svg {
  width: min(120px, 75%);
  aspect-ratio: 1;
  overflow: visible;
}

/* Face */
.clock-face       { fill: var(--surface-2); stroke: var(--border); stroke-width: 1; }
.clock-tick       { stroke: var(--text-muted); stroke-width: 1; }
.clock-tick-hour  { stroke: var(--text-sec); stroke-width: 2; }
.hand-hour        { stroke: var(--text-pri); stroke-width: 4; stroke-linecap: round; fill: none; }
.hand-minute      { stroke: var(--text-pri); stroke-width: 2.5; stroke-linecap: round; fill: none; }
.hand-second      { stroke: var(--accent); stroke-width: 1.5; stroke-linecap: round; fill: none; }
.hand-center      { fill: var(--text-pri); }
.hand-center-dot  { fill: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  .hand-second { transition: none !important; }
  .clock-tile  { transition: none !important; }
}

/* ── Tile footer ──────────────────────────────────── */
.tile-footer {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  margin-top: auto;
}
.tile-date {
  font-size: .7rem;
  color: var(--text-sec);
  font-variant-numeric: tabular-nums;
}
.tile-tz-row {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  justify-content: center;
}
.tile-tz {
  font-family: var(--font-num);
  font-size: .65rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: .04em;
}
.badge {
  font-size: .58rem;
  font-weight: 700;
  letter-spacing: .05em;
  padding: 1px 5px;
  border-radius: 4px;
  line-height: 1.5;
}
.badge-dst { background: var(--badge-dst); color: var(--badge-dst-txt); }
.badge-wkd { background: var(--badge-wkd); color: var(--badge-wkd-txt); }

/* ── Remove button (edit mode) ────────────────────── */
.remove-btn {
  position: absolute;
  top: 6px; right: 6px;
  width: 24px; height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(220,60,60,.8);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  transition: background var(--t-fast);
  z-index: 10;
}
.remove-btn:hover { background: rgba(220,60,60,1); }
.edit-active .remove-btn { display: flex; }

/* ── Add city tile ────────────────────────────────── */
.add-tile {
  background: transparent;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: .85rem;
  min-height: 130px;
  transition: border-color var(--t-fast), color var(--t-fast), background var(--t-fast);
}
.add-tile:hover, .add-tile:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(79,142,247,.05);
  outline: none;
}
.add-tile svg { width: 28px; height: 28px; }

/* ── Edit bar ─────────────────────────────────────── */
.edit-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--edit-bar-h);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--toolbar-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
.edit-hint { font-size: .8rem; color: var(--text-sec); }

.btn-primary {
  padding: 7px 20px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: .85rem;
  cursor: pointer;
  transition: background var(--t-fast), transform var(--t-fast);
}
.btn-primary:hover  { background: var(--accent-hover); }
.btn-primary:active { transform: scale(.97); }
.btn-primary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ── Modal ────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: max(60px, 10vh);
  padding-inline: 16px;
}
.modal.hidden { display: none; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: -1;
}
.modal-content {
  background: var(--modal-bg);
  border-radius: 14px;
  width: 100%;
  max-width: 480px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 40px rgba(0,0,0,.4);
  border: 1px solid var(--border);
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 0;
}
.modal-title { font-size: 1rem; font-weight: 600; }
.modal-close {
  width: 32px; height: 32px;
  border: none; background: transparent;
  color: var(--text-sec);
  border-radius: 6px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--t-fast);
}
.modal-close:hover { background: var(--surface-2); color: var(--text-pri); }
.modal-close svg { width: 16px; height: 16px; }
.modal-close:focus-visible { outline: 2px solid var(--accent); }

.city-search-input {
  margin: 12px 16px 8px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-pri);
  font-size: .9rem;
  font-family: var(--font-ui);
  outline: none;
  transition: border-color var(--t-fast);
}
.city-search-input::placeholder { color: var(--text-muted); }
.city-search-input:focus { border-color: var(--accent); }

.search-results {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 0 8px 8px;
}
.search-results li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 8px;
  border-radius: 8px;
  cursor: pointer;
  gap: 12px;
  transition: background var(--t-fast);
}
.search-results li:hover, .search-results li.focused { background: var(--surface-2); }
.search-results li:focus-visible { outline: 2px solid var(--accent); }

.result-info { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.result-city { font-size: .88rem; font-weight: 500; color: var(--text-pri); }
.result-country { font-size: .73rem; color: var(--text-muted); }
.result-time {
  font-family: var(--font-num);
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-sec);
  white-space: nowrap;
  flex-shrink: 0;
}
.result-already { font-size: .7rem; color: var(--text-muted); font-style: italic; }

.search-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: .85rem;
  padding: 24px 16px;
}

/* ── Toast ────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: var(--surface-2);
  color: var(--text-pri);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 8px 20px;
  font-size: .85rem;
  font-weight: 500;
  z-index: 300;
  box-shadow: var(--shadow);
  transition: opacity var(--t-fast), transform var(--t-fast);
  pointer-events: none;
}
.toast.hidden { opacity: 0; transform: translateX(-50%) translateY(12px); }

/* ── Utility ──────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Visually hidden (accessible, indexable) ─────── */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ── Skip to content link ─────────────────────────── */
.skip-link {
  position: fixed;
  top: -100%;
  left: 16px;
  z-index: 9999;
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  border-radius: 0 0 8px 8px;
  font-size: .85rem;
  font-weight: 600;
  text-decoration: none;
  transition: top var(--t-fast);
}
.skip-link:focus { top: 0; }

/* ── Site description blurb ──────────────────────── */
.site-description {
  text-align: center;
  font-size: .75rem;
  color: var(--text-muted);
  padding: 6px 16px 12px;
  line-height: 1.5;
  pointer-events: none;
  user-select: none;
}
.site-description-extra {
  display: block;
  opacity: .7;
}

/* ── Scrollbar (webkit) ───────────────────────────── */
.search-results::-webkit-scrollbar { width: 6px; }
.search-results::-webkit-scrollbar-track { background: transparent; }
.search-results::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   ════════════════════════════════════════════════════ */

/* Tiny phones (< 400px) — 1 column */
@media (max-width: 399px) {
  .clock-grid { grid-template-columns: 1fr; }
}

/* Phones portrait (400–599px) — 2 columns */
@media (min-width: 400px) and (max-width: 599px) {
  .clock-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Tablets portrait / small desktop (600–899px) — auto 3-4 */
@media (min-width: 600px) and (max-width: 899px) {
  .clock-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
}

/* Desktop (900–1399px) — auto 4-6 */
@media (min-width: 900px) and (max-width: 1399px) {
  .clock-grid { grid-template-columns: repeat(auto-fill, minmax(185px, 1fr)); }
}

/* Large (1400px+) — auto, up to 8 */
@media (min-width: 1400px) {
  .clock-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); max-width: 1920px; margin-inline: auto; }
}

/* Landscape phones */
@media (max-height: 500px) and (orientation: landscape) {
  :root { --toolbar-h: 44px; }
  .clock-grid { padding-top: calc(var(--toolbar-h) + 10px); }
  .clock-tile { min-height: 100px; padding: 10px; }
  .digital-time { font-size: 1.4rem; }
}

/* ── Mobile modal ─────────────────────────────────── */
@media (max-width: 599px) {
  .modal { padding-top: 0; align-items: flex-end; }
  .modal-content { max-height: 80vh; border-bottom-left-radius: 0; border-bottom-right-radius: 0; max-width: 100%; }
}

/* ── Toolbar on very small screens ───────────────────*/
@media (max-width: 380px) {
  .app-title { display: none; }
  .toolbar-btn { width: 36px; height: 36px; }
}
