/* ── DESIGN TOKENS — LIGHT (e-ink paper) / DARK (inverse) ──── */
:root {
  color-scheme: light dark;

  /* Background scale */
  --black:  light-dark(#f0efe8, #0d0d0a);
  --deep:   light-dark(#e8e7e0, #171714);
  --panel:  light-dark(#e4e3dc, #1b1b18);
  --glass:  light-dark(#ece9e2, #131310);
  --g0:     light-dark(#cecdc6, #2e2e2a);

  /* Ink scale */
  --g1:  light-dark(#0d0d0a, #f0efe8);   /* primary / strongest */
  --g2:  light-dark(#1a1a16, #d8d7d0);   /* secondary */
  --g3:  light-dark(#3a3a34, #b8b7b0);   /* muted text */
  --g4:  light-dark(#606058, #888880);   /* very muted / labels */
  --g5:  light-dark(#aeada6, #3a3a34);   /* borders / dividers */

  /* Accents — neutralised for e-ink */
  --amber: light-dark(#3a3a34, #c8c7c0);
  --red:   light-dark(#0d0d0a, #f0efe8);
  --dim:   light-dark(rgba(0, 0, 0, 0.06), rgba(255, 255, 255, 0.06));

  /* CRT overlays — invisible on paper, faint in dark */
  --overlay-scanline: light-dark(rgba(0, 0, 0, 0), rgba(255, 255, 255, 0.03));
  --overlay-vignette: light-dark(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.4));

  /* Bloom colours — transparent in light (paper emits no light),
     so every glow below self-erases in the light scheme */
  --bloom-30:    light-dark(rgba(240, 239, 232, 0), rgba(240, 239, 232, 0.3));
  --bloom-50:    light-dark(rgba(240, 239, 232, 0), rgba(240, 239, 232, 0.5));
  --bloom-glyph: light-dark(rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.2));

  /* Glow helpers */
  --glow-sm: 0 0 4px var(--bloom-30);
  --glow-md: 0 0 8px var(--bloom-30), 0 0 2px var(--bloom-50);
  --glow-lg: 0 0 16px var(--bloom-30), 0 0 4px var(--bloom-50);

  /* Amber glow helpers */
  --glow-amber-sm: 0 0 4px var(--bloom-30);
  --glow-amber-md: 0 0 8px var(--bloom-30);
  --glow-amber-lg: 0 0 16px var(--bloom-30);
}

/* Mode toggle — forces a scheme for this visit, overriding the
   OS preference. No radio checked = follow the OS. */
:root:has(#mode-light:checked) { color-scheme: light; }
:root:has(#mode-dark:checked)  { color-scheme: dark; }

/* ── RESET ─────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── BASE ──────────────────────────────────────────────────── */
html, body {
  width: 100%;
  min-height: 100%;
  background: var(--black);
  color: var(--g1);
  font-family: 'Share Tech Mono', monospace;
  /* No vertical scrolling at the intended text size — the cockpit
     fits 100dvh exactly. If a reader's browser enlarges the small
     type (Safari's minimum-font-size setting, text-only zoom), the
     panel grows and scrolls instead of cropping its own content. */
  overflow-x: hidden;
  overflow-y: auto;
  cursor: crosshair;
  /* The small instrument type is intentional — stop iOS Safari
     from auto-inflating it and breaking the fixed-width columns */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* ── CRT EFFECTS ───────────────────────────────────────────── */

/* Scanlines */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: 999; pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    transparent,
    transparent 2px,
    var(--overlay-scanline) 2px,
    var(--overlay-scanline) 4px
  );
}

/* Phosphor vignette */
body::after {
  content: '';
  position: fixed; inset: 0; z-index: 998; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 50%, var(--overlay-vignette) 100%);
}

/* Noise texture overlay — dark scheme only (base = light = hidden) */
.noise {
  display: none;
  position: fixed; inset: 0; z-index: 997; pointer-events: none; opacity: 0.02;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 128px 128px;
}

/* ── SCHEME ADJUSTMENTS (non-colour properties) ────────────── */
@media (prefers-color-scheme: dark) {
  :root:not(:has(#mode-light:checked)) .noise          { display: block; }
  :root:not(:has(#mode-light:checked)) .widget::before { opacity: 1; }
}
:root:has(#mode-dark:checked) .noise          { display: block; }
:root:has(#mode-dark:checked) .widget::before { opacity: 1; }

/* ── LAYOUT GRID ───────────────────────────────────────────── */
.cockpit {
  position: relative; z-index: 1;
  width: 100%; min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: 220px 1fr 220px;
  padding: 24px;
}

/* ── TOP BAR ───────────────────────────────────────────────── */
.top-bar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 0;
  border-bottom: 1px solid var(--g4);
  padding-bottom: 16px;
  margin-bottom: 20px;
}

.top-bar .unit {
  font-size: clamp(9px, 1.5vw, 10px);
  color: var(--g3);
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.top-bar .unit span { color: var(--g2); }

.status-row {
  display: flex;
  gap: 24px;
  align-items: center;
}

.status-dot {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: clamp(8px, 1.4vw, 9px);
  font-weight: 300;
  letter-spacing: 0.12em;
  color: #c8102e;   /* fixed red in BOTH themes */
}

.status-dot::before {
  content: '';
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--g2);
  box-shadow: var(--glow-sm);
  animation: pulse 2.4s ease-in-out infinite;
}

.status-dot.amber::before {
  background: var(--amber);
  box-shadow: var(--glow-amber-sm);
  animation-delay: 0.8s;
}

/* ── MODE TOGGLE — CSS-only radio group ────────────────────── */
.mode-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--g4);
}

.mode-radio {
  position: absolute;
  width: 1px; height: 1px;
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

.mode-btn {
  background: transparent;
  border-right: 1px solid var(--g4);
  color: var(--g3);
  font-family: 'Share Tech Mono', monospace;
  font-size: 8px;
  letter-spacing: 0.15em;
  padding: 3px 8px;
  cursor: pointer;
  text-transform: uppercase;
  transition: background 0.15s, color 0.15s;
  user-select: none;
}

.mode-btn:last-of-type {
  border-right: none;
}

.mode-radio:checked + .mode-btn {
  background: var(--g4);
  color: var(--black);
}

.mode-radio:not(:checked) + .mode-btn:hover {
  color: var(--g1);
}

.mode-radio:focus-visible + .mode-btn {
  outline: 1px dashed var(--g2);
  outline-offset: 1px;
}

/* ── PANELS ────────────────────────────────────────────────── */
.panel-left {
  grid-column: 1;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-right: 20px;
  border-right: 1px solid var(--g5);
}

.center {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Top-align the hero so it stays INSIDE this row and can never ride up
     over the top bar (a negative transform used to let it escape upward).
     Raise/lower the whole hero block with the top padding below. */
  justify-content: flex-start;
  padding: 12vh 40px 0;
  position: relative;
}

/* Holds name + rule + tagline + nav. Positioned via .center's padding
   (not a transform), so the grid background and corner brackets stay put
   while only this text block moves — and it can't overlap the header. */
.hero-content {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.panel-right {
  grid-column: 3;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-left: 20px;
  border-left: 1px solid var(--g5);
}

/* ── BOTTOM BAR ────────────────────────────────────────────── */
.bottom-bar {
  grid-column: 1 / -1;
  border-top: 1px solid var(--g4);
  padding-top: 16px;
  margin-top: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ── WIDGET CARD ───────────────────────────────────────────── */
.widget {
  background: var(--panel);
  border: 1px solid var(--g4);
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
}

.widget::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--g3), transparent);
  opacity: 0.3;   /* light scheme; dark restores full strength */
}

.widget-label {
  font-size: 8px;
  letter-spacing: 0.2em;
  color: var(--g4);
  text-transform: uppercase;
  margin-bottom: 8px;
}

.widget-value {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(16px, 3.5vw, 22px); font-weight: 700;
  color: var(--g1);
  text-shadow: var(--glow-md);
  line-height: 1;
}

.widget-value.small  { font-size: 14px; }
.widget-value.amber  { color: var(--amber); text-shadow: var(--glow-amber-md); }

.widget-sub {
  font-size: 9px;
  color: var(--g3);
  margin-top: 4px;
  letter-spacing: 0.1em;
}

/* ── GITHUB WIDGET (icon link + centered logo) ─────────────────
   NOTE: uses its own `gh-link*` class names — the `.nav-link` pill
   button further down reuses that name, so sharing it would leak a
   border, padding and background onto this widget. */
.gh-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--g2);
}

/* Small header row: GitHub icon + username, part of the link */
.gh-link-head {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;   /* label sits left; image stays centered */
}

.gh-link-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.gh-link-text {
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--g3);
}

.gh-link:hover .gh-link-text,
.gh-link:hover .gh-link-icon { color: var(--g1); }

/* Duck-rabbit logo: main, centered image.
   The PNG is a transparent line-art *mask*; the element's background paints
   through the lines, so it recolours with the theme (--g1 = primary ink) and
   blends on any background — no baked-in panel colour, no blend-mode hacks. */
.widget-media {
  display: block;
  width: min(120px, 50%);               /* stays inside the widget with margin */
  margin: 0 auto;
  aspect-ratio: 1118 / 1199;            /* trimmed art's proportions */
  background-color: var(--g1);          /* line colour, per theme */
  /* subtle bloom — transparent in light, faint glow in dark (self-erasing) */
  filter: drop-shadow(0 0 6px var(--bloom-30));
  -webkit-mask: url("../images/logo-mask.png") center / contain no-repeat;
          mask: url("../images/logo-mask.png") center / contain no-repeat;
}

/* ── PHOTOGRAPH WIDGET ─────────────────────────────────────────
   Fills the widget's content width and locks a fixed aspect ratio so
   the frame matches the other widgets regardless of the source file's
   native pixel size. object-fit: cover crops to fill without distorting.
   Change `aspect-ratio` to reframe (4/3 = landscape, 1 = square). */
.photograph {
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 1px solid var(--g5);
  filter: drop-shadow(0 0 6px var(--bloom-30));
}

.photograph img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ── BAR GRAPH ─────────────────────────────────────────────── */
.bar-graph {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 4px;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  /* If enlarged text leaves no room for the track, drop it to its
     own line rather than crushing it to a stub */
  flex-wrap: wrap;
}

.bar-label {
  font-size: 8px;
  color: var(--g3);
  /* ch scales with the rendered font, so the column survives
     browser minimum-font-size / text-only-zoom inflation */
  width: 10.5ch; max-width: 100%; flex-shrink: 0;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.bar-track {
  flex: 1 1 56px; min-width: 56px; height: 4px;
  background: var(--g0);
  border: 1px solid var(--g5);
  position: relative; overflow: hidden;
}

.bar-fill {
  position: absolute; top: 0; left: 0; bottom: 0;
  background: var(--g2);
  box-shadow: var(--glow-sm);
  transform-origin: left;
  animation: barIn 1.2s cubic-bezier(0.23, 1, 0.32, 1) both;
}

.bar-fill--primary { background: var(--g1); }

.bar-pct {
  font-size: 8px;
  color: var(--g3);
  width: 5ch; text-align: right;
  letter-spacing: 0.05em;
}

/* ── SESSION COUNTER — pure-CSS elapsed clock ──────────────── */
@property --sess-h { syntax: '<integer>'; initial-value: 0; inherits: false; }
@property --sess-m { syntax: '<integer>'; initial-value: 0; inherits: false; }
@property --sess-s { syntax: '<integer>'; initial-value: 0; inherits: false; }

.session-counter {
  counter-reset: sess-h var(--sess-h) sess-m var(--sess-m) sess-s var(--sess-s);
  animation:
    sessH 86400s steps(24) infinite,
    sessM 3600s  steps(60) infinite,
    sessS 60s    steps(60) infinite;
}

.session-counter::after {
  content: counter(sess-h, decimal-leading-zero) ':'
           counter(sess-m, decimal-leading-zero) ':'
           counter(sess-s, decimal-leading-zero);
}

@keyframes sessH { to { --sess-h: 24; } }
@keyframes sessM { to { --sess-m: 60; } }
@keyframes sessS { to { --sess-s: 60; } }

/* ── CENTER HERO ───────────────────────────────────────────── */
.hero-name {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(28px, 4vw, 52px); font-weight: 900;
  color: var(--g1);
  text-shadow: var(--glow-lg);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: center;
  line-height: 1;
  animation: fadeUp 1s ease both 0.3s;
}

.hero-rule {
  width: 100%; height: 1px;
  background: linear-gradient(90deg, transparent, var(--g2), var(--g2), transparent);
  margin: 22px 0;
  box-shadow: var(--glow-sm);
  animation: fadeUp 1s ease both 0.5s;
}

.hero-tagline {
  font-family: 'Rajdhani', sans-serif;
  font-size: clamp(11px, 2.5vw, 14px); font-weight: 300;
  color: var(--g3);
  letter-spacing: 0.35em;
  text-transform: uppercase;
  text-align: center;
  animation: fadeUp 1s ease both 0.7s;
}

/* Corner brackets on center panel */
.center::before, .center::after {
  content: '';
  position: absolute;
  width: 20px; height: 20px;
  border-color: var(--g3);
  border-style: solid;
  opacity: 0.5;
}
.center::before { top: 0;    left: 20px;  border-width: 1px 0 0 1px; }
.center::after  { bottom: 0; right: 20px; border-width: 0 1px 1px 0; }

/* ── NAV LINKS ─────────────────────────────────────────────── */
.nav-links {
  display: flex;
  gap: 8px;
  margin-top: 44px;
  flex-wrap: wrap;
  justify-content: center;
  animation: fadeUp 1s ease both 0.9s;
}

.nav-link {
  position: relative;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 18px;
  border: 1px solid var(--g4);
  background: var(--panel);
  color: var(--g2);
  text-decoration: none;
  font-family: 'Share Tech Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  transition: all 0.25s ease;
  overflow: hidden;
  cursor: pointer;
}

.nav-link::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(135deg, var(--g5) 0%, transparent 60%);
  opacity: 0;
  transition: opacity 0.25s;
}

.nav-link:hover {
  border-color: var(--g2);
  color: var(--g1);
  box-shadow: var(--glow-md), inset 0 0 20px var(--dim);
  text-shadow: var(--glow-sm);
}

.nav-link:hover::before { opacity: 1; }

.nav-link-icon { width: 12px; height: 12px; opacity: 0.7; }

/* ── DECORATIVE GRID ───────────────────────────────────────── */
.grid-bg {
  position: absolute; inset: 0; pointer-events: none; z-index: -1;
  background-image:
    linear-gradient(var(--g0) 1px, transparent 1px),
    linear-gradient(90deg, var(--g0) 1px, transparent 1px);
  background-size: 48px 48px;
  -webkit-mask-image: radial-gradient(ellipse at center, transparent 30%, black 80%);
  mask-image: radial-gradient(ellipse at center, transparent 30%, black 80%);
}

/* ── PANEL-RIGHT BAR GRAPH SPACING ─────────────────────────── */
.panel-right .bar-graph { margin-top: 10px; }

/* ── TICKER ────────────────────────────────────────────────── */
.ticker-wrap { overflow: hidden; flex: 1; }

.ticker {
  display: flex;
  gap: 40px;
  white-space: nowrap;
  animation: ticker 18s linear infinite;
  font-size: 9px;
  color: var(--g4);
  letter-spacing: 0.14em;
}

.ticker span { color: var(--g3); }

/* ── COORDINATES ───────────────────────────────────────────── */
.coords {
  font-size: 9px;
  color: var(--g4);
  letter-spacing: 0.1em;
}

/* ── ANIMATIONS ────────────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.35; }
}

@keyframes barIn {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

@keyframes ticker {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}

/* Staggered panel entry */
.panel-left  > *:nth-child(1) { animation: fadeUp 0.8s ease both 0.10s; }
.panel-left  > *:nth-child(2) { animation: fadeUp 0.8s ease both 0.20s; }
.panel-left  > *:nth-child(3) { animation: fadeUp 0.8s ease both 0.30s; }
.panel-left  > *:nth-child(4) { animation: fadeUp 0.8s ease both 0.40s; }
.panel-left  > *:nth-child(5) { animation: fadeUp 0.8s ease both 0.50s; }
.panel-right > *:nth-child(1) { animation: fadeUp 0.8s ease both 0.20s; }
.panel-right > *:nth-child(2) { animation: fadeUp 0.8s ease both 0.35s; }
.panel-right > *:nth-child(3) { animation: fadeUp 0.8s ease both 0.50s; }
.panel-right > *:nth-child(4) { animation: fadeUp 0.8s ease both 0.65s; }
.panel-right > *:nth-child(5) { animation: fadeUp 0.8s ease both 0.80s; }

/* ── FINANCE CARDS ─────────────────────────────────────────── */
/* Flex rather than a 1fr 1fr grid: two cards side by side at the
   intended size, but they stack instead of clipping their tickers
   when the text is enlarged */
.finance-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.finance-card {
  /* Basis under half the panel so the pair sits side by side at the
     intended size; their min-content width forces the wrap only when
     the text is enlarged */
  flex: 1 1 60px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 8px;
  border: 1px solid var(--g5);
  background: var(--g0);
}

.finance-ticker {
  font-family: 'Share Tech Mono', monospace;
  font-size: 8px;
  color: var(--g4);
  letter-spacing: 0.15em;
}

.finance-price {
  font-family: 'Orbitron', sans-serif;
  font-size: 13px;
  color: var(--g1);
  text-shadow: var(--glow-sm);
  letter-spacing: 0.05em;
}

.finance-change {
  font-family: 'Share Tech Mono', monospace;
  font-size: 8px;
  letter-spacing: 0.1em;
}

.finance-change.positive { color: var(--g2); }
.finance-change.negative { color: var(--red); }

.sparkline {
  width: 100%;
  height: 20px;
  display: block;
  margin-top: 4px;
}

.finance-sub {
  font-family: 'Share Tech Mono', monospace;
  font-size: 7px;
  color: var(--g4);
  letter-spacing: 0.1em;
  margin-top: 2px;
}

/* ── ZODIAC GLYPH ──────────────────────────────────────────── */
.glyph-display {
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  cursor: default;
}

.glyph-svg {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  filter: drop-shadow(0 0 6px var(--bloom-glyph));
}

.glyph-data {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ── TOOLTIP ───────────────────────────────────────────────── */
[data-tooltip] { position: relative; }

[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  background: var(--panel);
  border: 1px solid var(--g5);
  color: var(--g3);
  font-family: 'Share Tech Mono', monospace;
  font-size: 8px;
  padding: 4px 8px;
  white-space: nowrap;
  letter-spacing: 0.1em;
  z-index: 20;
  pointer-events: none;
}