/* ============================================================================
   Cryptoccino TV — terminal skin (dark default + Latte light via [data-theme]).
   Four-zone layout: top bar / [news digest · editorial · data sidebar] / ticker.
   Fonts: Playfair Display (headlines), Space Grotesk (UI/body), JetBrains Mono
   (data/timestamps/ticker) — loaded from Google Fonts in tv.html.
   ========================================================================== */

:root {
  --bg:        #0E1012;
  --bg-col:    #0B0D0F;
  --bar:       #080A0C;
  --border:    #1C2028;
  --line-soft: #14181E;

  --text:   #D8CCBC;
  --text2:  #8A7E70;
  --text3:  #6A7080;
  --micro:  #4A443C;

  --amber:  #D49A1A;
  --green:  #5BB85F;
  --red:    #E5544A;
  --blue:   #6E92B4;

  --head:   #ECE2D2;
  --newshead: #D2C2AA;
  --price:  #CFC3B2;
  --note:   #6E5E48;

  --serif: "Playfair Display", Georgia, serif;
  --sans:  "Space Grotesk", system-ui, sans-serif;
  --mono:  "JetBrains Mono", ui-monospace, Menlo, monospace;

  --top-h: 50px;
  --tick-h: 48px;
}

/* Latte — the warm light cappuccino skin. */
:root[data-theme="latte"] {
  --bg:        #FCFAF5;
  --bg-col:    #F4EDDD;
  --bar:       #EFE6D1;
  --border:    #D8C5A2;
  --line-soft: #EADFC6;

  --text:   #3A2C1E;
  --text2:  #6E5E48;
  --text3:  #8A7B64;
  --micro:  #A2937B;

  --amber:  #A35E1E;
  --green:  #4C7A47;
  --red:    #C0473C;
  --blue:   #466A8A;

  --head:   #2A1E12;
  --newshead: #43331F;
  --price:  #43331F;
  --note:   #8A7B64;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body.tv {
  height: 100vh; height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.tv-up   { color: var(--green); }
.tv-down { color: var(--red); }
.tv-amber{ color: var(--amber); }
.tv-muted{ color: var(--text2); }

.tv-digest, .tv-center, .tv-side { scrollbar-width: none; -ms-overflow-style: none; }
.tv-digest::-webkit-scrollbar, .tv-center::-webkit-scrollbar, .tv-side::-webkit-scrollbar { display: none; }

/* --- Grid (wider rails for breathing room) ----------------------------- */
.tv-grid {
  height: 100vh; height: 100dvh;
  display: grid;
  grid-template-rows: var(--top-h) 1fr var(--tick-h);
  grid-template-columns: 320px 1fr 320px;   /* left + right rails equal width */
  grid-template-areas:
    "top    top    top"
    "digest center side"
    "ticker ticker ticker";
}

/* --- Section header (the │ I-pipe pattern) ----------------------------- */
.tv-colhead {
  margin: 0;
  padding: 11px 16px 10px;
  display: flex; align-items: center; gap: 8px;
  font-family: var(--sans);
  font-size: 11.5px; font-weight: 700;
  letter-spacing: .16em; text-transform: uppercase;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.tv-colhead::before { content: "│"; color: var(--amber); font-weight: 700; }
.tv-upd { margin-left: auto; font-family: var(--mono); font-size: 11px; font-weight: 400; letter-spacing: 0; color: var(--micro); }

/* ============================ TOP BAR ================================== */
.tv-top {
  grid-area: top;
  background: var(--bar);
  border-bottom: 1px solid var(--border);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 0 18px;
}
.tv-top__brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.tv-logo { font-family: var(--sans); font-size: 16.5px; font-weight: 700; letter-spacing: .04em; color: var(--amber); white-space: nowrap; }
.tv-badge { font-family: var(--sans); font-size: 11px; letter-spacing: .12em; color: var(--amber); border: 1px solid var(--amber); border-radius: 2px; padding: 2px 7px; }
.tv-tagline { font-family: var(--sans); font-size: 11px; font-weight: 500; letter-spacing: .16em; color: var(--text2); text-transform: uppercase; white-space: nowrap; border-left: 1px solid var(--border); margin-left: 2px; padding-left: 13px; }
.tv-top__center { display: flex; align-items: baseline; justify-content: center; gap: 13px; }
.tv-clock { font-family: var(--mono); font-size: 23px; color: var(--text); font-variant-numeric: tabular-nums; }
.tv-topdate { font-family: var(--mono); font-size: 13px; letter-spacing: .08em; color: var(--text3); white-space: nowrap; }
.tv-top__right { display: flex; align-items: center; justify-content: flex-end; gap: 16px; }
.tv-live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; letter-spacing: .06em; color: var(--text2); }
.tv-live__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text2); }
.tv-live.is-live .tv-live__dot { background: var(--green); animation: tv-pulse 1.8s ease-in-out infinite; }
.tv-live.is-live .tv-live__label { color: var(--green); }
.tv-live.is-down .tv-live__dot { background: var(--red); }
.tv-live.is-down .tv-live__label { color: var(--red); }
.tv-status { font-size: 12px; letter-spacing: .1em; color: var(--text2); white-space: nowrap; }
.tv-updstamp { font-family: var(--mono); font-size: 11px; color: var(--text2); }
.tv-fsbtn { background: none; border: none; color: var(--text2); font-size: 18px; cursor: pointer; padding: 0 2px; line-height: 1; }
.tv-fsbtn:hover { color: var(--amber); }
/* espresso ↔ latte theme switch: both coffee icons shown, the active theme lit */
.tv-themebtn { display: inline-flex; align-items: center; gap: 9px; background: var(--bg-col); border: 1px solid var(--text3); border-radius: 999px; cursor: pointer; padding: 5px 13px; line-height: 0; transition: border-color .15s ease, background-color .15s ease; }
.tv-themebtn:hover { border-color: var(--amber); background: rgba(212,154,26,0.08); }
.tv-themebtn__label { font-family: var(--sans); font-size: 10.5px; font-weight: 700; letter-spacing: .16em; line-height: 1; color: var(--text2); padding-right: 9px; border-right: 1px solid var(--border); }
.tv-themebtn:hover .tv-themebtn__label { color: var(--amber); }
.tv-themebtn__ico { display: inline-flex; color: var(--text2); opacity: .4; transition: opacity .15s ease, color .15s ease; }
.tv-themebtn__ico svg { width: 19px; height: 19px; display: block; }
.tv-themebtn__ico--espresso { color: var(--amber); opacity: 1; }                       /* dark = espresso (active) */
:root[data-theme="latte"] .tv-themebtn__ico--espresso { color: var(--text2); opacity: .4; }
:root[data-theme="latte"] .tv-themebtn__ico--latte    { color: var(--amber); opacity: 1; }
@keyframes tv-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* ====================== LEFT: NEWS DIGEST ============================== */
.tv-digest { grid-area: digest; background: var(--bg-col); border-right: 1px solid var(--border); overflow-y: auto; min-height: 0; }
.tv-dg__list { list-style: none; margin: 0; padding: 0 0 18px; }
.tv-dg__cat { display: flex; align-items: center; gap: 9px; margin: 0; padding: 15px 16px 7px; border-top: 1px solid var(--border); font-size: 12px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: var(--amber); }
.tv-dg__cat::before { content: ""; width: 9px; height: 9px; border-radius: 2px; background: currentColor; flex: 0 0 auto; }
.tv-dg__cat--market   { color: var(--blue); }
.tv-dg__cat--business { color: var(--amber); }
.tv-dg__cat--security { color: var(--red); }
.tv-dg__cat--policy   { color: #8E78C8; }
.tv-dg__list > .tv-dg__cat:first-child { border-top: none; padding-top: 9px; }
.tv-dg__empty { padding: 16px; font-family: var(--mono); font-size: 13px; color: var(--text2); }
.tv-dg__item a { display: block; padding: 12px 16px; border-bottom: 1px solid var(--line-soft); text-decoration: none; color: var(--text); }
.tv-dg__item a:hover { background: rgba(212,154,26,0.06); }
.tv-dg__head { display: block; font-size: 15.5px; font-weight: 600; line-height: 1.4; color: var(--newshead); }
.tv-dg__item a:hover .tv-dg__head { color: var(--amber); }
.tv-dg__take { display: block; margin-top: 5px; font-size: 14px; line-height: 1.5; color: var(--text2); }
.tv-dg__src { display: block; margin-top: 7px; font-size: 10.5px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--micro); }

