/* ============================================================
   Westhampton Free Library — Lobby Program Kiosk
   Single-page display optimized for a 16:9 HD touchscreen,
   landscape or portrait. All event text scales with --s.
   ============================================================ */

:root {
  --blue:      #0a57a3;   /* seal blue */
  --blue-dark: #08427c;
  --blue-soft: #e7f0f9;
  --ink:       #1b2733;
  --muted:     #5d6c7b;
  --line:      #dce4ec;
  --bg:        #f3f6f9;
  --card:      #ffffff;
  --green:     #178a4c;
  --green-soft:#e7f6ee;
  --amber:     #a86e08;
  --red:       #b23b31;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
}

/* ================= Top bar ================= */

#topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 18px;
  padding: 9px 20px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  flex: none;
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { width: 52px; height: 52px; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-name {
  font-size: 23px; font-weight: 800; color: var(--blue-dark);
  white-space: nowrap; letter-spacing: -0.01em;
}
.brand-sub {
  font-size: 11px; font-weight: 700; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--muted); white-space: nowrap;
}

/* ---- Day buttons ---- */
#daynav { display: flex; gap: 8px; justify-content: center; min-width: 0; }

.day {
  position: relative;
  display: flex; flex-direction: column; align-items: center; line-height: 1.15;
  min-width: 76px;
  padding: 6px 14px 7px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font: inherit;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.05s ease;
}
.day:active { transform: scale(0.97); }
.day .dow  { font-size: 10.5px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); }
.day .dnum { font-size: 15px;  font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }

.day.is-today { border-color: var(--blue); }
.day.is-today .dow, .day.is-today .dnum { color: var(--blue); }

