/* ==========================================================================
   Wild Clash — game client
   No frameworks, no web fonts, no third-party requests. Cards are DOM elements
   animated with transform/opacity only, so everything runs on the compositor.
   ========================================================================== */

:root {
  --bg: #080b18;
  --bg-2: #0e1328;
  --panel: #141a33;
  --panel-2: #1b2347;
  --line: rgb(154 163 199 / 0.18);
  --text: #eaeefc;
  --muted: #98a2be;
  --gold: #ffb020;
  --red: #e5484d;
  --yellow: #f1b32b;
  --green: #30a46c;
  --blue: #3b82f6;
  --violet: #a78bfa;
  --cyan: #22d3ee;
  --pink: #f472b6;
  --ink: #1b1405;
  --r: 16px;
  --r-sm: 10px;
  /* Set per table from the equipped deck (progress.go). */
  --back-1: #1f2b57;
  --back-2: #101735;
  --felt-1: #102a22;
  --felt-2: #07140f;
  --glow: #ffb020;
  --card-h: clamp(84px, 15.5vh, 132px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif,
    "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji";
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(ellipse 80% 55% at 50% -10%, rgb(167 139 250 / 0.18), transparent 70%),
    radial-gradient(ellipse 70% 50% at 100% 100%, rgb(34 211 238 / 0.12), transparent 70%),
    var(--bg);
  color: var(--text);
  font: 400 16px/1.5 var(--font);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

body.quake { animation: quake .55s ease; }
@keyframes quake {
  0%, 100% { transform: none; }
  20% { transform: translate(-6px, 3px) rotate(-.4deg); }
  45% { transform: translate(5px, -4px) rotate(.4deg); }
  70% { transform: translate(-3px, 2px); }
}

/* .btn and friends set display, which would otherwise beat the hidden attribute. */
[hidden] { display: none !important; }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: var(--cyan); }
h2 { margin: 0 0 6px; font-size: 1.3rem; }
h3 { margin: 18px 0 6px; font-size: 1rem; letter-spacing: .02em; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }
ul, ol { margin: 0; padding: 0; list-style: none; }

/* ---------- screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) 12px calc(10px + var(--safe-b));
  /* A screen's own stacking context. Without it, anything the compositor promotes inside it — the
     cards in flight, the orbiting direction ring, a pulsing button — paints above the modals and
     toasts that come later in the document, however high their z-index. */
  isolation: isolate;
}
.screen.active { display: flex; }
.screen.center { align-items: center; justify-content: center; }

.logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: .92;
  margin: 10px 0 14px;
}
.logo span { font-size: .8rem; letter-spacing: .5em; color: var(--muted); text-indent: .5em; }
.logo b {
  font-size: clamp(2.1rem, 11vw, 3.1rem);
  font-weight: 900;
  letter-spacing: -.02em;
  background: linear-gradient(100deg, var(--gold), var(--pink) 45%, var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 6px 22px rgb(255 176 32 / .25));
}

