:root {
  --lime: #CCFF00; --pale: #EDFFB0; --ink: #080A04; --panel: #0E1206; --panel2: #23271a;
  --muted: #A6AA9C; --white: #F4F6F4; --red: #FF2A3C; --deepred: #B3121F;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--white); overflow: hidden; overscroll-behavior: none; }
body { font-family: 'Chakra Petch', system-ui, sans-serif; font-weight: 500; user-select: none; -webkit-user-select: none; touch-action: none; }
[hidden] { display: none !important; }
canvas#gl, canvas#ov { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
canvas#ov { pointer-events: none; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--lime); }

.panel { background: rgba(14, 18, 6, 0.82); border: 1px solid rgba(204, 255, 0, 0.22); border-radius: 10px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.lbl { font-size: 11px; font-weight: 700; letter-spacing: 0.14em; color: var(--muted); text-transform: uppercase; }
.kicker { font-weight: 700; letter-spacing: 0.22em; font-size: 13px; color: var(--lime); text-transform: uppercase; }
.kicker.r, .r { color: var(--red); }
.g { color: var(--lime); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { position: absolute; }
#hud-herd { left: calc(12px + var(--sal)); top: calc(12px + var(--sat)); padding: 10px 16px 10px 14px; min-width: 132px; }
#herd-n { font-family: 'Unbounded', sans-serif; font-weight: 900; font-size: 44px; line-height: 1; color: var(--lime); margin: 4px 0 2px; text-shadow: 0 0 18px rgba(204, 255, 0, 0.35); transition: transform 0.12s; }
#herd-n.pop { transform: scale(1.18); }
#herd-n.hit { color: var(--red); text-shadow: 0 0 18px rgba(255, 42, 60, 0.5); }
#herd-rank { font-family: 'JetBrains Mono', monospace; font-weight: 700; font-size: 13px; color: var(--white); }
#hud-top { left: 50%; top: calc(12px + var(--sat)); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; }
#timer { font-family: 'JetBrains Mono', monospace; font-weight: 700; font-size: 22px; padding: 6px 16px; letter-spacing: 0.04em; }
#timer.late { color: var(--red); border-color: rgba(255, 42, 60, 0.6); }
#chips { display: flex; gap: 6px; }
.chip { font-family: 'JetBrains Mono', monospace; font-weight: 700; font-size: 12px; padding: 4px 9px; border-radius: 999px; background: var(--lime); color: var(--ink); white-space: nowrap; }
.chip.warn { background: var(--red); color: var(--white); }
.chip.dim { background: var(--panel2); color: var(--pale); }
#hud-right { right: calc(12px + var(--sar)); top: calc(12px + var(--sat)); display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
#board { padding: 10px 12px; width: 212px; }
#board ol { list-style: none; margin: 6px 0 0; padding: 0; font-size: 13px; }
#board li { display: flex; gap: 6px; padding: 2px 0; align-items: baseline; color: var(--white); }
#board li .rk { font-family: 'JetBrains Mono', monospace; color: var(--muted); width: 20px; flex: none; font-size: 11px; }
#board li .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#board li .ct { font-family: 'JetBrains Mono', monospace; font-weight: 700; }
#board li.me { color: var(--lime); font-weight: 700; }
#board li.gap { border-top: 1px dashed rgba(166, 170, 156, 0.35); margin-top: 3px; padding-top: 4px; }
#hud-btns { display: flex; gap: 8px; pointer-events: auto; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; background: rgba(14, 18, 6, 0.82); border: 1px solid rgba(204, 255, 0, 0.22); font-size: 19px; line-height: 1; color: var(--lime); padding: 0; }
.icon-btn.off { color: var(--muted); text-decoration: line-through; }

#banner { left: 50%; top: 21%; transform: translateX(-50%); text-align: center; width: min(92vw, 900px); animation: banner-in 0.35s cubic-bezier(.2, 1.4, .4, 1); }
#banner-t { font-family: 'Unbounded', sans-serif; font-weight: 900; font-size: clamp(30px, 6.4vw, 72px); line-height: 1; color: var(--lime); text-shadow: 0 4px 0 var(--ink), 0 0 34px rgba(204, 255, 0, 0.55); letter-spacing: 0.01em; }
#banner-s { margin-top: 10px; font-weight: 700; font-size: clamp(14px, 2.2vw, 20px); color: var(--white); text-shadow: 0 2px 0 var(--ink); }
#banner.red #banner-t { color: var(--red); text-shadow: 0 4px 0 var(--ink), 0 0 34px rgba(255, 42, 60, 0.6); }
#banner.out { opacity: 0; transition: opacity 0.5s; }
@keyframes banner-in { from { transform: translateX(-50%) scale(1.6); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }

#feed { left: calc(12px + var(--sal)); top: calc(118px + var(--sat)); display: flex; flex-direction: column; gap: 4px; align-items: flex-start; font-size: 13px; }
#feed div { background: rgba(8, 10, 4, 0.72); border-left: 3px solid var(--lime); padding: 3px 9px; border-radius: 0 6px 6px 0; animation: feed-in 0.2s ease-out; transition: opacity 0.6s; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#feed div.red { border-left-color: var(--red); }
#feed div.old { opacity: 0; }
#feed b { color: var(--lime); }
#feed i { color: var(--red); font-style: normal; font-weight: 700; }
@keyframes feed-in { from { transform: translateX(-16px); opacity: 0; } to { transform: none; opacity: 1; } }

#minimap { left: calc(12px + var(--sal)); bottom: calc(12px + var(--sab)); width: 160px; height: 160px; border-radius: 10px; border: 1px solid rgba(204, 255, 0, 0.3); background: rgba(8, 10, 4, 0.8); }
#hint { left: 50%; bottom: calc(22px + var(--sab)); transform: translateX(-50%); font-weight: 700; font-size: 14px; color: var(--pale); text-shadow: 0 2px 0 var(--ink); text-align: center; white-space: nowrap; transition: opacity 0.4s; }
#btn-charge { right: calc(22px + var(--sar)); bottom: calc(26px + var(--sab)); width: 104px; height: 104px; border-radius: 50%; border: none; background: rgba(14, 18, 6, 0.8); pointer-events: auto; padding: 0; display: grid; place-items: center; touch-action: none; }
#btn-charge svg { position: absolute; inset: 0; transform: rotate(-90deg); }
#btn-charge circle { fill: none; stroke: var(--lime); stroke-width: 7; stroke-dasharray: 282.7; stroke-dashoffset: 0; }
#btn-charge span { font-family: 'Unbounded', sans-serif; font-weight: 900; font-size: 13px; color: var(--lime); letter-spacing: 0.02em; }
#btn-charge.cd circle { stroke: var(--muted); }
#btn-charge.cd span { color: var(--muted); }
#btn-charge.live { box-shadow: 0 0 26px rgba(204, 255, 0, 0.45); }
#btn-charge.wind circle { stroke: var(--red); }
#btn-charge.wind span { color: var(--red); }
#joy { width: 124px; height: 124px; margin: -62px 0 0 -62px; border-radius: 50%; border: 2px solid rgba(204, 255, 0, 0.45); background: rgba(14, 18, 6, 0.35); }
#joy-knob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%; background: rgba(204, 255, 0, 0.85); }
#netwarn { left: 50%; top: 45%; transform: translate(-50%, -50%); background: var(--red); color: var(--white); font-weight: 700; padding: 8px 18px; border-radius: 8px; letter-spacing: 0.1em; }
#fps { position: fixed; left: calc(180px + var(--sal)); bottom: calc(12px + var(--sab)); font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--muted); pointer-events: none; white-space: pre; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
.overlay { background: rgba(8, 10, 4, 0.78); display: grid; place-items: center; padding: 16px; backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.card { background: rgba(14, 18, 6, 0.92); border: 1px solid rgba(204, 255, 0, 0.25); border-radius: 14px; padding: 18px; }
.card.center { text-align: center; width: min(92vw, 440px); padding: 26px 22px; }
h1, h2 { font-family: 'Unbounded', sans-serif; font-weight: 900; text-transform: uppercase; margin: 0; }
h2 { font-size: clamp(24px, 5vw, 38px); line-height: 1.05; margin: 8px 0 10px; }
.cta { display: inline-block; font-family: 'Unbounded', sans-serif; font-weight: 900; font-size: 20px; text-transform: uppercase; text-decoration: none; text-align: center; color: var(--ink); background: var(--lime); border: none; border-radius: 12px; padding: 15px 26px; box-shadow: 0 5px 0 #7a9900; transition: transform 0.06s, box-shadow 0.06s; }
.cta:active { transform: translateY(4px); box-shadow: 0 1px 0 #7a9900; }
.cta:disabled { background: var(--panel2); color: var(--muted); box-shadow: 0 5px 0 #14170d; }
.cta.small { font-size: 14px; padding: 11px 18px; border-radius: 10px; }
.cta.ghost { background: transparent; color: var(--lime); box-shadow: inset 0 0 0 2px var(--lime); }
.link { background: none; border: none; padding: 0; color: var(--lime); text-decoration: underline; }

#title { background: var(--ink); }
.title-art { position: fixed; inset: 0; background: url('../img/title.jpg') center 30% / cover no-repeat; }
.title-art::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(8, 10, 4, 0.96) 0%, rgba(8, 10, 4, 0.86) 36%, rgba(8, 10, 4, 0.25) 72%, rgba(8, 10, 4, 0.1) 100%), linear-gradient(0deg, rgba(8, 10, 4, 0.9) 0%, rgba(8, 10, 4, 0) 40%); }
.title-wrap { position: relative; max-width: 620px; padding: calc(28px + var(--sat)) 28px calc(22px + var(--sab)) calc(40px + var(--sal)); display: flex; flex-direction: column; gap: 14px; min-height: 100%; }
#title h1 { font-size: clamp(46px, 9.4vw, 92px); line-height: 0.92; color: var(--lime); text-shadow: 0 5px 0 var(--ink), 0 0 44px rgba(204, 255, 0, 0.35); margin: 6px 0 8px; letter-spacing: -0.01em; }
.tag { margin: 0; font-size: 17px; color: var(--white); }
.tag b { color: var(--lime); }
#join { display: flex; flex-direction: column; gap: 9px; }
#name { font: 700 20px 'Chakra Petch', sans-serif; color: var(--white); background: var(--ink); border: 2px solid var(--panel2); border-radius: 10px; padding: 12px 14px; outline: none; user-select: text; -webkit-user-select: text; width: 100%; }
#name:focus { border-color: var(--lime); }
#skins { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
#skins button { aspect-ratio: 1; border-radius: 10px; border: 2px solid var(--panel2); background: var(--ink); padding: 3px; position: relative; }
#skins button canvas { width: 100%; height: 100%; display: block; }
#skins button.on { border-color: var(--lime); box-shadow: 0 0 16px rgba(204, 255, 0, 0.35); }
#join .cta { margin-top: 6px; font-size: 24px; }
#join-status { min-height: 18px; font-size: 13px; color: var(--muted); text-align: center; }
.cols { display: grid; grid-template-columns: 1.25fr 1fr; gap: 12px; }
.how ul { margin: 8px 0 0; padding: 0 0 0 18px; font-size: 14px; line-height: 1.42; color: var(--white); }
.how li { margin-bottom: 5px; }
.how b { color: var(--lime); }
.keys { margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.best ol { list-style: none; margin: 8px 0 0; padding: 0; font-size: 14px; }
.best li { display: flex; gap: 8px; padding: 3px 0; }
.best li span:first-child { font-family: 'JetBrains Mono', monospace; color: var(--muted); width: 22px; }
.best li span:nth-child(2) { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.best li span:last-child { font-family: 'JetBrains Mono', monospace; font-weight: 700; color: var(--lime); }
.best li.empty { color: var(--muted); }
footer { margin-top: auto; font-size: 12.5px; color: var(--muted); padding-top: 6px; }

#dead-sub { color: var(--muted); margin: 0 0 18px; }
#dead-sub b { color: var(--lime); font-family: 'JetBrains Mono', monospace; }

.end-wrap { width: min(100%, 980px); text-align: center; padding: 8px 0; }
#podium { display: flex; justify-content: center; align-items: flex-end; gap: 10px; margin: 10px 0 14px; }
.pod { width: 30%; max-width: 210px; background: rgba(14, 18, 6, 0.92); border: 1px solid rgba(204, 255, 0, 0.25); border-bottom: none; border-radius: 12px 12px 0 0; padding: 10px 8px 12px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.pod canvas { width: 62px; height: 62px; }
.pod .pl { font-family: 'Unbounded', sans-serif; font-weight: 900; font-size: 22px; color: var(--muted); }
.pod .nm { font-weight: 700; font-size: 15px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pod .ct { font-family: 'JetBrains Mono', monospace; font-weight: 700; font-size: 20px; color: var(--lime); }
.pod.p1 { padding-bottom: 46px; border-color: var(--lime); box-shadow: 0 0 30px rgba(204, 255, 0, 0.25); }
.pod.p1 .pl { color: var(--lime); font-size: 30px; }
.pod.p2 { padding-bottom: 26px; }
.pod.me .nm { color: var(--lime); }
.end-cols { display: grid; grid-template-columns: 1fr 1.35fr; gap: 12px; align-items: start; text-align: left; }
#end-list { list-style: none; margin: 0; font-size: 14px; }
#end-list li { display: flex; gap: 8px; padding: 3px 0; }
#end-list li span:first-child { font-family: 'JetBrains Mono', monospace; color: var(--muted); width: 24px; }
#end-list li span:nth-child(2) { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#end-list li span:last-child { font-family: 'JetBrains Mono', monospace; font-weight: 700; }
#end-list li.me { color: var(--lime); font-weight: 700; }
.end-cols > * { min-width: 0; }
.share { padding: 10px; }
#card { width: 100%; height: auto; display: block; border-radius: 8px; }
.share-btns { display: flex; gap: 10px; margin-top: 10px; justify-content: center; }
#end-next { margin-top: 12px; color: var(--muted); font-weight: 700; }
#end-next b { color: var(--lime); font-family: 'JetBrains Mono', monospace; }

.settings { text-align: left !important; display: flex; flex-direction: column; gap: 12px; }
.settings h2 { text-align: center; }
.settings label { display: flex; align-items: center; justify-content: space-between; gap: 14px; font-weight: 700; }
.settings label.row { justify-content: flex-start; }
.settings input[type=range] { flex: 1; max-width: 220px; accent-color: var(--lime); }
.settings input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--lime); }
.settings .cta { align-self: center; margin-top: 6px; }

body.touch #hint { bottom: calc(264px + var(--sab)); font-size: 12px; }
body:not(.touch) #btn-charge { width: 78px; height: 78px; right: calc(16px + var(--sar)); bottom: calc(16px + var(--sab)); }
body:not(.touch) #btn-charge span { font-size: 10px; }

@media (max-width: 760px) {
  .title-art { background-position: 68% 0; background-size: auto 46%; }
  .title-art::after { background: linear-gradient(0deg, rgba(8, 10, 4, 1) 0%, rgba(8, 10, 4, 1) 52%, rgba(8, 10, 4, 0.55) 70%, rgba(8, 10, 4, 0.15) 100%); }
  .title-wrap { padding: calc(92px + var(--sat)) 16px calc(16px + var(--sab)); max-width: none; }
  .cols { grid-template-columns: 1fr; }
  .end-cols { grid-template-columns: 1fr; }
  #end-list { display: none; }
  #hud-herd { padding: 7px 10px; min-width: 96px; }
  #herd-n { font-size: 32px; }
  #board { width: 148px; padding: 7px 9px; }
  #board ol { font-size: 11.5px; }
  #board li:nth-child(n+4):not(.me) { display: none; }
  #banner { top: calc(176px + var(--sat)); width: 84vw; }
  #banner-t { font-size: 30px; }
  #banner-s { font-size: 13px; margin-top: 6px; text-wrap: balance; }
  #timer { font-size: 17px; padding: 5px 11px; }
  #minimap { width: 104px; height: 104px; bottom: calc(150px + var(--sab)); }
  #feed { top: calc(96px + var(--sat)); font-size: 11.5px; }
  #feed div:nth-last-child(n+4) { display: none; }
  .icon-btn { width: 36px; height: 36px; }
  #fps { left: calc(12px + var(--sal)); bottom: calc(262px + var(--sab)); }
}
@media (max-height: 520px) and (orientation: landscape) {
  #board li:nth-child(n+6):not(.me) { display: none; }
  #minimap { width: 110px; height: 110px; }
  .title-wrap { padding-top: 14px; gap: 8px; }
  #title h1 { font-size: 44px; }
  .cols { display: none; }
}

#intro { z-index: 60; display: flex; background: radial-gradient(120% 80% at 50% 0%, #141a08 0%, var(--ink) 62%); cursor: pointer; }
#intro-skip { position: fixed; z-index: 61; top: calc(12px + var(--sat)); right: calc(12px + var(--sar)); min-height: 44px; min-width: 84px; padding: 0 18px; font-family: 'Unbounded', sans-serif; font-weight: 900; font-size: 13px; letter-spacing: 0.08em; color: var(--lime); background: rgba(14, 18, 6, 0.9); border: 2px solid var(--lime); border-radius: 12px; }
.intro-wrap { margin: auto; width: min(100%, 880px); padding: calc(68px + var(--sat)) 20px calc(22px + var(--sab)); display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; }
#intro-cv { display: block; width: 100%; aspect-ratio: 16 / 9; max-height: 50vh; border-radius: 16px; border: 1px solid rgba(204, 255, 0, 0.28); background: var(--panel); box-shadow: 0 0 60px rgba(204, 255, 0, 0.08); }
#intro-k { margin-top: 8px; }
#intro-h { margin: 0; text-wrap: balance; color: var(--lime); text-shadow: 0 4px 0 var(--ink), 0 0 34px rgba(204, 255, 0, 0.3); }
#intro-p { margin: 0; max-width: 600px; min-height: 4.2em; font-size: 17px; line-height: 1.4; font-weight: 600; color: var(--white); text-wrap: balance; }
#intro-dots { display: flex; gap: 8px; }
#intro-dots span { width: 10px; height: 10px; border-radius: 5px; background: var(--panel2); transition: width 0.2s, background 0.2s; }
#intro-dots span.on { width: 28px; background: var(--lime); }
#intro-next { min-width: 200px; margin-top: 6px; }
.how-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
#how-replay { font-weight: 700; font-size: 14px; padding: 8px 0; }
@media (max-width: 760px) {
  .intro-wrap { padding: calc(66px + var(--sat)) 14px calc(16px + var(--sab)); }
  #intro-cv { aspect-ratio: 1 / 1; max-height: 46vh; }
  #intro-p { font-size: 15.5px; min-height: 5.6em; }
}
@media (prefers-reduced-motion: reduce) { #intro-dots span { transition: none; } }
@media (max-height: 480px) and (orientation: landscape) {
  .intro-wrap { display: grid; grid-template-columns: 1.1fr 1fr; column-gap: 18px; row-gap: 6px; align-items: center; justify-items: center; padding: calc(12px + var(--sat)) calc(16px + var(--sar)) calc(12px + var(--sab)) calc(16px + var(--sal)); }
  #intro-cv { grid-row: 1 / span 5; aspect-ratio: 4 / 3; max-height: calc(100vh - 24px); }
  #intro-k { margin-top: 46px; }
  #intro-h { font-size: 21px; }
  #intro-p { font-size: 14px; min-height: 0; }
  #intro-next { min-width: 150px; padding: 10px 20px; font-size: 16px; margin-top: 2px; }
}
