/* Is My Classroom Free? — Newspaper of record stylesheet.
   Two typefaces only: Georgia (default), Helvetica Neue (labels/metadata).
   No shadows, no rounded corners, no boxed cards.
   Mobile-first: works cleanly down to 320 px.
*/

:root {
  --ink: #121212;
  --paper: #ffffff;
  --secondary: #555555;
  --tertiary: #8a8a8a;
  --rule: #d6d2c8;
  --accent: #b8312f;
  --link: #1a4480;
  --verdict-green: #2e6e3e;
  --verdict-red:   #b8312f;

  --serif: "Georgia", "Times New Roman", "Source Serif Pro", serif;
  --sans: "Helvetica Neue", "Inter", Arial, sans-serif;

  --page-margin: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

.paper {
  max-width: 920px;
  margin: 0 auto;
  padding: 20px var(--page-margin) 40px;
}

/* ---------------- Masthead ---------------- */
.masthead {
  text-align: center;
  margin-bottom: 24px;
}
.masthead-topline {
  border-top: 1px solid var(--ink);
  margin-bottom: 12px;
}
.nameplate {
  font-family: var(--serif);
  font-weight: 700;
  /* Mobile-first: clamp from 22px on small phones up to 44px desktop.
     The 6.5vw factor keeps "Is My Classroom Free?" on one line down to 320 px. */
  font-size: clamp(22px, 6.5vw, 44px);
  line-height: 1.05;
  letter-spacing: -0.015em;
  margin: 0 0 10px 0;
  font-style: italic;
  white-space: nowrap;
  /* Belt-and-braces: scale text down if it would exceed the parent. */
  max-width: 100%;
}
.masthead-rule {
  border-top: 3px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  height: 4px;
  margin: 6px 0 8px;
}
.dateline {
  font-family: var(--sans);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tertiary);
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.dateline-edition { text-align: left; }
.dateline-date { text-align: center; flex: 1; }
.dateline-week { text-align: right; display: inline-flex; gap: 8px; align-items: center; }
.week-toggle {
  font-family: var(--sans);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tertiary);
  border-bottom: 1px solid transparent;
  padding: 4px 1px;
  min-height: 28px;
}
.week-toggle.active {
  color: var(--ink);
  border-bottom: 1px solid var(--ink);
  font-weight: 700;
}
.week-toggle:hover { color: var(--ink); }
.week-sep { color: var(--rule); }

/* ---------------- Eyebrow labels ---------------- */
.eyebrow {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--secondary);
  border-top: 1px solid var(--rule);
  padding-top: 8px;
  margin-bottom: 12px;
}
.eyebrow-accent { color: var(--accent); }

/* ---------------- Prefs form ---------------- */
.prefs {
  margin-bottom: 28px;
}
.prefs-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  align-items: end;
}
.field {
  display: flex;
  flex-direction: column;
  position: relative;
  min-width: 0;
}
.field-label {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--secondary);
  margin-bottom: 4px;
}
.field-input {
  font-family: var(--serif);
  font-size: 17px;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--ink);
  border-radius: 0;
  outline: none;
  /* 44px minimum tap target. */
  padding: 10px 0 10px 0;
  min-height: 44px;
  width: 100%;
  /* Prevent iOS auto-zoom on focus. */
  -webkit-appearance: none;
  appearance: none;
}
.field-input::placeholder { color: var(--tertiary); font-style: italic; }
.field-input:focus { border-bottom-color: var(--accent); }

.field-error {
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  color: var(--accent);
  margin-top: 4px;
}

.field-action { align-items: stretch; }
.save-button {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink);
  border: 1px solid var(--ink);
  padding: 12px 18px;
  background: var(--paper);
  min-height: 44px;
  width: 100%;
}
.save-button:hover { background: var(--ink); color: var(--paper); }
.save-button:active { background: var(--ink); color: var(--paper); }
.save-button:disabled { opacity: 0.5; cursor: not-allowed; }
.save-status {
  display: block;
  margin-top: 6px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 12px;
  color: var(--secondary);
  text-align: left;
}

/* ---------------- Typeahead dropdown ---------------- */
.typeahead { position: relative; }
.typeahead-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--paper);
  border: 1px solid var(--ink);
  border-top: none;
  /* Don't extend off-screen horizontally; bounded by parent's right edge. */
  max-width: 100%;
  max-height: 50vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  z-index: 50;
}
.typeahead-list li {
  font-family: var(--serif);
  font-size: 15px;
  padding: 10px 12px;
  min-height: 40px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
}
.typeahead-list li:last-child { border-bottom: none; }
.typeahead-list li.active,
.typeahead-list li:hover {
  background: var(--ink);
  color: var(--paper);
}

