/* layout and components. every colour is a token from tokens.css. */

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

/* the ground is a ledger page: faint horizontal rules, like the ruled endpapers
   behind the Field Book's own plates. barely there in either theme. */
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg);
  background-image: repeating-linear-gradient(to bottom, transparent 0 27px, var(--stripe) 27px 28px);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}

a {
  color: inherit;
}

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

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

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 10;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
}

.skip-link:focus {
  top: 12px;
}

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

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px 16px 8px;
}

/* the wordmark, set on the field book title page's own double rule: a hairline,
   a gap, then a heavier accent rule underneath */
.wordmark {
  display: inline-flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  margin: 0;
  min-width: 0;
}

.wordmark-word {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  line-height: 1;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.wordmark-rule {
  height: 4px;
  border-top: 1px solid var(--ink);
  border-bottom: 2px solid var(--accent);
}

/* the theme control as a small dial: a roundel with a gilt inner ring, echoing
   the sun mark on the Patek 1415's own 24-hour ring */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: var(--target);
  height: var(--target);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  box-shadow: inset 0 0 0 3px var(--surface), inset 0 0 0 4px var(--accent);
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
}

/* ---------------------------------------------------------------- main */

main {
  flex: 1;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 8px 16px 32px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--pad);
}

/* ---------------------------------------------------------------- shared bits */

main > * + * {
  margin-top: 16px;
}

h2 {
  margin: 0 0 6px;
  font-size: 1.05rem;
  font-weight: 600;
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

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

.field {
  display: block;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.field-error {
  margin: 6px 0 0;
  color: var(--danger);
  font-size: 0.875rem;
}

.field-error:empty {
  display: none;
}

input[type="text"],
input[type="date"],
select {
  width: 100%;
  min-height: var(--target);
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--field);
  color: var(--ink);
  font: inherit;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--target);
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}

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

.btn.small {
  padding: 6px 12px;
  font-size: 0.875rem;
}

.btn:disabled {
  border-style: dashed;
  background: transparent;
  color: var(--muted);
  cursor: not-allowed;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--gap);
  margin-top: 12px;
}

.grow {
  flex: 1 1 200px;
}

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  margin: 0 0 16px;
  padding: 12px 16px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
}

.banner p {
  margin: 0;
}

.banner.error {
  border-color: var(--danger);
  color: var(--danger);
}

.banner[hidden] {
  display: none;
}

/* ---------------------------------------------------------------- hero */

.hero {
  display: grid;
  gap: 20px;
}

.hero-number p {
  margin: 0;
}

/* the hero as a watch dial: an ink case ring, a gap, then a gilt bezel ring
   around the face the giant time sits on, after the Patek 1415's own case */
.dial {
  position: relative;
  padding: 18px 20px 20px;
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow:
    inset 0 0 0 4px var(--surface),
    inset 0 0 0 5px var(--accent);
}

