:root {
  --ink: #f5f3ec;
  --muted: rgba(245, 243, 236, 0.68);
  --glass: rgba(14, 26, 20, 0.58);
  --glass-strong: rgba(14, 26, 20, 0.78);
  --solid: #132219;
  --solid-2: #1b2e23;
  --accent: #ffd36b;
  --accent-ink: #1b2a20;
  --sky: #9fe3ff;
  --line: rgba(255, 255, 255, 0.12);
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #c4d3dc; color: var(--ink);
  font: 400 14px/1.4 Poppins, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
input { -webkit-user-select: text; user-select: text; font: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#app canvas { display: block; cursor: grab; touch-action: none; }
#app canvas.dragging { cursor: grabbing; }
body:not(.touch) .touch-only { display: none !important; }
[hidden] { display: none !important; }

kbd {
  display: inline-block; min-width: 1.6em; padding: 1px 6px; border-radius: 6px;
  background: rgba(255, 255, 255, 0.1); border: 1px solid var(--line);
  font: 600 11px/1.5 ui-monospace, Consolas, monospace; text-align: center;
}

.icon-btn {
  position: relative; width: 44px; height: 44px; border-radius: 13px; border: 0; flex: none;
  display: grid; place-items: center; background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow); transition: background 0.2s, transform 0.1s;
}
.icon-btn:hover { background: var(--glass-strong); }
.icon-btn:active { transform: scale(0.94); }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 700; font-size: 15px; color: #fff; background: hsl(var(--hue, 45) 60% 45%);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35);
}

/* ---------- top bar ---------- */
#hud {
  position: fixed; top: calc(10px + var(--safe-t)); left: calc(10px + var(--safe-l));
  display: flex; align-items: center; gap: 8px; max-width: calc(100vw - 150px);
}
.me { display: flex; align-items: center; gap: 9px; min-width: 0; }
#hud .me {
  padding: 5px 14px 5px 5px; border-radius: 999px; background: var(--glass);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: var(--shadow);
}
.me-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.me-text b { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-text small { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#hud-right { position: fixed; top: calc(10px + var(--safe-t)); right: calc(10px + var(--safe-r)); display: flex; gap: 8px; align-items: center; }
.pill {
  height: 32px; padding: 0 12px; border-radius: 999px; border: 0; font-size: 12px; font-weight: 500;
  background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: var(--shadow); white-space: nowrap;
}
.pill::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: #5be38a; box-shadow: 0 0 0 3px rgba(91, 227, 138, 0.25); }
.pill.off::before { background: #9aa; box-shadow: none; }
.badge {
  position: absolute; top: -4px; right: -4px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 999px;
  background: #ff6b57; color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center;
}

/* ---------- toasts ---------- */
#place {
  position: fixed; top: 20%; left: 50%; transform: translate(-50%, 10px); text-align: center; width: 90vw;
  opacity: 0; transition: opacity 0.8s, transform 0.8s; pointer-events: none; text-shadow: 0 2px 18px rgba(0, 0, 0, 0.5);
}
#place.show { opacity: 1; transform: translate(-50%, 0); }
#place-name { font: 700 clamp(26px, 5vw, 46px)/1.1 Poppins, sans-serif; letter-spacing: -0.5px; }
#place-sub { font-size: clamp(13px, 2vw, 16px); color: var(--muted); margin-top: 6px; }
#hint {
  position: fixed; bottom: calc(150px + var(--safe-b)); left: 50%; transform: translate(-50%, 8px); padding: 9px 16px; border-radius: 999px;
  background: var(--glass-strong); backdrop-filter: blur(10px); font-size: 13px; font-weight: 500; white-space: nowrap; box-shadow: var(--shadow);
  opacity: 0; transition: opacity 0.25s, transform 0.25s; pointer-events: none;
}
#hint.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- chat ---------- */
#chat-log {
  position: fixed; left: calc(10px + var(--safe-l)); top: calc(66px + var(--safe-t)); width: min(330px, 72vw);
  display: flex; flex-direction: column; gap: 5px; pointer-events: none; z-index: 5;
}
#chat-log .msg {
  align-self: flex-start; max-width: 100%; padding: 6px 11px; border-radius: 12px 12px 12px 4px; font-size: 13px; line-height: 1.35;
  background: var(--glass); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); overflow-wrap: anywhere;
  animation: msgin 0.25s ease-out, msgfade 14s 0.25s forwards;
}
#chat-log .msg b { color: var(--sky); font-weight: 600; margin-right: 6px; }
#chat-log .msg.mine b { color: var(--accent); }
#chat-log .msg.sys { background: transparent; backdrop-filter: none; color: var(--muted); font-size: 12px; padding: 2px 4px; text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6); }
body.chatting #chat-log { top: calc(76px + var(--safe-t)); width: min(520px, calc(100vw - 20px)); left: 50%; transform: translateX(-50%); }
body.chatting #chat-log .msg { animation: none; opacity: 1; }
@keyframes msgin { from { opacity: 0; transform: translateY(6px); } }
@keyframes msgfade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
#chat-form {
  position: fixed; left: 50%; top: calc(10px + var(--safe-t)); transform: translate(-50%, -160%);
  display: flex; gap: 6px; width: min(520px, calc(100vw - 20px)); padding: 6px; border-radius: 16px; z-index: 20;
  background: var(--solid); box-shadow: var(--shadow); transition: transform 0.22s ease;
}
body.chatting #chat-form { transform: translate(-50%, 0); }
#chat-form input {
  flex: 1; min-width: 0; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06); color: var(--ink); font-size: 16px; outline: none;
}
#chat-form input:focus { border-color: var(--accent); }
#chat-form button { width: 46px; border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
#chat-form button.ghost { width: 40px; background: transparent; color: var(--muted); }

