@font-face {
  font-family: 'DSEG7 Modern';
  font-style: normal;
  font-weight: 400;
  font-display: block;
  src: url('fonts/DSEG7Modern-Regular.woff2') format('woff2');
}
@font-face {
  font-family: 'DSEG7 Modern';
  font-style: italic;
  font-weight: 400;
  font-display: block;
  src: url('fonts/DSEG7Modern-Italic.woff2') format('woff2');
}

:root {
  /* Palette inputs; the board script overrides them from the display answer. */
  --pal-text: #ffffff;
  --pal-muted: #c2c2c2;
  --pal-accent: #ffd86b;
  --pal-panel: #000000;
  --fg: var(--pal-text);
  --muted: rgba(255, 255, 255, 0.72);
  --accent: var(--pal-accent);
  --dim: rgba(255, 255, 255, 0.5);
  --panel-bg: rgba(0, 0, 0, 0.32);
  --tile-bg: rgba(0, 0, 0, 0.20);
  --panel-border: rgba(255, 255, 255, 0.12);
  --glow: rgba(255, 255, 255, 0.35);
  /* Status colors for the default palette. */
  --c-up: #6ddc8b;
  --c-down: #ff7b7b;
  --c-overdue: #ff9a76;
  --c-err: #ffb4b4;
  font-family: var(--text-font, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif);
  /* Keeps a fallback font at the chosen font's x-height while it loads. */
  font-size-adjust: var(--text-adjust, none);
}

/* The default palette keeps the original translucent whites; a chosen palette
   derives every tint from its own colors, and pulls the status colors toward
   its text color so they keep contrast on a light panel. */
