/* USB4 version2 Gen4 by ryu-kazuho — styles */
:root {
  --topbar: 56px;
  --bg: #060a12;
  --panel: rgba(9, 14, 25, 0.74);
  --panel-solid: #0b1220;
  --line: rgba(148, 163, 184, 0.16);
  --line-strong: rgba(148, 163, 184, 0.32);
  --text: #e6edf6;
  --mute: #93a3b8;
  --faint: #5d6b80;
  --acc: #38bdf8;
  --pos: #ff8a3d;
  --zero: #dfe7f2;
  --neg: #3da5ff;
  --ok: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
#app { position: fixed; top: var(--topbar); left: 0; right: 0; bottom: 0; }

/* ---------- top bar ---------- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar); z-index: 8;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 16px 0 18px;
  background: #04060b; border-bottom: 1px solid rgba(148, 163, 184, 0.14);
}
.brand { display: flex; align-items: center; gap: 11px; color: #fff; min-width: 0; }
.brand-icon { width: 34px; height: 34px; flex: none; filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.18)); }
.brand-name { font-size: 16px; font-weight: 650; letter-spacing: -.005em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-name .by { font-size: 12px; font-weight: 400; margin-left: 4px; }
#topbar .lang { flex: none; }
#topbar .lang button { font-size: 12px; padding: 7px 11px; }

/* ---------- view tabs (under the top bar) ---------- */
#views {
  position: fixed; top: calc(var(--topbar) + 12px); left: 50%; transform: translateX(-50%); z-index: 6;
  display: flex; align-items: center; gap: 2px; padding: 4px; border-radius: 12px;
  max-width: calc(100vw - 32px); overflow-x: auto; scrollbar-width: none;
}
#views::-webkit-scrollbar { display: none; }
.vtab {
  appearance: none; border: 1px solid transparent; background: transparent; color: var(--mute); cursor: pointer;
  font-family: inherit; font-size: 13px; font-weight: 500; line-height: 1; white-space: nowrap;
  padding: 8px 13px; border-radius: 8px; display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s, color .15s, border-color .15s;
}
.vtab:hover { color: var(--text); background: rgba(255, 255, 255, .05); }
.vtab.active { color: #dff4ff; background: rgba(56, 189, 248, .16); border-color: rgba(56, 189, 248, .55); }
.vtab:focus-visible { outline: 2px solid var(--acc); outline-offset: 1px; }
.vicon { font-size: 14px; }
.vsep { width: 1px; height: 20px; background: var(--line-strong); margin: 0 4px; flex: none; }
#app canvas { display: block; touch-action: none; }
.label-layer { position: absolute; inset: 0; pointer-events: none; }

.panel {
  background: var(--panel);
  backdrop-filter: blur(12px) saturate(1.25);
  -webkit-backdrop-filter: blur(12px) saturate(1.25);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.38);
}

/* ---------- left column ---------- */
#left {
  position: fixed; top: calc(var(--topbar) + 66px); left: 16px; width: 344px;
  display: flex; flex-direction: column; gap: 10px;
  max-height: calc(100vh - var(--topbar) - 66px - 196px); z-index: 5;
}
#title { flex: none; display: flex; flex-direction: column; min-height: 0; }
#title summary {
  list-style: none; cursor: pointer; padding: 12px 14px 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