/* ---------- side menu ---------- */
#scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); opacity: 0; pointer-events: none; transition: opacity 0.25s; z-index: 30; }
#drawer {
  position: fixed; top: 0; bottom: 0; left: 0; width: min(340px, 90vw); z-index: 31; overflow-y: auto; overscroll-behavior: contain;
  padding: calc(14px + var(--safe-t)) 16px calc(24px + var(--safe-b)) calc(16px + var(--safe-l));
  background: linear-gradient(180deg, var(--solid-2), var(--solid)); box-shadow: 6px 0 40px rgba(0, 0, 0, 0.45);
  transform: translateX(-105%); transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
body.menu-open #drawer { transform: none; }
body.menu-open #scrim { opacity: 1; pointer-events: auto; }
.drawer-head { display: flex; align-items: center; gap: 10px; padding-bottom: 12px; }
.drawer-head .me { flex: 1; }
.drawer-head .avatar { width: 42px; height: 42px; font-size: 18px; }
#drawer-close { background: rgba(255, 255, 255, 0.07); box-shadow: none; }
#drawer section { padding: 14px 0; border-top: 1px solid var(--line); }
#drawer h3 { margin: 0 0 10px; font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
#players-count { color: var(--accent); }

#name-edit, #name {
  width: 100%; min-width: 0; padding: 11px 13px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06); color: var(--ink); font-size: 16px; font-weight: 500; outline: none; transition: border-color 0.2s;
}
#name-edit:focus, #name:focus { border-color: var(--accent); }

#players { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 6px; }
#players li { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); }
#players li .avatar { width: 30px; height: 30px; font-size: 13px; }
#players li span.n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
#players li small { color: var(--muted); font-size: 11px; display: block; font-weight: 400; }
#players li button { padding: 6px 12px; border-radius: 9px; border: 0; background: rgba(255, 211, 107, 0.16); color: var(--accent); font-weight: 600; font-size: 12px; }
#players li.you { background: rgba(255, 211, 107, 0.08); }
#players .empty { color: var(--muted); font-size: 13px; background: none; padding: 2px 0; }

