/* Shared components: toasts, popovers, menus, dialogs, tooltips, banners, nudge group, odometer,
   the signal runner, empty states and skeletons. Every overlay unrolls from a 2px cyan top edge. */

svg.icon { flex-shrink: 0; display: block; }

/* ---------- the overlay edge (S7): a 2px signal line along the top ---------- */
.edge-top { position: relative; }
.edge-top::before { content: ''; position: absolute; left: -1px; right: -1px; top: -1px; height: 2px; background: var(--accent); transform-origin: left; animation: edgeDraw var(--t-in) var(--e-whip) both; }

/* ---------- toasts (bottom-left, newest on top) ---------- */
.toasts { position: fixed; left: var(--s5); bottom: var(--s5); z-index: 60; display: flex; flex-direction: column; gap: var(--s2); width: min(26rem, calc(100vw - 3rem)); pointer-events: none; }
.toast { pointer-events: auto; position: relative; display: flex; align-items: center; gap: .625rem; min-height: 3rem; padding: .625rem .625rem .625rem 1.125rem; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 6px; box-shadow: var(--shadow-3); font-size: .875rem; color: var(--text); overflow: hidden; animation: toastIn 320ms var(--e-out) both; }
.toast.leaving { animation: toastOut 200ms var(--e-in) both; }
.toast { clip-path: polygon(.625rem 0, 100% 0, 100% 100%, 0 100%); border-left: 0; border-radius: 0 6px 6px 0; box-shadow: none; padding-left: 1.5rem; }
.toast-bar { position: absolute; left: 0; top: -1px; bottom: -1px; width: calc(.625rem + 4px); background: var(--accent); clip-path: polygon(.625rem 0, 100% 0, 4px 100%, 0 100%); }
.toast-ok .toast-bar { background: var(--live); }
.toast-error .toast-bar { background: var(--fail); }
.toast-warn .toast-bar { background: var(--amber); }
.toast-msg { flex: 1; min-width: 0; }
.toast-action { background: none; border: 1px solid var(--accent); color: var(--accent); border-radius: var(--radius); height: 1.875rem; padding: 0 .625rem; font: 700 .8125rem var(--display); letter-spacing: .06em; text-transform: uppercase; cursor: pointer; }
.toast-action:hover { background: rgba(54, 214, 255, .1); }
.toast-close { background: none; border: 0; color: var(--muted); width: 1.875rem; height: 1.875rem; display: grid; place-items: center; cursor: pointer; border-radius: var(--radius); }
.toast-close:hover { color: var(--text); background: var(--line); }

/* ---------- popovers (confirm, system) ---------- */
.popover { position: fixed; z-index: 70; width: min(20rem, calc(100vw - 1rem)); padding: .875rem var(--s4); background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 6px; box-shadow: var(--shadow-3); animation: popIn 180ms var(--e-out) both; }
.popover.leaving { animation: popOut var(--t-exit) var(--e-in) both; }
.popover::before { content: ''; position: absolute; left: -1px; top: -1px; height: 3px; width: 4rem; background: var(--accent); transform: skewX(-14deg); transform-origin: left; animation: edgeDraw var(--t-in) var(--e-whip) both; }
.popover.confirm::before { background: var(--fail); }
.pop-title { margin: 0 0 var(--s1); font: italic 800 1.125rem var(--display); letter-spacing: .03em; text-transform: uppercase; }
.pop-body { margin: 0 0 var(--s3); font-size: .875rem; line-height: 1.45; color: var(--text-2); }
.pop-actions { display: flex; justify-content: flex-end; gap: var(--s2); }

