/* =============================================================================
   Bokeh Sim - app shell. Dark, compact, phone-first; two columns on desktop.
   ============================================================================= */
:root {
  --bg: #0e0f12;
  --panel: #16181d;
  --panel-2: #1d2027;
  --line: #2a2e37;
  --text: #e9ebf0;
  --muted: #9aa1ad;
  --dim: #6b7280;
  --accent: #6fb4ff;
  --a: #6fb4ff;      /* frame A */
  --b: #ffb35c;      /* frame B */
  --warn: #ffcf5c;
  --bad: #ff6b6b;
  --ok: #67d391;
  --radius: 10px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

#app {
  height: 100dvh;
  display: flex; flex-direction: column;
  padding: var(--safe-t) var(--safe-r) 0 var(--safe-l);
}
#top {
  flex: none; display: flex; align-items: center; justify-content: space-between;
  height: 44px; padding: 0 12px;
}
#top h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: 0.2px; }
.top-actions { display: flex; gap: 8px; }

#frames {
  flex: none; position: relative; height: var(--frames-h, 56vh);
  background: #08090b; touch-action: pan-y;
}
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.frame {
  position: absolute; pointer-events: auto; border-radius: 4px;
  outline: 1px solid rgba(255, 255, 255, 0.06);
}
.frame.active { outline: 2px solid var(--slot-colour); outline-offset: 1px; }
.frame[data-slot="0"] { --slot-colour: var(--a); }
.frame[data-slot="1"] { --slot-colour: var(--b); }
.frame .tag {
  position: absolute; left: 6px; top: 6px; max-width: calc(100% - 12px);
  padding: 2px 7px; border-radius: 6px; font-size: 12px; font-weight: 600;
  background: rgba(8, 9, 11, 0.72); color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-left: 3px solid var(--slot-colour);
}
.frame .ball {
  position: absolute; right: 6px; bottom: 6px; padding: 2px 7px; border-radius: 6px;
  font-size: 12px; background: rgba(8, 9, 11, 0.72); font-variant-numeric: tabular-nums;
}
.frame .prog {
  position: absolute; left: 0; bottom: 0; height: 2px; width: 0; background: var(--slot-colour);
  opacity: 0.8; transition: opacity 0.4s;
}
.frame .prog.done { opacity: 0; }
.frame .warnflag {
  position: absolute; left: 6px; bottom: 6px; padding: 2px 7px; border-radius: 6px; font-size: 12px;
  background: rgba(60, 40, 0, 0.85); color: var(--warn); max-width: 60%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

#panel {
  flex: 1; min-height: 0; display: flex; flex-direction: column;
  background: var(--panel); border-top: 1px solid var(--line);
}
#tabs {
  flex: none; display: flex; gap: 2px; overflow-x: auto; padding: 6px 8px 0;
  scrollbar-width: none; border-bottom: 1px solid var(--line);
}
#tabs::-webkit-scrollbar { display: none; }
#tabs button {
  flex: none; border: 0; background: none; padding: 8px 11px 9px; color: var(--muted);
  border-bottom: 2px solid transparent; font-weight: 600; font-size: 14px;
}
#tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
#pane { flex: 1; overflow-y: auto; padding: 10px 12px calc(24px + var(--safe-b)); -webkit-overflow-scrolling: touch; }

/* ---- controls ---------------------------------------------------------------- */
.group { margin: 4px 0 14px; }
.group > h3 {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--dim);
  margin: 12px 0 6px; font-weight: 700;
}
.row { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.row > label { flex: none; width: 92px; color: var(--muted); font-size: 14px; }
.row > .grow { flex: 1; min-width: 0; }

.ctl { margin: 10px 0; }
.ctl .head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.ctl .head label { color: var(--muted); font-size: 14px; }
.ctl .head .hint { color: var(--dim); font-size: 12px; }
.ctl .body { display: flex; align-items: center; gap: 10px; margin-top: 2px; }
.ctl input[type="range"] { flex: 1; min-width: 0; }
.ctl input.num {
  flex: none; width: 96px; text-align: right; padding: 6px 8px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--line); font-variant-numeric: tabular-nums;
}
.ctl input.num:focus { outline: none; border-color: var(--accent); }
.ctl input.num.bad { border-color: var(--bad); }

input[type="range"] {
  -webkit-appearance: none; appearance: none; height: 30px; background: transparent;
}
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--line); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%; margin-top: -9px;
  background: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line); }
input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: var(--text); border: 0; }

.seg { display: flex; background: var(--panel-2); border-radius: 9px; padding: 2px; gap: 2px; flex-wrap: wrap; }
.seg button {
  flex: 1; border: 0; background: none; padding: 7px 8px; border-radius: 7px; color: var(--muted);
  font-size: 14px; font-weight: 600; white-space: nowrap;
}
.seg button[aria-pressed="true"] { background: #2d323d; color: var(--text); }
.seg.slots button[aria-pressed="true"][data-v="0"] { box-shadow: inset 0 -2px 0 var(--a); }
.seg.slots button[aria-pressed="true"][data-v="1"] { box-shadow: inset 0 -2px 0 var(--b); }

select {
  width: 100%; padding: 8px 10px; border-radius: 8px; background: var(--panel-2);
  border: 1px solid var(--line); -webkit-appearance: none; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%;
  background-size: 5px 5px; background-repeat: no-repeat; padding-right: 28px;
}
.chip {
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 999px; padding: 5px 12px;
  font-size: 13px; font-weight: 600;
}
.btn {
  border: 0; background: #2d323d; border-radius: 9px; padding: 9px 14px; font-weight: 600;
}
.btn.primary { background: var(--accent); color: #06121f; }
.btn.danger { background: #3a1f22; color: #ffb4b4; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 10px 0; }
.toggle span { color: var(--muted); }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }

.cards { display: grid; grid-template-columns: 1fr; gap: 8px; }
.card {
  text-align: left; border: 1px solid var(--line); background: var(--panel-2); border-radius: var(--radius);
  padding: 10px 12px;
}
.card b { display: block; font-size: 15px; }
.card small { color: var(--muted); font-size: 13px; }
.card[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }

.note { color: var(--muted); font-size: 13px; margin: 6px 0; }
.warn { color: var(--warn); font-size: 13px; margin: 6px 0; }
.warn::before { content: "\26A0  "; }

/* results table */
table.res { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; }
table.res th, table.res td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: top; }
table.res th:first-child, table.res td:first-child { text-align: left; color: var(--muted); font-weight: 500; }
table.res thead th { font-size: 13px; }
table.res thead th.a { color: var(--a); }
table.res thead th.b { color: var(--b); }
table.res td.big { font-size: 16px; font-weight: 650; }
.ratio { margin: 10px 0; padding: 10px 12px; border-radius: var(--radius); background: var(--panel-2); }
.ratio b { font-size: 18px; }

#plan { width: 100%; height: 240px; display: block; background: #0b0c0f; border-radius: var(--radius); border: 1px solid var(--line); }

#toast {
  position: fixed; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: #2b2f38; color: var(--text); padding: 9px 14px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; max-width: 90vw; z-index: 10;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 900px) {
  #app { display: grid; grid-template-columns: 1fr 400px; grid-template-rows: 44px 1fr; }
  #top { grid-column: 1 / 3; }
  #frames { height: auto; }
  #panel { border-top: 0; border-left: 1px solid var(--line); }
}
