/* Joins demo layout. Colours and controls come from ../shared/theme.css. */

html,
body { height: 100%; overflow: hidden; }

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 2;
}

.home {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  padding: 4px 8px 4px 2px;
  border-radius: 6px;
}
.home:hover { color: var(--ink); background: var(--panel-2); }

.title {
  margin: 0 6px 0 0;
  font-size: 20px;
  font-weight: 750;
  letter-spacing: -0.01em;
}

.group { display: flex; align-items: center; gap: 6px; }
.tools { display: flex; gap: 2px; margin-left: auto; }

.seg-algo { height: 36px; align-items: stretch; }
.seg-algo button { font-size: 14px; padding: 0 10px; }
.seg-algo button[data-v="nl"].on { color: var(--orange); }
.seg-algo button[data-v="inl"].on { color: var(--accent); }
.seg-algo button[data-v="hash"].on { color: var(--violet); }
.seg-algo button[data-v="merge"].on { color: var(--teal); }

/* ---------- Main area ---------- */

.main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  min-height: 0;
}
body.no-sidebar .main { grid-template-columns: minmax(0, 1fr) 0; }
body.no-sidebar .sidebar { display: none; }

.stage {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
}

.canvas-wrap {
  --watermark-bottom: 194px; /* sit above the scoreboard */
  position: relative;
  overflow: hidden;
  background: var(--bg);
  min-height: 300px;
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------- Caption (current step explanation) ---------- */

.caption {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 10px 14px 10px 16px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow);
  pointer-events: none;
  transition: border-color 0.25s;
}
.caption[data-status="success"] { border-left-color: var(--good); }
.caption[data-status="warn"] { border-left-color: var(--warn); }
.caption[data-status="error"] { border-left-color: var(--bad); }

.caption-text {
  flex: 1 1 420px;
  margin: 0;
  font-size: 17px;
  font-weight: 550;
  line-height: 1.4;
  min-height: 2.8em;
}

.rules { display: flex; flex-wrap: wrap; gap: 6px; }
.rules span {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.rules span b { color: var(--ink); }

.toast {
  position: absolute;
  left: 50%;
  bottom: 120px;
  max-width: min(520px, calc(100% - 32px));
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--panel);
  font-size: 14px;
  font-weight: 550;
  box-shadow: var(--shadow);
  transform: translate(-50%, 8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 5;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Scoreboard ---------- */

.board {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: grid;
  gap: 4px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow);
  transition: box-shadow 0.3s, border-color 0.3s;
}
.board.spot { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow); }

.lane {
  --lane: var(--orange);
  --lane-soft: var(--orange-soft);
  display: grid;
  grid-template-columns: minmax(172px, 1.1fr) 124px 160px 96px minmax(140px, 2fr);
  align-items: center;
  gap: 14px;
  padding: 4px 8px;
  border-radius: 9px;
  transition: background 0.2s, opacity 0.2s;
}
.lane[data-lane="inl"] { --lane: var(--accent); --lane-soft: var(--accent-soft); }
.lane[data-lane="hash"] { --lane: var(--violet); --lane-soft: var(--violet-soft); }
.lane[data-lane="merge"] { --lane: var(--teal); --lane-soft: var(--teal-soft); }
.lane.active { background: var(--lane-soft); }
.lane.empty { opacity: 0.55; }

.lane-name { display: flex; align-items: center; gap: 9px; min-width: 0; }
.lane-name b { display: block; font-size: 15px; color: var(--lane); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 10px; height: 10px; flex: none; border-radius: 50%; background: var(--lane); }
.lane.active .dot { animation: blink 0.9s infinite; }
@keyframes blink { 50% { opacity: 0.25; } }