/* ---------------- Answer area (dominant lead element) ---------------- */
.answer {
  margin: 24px 0 28px 0;
  border-top: 1px solid var(--rule);
  padding-top: 8px;
  /* Thick 2px rule under the verdict, like a banner under a lead story. */
  border-bottom: 2px solid var(--ink);
  padding-bottom: 18px;
}
.answer .eyebrow { border-top: none; padding-top: 0; }
.answer-headline {
  font-family: var(--serif);
  font-weight: 700;
  /* The single most dominant element after the masthead.
     Floor 80px on phones, up to 160px on desktop. */
  font-size: clamp(80px, 20vw, 160px);
  line-height: 0.95;
  letter-spacing: -0.02em;
  margin: 6px 0 14px 0;
  color: var(--ink);
}
.answer-headline.muted {
  color: var(--tertiary);
  font-style: italic;
  font-size: clamp(24px, 6.5vw, 40px);
  line-height: 1.2;
  letter-spacing: -0.005em;
}
/* Verdict state colors — JS toggles .is-free / .is-occupied on .verdict. */
.verdict.is-free     { color: var(--verdict-green); }
.verdict.is-occupied { color: var(--verdict-red); }
/* Muted edge cases (no inputs, weekend, outside school hours) override
   the state classes back to the tertiary ink color. */
.answer-headline.muted.is-free,
.answer-headline.muted.is-occupied { color: var(--tertiary); }
.answer-deck {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  /* A fraction more breathing room: 16-18 phones, 24-28 desktop. */
  font-size: clamp(16px, 3.2vw, 28px);
  line-height: 1.4;
  color: var(--secondary);
  margin: 8px 0 0 0;
  max-width: 60ch;
}

/* ---------------- Schedule strip (aside / supplementary) ---------------- */
.schedule {
  margin-top: 20px;
  margin-bottom: 28px;
}
.schedule-heading {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(20px, 4.5vw, 24px);
  line-height: 1.15;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 2px 0 10px 0;
}
.schedule-strip {
  display: grid;
  grid-template-columns: repeat(20, 1fr);
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  margin: 6px 0 4px 0;
}
.slot {
  position: relative;
  padding: 4px 1px 3px 1px;
  border-right: 1px solid var(--rule);
  text-align: center;
  font-family: var(--sans);
  font-size: 9px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--tertiary);
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  /* Prevent labels and times from breaking the column. */
  overflow: hidden;
}
.slot:last-child { border-right: none; }
.slot-label { line-height: 1; }
.slot-bar {
  width: 100%;
  height: 8px;
  margin: 4px 0;
  border-top: 1px solid var(--ink);
  background: transparent;
}
.slot-bar.busy { background: var(--ink); border-top-color: var(--ink); }
.slot-bar.mine {
  background: transparent;
  border-top: 1px solid var(--ink);
  background-image: repeating-linear-gradient(45deg, var(--ink) 0 2px, transparent 2px 5px);
}
.slot-time {
  font-size: 9px;
  color: var(--tertiary);
  line-height: 1;
  white-space: nowrap;
}
.slot.now {
  background: #fbf6e8;
}
.slot.now::after {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  border-top: 2px solid var(--accent);
}
.slot.now .slot-label { color: var(--accent); font-weight: 700; }

.schedule-legend {
  font-family: var(--sans);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--secondary);
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-top: 10px;
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-tick {
  display: inline-block;
  width: 16px;
  height: 8px;
  border-top: 1px solid var(--ink);
}
.legend-tick-free { background: transparent; }
.legend-tick-busy { background: var(--ink); }
.legend-tick-mine { background-image: repeating-linear-gradient(45deg, var(--ink) 0 2px, transparent 2px 5px); }
.legend-now-dot {
  display: inline-block;
  width: 16px; height: 2px; background: var(--accent);
}

/* ---------------- Colophon ---------------- */
.colophon {
  border-top: 1px solid var(--rule);
  padding-top: 10px;
  margin-top: 28px;
  font-family: var(--sans);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tertiary);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ---------------- Letters to the editor (public form) ---------------- */
