:root {
  --sea: #0b3a55; --deep: #06202f; --foam: #e8fbff; --gold: #ffcc33; --coral: #ff6f7d; --kelp: #4fd38a;
  --panel: rgba(6, 32, 50, 0.86); --ink: #eaf8ff; --muted: #9cc4d6;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #06202f; color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif; -webkit-user-select: none; user-select: none; touch-action: none; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
button { font: inherit; cursor: pointer; border: none; color: var(--ink); }
input { font: inherit; }

.screen { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.screen.show { display: flex; }
.panel { background: var(--panel); border: 3px solid rgba(160, 230, 255, 0.35); border-radius: 28px; padding: 22px 26px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5), inset 0 0 40px rgba(80, 200, 255, 0.08); max-width: 960px; width: 100%;
  max-height: calc(100vh - 32px); overflow: auto; text-align: center; backdrop-filter: blur(6px); }
h2 { margin: 6px 0 14px; font-size: 1.7rem; color: var(--gold); text-shadow: 0 3px 0 #7a4a00; }
.msg { min-height: 1.3em; color: #ffd6a0; margin: 10px 0 0; }
.hint { color: var(--muted); font-size: .92rem; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.menu { display: flex; flex-direction: column; gap: 10px; align-items: stretch; max-width: 380px; margin: 14px auto 0; }

.big { background: linear-gradient(#2a8fc4, #16618f); padding: 12px 20px; border-radius: 18px; font-size: 1.15rem; font-weight: bold;
  box-shadow: 0 5px 0 #0b3a55, 0 8px 16px rgba(0,0,0,.35); transition: transform .08s; }
.big:hover { filter: brightness(1.15); }
.big:active { transform: translateY(3px); box-shadow: 0 2px 0 #0b3a55; }
.big.go { background: linear-gradient(#ffd54a, #f0a012); color: #4a2a00; box-shadow: 0 5px 0 #9a5a00, 0 8px 16px rgba(0,0,0,.35); }
.big:disabled { filter: grayscale(1) brightness(.7); cursor: default; }
.small { background: rgba(255,255,255,.12); padding: 7px 12px; border-radius: 12px; font-size: .95rem; }
.small:hover { background: rgba(255,255,255,.22); }
.small.sel { background: var(--gold); color: #4a2a00; font-weight: bold; }

/* title */
.title-panel { max-width: 520px; }
.logo { margin: 0; font-size: clamp(2.6rem, 9vw, 4.2rem); line-height: .95; letter-spacing: 1px; }
.logo span:first-child { color: var(--gold); text-shadow: 0 4px 0 #8a5500, 0 0 30px rgba(255, 200, 60, .5); display: block; }
.logo span:last-child { color: #6ff0ff; text-shadow: 0 4px 0 #0a5a7a, 0 0 30px rgba(80, 230, 255, .5); }
.tag { color: var(--muted); margin: 10px 0 16px; }
.name-row { display: flex; align-items: center; gap: 8px; justify-content: center; color: var(--muted); }
.name-row input, .join-row input { background: rgba(0,0,0,.35); border: 2px solid rgba(160,230,255,.4); color: var(--ink); border-radius: 12px; padding: 8px 12px; width: 150px; text-align: center; font-weight: bold; }
.join-row { display: flex; gap: 8px; }
.join-row input { width: 110px; text-transform: uppercase; letter-spacing: 4px; font-size: 1.2rem; }
.join-row button { flex: 1; }

/* lobby */
.room-box { display: none; background: rgba(255, 204, 51, .12); border: 2px dashed var(--gold); border-radius: 18px; padding: 10px; margin-bottom: 10px; }
.room-box.show { display: block; }
.room-code { font-size: 3rem; font-weight: bold; letter-spacing: 12px; color: var(--gold); }
.char-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 720px) { .char-grid { grid-template-columns: repeat(2, 1fr); } }
.card { background: rgba(255,255,255,.07); border: 3px solid transparent; border-radius: 20px; padding: 8px 10px 12px; text-align: left; position: relative; color: var(--ink); }
.card:hover { background: rgba(255,255,255,.13); }
.card.sel { border-color: var(--gold); background: rgba(255, 204, 51, .15); }
.card.taken { opacity: .45; cursor: not-allowed; }
.card img { width: 100%; max-width: 112px; aspect-ratio: 1; display: block; margin: 0 auto; }
.card h3 { margin: 0 0 4px; text-align: center; }
.card .pw { color: #8ff7b0; font-size: .85rem; margin: 3px 0; }
.card .wk { color: #ffb0a0; font-size: .85rem; margin: 3px 0; }
.card .who { position: absolute; top: 8px; right: 8px; background: var(--gold); color: #4a2a00; border-radius: 10px; padding: 2px 8px; font-size: .8rem; font-weight: bold; }
.lobby-panel { display: flex; flex-direction: column; overflow: hidden; }
.lobby-panel .char-grid { overflow-y: auto; flex: 1 1 auto; min-height: 90px; padding: 2px; }
.lobby-bottom { margin-top: 10px; flex: 0 0 auto; }
.player-list { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.player-list .pl { background: rgba(255,255,255,.1); border-radius: 14px; padding: 5px 12px; }
.player-list .pl.host::after { content: " 👑"; }
.diff { margin-top: 10px; display: flex; gap: 6px; justify-content: center; align-items: center; flex-wrap: wrap; }

/* loading */
.loading-box { text-align: center; font-size: 1.4rem; }
.bubbles { display: flex; gap: 12px; justify-content: center; }
.bubbles i { width: 22px; height: 22px; border-radius: 50%; border: 3px solid #9ef; animation: bub 1s infinite ease-in-out; }
.bubbles i:nth-child(2) { animation-delay: .15s; } .bubbles i:nth-child(3) { animation-delay: .3s; }
@keyframes bub { 50% { transform: translateY(-16px) scale(1.2); } }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; display: none; z-index: 10; }
#hud.show { display: block; }
.hud-tl { position: absolute; left: 14px; top: 12px; display: flex; flex-direction: column; gap: 8px; }
.hearts { font-size: 1.9rem; filter: drop-shadow(0 2px 2px rgba(0,0,0,.6)); letter-spacing: 2px; }
.hearts .lost { filter: grayscale(1) brightness(.5); opacity: .5; }
.hearts.hit { animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.air { display: none; align-items: center; gap: 8px; font-weight: bold; color: #bff; }
.air.show { display: flex; }
.air .bar { width: 180px; height: 16px; border-radius: 10px; background: rgba(0,0,0,.45); border: 2px solid #9ef; overflow: hidden; }
.air .bar div { height: 100%; width: 100%; background: linear-gradient(90deg, #6ff0ff, #d8ffff); transition: width .2s; }
.air.low .bar { border-color: #ff6f6f; animation: pulse .6s infinite; }
.air.low .bar div { background: linear-gradient(90deg, #ff6f6f, #ffc0a0); }
@keyframes pulse { 50% { box-shadow: 0 0 16px #ff4040; } }
.chips { display: flex; gap: 8px; }
.chip { position: relative; overflow: hidden; background: rgba(0,0,0,.45); border: 2px solid rgba(160,230,255,.4); border-radius: 14px; padding: 5px 12px; min-width: 96px; }
.chip b { position: relative; z-index: 1; } .chip small { position: relative; z-index: 1; opacity: .7; margin-left: 4px; }
.chip .fill { position: absolute; left: 0; top: 0; bottom: 0; width: 100%; background: rgba(79, 211, 138, .45); transition: width .1s; }
.chip.power.ready { border-color: #8ff7b0; box-shadow: 0 0 12px rgba(143,247,176,.5); }
.chip.power.active { border-color: var(--gold); box-shadow: 0 0 16px rgba(255,204,51,.8); }
.chip.power.active .fill { background: rgba(255, 204, 51, .55); }
.inv { display: flex; gap: 8px; font-size: 1.25rem; }
.inv-item { background: rgba(0,0,0,.45); border-radius: 12px; padding: 3px 10px; }
.inv-item.off { opacity: .35; filter: grayscale(1); }
.inv-item b { font-size: 1rem; }
.hud-tr { position: absolute; right: 14px; top: 12px; }
.cave-list { background: rgba(0,0,0,.45); border-radius: 16px; padding: 8px 12px; font-size: .95rem; min-width: 200px; }
.cave-list .t { color: var(--gold); font-weight: bold; margin-bottom: 4px; }
.cave-list .cv { display: flex; align-items: center; gap: 6px; }
.cave-list .cv i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.cave-list .cv.no { text-decoration: line-through; opacity: .5; }
.cave-list .cv.yes { color: var(--gold); font-weight: bold; }
.compass { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); width: min(420px, 50vw); height: 34px; overflow: hidden;
  background: rgba(0,0,0,.4); border-radius: 17px; border: 2px solid rgba(160,230,255,.3); }
#compassStrip { position: absolute; inset: 0; }
#compassStrip span { position: absolute; top: 5px; transform: translateX(-50%); font-weight: bold; white-space: nowrap; font-size: .95rem; }
#compassStrip span.dir { color: var(--muted); }
.compass .needle { position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: var(--gold); opacity: .8; }
#crosshair { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px; border-radius: 50%; background: rgba(255,255,255,.7); box-shadow: 0 0 4px #000; }
.prompt { white-space: nowrap; position: absolute; left: 50%; top: 58%; transform: translateX(-50%); background: rgba(0,0,0,.55); padding: 8px 16px; border-radius: 14px; font-weight: bold; font-size: 1.1rem; display: none; }
.prompt.show { display: block; }
.digbar { position: absolute; left: 50%; top: 67%; transform: translateX(-50%); width: 220px; height: 16px; border-radius: 10px; background: rgba(0,0,0,.5); border: 2px solid var(--gold); overflow: hidden; display: none; }
.digbar.show { display: block; }
.digbar div { height: 100%; width: 0; background: linear-gradient(90deg, #d4bf8e, var(--gold)); }
.toasts { position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); display: flex; flex-direction: column-reverse; gap: 6px; align-items: center; width: 90%; }
.toast { background: rgba(0, 20, 40, .75); border: 2px solid rgba(160,230,255,.35); padding: 7px 16px; border-radius: 16px; font-weight: bold; animation: toastIn .25s ease-out; text-align: center; max-width: 560px; }
.toast.good { border-color: #8ff7b0; } .toast.bad { border-color: #ff7a7a; } .toast.gold { border-color: var(--gold); color: #ffe7a0; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } }
.team { position: absolute; left: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 5px; }
.team .tm { background: rgba(0,0,0,.45); border-radius: 12px; padding: 4px 10px; font-size: .9rem; }
.danger-arrow { position: absolute; left: 50%; top: 50%; font-size: 2.4rem; display: none; filter: drop-shadow(0 0 8px red); }
.danger-arrow.show { display: block; animation: pulse2 .5s infinite; }
@keyframes pulse2 { 50% { opacity: .5; } }
.air-arrow { position: absolute; left: 50%; top: 22%; transform: translateX(-50%); font-size: 1.5rem; font-weight: bold; color: #bff; text-shadow: 0 0 10px #09f, 0 2px 2px #000; display: none; animation: pulse2 .8s infinite; }
.air-arrow.show { display: block; }
#markers .mk { position: absolute; transform: translate(-50%, -50%); font-size: 1.4rem; filter: drop-shadow(0 0 6px #6ff); text-align: center; }
#markers .mk small { display: block; font-size: .7rem; color: #cff; }
#vignette { position: absolute; inset: 0; background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,.55) 100%); }
#hurtFlash { position: absolute; inset: 0; background: radial-gradient(ellipse at center, rgba(255,0,0,0) 40%, rgba(255,0,0,.6) 100%); opacity: 0; transition: opacity .5s; }
#hurtFlash.on { opacity: 1; transition: none; }
#camoTint { position: absolute; inset: 0; box-shadow: inset 0 0 120px rgba(120, 255, 160, .55); opacity: 0; transition: opacity .4s; }
#camoTint.on { opacity: 1; }
#clickToPlay { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); background: rgba(0,0,0,.6); padding: 14px 24px; border-radius: 18px; font-size: 1.4rem; font-weight: bold; display: none; pointer-events: none; }
#clickToPlay.show { display: block; }
#clickToPlay small { display: block; font-size: .85rem; opacity: .7; text-align: center; }

.scroll { position: fixed; left: 50%; top: 26%; transform: translateX(-50%) scale(.8); z-index: 15; opacity: 0; pointer-events: none; transition: all .3s; }
.scroll.show { opacity: 1; transform: translateX(-50%) scale(1); }
.scroll-inner { background: linear-gradient(#fff3d0, #f0d9a0); color: #4a2a10; border-radius: 10px; padding: 18px 26px; max-width: 460px;
  font-family: Georgia, serif; font-size: 1.2rem; box-shadow: 0 10px 30px rgba(0,0,0,.5); border: 4px solid #c9a060; }
#scrollWho { font-size: .85rem; opacity: .7; margin-bottom: 6px; font-family: "Trebuchet MS", sans-serif; }

.map-panel { max-width: 600px; }
#mapCanvas { width: min(540px, 80vw, 70vh); height: auto; aspect-ratio: 1; border-radius: 16px; border: 3px solid rgba(160,230,255,.4); }
.win-panel { max-width: 560px; }
.coins { font-size: 4rem; animation: bub 1.2s infinite; }
.help-panel { max-width: 640px; text-align: left; }
.help-panel h2 { text-align: center; }
.keys { width: 100%; border-collapse: collapse; margin: 10px 0; }
.keys td { padding: 5px 8px; border-bottom: 1px solid rgba(255,255,255,.1); }
.keys td:first-child { font-weight: bold; color: var(--gold); white-space: nowrap; }
.help-panel .big { display: block; margin: 12px auto 0; }
.slider { display: flex; justify-content: space-between; align-items: center; background: rgba(255,255,255,.08); padding: 8px 14px; border-radius: 14px; }

/* touch */
#touch { display: none; position: fixed; inset: 0; z-index: 12; pointer-events: none; }
#touch.on.play { display: block; }
#stick { position: absolute; width: 120px; height: 120px; border-radius: 50%; border: 3px solid rgba(255,255,255,.35); background: rgba(255,255,255,.08); display: none; }
#stick.on { display: block; }
#knob { position: absolute; left: 35px; top: 35px; width: 50px; height: 50px; border-radius: 50%; background: rgba(255,255,255,.4); }
.tbtns { position: absolute; right: 12px; bottom: 16px; display: grid; grid-template-columns: repeat(3, 62px); gap: 10px; pointer-events: auto; }
.tbtns-top { position: absolute; right: 12px; top: 132px; display: flex; flex-direction: row; gap: 10px; pointer-events: auto; }
.touch .chip small { display: none; }
.touch .tbtns-top .tbtn { width: 52px; height: 52px; font-size: 1.3rem; }
.tbtn { width: 62px; height: 62px; border-radius: 50%; background: rgba(0, 30, 50, .55); border: 2px solid rgba(160,230,255,.5); font-size: 1.5rem; touch-action: none; }
.tbtn.big { background: rgba(255, 204, 51, .35); }
.tbtn.down { background: rgba(255,255,255,.45); }
@media (max-width: 1000px) { .compass { top: auto; bottom: 14px; width: 44vw; } .toasts { bottom: 64px; } }
@media (max-width: 720px) { .hud-tr { display: none; } .hearts { font-size: 1.4rem; } .chip { min-width: 80px; padding: 3px 8px; } }

@media (max-height: 560px) {
  .card img { max-width: 70px; }
  .card { padding: 4px 8px 6px; }
  .card .pw, .card .wk { font-size: .75rem; }
  .char-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .room-code { font-size: 2rem; letter-spacing: 8px; }
  .room-box { padding: 4px; }
  h2 { font-size: 1.3rem; margin: 2px 0 8px; }
  .logo { font-size: 2.4rem; }
  .tag { margin: 4px 0 8px; }
  .big { padding: 8px 16px; font-size: 1rem; }
  .menu { gap: 7px; margin-top: 8px; }
}