#title summary::-webkit-details-marker { display: none; }
#title summary::after { content: "▾"; font-size: 12px; color: var(--mute); transition: transform .2s; }
#title:not([open]) summary::after { transform: rotate(-90deg); }
#title h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.title-body { padding: 0 16px 12px; }
#title .sub { color: var(--mute); font-size: 12.5px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 10px 0 2px; }
.chip {
  font: 500 11px/1 var(--mono); color: #cfe3f7;
  padding: 5px 7px; border-radius: 6px;
  background: rgba(56, 189, 248, 0.08); border: 1px solid rgba(56, 189, 248, 0.22);
}
.enc { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); font-family: var(--mono); font-size: 11.5px; }
.enc-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0; }
.enc .k { color: var(--mute); white-space: nowrap; }
.enc .k b { color: var(--text); font-weight: 600; }
.bits { letter-spacing: .12em; color: #9fe6ff; }
.trits { display: flex; gap: 3px; }
.trits span {
  width: 20px; height: 20px; display: grid; place-items: center; border-radius: 4px;
  font-weight: 700; font-size: 12px; border: 1px solid transparent; transition: transform .12s, box-shadow .12s;
}
.t-p { background: rgba(255, 138, 61, .16); color: var(--pos); }
.t-z { background: rgba(223, 231, 242, .10); color: var(--zero); }
.t-n { background: rgba(61, 165, 255, .16); color: var(--neg); }
.trits span.cur { border-color: currentColor; transform: translateY(-2px) scale(1.08); box-shadow: 0 0 10px currentColor; }
.simline { color: var(--faint); font-size: 10.5px; margin-top: 6px; }
.hint { margin-top: 10px; color: var(--faint); font-size: 11px; line-height: 1.5; }
.hint kbd {
  font: 600 10px/1 var(--mono); color: var(--mute); padding: 2px 4px; border-radius: 4px;
  border: 1px solid var(--line-strong); background: rgba(255,255,255,.03);
}

#left.compact #title .chips, #left.compact #title .hint { display: none; }
#info { padding: 14px 16px; position: relative; overflow: auto; min-height: 0; }
#info.hidden { display: none; }
#info .tag {
  display: inline-flex; align-items: center; gap: 6px;
  font: 600 10px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--c, var(--acc));
}
#info .tag::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--c, var(--acc)); box-shadow: 0 0 8px var(--c, var(--acc)); }
#info h2 { margin: 6px 26px 6px 0; font-size: 15.5px; font-weight: 650; }
#info p { margin: 0 0 10px; color: #c3cfdd; font-size: 12.5px; }
#info dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; font-size: 12px; }
#info dt { color: var(--mute); }
#info dd { margin: 0; font-family: var(--mono); font-size: 11.5px; text-align: right; color: var(--text); }
#infoClose {
  position: absolute; top: 10px; right: 10px; width: 24px; height: 24px; border-radius: 6px;
  border: 1px solid var(--line); background: transparent; color: var(--mute); cursor: pointer; font-size: 15px; line-height: 1;
}
#infoClose:hover { color: var(--text); border-color: var(--line-strong); }

/* ---------- language ---------- */
html:lang(zh-CN) body { font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif; }
html:lang(ja) body { font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", Meiryo, "Noto Sans CJK JP", sans-serif; }
html:lang(zh-CN) { --mono: ui-monospace, "SF Mono", Menlo, Consolas, "PingFang SC", "Microsoft YaHei", monospace; }
html:lang(ja) { --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Hiragino Sans", "Yu Gothic", Meiryo, monospace; }
.lang {
  display: inline-flex; padding: 2px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: rgba(255, 255, 255, .03);
}
.lang button {
  appearance: none; border: 0; background: transparent; color: var(--mute); cursor: pointer;
  font: 600 11px/1 system-ui, -apple-system, "PingFang SC", "Hiragino Sans", sans-serif;
  padding: 5px 8px; border-radius: 6px; transition: background .15s, color .15s;
}
.lang button:hover { color: var(--text); }
.lang button.active { background: rgba(56, 189, 248, .18); color: #dff4ff; }
.lang button:focus-visible { outline: 2px solid var(--acc); outline-offset: 1px; }

/* ---------- controls ---------- */
#controls {
  position: fixed; top: calc(var(--topbar) + 66px); right: 16px; width: 290px; z-index: 5;
  max-height: calc(100vh - var(--topbar) - 66px - 186px); overflow-y: auto;
}
#controls summary {
  list-style: none; cursor: pointer; padding: 12px 14px; display: flex; align-items: center; justify-content: space-between;
  font: 600 10.5px/1 var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--mute);
}
#controls summary::-webkit-details-marker { display: none; }
#controls summary::after { content: "▾"; font-size: 12px; transition: transform .2s; }
#controls:not([open]) summary::after { transform: rotate(-90deg); }
.ctl-body { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 12px; }
.group-title { font: 600 10px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--faint); margin-bottom: -4px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.slider label { display: flex; justify-content: space-between; font-size: 12px; color: #c3cfdd; margin-bottom: 5px; }
.slider label output { font-family: var(--mono); font-size: 11.5px; color: var(--text); }
input[type=range] { width: 100%; accent-color: var(--acc); height: 18px; margin: 0; }
.btn {
  appearance: none; border: 1px solid var(--line-strong); background: rgba(255,255,255,.03); color: var(--text);
  padding: 7px 10px; border-radius: 8px; font: 500 12px/1 system-ui, sans-serif; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: rgba(56,189,248,.10); border-color: rgba(56,189,248,.45); }
.btn.active { background: rgba(56,189,248,.16); border-color: rgba(56,189,248,.6); color: #dff4ff; }
#playBtn { min-width: 86px; font-weight: 600; }
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 7px 10px; }
.tog { display: flex; align-items: center; gap: 7px; font-size: 12px; color: #c3cfdd; cursor: pointer; user-select: none; }
.tog input { accent-color: var(--acc); margin: 0; width: 14px; height: 14px; }
.legend { display: flex; gap: 12px; font: 500 11px/1 var(--mono); color: var(--mute); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }

/* ---------- scopes ---------- */
#scopes {
  position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%);
  display: flex; gap: 10px; padding: 10px; z-index: 4;
}
#scopes.hidden { display: none; }
#scopes canvas.scope { width: 236px; height: 144px; border-radius: 8px; border: 1px solid var(--line); display: block; cursor: pointer; }

