:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface-hover: #222;
  --border: #2a2a2a;
  --border-bright: #3a3a3a;
  --text: #e0e0e0;
  --text-dim: #666;
  --text-dimmer: #444;
  --accent: #4a9eff;
  --accent-dim: rgba(74, 158, 255, 0.12);
  --accent-row: rgba(74, 158, 255, 0.07);
  --error-bg: #1f0a0a;
  --error-border: #5a1a1a;
  --error-text: #ff7070;
  --warn-bg: #1a1500;
  --warn-border: #4a3a00;
  --warn-text: #d4a500;
  --drag-over: rgba(74, 158, 255, 0.18);
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;
  --font-ui: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --radius: 6px;
  --tl-label-col: 240px;
}

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

button {
  -webkit-appearance: none;
  appearance: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  min-height: 100vh;
  padding: 1.5rem 1.75rem 3rem;
  line-height: 1.4;
}

/* ─── Header ─────────────────────────────────────────── */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
}

h1 {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 400;
  letter-spacing: 0.12em;
  color: var(--text-dim);
}

.controls {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

/* ─── Search ──────────────────────────────────────────── */

.search-wrapper {
  position: relative;
}

#tz-search {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-family: var(--font-ui);
  border-radius: var(--radius);
  width: 230px;
  outline: none;
  transition: border-color 0.15s;
}

#tz-search::placeholder {
  color: var(--text-dimmer);
}

#tz-search:focus {
  border-color: var(--accent);
}

#search-results {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  width: 320px;
  background: var(--surface);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  list-style: none;
  max-height: 260px;
  overflow-y: auto;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

#search-results li {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

#search-results li:last-child {
  border-bottom: none;
}

#search-results li:hover,
#search-results li.active {
  background: var(--accent-dim);
}

#search-results li .tz-name {
  color: var(--text);
  font-size: 0.875rem;
}

#search-results li .tz-detail {
  color: var(--text-dim);
  font-size: 0.7rem;
  font-family: var(--font-mono);
}

/* ─── Format toggle ───────────────────────────────────── */

.format-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.5rem 0.75rem;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  border-radius: var(--radius);
  cursor: pointer;
  letter-spacing: 0.06em;
  transition: border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.format-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* ─── Share button ───────────────────────────────────── */

.share-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
}

.share-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* ─── Help button ─────────────────────────────────────── */

.help-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 2rem;
  height: 2rem;
  font-size: 0.85rem;
  font-family: var(--font-ui);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
}

.help-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* ─── Help modal ──────────────────────────────────────── */

#help-modal {
  background: var(--surface);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0;
  max-width: 500px;
  width: calc(100% - 2rem);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
}

#help-modal::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

.help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
}

.help-header h2 {
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text);
}

.help-close {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.help-close:hover {
  color: var(--text);
  background: var(--border);
}

.help-body {
  padding: 1.25rem;
}

.help-body dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.6rem 1.25rem;
  align-items: baseline;
}

.help-body dt {
  font-size: 0.775rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  padding-top: 0.1rem;
}

.help-body dd {
  font-size: 0.775rem;
  color: var(--text-dim);
  line-height: 1.5;
  margin: 0;
}

.help-body dd em {
  color: var(--text);
  font-style: normal;
  font-family: var(--font-mono);
  font-size: 0.7rem;
}

.help-body dd strong {
  color: var(--text);
  font-weight: 600;
}

.help-body dd code {
  display: block;
  margin-top: 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 0.2rem 0.45rem;
  border-radius: 3px;
  overflow-wrap: break-word;
  word-break: break-all;
}

/* ─── Toast ───────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border-bright);
  color: var(--text);
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius);
  font-size: 0.8rem;
  z-index: 300;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateX(-50%) translateY(6px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ─── Error / warning banner ──────────────────────────── */

.error-banner {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-text);
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  font-size: 0.825rem;
}

.error-banner em {
  color: var(--text);
  font-style: normal;
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

/* ─── Clock cards ─────────────────────────────────────── */

.clock-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 2rem;
}

.clock-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.25rem 1rem;
  min-width: 210px;
  flex: 1 1 210px;
  max-width: 300px;
  position: relative;
  cursor: grab;
  user-select: none;
  transition: border-color 0.15s, background 0.15s;
}

.clock-card:hover {
  border-color: var(--border-bright);
}

.clock-card.dragging {
  opacity: 0.35;
  cursor: grabbing;
}

.clock-card.drag-over {
  border-color: var(--accent);
  background: var(--drag-over);
}

.card-remove {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: none;
  border: none;
  color: var(--text-dimmer);
  cursor: pointer;
  font-size: 1.1rem;
  width: 1.75rem;
  height: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}

.card-remove:hover {
  color: var(--error-text);
  background: var(--error-bg);
}

.card-tz-name {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-bottom: 0.6rem;
  padding-right: 1.5rem;
  letter-spacing: 0.02em;
  line-height: 1.3;
  min-height: 1.8em;
}

.card-time {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--text);
  margin-bottom: 0.5rem;
  line-height: 1;
}

.card-time .ampm {
  font-size: 0.9rem;
  color: var(--text-dim);
  margin-left: 0.2em;
}

.card-date {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 0.35rem;
}

.card-offset {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--accent);
  letter-spacing: 0.04em;
}

/* ─── Timeline ────────────────────────────────────────── */

#timeline-section {
  margin-top: 0.5rem;
}

.timeline-scroll-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.timeline-grid {
  display: grid;
  /* columns set dynamically via JS: sticky label + 24 hour cells */
  min-width: max-content;
}

/* Corner cell (top-left) */
.tl-corner {
  background: var(--surface);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  position: sticky;
  left: 0;
  z-index: 3;
  padding: 0.45rem 0.75rem;
  font-size: 0.65rem;
  color: var(--text-dim);
  font-family: var(--font-ui);
}

/* Header hour labels */
.tl-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 0.45rem 0;
  font-size: 0.65rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
  text-align: center;
}


.tl-header.tl-now {
  color: var(--accent);
  background: var(--accent-dim);
}

/* Row label (sticky left) */
.tl-row-label {
  background: var(--surface);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 0 0.75rem;
  font-size: 0.65rem;
  color: var(--text-dim);
  font-family: var(--font-ui);
  display: flex;
  align-items: center;
  position: sticky;
  left: 0;
  z-index: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Hour cells */
.tl-cell {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 0.45rem 0;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-align: center;
  color: var(--text);
  transition: background 0.08s;
}

.tl-cell.tl-now {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}

.tl-cell.tl-next-day {
  color: var(--text-dimmer);
}

/* Column hover highlight */
.tl-header.tl-col-hover,
.tl-cell.tl-col-hover {
  background: var(--accent-row);
}

.tl-header.tl-now.tl-col-hover,
.tl-cell.tl-now.tl-col-hover {
  background: var(--accent-dim);
}


/* ─── Utilities ───────────────────────────────────────── */

.hidden {
  display: none !important;
}

/* ─── Responsive ──────────────────────────────────────── */

@media (max-width: 600px) {
  :root {
    --tl-label-col: 120px;
  }

  body {
    padding: 1rem 1rem 2rem;
  }

  header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  #tz-search {
    width: 100%;
  }

  .controls {
    width: 100%;
  }

  .search-wrapper {
    flex: 1;
  }

  #search-results {
    width: 100%;
  }

  .clock-card {
    max-width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    animation: none;
  }
  .clock-card,
  .format-btn,
  #tz-search,
  .card-remove,
  .tl-cell,
  .tl-header {
    transition: none;
  }
}
