* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #8fd3ff; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: #fff; }
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }

.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(circle at 30% 20%, #ff4fa3 0, transparent 45%), radial-gradient(circle at 80% 80%, #3ad1ff 0, transparent 50%), #1b1440; z-index: 20; }
.card { width: 100%; max-width: 360px; background: rgba(20, 14, 50, .82); border: 2px solid #ffd23f; border-radius: 18px; padding: 22px; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.logo { font-size: 38px; font-weight: 900; letter-spacing: 1px; color: #ffd23f; text-shadow: 3px 3px 0 #ff4fa3; text-align: center; }
.logo span { color: #3ad1ff; }
.sub { text-align: center; margin: 4px 0 16px; opacity: .85; font-size: 14px; }
.card label { display: block; font-size: 13px; margin: 10px 0 4px; opacity: .9; }
.card input { display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font-size: 16px; border-radius: 10px; border: none; background: #fff; color: #111; }
#colors { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
#colors div { aspect-ratio: 1; border-radius: 8px; cursor: pointer; border: 3px solid transparent; }
#colors div.sel { border-color: #fff; transform: scale(1.08); }
#go { width: 100%; margin-top: 16px; padding: 12px; font-size: 18px; font-weight: 800; border: none; border-radius: 12px; cursor: pointer; background: #ffd23f; color: #1b1440; }
#go:disabled { opacity: .6; }
#err { color: #ff8a8a; min-height: 20px; margin-top: 10px; text-align: center; font-size: 14px; }
#info { text-align: center; font-size: 12px; opacity: .7; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#topbar { position: absolute; top: max(8px, env(safe-area-inset-top)); left: 10px; background: rgba(0,0,0,.35); padding: 5px 10px; border-radius: 8px; font-size: 14px; }
#help { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.35); padding: 5px 10px; border-radius: 8px; font-size: 12px; white-space: nowrap; }
#cross { position: absolute; left: 50%; top: 50%; width: 18px; height: 18px; margin: -9px 0 0 -9px; }
#cross::before, #cross::after { content: ""; position: absolute; background: #fff; box-shadow: 0 0 2px #000; }
#cross::before { left: 8px; top: 0; width: 2px; height: 18px; }
#cross::after { top: 8px; left: 0; height: 2px; width: 18px; }
#labels div { position: absolute; transform: translate(-50%, -100%); font-size: 13px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: rgba(0,0,0,.45); white-space: nowrap; }

#chat { position: absolute; left: 10px; bottom: 70px; width: min(420px, 70vw); }
#msgs div { font-size: 14px; text-shadow: 1px 1px 2px #000; margin-top: 2px; background: rgba(0,0,0,.25); padding: 2px 6px; border-radius: 6px; width: fit-content; max-width: 100%; word-wrap: break-word; transition: opacity 1s; }
#msgs div.old { opacity: 0; }
#msgs div .n { font-weight: 800; color: #ffd23f; }
#msgs div.sys { color: #9fe7ff; font-style: italic; }
#chatin { display: none; pointer-events: auto; width: 100%; margin-top: 6px; padding: 8px 10px; font-size: 16px; border-radius: 8px; border: none; background: rgba(0,0,0,.6); color: #fff; }
#chat.open #chatin { display: block; }
#chat.open #msgs div.old { opacity: 1; }

#palette { position: absolute; bottom: max(10px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); display: flex; gap: 4px; pointer-events: auto; background: rgba(0,0,0,.35); padding: 5px; border-radius: 10px; max-width: 96vw; overflow-x: auto; }
#palette div { width: 34px; height: 34px; flex: none; border-radius: 6px; border: 3px solid rgba(0,0,0,.3); position: relative; cursor: pointer; }
#palette div.sel { border-color: #fff; transform: translateY(-3px); }
#palette div span { position: absolute; left: 2px; top: 0; font-size: 10px; font-weight: 700; color: #fff; text-shadow: 0 0 2px #000; }

.touch-only { display: none; }
body.touch .touch-only { display: block; }
body.touch .desktop-only { display: none; }
body.touch #palette { bottom: max(6px, env(safe-area-inset-bottom)); }
body.touch #palette div { width: 30px; height: 30px; }
body.touch #palette div span { display: none; }
body.touch #chat { bottom: auto; top: 44px; width: 60vw; }
#stick { position: absolute; left: 24px; bottom: 70px; width: 130px; height: 130px; border-radius: 50%; background: rgba(255,255,255,.15); border: 2px solid rgba(255,255,255,.35); pointer-events: auto; }
#knob { position: absolute; left: 40px; top: 40px; width: 50px; height: 50px; border-radius: 50%; background: rgba(255,255,255,.55); }
#tbtns { position: absolute; right: 18px; bottom: 70px; display: grid; grid-template-columns: 64px 64px; gap: 10px; pointer-events: auto; }
#tbtns2 { position: absolute; right: 12px; top: 10px; display: flex; gap: 8px; pointer-events: auto; }
#touch button { width: 64px; height: 64px; border-radius: 50%; border: 2px solid rgba(255,255,255,.5); background: rgba(0,0,0,.35); color: #fff; font-size: 26px; }
#touch #tbtns2 button { width: 44px; height: 44px; font-size: 20px; }
#touch #bJump { grid-column: 1 / span 2; justify-self: center; width: 76px; height: 76px; }
#touch button:active { background: rgba(255,210,63,.6); }
