:root {
  color-scheme: light;
  --bg: #e9e6de;
  --ink: #15201d;
  --muted: #56625e;
  --glass: rgba(255, 255, 255, 0.74);
  --glass-line: rgba(21, 32, 29, 0.12);
  --warm: #f3a755;
  --cool: #6ebeb5;
  --moon: #fff5ce;
  --moon-dark: #24312f;
  --shadow: 0 28px 80px rgba(32, 41, 37, 0.1);
  /* Room-distance type scale for the first-class 1280 × 720 TV target. */
  --type-meta: 0.875rem;
  --type-secondary: 1rem;
  --type-body: 1.125rem;
  --type-headline: 1.25rem;
  --type-lead: 1.75rem;
  font-family: "Manrope", sans-serif;
  font-synthesis: none;
}

:root[data-theme="night"] {
  color-scheme: dark;
  --bg: #0d1417;
  --ink: #f0eee7;
  --muted: #b3bcba;
  --glass: rgba(25, 36, 40, 0.9);
  --glass-line: rgba(235, 242, 239, 0.12);
  --warm: #ffb86b;
  --cool: #74cbc3;
  --moon: #fff2bd;
  --moon-dark: #10191c;
  --shadow: 0 30px 90px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); transition: background-color 1.4s ease; }
@view-transition { navigation: auto; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  overflow-x: hidden;
  transition: color 1.1s ease, background-color 1.4s ease;
}

.atmosphere {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 83% 14%, color-mix(in srgb, var(--cool) 34%, transparent), transparent 31rem),
    radial-gradient(circle at 8% 92%, color-mix(in srgb, var(--warm) 26%, transparent), transparent 34rem);
  transition: background 1.4s ease;
}

.atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.12;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.18'/%3E%3C/svg%3E");
}

:root[data-theme="night"] .atmosphere::after { mix-blend-mode: screen; opacity: 0.06; }

