/*
  Board styles.

  Sizes are expressed in vw/vh via clamp() rather than fixed pixels, so the board
  survives being moved to a screen that isn't exactly 1920x1080 — which the
  previous version did not.

  No @import, no CDN, no web font. The system font stack is always available and
  can never stop resolving. v2 imported Font Awesome Pro from a licensed CDN
  whose subscription was tied to a staff member who has since retired.
*/

:root {
  --gap: clamp(12px, 1.2vw, 24px);
  --radius: clamp(10px, 0.9vw, 20px);

  --ink: #1c1c1e;
  --ink-soft: #5c5c66;
  --surface: #ffffff;
  --line: #e2e2e8;
  --accent: #7b1e2b;
  --warn: #8a5a00;
  --warn-bg: #fdf3dc;
  --error: #9b1c1c;
  --error-bg: #fdeaea;

  /* Height of the Google Slides player's control bar, cropped away. Tune by
     eye against the real screen; see .slides-frame. */
  --slides-chrome: 32px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(135deg, #f0dede, #f5ead3 55%, #dee7f2);
  display: flex;
  flex-direction: column;
}

/* ---------------------------------------------------------------- Header */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(16px, 2vw, 40px) clamp(20px, 2.4vw, 48px) var(--gap);
  gap: var(--gap);
}

.masthead h1 {
  margin: 0;
  font-size: clamp(24px, 2.6vw, 52px);
  color: var(--accent);
  letter-spacing: -0.01em;
}

.masthead #date {
  margin: 0.15em 0 0;
  font-size: clamp(15px, 1.5vw, 30px);
  color: var(--ink-soft);
}

#time {
  margin: 0;
  font-size: clamp(34px, 4.2vw, 84px);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

/* ------------------------------------------------------------------ Grid */

main {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: var(--gap);
  padding: 0 clamp(20px, 2.4vw, 48px) clamp(20px, 2.4vw, 48px);
}

/*
  LAYOUTS
  =======

  Each layout is a grid defined here and selected by `data-layout` on <main>,
  set from board.config.json by main.js.

  Why here and not in config: the CSP sets `style-src 'self'`, which blocks
  inline styles — silently, with no console error. Writing
  `main.style.gridTemplateAreas` from JS would look correct in the source and do
  nothing at all. Config declares each layout's slot LIST so JS knows which
  panels to render; the arrangement itself lives here.

  Adding a layout means three things, and test/layout.test.js checks all three
  agree:
    1. a `main[data-layout="<name>"]` rule below,
    2. a matching entry in `layouts` in board.config.json with the same slots,
    3. a panel configured for each of those slots.

  Slot names are semantic (schedule, daily-post, coming-up) rather than
  positional (left-top), so moving a panel across the screen is a change to the
  layout's `grid-template-areas` and nothing else.

  A note on sizing the slide deck: `coming-up` holds a 16:9 Google Slides embed,
  which is the least flexible element on the board. Its area wants to be roughly
  16:9 or wider, or the deck letterboxes. On a 1920x1080 screen the areas below
  give it about 680x400 — close enough that the frame fills it.
*/

/* Standard day: slide deck and absences stacked right, Daily Post centre. */
main[data-layout="standard"] {
  grid-template-columns: 0.8fr 1.6fr 1.5fr;
  /* Top row is taller so the 16:9 deck clears the panel chrome — an even split
     leaves it ~44px short and Google letterboxes the slide. */
  grid-template-rows: 1.15fr 0.85fr;
  grid-template-areas:
    "schedule daily-post coming-up"
    "schedule daily-post absences";
}

/* Adds the announcements column — for days with a notice worth featuring. */
main[data-layout="announcements"] {
  grid-template-columns: 0.9fr 1.5fr 1.4fr;
  /* Same reason as the standard layout: the deck row carries the chrome cost. */
  grid-template-rows: 1.15fr 0.85fr;
  grid-template-areas:
    "schedule daily-post coming-up"
    "absences daily-post announcements";
}

/* No slide deck: Daily Post takes the width the deck would have used. */
main[data-layout="no-slides"] {
  grid-template-columns: 1fr 2fr 1fr;
  grid-template-rows: 1fr 1fr;
  grid-template-areas:
    "schedule daily-post announcements"
    "absences daily-post announcements";
}

/* Schedule and absences stacked left; Daily Post above the deck, both spanning
   the middle and right columns. Gives the deck the full width of the board but
   costs the Daily Post most of its height — see test/geometry.test.js output. */
main[data-layout="wide"] {
  grid-template-columns: 0.8fr 1.5fr 1.7fr;
  grid-template-rows: 0.8fr 1.2fr;
  grid-template-areas:
    "schedule daily-post daily-post"
    "absences coming-up  coming-up";
}

