:root {
  --bg: #0b0d12;
  --bg2: #11141b;
  --card: #161a23;
  --line: #262c3a;
  --text: #eef1f7;
  --mute: #98a2b8;
  --accent: #5b8cff;
  --accent2: #9a6bff;
  --good: #2fd27a;
  --warn: #f5a524;
  --bad: #ff5d6c;
  --r: 16px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); overscroll-behavior: none; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; touch-action: manipulation; }
h1 { font-size: 28px; line-height: 1.15; letter-spacing: -0.02em; margin: 0; font-weight: 700; }
p { margin: 0; }
.grow { flex: 1; }
.row { display: flex; align-items: center; gap: 12px; }

#app { min-height: 100%; }
#shell {
  min-height: 100dvh; display: flex; flex-direction: column;
  padding: calc(var(--sat) + 14px) calc(var(--sar) + 20px) calc(var(--sab) + 20px) calc(var(--sal) + 20px);
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(154, 107, 255, 0.16), transparent 60%),
    radial-gradient(800px 480px at 0% 0%, rgba(91, 140, 255, 0.16), transparent 60%),
    var(--bg);
}

.brand { display: flex; align-items: center; gap: 10px; height: 44px; }
.mark {
  width: 28px; height: 28px; border-radius: 9px; position: relative; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 6px 20px rgba(91, 140, 255, 0.35);
}
.mark::before {
  content: ""; position: absolute; left: 8px; top: 13px; width: 13px; height: 2.5px; border-radius: 2px;
  background: #fff; transform: rotate(-45deg);
}
.mark::after { content: ""; position: absolute; right: 6px; top: 6px; width: 5px; height: 5px; border-radius: 50%; background: #fff; }
.word { font-weight: 700; font-size: 19px; letter-spacing: -0.01em; }

.view { flex: 1; width: 100%; max-width: 980px; margin: 0 auto; padding-top: 22px; }
.view.center { display: flex; flex-direction: column; justify-content: center; align-items: stretch; max-width: 440px; gap: 22px; padding-bottom: 10vh; }
.hero { text-align: center; display: grid; gap: 10px; justify-items: center; }
.sub { color: var(--mute); max-width: 34ch; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; }
.stack { display: grid; gap: 12px; }
.msg { color: var(--mute); font-size: 14px; min-height: 1.3em; }
.msg.bad { color: var(--bad); }
.msg.good { color: var(--good); }

.primary, .danger, .ghost {
  min-height: 48px; padding: 0 18px; border-radius: 13px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; box-shadow: 0 8px 24px rgba(91, 140, 255, 0.3); }
.primary:active { transform: translateY(1px); filter: brightness(0.95); }
.primary:disabled { opacity: 0.55; box-shadow: none; }
.ghost { color: var(--mute); min-height: 40px; padding: 0 12px; }
.ghost:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.danger { background: rgba(255, 93, 108, 0.14); color: var(--bad); border: 1px solid rgba(255, 93, 108, 0.3); }
.wide { width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

textarea {
  width: 100%; resize: vertical; font: inherit; color: var(--text); background: var(--bg2); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; min-height: 48px;
}
textarea::placeholder { color: #5f6880; }

.steps { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.steps li { padding-left: 30px; position: relative; color: var(--mute); }
.steps li::before {
  content: ""; position: absolute; left: 4px; top: 5px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line);
}
.steps li.doing { color: var(--text); }
.steps li.doing::before { border-color: var(--accent); border-top-color: transparent; animation: spin 0.8s linear infinite; }
.steps li.done { color: var(--text); }
.steps li.done::before { background: var(--good); border-color: var(--good); }

.lock {
  width: 64px; height: 64px; border-radius: 20px; background: var(--card); border: 1px solid var(--line); position: relative;
}
.lock::before { content: ""; position: absolute; left: 21px; top: 12px; width: 22px; height: 22px; border: 3px solid var(--mute); border-bottom: 0; border-radius: 12px 12px 0 0; }
.lock::after { content: ""; position: absolute; left: 16px; top: 30px; width: 32px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, var(--accent), var(--accent2)); }

.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- machine list ---- */
.head { margin-bottom: 18px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.machine {
  text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 18px; display: grid; gap: 14px;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease; position: relative; overflow: hidden;
}
.machine.on { cursor: pointer; }
.machine.on:hover, .machine.on:focus-visible { border-color: rgba(91, 140, 255, 0.6); box-shadow: 0 10px 34px rgba(0, 0, 0, 0.4); transform: translateY(-2px); }
.machine.on:active { transform: translateY(0); }
.machine .screen {
  aspect-ratio: 16 / 9; border-radius: 12px; background: linear-gradient(145deg, #1c2233, #121623); border: 1px solid var(--line);
  display: grid; place-items: center; color: #47506a; font-weight: 700; letter-spacing: 0.08em; font-size: 12px; text-transform: uppercase;
}
.machine.on .screen { background: linear-gradient(145deg, rgba(91, 140, 255, 0.28), rgba(154, 107, 255, 0.2)); color: #cdd8ff; border-color: rgba(91, 140, 255, 0.35); }
.machine .meta { display: flex; align-items: center; gap: 10px; }
.machine .nm { font-weight: 650; font-size: 18px; letter-spacing: -0.01em; }
.machine .st { display: inline-flex; align-items: center; gap: 7px; color: var(--mute); font-size: 14px; }
.machine .st::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: #4b5468; }
.machine.on .st { color: var(--good); }
.machine.on .st::before { background: var(--good); box-shadow: 0 0 0 4px rgba(47, 210, 122, 0.16); }
.machine .go { margin-left: auto; color: var(--accent); font-weight: 600; }
.machine:not(.on) .go { color: #4b5468; }
.foot { margin-top: 28px; color: #5f6880; font-size: 13px; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- session ---- */
#session { position: fixed; inset: 0; background: #000; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
#stage { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: none; }
#stage.mouse { cursor: default; }
#pic { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
#rv, #rc { position: absolute; inset: 0; width: 100%; height: 100%; display: block; background: #000; pointer-events: none; }
#rc.off, #rv.off { visibility: hidden; }
#cursor {
  position: absolute; width: 16px; height: 16px; margin: -1px 0 0 -1px; pointer-events: none; z-index: 3;
  background: conic-gradient(from 135deg at 0 0, #fff 0 45deg, transparent 0); filter: drop-shadow(0 0 1.5px #000) drop-shadow(0 1px 2px rgba(0, 0, 0, 0.7));
  clip-path: polygon(0 0, 0 100%, 30% 72%, 52% 100%, 68% 92%, 46% 64%, 80% 64%);
  background: #fff;
}
#ring { position: absolute; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%; border: 3px solid var(--accent); pointer-events: none; z-index: 3; animation: pop 0.25s ease-out; }
@keyframes pop { from { transform: scale(0.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

#veil { position: absolute; inset: 0; display: grid; place-content: center; gap: 14px; text-align: center; background: rgba(8, 10, 14, 0.86); color: var(--mute); z-index: 5; padding: 24px; }
#veil.gone { display: none; }

.bar {
  position: absolute; z-index: 10; top: calc(var(--sat) + 8px); left: 50%; transform: translateX(-50%);
  max-width: calc(100vw - var(--sal) - var(--sar) - 16px);
  display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 18px;
  background: rgba(18, 21, 30, 0.82); border: 1px solid rgba(255, 255, 255, 0.09);
  -webkit-backdrop-filter: blur(18px) saturate(1.4); backdrop-filter: blur(18px) saturate(1.4);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.5); overflow-x: auto; scrollbar-width: none;
}
.bar::-webkit-scrollbar { display: none; }
.bar.hide { display: none; }
.ib { min-width: 40px; height: 40px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 0 10px; color: #d6dcec; flex: none; font-size: 14px; font-weight: 550; }
.ib:hover, .ib.on { background: rgba(255, 255, 255, 0.09); color: #fff; }
.ib.on { background: rgba(91, 140, 255, 0.24); color: #dbe6ff; }
.ib svg { width: 19px; height: 19px; flex: none; }
.who { display: grid; padding: 0 8px 0 2px; line-height: 1.15; flex: none; }
.who .name { font-weight: 650; font-size: 14px; white-space: nowrap; }
.chip { font-size: 11.5px; color: var(--mute); white-space: nowrap; }
.chip.good { color: var(--good); }
.chip.warn { color: var(--warn); }
.seg { display: inline-flex; background: rgba(255, 255, 255, 0.06); border-radius: 11px; padding: 3px; gap: 2px; flex: none; }
.seg button { height: 34px; padding: 0 12px; border-radius: 9px; font-size: 14px; font-weight: 550; color: var(--mute); white-space: nowrap; }
.seg button.on { background: rgba(255, 255, 255, 0.14); color: #fff; }
#bar-tab {
  position: absolute; z-index: 10; top: calc(var(--sat) + 4px); left: 50%; transform: translateX(-50%); width: 64px; height: 22px; border-radius: 0 0 12px 12px;
  background: rgba(18, 21, 30, 0.7); border: 1px solid rgba(255, 255, 255, 0.1);
}
#bar-tab::after { content: ""; display: block; width: 26px; height: 4px; border-radius: 2px; background: #8d97ad; margin: 0 auto; }

#kbd { position: absolute; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; min-height: 0; padding: 0; border: 0; font-size: 16px; z-index: 1; resize: none; }

.sheet {
  position: absolute; z-index: 12; left: 50%; transform: translateX(-50%); bottom: calc(var(--sab) + 10px);
  width: min(720px, calc(100vw - var(--sal) - var(--sar) - 16px)); max-height: 70dvh; overflow: auto;
  background: rgba(18, 21, 30, 0.92); border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 20px; padding: 12px; display: grid; gap: 10px;
  -webkit-backdrop-filter: blur(20px) saturate(1.4); backdrop-filter: blur(20px) saturate(1.4); box-shadow: 0 18px 50px rgba(0, 0, 0, 0.6);
}
.sheet-head { display: flex; align-items: center; padding: 0 4px; }
.krow { display: flex; flex-wrap: wrap; gap: 6px; }
.k { min-width: 46px; height: 44px; padding: 0 12px; border-radius: 11px; background: rgba(255, 255, 255, 0.08); font-size: 14px; font-weight: 550; color: #e3e8f5; }
.k:active { background: rgba(255, 255, 255, 0.18); }
.k.on { background: var(--accent); color: #fff; }
.k.accent { background: rgba(91, 140, 255, 0.26); color: #dbe6ff; }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 2px 4px; color: #cfd6e6; font-size: 15px; }

@media (max-width: 620px) {
  h1 { font-size: 24px; }
  .ib.lab span { display: none; }
  .who .name { max-width: 22vw; overflow: hidden; text-overflow: ellipsis; }
  .seg button { padding: 0 9px; font-size: 13px; }
  #b-displays { display: none; }
  .bar { left: calc(var(--sal) + 8px); right: calc(var(--sar) + 8px); transform: none; max-width: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation-duration: 0.01ms !important; transition: none !important; } }