:root.themed {
  --muted: var(--pal-muted);
  --dim: color-mix(in srgb, var(--pal-muted) 70%, transparent);
  --panel-bg: color-mix(in srgb, var(--pal-panel) 32%, transparent);
  --tile-bg: color-mix(in srgb, var(--pal-panel) 20%, transparent);
  --panel-border: color-mix(in srgb, var(--pal-text) 12%, transparent);
  --glow: color-mix(in srgb, var(--pal-text) 35%, transparent);
  --c-up: color-mix(in srgb, #6ddc8b 70%, var(--pal-text));
  --c-down: color-mix(in srgb, #ff7b7b 70%, var(--pal-text));
  --c-overdue: color-mix(in srgb, #ff9a76 70%, var(--pal-text));
  --c-err: color-mix(in srgb, #ffb4b4 70%, var(--pal-text));
}

* { box-sizing: border-box; }

/* First paint waits for the display answer on the hosted board. */
html.hold body { opacity: 0; }
body { transition: opacity 0.3s ease; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #111;
  color: var(--fg);
  overflow: hidden;
}

.photo-bg {
  position: fixed;
  inset: 0;
  background-image: var(--photo-url, none);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  z-index: 0;
  transition: opacity 1s ease;
}

/* Fit: whole photo centered over a blurred, darkened copy of itself. */
.photo-bg.fit { background-image: none; overflow: hidden; }
.photo-bg.fit::before,
.photo-bg.fit::after {
  content: "";
  position: absolute;
  background-image: var(--photo-url, none);
  background-position: center;
  background-repeat: no-repeat;
}
.photo-bg.fit::before {
  inset: -6%;
  background-size: cover;
  filter: blur(28px) brightness(0.5);
}
.photo-bg.fit::after {
  inset: 0;
  background-size: contain;
}

.scrim {
  position: fixed;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(0,0,0,0.55) 0%, rgba(0,0,0,0.15) 35%, rgba(0,0,0,0.15) 65%, rgba(0,0,0,0.75) 100%),
    linear-gradient(90deg, rgba(0,0,0,0.35) 0%, rgba(0,0,0,0) 50%);
  z-index: 1;
  pointer-events: none;
}

/* The board is the size container: cqi and cqb below are percentages of its
   content box, inside the padding. */
.board {
  position: relative;
  z-index: 2;
  width: 100vw;
  /* dvh is the area left visible by the browser's toolbars, which 100vh includes on iPad Safari. */
  height: 100vh;
  height: 100dvh;
  container-type: size;
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  padding: 2.4vh 3.2vw;
  gap: 2.4vh;
}
/* Blocks are ordered by script (inline order); the clock row leads and the credit trails. */
.board > :not(.middle) { flex: 0 0 auto; }
.board > .top { order: 0; }
.board > .credit { order: 99; }
.part-off { display: none !important; }

/* --- Top: clock + weather --- */
.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 3.419cqi;
}

.clock {
  flex: 0 0 auto;
  min-width: 0;
}
.clock .time {
  position: relative;
  display: inline-block;
  font-family: var(--clock-font);
  font-size-adjust: var(--clock-adjust, none);
  font-size: clamp(28px, 5.128cqi, 70px);
  font-weight: 400;
  letter-spacing: 0.02em;
  line-height: 1;
  color: var(--fg);
  text-shadow: 0 0 11px var(--glow), 0 2px 19px rgba(0,0,0,0.6);
  white-space: nowrap;
}
.clock .time::before {
  content: "88:88:88";
  position: absolute;
  inset: 0;
  color: var(--fg);
  opacity: var(--clock-ghost);
  pointer-events: none;
  letter-spacing: inherit;
  text-shadow: none;
}
.clock .date {
  font-size: clamp(25.6px, 2.051cqi, 38.4px);
  color: var(--fg);
  margin-top: 0.4em;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.weather {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.282cqi;
  background: var(--panel-bg);
  -webkit-backdrop-filter: blur(6.4px);
  backdrop-filter: blur(6.4px);
  border: 1px solid var(--panel-border);
  border-radius: 12.8px;
  padding: 1.026cqi 1.368cqi;
  margin-left: 3.419cqi;
}
.board > .weather.standalone { margin-left: 0; }
.weather .wx-now {
  display: flex;
  align-items: center;
  gap: 0.684cqi;
}
.weather .wx-icon { font-size: clamp(27.2px, 3.692cqi, 53.6px); line-height: 1; }
.weather .wx-temp { font-size: clamp(27.2px, 3.692cqi, 53.6px); font-weight: 300; }
.weather .wx-high { font-size: clamp(11.2px, 1.026cqi, 15.2px); color: var(--muted); }
.weather .wx-label { font-size: clamp(11.2px, 1.026cqi, 15.2px); color: var(--muted); }
.weather .wx-astro {
  display: flex;
  flex-direction: column;
  gap: 0.4em;
  font-size: clamp(12.8px, 1.111cqi, 17.6px);
  color: var(--muted);
  padding-left: 1.282cqi;
  border-left: 1px solid var(--panel-border);
  white-space: nowrap;
}
.weather .wx-astro .astro-row {
  display: flex;
  align-items: center;
  gap: 0.55em;
}
.weather .wx-astro .astro-ic {
  width: 1.7em;
  height: 1.7em;
  flex: 0 0 auto;
  color: var(--fg);
}
.weather .wx-astro .astro-moon {
  font-size: 1.7em;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.7em;
  height: 1.7em;
}
.weather .wx-astro .astro-time { font-variant-numeric: tabular-nums; }
.weather .wx-forecast {
  display: flex;
  gap: 1.846cqi;
  padding-left: 1.282cqi;
  border-left: 1px solid var(--panel-border);
}
.weather .wx-day {
  display: flex; flex-direction: column; align-items: center; gap: 0.2em;
  font-size: clamp(15.2px, 1.333cqi, 20.8px);
}
.weather .wx-day .d { color: var(--muted); }
.weather .wx-day .ic { font-size: 1.6em; }
.weather .wx-day .hi { font-weight: 500; }
.weather .wx-day .lo { color: var(--muted); }
/* Emoji icons keep their own size rather than the text font's x-height. */
.weather .wx-icon,
.weather .wx-day .ic,
.weather .wx-astro .astro-moon { font-size-adjust: none; }

/* --- Middle: calendar (full width) --- */
.middle {
  display: grid;
  grid-template-columns: 1fr;
  flex: 1 1 0;
  min-height: 0;
}

.panel {
  background: var(--panel-bg);
  -webkit-backdrop-filter: blur(6.4px);
  backdrop-filter: blur(6.4px);
  border: 1px solid var(--panel-border);
  border-radius: 12.8px;
  padding: 1.368cqi 1.538cqi;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel h2 {
  margin: 0 0 1em 0;
  font-size: clamp(13.6px, 1.128cqi, 19.2px);
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}

/* Calendar */
.calendar {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.events {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.9em;
  flex: 1 1 auto;
  min-height: 0;
}
.panel.calendar h2,
.panel.tasks h2 { color: var(--fg); }
/* Each day is a container, so event text sizes follow the day's width: the full
   row in classic, the side column in photo-first, one column in week-grid. */
.events .day-group {
  container-type: inline-size;
  /* Lighter glass than the weather panel, so more of the photo shows through. */
  background: var(--tile-bg);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  border: 1px solid var(--panel-border);
  border-radius: 9.6px;
  padding: 0.8em 1em;
  display: flex;
  flex-direction: column;
  gap: 0.6em;
}
.events .day-header {
  font-size: calc(clamp(12px, 0.935rem + 0.24cqi, 19.2px) * var(--cal-scale, 1));
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--fg);
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--panel-border);
}
.events .event {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1em;
  align-items: baseline;
}
.events .event .when {
  font-size: calc(clamp(12px, 0.87rem + 0.48cqi, 22.4px) * var(--cal-scale, 1));
  color: var(--muted);
  white-space: nowrap;
}
.events .event .what {
  font-size: calc(clamp(14px, 1.15rem + 0.54cqi, 28px) * var(--cal-scale, 1));
  font-weight: 400;
}
.events .event .where {
  font-size: calc(clamp(11px, 0.8rem + 0.36cqi, 19.2px) * var(--cal-scale, 1));
  color: var(--dim);
  margin-top: 0.2em;
}

/* Tasks ticker */
.ticker {
  background: var(--panel-bg);
  -webkit-backdrop-filter: blur(6.4px);
  backdrop-filter: blur(6.4px);
  border: 1px solid var(--panel-border);
  border-radius: 9.6px;
  overflow: hidden;
  padding: 0.55em 0;
  font-size: clamp(14.4px, 1.368cqi, 22.4px);
  line-height: 1.4;
}
.ticker.hidden { display: none; }
.ticker-track {
  display: inline-flex;
  white-space: nowrap;
  animation: ticker-scroll linear infinite;
}
.ticker-half {
  display: inline-flex;
  align-items: baseline;
  padding-right: 0;
  flex: 0 0 auto;
}
.t-item { padding: 0 1.2em; }
.t-name {
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-right: 0.35em;
}
.t-logo {
  height: 1.2em;
  width: 1.2em;
  vertical-align: -0.25em;
  margin-right: 0.3em;
}
/* Light tile keeps dark logos visible on the dark ticker. */
.t-logo-tile {
  object-fit: contain;
  background: #fff;
  border-radius: 0.25em;
  padding: 0.1em;
  box-sizing: border-box;
}
.t-bold { font-weight: 700; margin-right: 0.35em; }
/* Chip hues are set by the board script from the palette accent; these are the
   default-palette values. Dark text on a light chip keeps contrast above 4.5:1. */
:root {
  --chip-h0: 44; --chip-h1: 89; --chip-h2: 134; --chip-h3: 179;
  --chip-h4: 224; --chip-h5: 269; --chip-h6: 314; --chip-h7: 359;
}
.t-chip {
  display: inline-block;
  padding: 0 0.7em;
  border-radius: 999px;
  color: #151515;
  font-weight: 600;
  line-height: 1.35;
  margin-right: 0.3em;
}
.t-chip-0 { background: hsl(var(--chip-h0), 65%, 80%); }
.t-chip-1 { background: hsl(var(--chip-h1), 65%, 80%); }
.t-chip-2 { background: hsl(var(--chip-h2), 65%, 80%); }
.t-chip-3 { background: hsl(var(--chip-h3), 65%, 80%); }
.t-chip-4 { background: hsl(var(--chip-h4), 65%, 80%); }
.t-chip-5 { background: hsl(var(--chip-h5), 65%, 80%); }
.t-chip-6 { background: hsl(var(--chip-h6), 65%, 80%); }
.t-chip-7 { background: hsl(var(--chip-h7), 65%, 80%); }
.t-chip-n { background: #dcdcdc; }
.t-more { color: var(--muted); font-size: 0.85em; margin-left: 0.6em; }
.t-due.t-overdue { color: var(--c-overdue); font-weight: 600; }
.t-urgent {
  display: inline-block;
  min-width: 1.1em;
  margin-right: 0.35em;
  border-radius: 50%;
  background: #ff6b6b;
  color: #151515;
  font-size: 0.75em;
  font-weight: 700;
  text-align: center;
  line-height: 1.3;
}
.t-recur { margin-left: 0.3em; color: var(--muted); font-size: 0.85em; }
.t-recur::before { content: "\21BB"; }
.t-task + .t-task { margin-left: 1.2em; }
/* Pages mode: one group at a time, tasks truncate instead of scrolling. */
.todo-page {
  display: flex;
  align-items: baseline;
  padding: 0 1.2em;
  gap: 0.6em;
}
.todo-page .t-tasks {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.t-count { flex: 0 0 auto; color: var(--muted); font-size: 0.75em; }
.t-due { color: var(--muted); font-size: 0.8em; margin-left: 0.4em; }
.t-price { margin-left: 0.4em; font-variant-numeric: tabular-nums; }
.t-chg { margin-left: 0.4em; font-size: 0.85em; font-variant-numeric: tabular-nums; }
.t-up { color: var(--c-up); }
.t-down { color: var(--c-down); }
.t-reminder { color: var(--accent); }
.t-birthday-celebration { color: #ff6b9d; font-weight: 600; font-size: 1.1em; }
.t-anniversary-celebration { color: #ff4d6d; font-weight: 600; font-size: 1.1em; }
.t-sep { color: var(--dim); }
/* Spacer placed between repeated cycles when a short list is looped, so the same
   entry isn't crammed edge-to-edge. Width is set inline, adaptive to viewport. */
.t-gap { display: inline-block; }
@keyframes ticker-scroll {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}
@media (prefers-reduced-motion: reduce) {
  .ticker-track { animation: none; }
}

.loading, .wx-loading { color: var(--muted); font-style: italic; }
.err { color: var(--c-err); font-size: 0.9em; }
.wx-setup { color: var(--muted, #9aa7b8); font-size: 0.9em; }

/* Footer credit */
.credit {
  font-size: clamp(8px, 0.684cqi, 10.4px);
  color: var(--dim);
  text-align: right;
}
.credit a {
  color: inherit;
  text-decoration: underline dotted var(--dim);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

/* --- Palettes: non-default palettes also tint headers, names and celebrations --- */
.themed .events .day-header,
.themed .t-name { color: var(--accent); }
.themed .t-birthday-celebration,
.themed .t-anniversary-celebration { color: var(--accent); }

/* --- Layouts (classic is the base rules above) --- */

/* calendar-first: slim top bar, large calendar, one ticker */
body.layout-calendar-first { --cal-scale: 1.2; }
body.layout-calendar-first .top { align-items: center; gap: 1.709cqi; }
body.layout-calendar-first .clock { display: flex; align-items: baseline; gap: 1.709cqi; }
body.layout-calendar-first .clock .time { font-size: clamp(19.2px, 3.419cqi, 48px); }
body.layout-calendar-first .clock .date { margin-top: 0; font-size: clamp(14.4px, 1.368cqi, 22.4px); }
body.layout-calendar-first .weather { padding: 0.427cqi 1.026cqi; margin-left: 0; }
body.layout-calendar-first .weather .wx-icon,
body.layout-calendar-first .weather .wx-temp { font-size: clamp(19.2px, 2.222cqi, 32px); }
body.layout-calendar-first .weather .wx-astro { display: none; }
body.layout-calendar-first .weather .wx-forecast { gap: 1.197cqi; padding-left: 1.026cqi; }
body.layout-calendar-first .weather .wx-day { font-size: clamp(11.2px, 0.94cqi, 14.4px); }

/* photo-first: clock and weather in the top-left corner, calendar as a side column, small ticker */
body.layout-photo-first .board {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 24vw;
  grid-template-rows: auto 1fr auto auto;
  column-gap: 2.4vw;
}
body.layout-photo-first.off-calendar .board { grid-template-columns: minmax(0, 1fr); }
body.layout-photo-first .top {
  grid-column: 1; grid-row: 1;
  flex-direction: column; align-items: flex-start; justify-self: start; gap: 1.68cqb;
}
body.layout-photo-first .weather { flex: 0 0 auto; margin-left: 0; gap: 1.026cqi; padding: 0.684cqi 1.026cqi; }
body.layout-photo-first .weather .wx-icon,
body.layout-photo-first .weather .wx-temp { font-size: clamp(20.8px, 2.564cqi, 36.8px); }
body.layout-photo-first .weather .wx-astro { display: none; }
body.layout-photo-first .weather .wx-forecast { gap: 1.026cqi; padding-left: 1.026cqi; }
body.layout-photo-first .weather .wx-day { font-size: clamp(11.2px, 0.94cqi, 14.4px); }
body.layout-photo-first .weather .wx-day:nth-child(n+4) { display: none; }
body.layout-photo-first .middle { grid-column: 2; grid-row: 1 / 3; }
body.layout-photo-first .ticker { grid-column: 1 / -1; grid-row: 3; font-size: clamp(11.2px, 1.026cqi, 16px); }
body.layout-photo-first .credit { grid-column: 1 / -1; grid-row: 4; }

/* week-grid: clock and weather on top, the next seven days as columns */
body.layout-week-grid .events {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: minmax(0, 1fr);
  gap: 0.684cqi;
}
body.layout-week-grid .events > .loading,
body.layout-week-grid .events > .err { grid-column: 1 / -1; }
body.layout-week-grid .events .day-col { min-height: 0; overflow: hidden; padding: 0.6em 0.7em; }
body.layout-week-grid .events .day-header { letter-spacing: 0.08em; }
body.layout-week-grid .events .day-col.today .day-header { color: var(--accent); }
body.layout-week-grid .events .event { grid-template-columns: minmax(0, 1fr); gap: 0.1em; }
body.layout-week-grid .events .event .what,
body.layout-week-grid .events .event .where { overflow-wrap: anywhere; }

/* --- Tablets held upright: the clock row is too narrow for the weather beside it --- */
@media (orientation: portrait) and (min-width: 768px) and (max-width: 1024px) {
  body:not(.layout-photo-first) .top { flex-wrap: wrap; }
  body:not(.layout-photo-first) .top > .weather { flex: 1 1 100%; margin-left: 0; }
}

/* --- Phones held upright: one scrolling column, whatever the chosen layout --- */
@media (orientation: portrait) and (max-width: 767px) {
  html, body { height: auto; overflow: visible; }

  /* The board grows with its content, so it can only be an inline-size container. */
  .board,
  body.demo .board,
  body.layout-photo-first .board {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 100dvh;
    container-type: inline-size;
    padding: 16px 16px 24px;
    gap: 16px;
  }
  body.demo .board { padding-bottom: 88px; }
  .board > * { grid-column: auto; grid-row: auto; }

  .top,
  body.layout-calendar-first .top,
  body.layout-photo-first .top {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .clock,
  body.layout-calendar-first .clock { display: block; }
  .clock .time,
  body.layout-calendar-first .clock .time { font-size: clamp(2rem, 13cqi, 3.5rem); }
  .clock .date,
  body.layout-calendar-first .clock .date {
    margin-top: 0.3em;
    font-size: clamp(1.1rem, 5.5cqi, 1.5rem);
    white-space: normal;
  }

  /* Weather drops below the clock: now and sun/moon side by side, forecast underneath. */
  .weather,
  body.layout-calendar-first .weather,
  body.layout-photo-first .weather {
    flex: none;
    flex-wrap: wrap;
    margin-left: 0;
    gap: 12px 16px;
    padding: 12px 14px;
  }
  .weather .wx-now { gap: 10px; }
  .weather .wx-icon,
  .weather .wx-temp,
  body.layout-calendar-first .weather .wx-icon,
  body.layout-calendar-first .weather .wx-temp,
  body.layout-photo-first .weather .wx-icon,
  body.layout-photo-first .weather .wx-temp { font-size: clamp(2rem, 10cqi, 2.75rem); }
  .weather .wx-high,
  .weather .wx-label { font-size: 0.85rem; }
  .weather .wx-astro,
  body.layout-calendar-first .weather .wx-astro,
  body.layout-photo-first .weather .wx-astro { display: flex; font-size: 0.85rem; padding-left: 12px; }
  .weather .wx-forecast,
  body.layout-calendar-first .weather .wx-forecast,
  body.layout-photo-first .weather .wx-forecast {
    flex: 1 1 100%;
    justify-content: space-between;
    gap: 4px;
    padding: 10px 0 0;
    border-left: 0;
    border-top: 1px solid var(--panel-border);
  }
  .weather .wx-day,
  body.layout-calendar-first .weather .wx-day,
  body.layout-photo-first .weather .wx-day { font-size: 0.9rem; }
  body.layout-photo-first .weather .wx-day:nth-child(n+4) { display: flex; }

  /* The calendar takes its natural height and the page scrolls. */
  .middle { flex: none; }
  .events { overflow: visible; }
  body.layout-week-grid .events {
    display: flex;
    flex-direction: column;
    gap: 0.9em;
  }
  body.layout-week-grid .events .day-col { overflow: visible; }
  body.layout-week-grid .events .event { grid-template-columns: auto 1fr; gap: 1em; }

  .ticker,
  body.layout-photo-first .ticker { font-size: 1rem; }
  .credit { font-size: 0.7rem; }
}
