:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #111827;
  --text-muted: #6b7280;
  --border: rgba(17, 24, 39, 0.08);
  --border-strong: rgba(17, 24, 39, 0.14);
  --accent: #111827;
  --accent-hover: #1f2937;
  --live-green: #10b981;
  --manual-amber: #f59e0b;
  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.04);
  --shadow-modal: 0 24px 64px rgba(15, 23, 42, 0.18);
  --transition: 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app {
  max-width: 1120px;
  margin: 0 auto;
  padding: 32px 24px 48px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 32px;
  flex-wrap: wrap;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

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

.brand-mark {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text);
  display: inline-block;
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.mode-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.05);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--live-green);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18);
  transition: background var(--transition), box-shadow var(--transition);
}

.mode-status.is-manual .status-dot {
  background: var(--manual-amber);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2);
}

.mode-status.is-manual {
  color: #92400e;
  background: rgba(245, 158, 11, 0.12);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Buttons & Controls */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform 100ms ease;
}

.btn:hover {
  background: #f9fafb;
  border-color: rgba(17, 24, 39, 0.24);
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-live {
  border-color: rgba(245, 158, 11, 0.4);
  background: #fffbeb;
  color: #92400e;
}

.btn-live:hover {
  background: #fef3c7;
  border-color: rgba(245, 158, 11, 0.6);
}

.segmented-control {
  display: inline-flex;
  padding: 3px;
  border-radius: var(--radius-md);
  background: rgba(17, 24, 39, 0.06);
  height: 38px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0 12px;
  border-radius: 9px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
}

.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.1);
}

.hidden {
  display: none !important;
}

/* Cards Grid */
.main {
  flex: 1;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 20px;
}

/* City Card */
.city-card {
  position: relative;
  border-radius: var(--radius-lg);
  padding: 22px 22px 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 16px;
  transition: transform var(--transition), box-shadow var(--transition), background 320ms ease, color 320ms ease, border-color 320ms ease;
}

.city-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06), 0 14px 30px rgba(15, 23, 42, 0.06);
}

/* Time-of-day themes */
.city-card.theme-day {
  background: linear-gradient(155deg, #ffffff 0%, #f8fafc 100%);
  color: #0f172a;
}

.city-card.theme-dawn {
  background: linear-gradient(155deg, #fffdf7 0%, #fef3e2 100%);
  color: #1c1917;
  border-color: rgba(217, 119, 6, 0.14);
}

.city-card.theme-dusk {
  background: linear-gradient(155deg, #fff8f3 0%, #fce7f3 48%, #ede9fe 100%);
  color: #1e1b4b;
  border-color: rgba(124, 58, 237, 0.14);
}

.city-card.theme-night {
  background: linear-gradient(155deg, #131c2e 0%, #0b1120 100%);
  color: #f8fafc;
  border-color: rgba(255, 255, 255, 0.08);
}

/* Card Header */
.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.city-info {
  min-width: 0;
}

.city-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.day-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.05);
  flex-shrink: 0;
}

.theme-night .day-icon {
  background: rgba(255, 255, 255, 0.09);
  color: #cbd5e1;
}

.theme-dawn .day-icon {
  background: rgba(245, 158, 11, 0.14);
  color: #d97706;
}

.theme-day .day-icon {
  background: rgba(234, 179, 8, 0.14);
  color: #ca8a04;
}

.theme-dusk .day-icon {
  background: rgba(236, 72, 153, 0.12);
  color: #db2777;
}

.city-name {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.city-country {
  margin: 3px 0 0 32px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.theme-night .city-country {
  color: #94a3b8;
}

.remove-btn {
  border: none;
  background: transparent;
  color: inherit;
  opacity: 0.35;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity var(--transition), background var(--transition);
  flex-shrink: 0;
}

.city-card:hover .remove-btn,
.remove-btn:focus-visible {
  opacity: 0.7;
}

.remove-btn:hover {
  opacity: 1 !important;
  background: rgba(15, 23, 42, 0.08);
}

.theme-night .remove-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* Time Display & Direct Edit */
.time-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.time-button {
  border: none;
  background: transparent;
  color: inherit;
  padding: 2px 6px;
  margin-left: -6px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 2.85rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  transition: background var(--transition);
}

.time-button:hover {
  background: rgba(15, 23, 42, 0.05);
}

.theme-night .time-button:hover {
  background: rgba(255, 255, 255, 0.08);
}

.time-seconds {
  font-size: 1.15rem;
  font-weight: 500;
  opacity: 0.45;
  letter-spacing: -0.02em;
}

.time-ampm {
  font-size: 1rem;
  font-weight: 600;
  opacity: 0.7;
  margin-left: 2px;
  letter-spacing: 0.02em;
}

.time-edit-input {
  font-family: inherit;
  font-size: 2.35rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: inherit;
  background: rgba(15, 23, 42, 0.06);
  border: 2px solid currentColor;
  border-radius: 12px;
  padding: 4px 10px;
  width: 170px;
  outline: none;
}

.theme-night .time-edit-input {
  background: rgba(255, 255, 255, 0.1);
  color-scheme: dark;
}

/* Meta row: Date, Day badge, UTC offset */
.meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.82rem;
}

.date-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.date-text {
  opacity: 0.72;
  font-weight: 500;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.badge-day-rel {
  background: rgba(15, 23, 42, 0.07);
  color: inherit;
}

.theme-night .badge-day-rel {
  background: rgba(255, 255, 255, 0.12);
}

.badge-day-rel.is-shifted {
  background: rgba(59, 130, 246, 0.14);
  color: #1d4ed8;
}

.theme-night .badge-day-rel.is-shifted {
  background: rgba(96, 165, 250, 0.22);
  color: #93c5fd;
}

.utc-offset {
  font-size: 0.76rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  opacity: 0.6;
}

/* Slider & Quick Step Controls */
.controls-block {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(15, 23, 42, 0.07);
}

.theme-night .controls-block {
  border-top-color: rgba(255, 255, 255, 0.1);
}

.slider-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.time-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.1);
  outline: none;
  cursor: pointer;
}

.theme-night .time-slider {
  background: rgba(255, 255, 255, 0.16);
}

.time-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #111827;
  border: 2px solid #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  cursor: grab;
  transition: transform 120ms ease;
}

.time-slider::-webkit-slider-thumb:active {
  cursor: grabbing;
  transform: scale(1.15);
}

.theme-night .time-slider::-webkit-slider-thumb {
  background: #f8fafc;
  border-color: #0f172a;
}

.time-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #111827;
  border: 2px solid #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  cursor: grab;
}

