:root {
  --bg: #05061a; --panel: rgba(16, 20, 52, 0.86); --panel2: rgba(255, 255, 255, 0.06); --line: rgba(255, 255, 255, 0.12);
  --text: #eef1ff; --muted: #9aa3c7; --moon: #ffe7a3; --accent: #7c8cff; --ok: #5dffae; --warn: #ffc45d; --err: #ff6b7d;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden;
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; overscroll-behavior: none; }
body { opacity: 0; transition: opacity .3s; } body.ready { opacity: 1; }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
#sky { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; touch-action: none; }

.topbar { position: fixed; top: 0; left: 0; right: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-t) + 8px) 12px 8px; background: linear-gradient(rgba(5,6,26,.85), rgba(5,6,26,0)); }
.brand { display: flex; align-items: center; gap: 8px; background: none; border: 0; font-weight: 700; letter-spacing: .3px; padding: 4px; cursor: pointer; }
.brand-moon { width: 22px; height: 22px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fffbe8, #cfc9b6 70%, #8f8a7c); box-shadow: 0 0 12px rgba(255,240,200,.6); }
.topbar-right { display: flex; gap: 8px; align-items: center; }
#langSelect { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; }
#langSelect option, select option { background: #111637; }
.avatar-btn { width: 40px; height: 40px; border-radius: 50%; padding: 0; border: 2px solid var(--line); background: none; overflow: hidden; cursor: pointer; }
.avatar-btn.logged { border-color: var(--moon); }
.avatar-btn img { width: 100%; height: 100%; object-fit: cover; }

main { position: relative; z-index: 10; height: 100%; }
.screen { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center;
  padding: calc(var(--safe-t) + 64px) 20px calc(var(--safe-b) + 20px); }
.screen.active { display: flex; animation: fade .35s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--panel2);
  border-radius: 14px; padding: 12px 18px; cursor: pointer; text-decoration: none; font-weight: 600; transition: transform .1s, background .2s; user-select: none; -webkit-user-select: none; }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, #7c8cff, #5a3fd6); border-color: transparent; box-shadow: 0 6px 24px rgba(110,90,255,.35); }