.lane-num { display: flex; align-items: baseline; gap: 6px; min-width: 0; line-height: 1.15; }
.lane-num b { font-size: 20px; font-weight: 750; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lane-num span { font-size: 11.5px; font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lane-head { padding-top: 0; padding-bottom: 0; }
.lane-head span { font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.lane-total b { color: var(--lane); }

.lane-bar { display: flex; align-items: center; gap: 10px; min-width: 0; }
.lane-bar .track { position: relative; flex: 1; height: 14px; border-radius: 7px; background: var(--line); overflow: hidden; }
.lane-bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 7px; background: var(--lane); }
.lane-bar em {
  flex: none;
  font-style: normal;
  font-size: 13px;
  font-weight: 750;
  color: var(--good);
  white-space: nowrap;
}
.lane-bar em:empty { display: none; }

/* ---------- Player ---------- */

.player {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 20px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.transport { display: flex; align-items: center; gap: 6px; }
.transport .btn { width: 40px; height: 40px; }
.transport .play { width: 48px; height: 48px; border-radius: 50%; }
.transport .play .icon { width: 22px; height: 22px; }

.progress { flex: 1 1 220px; min-width: 180px; }
.progress-label {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 14px;
}
.progress-label span { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.progress-label .queue { color: var(--accent); font-weight: 600; }
.progress-bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
#progressFill { height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width 0.3s; }

.speed { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; }
.speed input { width: 110px; accent-color: var(--accent); }
.speed output { width: 40px; font-variant-numeric: tabular-nums; color: var(--ink-2); }

/* ---------- Sidebar ---------- */

.sidebar {
  min-height: 0;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: var(--panel);
}

.panel { padding: 14px 16px 16px; border-bottom: 1px solid var(--line); }
.panel h2 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.panel h2 span { text-transform: none; letter-spacing: 0; color: var(--ink); margin-left: 4px; }

.step-log {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 30vh;
  overflow-y: auto;
  counter-reset: step;
}
.step-log li {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 13.5px;
  line-height: 1.4;
  color: var(--ink-2);
  cursor: pointer;
}
.step-log li::before {
  counter-increment: step;
  content: counter(step);
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.step-log li:hover { background: var(--panel-2); }
.step-log li.current { background: var(--accent-soft); color: var(--ink); }
.step-log li.current::before { color: var(--accent); }
.step-log li.s-success::before { color: var(--good); }
.step-log li.s-warn::before { color: var(--warn); }
.step-log li.k-read::before { color: var(--warn); }

.pseudo {
  margin: 0;
  padding: 8px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  font: 12.5px/1.6 var(--mono);
}
.pseudo .ln {
  padding: 1px 10px 1px calc(9px + var(--indent, 0ch) + 2ch);
  text-indent: -2ch;
  border-left: 3px solid transparent;
  color: var(--ink-2);
}
.pseudo .ln.on { background: var(--accent-soft); border-left-color: var(--accent); color: var(--ink); font-weight: 650; }
.pseudo .ln .cm { color: var(--muted); font-weight: 400; }
.pseudo .empty { margin: 0; padding: 4px 12px; font-family: var(--font); font-size: 13px; color: var(--muted); }

.note { margin: 0 0 10px; font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.note:last-child { margin: 10px 0 0; }
.note b { color: var(--ink-2); }

.scale-label { display: flex; justify-content: space-between; align-items: baseline; font-size: 13.5px; font-weight: 600; }
.scale-label output { font-size: 15px; font-weight: 750; color: var(--accent); }
.scale-range { width: 100%; margin: 6px 0 10px; accent-color: var(--accent); }

.scale { display: grid; gap: 8px; }
.sc-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: 13px; }
.sc-row .sc-name { font-weight: 700; }
.sc-row .sc-val { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.sc-row .sc-val b { color: var(--ink); }
.sc-row .sc-bar { grid-column: 1 / -1; height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; }
.sc-row .sc-bar i { display: block; height: 100%; min-width: 3px; border-radius: 5px; }
.sc-nl .sc-name { color: var(--orange); }
.sc-nl .sc-bar i { background: var(--orange); }
.sc-inl .sc-name { color: var(--accent); }
.sc-inl .sc-bar i { background: var(--accent); }
.sc-hash .sc-name { color: var(--violet); }
.sc-hash .sc-bar i { background: var(--violet); }
.sc-merge .sc-name,
.sc-sorted .sc-name { color: var(--teal); }
.sc-merge .sc-bar i,
.sc-sorted .sc-bar i { background: var(--teal); }
.sc-sorted .sc-bar i { opacity: 0.55; }
.scale-range + .scale-label { margin-top: 2px; }
.scale-verdict { margin: 10px 0 0; font-size: 14px; font-weight: 700; color: var(--good); }
.scale-verdict.warn { color: var(--warn); }

.setting { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin-top: 12px; }
.setting:first-of-type { margin-top: 0; }
.setting-label { font-size: 13.5px; font-weight: 600; }
.setting-label small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.setting .switch { font-size: 13.5px; }

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px 10px;
  font-size: 12.5px;
  color: var(--ink-2);
}
.legend li { display: flex; align-items: center; gap: 7px; }
.sw { width: 20px; height: 16px; border-radius: 4px; flex: none; border: 1.5px solid var(--line-strong); background: var(--panel); }
.sw-key { background: var(--accent-soft); border-color: var(--accent-soft); }
.sw-cur { background: var(--warn-soft); border: 2.5px solid var(--warn); }
.sw-match { background: var(--good); border-color: var(--good); }
.sw-nomatch { background: var(--line); border-color: var(--line); }
.sw-untouched { border: 1.5px dashed var(--line-strong); }
.sw-dropped { background: var(--panel-2); opacity: 0.5; }
.sw-bucket { background: var(--violet-soft); border: 2.5px solid var(--violet); }
.sw-result { background: var(--good-soft); }
.sw-ptr { border: 2.5px dashed var(--accent); background: transparent; }

/* ---------- Cheat sheet ---------- */

.cheat { margin: 0; display: grid; gap: 10px; }
.cheat div { padding-left: 10px; border-left: 3px solid var(--algo); }
.cheat dt { font-size: 13.5px; font-weight: 750; color: var(--algo); }
.cheat dd { margin: 2px 0 0; font-size: 12.5px; line-height: 1.45; color: var(--ink-2); }
.ch-nl { --algo: var(--orange); }
.ch-inl { --algo: var(--accent); }
.ch-hash { --algo: var(--violet); }
.ch-merge { --algo: var(--teal); }

/* ---------- Help modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 14, 22, 0.45);
}
.modal-card {
  position: relative;
  width: min(900px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 24px 28px;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.modal-card h2 { margin: 0 0 12px; font-size: 20px; }
.modal-card h3 { margin: 16px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.modal-card ul { margin: 0; padding-left: 18px; }
.modal-card li { margin: 4px 0; font-size: 14px; }
.modal-card code { font-family: var(--mono); font-size: 13px; background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.modal-close { position: absolute; top: 14px; right: 14px; }
.help-grid { display: grid; grid-template-columns: 1.15fr 1fr; gap: 0 32px; }
.modal-card table.algos { width: 100%; border-collapse: collapse; margin: 6px 0 0; font-size: 13.5px; }
.algos th, .algos td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.algos th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.algos td:first-child { font-weight: 750; white-space: nowrap; }
.credit { margin: 20px 0 0; padding-top: 14px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.credit b { color: var(--ink-2); }
.keys { border-collapse: collapse; font-size: 14px; }
.keys td { padding: 4px 12px 4px 0; }
.keys td:first-child { white-space: nowrap; }

/* ---------- Short screens (projectors) ---------- */

/* Keep the caption and the three-lane scoreboard compact so the scene stays large. */
@media (max-height: 820px) and (min-width: 861px) {
  .canvas-wrap { --watermark-bottom: 150px; }
  .caption { top: 8px; left: 8px; right: 8px; padding: 7px 12px 7px 14px; }
  .caption-text { font-size: 15.5px; line-height: 1.35; min-height: 2.7em; }
  .rules { display: none; }
  .board { left: 8px; right: 8px; bottom: 8px; padding: 5px 10px; gap: 1px; }
  .lane { padding: 2px 8px; }
  .lane-name b { font-size: 14px; }
    .lane-num b { font-size: 17px; line-height: 1.1; }
  .lane-num span { font-size: 10.5px; }
  .lane-bar .track { height: 10px; }
}

/* ---------- Smaller screens ---------- */

@media (max-width: 1240px) {
  .lane { grid-template-columns: minmax(172px, 1fr) 124px 150px 92px minmax(100px, 1.4fr); gap: 10px; }
}

@media (max-width: 1100px) {
  .main { grid-template-columns: minmax(0, 1fr) 300px; }
}

@media (max-width: 860px) {
  html, body { overflow: auto; }
  .app { height: auto; min-height: 100vh; }
  .main { grid-template-columns: 1fr; }
  body.no-sidebar .main { grid-template-columns: 1fr; }
  .canvas-wrap { height: 82vh; }
  .sidebar { border-left: 0; border-top: 1px solid var(--line); }
  .help-grid { grid-template-columns: 1fr; }
  .caption-text { font-size: 15px; flex-basis: 100%; }
  .group { flex-wrap: wrap; }
  .canvas-wrap { --watermark-bottom: 218px; }
  .lane { grid-template-columns: minmax(0, 1fr) 112px 84px; gap: 2px 12px; padding: 2px 6px; }
    .lane-num:nth-child(3),
  .lane-head span:nth-child(3),
  .lane-head span:nth-child(5) { display: none; }
  .lane-head span { font-size: 10px; letter-spacing: 0; }
  .lane-bar { grid-column: 1 / -1; }
  .lane-bar .track { height: 8px; }
  .lane-num b { font-size: 16px; }
  .lane-num span { font-size: 10.5px; }
}
