:root {
  --bg: #1b1a17;
  --paper: #23221e;
  --ink: #d8cfb8;
  --ink-dim: #948a74;
  --accent: #b8905a;
  --line: #3a382f;
  --mono: ui-monospace, "Cascadia Mono", "Consolas", "Liberation Mono", "SFMono-Regular", Menlo, monospace;
}

* { box-sizing: border-box; }

/*
 * Font size option: `html`'s font-size is the one source of truth. Every
 * other font-size in this file is in `rem`, i.e. relative to it, so the
 * 3-way toggle in the footer (app.js sets `document.documentElement.style.
 * fontSize`) scales the whole page at once. 15px is the default ("md").
 */
html {
  font-size: 15px;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
}

body {
  font-size: 1rem;
}

.crt {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

/*
 * .layout places the 4 top-level sections (links / weather / football /
 * news) using named grid-area strings -- each string below is literally a
 * sketch of the page: edit it to reorder or reshuffle sections, the actual
 * CSS properties on .links/.weather/.football/.news never need to change.
 *
 * Mobile (default): one column, top-to-bottom as drawn below.
 * Wide screens (see media query further down): weather/football move to
 * side rails flanking a centered links+news column.
 */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto auto auto auto auto 1fr;
  grid-template-areas:
    "links"
    "chaos"
    "weather"
    "radio"
    "football"
    "news";
}

.links    { grid-area: links; }
.chaos    { grid-area: chaos; }
.weather  { grid-area: weather; }
.radio    { grid-area: radio; }
.football { grid-area: football; }
.news     { grid-area: news; min-width: 0; }

/* mobile: inert, just makes weather+radio act like two plain, separately
   ordered grid items (see the media query below for its wide-screen job) */
.weather-rail {
  display: contents;
}

/* on wide screens, give weather+radio and football their own side rails
   instead of stacking everything in one narrow column -- avoids big
   empty margins */
