/* DynaLink wall: the live bitrate chart, full screen. Dark is the dashboard's own tokens (public/app.css :root); light is
   the same roles stepped for a white surface. Series hues: the dataviz reference palette (8 slots, fixed order), the dark
   steps checked on the chart surface #10141b and the light steps on #ffffff (validate_palette.js: adjacent CVD and
   normal-vision floors pass in both modes; three light slots are under 3:1 on white, so every value is also in the legend) */
:root {
  color-scheme: dark;
  --bg: #0b0e13; --panel: #10141b; --card: #161b24; --line: #232a36; --line-2: #2d3542; --sel: #2d3542;
  --text: #e7eaf0; --dim: #8b94a3; --muted: #5f6878;
  --ok: #3ecf8e; --bad: #ef5b5b; --warn: #e9b44c; --accent: #4f8ff7; --paused: #8fb4ff;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --input: #e7eaf0; /* an input's line: the primary ink, thicker (the outputs' reference) */
  --shadow: 0 6px 24px rgba(0, 0, 0, .45);
  /* type that grows with the screen: a phone at 360 px, a wall TV at 1920 px read from across the room */
  --fs: clamp(13px, 0.5vw + 10.5px, 21px);
  --fs-axis: clamp(11px, 0.42vw + 8.5px, 18px);
  --fs-title: clamp(15px, 0.75vw + 11.5px, 30px);
  --gut: clamp(12px, 1.3vw, 28px);
  --gap: clamp(8px, 0.9vw, 20px);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f4f6f9; --panel: #ffffff; --card: #ffffff; --line: #e3e7ee; --line-2: #cfd5df; --sel: #e3e7ee;
    --text: #0f141b; --dim: #4b5563; --muted: #6b7380;
    --ok: #1a8a55; --bad: #d03b3b; --warn: #a86b00; --accent: #2a66d0; --paused: #3466c9;
    --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
    --input: #0f141b;
    --shadow: 0 6px 24px rgba(15, 20, 27, .14);
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6f9; --panel: #ffffff; --card: #ffffff; --line: #e3e7ee; --line-2: #cfd5df; --sel: #e3e7ee;
  --text: #0f141b; --dim: #4b5563; --muted: #6b7380;
  --ok: #1a8a55; --bad: #d03b3b; --warn: #a86b00; --accent: #2a66d0; --paused: #3466c9;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --input: #0f141b;
  --shadow: 0 6px 24px rgba(15, 20, 27, .14);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: var(--fs)/1.4 -apple-system, "Segoe UI", Roboto, Inter, sans-serif; overflow: hidden; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
a { color: var(--accent); }

.wall { height: 100vh; height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr); gap: var(--gap);
  padding: max(var(--gut), env(safe-area-inset-top)) max(var(--gut), env(safe-area-inset-right)) max(var(--gut), env(safe-area-inset-bottom)) max(var(--gut), env(safe-area-inset-left)); }

/* header: the name, the time shown, India time, Exit (two rows on a phone) */
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px var(--gap); min-width: 0; }
.title { order: 1; flex: 1 1 auto; min-width: 0; margin: 0; display: flex; align-items: center; gap: .5em; font-size: var(--fs-title); font-weight: 700; line-height: 1.2; }
.title > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title .sep { color: var(--muted); font-weight: 400; }
.mark { flex: none; display: grid; place-items: center; width: 1.45em; height: 1.45em; border-radius: .32em; background: linear-gradient(135deg, #4f8ff7, #8b5cf6); color: #fff; font-size: .8em; font-weight: 800; }
.exit { order: 2; flex: none; display: inline-flex; align-items: center; min-height: 2.2em; padding: 0 .9em; border: 1px solid var(--line-2); border-radius: 7px; color: var(--text); text-decoration: none; font-weight: 500; }
.exit:hover { background: var(--line); }
.ctrl { order: 3; flex: 1 1 100%; display: flex; align-items: center; justify-content: space-between; gap: var(--gap); min-width: 0; }
.seg { display: inline-flex; padding: 2px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--panel); }
.seg button { min-height: 2.2em; padding: 0 .85em; border: 0; border-radius: 6px; background: transparent; color: var(--dim); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--sel); color: var(--text); font-weight: 600; }
.seg button:focus-visible, .exit:focus-visible, #cv:focus-visible, .lg:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.clock { color: var(--dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (min-width: 720px) {
  .ctrl { order: 2; flex: 0 1 auto; justify-content: flex-end; }
  .exit { order: 3; }
}

