/*
 * THE EZ CLOCK — base.css
 * ez.sy
 *
 * Layout, typography, and structure. No colour literals: every colour
 * comes from a token defined in themes.css.
 *
 * Load order matters. themes.css first, then base.css, then clock.css.
 *
 * Page anatomy:
 *   .hero      your own clock. Never changes location when a theme
 *              changes. Only its palette and type change.
 *   .wall      the eleven city clocks. The active theme's city is
 *              promoted to a full-width row, the other ten sit in a
 *              two-column grid. Purely passive: tapping does nothing.
 */

/* ------------------------------------------------------------------ *
 * Reset
 * ------------------------------------------------------------------ */

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

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

body,
h1, h2, h3, h4, h5, h6,
p, figure, blockquote, dl, dd, ul, ol {
  margin: 0;
  padding: 0;
}

ul, ol {
  list-style: none;
}

img, svg {
  display: block;
  max-width: 100%;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

/* ------------------------------------------------------------------ *
 * Document
 * ------------------------------------------------------------------ */

html {
  background: var(--bg);
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;

  /* iOS home-screen app: respect the notch and the home indicator. */
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);

  /* Theme changes should feel like a change of light, not a flash. */
  transition:
    background-color var(--transition),
    color var(--transition);
}

/* Standalone mode: no browser chrome, so the page is the app. */
@media (display-mode: standalone) {
  body {
    overscroll-behavior-y: none;
  }
}

/* ------------------------------------------------------------------ *
 * Typography
 * ------------------------------------------------------------------ */

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 400;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--ink);
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.175rem; }
h4 { font-size: 1rem; }

p + p {
  margin-top: 1em;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

a:hover {
  color: var(--ink);
}

code, kbd, samp {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

strong {
  font-weight: 600;
}

.lede {
  font-size: 1.125rem;
  color: var(--ink-soft);
  max-width: 38ch;
}

.label {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.muted {
  color: var(--ink-soft);
}

/* Visible only to screen readers. Used to give the clock a readable
   text equivalent, since a dial and a shadow figure are meaningless
   without one. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ------------------------------------------------------------------ *
 * Layout primitives
 * ------------------------------------------------------------------ */

.wrap {
  width: 100%;
  max-width: 1080px;
  margin-inline: auto;
  padding-inline: 20px;
}

.wrap--narrow {
  max-width: 720px;
}

.stack > * + * {
  margin-top: var(--stack-gap, 1rem);
}

.section {
  padding-block: 56px;
}

.section + .section {
  border-top: 1px solid var(--line);
}

.rule {
  height: 1px;
  background: var(--line);
  border: 0;
}

/* ------------------------------------------------------------------ *
 * Site header
 * ------------------------------------------------------------------ */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-block: 18px;
  border-bottom: 1px solid var(--line);
}

.site-header__mark {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  letter-spacing: 0.02em;
  color: var(--ink);
  text-decoration: none;
}

.site-header__mark span {
  color: var(--accent);
}

.site-nav {
  display: flex;
  gap: 18px;
}

.site-nav a {
  font-size: 0.875rem;
  color: var(--ink-soft);
  text-decoration: none;
}

.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--ink);
}

/* ------------------------------------------------------------------ *
 * Hero
 *
 * Your own clock. Location is set here and only here.
 * ------------------------------------------------------------------ */

.hero {
  padding-block: 40px 48px;
  border-bottom: 1px solid var(--line);
}

.hero__inner {
  display: grid;
  gap: 32px;
  justify-items: center;
  text-align: center;
}

.hero__place {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.hero__city {
  font-family: var(--font-display);
  font-size: 1.375rem;
  color: var(--ink);
}

.hero__coords {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
}

/* ------------------------------------------------------------------ *
 * Location controls
 * ------------------------------------------------------------------ */

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-raised);
  color: var(--ink-soft);
  border-radius: var(--radius);
  padding: 9px 15px;
  font-size: 0.8125rem;
  cursor: pointer;
  transition:
    border-color var(--transition),
    color var(--transition),
    background-color var(--transition);
  min-height: 40px;
}

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

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

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

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

.field {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}

.input,
.select {
  appearance: none;
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  padding: 9px 12px;
  font-size: 0.875rem;
  min-height: 40px;
  min-width: 0;
}

