:root {
  --bg: #050b12;
  --panel: rgba(9, 20, 32, 0.86);
  --panel2: rgba(6, 14, 24, 0.92);
  --line: #1d3956;
  --line2: #15304a;
  --text: #d8e8f8;
  --muted: #89a6bd;
  --cyan: #46d9ff;
  --blue: #2478ff;
  --yellow: #ffd21f;
  --danger: #ff5c7a;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background:
    radial-gradient(circle at 35% 20%, rgba(0, 102, 255, 0.14), transparent 34%),
    radial-gradient(circle at 82% 15%, rgba(173, 0, 255, 0.10), transparent 28%),
    linear-gradient(180deg, #08111d 0%, #03070c 100%);
}
.appShell {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: 86px 1fr;
  gap: 10px;
  padding: 14px;
}
.topBar {
  display: grid;
  grid-template-columns: 360px 1fr;
  align-items: center;
  gap: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(12, 26, 43, 0.92), rgba(8, 17, 29, 0.92));
  box-shadow: 0 0 24px rgba(0, 154, 255, 0.08), inset 0 0 0 1px rgba(255,255,255,0.03);
  z-index: 20;
}
.brand { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; white-space: nowrap; }
.brand span { color: var(--cyan); }
.topControls { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 8px; }
.inlineLabel { color: var(--muted); font-size: 13px; }
select, button, input[type="file"]::file-selector-button, .fileButton {
  background: #0d1b2c;
  color: var(--text);
  border: 1px solid #294563;
  border-radius: 7px;
  padding: 8px 11px;
  font-size: 13px;
  min-height: 36px;
}
select { min-width: 180px; }
.wideSelect { min-width: 270px; }
button { cursor: pointer; transition: 0.16s ease; }
button:hover, .fileButton:hover { border-color: var(--cyan); box-shadow: 0 0 16px rgba(70,217,255,0.22); }
button.primary { background: linear-gradient(180deg, #0966db, #064da8); border-color: #3b93ff; color: white; }
.fileButton { position: relative; display: inline-flex; align-items: center; gap: 8px; overflow: hidden; }
.fileButton input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-size: 13px; }
.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 320px minmax(500px, 1fr) 300px;
  grid-template-rows: minmax(360px, 1fr);
  gap: 12px;
}
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel), var(--panel2));
  box-shadow: 0 0 22px rgba(0, 148, 255, 0.08), inset 0 0 0 1px rgba(255,255,255,0.025);
}
.leftPanel, .rightPanel, .centerPanel { min-height: 0; }
.leftPanel {
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 12px;
  overflow: auto;
}
.panelTitle, .controlTitle {
  color: #79dcff;
  font-weight: 800;
  text-transform: uppercase;
  font-size: 13px;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}
