:root {
  --bg: #0a0817;
  --panel: rgba(20, 16, 44, 0.88);
  --line: rgba(255, 255, 255, 0.11);
  --text: #f3f0ff;
  --muted: #a8a2cb;
  --gold: #ffd45c;
  --violet: #b48cff;
  --teal: #38d6c4;
  --danger: #ff6b81;
  --ok: #6cf0a6;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden;
  font-family: 'Fredoka', 'Segoe UI', system-ui, sans-serif;
}
#app { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
canvas#game { display: block; border-radius: 16px; box-shadow: 0 0 0 1px #ffffff12, 0 24px 90px #000d; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.l { color: var(--gold); text-shadow: 0 0 22px #ffb30088; }
.u { color: var(--violet); text-shadow: 0 0 22px #7c4dff88; }

/* ---------- screens ---------- */
.screen, .overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 26px; padding: 20px;
  background: radial-gradient(ellipse at center, rgba(22, 16, 56, 0.55), rgba(5, 4, 14, 0.9));
  backdrop-filter: blur(4px);
  animation: fade 0.25s ease;
}
.overlay { background: rgba(5, 4, 14, 0.6); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { transform: scale(0.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- title ---------- */
.title-art { display: flex; align-items: center; gap: 18px; }
.logo { font-size: clamp(46px, 7.5vw, 92px); font-weight: 700; display: flex; gap: 0.22em; align-items: baseline; line-height: 1; }
.logo .l { animation: breatheA 3.2s ease-in-out infinite; }
.logo .u { animation: breatheB 3.2s ease-in-out infinite; }
@keyframes breatheA { 50% { text-shadow: 0 0 40px #ffb300cc; } }
@keyframes breatheB { 50% { text-shadow: 0 0 40px #7c4dffcc; } }
.amp { font-size: 0.55em; opacity: 0.8; }
.tagline { text-align: center; color: var(--muted); font-size: 20px; margin-top: 10px; letter-spacing: 0.5px; }
.avatar { display: block; }
.avatar.big { width: 120px; height: 120px; animation: float 3s ease-in-out infinite; }
.avatar.big[data-id="B"] { animation-delay: -1.5s; }
@keyframes float { 50% { transform: translateY(-10px); } }
.menu-col { display: flex; flex-direction: column; gap: 12px; width: min(380px, 86vw); }
.corner { position: absolute; right: 22px; bottom: 22px; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-size: 18px; font-weight: 600; color: var(--text); cursor: pointer;
  background: linear-gradient(180deg, #3b3274, #2a2357); border: 1px solid var(--line); border-radius: 14px;
  padding: 11px 20px; box-shadow: 0 4px 0 #140f2c; transition: transform 0.1s, box-shadow 0.1s, filter 0.15s;
}
.btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 0 #140f2c, 0 0 26px #7c4dff40; filter: brightness(1.08); }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 #140f2c; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.big { font-size: 24px; padding: 14px 22px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.btn small { font-size: 14px; font-weight: 400; opacity: 0.8; }
.btn.primary { background: linear-gradient(180deg, #ffd65e, #f39a1d); color: #3b2300; box-shadow: 0 4px 0 #9a5800; }
.btn.primary:hover:not(:disabled) { box-shadow: 0 6px 0 #9a5800, 0 0 30px #ffb30055; }
.btn.online { background: linear-gradient(180deg, #a07bff, #6a3fe0); box-shadow: 0 4px 0 #3a1e8c; }
.btn.online:hover:not(:disabled) { box-shadow: 0 6px 0 #3a1e8c, 0 0 30px #7c4dff66; }
.btn.teal { background: linear-gradient(180deg, #4fe3d1, #1fa898); color: #032a26; box-shadow: 0 4px 0 #0d6158; }
.btn.danger { background: linear-gradient(180deg, #ff8597, #e0455f); box-shadow: 0 4px 0 #84213a; }
.icon-btn, .back {
  font: inherit; font-size: 20px; width: 44px; height: 44px; border-radius: 50%; cursor: pointer; color: var(--text);
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line); transition: background 0.15s;
  display: grid; place-items: center; flex: none;
}
.icon-btn:hover, .back:hover { background: rgba(255, 255, 255, 0.14); }

/* ---------- panels ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 24px; padding: 24px 28px;
  box-shadow: 0 30px 90px #000b, inset 0 1px 0 #ffffff14; width: min(900px, 96vw); max-height: 94vh; overflow: auto;
  animation: pop 0.22s ease;
}
.panel.narrow { width: min(440px, 94vw); }
.panel.center { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.panel h2 { margin: 0; font-size: 30px; font-weight: 600; }
.panel h3 { margin: 0; font-weight: 600; }
.panel-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.panel-head h2 { flex: 1; }

/* ---------- level select ---------- */
.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.level-card {
  position: relative; text-align: left; font: inherit; color: var(--text); cursor: pointer;
  border: 1px solid var(--line); border-radius: 18px; padding: 18px; min-height: 150px;
  background: linear-gradient(160deg, rgba(255, 212, 92, 0.1), rgba(124, 77, 255, 0.14));
  transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
  display: flex; flex-direction: column; gap: 6px;
}
.level-card:hover:not(:disabled) { transform: translateY(-3px); border-color: #ffffff40; box-shadow: 0 10px 30px #0008; }
.level-card:disabled { cursor: not-allowed; filter: grayscale(0.8); opacity: 0.55; }
.level-card .num { font-size: 40px; font-weight: 700; line-height: 1; opacity: 0.9; }
.level-card .name { font-size: 20px; font-weight: 600; }
.level-card .meta { color: var(--muted); font-size: 14px; margin-top: auto; display: flex; justify-content: space-between; }
.level-card .lstars { font-size: 20px; letter-spacing: 2px; }
.lock { position: absolute; right: 16px; top: 14px; font-size: 22px; }
.star { color: #ffffff26; }
.star.on { color: var(--gold); text-shadow: 0 0 14px #ffb300aa; }

/* ---------- how to ---------- */
.howto-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.char-card { display: flex; gap: 14px; align-items: center; padding: 16px; border-radius: 18px; border: 1px solid var(--line); }
.char-card.A { background: linear-gradient(160deg, rgba(255, 212, 92, 0.14), transparent); }
.char-card.B { background: linear-gradient(160deg, rgba(180, 140, 255, 0.16), transparent); }
.char-card h3 { font-size: 24px; }
.char-card p { margin: 6px 0 0; color: var(--muted); }
.keys { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; color: var(--text) !important; }
kbd {
  display: inline-block; min-width: 26px; text-align: center; font-family: inherit; font-size: 14px; font-weight: 600;
  background: #ffffff18; border: 1px solid #ffffff30; border-bottom-width: 3px; border-radius: 7px; padding: 1px 7px;
}
.rules { list-style: none; padding: 0; margin: 20px 0 0; display: grid; gap: 10px; font-size: 17px; }
.rules li { display: flex; align-items: center; gap: 10px; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.dot.ooze { background: #7cf06a; box-shadow: 0 0 10px #7cf06a; }
.dot.teal { background: var(--teal); box-shadow: 0 0 10px var(--teal); }
.dot.orange { background: #ff9b42; box-shadow: 0 0 10px #ff9b42; }
.dot.gold { background: var(--gold); box-shadow: 0 0 10px var(--gold); }
.dot.violet { background: var(--violet); box-shadow: 0 0 10px var(--violet); }
.dot.white { background: #fff; box-shadow: 0 0 10px #fff; }

/* ---------- online hub ---------- */
.status { display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--muted); }
.sdot { width: 10px; height: 10px; border-radius: 50%; background: #888; }
.status.online .sdot { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.status.offline .sdot { background: var(--danger); box-shadow: 0 0 10px var(--danger); }
.status.connecting .sdot { background: var(--gold); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.3; } }
.name-row { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; font-size: 17px; }
.name-row input { max-width: 280px; }
input[type=text], select {
  font: inherit; font-size: 17px; color: var(--text); background: #0d0a21; border: 1px solid var(--line);
  border-radius: 11px; padding: 10px 12px; outline: none; width: 100%; transition: border-color 0.15s, box-shadow 0.15s;
}
input[type=text]:focus, select:focus { border-color: var(--violet); box-shadow: 0 0 0 3px #7c4dff33; }
select:disabled { opacity: 0.6; }
.code-input { text-transform: uppercase; letter-spacing: 8px; text-align: center; font-weight: 700; font-size: 22px !important; }
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.card {
  background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); border-radius: 18px; padding: 18px;
  display: flex; flex-direction: column; gap: 10px;
}
.card-icon { font-size: 28px; }
.card h3 { font-size: 21px; }
.card p { margin: 0; color: var(--muted); font-size: 15px; flex: 1; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 15px; color: var(--muted); }
.switch input { display: none; }
.track { width: 40px; height: 22px; border-radius: 11px; background: #ffffff22; position: relative; transition: background 0.15s; flex: none; }
.track::after { content: ''; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.switch input:checked + .track { background: var(--teal); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:disabled + .track { opacity: 0.5; }
.list-head { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 0 10px; }
.lobby-list { display: flex; flex-direction: column; gap: 8px; min-height: 60px; }
.lobby-row {
  display: flex; align-items: center; gap: 14px; padding: 10px 14px; border-radius: 14px;
  background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line);
}
.lobby-row .who { flex: 1; font-weight: 600; }
.lobby-row .what { color: var(--muted); font-size: 14px; }
.lobby-row .btn { padding: 7px 16px; font-size: 15px; }
.empty { color: var(--muted); text-align: center; padding: 16px; border: 1px dashed var(--line); border-radius: 14px; }

/* ---------- searching ---------- */
.orbit { position: relative; width: 90px; height: 90px; animation: spin 2.2s linear infinite; }
.orbit .o { position: absolute; width: 26px; height: 26px; border-radius: 50%; }
.orbit .a { left: 0; top: 32px; background: var(--gold); box-shadow: 0 0 22px var(--gold); }
.orbit .b { right: 0; top: 32px; background: var(--violet); box-shadow: 0 0 22px var(--violet); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- lobby ---------- */
.code-chip {
  font: inherit; color: var(--text); cursor: pointer; display: flex; gap: 10px; align-items: center;
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px; font-size: 16px;
}
.code-chip b { font-size: 22px; letter-spacing: 5px; }
.code-chip:hover { background: rgba(255, 255, 255, 0.12); }
.slots { display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; align-items: center; }
.slot {
  border-radius: 20px; padding: 18px; display: flex; align-items: center; gap: 14px; min-height: 120px;
  border: 2px solid var(--line); transition: border-color 0.2s, background 0.2s;
}
.slot.A { border-color: #ffd45c55; background: linear-gradient(160deg, rgba(255, 212, 92, 0.16), transparent 70%); }
.slot.B { border-color: #b48cff55; background: linear-gradient(160deg, rgba(180, 140, 255, 0.18), transparent 70%); }
.slot.empty-slot { border-style: dashed; }
.slot .info { flex: 1; min-width: 0; }
.slot .pname { font-size: 21px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot .prole { color: var(--muted); font-size: 15px; }
.tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 8px; margin-left: 6px; vertical-align: middle; }
.tag.host { background: #ffd45c33; color: var(--gold); }
.tag.you { background: #ffffff1f; color: #fff; }
.ready-badge { font-size: 14px; font-weight: 600; padding: 6px 10px; border-radius: 10px; white-space: nowrap; }
.ready-badge.yes { background: #6cf0a62a; color: var(--ok); }
.ready-badge.no { background: #ffffff12; color: var(--muted); }
.swap { width: 52px; height: 52px; padding: 0; font-size: 22px; border-radius: 50%; }
.lobby-bottom { display: grid; grid-template-columns: 1fr 1.3fr; gap: 18px; margin-top: 20px; }
.lobby-opts { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 15px; }
.chat { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; background: rgba(0, 0, 0, 0.2); }
.chat-log { flex: 1; min-height: 150px; max-height: 190px; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; font-size: 15px; }
.chat-log .sys { color: var(--muted); font-style: italic; }
.chat-log b { color: var(--violet); }
.chat-form { display: flex; gap: 8px; padding: 8px; border-top: 1px solid var(--line); }
.chat-form input { padding: 8px 10px; font-size: 15px; }
.chat-form .btn { padding: 7px 14px; font-size: 15px; }

/* ---------- win ---------- */
.stars { font-size: 54px; letter-spacing: 6px; }
.stars .star { display: inline-block; animation: starIn 0.5s ease backwards; }
.stars .star:nth-child(2) { animation-delay: 0.15s; }
.stars .star:nth-child(3) { animation-delay: 0.3s; }
@keyframes starIn { from { transform: scale(0) rotate(-90deg); } }
.win-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 22px; text-align: left; font-size: 17px; }
.win-stats .k { color: var(--muted); }
.win-stats .best { color: var(--ok); font-size: 13px; margin-left: 6px; }

/* ---------- toasts ---------- */
#toasts { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; pointer-events: none; align-items: center; }
.toast {
  background: rgba(20, 16, 44, 0.95); border: 1px solid var(--line); border-radius: 14px; padding: 10px 18px;
  font-size: 16px; box-shadow: 0 10px 30px #000a; animation: toastIn 0.25s ease; max-width: 80vw;
}
.toast.error { border-color: #ff6b8166; color: #ffc2cc; }
.toast.ok { border-color: #6cf0a666; }
.toast.out { opacity: 0; transform: translateY(-8px); transition: 0.3s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } }

@media (max-width: 760px) {
  .cards, .howto-grid, .lobby-bottom { grid-template-columns: 1fr; }
  .slots { grid-template-columns: 1fr; }
  .swap { justify-self: center; }
  .title-art .avatar { display: none; }
}
