:root {
  --navy: #1d2b53;
  --navy-2: #46557f;
  --yellow: #ffd23f;
  --yellow-d: #f2b705;
  --blue: #3d7bff;
  --sky: #dff5ff;
  --gas: #a6e83a;
  --gas-d: #6fbf1a;
  --breath: #5cc8ff;
  --err: #e5484d;
  --line: #e6eef9;
  --shadow: 0 2px 0 rgba(29, 43, 83, 0.06), 0 24px 60px rgba(29, 43, 83, 0.22);
  --r: 26px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #d3f0ff; color: var(--navy); font-family: 'Nunito', system-ui, sans-serif; font-weight: 800; -webkit-font-smoothing: antialiased; user-select: none; }
canvas#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; color: var(--navy); }

.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 28px; z-index: 20; }
.screen.dim { background: rgba(29, 43, 83, 0.35); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.card { background: rgba(255, 255, 255, 0.94); border-radius: var(--r); box-shadow: var(--shadow); padding: 22px; }
.lbl { font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--navy-2); margin: 2px 2px 8px; }
.sub { font-size: 15px; color: var(--navy-2); margin: 8px 2px 14px; line-height: 1.4; font-weight: 700; }
.center { text-align: center; }
.err { color: var(--err); font-size: 14px; min-height: 0; margin-top: 2px; }
.err:empty { display: none; }
.row { display: flex; gap: 12px; margin-top: 14px; }
.row .btn { flex: 1; }

