/* ==========================================================================
   PyLogic Bench — "drafting table" theme
   Palette: blueprint navy / brass / warm paper / ink
   ========================================================================== */

:root{
  --navy-950: #131c26;
  --navy-900: #182430;
  --navy-800: #1e2d3b;
  --navy-700: #29394a;
  --navy-600: #3a4f63;
  --brass-500: #c9922b;
  --brass-400: #ddab52;
  --brass-300: #eec981;
  --paper: #f7f3ea;
  --paper-dim: #ece5d4;
  --ink: #2a2723;
  --ink-soft: #5b564c;
  --success: #3f8f5f;
  --error: #c1443b;
  --error-soft: #f3d9d6;

  --font-display: "Space Grotesk", sans-serif;
  --font-ui: "IBM Plex Sans", sans-serif;
  --font-mono: "IBM Plex Mono", monospace;

  --radius-s: 6px;
  --radius-m: 12px;
  --radius-l: 18px;

  --shadow-raised: 0 1px 0 rgba(255,255,255,.06) inset, 0 1px 2px rgba(0,0,0,.4), 0 4px 10px rgba(0,0,0,.28);
  --shadow-pressed: inset 0 2px 5px rgba(0,0,0,.45);
  --shadow-panel: 0 1px 0 rgba(255,255,255,.03) inset, 0 10px 30px rgba(0,0,0,.35);
}

*{ box-sizing: border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: var(--font-ui);
  background:
    radial-gradient(1200px 600px at 15% -10%, #203041 0%, transparent 60%),
    var(--navy-950);
  color: var(--paper);
  -webkit-font-smoothing: antialiased;
}
.hidden{ display:none !important; }
button{ font-family:inherit; cursor:pointer; }
textarea{ font-family:inherit; }

.bench{
  display:flex;
  flex-direction:column;
  height:100vh;
}

/* ===== Top rail ===== */
.rail{
  display:flex;
  align-items:center;
  gap:24px;
  padding:10px 20px;
  background: linear-gradient(180deg, var(--navy-800), var(--navy-900));
  border-bottom: 1px solid var(--navy-700);
  box-shadow: var(--shadow-panel);
  z-index: 5;
}
.rail-brand{ display:flex; align-items:center; gap:10px; }
.brand-mark{ color: var(--brass-400); display:flex; }
.brand-text{ display:flex; flex-direction:column; line-height:1.1; }
.brand-title{ font-family:var(--font-display); font-weight:700; font-size:16px; letter-spacing:.2px; }
.brand-sub{ font-size:10.5px; color: var(--paper-dim); opacity:.6; letter-spacing:.4px; }

.rail-tabs{
  display:flex;
  gap:4px;
  background: var(--navy-950);
  padding:4px;
  border-radius: 999px;
  box-shadow: var(--shadow-pressed);
  margin-left:auto;
}
.rail-tab{
  border:none;
  background:transparent;
  color: var(--paper-dim);
  padding:7px 16px;
  border-radius:999px;
  font-size:13px;
  font-weight:600;
  font-family: var(--font-display);
  transition: color .15s ease;
}
.rail-tab.is-active{
  color: var(--navy-950);
  background: linear-gradient(180deg, var(--brass-300), var(--brass-500));
  box-shadow: var(--shadow-raised);
}

.rail-controls{ display:flex; align-items:center; gap:10px; }
.dial{ display:flex; flex-direction:column; gap:2px; }
.dial-label{ font-size:9px; text-transform:uppercase; letter-spacing:.6px; color:var(--paper-dim); opacity:.6; }
#provider-select{
  background: var(--navy-950);
  color: var(--paper);
  border:1px solid var(--navy-600);
  border-radius: var(--radius-s);
  padding:5px 8px;
  font-size:12.5px;
  box-shadow: var(--shadow-pressed);
}
.icon-key{
  width:34px; height:34px;
  border-radius: 50%;
  border: 1px solid var(--navy-600);
  background: linear-gradient(180deg, var(--navy-700), var(--navy-800));
  color: var(--brass-400);
  display:flex; align-items:center; justify-content:center;
  box-shadow: var(--shadow-raised);
}
.icon-key:active{ box-shadow: var(--shadow-pressed); }

/* ===== Grid layout ===== */
.grid{
  flex:1;
  display:grid;
  grid-template-columns: 220px 1fr 340px;
  gap:14px;
  padding:14px;
  min-height:0;
}

.panel-heading{
  font-family: var(--font-display);
  font-size:11px;
  text-transform:uppercase;
  letter-spacing:.8px;
  color: var(--brass-400);
  margin:0 0 10px;
}