.input:focus-visible,
.select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.input--coord {
  width: 8.5rem;
  font-family: var(--font-mono);
  text-align: center;
}

/* Panels open under the controls. Hidden by default, JS toggles [hidden]. */
.panel {
  width: 100%;
  max-width: 460px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-top: 4px;
}

.panel[hidden] {
  display: none;
}

/* ------------------------------------------------------------------ *
 * Notices
 *
 * The polar fallback notice lives here. Spec §37 requires that a
 * substitute solar reference is never hidden from the user, so this
 * is deliberately prominent rather than tucked away.
 * ------------------------------------------------------------------ */

.notice {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  background: var(--bg-raised);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 0.8125rem;
  color: var(--ink-soft);
  text-align: left;
  max-width: 460px;
}

.notice[hidden] {
  display: none;
}

.notice__title {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}

.notice__detail {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-faint);
}

/* ------------------------------------------------------------------ *
 * Theme switcher
 * ------------------------------------------------------------------ */

.themes {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-block: 4px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.themes::-webkit-scrollbar {
  display: none;
}

.theme-chip {
  flex: 0 0 auto;
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-faint);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 0.75rem;
  white-space: nowrap;
  cursor: pointer;
  min-height: 34px;
  transition:
    color var(--transition),
    border-color var(--transition),
    background-color var(--transition);
}

.theme-chip:hover {
  color: var(--ink-soft);
}

.theme-chip[aria-pressed="true"] {
  color: var(--ink);
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* ------------------------------------------------------------------ *
 * The city wall
 *
 * The active theme's city is promoted to its own full-width row at the
 * top. The remaining ten fill a two-column grid beneath it. Eleven is
 * odd on purpose: one leads, ten follow.
 * ------------------------------------------------------------------ */

.wall {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.city {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px 14px;
  display: grid;
  gap: 10px;
  align-content: start;

  /* Passive by decision. No click target, no hover affordance. */
  cursor: default;
}

.city--lead {
  grid-column: 1 / -1;
  border-color: var(--accent-soft);
  padding: 20px 18px;
}

.city__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.city__name {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--ink);
}

.city--lead .city__name {
  font-size: 1.25rem;
}

.city__stage {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  text-align: right;
}

.city__coords {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  color: var(--ink-faint);
  letter-spacing: 0.03em;
}

/* Stage tint, set by JS via data-stage. The three stages must be
   visually distinct everywhere they appear, because the three-stage
   structure is the system, not a detail of it. */
.city[data-stage="night"] .city__stage { color: var(--night); }
.city[data-stage="morning"] .city__stage { color: var(--morning); }
.city[data-stage="afternoon"] .city__stage { color: var(--afternoon); }

/* ------------------------------------------------------------------ *
 * Explainer blocks
 * ------------------------------------------------------------------ */

.anchors {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.anchor {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--bg-raised);
}

.anchor__value {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  color: var(--accent);
  line-height: 1;
}

.anchor__name {
  display: block;
  margin-top: 6px;
  font-size: 0.8125rem;
  color: var(--ink-soft);
}

.stages {
  display: grid;
  gap: 10px;
}

.stage-card {
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: var(--radius);
  padding: 14px;
  background: var(--bg-raised);
}

.stage-card[data-stage="night"] { border-left-color: var(--night); }
.stage-card[data-stage="morning"] { border-left-color: var(--morning); }
.stage-card[data-stage="afternoon"] { border-left-color: var(--afternoon); }

.stage-card__range {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-faint);
}

/* ------------------------------------------------------------------ *
 * Documentation
 * ------------------------------------------------------------------ */

.doc {
  max-width: 68ch;
}

.doc h2 {
  margin-top: 2.5em;
  padding-top: 0.6em;
  border-top: 1px solid var(--line);
}

.doc h3 {
  margin-top: 1.8em;
}

.doc p,
.doc ul,
.doc ol,
.doc table {
  margin-top: 1em;
}

.doc ul,
.doc ol {
  padding-left: 1.2em;
}

.doc ul { list-style: disc; }
.doc ol { list-style: decimal; }

.doc li + li {
  margin-top: 0.35em;
}

.doc blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1em;
  margin-top: 1.2em;
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: 1.0625rem;
}

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

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

