/* host.css -- the DIYgasm host shell. Brand: diygasm/web docs/BRAND.md (forced dark, flat 0.2rem radius,
   Big Shoulders Display + Inter + Dancing Script accent, brand blue #3495fd). Single theme by choice. */
:root {
  color-scheme: dark;
  --bg: #1e1e1e;
  --surface: #242424;
  --surface-2: #2d2d2d;
  --surface-3: #383838;
  --blue: #3495fd;
  --blue-hover: #2a86e8;
  --blue-light: #5c83fa;
  --blue-glow: rgba(52, 149, 253, 0.14);
  --gold: #d9a441;
  --text: #ffffff;
  --text-2: #9e9e9e;
  --text-3: #8e8e8e;
  --border: #424242;
  --border-soft: #383838;
  --ok: #4caf50;
  --warn: #ff9800;
  --err: #f44336;
  --r: 0.2rem;
  /* Faces are vendored under fonts/ (fonts.css); the fallbacks cover missing glyphs. */
  --font-body: 'Inter', 'Segoe UI', system-ui, sans-serif;
  --font-display: 'Big Shoulders Display', 'Arial Narrow', Impact, sans-serif;
  --font-mono: ui-monospace, 'Cascadia Mono', Consolas, monospace;

  --strip: 56px; /* rail width (landscape) = bar height (portrait) */
  --btn: 44px; /* minimum touch target */
  --trust-h: 32px;
}

* { box-sizing: border-box; }
/* `hidden` must win over any component display rule (a .stop-note display:flex once showed it while hidden). */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font-body);
  overflow: hidden;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }

/* ---- layout: portrait = bar on top, landscape = rail on the left ---- */
.host {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr);
}
.stage {
  display: grid;
  grid-template-rows: var(--trust-h) minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  padding-right: env(safe-area-inset-right, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
}

/* ---- the strip: DOM order = button order (STOP first) ---- */
.strip {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-soft);
  padding: calc(env(safe-area-inset-top, 0px) + 6px) calc(env(safe-area-inset-right, 0px) + 6px) 6px calc(env(safe-area-inset-left, 0px) + 6px);
  min-height: var(--strip);
  z-index: 10; /* above the app area; nothing a child draws can reach it (the frame is clipped to the area) */
}
.strip-spacer { flex: 1 1 auto; }
.strip-btn {
  position: relative;
  flex: none;
  width: var(--btn);
  height: var(--btn);
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r);
  color: var(--text-2);
  cursor: pointer;
}
.strip-btn:hover { background: var(--surface-3); color: var(--text); }
.strip-btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.strip-btn[aria-current='page'] { background: var(--blue-glow); border-color: var(--blue); color: var(--blue); }
.strip-btn .ic { width: 22px; height: 22px; }

/* STOP: host-drawn, red, the largest target in the strip, never hidden by any state. */
.strip-stop {
  width: 64px;
  background: var(--err);
  color: #fff;
  font: 800 13px/1 var(--font-body);
  letter-spacing: 0.06em;
  border-color: var(--err);
}
.strip-stop:hover { background: #d32f2f; color: #fff; }
.strip-stop:active { background: #b71c1c; }
html[data-stopped='true'] .strip-stop { box-shadow: 0 0 0 3px rgba(244, 67, 54, 0.35); }

.strip-dot {
  position: absolute;
  right: 7px;
  bottom: 7px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 2px solid var(--surface-2);
}
.strip-dot-on { background: var(--ok); }
.strip-dot-off { background: var(--text-3); }

.strip-app-ic {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: var(--r);
  background: var(--surface-3);
  color: var(--text);
  font: 700 11px/1 var(--font-body);
}
.strip-badge {
  position: absolute;
  top: 3px;
  right: 3px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font: 700 10px/16px var(--font-body);
  text-align: center;
}

/* Landscape: the same strip turned on its side. Rail bottom = bar left (E21), so column-reverse. */
@media (orientation: landscape) {
  .host { grid-template-rows: minmax(0, 1fr); grid-template-columns: auto minmax(0, 1fr); }
  .strip {
    flex-direction: column-reverse;
    min-height: 0;
    min-width: var(--strip);
    border-bottom: 0;
    border-right: 1px solid var(--border-soft);
    padding: calc(env(safe-area-inset-top, 0px) + 6px) 6px calc(env(safe-area-inset-bottom, 0px) + 6px) calc(env(safe-area-inset-left, 0px) + 6px);
    overflow-y: auto;
  }
  .strip-stop { width: var(--btn); height: 64px; }
  .stage { padding-left: 0; padding-top: env(safe-area-inset-top, 0px); }
}

/* ---- trust line (H3 A): host-drawn, outside the app area ---- */
.trust {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  border-bottom: 1px solid var(--border-soft);
}
.trust-maker { color: var(--text-2); }
.tbadge {
  font: 700 10px/1 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 5px;
  border-radius: var(--r);
}
.tbadge-off { background: var(--blue-glow); color: var(--blue); }
.tbadge-comm { background: rgba(217, 164, 65, 0.18); color: var(--gold); }

/* ---- the app area: the rectangle handed to the child ---- */
.app-area {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  contain: strict;
}
.placeholder {
  position: absolute;
  inset: 12px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--border);
  border-radius: var(--r);
  color: var(--text-3);
  font: 800 1.6rem/1 var(--font-display);
  letter-spacing: 0.01em;
}

/* ---- STOP note: over the app area, never over the strip ---- */
.stop-note {
  position: fixed;
  right: calc(env(safe-area-inset-right, 0px) + 12px);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--err);
  border-radius: var(--r);
  padding: 10px 12px;
  font-size: 14px;
}
.stop-note button {
  min-height: var(--btn);
  padding: 0 14px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--r);
  cursor: pointer;
}

