:root {
  --ink: #17303a; --deep: #0f2b33; --pond: #1d5a5e; --pond2: #2c8077; --lily: #5faa55; --lily2: #3d8a43;
  --paper: #fff6df; --paper2: #f4e4bd; --amber: #f6b73c; --coral: #e8604c; --cream: #fdf3d8;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: 'Fredoka', system-ui, sans-serif; color: var(--cream); -webkit-tap-highlight-color: transparent;
  background: radial-gradient(120% 80% at 50% -10%, #f6b76c 0%, #c8705f 24%, #4c5272 48%, #16424c 72%, #0f2b33 100%) fixed var(--deep);
}
#app { min-height: 100dvh; display: flex; justify-content: center; padding: 16px; }
h1, h2, p { margin: 0; }
small { opacity: .75; font-size: .8em; font-weight: 400; }
button, input { font: inherit; }
button { cursor: pointer; color: inherit; }
button:focus-visible, input:focus-visible, summary:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
[hidden] { display: none !important; }
.spacer { flex: 1; }
.dim { opacity: .75; }
body.offline::after {
  content: 'Lost the pond. Reconnecting...'; position: fixed; top: 0; left: 0; right: 0; z-index: 60;
  background: var(--coral); color: #fff; text-align: center; padding: 6px; font-weight: 600;
}

/* --------- shared bits */
.logo { font-size: clamp(44px, 12vw, 64px); font-weight: 700; line-height: 1; letter-spacing: -.01em; color: var(--paper); text-shadow: 0 4px 0 var(--ink); }
.logo span { color: var(--amber); }
.logo.small { font-size: 24px; text-shadow: 0 2px 0 var(--ink); }
.btn {
  border: 0; border-radius: 14px; padding: 11px 18px; font-weight: 600; color: var(--ink); background: var(--amber);
  box-shadow: 0 4px 0 #b57a1a; transition: transform .08s, box-shadow .08s, filter .15s;
}
.btn:hover:not(:disabled) { filter: brightness(1.07); }
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 #b57a1a; }
.btn:disabled { filter: grayscale(.7); opacity: .65; cursor: default; }
.btn.big { font-size: 20px; padding: 14px 22px; width: 100%; }
.btn.alt { background: var(--paper2); box-shadow: 0 4px 0 #bda877; }
.btn.small { padding: 7px 14px; font-size: 15px; }
.icon-btn { background: rgba(255,255,255,.12); border: 0; border-radius: 9px; padding: 6px 10px; font-size: 13px; }
.icon-btn:hover { background: rgba(255,255,255,.22); }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.mini { display: inline-block; width: 20px; height: 20px; vertical-align: -4px; flex: none; }
.mini-frog { display: inline-block; width: 32px; height: 32px; flex: none; }
#toast {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none; z-index: 70;
  background: var(--paper); color: var(--ink); padding: 10px 16px; border-radius: 12px; font-weight: 500; transition: .2s; max-width: calc(100vw - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.card-panel { width: 100%; max-width: 440px; margin: auto; background: rgba(15, 43, 51, .82); border-radius: 22px; padding: 24px; box-shadow: 0 18px 50px rgba(0,0,0,.35); text-align: center; }
.tag { margin: 10px 0 12px; opacity: .9; }
.preview { width: 120px; height: 120px; margin: 4px auto; }
.bob { animation: bob 1.4s ease-in-out infinite; }
form label { display: block; text-align: left; margin: 12px 0 5px; font-size: 14px; opacity: .85; font-weight: 500; }
input { width: 100%; padding: 11px 13px; border-radius: 12px; border: 2px solid transparent; background: var(--paper); color: var(--ink); }
.swatches { display: flex; gap: 9px; }
.swatches button { flex: 1; height: 36px; border-radius: 10px; border: 3px solid transparent; }
.swatches button.on { border-color: var(--paper); box-shadow: 0 0 0 2px var(--ink) inset; }
.hats { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.hats button { flex: 1 1 28%; background: rgba(255,255,255,.1); border: 2px solid transparent; border-radius: 10px; padding: 6px; font-size: 14px; }
.hats button.on { border-color: var(--amber); }
.rules { text-align: left; margin-top: 16px; background: rgba(255,255,255,.07); border-radius: 12px; padding: 10px 14px; }
.rules summary { cursor: pointer; font-weight: 600; }
.rules p { margin-top: 8px; }
.rules ul { margin: 8px 0 0; padding-left: 4px; list-style: none; display: grid; gap: 4px; }

/* --------- lobby */
.lobby { width: 100%; max-width: 760px; display: flex; flex-direction: column; gap: 16px; }
.lobby.enter { animation: rise .3s ease-out; }
.topbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.me { display: inline-flex; align-items: center; gap: 6px; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; background: rgba(15,43,51,.75); padding: 16px; border-radius: 18px; }
.actions .big { grid-column: 1 / -1; }
.code-form { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.code-form input { text-transform: uppercase; letter-spacing: .25em; text-align: center; font-weight: 600; }
.rooms { background: rgba(15,43,51,.75); padding: 16px; border-radius: 18px; }
.rooms h2 { font-size: 19px; margin-bottom: 8px; }
.rooms ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.rooms li { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,.08); padding: 8px 12px; border-radius: 12px; }
.rooms li.empty { display: block; opacity: .8; text-align: center; padding: 18px; }
.host { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow-wrap: anywhere; }
.lobby footer { text-align: center; opacity: .85; }
.lobby .rules { margin-top: 0; background: rgba(15,43,51,.75); border-radius: 18px; }
.waiting h2 { margin-top: 8px; }
.waiting p { opacity: .85; margin-top: 6px; }
.code { font-size: 52px; font-weight: 700; letter-spacing: .14em; color: var(--amber); margin: 14px 0 16px; padding-left: .14em; }

/* --------- match */
.match { width: 100%; max-width: 960px; display: flex; flex-direction: column; gap: 8px; }
.hud { display: flex; align-items: center; gap: 8px; }
.round { font-weight: 600; }
.stage { display: grid; grid-template-columns: 148px minmax(0, 1fr) 148px; gap: 8px; }
.side { background: rgba(15,43,51,.8); border-radius: 14px; padding: 9px; min-width: 0; }
.side.opp { order: 3; }
.side.you { order: 1; }
.arena { order: 2; }
.nameplate { display: flex; flex-direction: column; min-height: 40px; overflow-wrap: anywhere; line-height: 1.15; }
.bank { display: grid; gap: 6px; margin-top: 6px; }
.stack { display: flex; flex-wrap: wrap; gap: 3px; align-items: center; min-height: 24px; }
.chip { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font-size: 12px; color: #fff; box-shadow: 0 2px 0 rgba(0,0,0,.3); animation: pop .25s ease-out; }
.chip.star { outline: 3px solid var(--amber); animation: glow .7s ease-in-out infinite alternate; }

.arena {
  position: relative; height: 300px; overflow: hidden; border-radius: 16px;
  background: linear-gradient(#f6a765 0%, #c96f62 26%, #6b5a84 42%, #2c8077 43%, #1d5a5e 100%);
}
.arena::before {
  content: ''; position: absolute; left: 0; right: 0; top: 28%; height: 16%;
  background: radial-gradient(120% 100% at 20% 100%, #2f5a55 40%, transparent 41%), radial-gradient(90% 90% at 75% 100%, #274e50 42%, transparent 43%);
}
.pad { position: absolute; bottom: 12px; width: 150px; height: 44px; border-radius: 50%; background: var(--lily); box-shadow: 0 7px 0 var(--lily2), 0 14px 22px rgba(0,0,0,.25); }
.pad::after { content: ''; position: absolute; right: 16px; top: 50%; width: 34px; height: 16px; background: #24676a; clip-path: polygon(0 50%, 100% 0, 100% 100%); }
.pad.you { left: 5%; } .pad.opp { right: 5%; transform: scaleX(-1); }
.frog { position: absolute; bottom: 28px; width: 118px; height: 118px; }
.frog.you { left: calc(5% + 16px); animation: idle 2.2s ease-in-out infinite; }
.frog.opp { right: calc(5% + 16px); transform: scaleX(-1); animation: idle-opp 2.2s ease-in-out infinite .4s; }
.frog.you.leap { animation: leap-you .85s ease-out; }
.frog.opp.leap { animation: leap-opp .85s ease-out; }
.frog.you.hit { animation: hit-you .75s ease-out; }
.frog.opp.hit { animation: hit-opp .75s ease-out; }
.bubble { position: absolute; top: 12px; z-index: 6; max-width: 46%; background: var(--paper); color: var(--ink); padding: 6px 11px; border-radius: 12px; font-weight: 500; opacity: 0; pointer-events: none; }
.bubble.you { left: 8px; } .bubble.opp { right: 8px; }
.bubble.show { animation: bubble 2.2s ease-out; }

.clash { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.clash .card { position: absolute; top: 18px; width: 92px; height: 132px; }
.clash .you { left: calc(50% - 98px); } .clash .opp { left: calc(50% + 6px); }
.clash .back { background: repeating-linear-gradient(45deg, #2c8077 0 8px, #236a64 8px 16px); border: 4px solid var(--paper); animation: slide .25s ease-out; }
.clash .face { animation: flip .4s ease-out; }
.clash .wobble { animation: wobble .4s ease-in-out 2; }
.clash .winner { box-shadow: 0 0 0 4px var(--amber), 0 0 24px var(--amber); z-index: 2; transform: scale(1.08); transition: .2s; }
.clash .beaten { filter: grayscale(.8) brightness(.7); transform: rotate(-7deg) translateY(14px) scale(.92); transition: .25s; }
.clash .bank-you { transition: .35s ease-in; transform: translate(-260px, 40px) scale(.2) !important; opacity: 0; }
.clash .bank-opp { transition: .35s ease-in; transform: translate(260px, 40px) scale(.2) !important; opacity: 0; }

.card {
  position: relative; display: block; border: 4px solid var(--c, #999); border-radius: 13px; background: linear-gradient(var(--paper), var(--paper2));
  color: var(--ink); padding: 0; box-shadow: 0 5px 0 rgba(0,0,0,.28); overflow: hidden;
}
.corner { position: absolute; left: 6px; top: 3px; display: flex; flex-direction: column; align-items: center; line-height: 1; color: var(--c); }
.corner b { font-size: 25px; font-weight: 700; }
.corner i { font-style: normal; font-size: 14px; }
.card .icon { position: absolute; left: 50%; top: 50%; width: 68%; transform: translate(-44%, -48%); aspect-ratio: 1; }
.card .icon svg, .frog-art { display: block; width: 100%; height: 100%; overflow: visible; }
.card .name { position: absolute; left: 0; right: 0; bottom: 4px; text-align: center; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; opacity: .7; }
.card .charm { position: absolute; left: 0; right: 0; bottom: 0; background: var(--ink); color: var(--amber); font-size: 11px; padding: 2px 0; text-align: center; font-weight: 500; }

.timer { height: 7px; border-radius: 4px; background: rgba(255,255,255,.14); overflow: hidden; }
.timer i { display: block; height: 100%; width: 100%; transform-origin: left; background: var(--amber); }
.timer.low i { background: var(--coral); }
.notice { min-height: 26px; text-align: center; font-weight: 500; font-size: 17px; }
.hand { display: flex; justify-content: center; gap: 10px; min-height: 158px; align-items: center; }
.hand .card { flex: 0 1 106px; min-width: 0; aspect-ratio: 106 / 148; transition: transform .14s, box-shadow .14s; cursor: pointer; }
.hand .card.deal { animation: deal .3s ease-out backwards; animation-delay: calc(var(--i) * 40ms); }
.hand:not(.locked) .card:hover, .hand:not(.locked) .card:focus-visible { transform: translateY(-12px) rotate(-1.5deg); box-shadow: 0 13px 0 rgba(0,0,0,.2); }
.hand.locked .card { filter: saturate(.55) brightness(.75); cursor: default; }
.emotes { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.emotes button { background: rgba(255,255,255,.1); border: 0; border-radius: 16px; padding: 5px 11px; font-size: 13px; }
.emotes button:hover { background: rgba(255,255,255,.2); }

.over { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: rgba(8, 24, 30, .7); animation: fade .3s; }
.over-box { width: 100%; max-width: 380px; text-align: center; padding: 24px; border-radius: 22px; background: var(--deep); box-shadow: 0 18px 50px rgba(0,0,0,.45); animation: rise .35s ease-out; }
.over-box h2 { font-size: 38px; color: var(--amber); }
.over-box.lost h2 { color: #a6c6c8; }
.over-box p { margin: 6px 0 14px; }
.over-box.won .preview { animation: bob .55s ease-in-out infinite; }
.over-box.lost .preview { filter: grayscale(.6); transform: rotate(9deg); }

/* --------- attack effects */
.fx { position: absolute; inset: 0; pointer-events: none; z-index: 4; overflow: hidden; }
.sunbeam { position: absolute; bottom: 62px; height: 42px; width: 66%; border-radius: 24px; background: linear-gradient(90deg, #fff5b0, #fbc531 50%, #f0801f); box-shadow: 0 0 34px 12px rgba(251,197,49,.75); animation: beam 1s ease-out forwards; mix-blend-mode: screen; }
.sunbeam.from-you { left: 18%; transform-origin: left; }
.sunbeam.from-opp { right: 18%; transform-origin: right; background: linear-gradient(270deg, #fff5b0, #fbc531 50%, #f0801f); }
.flare { position: absolute; bottom: 30px; width: 110px; height: 110px; border-radius: 50%; background: radial-gradient(#fff, #fbc531 45%, transparent 70%); animation: flare 1.1s ease-out .3s backwards; opacity: 0; }
.flare.from-you { right: 9%; } .flare.from-opp { left: 9%; }
.cloud { position: absolute; top: 8px; width: 150px; height: 112px; animation: cloud 1.5s ease-out both; }
.cloud.from-you { right: 3%; } .cloud.from-opp { left: 3%; }
.drop { position: absolute; top: 96px; width: 4px; height: 15px; border-radius: 3px; background: #6fb6ef; animation: drop .5s linear calc(.25s + var(--d)) 3 backwards; opacity: 0; }
.drop.from-you { right: calc(4% + var(--x) * 1.3px); } .drop.from-opp { left: calc(4% + var(--x) * 1.3px); }
.vine { position: absolute; bottom: calc(8px + (var(--i) * 7px)); width: 70px; height: 70px; animation: grow .9s cubic-bezier(.2,1.6,.4,1) calc(var(--i) * .06s) both; }
.vine.from-you { right: calc(4% + var(--i) * 15px); } .vine.from-opp { left: calc(4% + var(--i) * 15px); }

@keyframes bob { 50% { transform: translateY(-7px); } }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(0); } }
@keyframes glow { from { box-shadow: 0 0 2px var(--amber); } to { box-shadow: 0 0 12px var(--amber); } }
@keyframes idle { 50% { transform: scaleY(.96) translateY(2px); } }
@keyframes idle-opp { 50% { transform: scaleX(-1) scaleY(.96) translateY(2px); } }
@keyframes leap-you { 45% { transform: translate(34px, -62px) rotate(-8deg); } 100% { transform: none; } }
@keyframes leap-opp { 0% { transform: scaleX(-1); } 45% { transform: scaleX(-1) translate(34px, -62px) rotate(-8deg); } 100% { transform: scaleX(-1); } }
@keyframes hit-you { 15% { transform: translateX(-14px) rotate(-9deg); filter: brightness(1.8); } 35% { transform: translateX(9px); } 55% { transform: translateX(-5px); } 100% { transform: none; } }
@keyframes hit-opp { 0%, 100% { transform: scaleX(-1); } 15% { transform: scaleX(-1) translateX(-14px) rotate(-9deg); filter: brightness(1.8); } 35% { transform: scaleX(-1) translateX(9px); } 55% { transform: scaleX(-1) translateX(-5px); } }
@keyframes bubble { 0% { opacity: 0; transform: translateY(8px); } 10%, 82% { opacity: 1; transform: none; } 100% { opacity: 0; } }
@keyframes slide { from { transform: translateY(170px) scale(.7); opacity: 0; } }
@keyframes flip { from { transform: rotateY(90deg) scale(1.1); } }
@keyframes wobble { 25% { transform: rotate(-4deg); } 75% { transform: rotate(4deg); } }
@keyframes deal { from { transform: translateY(46px) scale(.8); opacity: 0; } }
@keyframes beam { 0% { transform: scaleX(0); opacity: 0; } 25% { transform: scaleX(1); opacity: 1; } 70% { opacity: 1; } 100% { opacity: 0; } }
@keyframes flare { 0% { transform: scale(.2); opacity: 0; } 30% { opacity: 1; } 100% { transform: scale(1.8); opacity: 0; } }
@keyframes cloud { 0% { transform: translateY(-110px); opacity: 0; } 22%, 80% { transform: none; opacity: 1; } 100% { opacity: 0; } }
@keyframes drop { 0% { transform: translateY(0); opacity: 1; } 100% { transform: translateY(110px); opacity: .4; } }
@keyframes grow { 0% { transform: scale(0); transform-origin: bottom; } 100% { transform: scale(1); transform-origin: bottom; } }

@media (max-width: 720px) {
  #app { padding: 10px; }
  .stage { grid-template-columns: 1fr 1fr; }
  .arena { order: 0; grid-column: 1 / -1; height: 236px; }
  .side.you { order: 1; } .side.opp { order: 2; }
  .side { padding: 7px; }
  .nameplate { min-height: 0; }
  .bank { grid-template-columns: repeat(3, 1fr); margin-top: 4px; }
  .stack { flex-direction: column; align-items: flex-start; }
  .chip { width: 19px; height: 19px; }
  .frog { width: 76px; height: 76px; bottom: 22px; }
  .pad { width: 100px; height: 32px; }
  .frog.you { left: calc(3% + 12px); } .frog.opp { right: calc(3% + 12px); }
  .pad.you { left: 3%; } .pad.opp { right: 3%; }
  .clash .card { top: 10px; width: 74px; height: 106px; }
  .clash .you { left: calc(50% - 78px); } .clash .opp { left: calc(50% + 4px); }
  .hand { gap: 5px; min-height: 0; }
  .corner b { font-size: 19px; } .corner i { font-size: 11px; } .corner { left: 4px; }
  .card { border-width: 3px; border-radius: 10px; }
  .card .charm { font-size: 9px; } .card .name { font-size: 9px; }
  .actions { grid-template-columns: 1fr; }
  .notice { font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
