* { box-sizing: border-box; margin: 0; padding: 0; }

/* The drawing is black on a white WebGL canvas, which a browser's automatic dark
   theme cannot touch — it would only grey out the text and the windows around it.
   `only light` is the opt-out; index.html carries the same as a meta tag. */
html { overflow: hidden; color-scheme: only light; }
/* No pull-to-refresh or rubber-band bounce when a swipe runs past the page edge. */
html, body { overscroll-behavior: none; }

body {
  display: flex;
  flex-direction: column;
  /* --zoom: the CSS zoom of a phone (mobile.js), else 1. vh/vw are
     screen sizes, which a zoomed page has to divide back into its own px. */
  height: calc(100vh / var(--zoom, 1));
  overflow: hidden;
  font-family: sans-serif;
}

/* Toolbar: one flat button per floating window, plus the separator before the
   two inspector windows. The buttons inside the windows share this look. */
#toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  padding: 5px 10px;
  background: #fafafa;
  border-bottom: 1px solid #e2e2e2;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  font: 13px system-ui, sans-serif;
  color: #333;
}

#toolbar select, #toolbar button,
.panelBody select, .panelBody button {
  height: 28px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

#toolbar select, .panelBody select { border-color: #d6d6d6; background: #fff; padding: 0 6px; }
#toolbar button:hover, .panelBody button:hover { background: #ececec; }
#toolbar button.active, .panelBody button.active { background: #e3ecff; border-color: #c4d5fb; color: #1f4fc4; }

.toolbar-sep { width: 1px; height: 20px; background: #e0e0e0; margin: 0 6px; }

/* Fixed width so the toolbar does not shift when ▶ and ⏸ swap. */
#playBtn { width: 32px; }

#timeLabel { min-width: 54px; padding: 0 4px; color: #777; font-variant-numeric: tabular-nums; }

/* min-height 0: as a flex item the canvas would otherwise keep at least the inline
   height three.js last gave it, so it could grow but never shrink back — entering
   fullscreen on a phone left it taller than the page. */
#canvas { flex: 1; display: block; min-height: 0; margin-left: var(--readme-w, 0px); }

/* The scene's readme, docked left over 35 % of the window; the canvas and the overlay layer
   start right of it (app.js toggles .readme-open on <html> and resizes). */
html.readme-open { --readme-w: calc(35vw / var(--zoom, 1)); }
#readme {
  display: none; position: fixed; top: var(--toolbar-h); left: 0; bottom: 0; width: var(--readme-w);
  box-sizing: border-box; flex-direction: column; padding: 0 0 12px 22px; z-index: 10;
  background: #fafafa; border-right: 1px solid #e0e0e0; font-size: 15px; line-height: 1.45; color: #222;
}
.readme-open #readme { display: flex; }
#readmeText, #readmeDock { flex: 1; min-height: 0; overflow: auto; padding-right: 18px; }
/* Two tabs: the text (Readme) and the docked live cards (Live); data-tab on #readme picks one. */
#readme[data-tab="text"] #readmeDock, #readme[data-tab="dock"] #readmeText { display: none; }
/* A docked card is as wide as its content, at least the column; a wider one scrolls sideways. */
#readmeDock > div { width: max-content !important; min-width: 100%; }
#readmeText:empty::before { content: 'No readme for this scene.'; }
#readmeDock:empty::before { content: 'Nothing live in this scene.'; }
#readmeText:empty::before, #readmeDock:empty::before { color: #888; display: block; margin-top: 10px; }
#readmeTabs { display: flex; gap: 4px; padding: 6px 18px 6px 0; border-bottom: 1px solid #e0e0e0; }
#readmeTabs button { padding: 3px 12px; border: 1px solid transparent; border-radius: 6px; background: none; font: inherit; font-size: 14px; cursor: pointer; }
#readme[data-tab="text"] [data-tab="text"], #readme[data-tab="dock"] [data-tab="dock"] { background: #e3ecff; border-color: #c4d5fb; color: #1f4fc4; }
#readme h1 { font-size: 21px; margin: 10px 0 8px; }
#readme h2 { font-size: 16px; margin: 18px 0 4px; color: #0b4f8a; }
#readme p, #readme ul, #readme ol { margin: 6px 0; }
#readme ul, #readme ol { padding-left: 22px; }
#readme a { color: #1f4fc4; }
#overlays { position: fixed; top: 0; right: 0; bottom: 0; left: var(--readme-w, 0px); pointer-events: none; z-index: 20; }
/* Every finger on the drawing is ours (app.js) or the camera's, never a page
   scroll or a browser zoom — including the labels lying over it: a lecture card
   is large, and a swipe that starts on it used to move the page instead. */
#canvas, .pickable-label { touch-action: none; }

/* Floating panels (Properties, Objects, add-on windows). */
.panel {
  position: fixed;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  font-size: 13px;
  /* Above everything else on screen, including a screen-overlay latex label
     (z-index 20, set inline in objects/latex.js) and the CSS2D label layer. */
  z-index: 30;
}

/* Copy stack, newest on top; hidden while empty. */
#clipStack { position: fixed; right: 12px; bottom: 12px; max-width: 240px; font-size: 11px; color: #666;
  background: rgba(255,255,255,0.85); border: 1px solid #ccc; border-radius: 4px; padding: 4px 8px; }
#clipStack:empty { display: none; }
#clipStack div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#clipStack div:first-child { color: #222; font-weight: bold; }

/* Default places: the two inspector windows side by side at the top left, the
   command windows in one column down the top right. All of them are draggable
   from there — a drag writes left/top, which wins over the right below.
   Every top is measured from the toolbar, whose height app.js keeps in
   --toolbar-h: it grows a second row on a narrow screen, and a window must not
   land on the buttons that open it. */
:root { --toolbar-h: 38px; --top0: calc(var(--toolbar-h) + 10px); }
#props { top: var(--top0); left: 12px; width: 210px; }
#propsFields { max-height: calc(100vh / var(--zoom, 1) - var(--top0) - 70px); overflow-y: auto; }
#browser { top: var(--top0); left: 230px; width: 160px; }
/* A deep tree indents past the panel width — scroll it rather than wrap names. */
#browserList { max-height: calc(100vh / var(--zoom, 1) - var(--top0) - 70px); overflow: auto; }

/* One width for the whole right column, and tops that clear the window above. */
#scenePanel, #selPanel, #camPanel, #timePanel, #filePanel { right: 12px; width: 244px; }
#scenePanel { top: var(--top0); }
#selPanel   { top: calc(var(--top0) + 144px); }
#camPanel   { top: calc(var(--top0) + 248px); }
#timePanel  { top: calc(var(--top0) + 424px); }
#filePanel  { top: calc(var(--top0) + 504px); }

/* Window contents: rows of buttons, a select stretching to fill its row. */
.panelBody { display: flex; flex-direction: column; gap: 4px; padding: 6px; }
.panelRow { display: flex; align-items: center; gap: 2px; }
.panelRow select { flex: 1; min-width: 0; }
.rowLabel { font-size: 11px; color: #888; text-transform: uppercase; padding-right: 2px; }

/* One line on the current selection, kept to the window width. */
#selInfo { padding: 2px 4px; color: #777; font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Title bar; also the drag handle (makeDraggable). */
.panelHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  background: #f0f0f0;
  border-bottom: 1px solid #ccc;
  border-radius: 4px 4px 0 0;
  cursor: move;
  font-weight: bold;
  user-select: none;
  touch-action: none; /* the drag is ours (makeDraggable), not a page scroll */
}

.panelHeader button { border: none; background: none; cursor: pointer; font-size: 14px; }

#props > p { padding: 8px 10px; color: #888; }

#propsFields {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#propsFields strong { font-size: 11px; color: #888; text-transform: uppercase; }
#propsFields label { display: flex; justify-content: space-between; align-items: center; }
#propsFields .heading, #fileDialog .heading { font-size: 11px; color: #888; text-transform: uppercase; margin-bottom: 3px; }
/* The JS property a row edits (obj.<key>), for use in Code blocks. */
.key { margin-left: 5px; font: 10px monospace; color: #aaa; text-transform: none; }

/* Row states, weakest first — a later rule of equal specificity wins, so the
   order here is what decides which highlight you see on a row that is several
   things at once (a selected group you have also entered). */
.browserItem { padding: 5px 10px; cursor: pointer; user-select: none; white-space: nowrap; }
.browserItem.group { font-weight: bold; background: #f5f5f5; font-size: 12px; }
.browserItem:hover { background: #f0f0f0; }
/* The group you have entered — its members are what the canvas lets you click.
   Warm, so it reads as "you are here" rather than as a second selection. */
.browserItem.entered { background: #fdf0d5; box-shadow: inset 3px 0 0 #d79a1e; }
/* Selection wins the background; an entered row keeps its marker bar. */
.browserItem.sel { background: #e0e8ff; }
.browserItem.sel.entered { background: #dde6ff; }
/* Fixed width so names line up whether or not a row has a twisty. */
.browserTwisty { display: inline-block; width: 12px; color: #888; }
.browserTwisty:hover { color: #333; }

/* Export / Import dialog, and the Bug report dialog */
#fileDialog, #bugDialog {
  margin: auto; width: 360px; padding: 16px;
  border: 1px solid #ccc; border-radius: 8px; box-shadow: 0 8px 30px rgba(0,0,0,0.2);
  font: 13px system-ui, sans-serif;
}
#fileDialog::backdrop, #bugDialog::backdrop { background: rgba(0,0,0,0.15); }
#fileDialog h3, #bugDialog h3 { font-size: 15px; margin-bottom: 12px; }
#bugDialog { width: 440px; max-width: calc(100vw / var(--zoom, 1) - 32px); }
#bugDialog p { line-height: 1.45; }
#bugDialog .fileActions { flex-wrap: wrap; }
#dbSection { margin-top: 12px; }
#fileNameRow { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
#fileName { flex: 1; }
#fileList, #dbList { max-height: 200px; overflow-y: auto; border: 1px solid #e2e2e2; border-radius: 6px; padding: 4px; color: #888; }
.fileItem { display: flex; justify-content: space-between; align-items: center; color: #333; border-radius: 4px; }
.fileItem:hover { background: #f0f0f0; }
.fileItem span { flex: 1; padding: 4px 6px; cursor: pointer; }
.fileItem button { border: none; background: none; color: #999; cursor: pointer; padding: 2px 6px; }
.fileActions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 14px; }
.fileActions button { white-space: nowrap; padding: 5px 10px; border: 1px solid #d0d0d0; border-radius: 6px; background: #fff; cursor: pointer; }
.fileActions button:hover { background: #f0f0f0; }

/* CSS2D labels from Three.js */
.label3d {
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
  font-size: 15px;
}

/* Opens the selected object's code in the code editor add-on. */
#codeEditBtn { float: right; border: none; background: none; cursor: pointer; font-size: 13px; color: #666; }
#codeEditBtn:hover { color: #1f4fc4; }

/* Phones. The windows are laid out for a desktop: a fixed width, and two columns
   that together are wider than a narrow screen — which would leave the Objects
   window hanging off the right edge. Keep every window inside the screen and put
   that one under the Properties window instead of beside it. */
/* A finger is not a text cursor: a long press or a drag would select page text
   (the blue wash over the screen) and a tap flashes its own highlight. Text
   fields and the code editor keep selection. */
@media (pointer: coarse) {
  body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
  input, textarea, [contenteditable] { -webkit-user-select: text; user-select: text; }
}

/* Start screen (mobile.js): over everything, windows included — until Start. The rotate
   page: a touch device held upright, over the start screen and a running scene alike. Sizes
   are divided by --zoom so both look the same at any page zoom; a long note scrolls. One
   language shows, by html[data-ui-lang] (mobile.js). */
#startScreen, #rotateScreen { display: none; position: fixed; inset: 0; z-index: 100; flex-direction: column;
  align-items: center; justify-content: safe center; overflow-y: auto; padding: calc(20px / var(--zoom, 1));
  background: #f4f6f8; font: calc(15px / var(--zoom, 1)) system-ui, sans-serif; color: #2c3e50; }
#startCard { max-width: 44em; background: #fff; border-radius: 10px; box-shadow: 0 2px 14px rgba(0, 0, 0, 0.08);
  padding: 1.6em 2em; }
#startTitle { font-size: 1.9em; font-weight: 600; color: #0081c7; }
#startSub { margin: 0.1em 0 0.9em; padding-bottom: 0.7em; border-bottom: 1px solid #e3e8ec;
  font-size: 0.8em; letter-spacing: 0.08em; text-transform: uppercase; color: #7f8c8d; }
.startText { line-height: 1.5; text-align: justify; hyphens: auto; }
.startText p { margin: 0 0 0.7em; }
.startText strong { font-weight: 600; }
#startBtns { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.8em; margin-top: 1.1em; }
#startBtns button { font: 1.15em system-ui, sans-serif; padding: 0.5em 1.6em; border-radius: 6px; cursor: pointer;
  border: 1px solid #0081c7; background: #fff; color: #0081c7; }
#startBtns #startBtn { background: #0081c7; color: #fff; }
html:not(.started) #startScreen { display: flex; }
#rotateScreen { z-index: 101; gap: 0.8em; font-size: calc(20px / var(--zoom, 1)); text-align: center; color: #0081c7; }
#rotateScreen div { color: #2c3e50; }
@media (orientation: portrait) { html.touch #rotateScreen { display: flex; } }
html[data-ui-lang="de"] :is(#startScreen, #rotateScreen, #bugDialog) [lang="en"],
html[data-ui-lang="en"] :is(#startScreen, #rotateScreen, #bugDialog) [lang="de"] { display: none; }
/* A phone in landscape (~390 px tall): small enough that note and buttons fit without scrolling. */
@media (max-height: 500px) {
  #startScreen { font-size: calc(11.5px / var(--zoom, 1)); padding: calc(8px / var(--zoom, 1)); }
  #startCard { max-width: 56em; padding: 0.8em 1.6em; }
  #startTitle { font-size: 1.5em; }
  #startSub { margin-bottom: 0.5em; padding-bottom: 0.4em; }
  .startText { line-height: 1.35; }
  .startText p { margin-bottom: 0.45em; }
  #startBtns { margin-top: 0.6em; }
}
/* No page zoom by pinch or double tap anywhere (iOS ignores user-scalable=no);
   lists in the windows still scroll. The canvas and labels have none at all. */
html.touch { touch-action: pan-x pan-y; }

@media (max-width: 480px) {
  .panel { max-width: calc(100vw / var(--zoom, 1) - 24px); }
  #browser { left: 12px; top: calc(var(--top0) + 292px); }
}