.letters {
  margin-top: 28px;
  border-top: 1px solid var(--rule);
  padding-top: 10px;
}
.letters .eyebrow { border-top: none; padding-top: 0; }
.letters-heading {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(22px, 4.8vw, 26px);
  line-height: 1.15;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 2px 0 6px 0;
}
.letters-deck {
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(14px, 2.4vw, 16px);
  line-height: 1.4;
  color: var(--secondary);
  margin: 0 0 16px 0;
  max-width: 60ch;
}
.letters-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: start;
}
.letters-form .field-message { grid-column: 1 / -1; }
.field-textarea {
  font-family: var(--serif);
  font-size: 17px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--ink);
  border-radius: 0;
  outline: none;
  padding: 10px 12px;
  min-height: 110px;
  width: 100%;
  resize: vertical;
  line-height: 1.45;
  -webkit-appearance: none;
  appearance: none;
  box-sizing: border-box;
}
.field-textarea:focus { border-color: var(--accent); }
.letters-status {
  display: block;
  margin-top: 6px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  color: var(--secondary);
  text-align: left;
}
.letters-status.is-error { color: var(--accent); }

/* ---------------- Phone: stack the dateline ---------------- */
@media (max-width: 640px) {
  .dateline {
    flex-direction: column;
    gap: 4px;
    align-items: center;
  }
  .dateline-edition,
  .dateline-date,
  .dateline-week { text-align: center; flex: 0 0 auto; }
}

/* ---------------- Phone: tighten the schedule ---------------- */
/* On phones the 20-slot strip is denser: numbers only for most slots.
   Time labels are hidden inside slots (they don't fit at ~16 px col width)
   and re-rendered as anchored tick labels every 4 slots below the strip,
   using absolute positioning so each label can extend past its column. */
@media (max-width: 640px) {
  /* Reserve room below the slots for the tick-time labels.
     The bottom border of the strip sits below the labels. */
  .schedule-strip { position: relative; padding-bottom: 22px; }
  .slot {
    padding: 5px 0 3px 0;
    min-height: 44px;
    font-size: 8.5px;
    letter-spacing: 0;
  }
  .slot-bar { margin: 3px 0; height: 7px; }
  .slot-time {
    /* Hide by default. */
    display: none;
  }
  /* Marker slots: 1, 5, 9, 13, 17 (and 20). Anchor time label to bottom-left
     of the slot so wider strings ("10:00") don't get clipped by the column. */
  .slot:nth-child(4n+1) .slot-time,
  .slot:nth-child(20) .slot-time {
    display: block;
    position: absolute;
    left: 0;
    bottom: -12px;
    font-size: 8px;
    letter-spacing: 0;
    color: var(--tertiary);
    transform: translateX(-25%);
  }
  /* Last marker (slot 20) anchors to the right edge instead. */
  .slot:nth-child(20) .slot-time {
    left: auto;
    right: 0;
    transform: translateX(25%);
  }
  /* The slot needs to allow its time label to escape its bounds. */
  .slot { overflow: visible; }
}

/* ---------------- Narrow phones (≤360 px): squeeze further ---------------- */
@media (max-width: 360px) {
  :root { --page-margin: 14px; }
  .slot { font-size: 8px; padding: 4px 0 3px 0; }
  .slot:nth-child(4n+1) .slot-time,
  .slot:nth-child(20) .slot-time {
    font-size: 7.5px;
  }
}

/* ---------------- Tablet and up: restore horizontal dateline & 3-col form ---------------- */
@media (min-width: 641px) {
  :root { --page-margin: 32px; }
  .paper { padding-top: 28px; padding-bottom: 56px; }
  .prefs-form {
    grid-template-columns: 1fr 1fr auto;
    gap: 22px 28px;
  }
  .field-action { align-items: flex-start; }
  .save-button { width: auto; }
  .colophon {
    flex-direction: row;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
  }
  .letters-form {
    grid-template-columns: 1fr 1fr;
    gap: 18px 28px;
  }
  .letters-form .field-message { grid-column: 1 / -1; }
  .letters-form .field-action { grid-column: 1 / -1; }
  .field-textarea { min-height: 4.5em; }
}

/* ---------------- Desktop ---------------- */
@media (min-width: 1024px) {
  :root { --page-margin: 48px; }
  .paper { padding-top: 32px; padding-bottom: 64px; }
  .masthead { margin-bottom: 28px; }
}