.hero-label {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero-time {
  font-family: var(--font-display);
  font-size: clamp(3rem, 14vw, 5.5rem);
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.hero-number p.hero-date {
  margin-top: 10px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.hero-number p.hero-fit {
  margin-top: 4px;
  color: var(--accent-text);
  font-weight: 600;
}

.controls {
  display: grid;
  gap: 16px;
  align-content: start;
}

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

.chips legend {
  float: left;
  width: 100%;
}

.chip {
  position: relative;
}

.chip input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}

.chip span {
  display: inline-flex;
  align-items: center;
  min-height: var(--target);
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.9375rem;
}

.chip input:checked + span {
  border-color: transparent;
  background: var(--accent-fill);
  color: var(--accent-ink);
}

.chip input:focus-visible + span {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

@media (min-width: 820px) {
  .hero {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
    align-items: center;
  }
}

/* ---------------------------------------------------------------- timeline */

.timeline {
  --label: 0px;
  --cursor: 0%;
  --span: 4%;
}

.timeline-head {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin: calc(var(--pad) * -1) calc(var(--pad) * -1) 16px;
  padding: 14px var(--pad);
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--surface);
}

.ref-label {
  margin: 0;
  min-width: 0;
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.ref-select {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1 1 220px;
  max-width: 340px;
}

/* a select sizes to its longest option (America/Argentina/Buenos_Aires); let it shrink */
.ref-select select,
select {
  min-width: 0;
  max-width: 100%;
}

.ref-select select {
  flex: 1 1 auto;
}

.ref-select span {
  color: var(--muted);
  font-size: 0.8125rem;
  white-space: nowrap;
}

.add {
  position: relative;
  margin-bottom: 20px;
}

.combo {
  position: relative;
}

.suggestions {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 4;
  max-height: 320px;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.suggestion {
  display: flex;
  flex-direction: column;
  min-height: var(--target);
  justify-content: center;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.suggestion[aria-selected="true"] {
  background: var(--field);
  box-shadow: inset 3px 0 0 var(--accent);
}

.s-name {
  font-weight: 600;
}

.s-region {
  color: var(--muted);
  font-size: 0.8125rem;
}

.grid {
  position: relative;
  touch-action: pan-y;
}

.band-row,
.person {
  display: grid;
  grid-template-columns: var(--label) minmax(0, 1fr);
  column-gap: 0;
  align-items: center;
}

.band-row-label {
  color: var(--muted);
  font-size: 0.75rem;
  display: none;
}

.track {
  position: relative;
  grid-column: 2;
}

.overlap-track {
  height: 12px;
  margin-bottom: 6px;
  border-radius: 6px;
  background: var(--field);
  cursor: pointer;
}

.overlap {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 6px;
}

.overlap.fit {
  background: var(--accent);
}

.overlap.least-bad {
  background: var(--band-early);
}

.overlap.least-bad[data-rank="1"] {
  background: var(--band-evening);
}

.ruler-track {
  height: 30px;
  cursor: pointer;
}

.ruler {
  position: absolute;
  inset: 0;
  border-bottom: 1px solid var(--border);
}

.tick {
  position: absolute;
  bottom: 4px;
  transform: translateX(-50%);
  color: var(--muted);
  font-size: 0.75rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.tick:first-child {
  transform: none;
}

.cursor-handle {
  position: absolute;
  top: 0;
  bottom: -2px;
  left: var(--cursor);
  width: 16px;
  margin-left: -8px;
  z-index: 2;
  cursor: grab;
}

/* the handle's visible part: a pin head over the ruler */
.cursor-handle::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: var(--ink);
}

.cursor-handle::after {
  content: "";
  position: absolute;
  left: 7px;
  top: 12px;
  bottom: 0;
  width: 2px;
  background: var(--ink);
}

.cursor-handle:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.people {
  margin: 0;
  padding: 0;
  list-style: none;
}

.person {
  row-gap: 8px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.person:last-child {
  border-bottom: 0;
}

.person-head {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  min-width: 0;
}

/* a numbered specimen chip, like the plate numbers on the Field Book's own
   "Flower Colors of the North Temperate Zone" chart; decorative, never the
   only way a row is told apart */
.chip-num {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 20px;
  border: 1px solid var(--ink);
  font-family: var(--font-display);
  font-size: 0.8125rem;
  color: var(--muted);
  align-self: flex-start;
  margin-top: 2px;
}

.who {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1 1 160px;
}

.name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.place {
  color: var(--muted);
  font-size: 0.8125rem;
  overflow-wrap: anywhere;
}

.reading {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.reading .time {
  font-weight: 600;
}

.reading .day {
  color: var(--muted);
  font-size: 0.875rem;
}

.day-shift {
  padding: 1px 8px;
  border: 1px solid var(--warn);
  border-radius: 999px;
  color: var(--warn);
  font-size: 0.75rem;
  font-weight: 600;
}

.band-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.8125rem;
}

.band-name::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--swatch, var(--band-asleep));
}

.band-name[data-band="work"] { --swatch: var(--band-work); }
.band-name[data-band="early"] { --swatch: var(--band-early); }
.band-name[data-band="evening"] { --swatch: var(--band-evening); }
.band-name[data-band="late"] { --swatch: var(--band-late); }
.band-name[data-band="asleep"] { --swatch: var(--band-asleep); }

.row-actions {
  display: flex;
  gap: 8px;
}

.strip {
  position: relative;
  grid-column: 2;
  height: 28px;
  border-radius: 6px;
  background: var(--band-asleep);
  cursor: pointer;
}

.seg {
  position: absolute;
  top: 0;
  bottom: 0;
}

.seg:first-child {
  border-radius: 6px 0 0 6px;
}

.seg:nth-last-child(1 of .seg) {
  border-radius: 0 6px 6px 0;
}

.band-work { background: var(--band-work); }
.band-early { background: var(--band-early); }
.band-evening { background: var(--band-evening); }
.band-late { background: var(--band-late); }
.band-asleep {
  background: repeating-linear-gradient(135deg, var(--band-asleep) 0 6px, var(--stripe) 6px 8px), var(--band-asleep);
}

/* the meeting's span, outlined, and the cursor line, on every strip */
.strip::before {
  content: "";
  position: absolute;
  top: -3px;
  bottom: -3px;
  left: var(--cursor);
  width: var(--span);
  border: 2px solid var(--ink);
  border-radius: 6px;
  z-index: 1;
  pointer-events: none;
}

.midnight {
  position: absolute;
  top: -6px;
  bottom: -6px;
  width: 0;
  border-left: 2px dashed var(--ink);
  z-index: 1;
  pointer-events: none;
}

.midnight-label {
  position: absolute;
  top: -14px;
  left: 4px;
  color: var(--ink);
  font-size: 0.6875rem;
  font-weight: 600;
  white-space: nowrap;
}

.person .strip {
  margin-top: 10px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 0.8125rem;
}

.legend li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
}

.editor {
  grid-column: 1 / -1;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--field);
}

.editor .row {
  margin-top: 12px;
}

.hours {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin: 12px 0 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.hours legend {
  padding: 0;
}

.empty {
  padding: 20px 0 8px;
}

.empty p {
  margin: 0 0 12px;
  color: var(--muted);
}

/* below 720px there is room for a label every six hours, not every three */
.tick.minor {
  display: none;
}

@media (min-width: 720px) {
  .timeline {
    --label: 220px;
  }

  .band-row,
  .person {
    column-gap: 16px;
  }

  .tick.minor {
    display: block;
  }

  .band-row-label {
    display: block;
  }

  .person-head {
    grid-column: 1;
    flex-direction: column;
    align-items: flex-start;
  }

  .who {
    flex: none;
  }

  .person .strip {
    margin-top: 0;
  }

  .editor {
    grid-column: 1 / -1;
  }
}

/* ---------------------------------------------------------------- results */

.windows {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.window {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: var(--target);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--field);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-fill);
  color: var(--accent-ink);
  font-weight: 600;
  font-size: 0.875rem;
}

.window-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.window-range {
  font-weight: 600;
}

.window-damage {
  color: var(--muted);
  font-size: 0.875rem;
  overflow-wrap: anywhere;
}

.warning-list {
  margin: 8px 0 0;
  padding-left: 20px;
  color: var(--warn);
}

.warning-list li + li {
  margin-top: 6px;
}

/* ---------------------------------------------------------------- output */

pre#pasteBlock {
  margin: 8px 0 0;
  padding: 14px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--field);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.subhead {
  margin: 24px 0 6px;
  font-size: 0.95rem;
  font-weight: 600;
}

/* the table scrolls inside its own box so the page never does */
.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.slot-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

.slot-table caption {
  padding: 10px 12px;
  color: var(--muted);
  text-align: left;
}

.slot-table th,
.slot-table td {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.slot-table th {
  color: var(--muted);
  font-weight: 600;
}

/* ---------------------------------------------------------------- groups */

.group-list {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.group-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.group-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.group-count {
  color: var(--muted);
  font-size: 0.875rem;
  flex: 1;
}

.group-actions {
  display: flex;
  gap: 8px;
}

[hidden] {
  display: none !important;
}

/* ---------------------------------------------------------------- notices */

.notice {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--bg);
}

.notice-card {
  max-width: 460px;
  padding: var(--pad);
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}

.notice-card h1 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 400;
}

.notice-card p {
  margin: 0;
  color: var(--muted);
}

/* ---------------------------------------------------------------- footer */

.site-footer {
  padding: 24px 16px 32px;
  text-align: center;
  font-size: 0.875rem;
}

.footer-link {
  color: var(--muted);
  text-decoration: none;
}

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