/* The plot-first page shared by the newer demos (String, Notes and clangs):
   the IA Mechanics rule that the picture is most of the screen and the
   controls fit round it. Phones upright: bar, plot, strip, then the deck
   underneath. Anything wider than tall: the deck is a column beside the
   plot. Markup: #app > #bar, #stage (one #plot-wrap, or .plots holding
   several .plot-wrap), #strip, #deck; #help-overlay. Theme tokens only. */

:root {
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
}

html, body { height: 100%; overflow: hidden; }

#app {
  display: grid;
  grid-template-areas: 'bar' 'stage' 'deck';
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100dvh;
  padding: var(--sat) var(--sar) var(--sab) var(--sal);
}

/* ---------- bar ---------- */
#bar {
  grid-area: bar;
  display: flex; align-items: center; flex-wrap: wrap; gap: 0.4rem 0.7rem;
  padding: 0.45rem 0.7rem;
  border-bottom: 1px solid var(--line);
}
.chip {
  font: 500 0.72rem/1 var(--font-mono); color: var(--accent);
  border: 1px solid var(--accent-border); border-radius: 4px; padding: 0.3rem 0.45rem; text-decoration: none;
}
#title { margin: 0; font-size: 1.1rem; font-weight: 600; }
#tabs { display: flex; gap: 0.15rem; margin-left: 0.4rem; }
#tabs button {
  font: 500 0.95rem/1 var(--font-ui); color: var(--text-dim);
  background: none; border: 0; padding: 0.45rem 0.65rem; border-radius: var(--radius-sm); cursor: pointer; position: relative;
}
#tabs button:hover { color: var(--text); }
#tabs button[aria-pressed='true'] { color: var(--accent); }
#tabs button[aria-pressed='true']::after { content: ''; position: absolute; left: 0.65rem; right: 0.65rem; bottom: 0.1rem; height: 2px; background: var(--accent); border-radius: 1px; }
#bar .end { margin-left: auto; display: flex; gap: 0.3rem; }

/* ---------- stage ---------- */
#stage { grid-area: stage; display: flex; flex-direction: column; min-height: 0; min-width: 0; padding: 0.5rem 0.6rem 0; }
#plot-wrap, .plot-wrap { position: relative; flex: 1; min-height: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-inset); overflow: hidden; }
.plots { flex: 1; min-height: 0; display: grid; grid-auto-rows: minmax(0, 1fr); gap: 0.5rem; }
.plot-wrap canvas, #plot { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.layers { position: absolute; top: 0.5rem; right: 0.5rem; display: flex; gap: 0.35rem; }
.layer {
  font: 500 0.72rem/1 var(--font-mono); color: var(--text-faint);
  background: var(--pill); border: 1px solid var(--line); border-radius: 999px; padding: 0.35rem 0.6rem; cursor: pointer;
}
.layer[aria-pressed='true'] { color: var(--accent); border-color: var(--accent-border); }
.hint {
  position: absolute; left: 0.7rem; top: 0.65rem; margin: 0; pointer-events: none;
  font: 500 0.78rem/1.3 var(--font-ui); color: var(--text-faint);
}

#strip { display: flex; align-items: center; gap: 0.5rem; padding: 0.45rem 0 0.4rem; min-height: 3rem; }
#btn-play { min-width: 3rem; font-size: 0.95rem; }
.pillwrap { position: relative; }
.pill {
  font: 500 0.8rem/1 var(--font-mono); color: var(--text); background: var(--bg-raised);
  border: 1px solid var(--line-strong); border-radius: 999px; padding: 0.45rem 0.7rem; cursor: pointer;
}
.pill[aria-expanded='true'] { border-color: var(--accent); color: var(--accent); }
.pop {
  position: absolute; bottom: calc(100% + 0.5rem); left: 0; z-index: 20;
  display: flex; align-items: center; gap: 0.6rem; padding: 0.6rem 0.8rem;
  background: var(--sheet); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: var(--sheet-shadow);
}
.pop input { width: 11rem; }
.ro { font: 500 0.78rem/1 var(--font-mono); color: var(--text-dim); white-space: nowrap; }
.ro.dim { color: var(--text-faint); }
.time { margin-left: auto; }

/* ---------- deck ---------- */
#deck { grid-area: deck; padding: 0.2rem 0.8rem 0.7rem; min-width: 0; }
#deck section { display: grid; gap: 0.55rem; }
.row { display: grid; grid-template-columns: 4.2rem minmax(0, 1fr) 4.6rem; align-items: center; gap: 0.6rem; }
.row label { font: 600 0.9rem/1 var(--font-ui); color: var(--text-dim); }
.row label sub { font-size: 0.7em; }
.row .ro { text-align: right; }
.row input[type='range'] { width: 100%; }

/* ---------- help ---------- */
#help-overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 1rem; background: var(--scrim); }
#help-card { width: min(32rem, 100%); max-height: min(84dvh, 42rem); display: flex; flex-direction: column; background: var(--sheet); }
#help-card header { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 1rem; border-bottom: 1px solid var(--line); }
#help-card h3 { margin: 0; font-size: 1rem; font-weight: 600; }
#help-body { overflow-y: auto; padding: 0.3rem 1.1rem 0.4rem; font-size: 0.95rem; line-height: 1.55; color: var(--text-dim); }
#help-body b { color: var(--text); }
#help-card .fbline { margin: 0 1.1rem 1rem; }
/* Every sheet: the app's title with its tab as a sub-line, and long material folded under "More"
   (Tore, 5 Oct, review D7). Was copied into each app's own css; one place keeps them the same. */
#help-card header .htitle { display: grid; gap: 0.15rem; }
#help-card header .sub { margin: 0; font: 500 0.78rem/1.2 var(--font-ui); color: var(--text-dim); }
#help-body details { margin: 0.9rem 0 0.5rem; border-top: 1px solid var(--line); }
#help-body summary { cursor: pointer; padding: 0.75rem 0 0.3rem; font-weight: 600; color: var(--accent); }
#help-body sup, #help-body sub { line-height: 0; }
#help-body:focus { outline: none; }

/* ---------- wider than tall: the deck becomes a column beside the plot ---------- */
@media (min-aspect-ratio: 1/1) and (min-width: 640px) {
  #app { grid-template-areas: 'bar bar' 'stage deck'; grid-template-columns: minmax(0, 1fr) 19rem; grid-template-rows: auto minmax(0, 1fr); }
  #deck { padding: 0.7rem 0.8rem; overflow-y: auto; border-left: 1px solid var(--line); }
  #stage { padding-bottom: 0.2rem; }
}
/* a phone lying down: everything slimmer */
@media (max-height: 520px) and (min-aspect-ratio: 1/1) {
  #bar { padding: 0.25rem 0.6rem; }
  #title { display: none; }
  #app { grid-template-columns: minmax(0, 1fr) 16rem; }
  #strip { min-height: 2.6rem; padding: 0.3rem 0; }
}
@media (max-width: 420px) {
  #title { display: none; }
  #tabs { margin-left: 0; }
}

/* the speed button (shared/js/ui/speed.js): a fixed width so the strip does not jump as it changes */
.speed { font: 600 0.85rem/1 var(--font-mono); min-width: 3.2rem; padding: 0.45rem 0.6rem; border-radius: 999px; }
