/* Rhombic Strips — instrument panel over a worksheet.
   Palette: ink UI + paper canvas; accents follow the Okabe-Ito / IBM hybrid
   already used in the papers and in gui.rs (vermillion #E66100, sky #56B4E9). */

:root {
  --ink: #14161c;
  --panel: #1b1e26;
  --panel-2: #232733;
  --hairline: #333949;
  --text: #e9e7e0;
  --text-dim: #9aa0ad;
  --paper: #f6f5f0;
  --paper-dot: #d9d5c9;
  --node-ink: #23262e;
  --vermillion: #e66100;
  --sky: #56b4e9;
  --green: #009e73;
  --focus: #56b4e9;
  --radius: 6px;
  --font-ui: "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", monospace;
  --font-display: "IBM Plex Serif", Georgia, serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--text);
  background: var(--ink);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---- top bar -------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--hairline);
  background: var(--ink);
  flex: none;
}
.wordmark { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.strip-glyph { width: 64px; height: 20px; align-self: center; flex: none; }
.wordmark h1 {
  margin: 0;
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 20px;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.wordmark .sub {
  color: var(--text-dim);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-right { display: flex; align-items: center; gap: 14px; flex: none; }
.stats { font-family: var(--font-mono); font-size: 12px; color: var(--text-dim); }

.mode-switch {
  display: flex;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  overflow: hidden;
}
.mode-switch button {
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text-dim);
  padding: 5px 14px;
}
.mode-switch button.active {
  background: var(--panel-2);
  color: var(--text);
  box-shadow: inset 0 -2px 0 var(--vermillion);
}

/* ---- layout ---------------------------------------------------------- */

.frame { display: flex; flex: 1; min-height: 0; }

.panel {
  width: 306px;
  flex: none;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--hairline);
  scrollbar-width: thin;
  scrollbar-color: var(--hairline) transparent;
}
.panel section {
  padding: 13px 16px 15px;
  border-bottom: 1px solid var(--hairline);
}
.panel h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.panel h2::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--hairline);
}
.group-label { margin: 10px 0 6px; font-size: 12.5px; color: var(--text-dim); }
.dim { color: var(--text-dim); font-weight: 400; font-size: 12px; }

.row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.row.wrap { flex-wrap: wrap; }
.row:last-child { margin-bottom: 0; }
.inline { color: var(--text-dim); }
.grow { flex: 1; }

/* ---- controls --------------------------------------------------------- */