/* ====================== CENTER: EDITORIAL ============================== */
.tv-center { grid-area: center; background: var(--bg); border-right: 1px solid var(--border); overflow-y: auto; min-height: 0; }

/* WHAT IS THIS — one-line orientation for first-time viewers */
.tv-intro { padding: 16px 30px; border-bottom: 1px solid var(--border); background: linear-gradient(180deg, rgba(212,154,26,0.05), transparent); }
.tv-intro__text { margin: 0; font-family: var(--sans); font-size: 15.5px; line-height: 1.6; color: var(--text2); }
.tv-intro__text strong { color: var(--amber); font-weight: 700; }

.tv-sec { border-bottom: 1px solid var(--border); }

/* TODAY'S BRIEF (whole block is a link to the latest issue) */
.tv-brief__link { display: block; padding: 20px 30px 24px; text-decoration: none; color: inherit; }
.tv-brief__link:hover { background: rgba(212,154,26,0.04); }
.tv-brief__head { margin: 0; font-family: var(--serif); font-weight: 700; font-size: clamp(30px, 3.4vw, 48px); line-height: 1.2; color: var(--head); }
.tv-brief__link:hover .tv-brief__head { color: var(--amber); }
.tv-brief__deck { margin: 14px 0 0; font-family: var(--sans); font-size: 18px; line-height: 1.6; color: var(--text2); max-width: 64ch; }
.tv-brief__meta { margin: 18px 0 0; font-family: var(--mono); font-size: 12px; letter-spacing: .08em; color: var(--micro); }
.tv-brief__cue { color: var(--amber); font-weight: 500; }

