/* Colour tokens and the theme select are in ../common/theme.css, loaded before this file. */

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  display: flex;
  background: var(--bg);
  color: var(--fg);
  font-family: "Courier New", "DejaVu Sans Mono", Consolas, ui-monospace, monospace;
  font-size: 16px;
  text-shadow: var(--glow);
}

a { color: var(--fg); text-decoration: none; }

/* ---------- left panel / tree ---------- */

#sidebar {
  flex: 0 0 auto;
  min-width: 240px;
  overflow: auto;
  padding: 12px 14px;
  border-right: 1px solid var(--dim);
}

.logo { margin: 0 0 14px; font-size: 22px; letter-spacing: 3px; }
.lab-link { display: block; margin-bottom: 6px; color: var(--dim); font-size: 14px; }
.lab-link:hover, .lab-link:focus-visible { color: var(--fg); }

.tree details { margin-bottom: 8px; }

.tree summary {
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.tree summary::-webkit-details-marker { display: none; }
.tree summary::before { content: "[+] "; }
.tree details[open] > summary::before { content: "[-] "; }
.tree summary:hover { background: var(--faint); }

.tree ul { list-style: none; margin: 4px 0 0; padding: 0 0 0 12px; }
.tree li { white-space: nowrap; }
.tree li::before { content: "├── "; color: var(--dim); }
.tree li.last::before { content: "└── "; } /* last *visible* item, set in app.js (search hides items) */

.tree li a { padding: 0 4px; }
.tree li a:hover { background: var(--faint); }
.tree li a.active { background: var(--fg); color: var(--bg); text-shadow: none; }
.tree mark { background: none; color: var(--hot); text-decoration: underline; }
.tree li a.active mark { color: var(--bg); }

#search {
  width: 100%;
  margin: 0 0 12px;
  padding: 3px 8px;
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--dim);
  text-shadow: inherit;
}
#search::placeholder { color: var(--dim); }
/* the browser's clear (×) button is blue by default: draw it in the theme green */
#search::-webkit-search-cancel-button {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  cursor: pointer;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2 2l8 8M10 2l-8 8' stroke='%2336b836' stroke-width='2'/%3E%3C/svg%3E") center / contain no-repeat;
}
#search:focus { outline: none; border-color: var(--fg); }
.no-match { margin: 0 0 8px; color: var(--dim); }

/* ---------- main area ---------- */

#main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.home { padding: 24px; line-height: 1.6; overflow: auto; }
.home-keys { color: var(--dim); }

/* ---------- home gallery ---------- */
.gallery-branch h3 { margin: 22px 0 8px; font-size: 17px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.card { display: flex; flex-direction: column; gap: 4px; padding: 4px; border: 1px solid var(--faint); line-height: 1.3; }
.card:hover, .card:focus-visible { border-color: var(--fg); outline: none; }
.card img, .card .no-thumb { width: 100%; height: auto; aspect-ratio: 3 / 2; display: block; background: var(--bg); }
.card .no-thumb { display: flex; align-items: center; justify-content: center; color: var(--dim); border: 1px dashed var(--faint); }
/* thumbnails are stored green: tint them to the theme */
:root[data-theme="classic"] .card img { filter: saturate(1.5) brightness(1.25); }
:root[data-theme="amber"] .card img { filter: sepia(1) saturate(2.6) hue-rotate(-12deg) brightness(1.05); }
:root[data-theme="white"] .card img { filter: grayscale(1) brightness(1.3); }

/* ---------- fullscreen (key F): the toy page fills the screen ---------- */
#main:fullscreen { background: var(--bg); }
.cursor { animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.toy-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 18px;
  padding: 10px var(--margin);
  border-bottom: 1px solid var(--dim);
}
.toy-header h2 { margin: 0; font-size: 20px; }

/* flex-basis 0 + a fixed min-width: whether the controls share the title's line depends only on the
   title width, never on the status text inside (see .info) */
.controls {
  flex: 1 1 0;
  min-width: min(100%, 26em);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}
.controls label { display: inline-flex; align-items: center; gap: 6px; }

.controls input,
.controls select,
.controls button {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--fg);
  padding: 2px 8px;
  text-shadow: inherit;
}
.controls input { width: 9em; }
.controls input.small { width: 5em; }
.controls button { cursor: pointer; }
/* Pause/Resume: as wide as "Resume" in both states, so the toolbar never re-wraps (and resizes the
   canvas) when a toy pauses itself, e.g. on an input error */
.controls button.pause { box-sizing: content-box; min-width: 6ch; }
/* buttons that show changing text (Hi-res PNG shows its progress) keep the width of their label */
.controls button.fixed { box-sizing: content-box; min-width: 10ch; }
.controls button:disabled { opacity: 0.35; cursor: default; pointer-events: none; }
.controls button:hover,
.controls button:focus-visible { background: var(--fg); color: var(--bg); text-shadow: none; outline: none; }
.controls input:focus,
.controls select:focus { outline: 1px dashed var(--fg); outline-offset: 2px; }