/* Deck gets a tall right-hand column to itself. 16:9 is width-hungry, so a tall
   column it can fill edge to edge renders a bigger slide than a short wide one
   — without taking height from the Daily Post. */
main[data-layout="slides-right"] {
  grid-template-columns: 0.7fr 1.4fr 1.9fr;
  grid-template-rows: 1fr 1fr;
  grid-template-areas:
    "schedule daily-post coming-up"
    "absences daily-post coming-up";
}

/* Reference info pinned left at a third of the width; the rest is one big
   stage that the Daily Post and the slide deck take turns on. Rotating a
   LOOKUP would be wrong — someone checking whether their teacher is out cannot
   wait for the carousel — so only browse content rotates. */
main[data-layout="rotate"] {
  grid-template-columns: 1fr 2fr;
  grid-template-rows: 1fr 1fr;
  grid-template-areas:
    "schedule stage"
    "absences stage";
}

/* Stage occupants are stacked in the same grid area; all but the active one
   are [hidden]. Keeping them mounted means no refetch and no reflow on each
   change — the swap is just a visibility flip. */
[data-slot="stage"] { grid-area: stage; }

/* Slot -> grid area. One line per slot, shared by every layout. */
[data-slot="schedule"]      { grid-area: schedule; }
[data-slot="daily-post"]    { grid-area: daily-post; }
[data-slot="coming-up"]     { grid-area: coming-up; }
[data-slot="absences"]      { grid-area: absences; }
[data-slot="announcements"] { grid-area: announcements; }
[data-slot="lunch"]         { grid-area: lunch; }

/* ---------------------------------------------------------------- Panels */

daily-post-panel,
announcements-panel,
coming-up-panel,
absences-panel,
schedule-panel,
lunch-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

/*
  The `hidden` attribute must actually hide things.

  The panel rule above sets `display: flex` on those element selectors, and an
  author `display` declaration beats the browser's own `[hidden] { display: none }`
  — so `element.hidden = true` silently does nothing. On the rotating stage that
  means every occupant stays visible and they superimpose on each other.

  !important is the right tool here: this must outrank any component's own
  display value, whatever it is.
*/
[hidden] { display: none !important; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5em;
  padding: 0.7em 1em;
  border-bottom: 1px solid var(--line);
  flex: none;
}

.panel-head h2 {
  margin: 0;
  font-size: clamp(13px, 1.05vw, 21px);
  font-weight: 600;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.panel-badge {
  font-size: clamp(11px, 0.85vw, 17px);
  padding: 0.25em 0.7em;
  border-radius: 999px;
  background: var(--warn-bg);
  color: var(--warn);
  white-space: nowrap;
}

[data-status="error"] .panel-badge {
  background: var(--error-bg);
  color: var(--error);
}

.panel-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: var(--gap);
  overflow: hidden;
}

/* A panel showing an error gets a tinted edge — legible from across a hallway,
   which is the only distance that matters here. */