/* the chart and its legend: the legend under the chart on a narrow screen (scrolling in its own box), beside it on a wide one */
.stage { min-height: 0; min-width: 0; display: grid; gap: var(--gap); grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; overflow: hidden; }
.chart { margin: 0; min-height: 0; min-width: 0; display: flex; flex-direction: column; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: clamp(8px, 0.9vw, 20px); }
.chart-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 1.6em; }
.unit { color: var(--dim); font-size: var(--fs-axis); font-weight: 600; }
.notes { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; min-width: 0; }
.note { display: inline-flex; align-items: center; gap: .45em; padding: .05em .7em; border: 1px solid var(--line-2); border-radius: 99px; color: var(--dim); font-size: calc(var(--fs) * .88); white-space: nowrap; }
.note i { width: .55em; height: .55em; border-radius: 50%; background: var(--warn); flex: none; }
.note.calm i { background: var(--dim); }
.plot { position: relative; flex: 1 1 auto; min-height: 90px; }
.plot canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#cv { touch-action: none; cursor: crosshair; border-radius: 4px; }
#ov { pointer-events: none; }

.legend { min-height: 0; max-height: 36vh; max-height: 36dvh; overflow: auto; overscroll-behavior: contain; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px; }
.legend ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); }
.lg-h { grid-column: 1 / -1; padding: .5em .6em .15em; color: var(--dim); font-size: .78em; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.lg { display: grid; grid-template-columns: 2.1em minmax(0, 1fr) auto auto; grid-template-areas: "sw nm val st"; align-items: center; column-gap: .6em; padding: .35em .6em; border-radius: 6px; min-width: 0; }
.lg:hover, .lg.hi { background: var(--card); }
.lg .sw { grid-area: sw; width: 2.1em; height: .9em; display: block; overflow: visible; }
.lg .nm { grid-area: nm; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lg .val { grid-area: val; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; text-align: right; }
.lg .val small { margin-left: .25em; color: var(--dim); font-weight: 400; font-size: .8em; }
.lg .st { grid-area: st; display: inline-flex; align-items: center; gap: .4em; color: var(--dim); font-size: .9em; white-space: nowrap; min-width: 6.4em; }
.dot { width: .6em; height: .6em; border-radius: 50%; flex: none; background: var(--dim); }
.dot[data-state="connected"] { background: var(--ok); }
.dot[data-state="waiting"] { background: var(--warn); }
.dot[data-state="error"] { background: var(--bad); }
.dot[data-state="paused"] { background: var(--paused); }
.dot[data-state="idle"] { background: transparent; box-shadow: inset 0 0 0 2px var(--dim); }

@media (min-width: 900px), (orientation: landscape) and (min-width: 600px) {
  .stage { grid-template-columns: minmax(0, 1fr) clamp(230px, 24vw, 480px); grid-template-rows: minmax(0, 1fr); }
  .legend { max-height: none; }
  .legend ul { grid-template-columns: minmax(0, 1fr); }
  .lg { grid-template-columns: 2.1em minmax(0, 1fr) auto; grid-template-areas: "sw nm val" ". st st"; row-gap: .05em; }
  .lg .st { min-width: 0; }
  /* more entries than fit: one line each, a size smaller (wall.js fitLegend) */
  .legend.dense { font-size: .82em; padding: 4px; }
  .legend.dense .lg { grid-template-columns: 2.1em minmax(0, 1fr) auto auto; grid-template-areas: "sw nm val st"; padding: .22em .5em; }
  .legend.dense .lg-h { padding-top: .3em; }
}

/* the readout at the crosshair: values lead, names follow */
.tip { position: absolute; left: 0; top: 0; z-index: 3; pointer-events: none; max-width: min(92%, 30em); padding: .5em .7em; background: var(--card); border: 1px solid var(--line-2); border-radius: 8px; box-shadow: var(--shadow); font-size: calc(var(--fs) * .9); }
.tip .tt { color: var(--dim); font-variant-numeric: tabular-nums; margin-bottom: .25em; white-space: nowrap; }
.tip .rows { display: grid; grid-template-columns: 1.6em auto minmax(0, 1fr); column-gap: .5em; row-gap: .1em; align-items: center; }
.tip .rows.two { grid-template-columns: 1.6em auto minmax(0, 1fr) 1.6em auto minmax(0, 1fr); column-gap: .5em; }
.tip .k { width: 1.6em; height: .7em; display: block; overflow: visible; }
.tip b { font-variant-numeric: tabular-nums; text-align: right; }
.tip .n { color: var(--dim); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tip .more { color: var(--dim); margin-top: .2em; }

/* in place of the chart: the media server off, not answering, or no sign-in */
.msg { grid-column: 1 / -1; grid-row: 1 / -1; align-self: center; justify-self: center; max-width: 34em; padding: var(--gap); text-align: center; }
.msg h2 { margin: 0 0 .4em; font-size: calc(var(--fs-title) * 1.1); }
.msg p { margin: 0 0 .7em; color: var(--dim); }
.msg .exit { display: inline-flex; color: var(--text); }
.msg .retry { font-size: calc(var(--fs) * .85); color: var(--dim); font-variant-numeric: tabular-nums; }
.stage.is-msg .chart, .stage.is-msg .legend { display: none; }
