/* isitpeakhours — stylesheet */

:root {
  --bg: #f6f6f8;
  --surface: #ffffff;
  --surface-2: #f1f1f4;
  --border: #e6e6ec;
  --text: #17181b;
  --muted: #5d6068;

  --off: #15803d;
  --peak: #d92b2b;
  --warm: #b45309;
  --brand: #2563eb;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  --mono: "SFMono-Regular", "JetBrains Mono", ui-monospace, Menlo, Consolas,
    "Liberation Mono", monospace;
}

/* explicit light — overrides a system-dark preference */
:root[data-theme="light"] {
  --bg: #f6f6f8;
  --surface: #ffffff;
  --surface-2: #f1f1f4;
  --border: #e6e6ec;
  --text: #17181b;
  --muted: #5d6068;
  --off: #15803d;
  --peak: #d92b2b;
  --warm: #b45309;
}

/* dark — via system preference (when no explicit theme) or explicit dark */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0e12;
    --surface: #16181e;
    --surface-2: #1e2128;
    --border: #262933;
    --text: #eaebef;
    --muted: #9da2ad;
    --off: #4ade80;
    --peak: #f87171;
    --warm: #fbbf24;
  }
}

:root[data-theme="dark"] {
  --bg: #0d0e12;
  --surface: #16181e;
  --surface-2: #1e2128;
  --border: #262933;
  --text: #eaebef;
  --muted: #9da2ad;
  --off: #4ade80;
  --peak: #f87171;
  --warm: #fbbf24;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Top bar (minimal, developer-chrome) ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem clamp(1.25rem, 3vw, 2.5rem);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 0.8rem;
  min-width: 0;
}

.brand .name {
  font-size: 1.06rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand .name::before {
  content: "~/";
  font-family: var(--mono);
  font-weight: 500;
  color: var(--brand);
  margin-right: 0.15rem;
}

.brand .tagline {
  font-family: var(--mono);
  font-size: 0.86rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand .tagline::before {
  content: "# ";
  color: var(--muted);
  opacity: 0.5;
}

/* Theme toggle — icon-only, quiet */
.theme-toggle {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.15rem;
  height: 2.15rem;
  padding: 0;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease;
}

.theme-toggle:hover {
  background: var(--surface-2);
  color: var(--text);
}

.theme-toggle:active {
  transform: translateY(1px);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

/* show the moon in light mode (tap to go dark), the sun in dark mode */
.theme-toggle .icon-moon {
  display: block;
}

.theme-toggle .icon-sun {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

/* ---------- Region panes ---------- */

main {
  flex: 1;
  display: flex;
}

.panes {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

.pane {
  --accent: #333333;
  position: relative;
  overflow: hidden;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 1.25rem;
  padding: clamp(1.5rem, 3vw, 2.75rem);
  background: var(--accent);
  color: #ffffff;
}

.pane-head,
.pane-mid,
.pane-foot {
  position: relative;
  z-index: 1;
}

/* Identity solid backgrounds, one per region */
.pane[data-region="us-east"] { --accent: #1b4fd8; }
.pane[data-region="us-west"] { --accent: #0e8a8a; }
.pane[data-region="europe"]  { --accent: #7a34c9; }
.pane[data-region="china"]   { --accent: #c5342f; }

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.pane-title {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.pane-title .flag {
  font-size: 1.25rem;
  line-height: 1;
  margin-right: 0.15rem;
}

.pane-title h2 {
  margin: 0;
  font-size: 1.28rem;
  font-weight: 720;
  letter-spacing: -0.015em;
}

.pane-title .sub {
  flex-basis: 100%;
  margin: 0.15rem 0 0;
  font-size: 0.88rem;
  color: rgba(255, 255, 255, 0.94);
  font-variant-numeric: tabular-nums;
}

/* Status pill — white background, strong fixed colors (AA on white) */

.pill {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.36rem 0.85rem;
  border-radius: 999px;
  background: #ffffff;
  font-size: 0.82rem;
  font-weight: 760;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22);
}

.pill::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
}

/* Theme-independent colors tuned for contrast on the white pill:
   OFF-PEAK is the positive (green), PEAK is the negative (red). */
.pill.off { color: #0e7a35; }
.pill.peak { color: #c3211f; }
.pill.warm,
.pill.ending { color: #9a4d00; }

/* Center readout */

.pane-mid {
  text-align: center;
}

.clock {
  margin: 0;
  font-size: clamp(2.9rem, 5.4vw, 4.5rem);
  font-weight: 680;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.region-date {
  margin: 0.9rem 0 0;
  font-size: 0.92rem;
  color: rgba(255, 255, 255, 0.94);
  font-variant-numeric: tabular-nums;
}

/* Time + date reflect state: red during peak, green off-peak */
.pane[data-state="peak"] .clock,
.pane[data-state="peak"] .region-date {
  color: #ff8686;
}

.pane[data-state="off"] .clock,
.pane[data-state="off"] .region-date {
  color: #85ffb1;
}

.pane-foot {
  text-align: center;
}

.count {
  margin: 0;
  font-size: 1.28rem;
  color: rgba(255, 255, 255, 0.96);
  font-weight: 680;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* colored by state: "Peak ends…" (peak) = red, "Peak starts…" (off) = green */
.count.peak-line { color: #ff8686; }
.count.off-line { color: #85ffb1; }

/* State-change flash */

.pane.flash .clock {
  animation: clockflash 500ms ease-out;
}

@keyframes clockflash {
  0% {
    opacity: 0.4;
    transform: translateY(3px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Utilities ---------- */

.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;
}

/* ---------- Accessibility ---------- */

:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Responsive ---------- */

/* 2 columns for everything below 1600 (tablet keeps 2-col too) */
@media (max-width: 1599px) {
  .panes {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 980px) {
  .panes {
    grid-template-columns: repeat(2, 1fr);
  }

  .pane {
    min-height: 58vh;
  }
}

@media (max-width: 560px) {
  .panes {
    grid-template-columns: 1fr;
  }

  .pane {
    min-height: auto;
  }

  .tagline {
    display: none;
  }
}

/* Desktop no-scroll: exactly one viewport, no scrolling.
   The panes fill the remaining height below the top bar. */
@media (min-width: 981px) {
  html {
    height: 100%;
  }

  body {
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
  }

  .topbar {
    flex-shrink: 0;
  }

  main {
    min-height: 0;
  }

  .panes {
    height: 100%;
  }

  .pane {
    min-height: 0;
    height: 100%;
  }
}

/* 2x2 quadrants below 1600 on desktop (no-scroll) */
@media (min-width: 981px) and (max-width: 1599px) {
  .panes {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, minmax(0, 1fr));
  }
}

/* 4 columns across on very wide screens */
@media (min-width: 1600px) {
  .panes {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }
}