/* pysims: the page. Three panes a student can resize or fold, a tabbed side
   panel, a console that folds to one line, a dark theme for a screen and a
   light one for a projector. Sizes live in CSS variables that js/layout.js
   sets; folding is a class on body. */

:root {
  --bg: #0b0e11;
  --panel: #12171c;
  --panel-2: #0e1216;
  --edge: #27313b;
  --text: #d8dee6;
  --dim: #8a97a6;
  --ok: #7fd38a;
  --bad: #f08a7a;
  --busy: #e8c56a;
  --accent: #5aa9ff;
  --button: #1d2630;
  --button-edge: #36424f;
  --primary: #214a78;
  --primary-edge: #2f6cb0;
  --canvas: #0f1317;
  --grid-line: #1b2229;
  --grid-axis: #3f4f5f;
  --grid-label: #5a6773;
  --select: #243242;
  --select-focus: #2b3d52;
  --kw: #c792ea; --num: #f78c6c; --str: #c3e88d; --cmt: #5f6b78; --builtin: #82aaff; --op: #89ddff;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f3f1ea;
  --panel: #faf8f2;
  --panel-2: #efece3;
  --edge: #d6d1c4;
  --text: #22262b;
  --dim: #6b7380;
  --ok: #2e7d32;
  --bad: #b3261e;
  --busy: #8a6d00;
  --accent: #2f6cb0;
  --button: #ffffff;
  --button-edge: #c9c4b6;
  --primary: #2f6cb0;
  --primary-edge: #245a94;
  --canvas: #ffffff;
  --grid-line: #e6e3da;
  --grid-axis: #b9b3a5;
  --grid-label: #8a8f98;
  --select: #dce7f5;
  --select-focus: #cfe0f5;
  --kw: #7c3aed; --num: #b45309; --str: #15803d; --cmt: #8a8f98; --builtin: #1d4ed8; --op: #0e7490;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
/* hidden wins over any display an element's class sets (the scrubber and
   the graph overlay are flex boxes and were showing through) */
[hidden] { display: none !important; }

body {
  --editor-w: 440px;
  --side-w: 300px;
  --console-h: 160px;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) 6px var(--console-h);
  grid-template-columns: var(--editor-w) 6px minmax(320px, 1fr) 6px var(--side-w);
  grid-template-areas:
    "bar bar bar bar bar"
    "editor split1 view split2 side"
    "split3 split3 split3 split3 split3"
    "console console console console console";
  height: 100vh;
  overflow: hidden;
}

body.no-editor { grid-template-columns: 0 0 minmax(320px, 1fr) 6px var(--side-w); }
body.no-side { grid-template-columns: var(--editor-w) 6px minmax(320px, 1fr) 0 0; }
body.no-editor.no-side { grid-template-columns: 0 0 minmax(320px, 1fr) 0 0; }
body.no-editor .editor, body.no-editor #split-editor { display: none; }
body.no-side .side, body.no-side #split-side { display: none; }
body.console-closed { grid-template-rows: auto minmax(0, 1fr) 0 28px; }
body.console-closed #split-console { display: none; }
body.console-closed #console { display: none; }
/* Canvas only still runs the simulation, so the transport stays: a view
   you cannot pause, step or slow down is a poster, not a tool. */
body.focus .bar .group:not(.brand):not(.right):not(.transport), body.focus .scrubber { display: none; }
body.dragging { cursor: col-resize; user-select: none; }
body.dragging * { cursor: inherit !important; }

/* ----- the bar ----- */

.bar {
  grid-area: bar;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--edge);
  background: var(--panel);
  min-height: 42px;
}
.group { display: flex; align-items: center; gap: 8px; }
.group.right { margin-left: auto; }
.bar h1 { font-size: 16px; margin: 0; font-weight: 600; letter-spacing: 0.02em; }
.filename { color: var(--dim); font-size: 13px; }

button {
  font: inherit;
  padding: 5px 13px;
  background: var(--button);
  color: var(--text);
  border: 1px solid var(--button-edge);
  border-radius: 4px;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--primary); border-color: var(--primary-edge); color: #fff; }
button.small { padding: 2px 8px; font-size: 12px; }
button.active { border-color: var(--busy); color: var(--busy); }

/* The transport: shapes rather than words, because the row is read a hundred
   times an hour and a shape is read faster than a word. Every one carries a
   title, so hovering still says what it does and what its key is. */
