/* Dash styles: Manager's look (zinc + emerald, dark), v12 layout. Landscape first: header cards in one row and two columns (timeline | 2x3 gauges) on tablet landscape / desktop (max ~1100 px), one column up to ~680 px on tablet portrait, a stacked view-only layout on phones; 44 px+ touch targets, 100dvh and safe-area insets. */
:root {
  --zinc-200: #e4e4e7; --zinc-300: #d4d4d8; --zinc-400: #a1a1aa; --zinc-500: #71717a; --zinc-700: #3f3f46; --zinc-800: #27272a; --zinc-900: #18181b; --zinc-950: #09090b;
  --emerald-300: #6ee7b7; --emerald-400: #34d399; --emerald-600: #059669; --emerald-700: #047857; --teal-700: #0f766e;
  --red: #f87171; --red-600: #dc2626; --red-700: #b91c1c; --amber: #fbbf24; --amber-bg: rgba(251, 191, 36, 0.12); --blue: #60a5fa;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100dvh; background: var(--zinc-950); color: #fff; font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; font-size: 16px; -webkit-tap-highlight-color: transparent; }
.app { min-height: 100dvh; display: flex; flex-direction: column; }
h2 { margin: 0 0 0.5rem; font-size: 1.05rem; }
.muted { color: var(--zinc-400); }
.small { font-size: 0.85rem; }
[hidden] { display: none !important; }
.loading { padding: 2rem; text-align: center; }

/* ----- buttons (Manager) ----- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; min-height: 44px; padding: 0 1.1rem; border-radius: 0.7rem; border: 2px solid transparent; font: inherit; font-weight: 700; text-decoration: none; cursor: pointer; color: #fff; white-space: nowrap; background: none; }
.btn.small { padding: 0 0.8rem; font-size: 0.9rem; }
.btn.big { min-height: 56px; padding: 0 1.4rem; font-size: 1.05rem; }
.btn.primary { background: var(--emerald-700); border-color: var(--emerald-600); }
.btn.secondary { background: var(--zinc-800); border-color: var(--zinc-700); }
.btn.ghost { color: var(--zinc-300); }
.btn.ghost:hover { background: var(--zinc-800); }
.btn.danger-fill { background: var(--red-700); border-color: var(--red-600); }
.btn:active:not([disabled]) { transform: scale(0.98); }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.btn:focus-visible, .seg-btn:focus-visible, .ev-select:focus-visible { outline: 3px solid var(--emerald-300); outline-offset: 2px; }

/* ----- top bar ----- */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 0.8rem; padding: max(8px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left)); background: rgba(9, 9, 11, 0.95); border-bottom: 1px solid var(--zinc-800); backdrop-filter: blur(6px); }
.brand { display: flex; align-items: center; gap: 0.5rem; color: #fff; text-decoration: none; font-weight: 800; font-size: 1.1rem; min-height: 44px; flex: none; }
.brand img { width: 4.5rem; }
.ev-select { min-height: 44px; min-width: 0; max-width: 26rem; flex: 0 1 26rem; padding: 0 0.7rem; border-radius: 0.6rem; border: 1px solid var(--zinc-700); background: var(--zinc-900); color: #fff; font: inherit; font-weight: 600; color-scheme: dark; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 0.4rem; }
.seg { display: inline-flex; border: 1px solid var(--zinc-700); border-radius: 0.6rem; overflow: hidden; }
.seg-btn { min-height: 44px; min-width: 44px; padding: 0 0.6rem; border: 0; background: transparent; color: var(--zinc-300); font: inherit; font-weight: 700; cursor: pointer; }
.seg-btn.on { background: var(--emerald-700); color: #fff; }

/* ----- page ----- */
.page { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 0.75rem max(16px, env(safe-area-inset-right)) 0.5rem max(16px, env(safe-area-inset-left)); display: flex; flex-direction: column; gap: 0.75rem; }
.panel { background: var(--zinc-900); border: 1px solid var(--zinc-800); border-radius: 1rem; padding: 0.9rem 1rem; min-width: 0; }
.message { text-align: center; padding: 2rem 1rem; width: 100%; max-width: 560px; margin: 2rem auto; }
.empty-note { margin: 1.5rem 0; text-align: center; }
.warn-banner { padding: 0.7rem 1rem; border-radius: 0.75rem; background: var(--amber-bg); border: 1px solid var(--amber); color: var(--amber); font-weight: 600; }
.foot { text-align: center; color: var(--zinc-500); font-size: 0.8rem; padding: 0.5rem 1rem max(0.6rem, env(safe-area-inset-bottom)); }

/* info line */
.infobar { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.badge { display: inline-block; padding: 0.15rem 0.6rem; border-radius: 999px; font-size: 0.78rem; font-weight: 700; background: var(--zinc-800); color: var(--zinc-300); }
.badge.st-active { background: rgba(52, 211, 153, 0.15); color: var(--emerald-300); }
.badge.st-active::before { content: ''; display: inline-block; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--emerald-400); margin-right: 0.35rem; vertical-align: 0.05rem; }
.badge.st-planned { background: rgba(96, 165, 250, 0.15); color: var(--blue); }
.badge.demo { background: var(--amber-bg); color: var(--amber); }
.view-only-note { flex-basis: 100%; margin: 0; font-size: 0.85rem; color: var(--zinc-300); background: var(--zinc-900); border: 1px dashed var(--zinc-700); border-radius: 0.6rem; padding: 0.5rem 0.7rem; }

/* header cards (v12): EVENT | STARTED | ENDED | TIME LAPSE | Start / End event */
.cards { display: grid; grid-template-columns: minmax(0, 2.2fr) minmax(0, 1.4fr) minmax(0, 1.4fr) minmax(0, 1fr) auto; gap: 0.6rem; }
.card { display: flex; flex-direction: column; justify-content: center; gap: 0.2rem; min-height: 72px; padding: 0.6rem 0.9rem; border-radius: 0.9rem; background: var(--zinc-900); border: 1px solid var(--zinc-800); min-width: 0; }
.card-label { font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--zinc-400); font-weight: 700; }
.card-value { font-size: 1.05rem; font-weight: 800; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-event .card-value { font-size: 1.2rem; }
.card-sub { font-size: 0.8rem; }
.c-lapse { background: var(--teal-700); border-color: #14b8a6; text-align: center; align-items: center; }
.c-lapse .card-label { color: #ccfbf1; }
.c-lapse .card-value { font-size: 1.5rem; }
.card-actions { display: flex; flex-direction: column; gap: 0.4rem; justify-content: center; }
.card-actions .btn.big { min-height: 48px; font-size: 1rem; }

/* main area */
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.75rem; }
.p-timeline { display: flex; flex-direction: column; }
.chart { position: relative; flex: 1 1 0; min-height: 260px; touch-action: pan-y; }
.chart svg { display: block; position: absolute; inset: 0; } /* out of the flow, so the box size comes from the layout only */
.chart .grid line { stroke: var(--zinc-800); }
.chart .ax { fill: var(--zinc-400); font-size: 11px; }
.chart .ht { stroke: var(--zinc-400); stroke-dasharray: 5 5; }
.chart .cursor { stroke: var(--zinc-500); }
.tip { position: absolute; z-index: 2; width: 170px; padding: 0.5rem 0.6rem; border-radius: 0.6rem; background: rgba(24, 24, 27, 0.96); border: 1px solid var(--zinc-700); font-size: 0.8rem; pointer-events: none; }
.tip div { display: flex; align-items: center; gap: 0.35rem; }
.legend { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.3rem 1rem; margin-bottom: 0.4rem; font-size: 0.8rem; color: var(--zinc-300); }
.legend ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.25rem 0.8rem; }
.legend li { display: inline-flex; align-items: center; gap: 0.3rem; }
.legend i, .tip i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; }
.legend-markers { color: var(--zinc-400); }

/* gauges */
.gauges { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.55rem; }
.gauge { display: flex; flex-direction: column; align-items: center; padding: 0.5rem 0.4rem 0.55rem; border-radius: 0.8rem; background: var(--zinc-950); border: 1px solid var(--zinc-800); text-align: center; min-width: 0; }
.gauge h3 { margin: 0 0 0.1rem; font-size: 0.9rem; }
.arc-wrap { position: relative; width: 100%; max-width: 130px; }
.arc { display: block; width: 100%; height: auto; }
.played { position: absolute; left: 0; right: 0; bottom: -0.1rem; font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.of { margin: 0.15rem 0 0; font-size: 0.78rem; color: var(--zinc-400); }
.left { font-weight: 700; color: var(--zinc-500); }
.left.has-left { color: var(--amber); }
.gauge .btn.launch { margin-top: 0.35rem; min-height: 44px; min-width: 7rem; padding: 0 0.9rem; background: var(--emerald-700); border-color: var(--emerald-600); font-size: 0.95rem; }
.done-pill { margin-top: 0.35rem; display: inline-flex; align-items: center; justify-content: center; min-height: 44px; min-width: 7rem; padding: 0 0.9rem; border-radius: 0.6rem; background: var(--zinc-800); color: var(--zinc-400); font-weight: 700; font-size: 0.9rem; }

/* tablet landscape / desktop: two columns, the screen fits one view */
@media (min-width: 900px) and (min-height: 501px) and (orientation: landscape) {
  .grid2 { grid-template-columns: minmax(0, 1.55fr) minmax(330px, 1fr); flex: 1; min-height: 0; }
  .chart { min-height: 240px; }
  .gauges { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.45rem; }
  .gauge { padding: 0.35rem 0.3rem 0.45rem; }
  .gauge .btn.launch, .done-pill { min-width: 0; width: 100%; padding: 0 0.3rem; }
  .grid2 { grid-template-columns: minmax(0, 1.45fr) minmax(360px, 1fr); }
  .arc-wrap { max-width: 104px; }
  .played { font-size: 1.3rem; }
  .gauge .btn.launch { margin-top: 0.25rem; }
  .done-pill { margin-top: 0.25rem; }
  .panel { padding: 0.75rem 0.9rem; }
  .card { min-height: 66px; }
}

/* tablet portrait: one column up to ~680 px, cards in two rows */
@media (orientation: portrait) and (min-width: 700px) {
  .page { max-width: 712px; }
  .cards { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr); }
  .c-event { grid-column: 1 / -1; }
  .card-actions { grid-column: 1 / -1; flex-direction: row; }
  .card-actions .btn { flex: 1; }
  .chart { min-height: 360px; }
  .gauges { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* any not-landscape-wide layout below 900 px that is not portrait tablet (e.g. small landscape windows) */
@media (max-width: 899px) and (orientation: landscape) and (min-height: 501px) {
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .c-event, .card-actions { grid-column: 1 / -1; }
  .card-actions { flex-direction: row; }
  .card-actions .btn { flex: 1; }
  .gauges { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* phones: stacked, view-only (no editing controls are rendered) */
@media (max-width: 699px), (orientation: landscape) and (max-height: 500px) {
  .topbar { flex-wrap: wrap; gap: 0.4rem 0.6rem; }
  .brand img { width: 3.6rem; }
  .ev-select { order: 3; flex: 1 1 100%; max-width: none; }
  .hide-phone { display: none; }
  .cards { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0.45rem; }
  .c-event, .c-lapse { grid-column: 1 / -1; }
  .card { min-height: 60px; padding: 0.5rem 0.7rem; }
  .card-value { font-size: 0.95rem; }
  .c-lapse .card-value { font-size: 1.2rem; }
  .chart { min-height: 260px; }
  .gauges { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .played { font-size: 1.25rem; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .gauges { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* toasts + confirm */
#toasts { position: fixed; z-index: 50; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 0.4rem; width: min(92vw, 520px); }
.toast { padding: 0.75rem 1rem; border-radius: 0.7rem; background: var(--zinc-800); border: 1px solid var(--zinc-700); color: #fff; font-weight: 600; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); }
.modal-wrap { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 1rem; background: rgba(0, 0, 0, 0.6); }
.modal { width: min(460px, 100%); padding: 1.3rem; border-radius: 1rem; background: var(--zinc-900); border: 1px solid var(--zinc-700); }
.modal h2 { font-size: 1.25rem; }
.modal-actions { display: flex; gap: 0.6rem; justify-content: flex-end; margin-top: 1rem; flex-wrap: wrap; }
@media (prefers-reduced-motion: reduce) { .btn:active { transform: none !important; } }

/* game control (host.js): one compact row on landscape, wraps elsewhere */
.host { padding: 0.55rem 0.9rem; }
.host h2 { margin: 0; white-space: nowrap; }
.host-row { display: flex; align-items: center; gap: 0.5rem 0.8rem; flex-wrap: wrap; }
.host-note { margin: 0.2rem 0 0; }
.host-ev { flex: 0 1 14rem; }
.host-evname { font-weight: 700; color: var(--zinc-300); }
.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip { min-height: 44px; padding: 0 0.75rem; border-radius: 999px; border: 1px solid var(--zinc-700); background: var(--zinc-950); color: #fff; font: inherit; font-weight: 600; font-size: 0.9rem; cursor: pointer; }
.chip.on { background: var(--emerald-700); border-color: var(--emerald-400); }
.chip[disabled] { opacity: 0.4; cursor: not-allowed; }
.chip small { color: var(--zinc-400); font-weight: 500; }
.host .btn.big { min-height: 48px; }
.host-status { font-weight: 700; color: var(--zinc-400); font-variant-numeric: tabular-nums; }
.host-status.countdown { color: var(--amber); font-size: 1.15rem; }
.host-status.running { color: var(--emerald-300); }
