:root {
  --bg: #0b0d12;
  --panel: #12151c;
  --panel-2: #181c25;
  --line: #262b36;
  --text: #e7eaf0;
  --muted: #8b93a3;
  --accent: #7cc4ff;
  --accent-2: #b48cff;
  --ok: #58d68d;
  --warn: #ffb454;
  --bad: #ff6b6b;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body { padding: 0 16px 32px; }

.top {
  max-width: 1480px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0 14px;
  padding-top: calc(18px + env(safe-area-inset-top, 0px));
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: conic-gradient(from 210deg, #7cc4ff, #b48cff, #ff7ab8, #ffb454, #7cc4ff);
  box-shadow: 0 0 24px rgba(124, 196, 255, .35);
}
h1 { font-size: 18px; margin: 0; letter-spacing: .2px; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }

.conn { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.conn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 8px currentColor; }
.conn.ok .dot { background: var(--ok); }
.conn.bad .dot { background: var(--bad); }

.layout {
  max-width: 1480px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
}

.stage-wrap { min-width: 0; }

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  touch-action: none;
  user-select: none;
}
.stage:fullscreen { border-radius: 0; border: 0; aspect-ratio: auto; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
/* full screen keeps the frame's aspect ratio (16:9 or 32:9 side by side) and centres it */
.stage:fullscreen canvas, .stage:fullscreen .lane-labels {
  inset: auto; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(100vw, calc(100vh * var(--ar, 1.7778))); height: min(100vh, calc(100vw / var(--ar, 1.7778)));
}
#echo { cursor: crosshair; }

.overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; background: rgba(6, 8, 12, .72); backdrop-filter: blur(3px); text-align: center; padding: 16px;
  transition: opacity .25s;
}
.overlay[hidden] { display: none; }
.overlay p { margin: 0; color: var(--text); max-width: 46ch; }
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.15); border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  background: rgba(0,0,0,.45); color: #fff; padding: 6px 12px; border-radius: 999px; font-size: 12.5px;
  pointer-events: none; transition: opacity .6s;
}
.hint.gone { opacity: 0; }

.hud {
  position: absolute; left: 10px; top: 10px; font: 11.5px/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: rgba(255,255,255,.85); background: rgba(0,0,0,.38); padding: 5px 8px; border-radius: 8px; pointer-events: none;
  white-space: pre;
}

.bar { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button {
  appearance: none; border: 0; background: transparent; color: var(--muted); padding: 7px 12px; border-radius: 8px;
  font: inherit; cursor: pointer; white-space: nowrap;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.seg button[data-method="ksf"][aria-pressed="true"] { color: var(--accent); }
.seg button[data-method="sf"][aria-pressed="true"] { color: #ff7ab8; }
.seg button[data-method="cf"][aria-pressed="true"] { color: #ffb454; }
.seg.small { padding: 2px; border-radius: 8px; }
.seg.small button { padding: 3px 8px; font-size: 12px; border-radius: 6px; }

.toggle {
  appearance: none; background: var(--panel); color: var(--muted); border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 12px; font: inherit; cursor: pointer; white-space: nowrap;
}
.toggle:hover { color: var(--text); }
.toggle[aria-pressed="true"] { color: #ffb454; border-color: #ffb454; box-shadow: inset 0 0 0 1px rgba(255, 180, 84, .35); }

.lane-labels { position: absolute; inset: 0; pointer-events: none; }
.lane-label {
  position: absolute; top: 10px; transform: translateX(-50%); display: inline-flex; align-items: center; gap: 7px;
  background: rgba(0, 0, 0, .5); color: #fff; padding: 4px 11px; border-radius: 999px; font-size: 12.5px;
  white-space: nowrap;
}
.lane-label::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--dot, #fff); }
.stage.compare .hud { top: 44px; }
.seg button:disabled { opacity: .35; cursor: not-allowed; }
.check.off { opacity: .45; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chips[hidden] { display: none; }
.chips button {
  appearance: none; border: 1px solid var(--line); background: var(--panel); color: var(--muted); padding: 6px 12px;
  border-radius: 999px; font: inherit; cursor: pointer;
}
.chips button[aria-pressed="true"] { color: var(--text); border-color: var(--accent-2); box-shadow: 0 0 0 1px var(--accent-2) inset; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
  display: flex; flex-direction: column; gap: 14px;
}
.panel-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.stats[hidden] { display: none; }

/* side by side: the 32:9 stage takes the full width and the panel lays out in columns below it */
body.compare .layout { grid-template-columns: minmax(0, 1fr); }
body.compare .panel { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; align-items: start; }
.group { display: flex; flex-direction: column; gap: 10px; }
.group.row { flex-direction: row; gap: 10px; }
.group.wrap { flex-wrap: wrap; align-items: center; }
.group h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0; }

.slider { display: flex; flex-direction: column; gap: 4px; }
.slider span { display: flex; justify-content: space-between; color: var(--muted); }
.slider b { color: var(--text); font-weight: 600; }
input[type=range] { width: 100%; accent-color: var(--accent); }

.select { display: flex; flex-direction: column; gap: 4px; flex: 1; color: var(--muted); }
select {
  appearance: none; background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 10px; font: inherit;
}
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.buttons { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.buttons .btn { padding: 7px 4px; white-space: nowrap; }
@media (max-width: 380px) { .buttons { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.btn {
  appearance: none; background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 11px; font: inherit; cursor: pointer;
}
.btn:hover { border-color: #3a4152; }
.btn[aria-pressed="true"] { border-color: var(--warn); color: var(--warn); }

.stats {
  display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; margin: 0;
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.stats dt { color: var(--muted); }
.stats dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.about { color: var(--muted); margin: 0; font-size: 12.5px; }

.explain { max-width: 1480px; margin: 28px auto 0; }
.explain h2 { font-size: 15px; margin: 0 0 12px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.cards article { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.cards h3 { margin: 0 0 6px; font-size: 13.5px; }
.cards p { margin: 0; color: var(--muted); font-size: 13px; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  body { padding: 0 12px 24px; }
  .sub { display: none; }
  .seg { flex-wrap: wrap; }
}

.chart-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chart { width: 100%; height: 128px; display: block; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--muted); font-size: 12px; min-height: 16px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 3px; border-radius: 2px; display: inline-block; }

.cmp-wrap[hidden] { display: none; }
.cmp { width: 100%; border-collapse: collapse; font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.cmp th, .cmp td { padding: 3px 0; text-align: right; font-weight: normal; white-space: nowrap; }
.cmp thead th { font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 12px; font-weight: 600; }
.cmp tbody th { text-align: left; color: var(--muted); }
.cmp td + td, .cmp th + th { padding-left: 10px; }
.cmp-note { margin: 4px 0 8px; color: var(--muted); font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.stats + .stats, .cmp-wrap + .stats { margin-top: 8px; }