button.icon { padding: 5px 9px; line-height: 0; }
button.icon svg { width: 15px; height: 15px; display: block; fill: currentColor; }
button.icon.primary svg { fill: #fff; }
#back:not(:disabled), #step:not(:disabled) { color: var(--text); }
/* looking at a step that has already been, rather than the live one */
body.rewound #back, body.rewound #step { border-color: var(--busy); color: var(--busy); }
body.rewound .view canvas { outline: 1px solid var(--busy); outline-offset: -1px; }

.status { color: var(--dim); font-size: 13px; max-width: 34ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status.ok { color: var(--ok); }
.status.bad { color: var(--bad); }
.status.busy { color: var(--busy); }

label.check { color: var(--dim); font-size: 13px; }
label.speed input[type=range] { width: 90px; vertical-align: middle; }
a.link { color: var(--accent); font-size: 13px; text-decoration: none; }
a.link:hover { text-decoration: underline; }

/* the View menu: a native details element, styled as a dropdown */
.menu { position: relative; font-size: 13px; }
.menu summary { list-style: none; cursor: pointer; padding: 5px 10px; border: 1px solid var(--button-edge); border-radius: 4px; background: var(--button); }
.menu summary::-webkit-details-marker { display: none; }
.menu[open] summary { border-color: var(--accent); }
.menu-body { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 260px; background: var(--panel); border: 1px solid var(--edge); border-radius: 6px; padding: 8px 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.35); }
.menu-body label { display: block; padding: 4px 2px; cursor: pointer; }
.menu-body hr { border: none; border-top: 1px solid var(--edge); margin: 6px 0; }
.menu-body .keys { color: var(--dim); font-size: 12px; line-height: 1.6; }
#helpmenu .menu-body { min-width: 360px; }
.menu-link { display: block; padding: 5px 2px; color: var(--accent); text-decoration: none; font-weight: 600; }
.menu-link:hover { text-decoration: underline; }
.menu-link .hint { display: block; color: var(--dim); font-weight: normal; font-size: 12px; }
kbd { font: 11px system-ui, sans-serif; background: var(--button); border: 1px solid var(--button-edge); border-bottom-width: 2px; border-radius: 3px; padding: 0 5px; }

/* ----- the panes ----- */

.splitter { background: transparent; }
.splitter.v { grid-area: split1; cursor: col-resize; }
#split-side { grid-area: split2; }
.splitter.h { grid-area: split3; cursor: row-resize; }
.splitter:hover { background: var(--accent); opacity: 0.5; }

.editor { grid-area: editor; min-height: 0; min-width: 0; display: flex; flex-direction: column; border-right: 1px solid var(--edge); }
.editor .CodeMirror { flex: 1; height: auto; font: 14px/1.45 ui-monospace, Consolas, "Cascadia Mono", monospace; background: var(--panel); color: var(--text); }
.editor .CodeMirror-gutters { background: var(--panel-2); border-right: 1px solid var(--edge); }
.editor .CodeMirror-linenumber { color: var(--dim); opacity: 0.7; }
.editor .CodeMirror-cursor { border-left: 1px solid var(--text); }
.editor .CodeMirror-selected { background: var(--select); }
.editor .CodeMirror-focused .CodeMirror-selected { background: var(--select-focus); }
.editor .cm-s-default .cm-keyword { color: var(--kw); }
.editor .cm-s-default .cm-number { color: var(--num); }
.editor .cm-s-default .cm-string { color: var(--str); }
.editor .cm-s-default .cm-comment { color: var(--cmt); font-style: italic; }
.editor .cm-s-default .cm-builtin, .editor .cm-s-default .cm-def { color: var(--builtin); }
.editor .cm-s-default .cm-variable { color: var(--text); }
.editor .cm-s-default .cm-operator { color: var(--op); }
.editor .CodeMirror-matchingbracket { color: var(--ok) !important; font-weight: bold; }

.view { grid-area: view; min-height: 0; min-width: 0; display: flex; flex-direction: column; position: relative; }
.view canvas { flex: 1; min-height: 0; cursor: crosshair; }
.readout { position: absolute; top: 6px; right: 10px; font: 12px/1.3 ui-monospace, Consolas, monospace; color: var(--dim); pointer-events: none; white-space: pre; }
.scrubber { display: flex; align-items: center; gap: 8px; padding: 4px 10px; border-top: 1px solid var(--edge); background: var(--panel); font-size: 12px; color: var(--dim); }
.scrubber input[type=range] { flex: 1; }
/* nothing to replay yet: the bar holds its height so the canvas never
   changes size mid-session, and dims so it does not invite a click */
.scrubber.idle { opacity: 0.45; }
.scrubber.idle input[type=range], .scrubber.idle button { cursor: default; }

/* ----- the side panel ----- */

.side { grid-area: side; border-left: 1px solid var(--edge); background: var(--panel); min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.tabs { display: flex; border-bottom: 1px solid var(--edge); }
.tabs button { flex: 1; border: none; border-radius: 0; background: transparent; color: var(--dim); padding: 8px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; border-bottom: 2px solid transparent; }
.tabs button:hover { border-color: transparent; color: var(--text); }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.tabs button.has-content:not(.active)::after { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); margin-left: 6px; vertical-align: middle; }
.pane { overflow: auto; min-height: 0; flex: 1; }
.panel { padding: 8px 10px; border-bottom: 1px solid var(--edge); }
.panel h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--dim); margin: 0 0 6px; font-weight: 600; }
.panel h3 { font-size: 12px; color: var(--dim); margin: 10px 0 4px; font-weight: 600; }
.panel .note, .pane .note { color: var(--dim); font-size: 12px; margin: 0 0 6px; }
.pane .empty { padding: 10px 12px; }
.pane .empty code { font-size: 11px; }