/* Status line: its length must never change the layout (that would resize the canvas and
   re-render on every status update), so it gets a fixed minimum width and is cut with "…". */
.info {
  flex: 1 1 0;
  min-width: 14em;
  min-height: 1.25em; /* one line even while still empty, before the first status arrives */
  line-height: 1.25;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stage { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; }
.stage canvas { position: absolute; left: var(--margin); top: var(--margin); }

/* e.g. the differential equations of an attractor; mouse events pass through to the canvas */
.overlay {
  position: absolute;
  top: calc(var(--margin) * 2);
  right: calc(var(--margin) * 2);
  max-width: calc(100% - var(--margin) * 4);
  padding: 6px 10px;
  border: 1px solid var(--dim);
  background: rgba(0, 0, 0, 0.7);
  font-size: 14px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  pointer-events: none;
}
.overlay-note { margin-top: 4px; color: var(--dim); }

/* ---------- input errors (view.error): the status line can cut them off, so the whole message
   goes in a box over the dimmed picture, and the bad control gets a dashed frame ---------- */
.info.err { color: var(--hot); }
.stage.has-error canvas { opacity: 0.35; }
.error-box {
  position: absolute;
  left: calc(var(--margin) * 2);
  bottom: calc(var(--margin) * 2);
  max-width: min(40em, calc(100% - var(--margin) * 4));
  padding: 8px 12px;
  border: 3px double var(--hot);
  background: rgba(0, 0, 0, 0.85);
  color: var(--hot);
  font-size: 15px;
  line-height: 1.35;
  pointer-events: none;
}
.error-box::before { content: "ERR: "; font-weight: bold; }
[aria-invalid="true"] { outline: 2px dashed var(--hot); outline-offset: 1px; }
@media (max-width: 700px) { .overlay { font-size: 11px; } }

/* ---------- About panel (key A): over the picture, takes the mouse ---------- */
.about {
  position: absolute;
  top: calc(var(--margin) * 2);
  left: calc(var(--margin) * 2);
  width: min(36em, calc(100% - var(--margin) * 4));
  max-height: calc(100% - var(--margin) * 4);
  overflow: auto;
  padding: 10px 14px;
  border: 1px solid var(--fg);
  background: rgba(0, 0, 0, 0.9);
  font-size: 14px;
  line-height: 1.45;
  z-index: 2;
}
.about h3 { margin: 0 0 8px; font-size: 16px; }
.about p { margin: 0 0 8px; }
.about-links { margin: 0 0 8px; padding-left: 1.2em; }
.about a { text-decoration: underline; }
.about a:hover { color: var(--hot); }
.about-keys { color: var(--dim); font-size: 13px; }
.about-close {
  float: right;
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--dim);
  cursor: pointer;
  margin: -4px -8px 0 8px;
}

/* ---------- narrow screens: panel on top ---------- */

@media (max-width: 700px) {
  body { flex-direction: column; }
  #sidebar { flex: 0 0 auto; max-height: 40vh; border-right: 0; border-bottom: 1px solid var(--dim); }
  #main { flex: 1 1 auto; min-height: 60vh; }
}

/* ---------- dialogs (affine editor: designs) ---------- */

dialog.designs {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 14px 18px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--fg);
  font: inherit;
  text-shadow: var(--glow);
}
dialog.designs::backdrop { background: rgba(0, 0, 0, 0.75); }
dialog.designs h3 { margin: 14px 0 6px; font-size: 16px; }
dialog.designs h3:first-child { margin-top: 0; }
dialog.designs .row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
dialog.designs .row.end { justify-content: flex-end; margin-top: 12px; }
dialog.designs input,
dialog.designs textarea,
dialog.designs button {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--fg);
  padding: 2px 8px;
  text-shadow: inherit;
}
dialog.designs input[type=text] { flex: 1 1 14em; }
dialog.designs textarea { display: block; width: 100%; font-size: 13px; white-space: pre; resize: vertical; }
dialog.designs button { cursor: pointer; }
dialog.designs button:hover,
dialog.designs button:focus-visible { background: var(--fg); color: var(--bg); text-shadow: none; outline: none; }
dialog.designs input:focus,
dialog.designs textarea:focus { outline: 1px dashed var(--fg); outline-offset: 2px; }
.saved-list { list-style: none; margin: 0; padding: 0; }
.saved-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 3px 0; border-bottom: 1px solid var(--faint); }
.saved-name { flex: 1 1 10em; }
.saved-meta { color: var(--dim); }
.dialog-message { min-height: 1.25em; margin: 10px 0 0; color: var(--dim); }
.dialog-message.bad { color: var(--hot); }