.btn.moon { background: linear-gradient(135deg, #ffe7a3, #f5b74a); color: #241a00; border-color: transparent; box-shadow: 0 6px 26px rgba(255,210,120,.4); }
.btn.ghost { background: rgba(255,255,255,.05); }
.btn.danger { color: var(--err); }
.btn.big { font-size: 1.15rem; padding: 16px 26px; border-radius: 18px; }
.btn.icon { padding: 8px 12px; border-radius: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }

/* home */
#screen-home { overflow-y: auto; }
.home-spacer { flex: 0 0 38vh; }
#screen-home h1 { margin: 0 0 6px; font-size: clamp(2rem, 9vw, 3rem); text-align: center; text-shadow: 0 0 24px rgba(255,231,163,.35); }
.tagline { margin: 0 0 22px; text-align: center; color: var(--muted); max-width: 30em; }
#screen-home .btn { width: min(360px, 100%); margin-bottom: 12px; }
.moon-info { color: var(--muted); font-size: .9rem; margin-top: auto; }

/* game */
.game { padding-top: calc(var(--safe-t) + 58px); pointer-events: none; }
.game > * { pointer-events: auto; }
.hud { display: flex; gap: 8px; width: 100%; max-width: 460px; }
.hud > div { flex: 1; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px 10px; text-align: center; backdrop-filter: blur(6px); }
.hud small { display: block; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .5px; }
.hud b { font-variant-numeric: tabular-nums; font-size: 1.05rem; white-space: nowrap; }
.progress { width: 100%; max-width: 460px; height: 6px; background: rgba(255,255,255,.1); border-radius: 3px; margin: 8px 0; overflow: hidden; }
#progressBar { height: 100%; width: 0; background: linear-gradient(90deg, #7c8cff, #ffe7a3); transition: width .6s ease; }
.status { margin: 6px 0; padding: 5px 12px; font-size: .9rem; border-radius: 12px; background: var(--panel); text-align: center; max-width: 460px; font-weight: 600; }
.status.ok { color: var(--ok); } .status.warn { color: var(--warn); } .status.error { color: var(--err); }
.status:empty { display: none; }
.sim-badge { font-size: .75rem; color: var(--warn); border: 1px dashed var(--warn); padding: 3px 8px; border-radius: 8px; }
.game-bottom { margin-top: auto; width: 100%; max-width: 460px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.hint { margin: 0; color: var(--muted); font-size: .85rem; text-align: center; min-height: 1.2em; }
.pull-meter { width: 70%; height: 8px; border-radius: 4px; background: rgba(255,255,255,.1); overflow: hidden; }
#pullMeter { height: 100%; width: 0; background: linear-gradient(90deg, var(--ok), var(--moon)); transition: width .05s; }
.btn.grab { width: 100%; padding: 22px; font-size: 1.3rem; border-radius: 22px; touch-action: none;
  background: linear-gradient(135deg, #ffe7a3, #f5b74a); color: #241a00; border: 0; box-shadow: 0 10px 34px rgba(255,210,120,.45); }
.btn.grab .hand { font-size: 1.6rem; }
.btn.grab.holding { transform: scale(.95); box-shadow: 0 0 0 6px rgba(93,255,174,.4), 0 10px 34px rgba(255,210,120,.6); }
.btn.grab:disabled { background: rgba(255,255,255,.1); color: var(--muted); }
.quit-game { position: absolute; left: 12px; bottom: calc(var(--safe-b) + 120px); background: var(--panel); }

/* landed */
.landed, .locked { justify-content: flex-start; }
.landed-card { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 20px; width: min(420px, 100%);
  display: flex; flex-direction: column; gap: 10px; text-align: center; backdrop-filter: blur(8px); animation: pop .6s cubic-bezier(.2,1.4,.4,1); }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
.landed-card h2 { margin: 0; color: var(--moon); }
.big-time { font-size: 2.4rem; font-weight: 800; margin: 0; font-variant-numeric: tabular-nums; }
.astronaut-scene { position: absolute; bottom: calc(var(--safe-b) + 6vh); left: 50%; transform: translateX(-50%); display: flex; align-items: flex-end; gap: 6px; }
.astro { width: 96px; height: 96px; border-radius: 50%; animation: float 3s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-10px) rotate(-4deg); } }
.flag { position: relative; width: 60px; height: 110px; }
.flag .pole { position: absolute; left: 0; bottom: 0; width: 4px; height: 110px; background: #ddd; border-radius: 2px; }
.flag .cloth { position: absolute; left: 6px; top: 0; font-size: 44px; line-height: 1; animation: wave 2s ease-in-out infinite; transform-origin: left center; }
@keyframes wave { 50% { transform: skewY(4deg) scaleX(.94); } }

/* leaderboard */
.board h2 { margin: 0 0 12px; }
.seg { display: flex; background: var(--panel2); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.seg button { border: 0; background: none; padding: 8px 14px; border-radius: 9px; cursor: pointer; }
.seg button.active { background: var(--accent); }
.board-list { list-style: none; padding: 0; margin: 0 0 12px; width: min(520px, 100%); overflow-y: auto; flex: 1; }
.board-list li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 8px; }
.board-list li.me { border-color: var(--moon); }
.board-list li.empty { justify-content: center; color: var(--muted); }
.board-list .rank { width: 32px; text-align: center; font-weight: 800; font-size: 1.1rem; }
.board-list .who { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.board-list .who b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-list .who small { color: var(--muted); }
.board-list .time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--moon); }
.av { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; flex: none; background: #1a2050; }
.av.sm { width: 28px; height: 28px; } .av.xl { width: 96px; height: 96px; }

/* chat */
.chat { padding: calc(var(--safe-t) + 56px) 0 0; align-items: stretch; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
.chat-title { flex: 1; display: flex; flex-direction: column; min-width: 0; text-align: center; }
.chat-title b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-title small { color: var(--muted); font-size: .78rem; }
#btnRooms { position: relative; }
#btnRooms:not([data-badge=""])::after { content: attr(data-badge); position: absolute; top: -4px; right: -4px; background: var(--err); color: #fff; font-size: .7rem; border-radius: 9px; padding: 1px 6px; }
.room-tabs { display: flex; gap: 6px; overflow-x: auto; padding: 6px 10px; background: rgba(5,6,26,.6); scrollbar-width: none; }
.tab { flex: none; display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel2); border-radius: 999px; padding: 5px 12px; font-size: .88rem; cursor: pointer; white-space: nowrap; }
.tab.active { background: var(--accent); border-color: transparent; }
.tab .x { opacity: .7; padding-left: 2px; }
.badge { background: var(--err); color: #fff; border-radius: 9px; font-size: .7rem; padding: 1px 6px; font-weight: 700; }
.messages { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; background: rgba(5,6,26,.55); }
.msg { display: flex; gap: 8px; align-items: flex-end; max-width: 88%; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.av-btn { padding: 0; border: 0; background: none; cursor: pointer; }
.av-btn .av { width: 32px; height: 32px; }
.bubble { background: var(--panel); border: 1px solid var(--line); border-radius: 16px 16px 16px 4px; padding: 6px 12px; min-width: 0; }
.msg.mine .bubble { background: linear-gradient(135deg, #4b53c9, #3a2a9e); border-radius: 16px 16px 4px 16px; }
.meta { font-size: .72rem; color: var(--muted); }
.meta b { color: var(--moon); }
.text { white-space: pre-wrap; overflow-wrap: anywhere; }
.composer { display: flex; gap: 8px; padding: 8px 10px calc(var(--safe-b) + 8px); background: var(--panel); border-top: 1px solid var(--line); }
.composer input { flex: 1; min-width: 0; border-radius: 14px; border: 1px solid var(--line); background: rgba(255,255,255,.06); padding: 10px 14px; }

.drawer { position: fixed; top: 0; bottom: 0; width: min(330px, 86vw); background: #0b0f2e; z-index: 40; padding: calc(var(--safe-t) + 66px) 14px calc(var(--safe-b) + 14px);
  overflow-y: auto; transition: transform .25s ease; display: flex; flex-direction: column; gap: 10px; }
.drawer.left { left: 0; transform: translateX(-105%); border-right: 1px solid var(--line); }
.drawer.right { right: 0; transform: translateX(105%); border-left: 1px solid var(--line); }
.drawer.open { transform: none; }
.drawer h3, .drawer h4 { margin: 0; }
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 35; display: none; }
.drawer-backdrop.open { display: block; }
.room-list, .user-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.room-list li { display: flex; align-items: center; gap: 4px; }
.room-list li.active .room-item { background: rgba(124,140,255,.25); }
.room-item, .user-item { flex: 1; display: flex; align-items: center; gap: 10px; border: 0; background: var(--panel2); padding: 9px 10px; border-radius: 12px; cursor: pointer; text-align: left; min-width: 0; }
.room-item .name, .user-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-ic { width: 28px; text-align: center; }
.count, .lang { color: var(--muted); font-size: .8rem; }
.quit { border: 0; background: none; color: var(--muted); padding: 6px; cursor: pointer; }
.user-list .empty { color: var(--muted); padding: 10px; }
.new-room { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; margin-top: auto; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
input:not([type=checkbox]), select { border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,.06); padding: 10px 12px; width: 100%; }
.check { display: flex; gap: 8px; align-items: center; font-size: .9rem; }

/* dialogs */
dialog.sheet { border: 1px solid var(--line); background: #0d1236; color: var(--text); border-radius: 22px; padding: 18px; width: min(420px, 94vw); max-height: 90vh; overflow-y: auto; }
dialog::backdrop { background: rgba(0,0,0,.6); backdrop-filter: blur(3px); }
dialog h2 { margin: 0 0 8px; }
.close-row { display: flex; justify-content: flex-end; margin: -6px -6px 0 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack.center { align-items: center; text-align: center; }
.stack.center .btn { width: 100%; }
.stack.center h3 { margin: 4px 0 0; }
.stack.center p { margin: 0; }
.providers { display: flex; flex-direction: column; gap: 8px; }
.btn.provider { justify-content: flex-start; }
.btn.provider img { width: 22px; height: 22px; }
.btn.provider.google { background: #fff; color: #1f1f1f; }
.btn.provider.facebook { background: #1877f2; border-color: transparent; }
.btn.provider.apple, .btn.provider.twitter { background: #000; border-color: #333; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); margin: 12px 0; font-size: .85rem; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.error { color: var(--err); min-height: 1.2em; margin: 8px 0 0; }
.profile-photo { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.btn.file { position: relative; }
#btnLogout { width: 100%; margin-top: 12px; }

#toasts { position: fixed; left: 0; right: 0; top: 58%; z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { background: var(--panel); border: 1px solid var(--line); padding: 8px 16px; border-radius: 12px; font-weight: 700; animation: toastIn .25s ease; transition: opacity .4s, transform .4s; backdrop-filter: blur(6px); max-width: 90vw; text-align: center; }
.toast.ok { color: var(--ok); } .toast.warn { color: var(--warn); } .toast.error { color: var(--err); }
.toast.out { opacity: 0; transform: translateY(-10px); }
@keyframes toastIn { from { opacity: 0; transform: scale(.8); } }

#rotateOverlay { display: none; position: fixed; inset: 0; z-index: 100; background: var(--bg); align-items: center; justify-content: center; font-size: 1.3rem; }
@media (orientation: landscape) and (pointer: coarse) and (max-height: 500px) {
  body[data-screen="game"] #rotateOverlay { display: flex; }
}
body[data-screen="chat"] .topbar { background: var(--panel); }
body[data-screen="game"] { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body[data-screen="game"] main { touch-action: none; }
.pull-pop { position: fixed; z-index: 70; transform: translate(-50%, -50%); pointer-events: none; white-space: nowrap;
  font-size: clamp(2rem, 11vw, 4rem); font-weight: 900; color: #ffe7a3;
  text-shadow: 0 0 18px rgba(255,210,120,.8), 0 2px 6px rgba(0,0,0,.6); animation: pullPop 1.4s ease-out forwards; }
.pull-pop.live { animation: none; opacity: 1; }
.pull-pop.great { color: var(--ok); text-shadow: 0 0 22px rgba(93,255,174,.8), 0 2px 6px rgba(0,0,0,.6); }
@keyframes pullPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.5); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  30% { transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -140%) scale(1); }
}
.help-game { position: absolute; right: 12px; bottom: calc(var(--safe-b) + 120px); background: var(--panel); font-weight: 800; }
.game-help { position: absolute; right: 12px; left: 12px; bottom: calc(var(--safe-b) + 176px); max-width: 460px; margin: 0 auto; z-index: 5;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 4px 14px; font-size: .9rem; backdrop-filter: blur(6px); }
.game-help.hidden { display: none; }
#screen-game > * { transition: opacity .4s, visibility 0s; }
#screen-game.zen > * { opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .4s, visibility 0s .4s; }

/* matches */
textarea { font: inherit; color: inherit; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,.06); padding: 10px 12px; width: 100%; resize: vertical; }
input[type=datetime-local] { color-scheme: dark; }
.new-match { width: min(520px, 100%); margin-bottom: 12px; }
.new-match summary { list-style: none; display: block; width: fit-content; margin: 0 auto 10px; }
.new-match summary::-webkit-details-marker { display: none; }
.board-list li.group { background: none; border: 0; padding: 6px 4px 0; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; }
.match-item { cursor: pointer; }
.match-item.live { border-color: var(--err); }
.live-badge { background: var(--err); color: #fff; border-radius: 8px; font-size: .72rem; font-weight: 800; padding: 2px 8px; }
.match .status { align-self: center; }
.match .seg { align-self: center; margin: 0 0 6px; }
.match-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; padding: 0 10px; }
#pane-game { overflow-y: auto; }
#pane-chat, #pane-board { align-items: stretch; padding: 0; }
#pane-board .board-list { width: min(520px, 100%); align-self: center; padding: 0 10px; }
.match-desc { margin: 0 0 8px; padding: 4px 12px; border-radius: 12px; background: var(--panel); color: var(--text, #fff) !important; text-align: center; color: var(--muted); max-width: 460px; overflow-wrap: anywhere; }
.arena { position: relative; flex: 1; width: min(520px, 100%); min-height: min(220px, 60vh); border: 1px solid var(--line); border-radius: 18px; background: rgba(5,6,26,.45); overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.arena-hud { position: absolute; top: 8px; left: 12px; right: 12px; display: flex; justify-content: space-between; font-size: 1.1rem; pointer-events: none; z-index: 2; }
.target-moon { position: absolute; left: 0; top: 0; width: 78px; height: 78px; border-radius: 50%; cursor: pointer; will-change: transform;
  background: radial-gradient(circle at 35% 30%, #fffbe6, #f3e7b8 45%, #c9b97f 75%, #8f8456); box-shadow: 0 0 28px rgba(255,240,180,.55); }
.hit-pop { position: absolute; transform: translate(-50%, -50%); font-size: 1.6rem; font-weight: 900; color: var(--moon); pointer-events: none; animation: pullPop .7s ease-out forwards; }
#screen-match .composer { padding-bottom: calc(var(--safe-b) + 8px); }
#btnMatchPlay { margin: 10px 0 calc(var(--safe-b) + 12px); }

/* cookies */
.cookie-bar { position: fixed; left: 12px; right: 12px; bottom: calc(var(--safe-b) + 12px); z-index: 80; max-width: 520px; margin: 0 auto;
  display: flex; gap: 12px; align-items: center; padding: 10px 14px; background: #0b0f2e; border: 1px solid var(--line); border-radius: 14px; font-size: .88rem; box-shadow: 0 6px 24px rgba(0,0,0,.5); }
.cookie-bar span { flex: 1; }