.area-debug {
  position: fixed;
  right: 8px;
  bottom: 8px;
  z-index: 20;
  font: 11px/1.3 var(--font-mono);
  background: rgba(0, 0, 0, 0.75);
  color: var(--blue);
  padding: 4px 6px;
  border-radius: var(--r);
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---- app area layers: frames (bottom), host view, tray, sheets (top). A child frame can only paint inside its own
   iframe box, so nothing below can cover the strip, the trust line, the tray or a host sheet. ---- */
.frames, .host-view, .sheets { position: absolute; inset: 0; }
.frames { z-index: 1; }
.app-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: var(--bg); }
.host-view { z-index: 2; overflow-y: auto; padding: 12px 12px 24px; background: var(--bg); }
.sheets { z-index: 4; pointer-events: none; }
.sheets > * { pointer-events: auto; }
.trust-spacer { flex: 1 1 auto; }
.trust-close { min-height: 28px; padding: 0 10px; background: transparent; color: var(--text-2); border: 1px solid var(--border); border-radius: var(--r); cursor: pointer; font-size: 12px; }
.dim { color: var(--text-3); }

.view-h { font: 800 1.5rem/1 var(--font-display); letter-spacing: 0.01em; margin: 6px 0 10px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); gap: 10px; margin-bottom: 18px; }
.tile { position: relative; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--r); overflow: hidden; min-width: 0; }
.tile-running { border-color: var(--blue); }
.tile-cover { position: relative; aspect-ratio: 16 / 9; background: var(--surface-3); }
.tile-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-icon { position: absolute; left: 10px; bottom: -16px; width: 40px; height: 40px; border-radius: var(--r); border: 2px solid var(--surface); background: var(--surface-2); overflow: hidden; }
.tile-icon img { width: 100%; height: 100%; display: block; }
.tile-body { display: flex; flex-direction: column; gap: 4px; padding: 22px 10px 10px; min-width: 0; }
.tile-head { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tile-name { margin: 0; font: 600 15px/1.2 var(--font-body); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-maker { font-size: 12px; color: var(--text-2); }
.tile-actions { display: flex; gap: 6px; margin-top: 6px; }
.glyphs { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 3px; }
.gl { width: 22px; height: 22px; display: grid; place-items: center; border-radius: var(--r); background: rgba(30, 30, 30, 0.9); border: 1px solid var(--border); font-size: 12px; line-height: 1; }

.btn { min-height: var(--btn); padding: 0 14px; background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--r); cursor: pointer; font-weight: 600; font-size: 14px; }
.btn-pri { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-pri:hover { background: var(--blue-hover); }
.btn-s { min-height: var(--btn); min-width: var(--btn); padding: 0 8px; font-size: 13px; }
.btn:focus-visible, .tray-sw:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }

.st { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.st-line { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 12px; color: var(--text-2); }
.st-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.st-age { color: var(--text-3); margin-left: auto; flex: none; }
.st-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--text-3); }
.st-ok { background: var(--ok); }
.st-busy { background: var(--blue); }
.st-attention { background: var(--warn); }
.st-idle { background: var(--text-3); }
.st-warn { color: var(--warn); font-size: 12px; }
.st-bar { height: 4px; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
.st-bar span { display: block; height: 100%; background: var(--blue); }
.st-spark { width: 100%; height: 16px; }
.st-spark path { fill: none; stroke: var(--blue); stroke-width: 1.4; }

/* layers tray: opens out of the strip's Layers button, inside the app area */
.tray { position: absolute; z-index: 3; left: 8px; top: 8px; width: min(360px, calc(100% - 16px)); max-height: calc(100% - 16px); overflow-y: auto; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); padding: 10px; display: flex; flex-direction: column; gap: 8px; box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45); }
.tray-h { margin: 0; font: 800 1.1rem/1 var(--font-display); }
.tray-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; grid-template-areas: "main up sw show"; align-items: center; column-gap: 6px; row-gap: 2px; }
.tray-main { grid-area: main; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.tray-up { grid-area: up; }
.tray-sw-wrap { grid-area: sw; display: grid; place-items: center; width: var(--btn); height: var(--btn); }
.tray-show { grid-area: show; }
.tray-drive { grid-template-columns: auto minmax(0, 1fr); grid-template-areas: none; column-gap: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.tray-k { color: var(--text-2); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; }
.tray-name { font-weight: 600; }
.tray-sw { width: 26px; height: 26px; margin: 0; accent-color: var(--blue); cursor: pointer; }
.tray-sw-wrap { cursor: pointer; }

/* sheets: H4 B consent, switch, optional */
.sheet-back { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); display: grid; place-items: end center; padding: 12px; }
.sheet { width: min(520px, 100%); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.sheet-title { margin: 0; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font: 600 16px/1.3 var(--font-body); }
.sheet-sub { margin: 0; color: var(--text-2); font-size: 14px; }
.sheet-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 3px; }
.sheet-opt { display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: var(--btn); font-size: 14px; }
.sheet-opt input { width: 22px; height: 22px; accent-color: var(--blue); }
.sheet-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* device view */
.dev-rig { display: flex; gap: 20px; align-items: stretch; flex-wrap: wrap; }
.dev-rail { position: relative; width: 56px; height: min(60vh, 420px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); }
.dev-bounds { position: absolute; left: 4px; right: 4px; border: 1px dashed var(--border); border-radius: var(--r); }
.dev-carriage { position: absolute; left: 6px; right: 6px; height: 20px; background: var(--blue); border-radius: var(--r); }
html[data-stopped='true'] .dev-carriage { background: var(--err); }
.dev-side { display: flex; flex-direction: column; gap: 10px; min-width: 200px; }
.dev-state { margin: 0; font-weight: 600; }
.dev-knob { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--text-2); }
.dev-knob input { accent-color: var(--blue); min-height: var(--btn); }

