:root {
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius: 14px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1216;
  --surface: #171c22;
  --inset: #1f262e;
  --border: #2a323b;
  --control: #3a444f;
  --text: #edf0f3;
  --muted: #98a4b0;
  --accent: #45c4a0;
  --on-accent: #08231b;
  --error: #ff9a9a;
  --warn: #f0c267;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #eef0f3;
  --surface: #ffffff;
  --inset: #f4f6f8;
  --border: #e0e4e9;
  --control: #bcc4cd;
  --text: #14181d;
  --muted: #58636f;
  --accent: #0b7a5e;
  --on-accent: #ffffff;
  --error: #b42323;
  --warn: #855a00;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--sans);
}

[hidden] { display: none !important; }

h1, p, dl, dd, ul { margin: 0; }
ul { padding: 0; list-style: none; }

.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

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

.page {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 24px 32px;
}

/* Header */

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.brand {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 12px;
}

h1 { font-size: 1.125rem; line-height: 1.4; }
.brand p { color: var(--muted); font-size: 0.875rem; }

.theme-toggle {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text);
  cursor: pointer;
}

.theme-toggle:hover { border-color: var(--control); }

.theme-toggle svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

[data-theme="dark"] .icon-moon, [data-theme="light"] .icon-sun { display: none; }

/* Hero: Unix clock and exchange */

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px 32px;
  align-items: start;
  margin-bottom: 16px;
  padding: 20px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.field-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.8125rem;
}

.now .field-label { margin-bottom: 0; }

.now-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 14px;
}

.now-value {
  color: var(--text);
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.now-ms { color: var(--muted); font-size: 0.875rem; }

.exchange-block { display: grid; gap: 8px; justify-self: end; width: 100%; max-width: 400px; }

.exchange-now {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 0 12px;
}

.exchange-now-label { color: var(--muted); font-size: 0.875rem; }
.exchange-now-value { font-size: 1.25rem; font-weight: 600; }
.exchange-now-zone { color: var(--muted); font-size: 0.875rem; font-weight: 400; }

.exchange-block .status {
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 400;
  text-align: right;
}

/* Tool surface */

.tool {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.tool-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px 24px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-left: -4px;
}

.tabs button {
  min-height: 36px;
  padding: 6px 14px;
  background: none;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  font: inherit;
  font-size: 0.9375rem;
  white-space: nowrap;
  cursor: pointer;
}

.tabs button:hover { color: var(--text); background: var(--inset); }

.tabs button[aria-selected="true"] {
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

.exchange {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.exchange { justify-content: flex-end; }
.exchange select { flex: 1; width: auto; min-width: 0; max-width: 320px; }

select, input {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--control);
  border-radius: 8px;
  font-size: 1rem;
}

/* Safari ignores height on native dropdowns, so draw them the same as inputs. */
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%23889' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px;
  text-overflow: ellipsis;
}

.nowrap { white-space: nowrap; }

.panel { padding: 24px; }

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
}

.big-input {
  min-height: 56px;
  font-size: 1.5rem;
  font-weight: 600;
}

.epoch-row {
  display: flex;
  gap: 8px;
  max-width: 640px;
}

.epoch-row input { flex: 1 1 auto; min-width: 0; max-width: 560px; }

.detected {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.875rem;
}

.date-entry { max-width: 560px; }

.date-wrap { position: relative; }
.date-wrap input { padding-right: 52px; font-size: 1.125rem; }

.cal-open {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
}

.cal-open:hover { background: var(--inset); color: var(--accent); }

.cal-open svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cal {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 10;
  width: 308px;
  max-width: 100%;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--control);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.3);
}

.cal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.cal-title { font-weight: 600; }

.cal-nav {
  width: 36px;
  height: 36px;
  padding: 0;
  background: none;
  border: 1px solid var(--control);
  border-radius: 8px;
  color: var(--text);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.cal-nav:hover { border-color: var(--accent); color: var(--accent); }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 2px;
}

