:root { --bg: #0b0d12; --glass: rgba(14, 18, 26, .78); --line: rgba(255,255,255,.09); --text: #e8edf4; --muted: #8893a4;
  --acc: #5eead4; --acc2: #22d3ee; --bad: #fb7185; --r: 14px; color-scheme: dark; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: #000; color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
button, select, input { font: inherit; color: inherit; }
.muted { color: var(--muted); } .small { font-size: 12px; } .err { color: var(--bad); min-height: 1.2em; margin: 4px 0 0; font-size: 13px; }

/* ---------- login ---------- */
body.login { display: grid; place-items: center; padding: 16px; min-height: 100dvh;
  background: radial-gradient(900px 500px at 70% -10%, #0e3b3b88, transparent 70%), radial-gradient(700px 400px at 0% 110%, #0c2a4466, transparent 70%), var(--bg); }
.login-card { width: min(380px, 100%); display: grid; gap: 14px; padding: 26px 24px 20px; border-radius: 22px; background: linear-gradient(180deg, #151a23f2, #10141bf2);
  border: 1px solid #ffffff14; box-shadow: 0 30px 80px #0009, 0 0 0 1px #5eead40f inset; }
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 6px; }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: .2px; } .brand p { margin: 0; color: var(--muted); font-size: 13px; }
.login label { display: grid; gap: 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.login input:not([type=checkbox]) { padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line); background: #0a0d13; font-size: 16px; outline: none; text-transform: none; letter-spacing: 0; }
.login input:focus { border-color: var(--acc); box-shadow: 0 0 0 3px #5eead422; }
#code { font-size: 24px; letter-spacing: .45em; text-align: center; font-variant-numeric: tabular-nums; }
.check { display: flex !important; align-items: center; gap: 8px; text-transform: none !important; letter-spacing: 0 !important; font-size: 13px !important; }
.check input { accent-color: var(--acc); width: 16px; height: 16px; }
.login button { padding: 13px; border: 0; border-radius: 12px; font-weight: 700; font-size: 15px; color: #03211e; cursor: pointer;
  background: linear-gradient(135deg, var(--acc), var(--acc2)); box-shadow: 0 10px 30px #22d3ee33; }
.login button:disabled { opacity: .6; }

/* ---------- app ---------- */
body.app { overflow: hidden; overscroll-behavior: none; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#stage { position: fixed; inset: 0; overflow: hidden; background: #000; }
#view { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
#screen { display: block; width: 100%; height: 100%; image-rendering: auto; }
body.hidecursor #stage { cursor: none; }

#curtain { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; background: radial-gradient(600px 400px at 50% 40%, #0f2a2c, #000);
  z-index: 50; transition: opacity .25s; }
#curtain.off { opacity: 0; pointer-events: none; }
#curtain p { margin: 0; color: var(--muted); }
#curtain button { padding: 10px 18px; border-radius: 10px; border: 1px solid var(--line); background: #151b24; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #5eead422; border-top-color: var(--acc); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* dock */
#dock { position: fixed; top: max(8px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 20; display: grid; justify-items: center; gap: 6px;
  max-width: calc(100vw - 16px); }
#handle { display: flex; align-items: center; gap: 8px; padding: 5px 12px 5px 9px; border-radius: 99px; border: 1px solid var(--line); background: var(--glass);
  backdrop-filter: blur(14px) saturate(1.4); -webkit-backdrop-filter: blur(14px) saturate(1.4); font: 12px/1 ui-monospace, "Cascadia Mono", Consolas, monospace; color: #b8c2d0; cursor: pointer; white-space: nowrap;
  box-shadow: 0 6px 24px #0007; opacity: .72; transition: opacity .2s; }
#handle:hover, #dock:not(.collapsed) #handle { opacity: 1; }
#handle .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--acc); box-shadow: 0 0 10px var(--acc); }
#handle.warn .dot { background: #fbbf24; box-shadow: 0 0 10px #fbbf24; } #handle.bad .dot { background: var(--bad); box-shadow: 0 0 10px var(--bad); }
#bar, #more { background: var(--glass); backdrop-filter: blur(18px) saturate(1.5); -webkit-backdrop-filter: blur(18px) saturate(1.5); border: 1px solid var(--line);
  border-radius: 18px; box-shadow: 0 16px 50px #000a; }
#bar { display: flex; align-items: center; gap: 4px; padding: 5px; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
#dock.collapsed #bar, #dock.collapsed #more { display: none; }
.grp { display: flex; gap: 2px; } .sep { width: 1px; align-self: stretch; margin: 6px 3px; background: var(--line); flex: none; }
#bar button, #bar select { display: grid; justify-items: center; gap: 2px; min-width: 52px; padding: 6px 8px 5px; border-radius: 12px; border: 0; background: transparent;
  color: #c9d2de; cursor: pointer; font-size: 10.5px; letter-spacing: .02em; flex: none; }
#bar button:hover { background: #ffffff0d; }
#bar button.on { background: #5eead41c; color: var(--acc); box-shadow: inset 0 0 0 1px #5eead430; }
#bar select { min-width: 0; appearance: none; -webkit-appearance: none; background: #ffffff0a; font-size: 12px; padding: 9px 10px; align-self: center; }
#bar i svg { width: 20px; height: 20px; display: block; }
.mon { font-weight: 700; font-size: 13px !important; }
.mon b { display: grid; place-items: center; width: 26px; height: 18px; border-radius: 4px; border: 1.5px solid currentColor; font-size: 11px; }
.mon small { font-size: 9.5px; opacity: .7; }
#more { padding: 12px 14px; display: grid; gap: 10px; width: min(360px, calc(100vw - 16px)); }
#more label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
#more label.check { display: flex; }
#more input[type=range] { accent-color: var(--acc); width: 100%; }
#more .row { display: flex; gap: 6px; flex-wrap: wrap; }
#more button { flex: 1; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: #ffffff08; cursor: pointer; white-space: nowrap; }
#more button.danger { color: var(--bad); }

/* special keys */
#keys { position: fixed; left: 0; right: 0; bottom: 0; z-index: 18; padding: 6px max(6px, env(safe-area-inset-left)) max(6px, env(safe-area-inset-bottom));
  background: linear-gradient(0deg, #05070bf0, #05070bcc); border-top: 1px solid var(--line); display: grid; gap: 5px; }
.krow { display: flex; gap: 5px; overflow-x: auto; scrollbar-width: none; }
.krow button { flex: 1 0 auto; min-width: 46px; padding: 10px 10px; border-radius: 9px; border: 1px solid #ffffff12; background: linear-gradient(180deg, #1c222d, #151a23);
  color: #d6dde7; font-size: 13px; cursor: pointer; box-shadow: 0 2px 0 #0009; }
.krow button:active, .krow button.held { transform: translateY(1px); background: #5eead42a; color: var(--acc); border-color: #5eead455; }
.krow button.sticky { background: #5eead41f; color: var(--acc); border-color: #5eead466; }

/* game pad overlay */
#pad { position: fixed; inset: 0; z-index: 15; pointer-events: none; }
#pad .ctl { position: absolute; pointer-events: auto; transform: translate(-50%, -50%); touch-action: none; }
#pad .btn { width: var(--s, 64px); height: var(--s, 64px); border-radius: 50%; display: grid; place-items: center; font: 700 13px/1 system-ui, sans-serif; color: #fff;
  background: radial-gradient(circle at 35% 30%, #ffffff30, #ffffff0a 60%), rgba(12, 16, 22, .38); border: 1.5px solid rgba(255,255,255,.28);
  box-shadow: 0 4px 16px #0006, inset 0 0 12px #ffffff10; backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); text-shadow: 0 1px 3px #000; opacity: var(--o, .7); }
#pad .btn.down { background: radial-gradient(circle, #5eead4aa, #22d3ee55); border-color: var(--acc); transform: translate(-50%, -50%) scale(.93); }
#pad .btn.sq { border-radius: 16px; }
#pad .stick { width: var(--s, 150px); height: var(--s, 150px); border-radius: 50%; background: radial-gradient(circle, rgba(255,255,255,.04), rgba(255,255,255,.12));
  border: 1.5px solid rgba(255,255,255,.22); opacity: var(--o, .7); }
#pad .stick .nub { position: absolute; left: 50%; top: 50%; width: 42%; height: 42%; border-radius: 50%; transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 30%, #ffffff66, #ffffff22); border: 1.5px solid #ffffff55; box-shadow: 0 4px 14px #0008; }
#pad .stick.down { border-color: #5eead488; }
#pad .stick .lbl { position: absolute; bottom: -18px; left: 0; right: 0; text-align: center; font-size: 10px; color: #fff9; text-shadow: 0 1px 2px #000; }
#pad.editing .ctl { outline: 2px dashed #5eead4aa; outline-offset: 4px; }
#pad.editing .ctl.sel { outline-color: #fbbf24; }
#editbar { position: fixed; bottom: max(12px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 30; display: flex; gap: 8px; align-items: center;
  padding: 8px 8px 8px 14px; border-radius: 14px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(14px); font-size: 12px; color: var(--muted); }
#editbar button { padding: 8px 14px; border-radius: 10px; border: 0; background: #5eead4; color: #03211e; font-weight: 700; cursor: pointer; }
#editbar #bAdd { background: #ffffff12; color: var(--text); }
#bindDlg { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: #0008; }
#bindDlg .box { width: min(420px, calc(100vw - 24px)); max-height: 80dvh; overflow: auto; padding: 16px; border-radius: 18px; background: #11151d; border: 1px solid var(--line); display: grid; gap: 10px; }
#bindDlg h3 { margin: 0; font-size: 15px; }
#bindDlg .opts { display: flex; flex-wrap: wrap; gap: 5px; }
#bindDlg .opts button, #bindDlg .row button { padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line); background: #1a202a; cursor: pointer; font-size: 12px; }
#bindDlg .opts button.on { background: #5eead42a; color: var(--acc); border-color: #5eead466; }
#bindDlg .row { display: flex; gap: 6px; align-items: center; } #bindDlg input[type=range] { flex: 1; accent-color: var(--acc); }
#bindDlg input[type=text] { width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: #0a0d13; }

#kbd { position: fixed; left: -100px; top: 50%; width: 40px; height: 20px; opacity: 0; font-size: 16px; }
#toast { position: fixed; left: 50%; bottom: 22%; transform: translate(-50%, 10px); padding: 9px 16px; border-radius: 12px; background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(12px); z-index: 60; opacity: 0; pointer-events: none; transition: .2s; font-size: 13px; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