.spinner {
  width: 30px; height: 30px; margin: 16px auto;
  border: 3px solid rgb(255 255 255 / .15);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.spinner.big { width: 46px; height: 46px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- buttons ---------- */
.btn {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  border-radius: var(--r);
  background: linear-gradient(var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  font-weight: 700;
  text-align: center;
  transition: transform .12s, filter .12s;
}
.btn small { font-weight: 500; font-size: .74rem; color: var(--muted); }
.btn:active { transform: scale(.975); }
.btn:disabled { opacity: .45; }
.btn.primary {
  background: linear-gradient(160deg, #ffc857, var(--gold));
  color: var(--ink);
  border-color: rgb(255 255 255 / .25);
  box-shadow: 0 8px 22px rgb(255 176 32 / .3), inset 0 -3px 0 rgb(0 0 0 / .12);
}
.btn.primary small { color: rgb(27 20 5 / .7); }
.btn.gold { background: linear-gradient(160deg, #a855f7, #6d28d9); color: #fff; border-color: rgb(255 255 255 / .2); }
.btn.gold small { color: rgb(255 255 255 / .75); }
.btn.danger { background: linear-gradient(var(--red), #b4252a); color: #fff; }
.btn.ghost { background: rgb(255 255 255 / .05); }
.btn.big { min-height: 62px; font-size: 1.06rem; }
.btn.tiny { min-height: 34px; width: auto; padding: 6px 12px; font-size: .8rem; border-radius: 99px; }
.linkbtn { color: var(--cyan); text-decoration: underline; padding: 0; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.row3 > * { flex: 1 1 0; }
.actions { display: flex; gap: 10px; margin-top: 14px; }
.actions.col { flex-direction: column; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 13px; border-radius: 99px; font-size: .85rem; font-weight: 700;
  background: rgb(255 255 255 / .06); border: 1px solid var(--line);
}
.chip.on { background: linear-gradient(160deg, #ffc857, var(--gold)); color: var(--ink); border-color: transparent; }
.chip:disabled { opacity: .35; }

.field { margin: 14px 0; }
.field > label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: 6px; }
input {
  width: 100%; min-height: 50px; padding: 12px 14px;
  border-radius: var(--r-sm); border: 1px solid var(--line);
  background: rgb(0 0 0 / .3); outline-offset: 2px;
}
input:focus-visible { outline: 2px solid var(--gold); }

.tabs { display: flex; gap: 6px; margin: 12px 0; background: rgb(0 0 0 / .25); padding: 4px; border-radius: 99px; }
.tab { flex: 1; padding: 9px; border-radius: 99px; font-size: .85rem; font-weight: 700; color: var(--muted); }
.tab.on { background: var(--panel-2); color: var(--text); }

.tg { display: flex; align-items: center; gap: 12px; padding: 13px 4px; border-bottom: 1px solid var(--line); font-weight: 600; }
/* A switch rather than a checkbox: the stock control is a grey square on most Android WebViews. */
.tg input {
  appearance: none; -webkit-appearance: none;
  position: relative; flex: none;
  width: 46px; height: 27px; min-height: 0; padding: 0; border-radius: 99px;
  background: rgb(255 255 255 / .12); border: 1px solid var(--line);
  transition: background .18s;
}
.tg input::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 21px; height: 21px; border-radius: 50%;
  background: #cfd6ee;
  transition: transform .18s cubic-bezier(.2,1.3,.4,1), background .18s;
}
.tg span { display: flex; flex-direction: column; }
.tg small { font-weight: 500; font-size: .74rem; color: var(--muted); }
.tg input:checked { background: var(--gold); border-color: transparent; }
.tg input:checked::after { transform: translateX(19px); background: var(--ink); }

/* ---------- signup / home ---------- */
.panel {
  width: min(430px, 100%);
  padding: 20px;
  border-radius: 22px;
  background: linear-gradient(var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 12px;
}
.avatars { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 6px; }
.av-pick {
  aspect-ratio: 1; font-size: 1.35rem; border-radius: 12px;
  background: rgb(255 255 255 / .05); border: 2px solid transparent;
}
.av-pick.on { border-color: var(--gold); background: rgb(255 176 32 / .16); }

.topbar { display: flex; align-items: center; gap: 8px; }
.top-icons { display: flex; gap: 6px; margin-left: auto; }
.icon {
  width: 42px; height: 42px; border-radius: 12px; font-size: 1.1rem;
  background: rgb(255 255 255 / .06); border: 1px solid var(--line);
  display: grid; place-items: center;
}
.icon-spacer { width: 42px; }
/* Scoped to the button itself: "me" is also the class that marks your row in lists, and a shared
   rule here once squeezed the lobby slot to half width. */
#h-me { display: flex; align-items: center; gap: 7px; padding: 5px 11px 5px 5px; border-radius: 99px; background: rgb(255 255 255 / .06); border: 1px solid var(--line); font-weight: 700; max-width: 52%; }
#h-me .av { font-size: 1.2rem; }
#h-me #h-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lv { font-size: .68rem; font-style: normal; color: var(--ink); background: var(--gold); padding: 2px 6px; border-radius: 99px; font-weight: 800; }
.gold-pill { position: relative; display: flex; align-items: center; gap: 4px; padding: 0 12px; height: 42px; border-radius: 99px; background: rgb(255 176 32 / .14); border: 1px solid rgb(255 176 32 / .35); font-weight: 800; }
.dot { position: absolute; top: -2px; right: -2px; width: 11px; height: 11px; border-radius: 50%; background: var(--red); border: 2px solid var(--bg); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { transform: scale(1.3); opacity: .7; } }

.menu { display: flex; flex-direction: column; gap: 10px; margin-top: auto; }
#s-home { overflow-y: auto; }
.hero-cards { display: grid; place-items: center; min-height: 86px; margin: 4px 0 2px; }
.hero-cards .fan { display: flex; }
.hero-cards .card { height: 76px; margin-inline: -16px; animation: float 3.4s ease-in-out infinite; }
.hero-cards .card:nth-child(2) { animation-delay: .25s; }
.hero-cards .card:nth-child(3) { animation-delay: .5s; }
.hero-cards .card:nth-child(4) { animation-delay: .75s; }
@keyframes float { 50% { transform: translateY(-9px) rotate(var(--tilt, 0deg)); } }
.join { display: flex; gap: 10px; }
.join input { flex: 1; text-align: center; letter-spacing: .3em; font-weight: 800; text-transform: uppercase; }
.join .btn { flex: 0 0 auto; width: auto; padding-inline: 20px; }

/* ---------- lobby ---------- */
#s-lobby { gap: 10px; overflow-y: auto; }
.code-card { text-align: center; padding: 14px; border-radius: var(--r); background: rgb(0 0 0 / .3); border: 1px solid var(--line); }
.code { font-size: 2.2rem; font-weight: 900; letter-spacing: .22em; color: var(--gold); text-indent: .22em; }
.modes { display: flex; flex-wrap: wrap; gap: 8px; }
.mode-desc { min-height: 2.6em; margin: 0; }
.slots { display: flex; flex-direction: column; gap: 8px; }
.slot { display: flex; align-items: center; gap: 9px; padding: 11px 13px; border-radius: var(--r-sm); background: rgb(255 255 255 / .05); border: 1px solid var(--line); }
.slot.me { border-color: var(--gold); background: rgb(255 176 32 / .1); }
.slot.empty { color: var(--muted); border-style: dashed; justify-content: center; }
.slot .av { font-size: 1.3rem; }
.slot .nm { flex: 1 1 auto; min-width: 5.5em; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: .7rem; font-style: normal; white-space: nowrap; color: var(--muted); background: rgb(255 255 255 / .07); padding: 3px 8px; border-radius: 99px; }
.fr .tag, .hist .tag { margin-left: auto; }
.tag.team0 { color: var(--cyan); } .tag.team1 { color: var(--pink); }
.x { width: 30px; height: 30px; border-radius: 8px; color: var(--muted); background: rgb(255 255 255 / .06); }
.star { color: var(--gold); font-style: normal; }
.off { font-style: normal; }
.wait { text-align: center; }

/* ==========================================================================
   Cards
   ========================================================================== */
.card {
  position: relative;
  flex: none;
  height: var(--card-h);
  aspect-ratio: 2 / 3;
  border-radius: 9%/6%;
  background: #fff;
  box-shadow: 0 4px 12px rgb(0 0 0 / .45), inset 0 0 0 1px rgb(0 0 0 / .08);
  overflow: hidden;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 900;
  transition: transform .18s cubic-bezier(.2,.9,.25,1), filter .18s, box-shadow .18s;
}
.card.sm { height: calc(var(--card-h) * .52); }
/* The white frame every card wears. */
.card::before {
  content: "";
  position: absolute; inset: 5.5%;
  border-radius: 7%/5%;
  background: linear-gradient(155deg, var(--c1), var(--c2));
  box-shadow: inset 0 0 0 .45em #fff;
}
.card.c-red { --c1: #e5484d; --c2: #b4252a; }
.card.c-yellow { --c1: #f1b32b; --c2: #c78a0d; }
.card.c-green { --c1: #30a46c; --c2: #1d7a4c; }
.card.c-blue { --c1: #3b82f6; --c2: #1d4fd8; }
.card.c-wild { --c1: #171a33; --c2: #090b18; }

/* The white oval behind the big glyph: the look everyone recognises. */
.oval {
  position: absolute; width: 74%; height: 54%;
  background: #fff; border-radius: 50%;
  transform: rotate(-32deg);
  opacity: .96;
}
.mid {
  position: relative;
  display: grid; place-items: center;
  width: 62%; height: 62%;
  color: var(--c1);
}
.mid .num {
  font-size: calc(var(--card-h) * .40);
  line-height: 1;
  -webkit-text-stroke: calc(var(--card-h) * .012) rgb(0 0 0 / .18);
  text-shadow: 0 2px 0 rgb(0 0 0 / .12);
}
.mid .plus { font-size: calc(var(--card-h) * .25); letter-spacing: -.04em; }
.mid .gl { width: 88%; height: 88%; }
.mid .wheel { width: 100%; height: 100%; filter: drop-shadow(0 2px 4px rgb(0 0 0 / .3)); }
.mid .plus.w4 {
  position: absolute; right: -6%; bottom: -8%;
  font-size: calc(var(--card-h) * .20);
  color: #fff;
  text-shadow: 0 0 4px #000, 0 2px 4px #000;
}
.pip {
  position: absolute;
  font-size: calc(var(--card-h) * .14);
  line-height: 1;
  color: #fff;
  text-shadow: 0 1px 2px rgb(0 0 0 / .45);
  display: grid; place-items: center;
  width: 20%; height: 14%;
}
.pip .gl { width: 100%; height: 100%; }
.pip .wheel { display: none; }
.pip.tl { top: 7%; left: 8%; }
.pip.br { bottom: 7%; right: 8%; transform: rotate(180deg); }

/* Face-down: the deck's own back art. */
.card.down::before {
  background: linear-gradient(150deg, var(--back-1), var(--back-2));
  box-shadow: inset 0 0 0 .45em #fff, inset 0 0 0 1.1em var(--back-2);
}
.card.down .logo-mark {
  position: relative;
  display: block;
  width: 46%;
  transform: rotate(-16deg);
  filter: drop-shadow(0 0 10px color-mix(in srgb, var(--glow) 70%, transparent));
}
.card.down .logo-mark svg { width: 100%; height: auto; display: block; }

/* A wild on the pile remembers the colour that was called. */
.card.chosen-red { box-shadow: 0 0 0 3px var(--red), 0 8px 22px rgb(229 72 77 / .5); }
.card.chosen-yellow { box-shadow: 0 0 0 3px var(--yellow), 0 8px 22px rgb(241 179 43 / .5); }
.card.chosen-green { box-shadow: 0 0 0 3px var(--green), 0 8px 22px rgb(48 164 108 / .5); }
.card.chosen-blue { box-shadow: 0 0 0 3px var(--blue), 0 8px 22px rgb(59 130 246 / .5); }

/* ==========================================================================
   Game screen
   ========================================================================== */
#s-game { padding: 0; }
#table {
  position: relative;
  isolation: isolate;
  flex: 1;
  display: grid;
  grid-template-rows: auto auto 1fr auto; /* chrome, opponents, the pile, your side */
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse 70% 48% at 50% 42%, color-mix(in srgb, var(--felt-1) 85%, #fff 8%), var(--felt-1) 60%, var(--felt-2));
}

/* Grid items default to min-width: min-content, so a wide hand would stretch the whole table
   instead of scrolling inside it. */
#table > * { min-width: 0; }

.g-top {
  display: flex; align-items: center; gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 10px 4px;
}
#g-clock {
  margin-left: auto; font-weight: 800; font-variant-numeric: tabular-nums;
  padding: 5px 11px; border-radius: 99px; background: rgb(0 0 0 / .4); border: 1px solid var(--line);
}
#g-clock.low { color: var(--red); animation: pulse .8s infinite; }
#g-round { font-size: .78rem; color: var(--muted); padding: 5px 10px; border-radius: 99px; background: rgb(0 0 0 / .3); }

/* ---------- opponents ---------- */
#opponents {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 6px;
  padding: 2px 8px 0;
  min-height: 92px;
}
.opp { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; }
.opp.at-left { grid-column: 1; justify-self: start; }
.opp.at-top { grid-column: 2; }
.opp.at-right { grid-column: 3; justify-self: end; }
.opp.out { opacity: .4; filter: grayscale(1); }
.opp-av { position: relative; width: 46px; height: 46px; display: grid; place-items: center; }
.opp-av .av {
  font-size: 1.5rem;
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgb(0 0 0 / .4); border: 2px solid var(--line);
}
.opp.turn .opp-av .av { border-color: var(--glow); box-shadow: 0 0 18px color-mix(in srgb, var(--glow) 65%, transparent); }
.opp .ring { position: absolute; inset: -2px; transform: rotate(-90deg); pointer-events: none; }
.opp .ring circle {
  fill: none; stroke: var(--glow); stroke-width: 3; stroke-linecap: round;
  stroke-dasharray: 126; stroke-dashoffset: 0;
  animation: ringSweep var(--turn, 30s) linear forwards;
}
@keyframes ringSweep { to { stroke-dashoffset: 126; } }
.opp .count {
  position: absolute; right: -6px; bottom: -4px;
  min-width: 21px; height: 21px; padding: 0 5px;
  border-radius: 99px; background: var(--glow); color: #0b0b14;
  font-size: .76rem; font-weight: 900; display: grid; place-items: center;
  border: 2px solid var(--felt-2);
}
.opp .catch {
  position: absolute; top: -20px; left: 50%; transform: translateX(-50%);
  padding: 3px 9px; border-radius: 99px; white-space: nowrap;
  background: var(--red); color: #fff; font-size: .66rem; font-weight: 900; letter-spacing: .06em;
  box-shadow: 0 0 14px rgb(229 72 77 / .7);
  animation: pulse .9s infinite;
}
.opp-name { font-size: .72rem; font-weight: 700; max-width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opp-score { font-size: .66rem; color: var(--muted); }
.opp-fan { display: flex; height: 20px; justify-content: center; }
.mini {
  display: block; width: 13px; height: 19px; border-radius: 3px;
  background: linear-gradient(150deg, var(--back-1), var(--back-2));
  border: 1px solid rgb(255 255 255 / .35);
  margin-left: -5px;
  transform: rotate(calc((var(--i) - (var(--n) - 1) / 2) * 7deg));
}
.bubble, #my-bubble {
  position: absolute; top: -6px; left: 50%;
  transform: translate(-50%, -6px) scale(.4);
  font-size: 1.5rem; opacity: 0; pointer-events: none;
  transition: transform .25s cubic-bezier(.2,1.5,.4,1), opacity .25s;
}
.bubble.pop, #my-bubble.pop { opacity: 1; transform: translate(-50%, -26px) scale(1); }

/* ---------- centre: deck and pile ---------- */
.middle {
  position: relative;
  display: flex; align-items: center; justify-content: center; gap: clamp(14px, 6vw, 38px);
  min-height: 0;
}
#deck, .pile-wrap { position: relative; height: var(--card-h); aspect-ratio: 2/3; }
#pile { position: absolute; inset: 0; }
#deck { cursor: pointer; }
/* Two offset shadows make the deck look like a stack. */
#deck::before, #deck::after {
  content: ""; position: absolute; inset: 0;
  border-radius: 9%/6%;
  background: linear-gradient(150deg, var(--back-1), var(--back-2));
  box-shadow: 0 4px 10px rgb(0 0 0 / .5), inset 0 0 0 1px rgb(255 255 255 / .12);
}
#deck::before { transform: translate(5px, 5px) rotate(3deg); opacity: .55; }
#deck::after { transform: translate(2px, 2px) rotate(1.5deg); opacity: .8; }
#deck .card { position: relative; z-index: 1; }
#deck:active .card { transform: translateY(2px) scale(.97); }
#deck-n {
  position: absolute; z-index: 2; bottom: -9px; left: 50%; transform: translateX(-50%);
  padding: 2px 9px; border-radius: 99px; font-size: .7rem; font-weight: 800;
  background: rgb(0 0 0 / .65); border: 1px solid var(--line);
}
#pile .card { position: absolute; inset: 0; height: auto; }
/* An empty pile still shows where the cards land. */
.pile-wrap::before {
  content: ""; position: absolute; inset: 0;
  border-radius: 9%/6%; border: 2px dashed rgb(255 255 255 / .14);
}
.pile-colour {
  position: absolute; inset: -14%;
  border-radius: 50%;
  filter: blur(14px);
  opacity: .5;
  z-index: -1;
  transition: background .35s;
}
.pile-colour.c-red { background: var(--red); }
.pile-colour.c-yellow { background: var(--yellow); }
.pile-colour.c-green { background: var(--green); }
.pile-colour.c-blue { background: var(--blue); }
.pile-colour.c-wild { background: var(--violet); }

/* The direction arrows that circle the pile. */
.dir {
  position: absolute; top: 50%; left: 50%; translate: -50% -50%;
  width: min(calc(var(--card-h) * 1.55), 40vw); aspect-ratio: 1;
  border-radius: 50%;
  border: 2px dashed rgb(255 255 255 / .16);
  animation: orbit 14s linear infinite;
  pointer-events: none;
}
.dir.ccw { animation-direction: reverse; }
.dir::before, .dir::after {
  content: "▲"; position: absolute; left: 50%; font-size: .7rem; color: rgb(255 255 255 / .4);
}
.dir::before { top: -8px; transform: translateX(-50%); }
.dir::after { bottom: -8px; transform: translateX(-50%) rotate(180deg); }
@keyframes orbit { to { transform: rotate(360deg); } }

#stack {
  position: absolute; top: -14px; left: 50%; transform: translateX(-50%);
  padding: 4px 12px; border-radius: 99px;
  background: linear-gradient(var(--red), #a81d22); color: #fff;
  font-weight: 900; font-size: .9rem;
  box-shadow: 0 0 20px rgb(229 72 77 / .75);
  animation: pulse 1s infinite;
  z-index: 3;
}

/* ---------- your side ---------- */
.g-bottom { position: relative; padding: 0 8px calc(6px + var(--safe-b)); }
#turn-bar {
  height: 4px; border-radius: 99px; overflow: hidden;
  background: rgb(255 255 255 / .1);
  margin: 0 8px 5px;
}
#turn-bar::after {
  content: ""; display: block; height: 100%;
  width: calc(var(--frac, 1) * 100%);
  background: linear-gradient(90deg, var(--green), var(--gold));
  transition: width .2s linear;
}
#turn-bar.low::after { background: var(--red); }

#meter-wrap { display: flex; align-items: center; gap: 8px; padding: 3px 10px 5px; }
.meter { position: relative; flex: 1; height: 13px; border-radius: 99px; background: rgb(0 0 0 / .45); overflow: hidden; border: 1px solid var(--line); }
#meter-fill {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--cyan), var(--violet), var(--pink));
  background-size: 200% 100%;
  transition: width .4s cubic-bezier(.2,.9,.25,1);
  animation: slide 2.4s linear infinite;
}
@keyframes slide { to { background-position: 200% 0; } }
#meter-pct { font-size: .66rem; font-weight: 800; color: var(--muted); min-width: 30px; text-align: right; }
#bag { display: flex; gap: 6px; }
.pw {
  display: flex; align-items: center; gap: 4px;
  padding: 5px 10px; border-radius: 99px;
  background: linear-gradient(150deg, #7c3aed, #4c1d95);
  border: 1px solid rgb(255 255 255 / .25);
  font-size: .72rem; font-weight: 800;
  box-shadow: 0 0 16px rgb(124 58 237 / .55);
  animation: breathe 2.2s ease-in-out infinite;
}
@keyframes breathe { 50% { transform: scale(1.06); } }
.pw-ic { font-size: .95rem; }
#shield {
  position: absolute; right: 12px; top: -22px;
  font-size: .68rem; font-weight: 800; padding: 3px 9px; border-radius: 99px;
  background: rgb(59 130 246 / .25); border: 1px solid var(--blue);
}

#g-status { text-align: center; font-size: .8rem; font-weight: 700; color: var(--muted); min-height: 1.3em; }
#hand-worth { font-size: .66rem; color: var(--muted); }

/* The fan. Cards overlap and lift when they can be played. */
#hand {
  display: flex; justify-content: center; align-items: flex-end;
  min-height: calc(var(--card-h) + 16px);
  padding: 14px 10px 4px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  scroll-padding-inline: 12px;
}
#hand::-webkit-scrollbar { display: none; }
/* --ov is set by fitHand() in app.js: however much overlap it takes to fit the screen. */
#hand .card {
  margin-left: calc(var(--ov, 0px) * -1);
  transform: rotate(calc((var(--i) - (var(--n) - 1) / 2) * 2.6deg));
  transform-origin: 50% 160%;
}
#hand .card:first-child { margin-left: 0; }
#hand .card.ok { box-shadow: 0 0 0 2px var(--glow), 0 10px 24px rgb(0 0 0 / .5); }
#hand .card.ok:active,
#hand .card.jump:active { transform: translateY(-16px) scale(1.06); z-index: 5; }
#hand .card.jump { box-shadow: 0 0 0 2px var(--cyan), 0 0 22px rgb(34 211 238 / .6); animation: breathe 1.3s ease-in-out infinite; }
#hand .card.no { filter: brightness(.62) saturate(.7); }
@media (hover: hover) {
  #hand .card.ok:hover, #hand .card.jump:hover { transform: translateY(-14px) scale(1.05); z-index: 5; }
}
.card.shake { animation: shake .3s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px) rotate(-2deg); }
  75% { transform: translateX(6px) rotate(2deg); }
}

.controls { display: flex; align-items: center; gap: 8px; padding: 4px 10px 0; }
.controls .btn { min-height: 46px; }
#btn-draw.must { animation: breathe 1.2s ease-in-out infinite; box-shadow: 0 0 18px color-mix(in srgb, var(--glow) 60%, transparent); }
#btn-clash {
  min-height: 46px; width: auto; padding-inline: 20px;
  background: linear-gradient(160deg, #ff4d6d, #c9184a);
  color: #fff; font-size: 1rem; font-weight: 900; letter-spacing: .08em;
  box-shadow: 0 0 24px rgb(255 77 109 / .8);
  animation: clashPulse .7s ease-in-out infinite;
}
@keyframes clashPulse { 50% { transform: scale(1.07); box-shadow: 0 0 34px rgb(255 77 109 / 1); } }
#g-emotes { position: absolute; right: 10px; bottom: 58px; display: flex; flex-wrap: wrap; gap: 4px; width: 190px; padding: 8px; border-radius: var(--r); background: rgb(10 12 24 / .96); border: 1px solid var(--line); }
#g-emotes button { font-size: 1.4rem; width: 40px; height: 40px; border-radius: 10px; }

/* ---------- effects layer ---------- */
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
/* will-change only while a card is actually moving: a promoted layer per card costs memory, and a
   permanently promoted one composites above the modal's backdrop-filter. */
#fx .card.flying { position: fixed; margin: 0; box-shadow: 0 16px 36px rgb(0 0 0 / .6); will-change: transform; }
#fx .card.flip { transform-style: preserve-3d; }

.banner {
  position: absolute; left: 50%; top: 42%;
  transform: translate(-50%, -50%) scale(.7);
  padding: 10px 22px; border-radius: 99px;
  background: rgb(8 11 24 / .9);
  border: 1px solid var(--line);
  font-weight: 900; font-size: clamp(1rem, 4.4vw, 1.3rem);
  white-space: nowrap;
  opacity: 0;
  transition: transform .3s cubic-bezier(.2,1.6,.4,1), opacity .3s;
  pointer-events: none;
  z-index: 55;
}
.banner.in { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.banner.take, .banner.catch, .banner.bad { background: linear-gradient(var(--red), #8f1a1f); border-color: transparent; }
.banner.win { background: linear-gradient(var(--gold), #c47f06); color: var(--ink); border-color: transparent; }
.banner.power, .banner.mayhem, .banner.jump { background: linear-gradient(#7c3aed, #4c1d95); border-color: transparent; }
.banner.c-red { background: var(--red); } .banner.c-yellow { background: var(--yellow); color: var(--ink); }
.banner.c-green { background: var(--green); } .banner.c-blue { background: var(--blue); }

.burst {
  position: absolute; left: 50%; top: 46%;
  transform: translate(-50%, -50%);
  font-size: clamp(2rem, 13vw, 4rem); font-weight: 900; letter-spacing: -.02em;
  background: linear-gradient(100deg, var(--gold), var(--pink), var(--cyan));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 18px rgb(255 77 109 / .6));
  animation: burstIn 1.1s cubic-bezier(.2,1.4,.3,1) forwards;
  z-index: 58;
}
@keyframes burstIn {
  0% { transform: translate(-50%, -50%) scale(.3); opacity: 0; }
  25% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
  70% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -120%) scale(.9); opacity: 0; }
}
.burst.charge { font-size: clamp(1.2rem, 6vw, 2rem); }

.wave {
  position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px;
  border-radius: 50%; border: 2px solid var(--glow);
  animation: wave .65s ease-out forwards;
}
@keyframes wave { to { width: 240px; height: 240px; margin: -120px 0 0 -120px; opacity: 0; border-width: 1px; } }

.conf {
  position: absolute; top: -20px; left: var(--x);
  width: var(--s); height: var(--s); background: var(--c); border-radius: 2px;
  animation: fall var(--d) cubic-bezier(.3,.1,.6,1) forwards;
}
@keyframes fall { to { transform: translateY(108vh) rotate(var(--r)); opacity: .2; } }

/* ---------- modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center;
  padding: 14px;
  /* A plain dim, no backdrop-filter: it makes a backdrop root that composited cards behind it
     punch through, and it is the most expensive thing on the screen on a cheap phone. */
  background: rgb(4 6 14 / .74);
  opacity: 0;
  transition: opacity .18s;
  overflow-y: auto;
}
.modal.in { opacity: 1; }
.sheet {
  width: min(440px, 100%);
  max-height: calc(100dvh - 28px);
  overflow-y: auto;
  padding: 20px;
  border-radius: 22px;
  background: linear-gradient(var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgb(0 0 0 / .6);
  transform: translateY(12px) scale(.98);
  transition: transform .22s cubic-bezier(.2,1.3,.4,1);
  display: flex; flex-direction: column; gap: 10px;
}
.modal.in .sheet { transform: none; }
.modal.search .sheet { text-align: center; }

.wheel-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.wp {
  aspect-ratio: 1.3; border-radius: var(--r);
  font-weight: 900; font-size: 1rem; color: #fff;
  box-shadow: inset 0 -4px 0 rgb(0 0 0 / .2);
  transition: transform .12s;
}
.wp:active { transform: scale(.95); }
.wp.c-red { background: linear-gradient(150deg, #ff6b6f, #c9262b); }
.wp.c-yellow { background: linear-gradient(150deg, #ffd166, #c78a0d); color: var(--ink); }
.wp.c-green { background: linear-gradient(150deg, #4ade80, #157f4a); }
.wp.c-blue { background: linear-gradient(150deg, #6ea8ff, #1d4fd8); }

.pick-list { display: flex; flex-direction: column; gap: 8px; }
.pick { display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: var(--r-sm); background: rgb(255 255 255 / .06); border: 1px solid var(--line); font-weight: 700; }
.pick .av { font-size: 1.3rem; }
.pick b { margin-left: auto; color: var(--muted); font-size: .8rem; }

.results { display: flex; flex-direction: column; gap: 6px; }
.res { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: var(--r-sm); background: rgb(255 255 255 / .05); }
.res.me { background: rgb(255 176 32 / .13); border: 1px solid rgb(255 176 32 / .4); }
.res .place { width: 24px; text-align: center; }
.res .nm { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.res .left { font-size: .7rem; color: var(--muted); font-style: normal; }
.res .w { color: var(--gold); }
.reward { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.chipr { padding: 6px 11px; border-radius: 99px; background: rgb(255 176 32 / .15); border: 1px solid rgb(255 176 32 / .4); font-size: .82rem; font-weight: 800; }
.chipr.lvl { background: rgb(167 139 250 / .2); border-color: var(--violet); }
.daily-score { text-align: center; padding: 10px; }
.daily-score b { display: block; font-size: 2.6rem; font-weight: 900; color: var(--gold); line-height: 1; }
.daily-score small { color: var(--muted); }

.frs { display: flex; flex-direction: column; gap: 6px; }
.fr { display: flex; align-items: center; gap: 9px; padding: 9px 11px; border-radius: var(--r-sm); background: rgb(255 255 255 / .05); }
.fr .nm { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fr .st { font-size: .7rem; }

.ranks { display: flex; flex-direction: column; gap: 5px; }
.ranks li { display: flex; align-items: center; gap: 9px; padding: 8px 11px; border-radius: var(--r-sm); background: rgb(255 255 255 / .04); }
.ranks li.me { background: rgb(255 176 32 / .14); }
.ranks .place { width: 26px; color: var(--muted); font-weight: 800; }
.ranks .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.stats li { text-align: center; padding: 10px 4px; border-radius: var(--r-sm); background: rgb(255 255 255 / .05); }
.stats b { display: block; font-size: 1.05rem; }
.stats small { color: var(--muted); font-size: .68rem; }
.xp { margin: 4px 0; }
.xp-bar { height: 8px; border-radius: 99px; background: rgb(0 0 0 / .4); overflow: hidden; }
.xp-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--cyan), var(--violet)); }
.hist { display: flex; flex-direction: column; gap: 5px; font-size: .8rem; }
.hist li { padding: 8px 10px; border-radius: var(--r-sm); background: rgb(255 255 255 / .04); }
.hist .me { color: var(--gold); font-weight: 700; }
.howto { display: flex; flex-direction: column; gap: 7px; font-size: .9rem; }
.howto li { padding-left: 1.1em; position: relative; }
.howto li::before { content: "·"; position: absolute; left: .2em; color: var(--gold); font-weight: 900; }
ol.howto { counter-reset: h; }
ol.howto li::before { counter-increment: h; content: counter(h) "."; font-size: .8em; }
.news { display: flex; flex-direction: column; gap: 8px; }
.news li { padding: 10px 12px; border-radius: var(--r-sm); background: rgb(255 255 255 / .05); }

.decks { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 9px; }
.deck {
  padding: 10px 8px; border-radius: var(--r);
  background: linear-gradient(160deg, var(--felt-1), var(--felt-2));
  border: 2px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 5px;
}
.deck.on { border-color: var(--glow); box-shadow: 0 0 18px color-mix(in srgb, var(--glow) 45%, transparent); }
.deck-art { display: flex; height: 44px; }
.deck-art i {
  width: 24px; height: 36px; border-radius: 4px; margin-left: -8px;
  background: linear-gradient(150deg, var(--back-1), var(--back-2));
  border: 1px solid rgb(255 255 255 / .4);
}
.deck-art i:first-child { margin-left: 0; transform: rotate(-9deg); }
.deck-art i:last-child { transform: rotate(9deg); }
.deck-nm { font-size: .74rem; font-weight: 700; }
.deck-buy { font-size: .7rem; color: var(--glow); font-weight: 800; }
.packs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.prem { padding: 11px; border-radius: var(--r-sm); background: rgb(167 139 250 / .18); border: 1px solid var(--violet); font-weight: 700; text-align: center; }
.gold-row { margin: 0; font-weight: 800; }

#toasts { position: fixed; left: 0; right: 0; bottom: calc(14px + var(--safe-b)); z-index: 90; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; padding: 0 12px; }
.toast {
  max-width: 420px; padding: 11px 16px; border-radius: 99px;
  background: rgb(10 13 26 / .96); border: 1px solid var(--line);
  font-size: .88rem; font-weight: 600; text-align: center;
  box-shadow: 0 10px 30px rgb(0 0 0 / .5);
  animation: toastIn .25s cubic-bezier(.2,1.4,.4,1);
  pointer-events: auto;
}
.toast.out { opacity: 0; transform: translateY(8px); transition: .3s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(.95); } }

#net {
  position: fixed; top: max(8px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  z-index: 95; padding: 6px 14px; border-radius: 99px;
  background: var(--red); color: #fff; font-size: .78rem; font-weight: 700;
}

.skip-link { position: absolute; left: -9999px; }

/* ---------- bigger screens and landscape ---------- */
@media (min-width: 620px) {
  :root { --card-h: clamp(110px, 18vh, 170px); }
  .screen { padding-inline: 20px; }
  #s-home .menu, .code-card, .modes, .slots, #l-host { width: min(520px, 100%); margin-inline: auto; }
  #opponents { min-height: 112px; padding-inline: 16px; }
}

/* Landscape phone: the table is wide and short, so trim the chrome. */
@media (orientation: landscape) and (max-height: 520px) {
  :root { --card-h: clamp(70px, 26vh, 110px); }
  #opponents { min-height: 72px; }
  .opp-fan { display: none; }
  #g-status { display: none; }
  #hand { padding-top: 8px; }
}

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