/* ===== Left palette ===== */
.palette{
  background: linear-gradient(180deg, var(--navy-800), var(--navy-900));
  border:1px solid var(--navy-700);
  border-radius: var(--radius-m);
  padding:14px;
  box-shadow: var(--shadow-panel);
  display:flex;
  flex-direction:column;
  overflow-y:auto;
}
.shape-tray{ display:flex; flex-direction:column; gap:8px; }
.shape-chip{
  display:flex;
  align-items:center;
  gap:10px;
  background: var(--navy-800);
  border:1px solid var(--navy-600);
  border-radius: var(--radius-s);
  padding:8px 10px;
  color: var(--paper);
  font-size:12px;
  box-shadow: var(--shadow-raised);
  text-align:left;
}
.shape-chip:active{ box-shadow: var(--shadow-pressed); cursor:grabbing; }
.shape-chip svg{ width:34px; height:20px; flex-shrink:0; }
.chip-fill{ fill:none; stroke: var(--brass-400); stroke-width:2; }

.palette-hint{
  font-size:11px;
  line-height:1.5;
  color: var(--paper-dim);
  opacity:.65;
  margin-top:14px;
}
.palette-actions{ margin-top:auto; padding-top:12px; }

/* ===== Center surface (editor) ===== */
.surface{
  background: var(--navy-800);
  border:1px solid var(--navy-700);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-panel);
  display:flex;
  flex-direction:column;
  min-height:0;
  overflow:hidden;
}
.surface-toolbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:10px 14px;
  border-bottom:1px solid var(--navy-700);
}
.surface-toolbar-left{ display:flex; align-items:center; gap:10px; }
.mode-pill{
  font-family: var(--font-display);
  font-weight:600;
  font-size:12px;
  background: var(--navy-950);
  padding:4px 10px;
  border-radius:999px;
  color: var(--brass-400);
}
.word-count{ font-size:11px; color:var(--paper-dim); opacity:.6; }

.editor-pane{
  flex:1;
  width:100%;
  border:none;
  resize:none;
  outline:none;
  padding:22px 26px;
  font-size:14.5px;
  line-height:1.7;
}
.paper{
  background:
    repeating-linear-gradient(180deg, transparent, transparent 27px, rgba(0,0,0,.045) 28px),
    var(--paper);
  color: var(--ink);
}
.editor-pane.mono{ font-family: var(--font-mono); }
.editor-pane::placeholder{ color: var(--ink-soft); opacity:.55; }

.flowchart-wrap{
  flex:1;
  background:
    linear-gradient(90deg, rgba(201,146,43,.08) 1px, transparent 1px) 0 0/28px 28px,
    linear-gradient(0deg, rgba(201,146,43,.08) 1px, transparent 1px) 0 0/28px 28px,
    var(--navy-900);
  position:relative;
  overflow:auto;
}
.flowchart-svg{ width:100%; height:100%; min-height:600px; display:block; }

.surface-footer{
  display:flex;
  align-items:center;
  gap:14px;
  padding:12px 14px;
  border-top:1px solid var(--navy-700);
  background: var(--navy-800);
}
.status-line{ font-size:12px; color:var(--paper-dim); opacity:.75; }

