:root {
  --bg: #0b0f14;
  --bg-2: #101620;
  --bg-3: #161e2a;
  --line: #22303f;
  --text: #e6edf3;
  --muted: #8b9bb0;
  --accent: #64d2ff;
  --accent-2: #ff9d9d;
  --ok: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--bg-2);
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 26px; height: 26px; border-radius: 7px; background: #0b0f14; border: 1px solid var(--line);
  position: relative; overflow: hidden;
}
.logo::before { content: ""; position: absolute; left: 3px; right: 3px; top: 12px; height: 3px; background: var(--accent-2); border-radius: 2px; }
.logo::after { content: ""; position: absolute; left: 8px; top: 3px; width: 8px; height: 8px; border: 2px solid var(--accent); border-radius: 50%; }
.name { font-weight: 700; letter-spacing: .2px; }
.tag { color: var(--muted); font-size: 12px; white-space: nowrap; }
@media (max-width: 1180px) { .tag { display: none; } }
.sibling { color: var(--accent); text-decoration: none; font-size: 12px; font-weight: 600; padding: 6px 11px; border: 1px solid var(--line); border-radius: 8px; margin-left: 8px; white-space: nowrap; }
.sibling:hover { border-color: var(--accent); }
.topbar-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.pdk-pick { display: flex; align-items: center; gap: 6px; background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; }
.pdk-pick .pdk-label { color: var(--muted); font-size: 12px; }
.pdk-pick select { background: transparent; border: 0; color: var(--text); font-weight: 500; outline: none; max-width: 220px; }
.pdk-pick select option { background: var(--bg-2); }
.pdk-pick.fab { border-color: #1f4d33; }
.pdk-pick.fab .pdk-label { color: var(--ok); }
.pill {
  font-family: var(--mono); font-size: 11px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px;
}
.pill.ok { color: var(--ok); border-color: #1f4d33; }
.pill.bad { color: var(--bad); border-color: #5a2626; }

.btn {
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; font-weight: 500; transition: background .12s, border-color .12s;
}
.btn:hover { background: #1d2836; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #05131a; border-color: transparent; font-weight: 600; }
.btn.primary:hover { background: #82dcff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
.btn.toggled { border-color: var(--accent); color: var(--accent); }

.workspace {
  flex: 1; display: grid;
  grid-template-columns: 340px 1fr 420px;
  min-height: 0;
}
.pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; border-right: 1px solid var(--line); }
.pane:last-child { border-right: 0; }

/* chat */
.messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { border-radius: 10px; padding: 10px 12px; line-height: 1.45; max-width: 100%; white-space: pre-wrap; word-wrap: break-word; }
.msg p { margin: 0 0 6px; }
.msg p:last-child { margin: 0; }
.msg.user { background: #16324a; align-self: flex-end; }
.msg.assistant { background: var(--bg-3); }
.msg.system { background: transparent; border: 1px dashed var(--line); color: var(--text); }
.msg.error { background: #3a1c1c; border: 1px solid #5a2626; font-family: var(--mono); font-size: 12px; }
.msg .meta { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }
.status { display: flex; align-items: center; gap: 8px; padding: 8px 14px; color: var(--accent); font-size: 13px; border-top: 1px solid var(--line); }
.spinner { width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.composer { border-top: 1px solid var(--line); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; background: var(--bg-2); }
.composer textarea {
  width: 100%; resize: vertical; min-height: 64px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 10px; outline: none;
}
.composer textarea:focus { border-color: var(--accent); }
.composer-row { display: flex; justify-content: space-between; align-items: center; }
.check { color: var(--muted); font-size: 12px; display: flex; gap: 6px; align-items: center; }

/* viewer */
.viewer { position: relative; background: #070a0e; }
.viewer-tools {
  position: absolute; top: 10px; left: 10px; z-index: 2; display: flex; gap: 6px; align-items: center;
  background: rgba(16, 22, 32, .85); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; backdrop-filter: blur(4px);
}
.coords, .dims { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-left: 6px; white-space: pre; }
#canvas { width: 100%; height: 100%; display: block; cursor: grab; }
#canvas.dragging { cursor: grabbing; }
.legend {
  position: absolute; right: 10px; bottom: 10px; z-index: 2; display: flex; flex-direction: column; gap: 4px;
  background: rgba(16, 22, 32, .85); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; backdrop-filter: blur(4px);
  font-size: 12px; max-height: 45%; overflow: auto;
}
.legend label { display: flex; align-items: center; gap: 7px; cursor: pointer; }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; border: 1px solid rgba(255,255,255,.25); }
.legend .ln { color: var(--muted); font-family: var(--mono); font-size: 11px; }
.empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); pointer-events: none; }
.empty-art { width: 140px; height: 70px; border: 1px dashed var(--line); border-radius: 10px; margin-bottom: 12px; position: relative; }
.empty-art::before { content: ""; position: absolute; left: 10px; right: 10px; top: 33px; height: 3px; background: #3a2b2b; border-radius: 2px; }
.empty-art::after { content: ""; position: absolute; left: 56px; top: 8px; width: 24px; height: 24px; border: 2px solid #234; border-radius: 50%; }

/* side */
.tabs { display: flex; border-bottom: 1px solid var(--line); background: var(--bg-2); }
.tab { flex: 1; background: transparent; border: 0; padding: 10px 6px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; font-weight: 500; display: flex; justify-content: center; gap: 6px; align-items: center; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.badge { background: var(--bad); color: #fff; font-size: 10px; border-radius: 999px; padding: 1px 6px; font-weight: 600; }
.badge.ok { background: var(--ok); color: #05131a; }
.tabpanel { display: none; flex: 1; min-height: 0; flex-direction: column; }
.tabpanel.active { display: flex; }
.panel-toolbar { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); gap: 8px; font-size: 12px; }
.panel-toolbar.wrap { flex-wrap: wrap; justify-content: flex-start; }
.panel-toolbar label { display: flex; gap: 5px; align-items: center; color: var(--muted); }
.panel-toolbar input { width: 64px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; font-family: var(--mono); font-size: 12px; }
.code {
  flex: 1; width: 100%; resize: none; border: 0; outline: none; background: var(--bg); color: var(--text);
  font-family: var(--mono); font-size: 12.5px; line-height: 1.5; padding: 12px; tab-size: 4; white-space: pre; overflow: auto;
}
.error { margin: 0; padding: 10px 12px; background: #3a1c1c; color: #ffd0d0; font-family: var(--mono); font-size: 11.5px; white-space: pre-wrap; max-height: 40%; overflow: auto; border-top: 1px solid #5a2626; }
#sim-canvas { width: 100%; height: 300px; display: block; background: var(--bg); }
.sim-legend { display: flex; flex-wrap: wrap; gap: 8px 14px; padding: 8px 12px; font-family: var(--mono); font-size: 11px; }
.sim-legend span::before { content: ""; display: inline-block; width: 14px; height: 3px; background: var(--c); margin-right: 6px; vertical-align: middle; border-radius: 2px; }
#sim-note { padding: 0 12px 12px; margin: 0; }
.list { padding: 12px; overflow: auto; flex: 1; display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; justify-content: space-between; gap: 10px; padding: 8px 10px; background: var(--bg-3); border-radius: 8px; font-size: 13px; }
.row .k { color: var(--muted); }
.row .v { font-family: var(--mono); font-size: 12px; }
.row.bad { border-left: 3px solid var(--bad); }
.row.ok { border-left: 3px solid var(--ok); }
.row.warn { border-left: 3px solid var(--warn); }
.row.clickable { cursor: pointer; }
.row.clickable:hover { background: #1d2836; }
h4 { margin: 8px 0 2px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
table.ports { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 11.5px; }
table.ports th, table.ports td { text-align: left; padding: 5px 6px; border-bottom: 1px solid var(--line); }
table.ports th { color: var(--muted); font-weight: 500; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 10; padding: 16px; }
.modal-card { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; width: min(720px, 100%); max-height: 85vh; overflow: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.examples { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 14px 16px; }
.example { text-align: left; background: var(--bg-3); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.example:hover { border-color: var(--accent); }
.example strong { display: block; margin-bottom: 4px; }
.example span { color: var(--muted); font-size: 12px; }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 300px 1fr; grid-template-rows: 1fr 1fr; }
  .side { grid-column: 1 / -1; border-top: 1px solid var(--line); }
  .examples { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  body { overflow: auto; }
  .workspace { display: flex; flex-direction: column; }
  .pane { border-right: 0; border-bottom: 1px solid var(--line); flex: none; }
  .viewer { order: 1; height: 46vh; min-height: 300px; }
  .chat { order: 2; }
  .chat .messages { max-height: 26vh; }
  .side { order: 3; min-height: 480px; }
  .tag { display: none; }
  .topbar { padding: 8px 12px; }
  .topbar .pill { display: none; }
}

/* ---------- ASIC mode ---------- */
.asic-only { display: none; }
body.asic .asic-only { display: block; }
body.asic span.asic-only { display: inline-flex; }
body.asic .photonic-only { display: none !important; }
.asic-settings { gap: 10px; align-items: center; color: var(--muted); font-size: 12px; }
.asic-settings label { display: inline-flex; align-items: center; gap: 4px; }
.asic-settings select { background: var(--bg-3); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; font-size: 12px; }
.asic-settings input { width: 62px; background: var(--bg-3); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; font-family: var(--mono); font-size: 12px; }
pre.report { font-family: var(--mono); font-size: 11px; line-height: 1.35; color: var(--muted); background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow: auto; max-height: 420px; white-space: pre; margin: 6px 0 0; }
.ports td.neg { color: var(--bad); }
.filelinks { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.filelinks a { color: var(--accent); font-size: 12px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; text-decoration: none; }
.filelinks a:hover { border-color: var(--accent); }
.msg.system.note { border-left: 2px solid var(--accent); }
.tabpanel > .photonic-only { display: flex; flex-direction: column; flex: 1; min-height: 0; }
body.asic .tabpanel > .asic-only { display: flex; flex-direction: column; flex: 1; min-height: 0; }
body.asic .panel-toolbar.asic-only { display: flex; flex: none; }