#qasmInput {
  flex: 1 1 260px;
  min-height: 250px;
  width: 100%;
  resize: none;
  padding: 14px;
  color: #dff5ff;
  background: #06101d;
  border: 1px solid #263d59;
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
  outline: none;
}
#qasmInput:focus { border-color: var(--cyan); box-shadow: 0 0 0 2px rgba(70, 217, 255, 0.10); }
.statusLine { color: #9ad8a7; font-size: 12px; min-height: 18px; margin-top: 8px; }
#errorBox {
  display: none;
  max-height: 120px;
  overflow: auto;
  padding: 10px;
  white-space: pre-wrap;
  color: #ffc1cf;
  background: rgba(80, 8, 20, 0.75);
  border: 1px solid rgba(255, 92, 122, 0.65);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
}
.controlCard {
  padding: 12px;
  border: 1px solid #1c344d;
  border-radius: 10px;
  background: rgba(2, 10, 18, 0.45);
}
.controlCard label {
  display: grid;
  grid-template-columns: 96px 1fr;
  align-items: center;
  gap: 8px;
  margin: 10px 0;
  color: var(--text);
  font-size: 13px;
}
.controlCard .check { display: flex; grid-template-columns: none; }
.helpCard p { color: var(--muted); font-size: 12px; line-height: 1.35; margin: 8px 0; }
input[type="range"] { accent-color: var(--blue); width: 100%; }
.centerPanel { display: grid; grid-template-rows: minmax(380px, 1fr) 300px; gap: 12px; min-width: 0; }
.renderCard { position: relative; overflow: hidden; min-height: 0; }
.renderCard::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 52% 44%, rgba(0, 190, 255, 0.08), transparent 36%);
  pointer-events: none;
  z-index: 1;
}
.renderHeader {
  position: absolute;
  left: 22px;
  top: 18px;
  right: 22px;
  z-index: 5;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  pointer-events: none;
}
.renderTitle { color: #47d9ff; font-size: 18px; font-weight: 800; text-transform: uppercase; }
.renderSubtitle { margin-top: 6px; color: #e8f6ff; font-size: 14px; }
#scene { position: absolute; inset: 0; z-index: 0; }
#scene canvas { display: block; width: 100% !important; height: 100% !important; }
.miniLegend { min-width: 210px; display: grid; gap: 5px; color: var(--muted); font-size: 11px; }
.phaseBar { height: 8px; border-radius: 999px; background: linear-gradient(90deg, #2a00ff, #00d5ff, #00ff75, #ffe600, #ff2b00, #ff007a); box-shadow: 0 0 12px rgba(255, 0, 130, 0.2); }
.probBar { height: 7px; margin-top: 10px; border-radius: 999px; background: linear-gradient(90deg, #041b2d, #0b8dc6, #ffffff); }
.yellowLine { height: 3px; margin-top: 10px; background: var(--yellow); box-shadow: 0 0 8px var(--yellow); }
.readOverlay {
  position: absolute;
  right: 18px;
  bottom: 18px;
  width: 250px;
  z-index: 5;
  padding: 13px 14px;
  line-height: 1.45;
  font-size: 12px;
  color: #d7e9f7;
  border: 1px solid #21415e;
  border-radius: 10px;
  background: rgba(5, 13, 22, 0.74);
  backdrop-filter: blur(6px);
}
.tracePanel { min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.stepPanelHeader {
  height: 44px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  color: #7cddff;
  background: rgba(8, 22, 36, 0.9);
  font-size: 13px;
}
#stepSummary { color: var(--muted); }
#stepTableWrap { flex: 1; min-height: 0; overflow: auto; }
#stepTable { min-width: 1280px; width: 100%; border-collapse: collapse; font-size: 12px; }
#stepTable th, #stepTable td {
  padding: 10px 12px;
  border-right: 1px solid #13263c;
  border-bottom: 1px solid #172b43;
  vertical-align: top;
  text-align: left;
}
#stepTable th {
  position: sticky;
  top: 0;
  z-index: 4;
  color: #8cdbff;
  background: #0d1b2c;
  font-weight: 800;
}
#stepTable tr:hover td { background: rgba(27, 72, 112, 0.28); }
#stepTable th:nth-child(1), #stepTable td:nth-child(1) { width: 56px; }
#stepTable th:nth-child(2), #stepTable td:nth-child(2) { width: 230px; }
#stepTable th:nth-child(3), #stepTable td:nth-child(3) { width: 90px; }
#stepTable th:nth-child(4), #stepTable td:nth-child(4) { width: 170px; }
#stepTable th:nth-child(5), #stepTable td:nth-child(5) { width: 180px; }
#stepTable th:nth-child(6), #stepTable td:nth-child(6) { width: 330px; }
#stepTable th:nth-child(7), #stepTable td:nth-child(7) { width: 220px; }
#stepTable th:nth-child(8), #stepTable td:nth-child(8) { width: 360px; }
.mono, code, .monoBox, .kvBox, .stateCell, .vectorCell {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
.stateCell, .vectorCell { white-space: pre-wrap; word-break: break-word; color: #d8e2ec; }
.rightPanel { display: flex; flex-direction: column; gap: 12px; min-height: 0; overflow: auto; }
.statCard { padding: 14px; }
.kvBox { display: grid; gap: 10px; font-size: 13px; }
.kvBox div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid rgba(48, 83, 116, 0.45); padding-bottom: 7px; }
.kvBox span { color: #c6d6e4; }
.kvBox b { color: #f8fbff; font-weight: 700; }
.monoBox { white-space: pre-wrap; line-height: 1.55; color: #d9e7f5; font-size: 12px; }
.legendText { color: var(--muted); font-size: 12px; margin-top: 6px; }
body.focusRender .leftPanel,
body.focusRender .rightPanel,
body.focusRender .tracePanel { display: none; }
body.focusRender .workspace { grid-template-columns: 1fr; }
body.focusRender .centerPanel { grid-template-rows: 1fr; }
body.hideTable .tracePanel { display: none; }
body.hideTable .centerPanel { grid-template-rows: minmax(380px, 1fr); }
@media (max-width: 1280px) {
  .workspace { grid-template-columns: 280px minmax(420px,1fr); }
  .rightPanel { display: none; }
  .topBar { grid-template-columns: 1fr; height: auto; }
  .topControls { justify-content: flex-start; }
}
@media (max-width: 900px) {
  .appShell { position: static; height: auto; min-height: 100%; overflow: auto; }
  body { overflow: auto; }
  .workspace { grid-template-columns: 1fr; }
  .centerPanel { grid-template-rows: 460px 340px; }
  .leftPanel { max-height: none; }
}

/* Help overlay controls */
.readOverlayHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.readOverlayButtons {
  display: flex;
  gap: 6px;
}
.readOverlayButtons button,
.showReadButton {
  min-height: 0;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid #2a536f;
  background: rgba(6, 18, 30, 0.9);
  color: #d8e8f8;
  font-size: 12px;
  cursor: pointer;
}
.readOverlayButtons button:hover,
.showReadButton:hover {
  border-color: var(--cyan);
  box-shadow: 0 0 12px rgba(70,217,255,0.24);
}
.readOverlay.collapsed {
  width: auto;
  min-width: 180px;
  padding: 9px 10px;
}
.readOverlay.collapsed .readOverlayBody {
  display: none;
}
.readOverlay.hidden {
  display: none;
}
.showReadButton {
  display: none;
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 6;
  padding: 7px 11px;
  background: rgba(5, 13, 22, 0.82);
  backdrop-filter: blur(6px);
}
.showReadButton.visible {
  display: inline-flex;
  align-items: center;
}

.closeHelpBtn{
position:absolute;top:8px;right:8px;width:28px;height:28px;border:1px solid #2c4f6e;
border-radius:6px;background:rgba(10,20,30,0.85);color:#d8e8f8;cursor:pointer;font-size:18px;line-height:1;z-index:20}
.closeHelpBtn:hover{border-color:#46d9ff;box-shadow:0 0 10px rgba(70,217,255,0.3)}
