/* Every colour is a token: light values first, the dark ones redefine them. Dark applies by the system setting unless
   the host page forces a theme with data-theme on the root element (data-theme="light" keeps the light values). */
:root {
  color-scheme: light;
  --fg: #151a21;
  --muted: #5d6776;
  --panel: rgba(255, 255, 255, 0.84);
  --panel-solid: #ffffff;
  --line: rgba(21, 26, 33, 0.12);
  --hover: rgba(21, 26, 33, 0.07);
  --accent: #2563d9;
  --accent-fg: #ffffff;
  --busy: #1f9d55;
  --wait: #c27803;
  --idle: #9aa3af;
  --strip: rgba(21, 26, 33, 0.1);
  --strip-on: rgba(37, 99, 217, 0.55);
  --shadow: 0 6px 24px rgba(15, 23, 42, 0.14);
  --page: #e6eaf0;
  --gap: 10px;
  --radius: 12px;
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --fg: #eef1f5;
    --muted: #9da7b5;
    --panel: rgba(24, 28, 35, 0.8);
    --panel-solid: #1b1f26;
    --line: rgba(255, 255, 255, 0.13);
    --hover: rgba(255, 255, 255, 0.09);
    --accent: #6ea8ff;
    --accent-fg: #0c1220;
    --busy: #4ccb86;
    --wait: #f0b142;
    --idle: #6f7986;
    --strip: rgba(255, 255, 255, 0.14);
    --strip-on: rgba(110, 168, 255, 0.7);
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
    --page: #14171c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --fg: #eef1f5;
  --muted: #9da7b5;
  --panel: rgba(24, 28, 35, 0.8);
  --panel-solid: #1b1f26;
  --line: rgba(255, 255, 255, 0.13);
  --hover: rgba(255, 255, 255, 0.09);
  --accent: #6ea8ff;
  --accent-fg: #0c1220;
  --busy: #4ccb86;
  --wait: #f0b142;
  --idle: #6f7986;
  --strip: rgba(255, 255, 255, 0.14);
  --strip-on: rgba(110, 168, 255, 0.7);
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  --page: #14171c;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; background: var(--page); color: var(--fg); -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.dim { color: var(--muted); }

#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }

/* ---- surfaces -------------------------------------------------------------------------------------------------- */
.caption, .tools, #panel, #transport, .menu, #toast, #loading .box {
  background: var(--panel);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

#top {
  position: fixed; z-index: 3;
  top: calc(var(--gap) + env(safe-area-inset-top)); left: calc(var(--gap) + env(safe-area-inset-left)); right: calc(var(--gap) + env(safe-area-inset-right));
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--gap); pointer-events: none;
}
#top > * { pointer-events: auto; }
.caption { padding: 8px 14px 9px; min-width: 0; }
.caption h1 { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: 0.01em; text-wrap: balance; }
.caption p { margin: 1px 0 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#scenario { color: var(--fg); font-weight: 550; }
.tools { display: flex; gap: 2px; padding: 4px; flex: none; }

button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.chip {
  border: 0; background: transparent; border-radius: 9px; padding: 7px 12px; min-height: 34px; font-weight: 550; display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover, .chip[aria-expanded="true"] { background: var(--hover); }
.chip.icon { padding: 7px 8px; }
.chip.icon[aria-pressed="true"] { color: var(--accent); }
.chip svg, .round svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chip svg circle { fill: var(--panel-solid); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- menus -------------------------------------------------------------------------------------------------------- */
.menu {
  position: fixed; z-index: 5; top: calc(60px + env(safe-area-inset-top)); right: calc(var(--gap) + env(safe-area-inset-right));
  width: min(280px, calc(100vw - 2 * var(--gap))); max-height: min(70vh, 560px); overflow: auto; padding: 6px; background: var(--panel-solid);
}
.menu h3 { margin: 8px 10px 4px; font-size: 11px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.menu button.item {
  display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 10px; text-align: left; border: 0; background: transparent; border-radius: 8px;
  padding: 8px 10px; min-height: 36px;
}
.menu button.item:hover { background: var(--hover); }
.menu button.item[aria-checked="true"] { color: var(--accent); font-weight: 600; }
.menu button.item[aria-checked="true"]::after { content: ""; width: 7px; height: 12px; border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-2px, -2px); flex: none; }
.menu kbd { font: inherit; font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
.menu p.hint { margin: 8px 10px; font-size: 12px; color: var(--muted); }

/* ---- status panel ---------------------------------------------------------------------------------------------------- */
#panel {
  position: fixed; z-index: 2; right: calc(var(--gap) + env(safe-area-inset-right)); top: calc(64px + env(safe-area-inset-top));
  width: 320px; max-height: calc(100vh - 64px - 96px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); overflow: auto; padding: 12px;
  max-height: calc(100dvh - 64px - 96px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  font-variant-numeric: tabular-nums;
}
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { min-width: 0; }
.tile b { display: block; font-size: 22px; font-weight: 650; line-height: 1.15; letter-spacing: -0.01em; }
.tile span { display: block; font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now { margin-top: 10px; font-size: 12.5px; }
.now .meter { height: 4px; border-radius: 2px; background: var(--strip); margin-top: 5px; overflow: hidden; }
.now .meter i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 2px; }
#panel h2 { margin: 14px 0 6px; font-size: 11px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.machines { list-style: none; margin: 0; padding: 0; }
.machines li { display: grid; grid-template-columns: 9px 1fr; column-gap: 8px; align-items: baseline; padding: 3px 0; }
.machines .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--idle); align-self: center; }
.machines li[data-state="busy"] .dot { background: var(--busy); }
.machines li[data-state="wait"] .dot { background: var(--wait); }
.machines .name { font-weight: 550; }
.machines .what { grid-column: 2; font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; min-height: 1.4em; }      /* a sentence; a long one may take a second line */
details { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; }
summary { cursor: pointer; font-size: 12.5px; color: var(--muted); }
dl { display: grid; grid-template-columns: 1fr auto; gap: 3px 12px; margin: 8px 0 0; font-size: 12.5px; }
dt { color: var(--muted); }
dd { margin: 0; text-align: right; }

/* ---- transport ------------------------------------------------------------------------------------------------------- */
#transport {
  position: fixed; z-index: 3; left: calc(var(--gap) + env(safe-area-inset-left)); right: calc(var(--gap) + env(safe-area-inset-right));
  bottom: calc(var(--gap) + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 10px; padding: 8px 14px 8px 8px;
}
.round { flex: none; width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; }
.round svg { fill: currentColor; stroke: none; width: 22px; height: 22px; }
.round:hover { filter: brightness(1.08); }
.speed select {
  appearance: none; -webkit-appearance: none; border: 1px solid var(--line); background: transparent; border-radius: 9px; padding: 6px 10px; min-height: 34px;
  font-weight: 600; font-variant-numeric: tabular-nums; text-align: center; text-align-last: center; cursor: pointer;
}
.speed select:hover { background: var(--hover); }
.speed option { background: var(--panel-solid); color: var(--fg); }
.clock { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 15px; flex: none; }
.clock.dim { font-weight: 500; font-size: 13px; }
.scrub { position: relative; flex: 1 1 auto; min-width: 60px; height: 34px; display: flex; align-items: center; }
.strip { position: absolute; left: 0; right: 0; top: 50%; height: 6px; margin-top: -3px; border-radius: 3px; background: var(--strip); pointer-events: none; }
#seek { position: relative; width: 100%; margin: 0; height: 34px; background: transparent; appearance: none; -webkit-appearance: none; cursor: pointer; }
#seek::-webkit-slider-runnable-track { height: 6px; background: transparent; border-radius: 3px; }
#seek::-moz-range-track { height: 6px; background: transparent; border-radius: 3px; }
#seek::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -5px; border-radius: 50%; background: var(--accent); border: 2px solid var(--panel-solid); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35); }
#seek::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 2px solid var(--panel-solid); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35); }

#toast {
  position: fixed; z-index: 6; left: 50%; transform: translateX(-50%); bottom: calc(var(--gap) + 76px + env(safe-area-inset-bottom));
  max-width: calc(100vw - 4 * var(--gap)); padding: 8px 14px; font-size: 13px; background: var(--panel-solid); text-align: center;
}

/* ---- loading and errors ------------------------------------------------------------------------------------------------ */
#loading { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; background: var(--page); transition: opacity 0.35s ease; }
#loading.done { opacity: 0; pointer-events: none; }
#loading .box { width: min(340px, calc(100vw - 40px)); padding: 18px 20px; }
#loading p { margin: 0; }
#loading-title { font-weight: 650; font-size: 15px; }
#loading-detail { font-size: 12.5px; margin-top: 8px !important; min-height: 1.4em; overflow-wrap: anywhere; }
.bar { height: 6px; border-radius: 3px; background: var(--strip); margin-top: 12px; overflow: hidden; }
.bar i { display: block; width: 0; height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.15s linear; }
#loading.error .bar { display: none; }
#loading.error #loading-title { color: #d0342c; }
.fatal { position: fixed; inset: 0; z-index: 11; display: grid; place-items: center; padding: 24px; text-align: center; background: var(--page); }

/* ---- small screens ----------------------------------------------------------------------------------------------------- */
/* narrow windows (phones held upright): compact chrome, the slider on its own row */
@media (max-width: 720px) {
  :root { --gap: 8px; font-size: 13.5px; }
  #top { flex-wrap: wrap; justify-content: flex-end; }                 /* the name and its note on a row of their own, the buttons under it */
  .caption { padding: 6px 10px 7px; flex: 1 1 100%; }
  .caption h1 { font-size: 13.5px; }
  .caption p { white-space: normal; }
  .chip { padding: 7px 9px; }
  .menu { top: calc(104px + env(safe-area-inset-top)); }
  #transport { gap: 8px; padding: 6px 10px 6px 6px; flex-wrap: wrap; }
  .round { width: 40px; height: 40px; }
  #duration { display: none; }
  .scrub { order: 5; flex-basis: 100%; height: 30px; }
  .clock { margin-left: auto; }
}
/* narrow and tall: the figures sit above the transport bar; the machine list opens on demand */
@media (max-width: 720px) and (min-height: 481px) {
  #panel {
    top: auto; left: calc(var(--gap) + env(safe-area-inset-left)); width: auto; bottom: calc(var(--gap) + 96px + env(safe-area-inset-bottom));
    max-height: 46vh; padding: 10px 12px;
  }
  #panel:not(.open) h2, #panel:not(.open) .machines, #panel:not(.open) details { display: none; }
  .tile b { font-size: 18px; }
}
/* short windows (phones held sideways): the figures stay top right, small; the machine list opens on demand */
@media (max-height: 480px) {
  .menu { max-height: calc(100vh - 70px); }
  #panel { top: calc(56px + env(safe-area-inset-top)); width: 304px; padding: 8px 10px; max-height: calc(100vh - 56px - 70px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
  #panel:not(.open) h2, #panel:not(.open) .machines, #panel:not(.open) details { display: none; }
  .tile b { font-size: 17px; }
  .now { margin-top: 6px; }
  #transport { padding-top: 5px; padding-bottom: 5px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