[data-status="error"] { border-color: #e8bcbc; }
[data-status="stale"] { border-color: #e8d5a8; }

/* ----------------------------------------------------------- Panel states */

.panel-note {
  margin: 0;
  text-align: center;
  font-size: clamp(16px, 1.5vw, 30px);
  color: var(--ink-soft);
}

.panel-note-error { color: var(--error); font-weight: 600; }

.panel-detail {
  margin: 0.6em 0 0;
  text-align: center;
  font-size: clamp(12px, 0.95vw, 19px);
  color: var(--ink-soft);
}

/* ------------------------------------------------------- Announcements */

.scroll-window {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  margin: calc(var(--gap) * -1);
  padding: var(--gap);
}

/*
  Uniform spacing via `gap`, not margin-bottom with a :last-child exception.

  The Daily Post loops by rendering its content twice and translating by the
  height of one copy. Any spacing that differs at the end of a copy shows up as
  a visible hitch at the wrap, so every gap here must be identical — including
  the one between the last card of copy 1 and the first card of copy 2.
*/
.scroll-track {
  display: flex;
  flex-direction: column;
  gap: 0.7em;
  will-change: transform;
}

.card {
  background: #fbf7ef;
  border: 1px solid #ece2cf;
  border-radius: calc(var(--radius) * 0.6);
  padding: 0.8em 1em;
  flex: none;
}

.card h3 {
  margin: 0 0 0.3em;
  font-size: clamp(16px, 1.35vw, 27px);
  color: var(--accent);
}

.card > * + * { margin-top: 0.45em; }

.card-list {
  margin: 0;
  padding-left: 1.15em;
  font-size: clamp(13px, 1.1vw, 22px);
  line-height: 1.4;
}

.card-list li { margin: 0.15em 0; }

.card p {
  margin: 0;
  font-size: clamp(13px, 1.1vw, 22px);
  line-height: 1.45;
}

/* The centre column is the main reading surface, so it gets a size bump. */
daily-post-panel .card h3 { font-size: clamp(17px, 1.5vw, 30px); }
daily-post-panel .card p,
daily-post-panel .card-list { font-size: clamp(14px, 1.22vw, 25px); }

/* ------------------------------------------------------------- Absences */

.chip-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
  justify-content: center;
}

.chip {
  background: #f5ead3;
  border: 1px solid #e6d6b4;
  border-radius: calc(var(--radius) * 0.5);
  padding: 0.45em 0.8em;
  font-size: clamp(14px, 1.2vw, 24px);
}

/* ------------------------------------------------------------- Schedule */

.schedule { text-align: center; }

/* Today is not a normal day. Deliberately the most prominent thing in the
   panel after the headline — the times being different matters less than
   people knowing they are different. */
.schedule-adjusted {
  margin: 0 0 0.5em;
  align-self: center;
  padding: 0.3em 0.9em;
  border-radius: 999px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: clamp(12px, 1vw, 20px);
  font-weight: 600;
  letter-spacing: 0.03em;
}

.schedule-label {
  margin: 0 0 0.2em;
  font-size: clamp(12px, 1vw, 20px);
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* The headline is either the period name or, near a transition, the countdown.
   Both need to be readable from the far end of a hallway. */
.schedule-headline {
  margin: 0;
  font-size: clamp(26px, 2.9vw, 58px);
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

.schedule-foot {
  margin: 0.6em 0 0;
  font-size: clamp(12px, 1.05vw, 21px);
  color: var(--ink-soft);
}

/* Inside the warning window the panel shifts colour, so a passer-by registers
   "something is about to happen" before reading any words. */
.schedule[data-tone="urgent"] .schedule-headline { color: var(--accent); }
.schedule[data-tone="urgent"] /* Today is not a normal day. Deliberately the most prominent thing in the
   panel after the headline — the times being different matters less than
   people knowing they are different. */
.schedule-adjusted {
  margin: 0 0 0.5em;
  align-self: center;
  padding: 0.3em 0.9em;
  border-radius: 999px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: clamp(12px, 1vw, 20px);
  font-weight: 600;
  letter-spacing: 0.03em;
}

.schedule-label { color: var(--accent); opacity: 0.8; }

/* ---------------------------------------------------------------- Lunch */

.lunch {
  margin: 0;
  text-align: center;
  font-size: clamp(16px, 1.5vw, 30px);
  line-height: 1.4;
}

/* ------------------------------------------------------- Embedded frame */

/*
  The Coming Up slide deck.

  Google's embedded player draws a control bar along the bottom — prev/next
  arrows, a slide counter and a "Google Slides" link. There is no parameter to
  turn it off, so it is CROPPED: the wrapper is the visible box with
  `overflow: hidden`, and the iframe inside is made taller than the wrapper by
  exactly the bar's height. The bar renders below the clip and the slide gets
  the whole visible box.

  --slides-chrome is that bar's height. If a sliver of it shows, or the slide
  looks slightly cut off at the bottom, nudge this value — it is the one number
  worth tuning by eye against the real screen.

  The wrapper is width-driven with a max-height guard. Where the area is taller
  than 16:9 the slide fills it exactly; where the area is wider, the wrapper
  clamps and Google letterboxes the slide inside with bars to the sides. Either
  way the slide keeps its shape.
*/
.slides-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 100%;
  margin: auto;
  overflow: hidden;
  background: #000;
  border-radius: calc(var(--radius) * 0.4);
}

.slides-frame iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: calc(100% + var(--slides-chrome));
  border: 0;
  display: block;
}

/* A panel that is deliberately unfinished reads as pending, not broken. */
[data-status="static"] .panel-body { justify-content: center; }
[data-status="static"] .panel-note { color: var(--ink-soft); }

/* -------------------------------------------------------------- Credits */

/*
  A slim colophon. Deliberately quiet — present enough to be a real
  acknowledgement, small enough that it never competes with the panels.
*/
#credits {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: baseline;
  gap: 0.6em;
  padding: 0 clamp(20px, 2.4vw, 48px) clamp(10px, 1.1vw, 20px);
  font-size: clamp(10px, 0.78vw, 15px);
  color: var(--ink-soft);
  opacity: 0.75;
  letter-spacing: 0.02em;
}

#credits .credit-sep { opacity: 0.5; }

/* ---------------------------------------------------------------- Fatal */

.fatal {
  grid-area: center;
  align-self: center;
  text-align: center;
  color: var(--error);
}