.day.is-selected { background: var(--blue); border-color: var(--blue); }
.day.is-selected .dow  { color: rgba(255,255,255,0.78); }
.day.is-selected .dnum { color: #fff; }

.dcount {
  position: absolute; top: -8px; right: -8px;
  min-width: 21px; height: 21px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 6px;
  background: var(--blue-soft); color: var(--blue-dark);
  border: 2px solid #fff; border-radius: 999px;
  font-size: 11.5px; font-weight: 800; font-variant-numeric: tabular-nums;
}
.day.is-selected .dcount { background: #fff; }
.dcount.dnone { background: #eef1f4; color: #9aa7b3; }

/* ---- Right cluster: hours · clock (fixed widths so the day nav never shifts) ---- */
.top-right { display: flex; align-items: center; gap: 13px; min-width: 0; }

.pill {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 13px;
  background: #eef3f8;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 14px; font-weight: 700; color: var(--muted);
  white-space: nowrap;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: #9aa7b3; }
.pill span { overflow: hidden; text-overflow: ellipsis; }

#hourspill { width: 248px; flex: none; justify-content: center; }
#hourspill[data-tone="open"]    .dot { background: var(--green); }
#hourspill[data-tone="opens"]   .dot { background: var(--amber); }
#hourspill[data-tone="closed"]  .dot { background: #9aa7b3; }
#hourspill[data-tone="hours"]   .dot { background: var(--blue); }

.clock { width: 118px; flex: none; text-align: right; line-height: 1.08; }
.clock-time {
  font-size: 33px; font-weight: 800; color: var(--ink);
  font-variant-numeric: tabular-nums; letter-spacing: -0.01em; white-space: nowrap;
}
.clock-time .ap { font-size: 16px; font-weight: 700; color: var(--muted); margin-left: 3px; }
.clock-sub {
  display: flex; align-items: center; justify-content: flex-end; gap: 6px;
  font-size: 15px; font-weight: 800; color: var(--ink); white-space: nowrap;
}
.feed-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--amber); }
.feed-dot[data-tone="error"] { background: var(--red); }

/* ================= Stage / event grid ================= */

#stage {
  flex: 1;
  min-height: 0;
  /* top padding must clear the corner badge overhang (~17px at max scale) */
  padding: 22px 20px 18px;
  position: relative;
  overflow: hidden;
}

.grid {
  display: grid;
  gap: 0.9em;
  height: 100%;
  /* no overflow clipping here: status badges overlap the top-right card
     corners and must be able to extend above the first row */
  /* base font size × scale factor (--s) drives every dimension below */
  font-size: calc(16px * var(--s, 1));
  line-height: 1.25;
}

/* ================= Event card ================= */

.event {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.45em;
  padding: 0.85em 1em 0.9em 1.15em;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(16, 35, 61, 0.05);
  min-width: 0;
  min-height: 0;
  transition: background-color 0.4s ease, border-color 0.4s ease,
              box-shadow 0.4s ease, opacity 0.4s ease, filter 0.4s ease;
}
.event::before {
  content: "";
  position: absolute; top: 0; left: 0; bottom: 0;
  width: 5px; background: transparent;
  border-radius: 13px 0 0 13px;
}

/* --- status: in progress (blue, matches the seal) --- */
.event.is-ongoing {
  border-color: rgba(10, 87, 163, 0.55);
  background: linear-gradient(180deg, #e9f2fb 0%, #fff 55%);
  box-shadow: 0 0 0 2px rgba(10, 87, 163, 0.10), 0 2px 8px rgba(16, 35, 61, 0.08);
}
.event.is-ongoing::before { background: var(--blue); }

/* --- status: ended (dimmed, still visible) --- */
.event.is-ended { opacity: 0.52; filter: saturate(0.55); }
.event.is-ended::before { background: #b9c4cf; }

/* --- title (full card width; the status badge overlaps the corner) --- */
.ev-title {
  margin: 0;
  font-size: 1.36em; font-weight: 800; line-height: 1.16;
  color: var(--ink); letter-spacing: -0.01em;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}

/* --- status badge: overlaps the card's top-right corner --- */
.badge {
  position: absolute;
  top: -0.75em; right: -0.45em;
  z-index: 2;
  display: inline-flex; align-items: center;
  font-size: 0.72em; font-weight: 800; letter-spacing: 0.04em;
  padding: 0.32em 0.75em;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(16, 35, 61, 0.28);
  animation: badgePop 0.3s ease;
  transition: background-color 0.4s ease, color 0.4s ease;
}
.badge-now { background: var(--blue); color: #fff; }
.badge-now .b-dot {
  width: 0.55em; height: 0.55em; border-radius: 50%;
  background: #fff; margin-right: 0.4em;
  animation: pulse 1.6s ease-in-out infinite;
}
.badge-ended { background: #d8dfe6; color: #5d6c7b; }
.badge[hidden] { display: none; }

/* --- time · location row (single line, ellipsis when tight) --- */
.ev-meta {
  display: flex; align-items: center; gap: 0.4em;
  font-size: 0.95em; min-width: 0; overflow: hidden;
}
.ev-time {
  display: flex; align-items: center; gap: 0.22em;
  flex: none;
  font-weight: 700; color: var(--blue-dark);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.ev-time svg { width: 0.95em; height: 0.95em; flex: none; color: var(--blue); }
.ev-room {
  display: flex; align-items: center; gap: 0.22em;
  flex: 1 1 0; min-width: 2.5em;
  font-size: 0.93em;
  color: var(--ink); font-weight: 600;
  white-space: nowrap;
}
.ev-room svg { width: 1em; height: 1em; flex: none; color: var(--blue); }
.ev-room .rt {
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis;
}
.ev-room::before { content: "·"; color: #b3bfca; }
.ev-room:first-child::before { content: none; }

/* --- age groups (compact chips, single line, ellipsis when tight) --- */
.ev-ages {
  display: flex; flex-wrap: nowrap; gap: 0.35em;
  min-width: 0; overflow: hidden; position: relative;
}
.ev-ages.trunc::after {
  content: "…";
  position: absolute; right: 0; top: 50%; transform: translateY(-50%);
  background: var(--card); padding-left: 3px;
  font-weight: 800; color: #41505f;
}
.age {
  flex: none;
  font-size: 0.72em; font-weight: 800; letter-spacing: 0.02em;
  color: #fff;
  background: #616161;
  border-radius: 999px;
  padding: 0.24em 0.62em;
  white-space: nowrap;
}

/* --- description (clamped, ellipsis) --- */
.ev-desc {
  margin: 0;
  font-size: 0.88em; line-height: 1.3;
  color: #41505f;
  display: -webkit-box;
  -webkit-line-clamp: var(--clamp, 3);
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* single-event day: one large, centered “poster” card */
.grid.is-single .event {
  justify-content: center;
  width: 100%;
  max-width: 52%;
  margin-inline: auto;
}

/* ================= Notice states (loading / empty / error) ================= */

.notice {
  position: absolute;
  inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px;
  text-align: center;
  color: var(--muted);
  padding: 20px;
}
.notice[hidden] { display: none; }
.notice-mark img { width: 150px; height: 150px; opacity: 0.16; }
.notice-mark .glyph { font-size: 92px; line-height: 1; color: #c3cdd7; }
.notice-mark .spinner {
  width: 54px; height: 54px;
  border: 5px solid var(--blue-soft);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
.notice h2 { margin: 0; font-size: 38px; font-weight: 800; color: var(--ink); letter-spacing: -0.01em; }
.notice-sub { font-size: 19px; font-weight: 600; max-width: 720px; }
.notice-hours {
  font-size: 17px; font-weight: 700;
  background: #eef3f8; border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 999px; padding: 11px 22px;
}
.notice-hours .nh-label {
  font-size: 11px; font-weight: 800; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--muted); margin-right: 8px;
}

/* ================= Portrait orientation ================= */

@media (orientation: portrait) {
  #topbar {
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
    row-gap: 10px;
    column-gap: 14px;
    padding: 10px 16px 12px;
  }
  .brand { grid-column: 1; grid-row: 1; }
  .top-right { grid-column: 3; grid-row: 1; }
  #daynav {
    grid-column: 1 / -1; grid-row: 2;
    justify-content: stretch;
    gap: 7px;
  }
  .day { flex: 1; min-width: 0; justify-content: center; padding: 6px 4px 7px; }
  .brand img { width: 46px; height: 46px; }
  .brand-name { font-size: 19px; }
  .clock-time { font-size: 26px; }
  #hourspill { width: 224px; }
  .clock { width: 108px; }

  .grid.is-single .event { max-width: 78%; }
  .notice h2 { font-size: 30px; }
  .notice-mark img { width: 120px; height: 120px; }
}

/* ================= Motion / misc ================= */

@keyframes spin  { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes badgePop { from { transform: scale(0.55); opacity: 0; } to { transform: scale(1); opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