/* ===== Buttons ===== */
.btn-run{
  display:flex; align-items:center; gap:8px;
  border:none;
  padding:10px 20px;
  border-radius: var(--radius-s);
  background: linear-gradient(180deg, #4fae76, var(--success));
  color:#0d1f14;
  font-weight:700;
  font-family: var(--font-display);
  font-size:13px;
  box-shadow: var(--shadow-raised);
}
.btn-run:active{ box-shadow: var(--shadow-pressed); transform: translateY(1px); }
.btn-run:disabled{ opacity:.5; cursor:not-allowed; }

.btn-brass{
  border:none;
  padding:8px 16px;
  border-radius: var(--radius-s);
  background: linear-gradient(180deg, var(--brass-300), var(--brass-500));
  color: var(--navy-950);
  font-weight:700;
  font-size:12.5px;
  box-shadow: var(--shadow-raised);
}
.btn-brass:disabled{ opacity:.4; cursor:not-allowed; box-shadow:none; }
.btn-brass:active:not(:disabled){ box-shadow: var(--shadow-pressed); }

.btn-ghost{
  border:1px solid var(--navy-600);
  background:transparent;
  color: var(--paper-dim);
  padding:7px 14px;
  border-radius: var(--radius-s);
  font-size:12px;
  width:100%;
}
.btn-ghost:hover{ color:var(--paper); border-color: var(--brass-400); }

.btn-key{
  border:1px solid var(--navy-600);
  background: linear-gradient(180deg, var(--navy-700), var(--navy-800));
  color: var(--paper);
  padding:8px 14px;
  border-radius: var(--radius-s);
  font-size:12px;
  box-shadow: var(--shadow-raised);
}
.btn-key:disabled{ opacity:.4; cursor:not-allowed; }
.btn-key:active:not(:disabled){ box-shadow: var(--shadow-pressed); }

/* ===== Right console ===== */
.console{ display:flex; flex-direction:column; gap:10px; min-height:0; }
.console-bezel{
  flex:1;
  min-height:0;
  display:flex;
  flex-direction:column;
  background: linear-gradient(155deg, #2a2118, #1c150f 60%);
  border:1px solid #3d2f20;
  border-radius: var(--radius-m);
  padding:10px;
  box-shadow: var(--shadow-panel);
}
.console-tabs{ display:flex; gap:4px; margin-bottom:8px; }
.console-tab{
  flex:1;
  border:none;
  background: rgba(0,0,0,.25);
  color: var(--paper-dim);
  padding:7px 6px;
  border-radius: 6px 6px 0 0;
  font-size:11px;
  font-weight:600;
}
.console-tab.is-active{ background: #0b1410; color:#8ff0b0; }

.console-screen{
  flex:1;
  min-height:0;
  background: #0b1410;
  border-radius: var(--radius-s);
  box-shadow: inset 0 2px 10px rgba(0,0,0,.65), inset 0 0 40px rgba(0,0,0,.4);
  position:relative;
  overflow:hidden;
}
.console-pane{
  display:none;
  height:100%;
  margin:0;
  padding:16px;
  overflow:auto;
  color:#8ff0b0;
  font-size:12.5px;
  line-height:1.6;
  white-space:pre-wrap;
  word-break: break-word;
}
.console-pane.is-active{ display:block; }
.notes-pane{ color:#f0d98f; font-size:13px; line-height:1.6; }
.notes-pane .note-error{ color:#f0a08f; }
.notes-pane p{ margin:0 0 10px; }

.console-controls{ display:flex; gap:8px; }

/* ===== Status bar ===== */
.statusbar{
  display:flex; align-items:center; gap:8px;
  padding:6px 20px;
  font-size:11px;
  color: var(--paper-dim);
  background: var(--navy-900);
  border-top:1px solid var(--navy-800);
}
.conn-dot{ width:8px; height:8px; border-radius:50%; background:#8a6b3a; box-shadow:0 0 0 3px rgba(138,107,58,.2); }
.conn-dot.is-live{ background: var(--success); box-shadow:0 0 0 3px rgba(63,143,95,.25); }
.conn-dot.is-error{ background: var(--error); box-shadow:0 0 0 3px rgba(193,68,59,.25); }
.statusbar-sep{ opacity:.3; }

/* ===== Settings dialog ===== */
.settings-dialog{
  border:1px solid var(--navy-600);
  border-radius: var(--radius-m);
  background: var(--navy-800);
  color: var(--paper);
  padding:0;
  width:min(420px, 90vw);
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.settings-dialog::backdrop{ background: rgba(10,14,18,.65); }
.settings-form{ padding:20px; display:flex; flex-direction:column; gap:14px; }
.settings-form h2{ margin:0; font-family:var(--font-display); font-size:16px; }
.settings-note{ font-size:12px; color:var(--paper-dim); line-height:1.5; margin:0; }
.settings-note code{ background: var(--navy-950); padding:1px 5px; border-radius:4px; }
.settings-field{ display:flex; flex-direction:column; gap:5px; font-size:12px; color:var(--paper-dim); }
.settings-field input{
  background: var(--navy-950);
  border:1px solid var(--navy-600);
  color: var(--paper);
  padding:8px 10px;
  border-radius: var(--radius-s);
  font-size:13px;
  box-shadow: var(--shadow-pressed);
}
.settings-actions{ display:flex; justify-content:flex-end; gap:8px; margin-top:6px; }

/* ===== Flowchart node styling (SVG classes used by flowchart.js) ===== */
.fc-node-shape{
  fill: var(--paper);
  stroke: var(--brass-400);
  stroke-width:2;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,.35));
}
.fc-node.is-selected .fc-node-shape{ stroke: #8ff0b0; stroke-width:3; }
.fc-node-text{
  font-family: var(--font-ui);
  font-size:12px;
  fill: var(--ink);
  pointer-events:none;
  text-anchor:middle;
  dominant-baseline:middle;
}
.fc-edge{ stroke: var(--brass-300); stroke-width:2; fill:none; marker-end:url(#fc-arrow); }
.fc-anchor{ fill: var(--brass-400); stroke:#1c150f; stroke-width:1; cursor:crosshair; }
.fc-anchor:hover{ fill:#8ff0b0; }

/* ===== Selection highlight for "explain selection" ===== */
::selection{ background: rgba(201,146,43,.35); }

/* ===== Responsive ===== */
@media (max-width: 1000px){
  .grid{ grid-template-columns: 1fr; grid-template-rows:auto 1fr auto; }
  .palette{ flex-direction:row; overflow-x:auto; }
  .shape-tray{ flex-direction:row; }
  .console{ max-height:340px; }
}

/* ===== Reduced motion ===== */
@media (prefers-reduced-motion: reduce){
  *{ transition:none !important; animation:none !important; }
}

/* ===== Focus visibility ===== */
button:focus-visible, select:focus-visible, textarea:focus-visible, input:focus-visible{
  outline: 2px solid #8ff0b0;
  outline-offset: 2px;
}