#tooltip {
  position: fixed; pointer-events: none; z-index: 10; padding: 6px 9px; border-radius: 7px;
  background: rgba(6, 10, 18, .92); border: 1px solid var(--line-strong); font-size: 12px; white-space: nowrap;
  transform: translate(14px, 14px); opacity: 0; transition: opacity .12s;
}
#tooltip.show { opacity: 1; }
#tooltip small { display: block; color: var(--mute); font: 500 10.5px/1.4 var(--mono); }

/* ---------- 3D labels ---------- */
.lbl {
  font: 600 10.5px/1 var(--mono); color: #e6edf6; white-space: nowrap;
  padding: 4px 7px; border-radius: 5px;
  background: rgba(6, 10, 18, .72); border: 1px solid color-mix(in srgb, var(--c) 55%, transparent);
  box-shadow: 0 0 12px color-mix(in srgb, var(--c) 25%, transparent);
  transition: opacity .25s;
}
.lbl.big { font-size: 12px; padding: 6px 10px; letter-spacing: .06em; color: var(--c); }
.lbl.blk { font-weight: 500; font-size: 10px; padding: 3px 6px; }

#loading {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 20; background: var(--bg);
  color: var(--mute); font: 500 13px/1.7 var(--mono); letter-spacing: .04em; transition: opacity .6s;
  padding: 24px; text-align: center;
}
#loading.gone { opacity: 0; pointer-events: none; }

@media (max-width: 1280px), (max-height: 820px) {
  #scopes canvas.scope { width: 200px; height: 122px; }
  #left { max-height: calc(100vh - var(--topbar) - 66px - 170px); }
}
@media (max-width: 860px) {
  :root { --topbar: 50px; }
  #topbar { padding: 0 12px; gap: 10px; }
  .brand { gap: 9px; }
  .brand-icon { width: 28px; height: 28px; }
  .brand-name { font-size: 14px; }
  .brand-name .by { font-size: 11px; }
  #topbar .lang button { padding: 6px 8px; font-size: 11.5px; }
  #views {
    top: calc(var(--topbar) + 10px); left: 16px; right: 16px; transform: none;
    justify-content: flex-start; justify-content: safe center;   /* centred, but never clipped when it scrolls */
  }
  .vtab { padding: 7px 10px; font-size: 12.5px; }
  #left { top: calc(var(--topbar) + 60px); width: calc(100vw - 32px); max-height: 46vh; }
  .title-body { max-height: 32vh; overflow-y: auto; }
  #controls { top: auto; bottom: calc((100vw - 56px) / 3 * 0.611 + 42px); right: 16px; width: min(290px, calc(100vw - 32px)); max-height: 50vh; overflow: auto; }
  #scopes { gap: 6px; padding: 6px; width: calc(100vw - 32px); justify-content: space-between; }
  #scopes canvas.scope { width: calc((100vw - 32px - 24px) / 3); height: auto; aspect-ratio: 360 / 220; }
}

/* legend dots (classes instead of inline style attributes, so CSP can stay strict) */
.legend i.d-pos { background: var(--pos); }
.legend i.d-zero { background: var(--zero); }
.legend i.d-neg { background: var(--neg); }
