:root {
  --paper: #faf8f3;
  --ink: #2a2622;
  --line: rgba(42, 38, 34, 0.18);
  --accent: #2471a3;
  --chrome: rgba(250, 248, 243, 0.94);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--paper); color: var(--ink);
  font: 14px system-ui, sans-serif; overscroll-behavior: none; -webkit-user-select: none; user-select: none; }
canvas { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

#top, #bar { position: fixed; left: 0; right: 0; display: flex; gap: 8px; align-items: center;
  padding: 8px max(8px, env(safe-area-inset-left)); background: var(--chrome); backdrop-filter: blur(6px); z-index: 2; }
#top { top: 0; border-bottom: 1px solid var(--line); }
#bar { bottom: 0; border-top: 1px solid var(--line); padding-bottom: max(8px, env(safe-area-inset-bottom)); overflow-x: auto; }
.grow { flex: 1; }

button, .btn { min-height: 44px; min-width: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 8px;
  background: transparent; color: inherit; font: inherit; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
a.btn { text-decoration: none; }
button.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.seg { display: flex; gap: 4px; }
.ctx { display: none; gap: 12px; align-items: center; flex-shrink: 0; }
#bar button, #bar .btn { flex-shrink: 0; white-space: nowrap; }   /* the bar scrolls; nothing in it squashes */
body[data-mode="draw"] .ctx[data-ctx="draw"],
body[data-mode="select"] .ctx[data-ctx="select"],
body[data-mode="run"] .ctx[data-ctx="run"] { display: flex; }
#tail { display: contents; }                      /* Console, Shared script, Reset: for editing and for a live document, not for drawing */
body[data-mode="draw"] #tail { display: none; }

.swatch { padding: 0; width: 44px; }
.swatch i { width: 22px; height: 22px; border-radius: 50%; background: var(--c); }
.swatch.on { background: transparent; border: 2px solid var(--ink); }
.dot i { border-radius: 50%; background: var(--ink); display: block; width: var(--d); height: var(--d); }
.dot.on { background: transparent; border: 2px solid var(--ink); color: inherit; }
.hint { color: rgba(42, 38, 34, 0.6); white-space: nowrap; }

#hist { position: fixed; z-index: 2; top: 68px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; align-items: center;
  padding: 3px 10px; background: var(--chrome); backdrop-filter: blur(6px); border: 1px solid var(--line); border-radius: 22px; }
#hist button { min-width: 36px; min-height: 36px; padding: 0; border-radius: 50%; }
#hist button:disabled, #hist input:disabled { opacity: 0.35; }
#scrub { width: min(34vw, 220px); accent-color: var(--ink); }
#step { min-width: 4.2em; text-align: right; font: 12px ui-monospace, monospace; color: rgba(42, 38, 34, 0.7); }

#panel { position: fixed; z-index: 3; right: 8px; top: 64px; width: min(340px, calc(100vw - 16px));
  max-height: calc(100vh - 150px); display: flex; flex-direction: column; gap: 8px; padding: 10px;
  background: var(--chrome); border: 1px solid var(--line); border-radius: 10px; overflow: auto; -webkit-user-select: text; user-select: text; }
#panel[hidden], #panel [hidden] { display: none !important; }
#panel input[type=checkbox] { width: auto; }
#panel input, #panel textarea { font: 13px ui-monospace, monospace; padding: 8px; border: 1px solid var(--line);
  border-radius: 6px; background: #fff; color: inherit; width: 100%; }
#panel textarea { min-height: 120px; resize: vertical; tab-size: 2; }
#panel h3 { margin: 0; padding-top: 6px; border-top: 1px solid var(--line);
  font: 600 11px system-ui, sans-serif; text-transform: uppercase; letter-spacing: 0.04em; color: rgba(42, 38, 34, 0.55); }
#msg { margin: 0; white-space: pre-wrap; color: #c0392b; font: 12px ui-monospace, monospace; }
#msg:empty { display: none; }
#panel .chips { display: flex; flex-wrap: wrap; gap: 4px; }
#panel .chips:empty { display: none; }
#panel .chips button { min-height: 34px; padding: 0 10px; font: 12px ui-monospace, monospace; }
#preview, #vars, #uses, #out { margin: 0; white-space: pre-wrap; font: 12px ui-monospace, monospace; color: rgba(42, 38, 34, 0.75); }
#preview:empty, #uses:empty, #out:empty { display: none; }
#out { max-height: 9em; overflow: auto; flex-shrink: 0; }
#out.err { color: #c0392b; }
#preview.err { color: #c0392b; }
details pre { margin: 6px 0 0; font: 11px ui-monospace, monospace; white-space: pre-wrap; }

#actions { display: contents; }
#more { display: none; }
@media (max-width: 600px) {
  #top { z-index: 4; }                      /* above the history pill, so the open menu is not covered by it */
  #modes { flex: 1; }
  #modes button { flex: 1; padding: 0 8px; }
  #more { display: inline-flex; font-size: 20px; }
  #actions { display: none; position: absolute; top: calc(100% + 4px); right: max(8px, env(safe-area-inset-right)); z-index: 3; flex-direction: column;
    gap: 4px; padding: 6px; min-width: 150px; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 20px rgba(42, 38, 34, 0.18); }
  #top.open #actions { display: flex; }
  #actions .btn, #actions button { justify-content: flex-start; width: 100%; }
  #panel { right: 0; left: 0; top: auto; bottom: 64px; width: auto; max-height: 55vh; border-radius: 10px 10px 0 0; }
}

#editable-row { display: flex; gap: 8px; align-items: center; font-size: 13px; }
#field { position: fixed; z-index: 4; padding: 0 10px; font: 16px system-ui, sans-serif; text-align: center;
  color: var(--ink); background: #fff; border: 2px solid var(--accent); border-radius: 8px; -webkit-user-select: text; user-select: text; }
#field[hidden] { display: none; }

#props { display: grid; grid-template-columns: auto 1fr; gap: 4px 8px; align-items: center; font: 12px ui-monospace, monospace; }
#props label { color: rgba(42, 38, 34, 0.7); }
#props .ro { color: rgba(42, 38, 34, 0.5); }
#props .add { display: contents; }

/* visually hidden, still read by screen readers and reachable with Tab: the accessibility mirror */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
