/* MERGE live room */
:root { --side: 384px; --top: 58px; }

body { height: 100vh; display: grid; grid-template-rows: var(--top) minmax(0, 1fr); overflow: hidden; }
button { font: inherit; color: inherit; }
.dim { color: var(--dim); }
.right { margin-left: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

.btn-sm { padding: 8px 12px; font-size: 13px; border-radius: 6px; }
.btn-ghost { background: transparent; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 22px; padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--ink-2); min-width: 0; }
.logo { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; }
.logo svg { fill: var(--signal); stroke: var(--signal); stroke-width: 2; }
.logo svg path { fill: none; }
.logo .display-x { font-size: 20px; }
.session { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font: 800 12px var(--font-mono); color: var(--signal-ink); background: conic-gradient(from 210deg, var(--signal), var(--warn), var(--add), var(--signal)); box-shadow: 0 0 0 2px var(--ink-2), 0 0 0 3px var(--del); flex: none; }
.session-meta { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.session-title { font-size: 22px; }
.session-meta .mono { font-size: 12px; }
.live-tag { color: var(--del); }
.stats { display: flex; gap: 18px; font-size: 13px; white-space: nowrap; }
.stats b { font-weight: 700; color: var(--text); }
.top-actions { margin-left: auto; display: flex; gap: 8px; }
#view-toggle { text-decoration: none; }
body.host #view-toggle { border-color: var(--warn); color: var(--warn); }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: minmax(0, 1fr) var(--side); min-height: 0; }
.main { display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 12px; padding: 12px; min-width: 0; min-height: 0; }
.stage { display: grid; grid-template-columns: minmax(220px, 280px) minmax(0, 1fr); gap: 12px; min-height: 0; }
.stage-side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.panel-head { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 12px; min-width: 0; white-space: nowrap; }
.panel-head .mono { overflow: hidden; text-overflow: ellipsis; }
.panel-title { font: 700 13px var(--font-body); font-variation-settings: 'wdth' 100; word-spacing: .08em; }

/* cam */
.cam { position: relative; aspect-ratio: 4 / 3; border-radius: var(--r-2); overflow: hidden; border: 1px solid var(--line); background: #0d0d10; }
.cam canvas { width: 100%; height: 100%; display: block; }
.cam-tag { position: absolute; left: 8px; bottom: 8px; font-size: 11px; padding: 3px 7px; background: rgba(11,11,12,.75); border-left: 2px solid var(--signal); }
.cam-rec { position: absolute; right: 8px; top: 8px; font-size: 10px; color: var(--dim); display: flex; align-items: center; gap: 5px; }
.cam-rec i { width: 6px; height: 6px; border-radius: 50%; background: var(--del); }

/* round */
.round { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 12px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: var(--r-2); background: var(--panel); }
.ring { position: relative; width: 104px; height: 104px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 7; }
.ring-bg { stroke: var(--line); }
.ring-fg { stroke: var(--signal); stroke-linecap: round; stroke-dasharray: 276.46; stroke-dashoffset: 0; transition: stroke .3s; }
.ring-inner { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; line-height: 1; }
.phase { font-size: 22px; }
#clock { font-size: 13px; color: var(--dim); margin-top: 4px; }
body[data-phase="VOTE"] .ring-fg { stroke: var(--warn); }
body[data-phase="BUILD"] .ring-fg { stroke: var(--info); }
body[data-phase="MERGE"] .ring-fg { stroke: var(--add); }
.steps { display: flex; gap: 4px; font-size: 10px; }
.steps span { flex: 1; text-align: center; padding: 3px 0; border-radius: 3px; background: var(--panel-2); color: var(--mute); }
.steps span.on { background: var(--text); color: var(--ink); }
.steps span.done { color: var(--dim); }
.lead { margin: 8px 0; font-size: 13px; line-height: 1.35; min-height: 2.7em; }
.lead b { color: var(--text); }
.lead .mono { color: var(--dim); font-size: 12px; }

/* build */
.build { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r-2); background: var(--panel); overflow: hidden; min-width: 0; }
.build-frame { position: relative; aspect-ratio: 16 / 9; background: #050607; }
.build-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; }
#confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.merged { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; opacity: 0; }
.merged.show { animation: merged 2.2s var(--ease) forwards; }
.merged-word { font-size: clamp(48px, 9vw, 120px); color: var(--add); text-shadow: 0 0 40px rgba(92,242,180,.45); }
.merged-meta { margin-top: 6px; font-size: 14px; color: var(--text); background: rgba(11,11,12,.8); padding: 6px 12px; justify-self: center; border-radius: 4px; }
@keyframes merged {
  0% { opacity: 0; transform: scale(1.25); }
  12% { opacity: 1; transform: scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: scale(.98); }
}
.build-frame.flash::after { content: ''; position: absolute; inset: 0; background: var(--add); opacity: 0; animation: flash .5s ease-out; pointer-events: none; }
@keyframes flash { 0% { opacity: .55; } 100% { opacity: 0; } }

/* diff */
.diff { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r-2); background: var(--ink-2); min-height: 180px; overflow: hidden; }
.diff .file { color: var(--info); }
#diff-stat .a { color: var(--add); } #diff-stat .d { color: var(--del); }
#diff-status.working { color: var(--info); }
#diff-status.working::before { content: ''; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: var(--info); animation: tally 1s infinite; }
.diff-body { flex: 1; overflow: auto; padding: 8px 0; font-size: 13px; line-height: 1.6; font-variant-ligatures: none; }
.dl { display: grid; grid-template-columns: 40px 40px 18px minmax(0, 1fr); white-space: pre; padding-right: 12px; }
.dl .n { color: var(--mute); text-align: right; padding-right: 10px; user-select: none; }
.dl .g { color: var(--mute); }
.dl.add { background: rgba(92,242,180,.07); }
.dl.add .g, .dl.add .c { color: var(--add); }
.dl.del { background: rgba(255,59,92,.07); }
.dl.del .g, .dl.del .c { color: var(--del); }
.dl.del .c { text-decoration: line-through; text-decoration-color: rgba(255,59,92,.35); }
.dl.ctx .c { color: var(--dim); }
.dl .c { overflow: hidden; text-overflow: ellipsis; }
.caret { display: inline-block; width: 8px; height: 1.1em; vertical-align: -2px; background: var(--info); animation: tally .8s steps(1) infinite; }
.diff-empty { padding: 18px; color: var(--mute); font-size: 13px; }