.cal-weekdays {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

.cal-day {
  height: 36px;
  padding: 0;
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  font-size: 0.875rem;
  cursor: pointer;
}

.cal-day:hover { background: var(--inset); }
.cal-day.today { border-color: var(--control); }

.cal-day[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

.time-selects {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.chip {
  min-height: 36px;
  padding: 4px 12px;
  background: none;
  border: 1px solid var(--control);
  border-radius: 999px;
  color: var(--text);
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
}

.chip:hover { border-color: var(--accent); color: var(--accent); }

.now-btn {
  min-height: 42px;
  padding: 8px 16px;
  background: none;
  border: 1px solid var(--control);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

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

.date-confirm {
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.875rem;
}

#date-zone { font-weight: 600; }

.output {
  min-width: 0;
  padding: 20px;
  background: var(--inset);
  border-radius: 10px;
}

.empty { color: var(--muted); font-size: 0.9375rem; }

.error { margin-top: 10px; color: var(--error); font-size: 0.9375rem; }
.output .error { margin-top: 0; }
.note { margin-top: 14px; color: var(--warn); font-size: 0.875rem; }
#load-error { margin: 0 0 16px; }

.result-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 16px;
}

.result-time {
  color: var(--accent);
  font-size: clamp(2.5rem, 11vw, 3.5rem);
  font-weight: 650;
  line-height: 1.15;
}

.fraction {
  display: inline-block;
  font-size: 0.45em;
  font-weight: 600;
}

.base-row { margin-top: 14px; }

.result-sub { margin-top: 4px; font-size: 1rem; }

.pairs {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
}

.pairs > div {
  display: flex;
  gap: 12px;
  margin-top: 6px;
}

.pairs dt {
  flex: none;
  width: 7.5rem;
  color: var(--muted);
}

.pairs dd { min-width: 0; }

.status { display: block; font-weight: 600; }
.status::before { content: "● "; }
.status.open::before { color: var(--accent); }
.status.closed::before { color: var(--muted); }
.hours { display: block; color: var(--muted); }

.result-label { color: var(--muted); font-size: 0.8125rem; }

.epoch-pairs {
  display: grid;
  gap: 12px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.epoch-pairs dt { color: var(--muted); font-size: 0.8125rem; }

.epoch-pairs dd {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 14px;
}

.result-value {
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.copy {
  min-height: 30px;
  padding: 3px 12px;
  background: none;
  border: 1px solid var(--control);
  border-radius: 999px;
  color: var(--text);
  font: inherit;
  font-size: 0.8125rem;
  white-space: nowrap;
  cursor: pointer;
}

.copy:hover { border-color: var(--accent); color: var(--accent); }

/* World clock */

.world-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.tile {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  background: var(--inset);
  border: 2px solid transparent;
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.tile:hover { border-color: var(--control); }
.tile[aria-pressed="true"] { border-color: var(--accent); }

.tile-head, .tile-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 8px;
}

.tile-head { justify-content: space-between; }
.tile-name { font-size: 0.875rem; font-weight: 600; }
.tile-abbr { color: var(--muted); font-family: var(--mono); font-size: 0.75rem; }
.tile-time { font-size: 1.375rem; font-weight: 600; line-height: 1.3; }
.tile-day { color: var(--warn); font-size: 0.75rem; font-weight: 600; }
.tile .status { color: var(--muted); font-size: 0.8125rem; font-weight: 400; }

/* Page text */

.info {
  margin-top: 16px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.info > * { max-width: 72ch; }
.info > .table-wrap { max-width: none; }

.info h2 { margin: 24px 0 8px; font-size: 1.125rem; line-height: 1.3; }
.info h2:first-child { margin-top: 0; }
.info h3 { margin: 16px 0 2px; font-size: 1rem; }
.info p { margin-bottom: 10px; }
.info ul { margin-bottom: 10px; padding-left: 20px; list-style: disc; }
.info li { margin-bottom: 4px; }
.info a, .footer-links a { color: var(--accent); }

.info code {
  padding: 1px 4px;
  background: var(--inset);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.875em;
  overflow-wrap: anywhere;
}

.table-wrap { margin-bottom: 10px; overflow-x: auto; }

.info table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.info th, .info td {
  padding: 8px 12px 8px 0;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.info thead th { color: var(--muted); font-weight: 400; }
.info tbody th { font-weight: 600; }
.hours-note, .hours-notes { color: var(--muted); font-size: 0.875rem; }

.brand-name { color: var(--muted); font-size: 0.875rem; text-decoration: none; }
.brand-name:hover { color: var(--accent); }

.not-found { padding: 40px 24px; text-align: center; }
.not-found > * { max-width: none; }
.not-found h1 { margin-bottom: 8px; font-size: 1.5rem; }

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-bottom: 8px;
}

footer {
  margin-top: 20px;
  color: var(--muted);
  font-size: 0.8125rem;
}

@media (max-width: 640px) {
  .hours-table thead { display: none; }
  .hours-table, .hours-table tbody, .hours-table tr, .hours-table th, .hours-table td { display: block; }
  .hours-table tr { margin-bottom: 8px; padding: 10px 12px; background: var(--inset); border-radius: 8px; }
  .hours-table th, .hours-table td { padding: 2px 0; border: 0; }
  .hours-table td::before {
    content: attr(data-label);
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-family: var(--sans);
    font-size: 0.75rem;
  }
  .hero { grid-template-columns: minmax(0, 1fr); }
  .exchange { flex-direction: column; align-items: stretch; gap: 4px; }
  .exchange select { flex: none; width: 100%; max-width: none; }
  .exchange-block { justify-self: stretch; max-width: none; }
  .exchange-block .status { text-align: left; }
}

@media (max-width: 600px) {
  .page { padding: 24px 16px 24px; }
  .hero, .panel, .info { padding: 16px; }
  .now-value { font-size: 1.625rem; }
  .tool-bar { padding: 10px 16px; }
  .tabs { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; margin-left: 0; }
  .tabs button { padding: 6px 2px; font-size: 0.8125rem; }
  .output { padding: 16px; }
  #epoch-input { font-size: 1.125rem; }
  .result-head { min-width: 0; }
  .pairs > div { display: block; margin-top: 10px; }
  .pairs dt { width: auto; }
  .result-value { font-size: 1.0625rem; }
  .world-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: 1fr; gap: 8px; }
  .tile { align-content: start; }
  .tile-head { flex-direction: column; align-items: flex-start; }
  .tile { padding: 10px; }
  .tile-time { font-size: 1.125rem; }
}