.control { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center; margin: 4px 0 8px; font-size: 13px; }
.control label { grid-column: 1 / 3; color: var(--text); }
.control input[type=range] { width: 100%; }
.control .value { color: var(--dim); font-variant-numeric: tabular-nums; min-width: 3.5em; text-align: right; }
.monitors { margin-top: 6px; }
.monitor { display: flex; justify-content: space-between; font-size: 13px; padding: 2px 0; }
.monitor .value { color: var(--ok); font-variant-numeric: tabular-nums; }

.graph { margin: 4px 0 10px; }
.graph-note { font-size: 12px; color: var(--dim); margin: 2px 0 0; line-height: 1.5; }
.graph-note b { color: var(--text); font-weight: 600; }
.graph-note code { font-family: ui-monospace, Consolas, monospace; color: var(--accent); }
#graphs h2 .cap { font-weight: 400; font-size: 11px; color: var(--dim); text-transform: none; letter-spacing: 0; opacity: 0.8; }
.graph .title { font-size: 12px; color: var(--dim); display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; }
.graph canvas { width: 100%; height: 120px; display: block; border: 1px solid var(--edge); }
.graph.big canvas { height: 280px; }
.graph .title .buttons { display: flex; gap: 4px; }
.graph .title .buttons button { padding: 0 6px; font-size: 11px; }

/* one graph large under the simulation, sharing the space rather than
   hiding it: the canvas keeps its whole view, drawn smaller */