#places { display: grid; gap: 6px; }
#places button {
  display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 12px; text-align: left;
  border: 1px solid transparent; background: rgba(255, 255, 255, 0.05); font-size: 14px; transition: background 0.15s;
}
#places button::after { content: '›'; margin-left: auto; font-size: 18px; color: var(--muted); }
#places button:hover { background: rgba(255, 255, 255, 0.1); }
#places button.active { border-color: rgba(255, 211, 107, 0.6); background: rgba(255, 211, 107, 0.1); }
#places button kbd { background: var(--accent); color: var(--accent-ink); border: 0; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); padding: 4px; gap: 4px; border-radius: 12px; background: rgba(255, 255, 255, 0.06); }
.seg button { padding: 9px 4px; border: 0; border-radius: 9px; background: transparent; font-weight: 500; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.switch { display: flex; align-items: center; justify-content: space-between; padding: 10px 2px; cursor: pointer; font-size: 14px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch i { width: 44px; height: 26px; border-radius: 999px; background: rgba(255, 255, 255, 0.15); position: relative; transition: background 0.2s; flex: none; }
.switch i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.switch input:checked + i { background: #3fbf6f; }
.switch input:checked + i::after { transform: translateX(18px); }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary, .btn-secondary {
  width: 100%; padding: 12px; border-radius: 12px; border: 0; font-weight: 600; font-size: 14px; margin-top: 8px;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: rgba(255, 255, 255, 0.07); }
.btn-primary:active, .btn-secondary:active { transform: scale(0.98); }
.note { margin: 8px 0 0; font-size: 12px; color: var(--muted); line-height: 1.45; }
.keys ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; font-size: 13px; color: var(--muted); }
body.touch .keys { display: none; }

/* character cards (start screen + menu) */
.chars { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.chars button {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 10px 6px 9px;
  border-radius: 14px; border: 1.5px solid var(--line); background: rgba(255, 255, 255, 0.05); transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.chars button:hover { background: rgba(255, 255, 255, 0.1); }
.chars button:active { transform: scale(0.97); }
.chars button i {
  font-style: normal; font-size: 24px; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center;
  background: var(--swatch, rgba(255, 255, 255, 0.1));
}
.chars button b { font-size: 12px; font-weight: 600; }
.chars button small { font-size: 10.5px; color: var(--muted); line-height: 1.2; text-align: center; }
.chars button.active { border-color: var(--accent); background: rgba(255, 211, 107, 0.12); }
.chars button.active::after {
  content: '✓'; position: absolute; top: 6px; right: 7px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; display: grid; place-items: center;
}

/* ---------- game controls ---------- */
#pad {
  position: fixed; right: calc(18px + var(--safe-r)); bottom: calc(20px + var(--safe-b));
  display: flex; align-items: flex-end; gap: 14px; touch-action: none; z-index: 6;
}
.round {
  width: 66px; height: 66px; border-radius: 50%; line-height: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 1.5px solid rgba(255, 255, 255, 0.28); background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow); touch-action: none; transition: transform 0.08s, background 0.2s;
}
.round small { font-size: 10px; font-weight: 600; letter-spacing: 0.03em; color: var(--muted); }
.round.big { width: 86px; height: 86px; }
.round.pressed { transform: scale(0.9); background: rgba(255, 255, 255, 0.3); }
.round.on { background: rgba(255, 211, 107, 0.4); border-color: var(--accent); }
.round.on small { color: var(--ink); }
.round.chute { display: none; font-size: 24px; background: #e8622a; border-color: #ffb48a; animation: pulse 0.9s infinite; }
.round.chute small { color: #fff; }
body.falling .round.chute { display: flex; }
@keyframes pulse { 50% { transform: scale(1.07); } }

/* floating joystick: appears where the left thumb touches */
#joy-zone { position: fixed; left: 0; bottom: 0; width: 50vw; height: 62vh; z-index: 4; touch-action: none; }
#joy {
  position: absolute; left: calc(28px + var(--safe-l)); bottom: calc(28px + var(--safe-b)); width: 128px; height: 128px; margin: 0;
  border-radius: 50%; display: grid; place-items: center; pointer-events: none; opacity: 0.55; transition: opacity 0.2s;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.12), rgba(14, 26, 20, 0.5)); border: 2px solid rgba(255, 255, 255, 0.28);
}
#joy.active { opacity: 1; border-color: var(--accent); transition: none; }
#knob { width: 54px; height: 54px; border-radius: 50%; background: rgba(255, 255, 255, 0.9); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35); }

/* ---------- start screen ---------- */
#loading {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; overflow-y: auto; z-index: 40;
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(255, 211, 107, 0.25), transparent 60%),
    linear-gradient(180deg, #4f7fb8 0%, #9fbfd2 45%, #6f9a55 100%);
  transition: opacity 0.7s;
}
#loading.gone { opacity: 0; pointer-events: none; }
#loading .card {
  width: min(460px, 100%); padding: 26px 22px 22px; border-radius: 24px; text-align: center;
  background: var(--glass-strong); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
}
.mark { display: block; margin: 0 auto 10px; width: 76px; height: 76px; border-radius: 18px; box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35); }
#loading h1 { margin: 0; font: 700 32px/1.1 Poppins, sans-serif; letter-spacing: -0.5px; }
.lead { margin: 8px auto 12px; color: var(--muted); max-width: 34ch; }
.live { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.07); font-size: 12px; font-weight: 500; }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: #5be38a; box-shadow: 0 0 0 0 rgba(91, 227, 138, 0.6); animation: ping 1.6s infinite; }
.live.off .dot { background: #9aa; animation: none; }
@keyframes ping { 70% { box-shadow: 0 0 0 8px rgba(91, 227, 138, 0); } 100% { box-shadow: 0 0 0 0 rgba(91, 227, 138, 0); } }
.field-label { display: block; margin: 18px 0 8px; font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); text-align: left; }
.name-row { display: flex; align-items: center; gap: 10px; }
.name-row .avatar { width: 44px; height: 44px; font-size: 18px; }
#name.bad { border-color: #ff7a6b; animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.progress { height: 4px; margin: 18px 0 6px; border-radius: 999px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width 0.4s ease; }
#loading.ready .progress { display: none; }
#loading-status { margin: 0 0 10px; font-size: 12px; color: var(--muted); min-height: 1.4em; }
.cta {
  width: 100%; padding: 14px; border: 0; border-radius: 14px; background: var(--accent); color: var(--accent-ink);
  font: 700 16px Poppins, sans-serif; box-shadow: 0 8px 24px rgba(255, 211, 107, 0.3); transition: transform 0.1s, opacity 0.2s;
}
.cta:active { transform: scale(0.98); }
.cta:disabled { opacity: 0.55; cursor: wait; box-shadow: none; }