/* CHARTS — token-selectable */
.tv-charts { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--border); border-bottom: 1px solid var(--border); }
.tv-chart { background: var(--bar); border: 1px solid var(--border); padding: 16px 18px; position: relative; }
.tv-chart__bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.tv-chart__title { margin: 0; font-family: var(--sans); font-size: 13px; font-weight: 600; letter-spacing: .04em; color: var(--text); }
.tv-chart__sym { -webkit-appearance: none; appearance: none; background: var(--bg); border: 1px solid var(--border); border-radius: 3px; color: var(--text); font-family: var(--mono); font-size: 13px; font-weight: 500; padding: 4px 24px 4px 9px; cursor: pointer; background-image: linear-gradient(45deg, transparent 50%, var(--text2) 50%), linear-gradient(135deg, var(--text2) 50%, transparent 50%); background-position: right 10px center, right 6px center; background-size: 4px 4px, 4px 4px; background-repeat: no-repeat; }
.tv-chart__sym:hover { border-color: var(--amber); color: var(--amber); }
.tv-chart__canvas { position: relative; height: 200px; }
.tv-chart__canvas canvas { display: block; }
.tv-chart__err { position: absolute; inset: 0; margin: 0; display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-size: 12.5px; letter-spacing: .08em; color: var(--micro); }
.tv-chart__err[hidden] { display: none; }
.tv-chart__foot { display: flex; justify-content: space-between; margin-top: 11px; font-family: var(--sans); font-size: 10.5px; letter-spacing: .04em; color: var(--micro); }

/* MARKET CONTEXT — the Claude blurb */
.tv-context { border-bottom: 1px solid var(--border); }
.tv-context[hidden] { display: none; }
.tv-context__body { margin: 0; padding: 16px 30px 20px; font-family: var(--sans); font-size: 17px; line-height: 1.7; color: var(--text2); }

/* ===================== RIGHT: DATA SIDEBAR ============================ */
.tv-side { grid-area: side; background: var(--bg-col); border-left: 1px solid var(--border); overflow-y: auto; min-height: 0; display: flex; flex-direction: column; }
.tv-panel { border-bottom: 1px solid var(--border); padding-bottom: 7px; }

/* per-section accent colours — distinct, readable on both themes */
.tv-panel--market   { --accent: var(--blue); }
.tv-panel--deriv    { --accent: #B06AC8; }
.tv-panel--defi     { --accent: var(--green); }
.tv-panel--yields   { --accent: #3FA89A; }
.tv-panel > .tv-colhead { border-left: 3px solid var(--accent, var(--amber)); padding-left: 13px; }
.tv-panel > .tv-colhead::before { color: var(--accent, var(--amber)); }

/* "?" help badge — pairs with the JS-driven .tv-tip tooltip (see initTips/showTip) */
.tv-help { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; margin-left: 6px; border: 1px solid var(--border); border-radius: 50%; font-family: var(--sans); font-size: 9.5px; font-weight: 700; line-height: 1; color: var(--text2); cursor: default; flex: 0 0 auto; }
.tv-help:hover { color: var(--amber); border-color: var(--amber); }
.tv-row__k { display: inline-flex; align-items: center; }

/* custom tooltip — positioned at the viewport level by tv.js (never clipped) */
.tv-tip {
  position: fixed; z-index: 60; display: none; max-width: 280px;
  padding: 9px 12px; background: var(--bar); color: var(--text);
  border: 1px solid var(--border); border-left: 3px solid var(--amber); border-radius: 4px;
  font-family: var(--sans); font-size: 13px; line-height: 1.5; font-weight: 400; letter-spacing: 0; text-transform: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35); pointer-events: none;
}
.tv-panel > .tv-row, .tv-panel > .tv-note, .tv-panel > .tv-sub { padding-left: 16px; padding-right: 16px; }

.tv-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 9px 16px; }
.tv-row--col { flex-direction: column; align-items: stretch; gap: 7px; }
.tv-row__top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.tv-row__k { font-family: var(--sans); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--text2); white-space: nowrap; }
.tv-row__v { font-family: var(--mono); font-size: 15.5px; color: var(--text); text-align: right; }