.btn { display: block; width: 100%; border: 0; border-radius: 16px; padding: 14px 18px; font-size: 17px; background: #eef5ff; color: var(--navy); box-shadow: inset 0 -4px 0 #d3e2f6; transition: transform 0.08s, background 0.15s, box-shadow 0.08s; }
.btn:hover { background: #e3eeff; }
.btn:active { transform: translateY(2px); box-shadow: inset 0 -1px 0 #d3e2f6; }
.btn.primary { background: var(--yellow); box-shadow: inset 0 -5px 0 var(--yellow-d); font-size: 21px; padding: 16px 18px; font-family: 'Lilita One', sans-serif; font-weight: 400; letter-spacing: 0.02em; }
.btn.primary:hover { background: #ffdb5c; }
.btn.primary:active { box-shadow: inset 0 -1px 0 var(--yellow-d); }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.mini { border: 0; background: #eef5ff; border-radius: 10px; padding: 7px 12px; font-size: 13px; box-shadow: inset 0 -3px 0 #d3e2f6; }

#menu { justify-content: space-between; align-items: flex-end; gap: 28px; padding: 36px 44px; }
#menu::before { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(211, 240, 255, 0.85) 0%, rgba(211, 240, 255, 0) 38%, rgba(211, 240, 255, 0) 64%, rgba(211, 240, 255, 0.6) 100%); pointer-events: none; z-index: -1; }
.menu-left { width: 380px; max-width: 100%; display: flex; flex-direction: column; gap: 14px; align-self: stretch; justify-content: space-between; }
.logo { font-family: 'Lilita One', sans-serif; font-weight: 400; margin: 0; line-height: 0.84; font-size: 104px; display: flex; flex-direction: column; letter-spacing: 0.01em; }
.logo span { color: var(--yellow); -webkit-text-stroke: 10px var(--navy); paint-order: stroke fill; text-shadow: 0 8px 0 var(--navy); }
.logo span:last-child { color: var(--gas); margin-left: 40px; transform: rotate(-3deg); transform-origin: left center; }
.tag { margin: 10px 4px 0; font-size: 17px; line-height: 1.35; max-width: 320px; }
.play-card { display: flex; flex-direction: column; gap: 10px; margin-top: auto; }
.play-card .lbl { margin-top: 2px; margin-bottom: 0; }
#name { width: 100%; border: 2px solid var(--line); border-radius: 14px; padding: 11px 14px; font-size: 18px; outline: none; background: #f7fbff; }
#name:focus, #code:focus { border-color: var(--blue); }
.picker { display: flex; align-items: center; gap: 10px; background: #f4f8ff; border-radius: 18px; padding: 8px; margin-bottom: 4px; }
.arrow { width: 44px; height: 44px; flex: none; border: 0; border-radius: 14px; background: #fff; box-shadow: inset 0 -3px 0 #d3e2f6; display: grid; place-items: center; }
.arrow svg { width: 22px; height: 22px; fill: none; stroke: var(--navy); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.arrow:active { transform: translateY(2px); }
.picked { flex: 1; text-align: center; }
#animal-name { font-family: 'Lilita One', sans-serif; font-size: 26px; font-weight: 400; line-height: 1.1; }
.dots { display: flex; justify-content: center; gap: 6px; margin-top: 6px; }
.dots button { width: 14px; height: 14px; border-radius: 50%; border: 0; padding: 0; opacity: 0.45; transition: transform 0.15s, opacity 0.15s; }
.dots button.on { opacity: 1; transform: scale(1.3); box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--navy); }
.split { display: flex; flex-direction: column; gap: 10px; }
.join { display: flex; gap: 10px; }
.join .btn { width: auto; flex: 0 0 110px; }
#code { flex: 1; min-width: 0; border: 2px solid var(--line); border-radius: 16px; padding: 10px 6px; font-size: 19px; letter-spacing: 0.22em; text-transform: uppercase; outline: none; background: #f7fbff; font-family: 'Lilita One', sans-serif; text-align: center; }

.menu-right { width: 360px; max-width: 100%; }
.tabs { display: flex; background: #eef5ff; border-radius: 14px; padding: 4px; margin-bottom: 16px; }
.tabs button { flex: 1; border: 0; background: transparent; border-radius: 11px; padding: 9px 10px; font-size: 14px; color: var(--navy-2); }
.tabs button.on { background: #fff; color: var(--navy); box-shadow: 0 2px 6px rgba(29, 43, 83, 0.1); }
.krow { display: flex; align-items: flex-start; gap: 6px; padding: 10px 2px; border-bottom: 2px solid #f0f5fc; }
.krow p { margin: 0 0 0 8px; font-size: 14px; line-height: 1.35; color: var(--navy-2); font-weight: 700; }
.krow p b { display: block; color: var(--navy); font-size: 16px; font-weight: 900; }
.kc { display: inline-grid; place-items: center; min-width: 38px; height: 38px; padding: 0 8px; border-radius: 10px; background: #fff; border: 2px solid var(--line); box-shadow: inset 0 -4px 0 #e2ebf8; font-size: 15px; font-weight: 900; color: var(--navy); flex: none; }
.kc.wide { min-width: 82px; }
.kc.sm { min-width: 0; height: 22px; font-size: 11px; padding: 0 6px; border-radius: 6px; border-width: 1px; box-shadow: inset 0 -2px 0 #e2ebf8; vertical-align: middle; }
.rules { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.rules li { display: flex; gap: 10px; font-size: 13.5px; line-height: 1.35; color: var(--navy-2); font-weight: 700; }
.rules i { width: 12px; height: 12px; border-radius: 50%; flex: none; margin-top: 3px; }
.credits { margin: 14px 2px 0; font-size: 11.5px; line-height: 1.4; color: #8a97b5; font-weight: 700; }
.seg { display: flex; gap: 6px; margin-bottom: 10px; }
.seg button { border: 0; background: #f4f8ff; border-radius: 10px; padding: 6px 12px; font-size: 13px; color: var(--navy-2); }
.seg button.on { background: var(--navy); color: #fff; }
.scores { list-style: none; margin: 0; padding: 0; counter-reset: s; max-height: 46vh; overflow: auto; }
.scores li { counter-increment: s; display: flex; align-items: baseline; gap: 10px; padding: 9px 6px; border-bottom: 2px solid #f0f5fc; font-size: 15px; }
.scores li::before { content: counter(s); width: 22px; text-align: right; color: var(--navy-2); font-size: 13px; }
.scores li .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scores li .tm { font-family: 'Lilita One', sans-serif; font-weight: 400; font-size: 17px; }
.scores li.me { background: #fff8d6; border-radius: 10px; }
.scores .empty { color: var(--navy-2); font-size: 14px; padding: 12px 6px; }
.scores .empty::before { content: none; }

.lobby-card { width: 380px; max-width: 100%; margin-left: auto; margin-right: 1vw; }
.room-code { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
#room-code { font-family: 'Lilita One', sans-serif; font-size: 66px; letter-spacing: 0.12em; line-height: 1; }
.plist { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.plist li { display: flex; align-items: center; gap: 12px; background: #f4f8ff; border-radius: 14px; padding: 11px 14px; font-size: 16px; }
.plist li i { width: 20px; height: 20px; border-radius: 6px; }
.plist li .who { flex: 1; }
.plist li .badge { font-size: 11px; background: var(--yellow); border-radius: 8px; padding: 3px 8px; letter-spacing: 0.06em; }
.plist li.empty { background: transparent; border: 2px dashed #dbe6f5; color: #9fb0cc; }

.pause-card, .res-card { width: 360px; display: flex; flex-direction: column; gap: 12px; }
.pause-title, .res-title { font-family: 'Lilita One', sans-serif; font-size: 40px; text-align: center; font-weight: 400; }
.res-card { width: 410px; }
.res-time { font-family: 'Lilita One', sans-serif; font-size: 76px; text-align: center; line-height: 1; color: var(--blue); }
.res-stats { display: flex; justify-content: center; gap: 18px; font-size: 14px; color: var(--navy-2); }
.res-stats b { color: var(--navy); font-size: 18px; }
#res-scores { max-height: 30vh; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.hud-top { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; }
#timer { font-family: 'Lilita One', sans-serif; font-size: 38px; color: #fff; -webkit-text-stroke: 6px var(--navy); paint-order: stroke fill; text-shadow: 0 3px 0 var(--navy); line-height: 1; font-variant-numeric: tabular-nums; }
#prog { position: relative; width: 220px; height: 6px; border-radius: 3px; background: rgba(29, 43, 83, 0.35); }
#prog-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; background: #fff; width: 0; }
#prog-ticks i { position: absolute; top: 50%; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; background: rgba(255, 255, 255, 0.7); box-shadow: 0 0 0 2px var(--navy); }
#prog-ticks i.on { background: var(--yellow); }
#prog-ticks i.fin { border-radius: 2px; }

#gas { position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); width: 260px; display: flex; flex-direction: column; gap: 6px; }
.gas-bar, .breath-bar { position: relative; height: 14px; border-radius: 8px; background: rgba(29, 43, 83, 0.5); box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85); overflow: hidden; }
#gas-fill { position: absolute; inset: 2px; border-radius: 6px; background: linear-gradient(180deg, #d0f76c, var(--gas) 55%, var(--gas-d)); transform-origin: left center; }
.breath-bar { height: 8px; opacity: 0; transition: opacity 0.25s; }
.breath-bar.show { opacity: 1; }
#breath-fill { position: absolute; inset: 1px; border-radius: 4px; background: var(--breath); transform-origin: left center; }
#gas.low #gas-fill { animation: low 0.45s infinite alternate; }
#gas.bean #gas-fill { animation: beanflash 0.6s; }
@keyframes low { to { filter: brightness(1.6); } }
@keyframes beanflash { 0% { filter: brightness(2.2); } 100% { filter: none; } }

.big { position: fixed; left: 50%; top: 36%; transform: translate(-50%, -50%); z-index: 15; pointer-events: none; text-align: center; font-family: 'Lilita One', sans-serif; color: #fff; -webkit-text-stroke: 10px var(--navy); paint-order: stroke fill; text-shadow: 0 7px 0 var(--navy); font-size: 110px; line-height: 0.95; opacity: 0; white-space: nowrap; }
.big small { display: block; font-size: 30px; -webkit-text-stroke: 6px var(--navy); text-shadow: 0 4px 0 var(--navy); margin-top: 12px; }
.big em { display: block; font-style: normal; font-family: 'Nunito', sans-serif; font-weight: 900; font-size: 19px; color: var(--navy); -webkit-text-stroke: 0; text-shadow: none; background: rgba(255, 255, 255, 0.92); border-radius: 12px; padding: 7px 14px; margin: 14px auto 0; width: max-content; }
.big.go { color: var(--gas); }
.big.cp { color: var(--yellow); font-size: 72px; }
.big.show { animation: bigpop 2.3s cubic-bezier(.2, 1.4, .4, 1) forwards; }
@keyframes bigpop { 0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4); } 10% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); } 18% { transform: translate(-50%, -50%) scale(1); } 82% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -58%) scale(1); } }

.toast { position: fixed; left: 50%; top: 90px; transform: translateX(-50%); z-index: 30; background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 12px; font-size: 15px; opacity: 0; transition: opacity 0.3s; pointer-events: none; }
.toast.show { opacity: 1; }
.toast.error { background: var(--err); }

#iris { position: fixed; inset: 0; z-index: 14; pointer-events: none; background: var(--sky); clip-path: circle(0% at 50% 50%); }

.loading { position: fixed; inset: 0; z-index: 50; background: #d3f0ff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; font-size: 18px; transition: opacity 0.5s; }
.loading.out { opacity: 0; pointer-events: none; }
.spin-ring { width: 64px; height: 64px; border-radius: 50%; border: 12px solid #fff; border-top-color: #ff8a2a; border-bottom-color: #ff8a2a; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1100px) {
  #menu { flex-direction: column; align-items: flex-start; justify-content: flex-start; overflow: auto; padding: 24px; }
  #menu::before { background: linear-gradient(90deg, rgba(211, 240, 255, 0.7) 0%, rgba(211, 240, 255, 0) 55%); }
  .menu-left { align-self: auto; }
  .play-card { margin-top: 8px; }
  .logo { font-size: 80px; }
  .lobby-card { margin: 0 auto; }
}