.display {
  position: relative;
  width: min(1500px, calc(100% - 72px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 0;
}

.topline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font: 600 var(--type-meta)/1 "DM Mono", monospace;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.topline p { margin: 0; }
.place { display: flex; align-items: center; gap: 10px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warm); box-shadow: 0 0 0 5px color-mix(in srgb, var(--warm) 16%, transparent); }
body.online .status-dot { background: var(--cool); box-shadow: 0 0 0 5px color-mix(in srgb, var(--cool) 16%, transparent); }

.clock-block { display: flex; align-items: center; padding: clamp(20px, 2.5vh, 28px) 0 clamp(16px, 2vh, 22px); }
.clock-row { display: flex; align-items: flex-start; gap: 22px; }
.clock-row h1 {
  margin: 0;
  font-size: clamp(5.5rem, 9.5vw, 9rem);
  font-weight: 500;
  line-height: 0.82;
  letter-spacing: -0.09em;
  font-variant-numeric: tabular-nums;
}
.clock-detail { display: flex; flex-direction: column; gap: 10px; margin-top: 0.85em; color: var(--warm); font: 600 clamp(1rem, 1.5vw, 1.25rem)/1 "DM Mono", monospace; }
#seconds, #clock-period { font-variant-numeric: tabular-nums; }
#clock-period { color: var(--ink); letter-spacing: 0.06em; }

.widgets { display: grid; grid-template-columns: 1.08fr 0.92fr; gap: 16px; }
.glass {
  min-height: 112px;
  border: 1px solid var(--glass-line);
  border-radius: 22px;
  background: var(--glass);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: background-color 1.1s ease, border-color 1.1s ease, box-shadow 1.1s ease;
}

.weather-card { position: relative; padding: clamp(16px, 1.6vw, 22px); display: grid; grid-template-columns: minmax(150px, 0.72fr) minmax(180px, 1fr); align-items: center; gap: clamp(20px, 2.4vw, 36px); }
.card-status { color: var(--warm); font: 600 var(--type-meta)/1 "DM Mono", monospace; letter-spacing: 0.04em; text-transform: uppercase; }
.weather-card > .card-status { position: absolute; top: 12px; right: 14px; }
.weather-reading, .carry { display: flex; align-items: center; gap: clamp(12px, 1.4vw, 20px); min-width: 0; }
.weather-icon { width: clamp(58px, 5vw, 72px); overflow: visible; color: var(--ink); }
.weather-icon .sun-fill { fill: var(--warm); }
.weather-icon .cloud-fill { fill: color-mix(in srgb, var(--ink) 14%, var(--glass)); stroke: var(--ink); stroke-width: 5; }
.weather-icon .weather-stroke { fill: none; stroke: var(--ink); stroke-width: 6; stroke-linecap: round; }
.weather-icon .rain-stroke { fill: none; stroke: var(--cool); stroke-width: 7; stroke-linecap: round; }
.feels, .carry > div:last-child, .sun-time div { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.feels span, .carry span, .sun-time span, .widget-label { color: var(--muted); font: 600 var(--type-meta)/1 "DM Mono", monospace; letter-spacing: 0.06em; text-transform: uppercase; }
.feels strong, .carry strong, .sun-time strong { overflow-wrap: anywhere; font: 600 var(--type-headline)/1.2 "DM Mono", monospace; }
.feels strong { color: var(--warm); font-size: clamp(2rem, 2.8vw, 2.6rem); line-height: 1; }
.carry small { color: var(--muted); font-size: var(--type-secondary); font-weight: 500; }
.carry strong { color: var(--cool); }
.carry.warning strong { color: var(--warm); }
.metric-icon, .solar-icon { width: 30px; flex: 0 0 auto; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.dressing-icons { display: flex; align-items: center; gap: 5px; }
.dressing-icons .metric-icon { width: 27px; }
.carry.warning .dressing-icons .metric-icon { stroke: var(--warm); }

.sky-card { padding: clamp(16px, 1.6vw, 22px); display: grid; grid-template-columns: auto 1fr; align-items: center; gap: clamp(24px, 3vw, 42px); }
.moon-wrap { display: flex; align-items: center; gap: 20px; }
.moon { width: clamp(64px, 5vw, 76px); filter: drop-shadow(0 0 24px color-mix(in srgb, var(--moon) 22%, transparent)); }
.moon-dark { fill: var(--moon-dark); }
#moon-lit { fill: var(--moon); }
.moon-rim { fill: none; stroke: color-mix(in srgb, var(--moon) 38%, transparent); stroke-width: 1.5; }
.widget-label { margin: 0; }
.moon-wrap h2 { margin: 8px 0 0; font-size: var(--type-headline); font-weight: 600; }

.sun-times { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 16px; }
.sun-time { display: flex; align-items: center; gap: 10px; }
.solar-icon { width: 27px; stroke: var(--warm); }
.sun-track { height: 1px; background: var(--glass-line); position: relative; }
.sun-track::before { content: ""; position: absolute; inset: -12px 0; border-top: 1px dashed var(--glass-line); border-radius: 50%; }
.sun-track span { position: absolute; top: -4px; left: var(--sun-progress, 50%); width: 9px; height: 9px; border-radius: 50%; background: var(--warm); box-shadow: 0 0 14px color-mix(in srgb, var(--warm) 70%, transparent); transform: translateX(-50%); transition: left 1s ease; }
.sunset-time { text-align: right; flex-direction: row-reverse; }

.lower-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 0.42fr); gap: 16px; margin-top: 16px; }
.news-card { min-height: 0; padding: clamp(18px, 1.8vw, 24px); }
.news-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.news-header h2 { margin: 0; font-size: var(--type-secondary); font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; }
.news-context { display: flex; align-items: center; gap: 10px; color: var(--muted); font: 600 var(--type-meta)/1 "DM Mono", monospace; letter-spacing: 0.05em; text-transform: uppercase; }
#news-category { color: var(--warm); }
#news-position { font-variant-numeric: tabular-nums; }
.news-context .card-status { padding-left: 10px; border-left: 1px solid var(--glass-line); }
.news-grid { min-height: 78px; opacity: 1; transition: opacity 220ms ease; }
.news-grid.changing { opacity: 0; }
.news-story { display: grid; align-content: center; min-height: 78px; }
.lead-story { padding: 0; }
.news-story h3 { margin: 0; font-weight: 600; letter-spacing: -0.02em; }
.news-story h3 { max-width: 580px; font-size: var(--type-lead); line-height: 1.16; }
.news-story a { color: inherit; text-decoration: none; }
.news-loading { margin: 0; color: var(--muted); }

.cricket-card {
  min-height: 0;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 7px;
}
.cricket-header { display: flex; align-items: center; gap: 8px; color: var(--muted); font: 600 var(--type-meta)/1 "DM Mono", monospace; letter-spacing: 0.06em; text-transform: uppercase; }
.cricket-header .card-status { margin-left: auto; }
.cricket-icon { width: 25px; flex: 0 0 auto; fill: none; stroke: var(--warm); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.cricket-card h2 { margin: 0; font-size: var(--type-headline); font-weight: 700; }
.cricket-scoreline { color: var(--ink); font: 600 var(--type-headline)/1.2 "DM Mono", monospace; }
.cricket-card p { margin: 0; color: var(--muted); font-size: var(--type-secondary); font-weight: 600; line-height: 1.2; }
.cricket-card.live .cricket-header, .cricket-card.live .cricket-scoreline { color: var(--cool); }

.bottom-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.scratch-card { min-height: 260px; padding: 18px 22px; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.scratch-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.scratch-header > div { display: flex; align-items: center; gap: 10px; }
.scratch-header svg { width: 25px; fill: none; stroke: var(--warm); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.scratch-header h2 { margin: 0; font-size: var(--type-secondary); font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; }
.scratch-header span { color: var(--muted); font: 600 var(--type-meta)/1 "DM Mono", monospace; letter-spacing: 0.05em; text-transform: uppercase; }
.scratch-content { min-height: 0; margin-top: 12px; display: grid; place-items: center; overflow: hidden; }
.scratch-content p { width: 100%; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: clamp(1.5rem, 2.6vw, 2.25rem); font-weight: 600; line-height: 1.22; }
.scratch-content.empty p { color: var(--muted); font-size: var(--type-body); text-align: center; }
.scratch-content img { display: block; width: 100%; height: 100%; min-width: 0; min-height: 0; max-width: 100%; max-height: 100%; object-fit: contain; }
:root[data-theme="night"] .scratch-content.drawing img { filter: invert(1) hue-rotate(180deg); }
body.scratch-fullscreen { overflow: hidden; }
body.scratch-fullscreen .scratch-card {
  position: fixed;
  inset: 0;
  z-index: 20;
  min-height: 0;
  padding: 0;
  border-radius: 0;
  background: var(--bg);
  box-shadow: 0 30px 100px rgba(20, 30, 27, 0.22);
  grid-template-rows: minmax(0, 1fr);
}
body.scratch-fullscreen .scratch-header { display: none; }
body.scratch-fullscreen .scratch-content { margin-top: 0; }
body.scratch-fullscreen .scratch-content p { max-width: 1100px; font-size: clamp(3rem, 7vw, 6rem); text-align: center; }

.reveal { opacity: 0; transform: translateY(10px); animation: reveal 0.8s cubic-bezier(.2,.8,.2,1) forwards; }
.clock-block { animation-delay: 80ms; }
.widgets article:first-child { animation-delay: 160ms; }
.widgets article:last-child { animation-delay: 240ms; }
.news-card { animation-delay: 300ms; }
.cricket-card { animation-delay: 360ms; }
.scratch-card { animation-delay: 420ms; }

::view-transition-old(root), ::view-transition-new(root) { animation-duration: 500ms; animation-timing-function: cubic-bezier(.2,.8,.2,1); }
@keyframes reveal { to { opacity: 1; transform: translateY(0); } }

/* First-class target: a 32-inch 1280 × 720 display. */
@media (min-width: 900px) and (max-height: 800px) {
  .display {
    width: min(1168px, calc(100% - 112px));
    height: 100vh;
    min-height: 0;
    padding: 32px 0;
    display: grid;
    grid-template-columns: 276px minmax(0, 1fr);
    grid-template-rows: auto 142px auto minmax(0, 1fr);
    column-gap: 16px;
    row-gap: 12px;
    align-content: start;
  }
  .topline, .lower-row, .bottom-row { grid-column: 1 / -1; }
  .clock-block { min-height: 142px; padding: 0; align-self: stretch; }
  .clock-row h1 { font-size: 6.6rem; }
  .clock-detail { font-size: 1rem; }
  .widgets { grid-template-columns: 1.06fr 0.94fr; gap: 12px; min-width: 0; }
  .glass { min-height: 94px; border-radius: 16px; box-shadow: 0 18px 48px rgba(32, 41, 37, 0.08); }
  .weather-card, .sky-card { min-width: 0; min-height: 142px; padding: 12px 14px; gap: 12px; }
  .weather-card { grid-template-columns: 130px minmax(0, 1fr); }
  .weather-reading, .carry { gap: 10px; }
  .weather-icon { width: 44px; }
  .feels, .carry > div:last-child, .sun-time div { gap: 5px; }
  .dressing-icons .metric-icon { width: 24px; }
  .moon { width: 52px; }
  .moon-wrap { gap: 10px; }
  .moon-wrap h2 { margin-top: 5px; }
  .sun-times { grid-template-columns: 1fr; align-content: center; gap: 10px; }
  .sun-time { gap: 6px; }
  .sun-time strong { white-space: nowrap; overflow-wrap: normal; }
  .solar-icon { width: 22px; }
  .sun-track { display: none; }
  .sunset-time { justify-self: start; text-align: left; flex-direction: row; }
  .lower-row { grid-template-columns: minmax(0, 1fr) 330px; gap: 12px; margin-top: 0; }
  .news-card { padding: 14px 18px; }
  .news-header { margin-bottom: 8px; }
  .news-grid, .news-story { min-height: 78px; }
  .news-story h3 { font-size: var(--type-lead); }
  .news-story h3 { max-width: none; }
  .cricket-card { padding: 12px 16px; }
  .bottom-row { min-height: 0; gap: 12px; margin-top: 0; overflow: hidden; }
  .scratch-card { height: 100%; min-height: 0; padding: 14px 18px; }
  .scratch-content { margin-top: 10px; }
  body.scratch-fullscreen .scratch-card { inset: 0; padding: 0; }
  .reveal { opacity: 1; transform: none; animation: none; }
}

@media (max-width: 1000px) {
  .display { width: min(100% - 36px, 760px); padding-top: 26px; }
  .widgets { grid-template-columns: 1fr; }
  .lower-row { grid-template-columns: 1fr; }
  .bottom-row { grid-template-columns: 1fr; }
  .clock-block { padding: 30px 0 24px; }
}

@media (max-width: 620px) {
  .clock-row h1 { font-size: 25vw; }
  .weather-card, .sky-card { grid-template-columns: 1fr; }
  .sun-times { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sun-track { display: none; }
  .sunset-time { justify-self: end; }
}

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