@media (min-width: 1000px) {
  .crt {
    max-width: 1160px;
    border-left: none;
    border-right: none;
  }

  .layout {
    grid-template-columns: 220px minmax(0, 760px) 220px;
    grid-template-rows: auto auto 1fr;
    column-gap: 24px;
    justify-content: center;
    grid-template-areas:
      "weather links   football"
      "weather chaos   football"
      "weather news    football";
  }

  /* now a real flex column occupying the whole "weather" area (all 3 rows,
     matching football's span on the other side) -- weather+radio stack
     inside it independently, instead of each being tied to a single outer
     grid row (which is what caused the row-height/stretch bugs). */
  .weather-rail {
    display: flex;
    flex-direction: column;
    gap: 12px;
    grid-area: weather;
    align-self: start;
  }

  /* .weather and .radio are flex children of .weather-rail now, not grid
     children of .layout -- they should keep the flex default (stretch to
     the rail's full width), so align-self:start is deliberately only on
     .football below (still a direct grid item spanning all 3 rows). */
  .weather,
  .radio,
  .football {
    border: 1px solid var(--line);
  }

  .football {
    align-self: start;
  }

  .links,
  .chaos,
  .news {
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
}

.bar {
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  letter-spacing: 0.02em;
}

.foot {
  border-bottom: none;
  border-top: 1px solid var(--line);
  margin-top: auto;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* header text (title + joke line) stays centered regardless of how wide
   the surrounding .crt container gets on large screens */
header.bar {
  text-align: center;
}

.prompt-row { display: flex; align-items: baseline; justify-content: center; }

.prompt { color: var(--accent); }

.otd {
  margin-top: 6px;
  font-size: 0.767rem;
  color: var(--ink-dim);
  line-height: 1.4;
  /* no truncation: a long joke just wraps and takes more vertical space */
}

.blink {
  animation: blink 1.1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.muted { color: var(--ink-dim); }

.links {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}

.tile {
  background: var(--paper);
  color: var(--ink);
  border: none;
  padding: 18px 16px;
  text-align: left;
  font-family: var(--mono);
  font-size: 0.933rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-decoration: none;
}

.tile:hover {
  background: #2a2924;
}

.tile:active {
  background: #1f1e1a;
}

.tile-label {
  color: var(--accent);
  text-transform: lowercase;
  font-weight: 600;
}

.tile-sub {
  color: var(--ink-dim);
  font-size: 0.8rem;
}

/* --- chaos index: a little ascii meter under the link tiles --- */

.chaos {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chaos-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  color: var(--accent);
  font-size: 0.867rem;
  text-transform: lowercase;
}

.chaos-value {
  color: var(--ink);
}

.chaos-bar {
  font-size: 0.867rem;
  letter-spacing: -1px;
  color: var(--accent);
  overflow-wrap: anywhere;
}

.chaos-bar .chaos-bar-empty {
  color: var(--line);
}

.chaos-desc {
  font-size: 0.767rem;
  color: var(--ink-dim);
}

.chaos-desc summary {
  color: var(--accent);
  cursor: pointer;
  text-transform: lowercase;
}

.chaos-desc summary::marker {
  color: var(--accent);
}

.chaos-desc p {
  margin: 6px 0 0 0;
  line-height: 1.5;
}

.weather {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}

.wx-tile {
  background: var(--paper);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.wx-city {
  color: var(--accent);
  font-size: 0.867rem;
  text-transform: lowercase;
}

.wx-temp {
  font-size: 1.333rem;
  color: var(--ink);
}

.wx-icon {
  font-size: 1rem;
}

.wx-forecast {
  margin-top: 8px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.wx-day {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.733rem;
  color: var(--ink-dim);
}

.wx-day-name {
  text-transform: lowercase;
  color: var(--ink);
  width: 3em;
  flex-shrink: 0;
}

.wx-day-temp {
  color: var(--ink);
}

.wx-day-icon {
  font-size: 0.867rem;
}

.radio {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.radio-head {
  display: flex;
  flex-direction: column;
}

.radio-label {
  color: var(--accent);
  font-size: 0.867rem;
  text-transform: lowercase;
}

.radio-sub {
  color: var(--ink-dim);
  font-size: 0.733rem;
}

.radio-player {
  width: 100%;
  height: 32px;
}

.radio-volume-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.radio-volume-icon {
  color: var(--ink-dim);
  font-size: 0.733rem;
  text-transform: lowercase;
}

.radio-volume {
  flex: 1;
  accent-color: var(--accent);
}

.radio-viz {
  display: none;
  width: 100%;
  height: 40px;
  background: var(--bg);
  border: 1px solid var(--line);
}

.radio-viz.active {
  display: block;
}

.football {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--line);
}

.fb-row {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  border-top: 1px solid var(--line);
}

.fb-row:first-child {
  border-top: none;
}

.fb-team {
  color: var(--accent);
  font-size: 0.867rem;
  text-transform: lowercase;
}

.fb-score {
  font-size: 0.867rem;
  color: var(--ink);
}

.fb-live {
  color: #c9654b;
  font-weight: 600;
}

.fb-next {
  font-size: 0.767rem;
  color: var(--ink-dim);
}

.fb-team {
  background: none;
  border: none;
  padding: 0;
  font-family: var(--mono);
  cursor: pointer;
  text-align: left;
}

.fb-team:hover {
  color: var(--ink);
}

.standings-panel {
  display: none;
  margin-top: 8px;
}

.standings-panel.open {
  display: block;
}

.standings-tabs {
  display: flex;
  gap: 1px;
  background: var(--line);
  margin-bottom: 1px;
}

.standings-tab {
  background: var(--bg);
  color: var(--ink-dim);
  border: none;
  font-family: var(--mono);
  font-size: 0.733rem;
  padding: 5px 10px;
  cursor: pointer;
  text-transform: lowercase;
}

.standings-tab.active {
  color: var(--accent);
  background: var(--paper);
}

.standings-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.733rem;
}

.standings-table th,
.standings-table td {
  text-align: left;
  padding: 4px 6px;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.standings-table th:first-child,
.standings-table td:first-child {
  width: 2.4em;
}

.standings-table th:last-child,
.standings-table td:last-child {
  width: 3.2em;
  text-align: right;
}

.standings-table th {
  color: var(--ink-dim);
  font-weight: normal;
  text-transform: lowercase;
}

.standings-highlight td {
  color: var(--accent);
  font-weight: 600;
}

.news {
  flex: 1;
  padding: 0;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.tab {
  background: none;
  border: none;
  color: var(--ink-dim);
  font-family: var(--mono);
  font-size: 0.867rem;
  padding: 10px 16px;
  cursor: pointer;
  border-right: 1px solid var(--line);
  white-space: nowrap;
}

.tab.active {
  color: var(--accent);
  background: var(--paper);
}

.feed {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.story {
  border: 1px solid var(--line);
  background: var(--paper);
  padding: 14px 16px;
}

.story-title {
  color: var(--ink);
  font-size: 0.967rem;
  font-weight: 600;
  margin: 0 0 6px 0;
}

.story-meta {
  color: var(--ink-dim);
  font-size: 0.767rem;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.story-summary {
  font-size: 0.867rem;
  line-height: 1.5;
  margin: 0 0 10px 0;
  color: var(--ink);
}

.story-link {
  font-size: 0.8rem;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
}

.story-link:hover { opacity: 0.8; }

.citation {
  color: var(--ink-dim);
  text-decoration: none;
  font-size: 0.733rem;
  border-bottom: 1px dotted var(--ink-dim);
}

.citation:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.show-more {
  justify-self: start;
  border: 1px solid var(--line);
  padding: 8px 14px;
  align-self: flex-start;
}

.show-more:hover {
  color: var(--accent);
}

.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: var(--bg);
  padding: 8px 14px;
  font-size: 0.8rem;
  font-family: var(--mono);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.toast.show {
  opacity: 1;
}

/* --- font size control (footer) --- */

/* --- boot screen (fake POST sequence on first load) --- */

.boot-screen {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  padding: 24px;
  display: flex;
  cursor: pointer;
  transition: opacity 0.3s ease;
}

.boot-screen.boot-done {
  opacity: 0;
  pointer-events: none;
}

.boot-lines {
  margin: 0;
  font-size: 0.867rem;
  line-height: 1.6;
  white-space: pre-wrap;
}

.boot-ok {
  color: var(--accent);
}

/* --- scanline overlay (toggle in footer) --- */

.scanline-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  pointer-events: none;
  display: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.2) 0px,
    rgba(0, 0, 0, 0.2) 1px,
    transparent 1px,
    transparent 3px
  );
}

body.scanlines-on .scanline-overlay {
  display: block;
}

.footer-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.scanline-toggle {
  background: var(--paper);
  color: var(--ink-dim);
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.8rem;
  padding: 4px 8px;
  cursor: pointer;
  text-transform: lowercase;
}

.scanline-toggle.active {
  color: var(--accent);
  border-color: var(--accent);
}

.fontsize {
  display: flex;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
}

.fontsize button {
  background: var(--paper);
  color: var(--ink-dim);
  border: none;
  font-family: var(--mono);
  font-size: 0.8rem;
  padding: 4px 8px;
  cursor: pointer;
}

.fontsize button.active {
  color: var(--accent);
}

.fontsize button:hover {
  color: var(--ink);
}