/* developer mode (item 4): host-drawn, red, outside the app area */
.stage { grid-template-rows: auto var(--trust-h) minmax(0, 1fr); }
.dev-banner { background: var(--err); color: #fff; font: 600 12px/1 var(--font-body); padding: 6px 12px; letter-spacing: 0.02em; }
.tbadge-dev { background: var(--err); color: #fff; }
.set-box { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 10px; max-width: 640px; }
.set-h { margin: 0; font: 600 16px/1.2 var(--font-body); }
.dev-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.dev-in { min-height: var(--btn); background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: var(--r); padding: 0 10px; font: inherit; width: 9rem; }
.dev-in:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.dev-msg { margin: 0; color: var(--warn); font-size: 13px; min-height: 1em; }
.dev-banner { grid-row: 1; }
.trust { grid-row: 2; }
.app-area { grid-row: 3; }
a.btn { display: inline-grid; place-items: center; text-decoration: none; justify-self: start; align-self: flex-start; }

/* Android shell (ANDROID-SEAM v1): the native strip replaces the web strip; the WebView is the app area */
html[data-embedded='android'] #strip { display: none; }
html[data-embedded='android'] .host { grid-template-rows: minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); }
.set-box + .set-box { margin-top: 12px; }
/* static pages (download) */
body.page { overflow: auto; }
.page-main { max-width: 640px; margin: 0 auto; padding: 24px 16px 48px; display: flex; flex-direction: column; gap: 10px; }
.page-main ul { margin: 0; padding-left: 18px; }