.tv-bar { height: 6px; background: var(--bar); border: 1px solid var(--border); overflow: hidden; }
.tv-bar__fill { display: block; height: 100%; width: 0; background: var(--amber); transition: width .5s ease; }

.tv-sub { padding: 2px 0 6px; }
.tv-subrow { display: flex; align-items: baseline; gap: 8px; padding: 6px 16px; }
.tv-subrow__name { flex: 1 1 auto; font-family: var(--sans); font-size: 14px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tv-subrow__v { font-family: var(--mono); font-size: 14px; color: var(--text); }
.tv-subrow__c { font-family: var(--mono); font-size: 11.5px; min-width: 48px; text-align: right; }

.tv-splitbar { display: flex; height: 10px; width: 100%; background: var(--bar); overflow: hidden; border-radius: 1px; }
.tv-splitbar > span { display: block; height: 100%; flex: 0 0 auto; }
.tv-stb__legend { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; }
.tv-stb__item { display: inline-flex; align-items: center; gap: 5px; font-family: var(--mono); font-size: 11.5px; color: var(--text2); }
.tv-stb__item i { width: 9px; height: 9px; border-radius: 2px; flex: 0 0 auto; }

.tv-note { margin: 6px 0; font-family: var(--sans); font-size: 12px; font-style: italic; color: var(--note); }

/* ========================= BOTTOM TICKER ============================== */
.tv-ticker { grid-area: ticker; background: var(--bar); border-top: 1px solid var(--border); overflow: hidden; display: flex; align-items: center; }
.tv-ticker__track { display: inline-flex; white-space: nowrap; will-change: transform; }
.tv-ticker__track.is-rolling { animation: tv-roll var(--roll, 60s) linear infinite; }
.tv-titem { display: inline-flex; align-items: baseline; gap: 11px; padding: 0 26px; border-right: 1px solid var(--border); font-family: var(--mono); font-size: 16px; }
.tv-titem__sym { color: var(--text3); font-weight: 600; }
.tv-titem__price { color: var(--price); }
.tv-titem__lead { padding: 0 18px 0 26px; font-family: var(--mono); font-size: 18px; font-weight: 700; }
@keyframes tv-roll { from { transform: translateX(0); } to { transform: translateX(-50%); } }

/* ========================== RESPONSIVE ================================ */
@media (max-width: 1240px) { .tv-tagline { display: none; } }

/* ≤1100px: collapse the left news column; keep center + data sidebar. */
@media (max-width: 1100px) {
  .tv-grid { grid-template-columns: 1fr 320px; grid-template-areas: "top top" "center side" "ticker ticker"; }
  .tv-digest { display: none; }
}

/* Phone: scrollable stacked terminal — masthead + ticker pinned. */
@media (max-width: 720px) {
  body.tv { overflow-y: auto; }
  .tv-grid {
    height: auto; min-height: 100dvh;
    grid-template-columns: 1fr;
    grid-template-rows: var(--top-h) auto auto auto var(--tick-h);
    grid-template-areas: "top" "center" "digest" "side" "ticker";
  }
  .tv-digest, .tv-side { display: block; overflow: visible; min-height: 0; border: none; border-top: 1px solid var(--border); }
  .tv-center { overflow: visible; }
  .tv-charts { grid-template-columns: 1fr; }
  .tv-top { position: sticky; top: 0; z-index: 4; padding: 0 10px; }
  .tv-ticker { position: sticky; bottom: 0; z-index: 4; }
  .tv-topdate, .tv-status, .tv-updstamp { display: none; }
  .tv-brief__head { font-size: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  .tv-ticker__track.is-rolling { animation: none; }
  .tv-live.is-live .tv-live__dot { animation: none; }
}