.graph-big { height: var(--biggraph-h, 300px); min-height: 0; display: flex; flex-direction: column; background: var(--panel); border-top: 1px solid var(--edge); }
.graph-big .head { display: flex; align-items: center; gap: 12px; padding: 4px 10px; font-size: 13px; color: var(--dim); }
.graph-big .head .title { font-weight: 600; color: var(--text); }
.graph-big .head .cursor { font: 12px ui-monospace, Consolas, monospace; color: var(--accent); min-width: 18ch; white-space: pre; font-variant-numeric: tabular-nums; }
.graph-big .head .tools { margin-left: auto; display: flex; gap: 4px; }
.graph-big canvas { flex: 1; min-height: 0; width: 100%; display: block; cursor: grab; }
.graph-big img { flex: 1; min-height: 0; width: 100%; object-fit: contain; display: block; background: #fff; }
#split-graph { height: 6px; flex: 0 0 auto; }

.output img { width: 100%; display: block; margin: 4px 0 8px; border: 1px solid var(--edge); background: #fff; cursor: zoom-in; }
.output img:hover, .output img:focus { border-color: var(--accent); outline: none; }

.card { padding: 6px 8px; margin: 4px 0; border: 1px solid var(--edge); border-radius: 4px; cursor: pointer; }
.card:hover, .card:focus { border-color: var(--accent); outline: none; }
.card .title { font-size: 13px; font-weight: 600; }
.card .desc { font-size: 12px; color: var(--dim); }

.filelist { font-size: 13px; }
.file { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; padding: 4px 0; border-top: 1px solid var(--edge); }
.file .name { flex: 1 0 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file .name.openable { cursor: pointer; color: var(--accent); }
.file.current .name { color: var(--text); font-weight: 600; }
.filebar { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.filebar input[type=text] { font: inherit; font-size: 12px; background: var(--panel-2); color: var(--text); border: 1px solid var(--button-edge); padding: 2px 6px; width: 140px; }

/* the editor's addons: the active line, trailing spaces, folds, matches, errors */
.editor .CodeMirror-activeline-background { background: rgba(127, 150, 180, 0.08); }
.editor .cm-trailingspace { background: rgba(240, 138, 122, 0.25); }
.editor .CodeMirror-foldgutter { width: 12px; }
.editor .CodeMirror-foldgutter-open, .editor .CodeMirror-foldgutter-folded { color: var(--dim); cursor: pointer; }
.editor .CodeMirror-foldmarker { color: var(--accent); text-shadow: none; font-family: inherit; }
.editor .cm-matchhighlight { background: rgba(90, 169, 255, 0.18); }
.editor .search-match { background: rgba(232, 197, 106, 0.3); }
.editor .search-match-current { background: rgba(232, 197, 106, 0.7); color: #111; }
.editor .line-error { background: rgba(240, 138, 122, 0.18); }
.editor .CodeMirror-dialog { background: var(--panel); color: var(--text); border-bottom: 1px solid var(--edge); font-size: 13px; }
.editor .CodeMirror-dialog input { background: var(--panel-2); color: var(--text); border: 1px solid var(--button-edge); }

/* find and replace: a panel at the top of the editor that stays */
.find-panel { background: var(--panel); border-bottom: 1px solid var(--edge); padding: 4px 6px; font-size: 12px; }
.find-row, .replace-row { display: flex; align-items: center; gap: 4px; }
.replace-row { margin-top: 4px; }
.find-panel input[type=text] { flex: 1; min-width: 80px; font: 13px ui-monospace, Consolas, monospace; background: var(--panel-2); color: var(--text); border: 1px solid var(--button-edge); border-radius: 3px; padding: 3px 6px; }
.find-panel input.bad { border-color: var(--bad); }
.find-panel button { padding: 2px 6px; font-size: 12px; }
.find-panel .opt { font-family: ui-monospace, Consolas, monospace; min-width: 28px; }
.find-panel .opt.active { border-color: var(--accent); color: var(--accent); }
.find-panel .find-count { color: var(--dim); min-width: 5em; text-align: center; font-variant-numeric: tabular-nums; }

.font-row { display: flex; align-items: center; gap: 6px; padding: 4px 2px; }
.font-row span { min-width: 2em; text-align: center; font-variant-numeric: tabular-nums; }

.CodeMirror-hints { background: var(--panel); border: 1px solid var(--edge); color: var(--text); font: 13px ui-monospace, Consolas, monospace; box-shadow: 0 4px 16px rgba(0,0,0,0.35); }
.CodeMirror-hint { color: var(--text); padding: 2px 8px; }
li.CodeMirror-hint-active { background: var(--primary); color: #fff; }

/* ----- the console ----- */

.console-wrap { grid-area: console; display: flex; flex-direction: column; min-height: 0; border-top: 1px solid var(--edge); background: var(--panel-2); }
.console-head { display: flex; align-items: center; gap: 10px; padding: 2px 10px; font-size: 12px; color: var(--dim); min-height: 28px; }
.console-last { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 12px ui-monospace, Consolas, monospace; }
.console-count { color: var(--bad); font-weight: 600; }
.console {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 2px 10px 6px;
  font: 13px/1.45 ui-monospace, Consolas, "Cascadia Mono", monospace;
  white-space: pre-wrap;
}
.console .line { min-height: 1.45em; }
.console .err { color: var(--bad); }
.console .say { color: var(--busy); }
.console .note { color: var(--dim); }

/* ----- narrow screens: the side panel and the console stack under the canvas ----- */

@media (max-width: 1024px) {
  body, body.no-editor, body.no-side, body.no-editor.no-side {
    grid-template-columns: minmax(280px, 1fr) 6px minmax(280px, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto 32vh 6px var(--console-h);
    grid-template-areas:
      "bar bar bar"
      "editor split1 view"
      "side side side"
      "side side side"
      "split3 split3 split3"
      "console console console";
  }
  body.no-editor { grid-template-columns: 0 0 1fr; }
  #split-side { display: none; }
  .side { border-left: none; border-top: 1px solid var(--edge); }
  body.no-side { grid-template-rows: auto minmax(0, 1fr) 0 0 6px var(--console-h); }
}

@media (max-width: 700px) {
  body, body.no-editor, body.no-side, body.no-editor.no-side {
    grid-template-columns: 1fr;
    grid-template-rows: auto 40vh minmax(200px, 1fr) 30vh 6px var(--console-h);
    grid-template-areas:
      "bar"
      "view"
      "editor"
      "side"
      "split3"
      "console";
  }
  #split-editor { display: none; }
  .editor { border-right: none; border-top: 1px solid var(--edge); }
  .bar { flex-wrap: wrap; gap: 8px; }
  .group.right { margin-left: 0; }
}