button {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 5px 11px;
  cursor: pointer;
  transition: border-color 120ms, background 120ms;
}
button:hover:not(:disabled) { border-color: var(--text-dim); }
button:active:not(:disabled) { background: #2b3040; }
button:disabled { opacity: 0.4; cursor: default; }
button.block {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  margin-bottom: 6px;
  text-align: left;
}
button.small { padding: 3px 9px; font-size: 12px; }
button.danger:hover:not(:disabled) { border-color: var(--vermillion); color: #ffb27a; }

kbd {
  font-family: var(--font-mono);
  font-size: 10.5px;
  line-height: 1;
  color: var(--text-dim);
  background: var(--ink);
  border: 1px solid var(--hairline);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 2px 5px 1px;
  white-space: nowrap;
}
button kbd { margin-left: 4px; position: relative; top: -0.5px; }
button:hover:not(:disabled) kbd { color: var(--text); }

input[type="text"], input[type="number"] {
  font: inherit;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text);
  background: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 5px 8px;
  min-width: 0;
  flex: 1;
}
input[type="number"] { flex: 0 0 64px; }
input::placeholder { color: #6b7280; }

:is(button, input, summary, a):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.check { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; cursor: pointer; }
.check input { accent-color: var(--vermillion); }

details summary { cursor: pointer; color: var(--text-dim); font-size: 13px; }
details[open] summary { margin-bottom: 6px; }

/* ---- compute section (the instrument's run block) ----------------------- */

section.compute {
  border-left: 3px solid var(--vermillion);
  padding-left: 13px;
  background: linear-gradient(90deg, rgba(230, 97, 0, 0.05), transparent 55%);
}
.compute-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.compute-row button { padding: 6px 8px; }
.compute-row button:last-child { grid-column: 1 / -1; }

/* ---- compute backends ---------------------------------------------------- */

.backend-switch {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 8px;
}
.backend-switch button {
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text-dim);
  padding: 5px 4px;
  font-size: 12.5px;
}
.backend-switch button + button { border-left: 1px solid var(--hairline); }
.backend-switch button.active {
  background: var(--panel-2);
  color: var(--text);
  box-shadow: inset 0 -2px 0 var(--vermillion);
}
.backend-status {
  margin: -2px 0 8px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-dim);
}
.backend-status.ok { color: var(--green); }
.backend-status.error { color: #ff9d66; }

/* ---- compute helper dialog ------------------------------------------------ */

.remote-card { max-width: 560px; }
.remote-explain { margin: 12px 0 6px; font-size: 13px; color: var(--text); }
.remote-explain.dim2 { color: var(--text-dim); font-size: 12px; margin-top: 14px; }
.remote-explain code { font-family: var(--font-mono); font-size: 11.5px; }
.cmdbox { position: relative; }
.cmdbox pre {
  margin: 0;
  padding: 10px 12px;
  padding-right: 64px;
  background: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  user-select: all;
}
.cmdbox button { position: absolute; top: 6px; right: 6px; }
.remote-status {
  margin: 8px 0 0;
  min-height: 1.4em;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
}
.remote-status.ok { color: var(--green); }
.remote-status.error { color: #ff9d66; }

/* ---- job / strips ------------------------------------------------------ */

.job {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
}
.job #job-status { flex: 1; min-width: 0; }
.spinner {
  width: 12px; height: 12px; flex: none;
  border: 2px solid var(--hairline);
  border-top-color: var(--vermillion);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; border-top-color: var(--hairline); background: var(--vermillion); }
}

#strip-nav { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--hairline); }
.strip-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
}
.strip-counter {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
}
#layers-box { margin-top: 8px; }
#layers-list {
  margin: 0 0 8px;
  padding-left: 0;
  list-style: none;
  font-family: var(--font-mono);
  font-size: 11.5px;
  max-height: 220px;
  overflow-y: auto;
}
#layers-list li {
  display: flex;
  gap: 7px;
  align-items: baseline;
  padding: 2px 0;
  overflow-wrap: anywhere;
}
#layers-list .chip {
  flex: none;
  width: 8px; height: 8px;
  border-radius: 2px;
  transform: rotate(45deg) scale(0.9);
  position: relative;
  top: -1px;
}

/* ---- log / help link ---------------------------------------------------- */

.panel-foot { padding: 12px 16px 16px; margin-top: auto; }
.log {
  margin: 0 0 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.45;
  color: var(--sky);
  min-height: 2.6em;
}
.log.error { color: #ff9d66; }
.help-link {
  background: transparent;
  border: none;
  padding: 0;
  color: var(--text-dim);
  font-size: 12.5px;
}
.help-link:hover:not(:disabled) { color: var(--text); }

/* ---- stage -------------------------------------------------------------- */

.stage { position: relative; flex: 1; min-width: 0; background: var(--paper); }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#canvas.linking { cursor: crosshair; }

#rename-input {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 130px;
  text-align: center;
  font-family: var(--font-mono);
  background: #fff;
  color: var(--node-ink);
  border: 1.5px solid var(--vermillion);
  z-index: 3;
}

.zoombox {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.zoombox button {
  width: 32px; height: 32px;
  font-size: 17px;
  line-height: 1;
  background: #fff;
  color: var(--node-ink);
  border-color: var(--paper-dot);
}
.zoombox button:hover { border-color: var(--node-ink); }
#zoom-help { font-size: 14px; font-family: var(--font-mono); }

/* ---- shortcut sheet -------------------------------------------------------- */

.help-overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(20, 22, 28, 0.42);
}
.help-card {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.4);
  padding: 16px 20px 20px;
  max-width: 720px;
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
}
.help-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.help-card h3 {
  margin: 0;
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 17px;
}
.help-card h4 {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.help-cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 18px 26px;
}
.help-card dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px 12px;
  align-items: baseline;
  font-size: 12.5px;
}
.help-card dt { color: var(--text-dim); white-space: nowrap; }
.help-card dd { margin: 0; }

/* ---- small screens ------------------------------------------------------- */

@media (max-width: 880px) {
  .frame { flex-direction: column; }
  .panel {
    width: 100%;
    max-height: 46vh;
    border-right: none;
    border-bottom: 1px solid var(--hairline);
  }
  .wordmark .sub { display: none; }
}