@media (max-height: 520px) {
  #loading { place-items: start center; }
  #loading .card { padding: 14px 16px; }
  .mark, .lead { display: none; }
  #loading h1 { font-size: 22px; }
  .field-label { margin: 10px 0 6px; }
  .round { width: 58px; height: 58px; }
  .round.big { width: 74px; height: 74px; }
  #joy { width: 112px; height: 112px; }
  #hint { bottom: calc(100px + var(--safe-b)); }
}

/* phones: keep the view clear — only the latest few messages float over the game */
body.touch:not(.chatting) #chat-log .msg:nth-last-child(n+4) { display: none; }
body.touch #chat-log { width: min(300px, 68vw); }

/* chat switched off for now */
body.no-chat #chat-btn, body.no-chat #chat-log, body.no-chat #chat-form { display: none !important; }
/* player status lives in the menu header now */
.drawer-head .me-text { flex: 1; gap: 4px; }
.drawer-head .status { font-size: 11px; color: var(--muted); padding-left: 4px; }
#hud { max-width: none; }

/* pose actions in the menu */
.acts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.acts button {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; border-radius: 12px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); font-size: 12px; font-weight: 500;
}
.acts button i { font-style: normal; font-size: 22px; }
.acts button:active { transform: scale(0.96); }

/* quick actions toolbar — top right, left of the online badge */
#quick {
  display: flex; align-items: center; gap: 2px; padding: 3px; border-radius: 14px;
  background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: var(--shadow);
}
.q-btn {
  position: relative; width: 38px; height: 38px; border: 0; border-radius: 11px; flex: none;
  display: grid; place-items: center; background: transparent; transition: background 0.2s, transform 0.1s;
}
.q-btn:hover { background: rgba(255, 255, 255, 0.1); }
.q-btn:active { transform: scale(0.9); background: rgba(255, 255, 255, 0.16); }
.q-btn i { font-style: normal; font-size: 19px; line-height: 1; }
.q-tag {
  position: absolute; bottom: 1px; left: 0; right: 0; text-align: center;
  font-size: 8px; font-weight: 600; letter-spacing: 0.02em; color: var(--accent); line-height: 1;
}
#q-cam svg { margin-top: -6px; }
@media (max-width: 400px) {
  #hud-right { gap: 6px; }
  .q-btn { width: 34px; height: 36px; }
  .q-btn i { font-size: 17px; }
  .pill { padding: 0 10px; }
}