.theme-night .time-slider::-moz-range-thumb {
  background: #f8fafc;
  border-color: #0f172a;
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  opacity: 0.45;
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.step-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.step-btn {
  border: 1px solid rgba(15, 23, 42, 0.1);
  background: rgba(255, 255, 255, 0.55);
  color: inherit;
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 6px 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform 90ms ease;
}

.step-btn:hover {
  background: rgba(255, 255, 255, 0.9);
  border-color: rgba(15, 23, 42, 0.22);
}

.step-btn:active {
  transform: scale(0.96);
}

.theme-night .step-btn {
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
}

.theme-night .step-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.24);
}

/* Footer */
.footer {
  margin-top: 40px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.footer p {
  margin: 0;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal {
  width: 100%;
  max-width: 460px;
  max-height: 80vh;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 12px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn:hover {
  background: rgba(15, 23, 42, 0.06);
  color: var(--text);
}

.modal-search-wrap {
  position: relative;
  padding: 0 20px 14px;
}

.search-icon {
  position: absolute;
  left: 32px;
  top: 11px;
  color: var(--text-muted);
  pointer-events: none;
}

.modal-search {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 36px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: #f9fafb;
  outline: none;
  transition: border-color var(--transition), background var(--transition);
}

.modal-search:focus {
  background: #ffffff;
  border-color: var(--accent);
}

.city-list {
  overflow-y: auto;
  padding: 0 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.city-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: transparent;
  border-radius: 10px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  transition: background var(--transition);
}

.city-option:hover:not(:disabled) {
  background: rgba(15, 23, 42, 0.05);
}

.city-option:disabled {
  opacity: 0.45;
  cursor: default;
}

.city-option-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.city-option-name {
  font-size: 0.92rem;
  font-weight: 600;
}

.city-option-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.city-option-right {
  font-size: 0.85rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.empty-state {
  padding: 28px 16px;
  text-align: center;
  font-size: 0.88rem;
  color: var(--text-muted);
}

@media (max-width: 600px) {
  .app {
    padding: 20px 16px 36px;
  }

  .header {
    margin-bottom: 22px;
  }

  .time-button {
    font-size: 2.5rem;
  }
}
