:root {
  color-scheme: dark;
  --bg: #09090b;
  --elev: #141418;
  --elev-2: #1e1e24;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --mask: #ff3d6e;
  --danger: #ffb4b4;
  font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { min-height: 100dvh; }
button, input, select, textarea { font: inherit; color: inherit; }
button { min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--elev-2); padding: 0 12px; }
button.primary { background: var(--text); color: #111; border-color: transparent; font-weight: 650; }
button.text { background: transparent; border-color: transparent; color: var(--muted); }
button:disabled { opacity: 0.45; }
input, select, textarea {
  width: 100%;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0c0c0f;
  padding: 10px 12px;
  font-size: 16px;
}
textarea { resize: none; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.wordmark { font-family: Georgia, "Iowan Old Style", serif; font-size: 28px; margin: 0; letter-spacing: -0.04em; }
.lede, .fine, .message { color: var(--muted); }
.fine { font-size: 13px; line-height: 1.4; margin: 0; }
.message { min-height: 1.2em; color: var(--danger); }
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.card { width: min(420px, 100%); display: grid; gap: 12px; background: var(--elev); padding: 20px; border-radius: 20px; border: 1px solid var(--line); }
.card.flat { width: auto; }

#screen-app { height: 100dvh; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); }
header {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  padding-left: calc(12px + env(safe-area-inset-left));
  padding-right: calc(12px + env(safe-area-inset-right));
}
header .wordmark { font-size: 22px; margin-right: auto; }
.pill { margin: 0; color: var(--muted); font-size: 13px; }

#stage { position: relative; flex: 1; min-height: 0; background: #050506; }
#empty { height: 100%; display: grid; align-content: center; justify-items: center; gap: 14px; padding: 24px; text-align: center; }
#viewport { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
#world { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
#world canvas { position: absolute; top: 0; left: 0; }
#mask { pointer-events: none; }
.help, .status {
  position: absolute; left: 12px; right: 12px; z-index: 2;
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
  background: rgba(12, 12, 16, 0.88); border: 1px solid var(--line); border-radius: 14px; padding: 8px 10px;
}
.help { top: 10px; }
.status { bottom: 10px; margin: 0; }
.toolbar {
  display: grid; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--elev); border-top: 1px solid var(--line);
}
.row { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.grow { flex: 1; min-width: 140px; }
.stack { display: grid; gap: 6px; }
.segment { display: flex; gap: 4px; }
.segment button { min-width: 44px; padding: 0 10px; }
.segment button[aria-pressed="true"] { background: var(--text); color: #111; }

.sheet {
  position: fixed; inset: 0; z-index: 5; background: rgba(0, 0, 0, 0.55);
  display: grid; align-content: end;
}
.sheet-bar, .sheet .card, .list { background: var(--bg); }
.sheet-bar { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px env(safe-area-inset-top); }
.sheet-bar h2 { margin: 0; font-size: 18px; }
.list { max-height: 70dvh; overflow: auto; padding: 0 12px calc(16px + env(safe-area-inset-bottom)); display: grid; gap: 8px; }
.item { display: grid; grid-template-columns: 72px 1fr auto; gap: 10px; align-items: center; padding: 8px; border: 1px solid var(--line); border-radius: 14px; background: var(--elev); }
.item img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; background: #000; }
.item button { min-height: 36px; }
.switch { width: 100%; display: flex; justify-content: space-between; align-items: center; }
.knob { width: 44px; height: 26px; border-radius: 99px; background: #333; position: relative; }
.knob::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; }
.switch[aria-checked="true"] .knob { background: var(--mask); }
.switch[aria-checked="true"] .knob::after { left: 21px; }

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