:root {
  --bg: #000;
  --panel: #111;
  --panel-border: #333;
  --text: #eee;
  --muted: #aaa;
  --accent: #fff;
  --accent-text: #111;
  --ok: #4cd08a;
  --warn: #f0b14a;
  --err: #ff6b6b;
  --gutter: 16px;
  --radius: 6px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}
#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  background: #000;
}
#canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
  outline: none;
  touch-action: none;
}
#stage.fixed-aspect {
  display: flex;
  align-items: center;
  justify-content: center;
}
#stage.fixed-aspect #canvas {
  flex: none;
  width: min(100vw, 100dvh * 16 / 9);
  height: min(100dvh, 100vw * 9 / 16);
}
@media (orientation: portrait) {
  #stage.fixed-aspect { align-items: flex-start; }
}
.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--gutter);
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
  overflow-y: auto;
  background: var(--bg);
}
.overlay-modal { z-index: 30; background: #000b; }
#error { z-index: 40; }
.panel {
  width: 100%;
  max-width: 460px;
  margin: auto;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
}
.panel-wide { max-width: 680px; }
#loader { background: #000; }
.loader-panel {
  max-width: 400px;
  padding: 28px;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.spinner { width: 32px; height: 32px; margin: auto; border: 3px solid #333; border-top-color: #eee; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }
#loader #checks { display: none; }
html[data-phase="incompatible"] #loader #checks { display: grid; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
h1 { margin: 0 0 4px; font-size: 1.9rem; letter-spacing: 0.01em; }
h2 { margin: 0; font-size: 1.35rem; }
h3 { margin: 20px 0 6px; font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
p { margin: 0 0 10px; }
.tagline { color: var(--muted); margin-bottom: 18px; }
.hint { color: var(--muted); font-size: 0.875rem; }
.status { margin: 10px 0 0; color: var(--muted); font-size: 0.9rem; min-height: 1.4em; overflow-wrap: anywhere; }
.checks { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 6px; }
.checks li { display: flex; gap: 10px; align-items: baseline; font-size: 0.95rem; }
.checks .mark { flex: none; width: 1.2em; text-align: center; font-weight: 700; }
.checks .ok .mark { color: var(--ok); }
.checks .fail .mark { color: var(--err); }
.checks .detail { color: var(--muted); font-size: 0.85rem; }
.notice { padding: 10px 12px; border-radius: 8px; border: 1px solid; font-size: 0.925rem; overflow-wrap: anywhere; }
.notice-error { background: rgba(255, 107, 107, 0.1); border-color: rgba(255, 107, 107, 0.45); }
.notice-warn { background: rgba(240, 177, 74, 0.1); border-color: rgba(240, 177, 74, 0.45); }
#error-summary { white-space: pre-line; max-height: 40vh; overflow-y: auto; }
button { font: inherit; cursor: pointer; }
button:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary {
  display: block;
  width: 100%;
  margin-top: 18px;
  padding: 10px 14px;
  border: 0;
  border-radius: 4px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  font-size: 1.05rem;
}
.primary:hover { filter: brightness(1.08); }
.row .primary { width: auto; margin-top: 0; padding: 9px 16px; font-size: 1rem; }
.chip {
  padding: 7px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  background: #111d;
  color: var(--text);
  font-size: 0.875rem;
}
.chip:hover { border-color: var(--accent); }
.toolbar {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  z-index: 20;
  display: flex;
  gap: 8px;
  opacity: 0.55;
  transition: opacity 0.2s;
}
.toolbar:hover, .toolbar:focus-within { opacity: 1; }
.toolbar.idle:not(:hover):not(:focus-within) { opacity: 0; }
@media (prefers-reduced-motion: reduce) { .toolbar { transition: none; } }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; }
.table-wrap { overflow-x: auto; margin: 10px 0; }
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--panel-border); }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 1px 6px;
  border: 1px solid var(--panel-border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: #222;
  font: 0.85em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-align: center;
}
.details {
  display: block;
  width: 100%;
  height: min(40vh, 320px);
  padding: 10px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: #111;
  color: var(--text);
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  resize: vertical;
  white-space: pre;
  overflow: auto;
}
@media (max-width: 480px) {
  .panel { padding: 18px; }
  h1 { font-size: 1.6rem; }
  .toolbar { gap: 6px; }
}
.primary + .hint { margin-top: 10px; }
.product-heading { font-size: 1.05rem; margin: 0 0 10px; color: var(--muted); font-weight: 600; }
.products { display: grid; gap: 10px; margin-bottom: 6px; }
.product {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 12px 16px;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  text-align: left;
  color: var(--text);
  background: #181818;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  cursor: pointer;
  overflow-wrap: anywhere;
}
.product:hover { border-color: var(--accent); }
.product:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.product.last { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.product-tag {
  flex: none;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
}
.linklike {
  display: block;
  margin: 14px 0 0;
  padding: 0;
  font: inherit;
  font-size: 0.875rem;
  color: var(--muted);
  background: none;
  border: 0;
  text-decoration: underline;
  cursor: pointer;
}
.linklike:hover, .linklike:focus-visible { color: var(--text); }
.pad-list { margin: 6px 0 10px; padding-left: 1.2em; }
.pad-list li { margin: 2px 0; overflow-wrap: anywhere; }
.pad-list li.hint { list-style: none; margin-left: -1.2em; }
.toggle { display: flex; align-items: flex-start; gap: 8px; margin: 12px 0 4px; font-size: 0.925rem; cursor: pointer; }
.toggle input { margin-top: 0.3em; flex: none; }
.debug-panel {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  z-index: 25;
  width: min(760px, calc(100% - 2 * var(--gutter)));
  max-height: min(70vh, 560px);
  overflow: auto;
  padding: 10px 12px;
  background: #111e;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  font-size: 0.85rem;
}
.debug-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.debug-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px; }
.debug-cols > div { min-width: 0; }
.debug-panel h4 { margin: 0 0 4px; font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.debug-panel pre {
  margin: 0;
  padding: 6px 8px;
  background: #181818;
  border-radius: 6px;
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
  overflow-x: auto;
}
.touch {
  --s: var(--touch-scale, 1);
  --edge-l: max(12px, env(safe-area-inset-left));
  --edge-r: max(12px, env(safe-area-inset-right));
  --edge-b: max(12px, env(safe-area-inset-bottom));
  --edge-t: max(10px, env(safe-area-inset-top));
  position: absolute;
  inset: 0;
  z-index: 15;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  opacity: var(--touch-opacity, 0.6);
}
.touch-zone, .touch-btn { pointer-events: auto; touch-action: none; }
.touch-zone {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 45%;
  height: 65%;
}
.touch-stick {
  position: absolute;
  left: calc(var(--edge-l) + 76px * var(--s));
  top: calc(100% - var(--edge-b) - 76px * var(--s));
  width: calc(112px * var(--s));
  height: calc(112px * var(--s));
  margin: calc(-56px * var(--s)) 0 0 calc(-56px * var(--s));
  border-radius: 50%;
  border: 1px solid #ffffff80;
  background: #0008;
  pointer-events: none;
}
.touch-stick.active { border-color: rgba(255, 255, 255, 0.85); }
.touch-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(52px * var(--s));
  height: calc(52px * var(--s));
  margin: calc(-26px * var(--s)) 0 0 calc(-26px * var(--s));
  border-radius: 50%;
  background: #ddd;
}
.touch-btn {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  width: calc(var(--d) * var(--s));
  height: calc(var(--d) * var(--s));
  border-radius: 50%;
  border: 1px solid #ffffff80;
  background: #000a;
  color: #fff;
  font: 500 calc(var(--f, 15px) * var(--s)) / 1 system-ui, sans-serif;
  cursor: default;
}
.touch-btn.held { background: rgba(232, 236, 244, 0.85); color: #0b0d12; text-shadow: none; }
.touch-a     { --d: 92px; --f: 28px; right: calc(var(--edge-r) + 26px * var(--s)); bottom: calc(var(--edge-b) + 34px * var(--s)); }
.touch-b     { --d: 64px; --f: 22px; right: calc(var(--edge-r) + 128px * var(--s)); bottom: calc(var(--edge-b) + 8px * var(--s)); }
.touch-r     { --d: 68px; right: calc(var(--edge-r) + 120px * var(--s)); bottom: calc(var(--edge-b) + 92px * var(--s)); }
.touch-l     { --d: 64px; right: calc(var(--edge-r) + 34px * var(--s)); bottom: calc(var(--edge-b) + 138px * var(--s)); }
.touch-trick { --d: 56px; --f: 13px; right: calc(var(--edge-r) + 206px * var(--s)); bottom: calc(var(--edge-b) + 40px * var(--s)); }
.touch-a.latched { border: 3px solid #fff; }
.touch-start, .touch-menu, .touch-latch {
  --d: 40px;
  --f: 13px;
  top: var(--edge-t);
  border-radius: 4px;
}
.touch-menu  { --f: 18px; left: var(--edge-l); }
.touch-start { width: calc(72px * var(--s)); left: calc(var(--edge-l) + 50px * var(--s)); }
.touch-latch { width: calc(72px * var(--s)); left: calc(var(--edge-l) + 132px * var(--s)); }
@media (orientation: portrait) {
  .touch-trick { right: calc(var(--edge-r) + 128px * var(--s)); bottom: calc(var(--edge-b) + 178px * var(--s)); }
}
.touch-on .toolbar { top: calc(var(--toolbar-top, max(10px, env(safe-area-inset-top))) + 50px); flex-wrap: wrap; justify-content: flex-end; max-width: calc(100% - 2 * var(--gutter)); }
.touch-on .toolbar .chip { padding: 5px 10px; }
.touch-on .toolbar.idle:not(:focus-within) { opacity: 0; pointer-events: none; }
.touch-settings { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 14px; align-items: center; margin: 10px 0 4px; font-size: 0.925rem; }
.touch-settings select, .touch-settings input[type="range"] { width: 100%; max-width: 320px; }
.touch-settings select {
  padding: 6px 8px;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  background: #222;
  color: var(--text);
  font: inherit;
}
