/* Header, viewport, sidebar, footer. Tokens only - no literal colours.
   Class vocabulary matches Bench-Calculator, so css/patterns.css applies. */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font: 400 14px/1.5 var(--font);
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/*
 * The header carries three things and no more: keep this experiment, fetch one,
 * change the theme. Sharing and printing are things you do when you have
 * finished, so they live at the bottom with Reset, where they cannot crowd the
 * wordmark on a phone.
 */
.app-header {
  flex: 0 0 auto;
  height: var(--header-h);
  display: flex; align-items: center; gap: var(--space-4);
  padding: 0 var(--space-4);
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: relative; z-index: 20;
}

.brand { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.brand__home { display: inline-flex; align-items: center; text-decoration: none; }
.brand__logo { height: 26px; width: auto; display: block; border-radius: 5px; }
.brand__sep { width: 1px; height: 22px; background: var(--border); }
.brand__tool { font-weight: 600; color: var(--text-dim); white-space: nowrap; }
.header-actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }

.app-main {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--sidebar-w);
  min-height: 0;
}

/*
 * The left-hand column: the drawing and the transport, then everything the
 * experiment says back.
 *
 * Two sections rather than one, so that on a phone the sidebar can be placed
 * between them — see the `display: contents` rule at the bottom of this file.
 * On a wide screen the split is invisible: `.workspace` is the single scrolling
 * column, exactly as before.
 */
.workspace {
  display: flex; flex-direction: column; min-width: 0;
  overflow-y: auto;
}

.viewport {
  display: flex; flex-direction: column; min-width: 0;
  padding: var(--space-4); gap: var(--space-4);
}

.viewport--more { padding-top: 0; }

.viewport__stage {
  display: flex; align-items: center; justify-content: center;
  min-height: 300px;
  padding: var(--space-4);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  position: relative;
}

.viewport__stage > * { width: 100%; max-width: 900px; }

.sidebar {
  border-left: 1px solid var(--border);
  background: var(--panel);
  overflow-y: auto;
  display: flex; flex-direction: column;
}

.sidebar__foot {
  margin-top: auto;
  padding: var(--space-4);
  border-top: 1px solid var(--border);
}

.app-footer {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap;
  padding: var(--space-3) var(--space-4);
  background: var(--panel);
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-faint);
}

.app-footer nav { margin-left: auto; display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }

/* A link that reads as a link, sitting in a row of buttons without pretending
   to be one — it leaves the app, and it should not look like an action here. */
.linkish { color: var(--accent-strong); text-decoration: underline; text-underline-offset: 2px; }
.linkish:hover { text-decoration-thickness: 2px; }

/* A phone gets the drawing first and the controls under it. */
@media (max-width: 640px) {
  .viewport { padding: var(--space-3); gap: var(--space-3); }
  .viewport__stage { padding: var(--space-3) var(--space-2); min-height: 200px; }
  .app-footer { font-size: 11px; }
  .readout { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: var(--space-2); }
  .stat__value { font-size: 17px; }
}

@media (max-width: 1040px) {
  .app-main { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    border-left: none;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
  }
  .workspace, .viewport, .sidebar { overflow-y: visible; }
  body { height: auto; }

  /*
   * The inputs go directly under the drawing, above the graphs.
   *
   * `display: contents` dissolves the workspace so its two halves become grid
   * items of `.app-main` alongside the sidebar, which is the only way to place
   * the sidebar *between* them without a second copy of anything. Stacked the
   * other way, reaching a control meant scrolling past every graph, every
   * measurement and every teaching panel on the page.
   */
  .workspace { display: contents; }
  .viewport { order: 1; }
  .sidebar { order: 2; }
  .viewport--more { order: 3; }
}