/* ---------- side ---------- */
.side { display: flex; flex-direction: column; border-left: 1px solid var(--line); background: var(--ink-2); min-height: 0; min-width: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab { flex: 1; padding: 13px 8px; background: none; border: 0; border-bottom: 2px solid transparent; font-weight: 600; font-size: 14px; color: var(--dim); cursor: pointer; }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--signal); }
.tab .count { font-size: 11px; color: var(--mute); }
.host-only { display: none; }
body.host .tab.host-only { display: block; }
body.host .tabpanel.host-only:not([hidden]) { display: flex; }
.tabpanel { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.tabpanel[hidden] { display: none; }

.submit { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.submit input { flex: 1; min-width: 0; background: var(--panel); border: 1px solid var(--line-2); border-radius: 6px; color: var(--text); padding: 9px 11px; font: 14px var(--font-body); }
.submit input:focus { outline: none; border-color: var(--signal); }
.points { padding: 8px 12px; font-size: 11px; display: flex; gap: 8px; border-bottom: 1px solid var(--line); }
.points b { color: var(--warn); }

.queue { list-style: none; margin: 0; padding: 6px 0; overflow: auto; flex: 1; }
.qi { position: relative; padding: 10px 12px 10px 14px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; }
.qi.top::before { content: ''; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 2px; background: var(--warn); }
.qi.lead-item::before { background: var(--signal); }
.qi.mine { background: rgba(255,90,31,.06); }
.qi.winner { background: rgba(92,242,180,.08); }
.qi.winner::before { background: var(--add); }
.qi.out { opacity: .38; }
.qi .txt { font-size: 14px; line-height: 1.3; overflow-wrap: anywhere; }
.qi .by { font: 11px var(--font-mono); color: var(--dim); display: flex; gap: 8px; flex-wrap: wrap; }
.qi .by .sim { color: var(--mute); }
.qi .by .note { color: var(--warn); }
.qi .acts { grid-row: span 2; display: flex; gap: 6px; align-items: center; }
.qi .bar { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: var(--panel-2); overflow: hidden; }
.qi .bar i { display: block; height: 100%; background: var(--dim); transition: width .4s var(--ease); }
.qi.top .bar i { background: var(--warn); }
.qi.lead-item .bar i { background: var(--signal); }
.qi.winner .bar i { background: var(--add); }
.vote, .boost { border: 1px solid var(--line-2); background: var(--panel); border-radius: 6px; padding: 5px 8px; font: 600 12px var(--font-mono); cursor: pointer; min-width: 52px; }
.vote[aria-pressed="true"] { border-color: var(--warn); color: var(--warn); }
.boost { color: var(--warn); min-width: 0; }
.vote:disabled, .boost:disabled { opacity: .4; cursor: default; }

.chat { list-style: none; margin: 0; padding: 8px 12px; overflow: auto; flex: 1; font-size: 13.5px; line-height: 1.45; }
.chat li { padding: 2px 0; overflow-wrap: anywhere; }
.chat .h { font-weight: 700; }
.chat .sys { color: var(--dim); font: 12px var(--font-mono); padding: 6px 0; }
.chat .sys b { color: var(--add); }
.chat-form, #chat-form { border-top: 1px solid var(--line); border-bottom: 0; }

.commits { list-style: none; margin: 0; padding: 4px 0; overflow: auto; flex: 1; font-size: 12px; }
.commits li { display: grid; grid-template-columns: 14px minmax(0, 1fr); gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.commits .dot { width: 9px; height: 9px; margin-top: 4px; border-radius: 50%; border: 2px solid var(--add); }
.commits .revert .dot { border-color: var(--del); }
.commits .seed .dot { border-color: var(--dim); }
.commits .msg { color: var(--text); font-family: var(--font-body); font-size: 13.5px; line-height: 1.3; }
.commits .meta { color: var(--dim); margin-top: 3px; display: flex; flex-wrap: wrap; gap: 8px; }
.commits .hash { color: var(--warn); }
.commits .new { animation: newc 1.6s ease-out; }
@keyframes newc { from { background: rgba(92,242,180,.16); } to { background: transparent; } }

/* host dashboard */
.host-dash { overflow: auto; flex: 1; padding: 4px 0; }
.host-dash section { padding: 12px; border-bottom: 1px solid var(--line); }
.host-dash h3 { margin: 0 0 10px; font-size: 13px; font-weight: 700; color: var(--warn); }
.field { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 13px; margin-bottom: 8px; }
.field select, .field input { background: var(--panel); border: 1px solid var(--line-2); color: var(--text); border-radius: 6px; padding: 6px 8px; font: 13px var(--font-body); width: 170px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; margin: 6px 0; color: var(--dim); }
.mod-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.mod-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; font-size: 13px; }
.mod-list .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mod-list .t small { color: var(--dim); font: 11px var(--font-mono); margin-left: 6px; }
.mod-list button { border: 1px solid var(--line-2); background: var(--panel); border-radius: 5px; padding: 3px 7px; font-size: 11px; cursor: pointer; }
.mod-list .hidden-item .t { opacity: .4; text-decoration: line-through; }
.locks { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.locks li { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; }
.locks button { border: 1px solid var(--line-2); background: var(--panel); border-radius: 5px; padding: 3px 8px; font: 11px var(--font-mono); cursor: pointer; min-width: 70px; }
.locks button[aria-pressed="true"] { border-color: var(--del); color: var(--del); }

/* drawer + modal */
.drawer, .modal { position: fixed; inset: 0; z-index: 30; display: grid; background: rgba(5,5,6,.6); }
.drawer[hidden], .modal[hidden] { display: none; }
.drawer { align-items: end; justify-items: start; padding: 12px; }
.drawer-card { width: min(560px, 100%); background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--r-3); padding: 16px; box-shadow: 0 30px 80px rgba(0,0,0,.6); animation: up .25s var(--ease); }
@keyframes up { from { transform: translateY(20px); opacity: 0; } }
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.icon-btn { background: none; border: 0; font-size: 24px; line-height: 1; cursor: pointer; color: var(--dim); }
.drawer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ctl { text-align: left; background: var(--ink-2); border: 1px solid var(--line); border-radius: var(--r-2); padding: 12px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; }
.ctl:hover { border-color: var(--line-2); }
.ctl b { font-size: 15px; }
.ctl span { font-size: 12.5px; color: var(--dim); line-height: 1.35; }
#veto-btn b { color: var(--del); } #revert-btn b { color: var(--warn); } #fork-btn-2 b { color: var(--signal); }
.ctl-static { cursor: default; }
.seg { display: flex; gap: 4px; margin-top: 6px; }
.seg button { flex: 1; padding: 7px 0; border-radius: 5px; border: 1px solid var(--line-2); background: var(--panel); font: 12px var(--font-mono); cursor: pointer; }
.seg button[aria-checked="true"] { background: var(--text); color: var(--ink); border-color: var(--text); }

.modal { place-items: center; padding: 16px; }
.modal-card { width: min(520px, 100%); background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--r-3); padding: 26px; animation: up .25s var(--ease); }
.fork-tally { color: var(--signal); }
.fork-tally::before { background: var(--signal); box-shadow: 0 0 12px var(--signal); }
.modal-card h2 { font-size: 38px; margin: 12px 0 10px; }
.modal-card h2 .mono { color: var(--warn); font-size: .7em; text-transform: none; }
.modal-card p { color: var(--dim); margin: 0 0 16px; }
.fork-row { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 10px 12px; background: var(--ink-2); border: 1px solid var(--line); border-radius: 6px; font-size: 13px; margin-bottom: 18px; }
.modal-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 30px); opacity: 0; z-index: 40; background: var(--text); color: var(--ink); padding: 10px 16px; border-radius: 6px; font-size: 13px; transition: .25s var(--ease); pointer-events: none; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- responsive ---------- */
@media (max-width: 1240px) {
  :root { --side: 340px; }
  .stage { grid-template-columns: 220px minmax(0, 1fr); }
  .round { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .steps { justify-content: center; }
}

@media (max-width: 900px) {
  body { height: auto; overflow: auto; display: block; }
  .topbar { position: sticky; top: 0; z-index: 20; gap: 10px; height: var(--top); padding: 0 10px; }
  .hide-sm { display: none !important; }
  .logo .display-x { display: none; }
  .session-title { font-size: 19px; }
  .stats { font-size: 12px; }
  .app { display: block; }
  .main { display: flex; flex-direction: column; padding: 10px; gap: 10px; }
  .stage { display: flex; flex-direction: column; gap: 10px; }
  .build { order: -1; }
  .stage-side { flex-direction: row; gap: 10px; }
  .cam { width: 42%; flex: none; aspect-ratio: auto; min-height: 150px; }
  .round { flex: 1; grid-template-columns: 1fr; padding: 10px; gap: 8px; }
  .ring { width: 86px; height: 86px; }
  .phase { font-size: 18px; }
  .lead { min-height: 0; font-size: 12.5px; margin: 6px 0; }
  .diff { height: auto; min-height: 150px; max-height: 340px; flex: none; }
  .diff-body { flex: none; }
  .dl { grid-template-columns: 30px 30px 14px minmax(0, 1fr); }
  .diff-body { font-size: 12px; }
  #diff-status { display: none; }
  .build-frame { aspect-ratio: 4 / 3; }
  .side { border-left: 0; border-top: 1px solid var(--line); height: 560px; }
  .drawer { justify-items: stretch; }
  .drawer-grid { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .top-actions #speed-btn { display: none; }
  .stats span:first-child .dim { display: none; }
  .modal-card h2 { font-size: 30px; }
}