/* ---------- tooltips ---------- */
/* Line 1 is the action, line 2 (after " · ") the consequence or live state, muted. */
.tooltip { position: fixed; z-index: 80; max-width: 18rem; padding: .4375rem .625rem .4375rem .8125rem; display: grid; grid-template-columns: 1fr auto; column-gap: .625rem; align-items: center; background: #1A1F28; border: 1px solid var(--line-2); border-radius: var(--radius); box-shadow: 0 .5rem 1.5rem rgba(0,0,0,.5); font-size: .8125rem; line-height: 1.35; color: var(--text); pointer-events: none; opacity: 0; transform: translateY(.25rem); transition: opacity 80ms, transform 80ms var(--e-in); }
/* The box is cut along the slash, so the cyan line is its left edge (no corner poking out). */
.tooltip { clip-path: polygon(.5rem 0, 100% 0, 100% 100%, 0 100%); border-left: 0; border-radius: 0 var(--radius) var(--radius) 0; padding-left: 1.125rem; box-shadow: none; }
.tooltip::before { content: ''; position: absolute; left: 0; top: -1px; bottom: -1px; width: calc(.5rem + 2px); background: var(--accent); clip-path: polygon(.5rem 0, 100% 0, 2px 100%, 0 100%); }
.tooltip[data-side="below"] { transform: translateY(-.25rem); }
.tooltip.on { opacity: 1; transform: none; transition: opacity 120ms, transform 120ms var(--e-out); }
.tooltip .tip-2 { grid-column: 1; color: var(--muted); }
.tooltip kbd { grid-column: 2; grid-row: 1; }
.tooltip.warn::before { background: var(--amber); }

/* ---------- menus ---------- */
.menu { position: fixed; z-index: 70; min-width: 15rem; max-width: 20rem; padding: 6px; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 6px; box-shadow: var(--shadow-3); transform-origin: top; animation: menuIn var(--t-exit) var(--e-out) both; }
.menu[data-side="above"] { transform-origin: bottom; }
.menu::before { content: ''; position: absolute; left: -1px; right: -1px; top: -1px; height: 2px; background: var(--accent); transform-origin: left; animation: edgeDraw var(--t-in) var(--e-whip) both; }
.menu.leaving { animation: popOut 90ms var(--e-in) both; }
.menu-item { width: 100%; display: flex; align-items: center; gap: .625rem; min-height: 2.25rem; padding: 6px .625rem; background: none; border: 0; border-radius: var(--radius); color: var(--text); font: 500 .875rem var(--body); text-align: left; cursor: pointer; }
/* Hover / focus: the fill starts at a slanted cyan edge (the signal line), never a rounded box. */
.menu-item { position: relative; isolation: isolate; }
.menu-item::before { content: ''; position: absolute; inset: 0; z-index: -1; background: transparent; clip-path: polygon(.375rem 0, 100% 0, 100% 100%, 0 100%); transition: background-color var(--t-press); }
.menu-item::after { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: calc(.375rem + 2px); background: var(--accent); clip-path: polygon(.375rem 0, 100% 0, 2px 100%, 0 100%); opacity: 0; transition: opacity var(--t-press); pointer-events: none; }
.menu-item:hover, .menu-item:focus-visible { outline: none; }
.menu-item:hover::before, .menu-item:focus-visible::before { background: var(--hover); }
.menu-item:hover::after, .menu-item:focus-visible::after { opacity: 1; }
.menu-item[aria-disabled="true"]:hover::before { background: transparent; }
.menu-item[aria-disabled="true"]:hover::after { opacity: 0; }
.menu-item[aria-disabled="true"] { opacity: .45; cursor: default; }
.menu-item.danger { color: var(--fail); }
.menu-item.danger:hover::before, .menu-item.danger:focus-visible::before { background: rgba(255, 77, 90, .12); }
.menu-item.danger::after { background: var(--fail); }
.menu-item .icon { color: var(--muted); }
.menu-item.danger .icon { color: var(--fail); }
.icon-space { width: 1rem; flex-shrink: 0; }
.menu-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.menu-sub { font: .75rem var(--mono); color: var(--muted); }
.menu-sep { height: 1px; margin: 6px 4px; background: var(--line); }
.menu-html { padding: 6px .625rem; }
.menu-head { padding: var(--s2) .625rem var(--s1); font: 600 .6875rem var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.menu-confirm { padding: var(--s2) 6px var(--s1); }
.menu-confirm p { margin: 0 0 var(--s3); font-size: .875rem; line-height: 1.45; color: var(--text-2); }
.menu.confirming { border-color: rgba(255, 77, 90, .5); }
.menu.confirming::before { background: var(--fail); }
/* Copyable id chips inside menus (API section). */
.id-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.id-chip { display: inline-flex; align-items: center; gap: 6px; height: 1.75rem; padding: 0 var(--s2); background: var(--field); border: 1px solid var(--line-2); border-radius: 3px; color: var(--text-2); font: .75rem var(--mono); cursor: pointer; }
.id-chip:hover { border-color: var(--accent); color: var(--accent); }
.id-chip b { color: var(--muted); font-weight: 400; }

/* ---------- dialogs ---------- */
.dialog { width: min(35rem, calc(100vw - 2rem)); max-width: none; max-height: calc(100vh - 4rem); padding: 0; background: var(--panel); color: var(--text); border: 1px solid var(--line-2); border-radius: 8px; box-shadow: var(--shadow-3); overflow: visible; }
.dialog.wide { width: min(75rem, calc(100vw - 2rem)); }
.dialog[open] { animation: dialogIn var(--t-move) var(--e-out) both; }
.dialog.leaving { animation: popOut var(--t-exit) var(--e-in) both; }
.dialog::backdrop { background: rgba(4, 5, 8, .78); animation: fadeIn var(--t-in) linear both; }
.dialog::before { content: ''; position: absolute; left: -1px; right: -1px; top: -1px; height: 2px; background: var(--accent); transform-origin: left; animation: edgeDraw var(--t-in) var(--e-whip) 120ms both; border-radius: 8px 8px 0 0; }
.dlg-head { display: flex; align-items: center; gap: var(--s3); padding: var(--s4) 1.25rem var(--s2); }
.dlg-title { margin: 0; flex: 1; font: italic 800 1.625rem/1.1 var(--display); letter-spacing: .02em; text-transform: uppercase; }
.dlg-body { padding: var(--s2) 1.25rem 1.25rem; overflow: auto; max-height: calc(100vh - 12rem); }
.dlg-body > p:first-child { margin-top: 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: var(--s2); padding: var(--s3) 1.25rem var(--s4); border-top: 1px solid var(--line); }

/* ---------- banners and callouts ---------- */
.banner { position: sticky; top: var(--bar-h); z-index: 9; min-height: 2.75rem; display: flex; align-items: center; gap: var(--s3); padding: .625rem var(--gutter); background: #2A1D05; border-bottom: 1px solid rgba(255, 176, 32, .5); color: var(--amber); font-size: .875rem; animation: bannerIn var(--t-in) var(--e-out) both; }
.banner.bad { background: #2A0A0E; border-color: rgba(255, 77, 90, .5); color: #FF7A84; }
.banner b { color: var(--text); font-weight: 600; }
.banner .mono { color: var(--text-2); }
.callout { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s3) var(--s4); background: rgba(255, 176, 32, .07); border: 1px solid rgba(255, 176, 32, .35); border-left: 3px solid var(--amber); border-radius: var(--radius); color: var(--text-2); font-size: .875rem; }
.callout .icon { color: var(--amber); margin-top: 1px; }

/* ---------- empty states, skeletons, spinners ---------- */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s3); padding: var(--s7) var(--s5); text-align: center; color: var(--muted); border: 1px dashed var(--line-2); border-radius: 6px; }
.empty-mark { width: 3rem; height: .5rem; background: var(--accent); transform: skewX(-14deg); transform-origin: left; animation: wipe var(--t-stage) var(--e-whip) both; }
.empty h2 { margin: 0; font: italic 800 1.625rem var(--display); letter-spacing: .02em; text-transform: uppercase; color: var(--text); }
.empty p { margin: 0; max-width: 36rem; font-size: .9375rem; line-height: 1.5; }
.skeleton { position: relative; overflow: hidden; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.skeleton::after { content: ''; position: absolute; top: 0; bottom: 0; left: 0; width: 30%; background: linear-gradient(90deg, transparent, rgba(54, 214, 255, .06), transparent); border-right: 2px solid rgba(54, 214, 255, .25); animation: skSweep 1.4s var(--e-whip) 6; }
.spin { width: .875rem; height: .875rem; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 700ms linear infinite; display: inline-block; }

/* ---------- nudge group: −1s −0.1 · +0.1 +1s ---------- */
/* Two halves with a gap (mis-click guard); outer ends slanted as a < > hint. */
.nudge-group { display: grid; grid-template-columns: 1.3fr 1fr .75rem 1fr 1.3fr; height: 2.75rem; }
.nudge-half { display: contents; }
.nudge-half.plus .nudge:first-child { grid-column: 4; }
.nudge { --sf: var(--panel-2); --sb: var(--line-2); position: relative; isolation: isolate; height: 100%; min-width: 0; padding: 0 6px; background: var(--sf); border: 1px solid var(--sb); color: var(--text-2); font: 600 .8125rem var(--mono); cursor: pointer; transition: background-color var(--t-press), border-color var(--t-press), transform var(--t-press); }
.nudge.big { color: var(--text); font-weight: 700; font-size: .9375rem; }
.nudge-half.minus .nudge:first-child { clip-path: polygon(.5rem 0, 100% 0, 100% 100%, 0 100%); padding-left: .75rem; border-radius: 0; }
/* Neighbours overlap by 1px instead of dropping a border, so each button keeps its whole outline;
   the hovered or focused one comes to the front and its outline lights up on every side. */
.nudge-half.minus .nudge:last-child { margin-left: -1px; border-radius: 0 3px 3px 0; }
.nudge:hover, .nudge:focus-visible { z-index: 1; }
.nudge-half.plus .nudge:first-child { border-radius: 3px 0 0 3px; }
.nudge-half.plus .nudge:last-child { clip-path: polygon(0 0, 100% 0, calc(100% - .5rem) 100%, 0 100%); padding-right: .75rem; margin-left: -1px; border-radius: 0; }
.nudge-half.minus .nudge:hover { --sf: var(--hover); --sb: #5B6478; color: var(--text); }
.nudge-half.plus .nudge:hover { --sf: #12262D; --sb: var(--accent); color: var(--text); }
/* Slanted outer ends keep their border on the diagonal: the button's background is the border
   colour clipped to the slanted shape, and ::before (same shape, 1px inside) is the fill. */
.nudge-half.minus .nudge:first-child, .nudge-half.plus .nudge:last-child { background: var(--sb); border-color: transparent; }
.nudge-half.minus .nudge:first-child::before, .nudge-half.plus .nudge:last-child::before { content: ''; position: absolute; inset: 0; z-index: -1; background: linear-gradient(var(--sf), var(--sf)), var(--under, var(--panel)); clip-path: inherit; transition: background-color var(--t-press); }
.nudge:active:not([aria-disabled="true"]) { transform: translateY(1px) scale(.97); }
.nudge[aria-disabled="true"] { opacity: .35; cursor: default; }
.nudge::after { content: ''; position: absolute; left: 12%; right: 12%; bottom: 3px; height: 2px; background: var(--accent); transform: scaleX(0); pointer-events: none; }
.nudge.hit::after { animation: hit 260ms var(--e-whip); }
.nudge-group.m { height: 2.25rem; }
.nudge-group.s { height: 2rem; }
.nudge-group.s .nudge { font-size: .75rem; }
/* While showing the running total of quick presses ("−2.0s"), the button reads in cyan. */
.nudge.sum { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: clip; }

/* ---------- odometer digits (setNum) ---------- */
.dg { display: inline-block; height: 1em; line-height: 1; overflow: clip; vertical-align: top; }
.dg > i { display: flex; flex-direction: column; font-style: normal; }
.dg b { font-weight: inherit; }
.dg.dg-up > i { animation: dgUp var(--t-in) var(--e-roll) both; }
.dg.dg-down > i { flex-direction: column-reverse; animation: dgDn var(--t-in) var(--e-roll) both; }
.pending-num { color: var(--text-2); }

/* ---------- the signal runner (fly) ---------- */
.sig-runner { position: fixed; inset: 0 auto auto 0; margin: 0; padding: 0; border: 0; width: 100px; height: 100px; background: var(--accent); transform-origin: 0 0; pointer-events: none; opacity: 0; overflow: visible; }
.sig-runner:popover-open { display: block; }

/* ---------- keyboard help ---------- */
.keys-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s1) var(--s6); }
.keys-grid h3 { grid-column: 1 / -1; margin: var(--s3) 0 var(--s1); font: italic 800 1rem var(--display); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.keys-grid div { display: flex; justify-content: space-between; gap: var(--s3); padding: 6px 0; border-bottom: 1px solid var(--line); font-size: .875rem; }

/* ---------- avatars (ui.js avatarHtml): the picture over the initials, round ---------- */
.avatar { position: relative; flex-shrink: 0; display: inline-grid; place-items: center; width: 2rem; height: 2rem; border-radius: 50%; overflow: hidden; background: var(--line); border: 1px solid var(--line-2); color: var(--text-2); font: 600 .75rem/1 var(--body); letter-spacing: .02em; }
.avatar-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.avatar-i { display: grid; place-items: center; }
.avatar.pending { background: none; border-style: dashed; color: var(--muted); }

/* ---------- preview stills (idle preview boxes; stills.js) ---------- */
/* Dimmed so it reads as "not playing" and the play button stays the brightest thing in the box. */
.pv-still { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; opacity: 0; transition: opacity 300ms var(--e-out); pointer-events: none; }
.has-still > .pv-still { opacity: .6; }
.has-still > .pv-mark, .has-still > .mv-ghost { display: none; }
.fc-well.playing > .pv-still, .mv-tile.playing .pv-still { display: none; }