.doc th {
  color: var(--ink-faint);
  font-weight: 400;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.formula {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 1em;
  overflow-x: auto;
  white-space: pre;
  color: var(--ink-soft);
}

/* Table of contents, sticky on wide screens only. */
.toc {
  font-size: 0.875rem;
}

.toc a {
  color: var(--ink-soft);
  text-decoration: none;
  display: block;
  padding: 3px 0;
}

.toc a:hover {
  color: var(--accent);
}

/* Deep-linked sections should not land under a sticky header. */
:target {
  scroll-margin-top: 24px;
}

/* ------------------------------------------------------------------ *
 * Footer
 * ------------------------------------------------------------------ */

.site-footer {
  border-top: 1px solid var(--line);
  padding-block: 32px 40px;
  font-size: 0.8125rem;
  color: var(--ink-faint);
}

.site-footer a {
  color: var(--ink-soft);
}

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

@media (min-width: 600px) {
  h1 { font-size: 2.5rem; }
  h2 { font-size: 1.75rem; }

  .wall {
    grid-template-columns: repeat(3, 1fr);
  }

  .anchors {
    grid-template-columns: repeat(4, 1fr);
  }

  .stages {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 900px) {
  .section {
    padding-block: 76px;
  }

  .wall {
    grid-template-columns: repeat(4, 1fr);
  }

  .doc-layout {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 48px;
    align-items: start;
  }


/* ------------------------------------------------------------------ *
 * Print
 * ------------------------------------------------------------------ */

@media print {
  .site-nav,
  .themes,
  .controls,
  .wall {
    display: none;
  }

  body {
    background: #fff;
    color: #000;
  }
}

/* ------------------------------------------------------------------ *
 * Header mark
 *
 * The three-wedge disc stands alone. No wordmark: the mark already
 * states the system, three equal sectors with one of them dark.
 * ------------------------------------------------------------------ */

.site-header__mark {
  display: flex;
  align-items: center;
  line-height: 0;
}

.site-header__mark img {
  width: 34px;
  height: 34px;
  display: block;
}

/* ==================================================================== *
 * SETTINGS MENU
 * ==================================================================== */

.settings {
  position: relative;
  display: inline-flex;
  margin-left: 4px;
}

.settings__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: none;
  color: var(--ink-soft);
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition),
              background var(--transition);
}

.settings__btn:hover,
.settings__btn[aria-expanded="true"] {
  color: var(--ink);
  border-color: var(--line);
  background: var(--bg-raised);
}

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

.settings__menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 40;
  min-width: 216px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-raised);
  box-shadow: 0 14px 40px -12px var(--shadow);
}

.settings__menu[hidden] { display: none; }

/* Three-way switch. One control, three states, current one obvious. */
.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  margin-top: 8px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-sunk);
}

.segmented__opt {
  padding: 7px 4px;
  border: 0;
  border-radius: calc(var(--radius) - 4px);
  background: none;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.segmented__opt:hover { color: var(--ink); }

.segmented__opt[aria-checked="true"] {
  background: var(--accent);
  color: var(--bg);
}

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

/* ==================================================================== *
 * MAP PICKER
 * ==================================================================== */

.map {
  height: min(52vh, 340px);
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-sunk);
  overflow: hidden;
  z-index: 0;               /* keeps Leaflet panes below the site header */
}

.field--map {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.map__readout {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--ink-soft);
}

.btn--quiet {
  color: var(--ink-faint);
}

.hero__note {
  display: block;
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--ink-faint);
}

.hero__note:empty { display: none; }

/* Leaflet's own chrome, brought into the palette so the map does not
   look like a foreign object dropped onto the page. */
.map .leaflet-control-attribution {
  background: var(--bg-raised);
  color: var(--ink-faint);
  font-size: 0.6875rem;
}

.map .leaflet-control-attribution a { color: var(--ink-soft); }

.map .leaflet-bar a {
  background: var(--bg-raised);
  color: var(--ink);
  border-bottom-color: var(--line);
}

.map .leaflet-bar a:hover { background: var(--bg-sunk); }

/* The default OSM tiles are a light image. In dark mode they are
   knocked back so they sit with the rest of the page instead of
   glowing out of it. */
[data-mode="dark"] .map .leaflet-tile-pane {
  filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.9);
}
