/* ============================================================
   Michi TCG — "dusk michi room" design
   Mobile-first. Warm dark espresso board, cream cards, gold accents.
   ============================================================ */

:root {
  /* michi.meme heritage palette */
  --cream: #faf0df;
  --cream-2: #f3e4c8;
  --paper: #fffaf2;
  --ink: #141010;
  --ink-2: #3d3530;
  --muted: #7a6f65;
  --brown: #8b4513;
  --brown-dark: #6b3410;
  --gold: #e8a013;
  --gold-soft: #f6c75c;

  /* dusk board */
  --board-0: #150e09;
  --board-1: #241710;
  --board-2: #332115;
  --board-line: rgba(246, 199, 92, 0.14);
  --board-text: #d9c5ab;
  --board-text-dim: #9a8369;

  --border: #e8dcc8;
  --shadow: rgba(20, 8, 0, 0.35);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  --t-fast: 120ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --t-normal: 200ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --t-bounce: 500ms cubic-bezier(0.34, 1.56, 0.64, 1);

  --font-display: 'Syne', sans-serif;
  --font-body: 'Plus Jakarta Sans', sans-serif;

  --type-chaos: #c2410c;
  --type-nap: #6d5bd0;
  --type-snack: #2f9e44;
  --type-zoomies: #e8a013;
  --type-cuddle: #d6548e;

  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--board-0);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

.ms {
  font-family: 'Material Symbols Rounded';
  font-weight: 500;
  font-style: normal;
  font-size: 1.15em;
  line-height: 1;
  display: inline-block;
  vertical-align: -0.18em;
  letter-spacing: normal;
  white-space: nowrap;
  direction: ltr;
  font-variation-settings: 'FILL' 1, 'GRAD' 0, 'opsz' 24;
  -webkit-font-smoothing: antialiased;
}

#app { height: 100dvh; position: relative; }

.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.screen.active { display: flex; }

/* ============ buttons ============ */
button { font-family: inherit; cursor: pointer; }
.btn {
  border: none;
  background: var(--brown);
  color: #fff8ee;
  font-weight: 800;
  border-radius: var(--radius-full);
  transition: transform var(--t-bounce), box-shadow var(--t-normal), filter var(--t-fast);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45em;
}
.btn:hover:not(:disabled) { transform: translateY(-2px) scale(1.03); filter: brightness(1.08); }
.btn:active:not(:disabled) { transform: translateY(0) scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-big {
  font-size: 1.05rem;
  padding: 0.95rem 2rem;
  font-family: var(--font-display);
  letter-spacing: 0.02em;
  min-height: 52px;
}
.btn-small { font-size: 0.78rem; padding: 0.5rem 1rem; min-height: 38px; }
.btn-gold {
  background: linear-gradient(170deg, var(--gold-soft), var(--gold) 55%, #c77f06);
  color: #3d2400;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
  box-shadow: 0 6px 22px rgba(232, 160, 19, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}
.btn-ghost {
  background: transparent;
  border: 2px solid rgba(246, 199, 92, 0.4);
  color: var(--gold-soft);
  box-shadow: none;
}
.icon-btn {
  width: 38px; height: 38px;
  border: none; border-radius: var(--radius-full);
  background: rgba(255, 248, 238, 0.1);
  color: var(--board-text);
  font-size: 1.05rem;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background var(--t-fast), transform var(--t-bounce);
}
.icon-btn:hover { background: rgba(255, 248, 238, 0.2); transform: scale(1.08); }

/* ============ title screen ============ */
#screen-title {
  background:
    radial-gradient(ellipse 120% 70% at 50% 115%, rgba(139, 69, 19, 0.55), transparent 65%),
    radial-gradient(ellipse 90% 50% at 50% -15%, rgba(232, 160, 19, 0.18), transparent 60%),
    linear-gradient(180deg, var(--board-0), var(--board-1) 55%, var(--board-0));
  overflow: hidden;
  justify-content: center;
  padding: 1.5rem;
}
.title-bg { position: absolute; inset: 0; pointer-events: none; }
.title-glow {
  position: absolute; left: 50%; top: 48%;
  width: min(80vw, 560px); aspect-ratio: 1;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(232, 160, 19, 0.16), transparent 60%);
  animation: glowPulse 5s ease-in-out infinite;
}
@keyframes glowPulse { 0%, 100% { opacity: 0.7; transform: translate(-50%, -50%) scale(1); } 50% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); } }
.float-card {
  position: absolute;
  width: clamp(54px, 9vw, 92px);
  aspect-ratio: 63 / 88;
  border-radius: var(--radius-md);
  border: 2px solid rgba(246, 199, 92, 0.35);
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 240, 210, 0.14) 0 18%, transparent 19%),
    repeating-linear-gradient(45deg, rgba(255, 235, 200, 0.05) 0 8px, transparent 8px 16px),
    linear-gradient(160deg, #7a431a, #4a230a);
  display: flex; align-items: center; justify-content: center;
  color: rgba(255, 240, 210, 0.5); font-size: 1.3rem;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
  animation: floaty 7s ease-in-out infinite;
}
.fc1 { left: 6%; top: 16%; rotate: -14deg; animation-delay: 0s; }
.fc2 { right: 8%; top: 12%; rotate: 11deg; animation-delay: -1.6s; }
.fc3 { left: 12%; bottom: 18%; rotate: 8deg; animation-delay: -3.1s; }
.fc4 { right: 13%; bottom: 22%; rotate: -9deg; animation-delay: -4.4s; }
.fc5 { left: 48%; top: 7%; rotate: 4deg; animation-delay: -5.2s; }
@keyframes floaty {
  0%, 100% { transform: translateY(0) }
  50% { transform: translateY(-18px) }
}
.title-inner { text-align: center; position: relative; animation: rise 800ms cubic-bezier(0.34, 1.56, 0.64, 1) both; max-width: 560px; }
@keyframes rise { from { opacity: 0; transform: translateY(34px); } to { opacity: 1; transform: none; } }
.title-badge {
  width: 84px; height: 84px;
  margin: 0 auto 1.1rem;
  border-radius: 28px;
  background: linear-gradient(160deg, var(--gold-soft), var(--gold) 60%, #b97607);
  display: flex; align-items: center; justify-content: center;
  font-size: 2.6rem; color: #3d2400;
  box-shadow: 0 14px 40px rgba(232, 160, 19, 0.4), inset 0 2px 0 rgba(255, 255, 255, 0.5);
  animation: bob 3.4s ease-in-out infinite;
}
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-9px) rotate(2deg); } }
.title-logo {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(3.4rem, 13vw, 5.6rem);
  letter-spacing: -0.03em;
  line-height: 0.92;
  background: linear-gradient(175deg, #ffe9b8 20%, var(--gold) 60%, #c77f06);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 18px rgba(232, 160, 19, 0.3));
}
.title-logo span {
  display: block;
  font-size: 0.34em;
  letter-spacing: 0.52em;
  margin-left: 0.26em;
  background: none; -webkit-background-clip: initial; background-clip: initial;
  color: var(--board-text);
  filter: none;
}
.title-tag {
  font-family: var(--font-display);
  color: var(--cream);
  font-weight: 700;
  font-size: 1.15rem;
  margin-top: 0.9rem;
  letter-spacing: 0.06em;
}
.title-sub { color: var(--board-text-dim); font-weight: 600; font-size: 0.85rem; margin: 0.4rem auto 1.8rem; max-width: 34ch; line-height: 1.5; }
.title-actions { display: flex; flex-direction: column; gap: 0.7rem; align-items: center; }
.title-actions .btn { width: min(78vw, 300px); }
.title-foot {
  position: absolute; bottom: calc(1rem + var(--safe-b)); left: 0; right: 0;
  text-align: center;
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--board-text-dim);
}

/* ============ loading ============ */
#screen-loading { background: linear-gradient(180deg, var(--board-0), var(--board-1)); }
.loader { text-align: center; color: var(--board-text); font-weight: 600; padding: 0 2rem; }
.loader-cat { font-size: 3rem; animation: pawspin 1.2s ease-in-out infinite; display: inline-block; color: var(--gold); margin-bottom: 0.6rem; }
@keyframes pawspin { 0%, 100% { transform: rotate(-20deg) scale(1); } 50% { transform: rotate(20deg) scale(1.2); } }

/* ============ deck reveal ============ */
#screen-reveal {
  padding: 1.2rem 1rem 0;
  justify-content: flex-start;
  overflow-y: auto;
  background: linear-gradient(180deg, var(--board-0), var(--board-1) 70%);
}
.reveal-title {
  font-family: var(--font-display); font-weight: 800; color: var(--gold-soft);
  font-size: clamp(1.5rem, 5vw, 2.1rem); margin: 0.4rem 0 1rem;
}
.reveal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(28vw, 150px), 1fr));
  gap: 0.7rem;
  width: min(1100px, 100%);
}
.reveal-footer { padding: 1.2rem 0 calc(1.6rem + var(--safe-b)); position: sticky; bottom: 0; }

.flip-wrap { perspective: 900px; position: relative; }
.flip-card {
  position: relative;
  transform-style: preserve-3d;
  transition: transform 650ms cubic-bezier(0.34, 1.56, 0.64, 1);
  transform: rotateY(180deg);
  aspect-ratio: 63 / 88;
}
.flip-card.flipped { transform: rotateY(0deg); }
.flip-card.flip-special { transition-duration: 900ms; }
.flip-face { position: absolute; inset: 0; backface-visibility: hidden; border-radius: var(--radius-md); }
.flip-back { transform: rotateY(180deg); }

/* rare+ reveal burst */
.reveal-burst {
  position: absolute; inset: -28%;
  pointer-events: none;
  background:
    repeating-conic-gradient(from 0deg, rgba(246, 199, 92, 0.35) 0deg 9deg, transparent 9deg 24deg),
    radial-gradient(circle, rgba(246, 199, 92, 0.5), transparent 62%);
  border-radius: 50%;
  animation: burstSpin 1100ms ease-out both;
  z-index: -1;
}
@keyframes burstSpin {
  0% { opacity: 0; transform: scale(0.3) rotate(0deg); }
  25% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.5) rotate(60deg); }
}
.flip-card.flip-special.flipped { animation: specialPop 900ms cubic-bezier(0.34, 1.56, 0.64, 1) 350ms both; }
@keyframes specialPop {
  0% { scale: 1; }
  40% { scale: 1.16; }
  100% { scale: 1; }
}

/* ============ battle board ============ */
#screen-battle {
  background:
    radial-gradient(ellipse 130% 60% at 50% -12%, rgba(139, 69, 19, 0.4), transparent 60%),
    radial-gradient(ellipse 130% 60% at 50% 112%, rgba(139, 69, 19, 0.4), transparent 60%),
    radial-gradient(ellipse 70% 40% at 50% 50%, rgba(232, 160, 19, 0.06), transparent 70%),
    linear-gradient(180deg, var(--board-0), var(--board-1) 50%, var(--board-0));
}
.board {
  width: min(1180px, 100vw);
  height: 100%;
  display: flex; flex-direction: column;
  padding: 0.45rem 0.6rem calc(0.4rem + var(--safe-b));
  gap: 0.3rem;
}
.side { display: flex; flex-direction: column; gap: 0.25rem; min-height: 0; }
.side-foe { flex: 1; }
.side-you { flex: 1.6; }
.side-meta {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.72rem; font-weight: 700; color: var(--board-text-dim);
  flex-wrap: wrap;
}
.player-name { font-family: var(--font-display); color: var(--gold-soft); font-size: 0.88rem; letter-spacing: 0.04em; }
.meta-chip {
  background: rgba(255, 248, 238, 0.07);
  border: 1px solid var(--board-line);
  border-radius: var(--radius-full);
  padding: 0.14rem 0.6rem;
  color: var(--board-text);
  white-space: nowrap;
}
.field { flex: 1; display: flex; align-items: stretch; justify-content: center; gap: clamp(0.5rem, 3vw, 1.6rem); min-height: 0; }
.field-foe { align-items: flex-start; }
.field-you { align-items: flex-end; }

.active-slot { width: clamp(118px, 34vw, 205px); position: relative; }
.active-slot .card { font-size: clamp(7px, 2vw, 12.5px); }
.bench { display: flex; align-items: center; }
.bench-slot {
  width: clamp(60px, 17vw, 104px);
  aspect-ratio: 63 / 88;
  border: 2px dashed var(--board-line);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  color: rgba(246, 199, 92, 0.22); font-size: 1.2rem;
  transition: border-color var(--t-fast), transform var(--t-bounce);
  position: relative;
}
.bench-slot:not(:first-child) { margin-left: clamp(-2.2rem, -5.5vw, -0.9rem); }
.bench-slot:hover { z-index: 6; transform: translateY(-4px); }
.bench-slot .card { font-size: clamp(4px, 0.95vw, 7.5px); }
.bench-slot.has-card { border-style: solid; border-color: transparent; }
.slot-label {
  position: absolute; top: -0.15rem; left: 50%; transform: translate(-50%, -100%);
  font-size: 0.56rem; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--board-text-dim);
  white-space: nowrap;
}

/* ============ midbar ============ */
.midbar {
  display: flex; align-items: center; gap: 0.6rem;
  background: rgba(28, 17, 10, 0.82);
  border: 1px solid var(--board-line);
  border-radius: var(--radius-lg);
  padding: 0.4rem 0.65rem;
  backdrop-filter: blur(8px);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.log {
  flex: 1 1 200px; max-height: 3.4rem; overflow: hidden;
  display: flex; flex-direction: column; justify-content: flex-end;
  font-size: 0.7rem; color: var(--board-text-dim); font-weight: 600;
  line-height: 1.35;
  min-width: 140px;
}
.log div {
  animation: logIn 250ms ease both;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.log div:last-child { color: var(--cream); }
@keyframes logIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.mid-right { display: flex; align-items: center; gap: 0.55rem; margin-left: auto; }
.energy {
  display: flex; align-items: center; gap: 0.25rem; font-size: 1.05rem;
  background: rgba(255, 248, 238, 0.07);
  border: 1px solid var(--board-line);
  border-radius: var(--radius-full);
  padding: 0.28rem 0.65rem;
}
.energy-label {
  font-size: 0.58rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--board-text-dim); margin-right: 0.2rem;
}
.energy-count { font-size: 0.72rem; font-weight: 800; color: var(--gold-soft); margin-left: 0.2rem; }
.attach-pip { color: rgba(246, 199, 92, 0.25); transition: color var(--t-normal), transform var(--t-bounce); }
.attach-pip.ready { color: var(--gold); transform: scale(1.15); }
.mid-buttons { display: flex; gap: 0.4rem; align-items: center; }
.btn-small { white-space: nowrap; }
#btn-retreat { background: rgba(255, 248, 238, 0.12); color: var(--cream); box-shadow: none; }
#btn-retreat:hover:not(:disabled) { background: rgba(255, 248, 238, 0.2); }

/* ============ hand dock ============ */
.hand-dock {
  flex-shrink: 0;
  background: linear-gradient(180deg, rgba(28, 17, 10, 0.6), rgba(20, 10, 5, 0.92));
  border: 1px solid var(--board-line);
  border-bottom: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 0.3rem 0.4rem 0.45rem;
  position: relative;
}
.hand-label {
  position: absolute; top: 0.35rem; left: 0; right: 0;
  text-align: center;
  font-size: 0.56rem; font-weight: 800; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--board-text-dim);
  pointer-events: none;
}
.hand {
  display: flex; justify-content: flex-start; align-items: flex-end;
  gap: 0.4rem;
  overflow-x: auto;
  padding: 1.45rem 0.3rem 0.2rem;
  min-height: clamp(92px, 24vw, 150px);
  scrollbar-width: none;
}
.hand::-webkit-scrollbar { display: none; }
.hand .card-wrap {
  width: clamp(76px, 20vw, 108px);
  flex-shrink: 0;
  transition: transform var(--t-bounce);
}
.hand .card-wrap:hover { transform: translateY(-10px); z-index: 6; }
.hand .card { font-size: clamp(5px, 1.35vw, 8.5px); }
.hand .card.unplayable { opacity: 0.55; filter: saturate(0.6); }
.card-wrap { position: relative; }
@media (min-width: 760px) {
  .hand { justify-content: center; }
}

/* ============ card ============ */
.card {
  position: relative;
  aspect-ratio: 63 / 88;
  width: 100%;
  border-radius: var(--radius-md);
  background: var(--paper);
  border: 2.5px solid var(--card-type-color, var(--border));
  box-shadow:
    0 6px 16px var(--shadow),
    inset 0 0 0 1.5px rgba(255, 255, 255, 0.65);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
  transition: transform var(--t-bounce), box-shadow var(--t-normal);
  font-size: 10px;
}
.card.clickable { cursor: pointer; }
.card.clickable:hover {
  transform: translateY(-5px) rotate(-1deg) scale(1.03);
  box-shadow: 0 16px 34px var(--shadow), 0 0 0 3px color-mix(in srgb, var(--card-type-color, var(--gold)) 55%, transparent);
  z-index: 5;
}
.card-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.42em 0.55em;
  background: linear-gradient(135deg, var(--card-type-color, var(--cream-2)), color-mix(in srgb, var(--card-type-color, var(--cream-2)) 62%, #000 16%));
  color: #fff;
  gap: 0.4em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.card-name {
  font-family: var(--font-display); font-weight: 700;
  font-size: 1em; line-height: 1.1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0; flex: 1;
}
.card-hp { font-weight: 800; font-size: 0.9em; white-space: nowrap; flex-shrink: 0; }
.card-art {
  position: relative; width: 100%;
  flex: 1 1 auto; min-height: 0;
  background: var(--cream-2);
  box-shadow: inset 0 2px 6px rgba(60, 30, 5, 0.18);
}
.card-art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-art-fallback {
  display: flex; align-items: center; justify-content: center;
  height: 100%; font-size: 3em; color: rgba(139, 69, 19, 0.25);
}
.card-type-chip {
  position: absolute; bottom: 0.4em; left: 0.4em;
  background: var(--card-type-color, var(--brown));
  color: #fff; font-weight: 800; font-size: 0.85em;
  padding: 0.16em 0.6em; border-radius: var(--radius-full);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}
.card-rarity {
  position: absolute; bottom: 0.4em; right: 0.4em;
  font-size: 1.1em; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
  color: #fff;
}
.card-rarity.rarity-uncommon { color: #9bd0ff; }
.card-rarity.rarity-rare { color: #5fb6ff; }
.card-rarity.rarity-epic { color: #c79bff; }
.card-rarity.rarity-legendary { color: #ffd84d; }

.card-attacks {
  flex: 0 0 auto; display: flex; flex-direction: column;
  padding: 0.22em 0.35em; gap: 0.18em;
  background: var(--paper);
}
.card-atk {
  display: flex; align-items: center; gap: 0.38em; line-height: 1.1;
  background: var(--cream);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 0.16em 0.45em 0.16em 0.2em;
  transition: opacity var(--t-normal), border-color var(--t-normal), background var(--t-normal);
}
.card-atk.ready {
  border-color: color-mix(in srgb, var(--card-type-color) 55%, white);
  background: color-mix(in srgb, var(--card-type-color) 10%, white);
}
.card-atk.locked { opacity: 0.55; }
.atk-ready-ic { color: #2f9e44; font-size: 1.15em; flex-shrink: 0; }
.card-atk-name {
  font-weight: 700; color: var(--ink-2); flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.card-atk-dmg { font-weight: 800; color: var(--ink); flex-shrink: 0; }

/* cost sockets */
.cost-sockets { display: inline-flex; gap: 0.14em; flex-shrink: 0; }
.socket {
  width: 1.55em; height: 1.55em; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-sizing: border-box;
}
.socket .ms { font-size: 0.95em; }
.socket.typed.filled { background: var(--socket-color); color: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); }
.socket.typed.empty {
  background: color-mix(in srgb, var(--socket-color) 12%, white);
  border: 1.6px dashed var(--socket-color);
  color: var(--socket-color);
}
.socket.any.filled { background: #8d7f6e; color: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); }
.socket.any.empty { background: var(--cream-2); border: 1.6px dashed #b3a08f; color: #a3927f; }

/* HP bar */
.card-hpbar {
  height: 0.62em;
  margin: 0.06em 0.42em 0.38em;
  background: var(--cream-2);
  border-radius: var(--radius-full);
  box-shadow: inset 0 1px 2px rgba(80, 40, 10, 0.22);
  overflow: hidden;
  flex-shrink: 0;
}
.card-hpbar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: #2f9e44;
  background-image: linear-gradient(rgba(255, 255, 255, 0.4), transparent 45%, rgba(0, 0, 0, 0.08));
  transition: width 500ms cubic-bezier(0.22, 1, 0.36, 1), background-color 400ms ease;
}

/* holo shimmer + legendary */
.card.holo::after {
  content: '';
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(115deg, transparent 30%, rgba(255, 255, 255, 0.55) 47%, rgba(255, 210, 130, 0.5) 53%, transparent 70%);
  background-size: 260% 260%;
  animation: holo 3.2s ease-in-out infinite;
  mix-blend-mode: soft-light;
}
@keyframes holo { 0%, 100% { background-position: 85% 85%; } 50% { background-position: 15% 15%; } }
.card.legendary { border-color: #d4a017; box-shadow: 0 6px 22px rgba(212, 160, 23, 0.55), inset 0 0 0 1.5px rgba(255, 234, 170, 0.8); }
.card.legendary .card-head { background: linear-gradient(135deg, #d4a017, #8b4513); }

/* attached energy chips */
.card-energy-row {
  position: absolute; top: 0.35em; left: 0.35em;
  display: flex; gap: 0.18em; flex-wrap: wrap; max-width: 75%;
  background: rgba(255, 255, 255, 0.85);
  border-radius: var(--radius-full);
  padding: 0.16em 0.22em;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25);
}
.energy-chip {
  width: 1.45em; height: 1.45em; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
}
.energy-chip .ms { font-size: 0.9em; }

/* item card */
.card.item-card { border-color: #8a7a5e; }
.card.item-card .card-head { background: linear-gradient(135deg, #6e5c43, #4a3a28); }
.card-item-body {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.45em; padding: 0.4em; text-align: center;
  background: radial-gradient(ellipse at 50% 32%, rgba(255, 255, 255, 0.8), transparent 65%), var(--cream-2);
}
.card-item-img {
  height: 4.2em;
  image-rendering: pixelated;
  filter: drop-shadow(0 3px 4px rgba(80, 40, 10, 0.3));
}
.hand .card-wrap:hover .card-item-img { animation: bob 1.2s ease-in-out infinite; }
.card-item-text { font-weight: 600; color: var(--ink-2); font-size: 0.92em; line-height: 1.3; }

/* energy card */
.card.energy-card .card-head {
  background: linear-gradient(135deg, var(--card-type-color), color-mix(in srgb, var(--card-type-color) 62%, #000 16%));
}
.card-energy-body {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.2em;
  background:
    radial-gradient(circle at 50% 45%, color-mix(in srgb, var(--card-type-color) 25%, transparent), transparent 70%),
    var(--paper);
}
.energy-big { font-size: 3.2em; color: var(--card-type-color); filter: drop-shadow(0 2px 6px color-mix(in srgb, var(--card-type-color) 45%, transparent)); }
.energy-word {
  font-size: 0.9em; font-weight: 800; letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--muted);
}

/* card back */
.card-back {
  width: 100%; height: 100%;
  aspect-ratio: 63 / 88;
  border-radius: var(--radius-md);
  border: 2.5px solid #5b3210;
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 240, 210, 0.16) 0 18%, transparent 19%),
    repeating-linear-gradient(45deg, rgba(255, 235, 200, 0.07) 0 8px, transparent 8px 16px),
    linear-gradient(160deg, #a0571d, #5d2c0c);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem;
  color: rgba(255, 240, 210, 0.85);
  box-shadow: 0 6px 16px var(--shadow);
}

/* status badges */
.badge-shield, .badge-stun {
  position: absolute; top: -8px; z-index: 3;
  font-size: 1rem;
  width: 1.7em; height: 1.7em;
  display: flex; align-items: center; justify-content: center;
  background: var(--paper);
  border-radius: var(--radius-full);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}
.badge-shield { right: -8px; color: var(--brown); animation: pop var(--t-bounce) both; }
.badge-stun { left: -8px; color: var(--type-nap); }
@keyframes pop { from { transform: scale(0); } to { transform: scale(1); } }

/* ============ overlays ============ */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(12, 6, 2, 0.7);
  backdrop-filter: blur(5px);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.overlay.hidden { display: none; }
.overlay-box {
  background: var(--cream);
  border-radius: var(--radius-xl);
  padding: 1.4rem 1.5rem;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  text-align: center;
  animation: pop 380ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
  max-width: min(94vw, 560px);
}
.overlay-box h3 { font-family: var(--font-display); color: var(--brown); margin-bottom: 1rem; }
.promote-choices { display: flex; gap: 0.7rem; justify-content: center; flex-wrap: wrap; }
.promote-choices .card-wrap { width: clamp(96px, 26vw, 130px); }
.promote-choices .card { font-size: clamp(6px, 1.6vw, 9px); }
.result-emoji { font-size: 4rem; animation: bob 2s ease-in-out infinite; color: var(--gold); }
.result-box h2 { font-family: var(--font-display); font-size: 2.3rem; color: var(--brown); margin: 0.4rem 0; }
.result-box p { color: var(--muted); font-weight: 600; margin-bottom: 1.3rem; }

/* detail modal — bottom sheet on mobile, side-by-side on desktop */
.detail-box {
  position: relative;
  display: flex; flex-direction: column; gap: 1rem;
  background: var(--cream);
  border-radius: var(--radius-xl);
  padding: 1.2rem;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  width: min(94vw, 640px);
  max-height: 88dvh;
  overflow-y: auto;
  animation: pop 320ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.detail-close {
  position: absolute; top: 0.7rem; right: 0.7rem; z-index: 2;
  border: none; background: var(--cream-2);
  width: 2.2rem; height: 2.2rem; border-radius: var(--radius-full);
  color: var(--ink-2); font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--t-fast), transform var(--t-bounce);
}
.detail-close:hover { background: var(--border); transform: scale(1.1); }
.detail-card { width: clamp(150px, 40vw, 210px); flex-shrink: 0; margin: 0 auto; }
.detail-card .card { font-size: clamp(9px, 2.4vw, 13px); }
.detail-side { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.detail-title { font-family: var(--font-display); color: var(--brown); font-size: 1.25rem; padding-right: 2.2rem; }
.detail-info { display: flex; flex-direction: column; gap: 0.4rem; }
.detail-row { font-size: 0.8rem; font-weight: 600; color: var(--ink-2); line-height: 1.5; }
.detail-attack {
  background: var(--paper);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.45rem 0.65rem;
}
.detail-attack.ready { border-color: #2f9e44; background: color-mix(in srgb, #2f9e44 6%, white); }
.detail-attack.locked { opacity: 0.62; }
.detail-attack-head { display: flex; justify-content: space-between; font-size: 0.85rem; font-weight: 800; color: var(--ink); }
.detail-attack-sub { font-size: 0.72rem; color: var(--muted); font-weight: 600; margin-top: 0.15rem; line-height: 1.5; }
.detail-attack .socket, .detail-legend .socket { width: 1.25rem; height: 1.25rem; vertical-align: middle; }
.detail-legend { line-height: 1.9; }
.detail-legend .socket, .detail-row .energy-chip { width: 1.2rem; height: 1.2rem; display: inline-flex; vertical-align: middle; }
.detail-actions { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.3rem; }
.atk-option {
  border: 1.5px solid var(--border);
  background: var(--paper);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.75rem;
  text-align: left;
  min-height: 44px;
  transition: border-color var(--t-fast), background var(--t-fast), transform var(--t-fast);
}
.atk-option:hover:not(:disabled) { border-color: var(--brown); background: var(--cream); transform: translateX(3px); }
.atk-option:disabled { opacity: 0.45; cursor: not-allowed; }
.atk-option .row1 { display: flex; justify-content: space-between; gap: 0.5rem; font-weight: 800; font-size: 0.85rem; color: var(--ink); }
.atk-option .row2 { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.7rem; color: var(--muted); margin-top: 0.15rem; }
@media (min-width: 700px) {
  .detail-box { flex-direction: row; align-items: flex-start; }
  .detail-card { margin: 0; }
}

/* ============ how to play ============ */
.howto-box {
  position: relative;
  background: var(--cream);
  border-radius: var(--radius-xl);
  padding: 1.4rem 1.4rem 1.8rem;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  width: min(94vw, 560px);
  max-height: 88dvh;
  overflow-y: auto;
  animation: pop 320ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.howto-close {
  position: sticky; top: 0; float: right; z-index: 2;
  border: none; background: var(--cream-2);
  width: 2.2rem; height: 2.2rem; border-radius: var(--radius-full);
  color: var(--ink-2); font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
}
.howto-title {
  font-family: var(--font-display); color: var(--brown);
  font-size: 1.5rem; margin-bottom: 1rem;
  display: flex; align-items: center; gap: 0.5rem;
}
.howto-section { margin-bottom: 1.1rem; }
.howto-section h3 {
  font-family: var(--font-display); font-size: 0.95rem; color: var(--brown);
  display: flex; align-items: center; gap: 0.4rem;
  margin-bottom: 0.35rem;
}
.howto-section p, .howto-section li { font-size: 0.82rem; font-weight: 600; color: var(--ink-2); line-height: 1.6; }
.howto-section ol { padding-left: 1.3rem; display: flex; flex-direction: column; gap: 0.2rem; }
.howto-socket {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.3rem; height: 1.3rem; border-radius: 50%;
  vertical-align: middle;
  box-sizing: border-box;
}
.howto-socket.typed { background: color-mix(in srgb, var(--type-chaos) 12%, white); border: 1.6px dashed var(--type-chaos); color: var(--type-chaos); }
.howto-socket.any { background: var(--cream-2); border: 1.6px dashed #b3a08f; color: #a3927f; }
.howto-socket .ms { font-size: 0.8rem; }
.ms.check { color: #2f9e44; }
.howto-wheel { display: flex; flex-wrap: wrap; gap: 0.3rem 0.45rem; align-items: center; }
.howto-type {
  display: inline-flex; align-items: center; gap: 0.25em;
  color: #fff; font-weight: 800; font-size: 0.72rem;
  padding: 0.2em 0.65em; border-radius: var(--radius-full);
}
.t-chaos { background: var(--type-chaos); }
.t-nap { background: var(--type-nap); }
.t-snack { background: var(--type-snack); }
.t-zoomies { background: var(--type-zoomies); }
.t-cuddle { background: var(--type-cuddle); }

/* ============ fx ============ */
#fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: 100; overflow: hidden; }
.dmg-float {
  position: absolute;
  font-family: var(--font-display); font-weight: 800;
  font-size: clamp(1.5rem, 5vw, 2.1rem); color: #ff5d49;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.4);
  animation: dmgFloat 900ms cubic-bezier(0.22, 1, 0.36, 1) both;
  transform: translate(-50%, -50%);
  white-space: nowrap;
}
.dmg-float.heal { color: #4ade80; }
@keyframes dmgFloat {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
  18% { opacity: 1; transform: translate(-50%, -60%) scale(1.25); }
  100% { opacity: 0; transform: translate(-50%, -150%) scale(1); }
}
.fx-impact {
  position: absolute; width: 90px; height: 90px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 220, 120, 0.95), rgba(255, 140, 40, 0.5) 55%, transparent 70%);
  animation: impact 420ms ease-out both;
}
@keyframes impact { from { transform: translate(-50%, -50%) scale(0.2); opacity: 1; } to { transform: translate(-50%, -50%) scale(1.8); opacity: 0; } }
.confetti { position: absolute; top: -20px; font-size: 1.5rem; animation: confFall linear both; }
@keyframes confFall { to { transform: translateY(110vh) rotate(720deg); } }

/* attack + hit */
.anim-lunge-up { animation: lungeUp 450ms cubic-bezier(0.34, 1.56, 0.64, 1); }
.anim-lunge-down { animation: lungeDown 450ms cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes lungeUp { 30% { transform: translateY(-46px) scale(1.08) rotate(-3deg); } 60% { transform: translateY(-30px); } }
@keyframes lungeDown { 30% { transform: translateY(46px) scale(1.08) rotate(3deg); } 60% { transform: translateY(30px); } }
.anim-hit { animation: hitShake 450ms ease both; }
@keyframes hitShake {
  10% { transform: translate(-7px, 2px) rotate(-2deg); filter: brightness(1.7) saturate(2.2); }
  30% { transform: translate(7px, -2px) rotate(2deg); }
  50% { transform: translate(-5px, 1px); }
  70% { transform: translate(4px, -1px); filter: none; }
}
.board.shake { animation: boardShake 350ms ease; }
@keyframes boardShake {
  20% { transform: translate(-5px, 3px); } 40% { transform: translate(5px, -3px); }
  60% { transform: translate(-3px, 2px); } 80% { transform: translate(3px, -1px); }
}

/* placement slam */
.anim-place { animation: placeSlam 520ms cubic-bezier(0.34, 1.56, 0.64, 1) both; }
@keyframes placeSlam {
  0% { opacity: 0; transform: translateY(-44px) scale(1.45) rotate(3deg); }
  55% { opacity: 1; transform: translateY(2px) scale(0.97) rotate(0deg); }
  75% { transform: translateY(-3px) scale(1.02); }
  100% { transform: none; }
}
.fx-ring {
  position: absolute; width: 110px; height: 110px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 3px solid rgba(246, 199, 92, 0.85);
  animation: ring 500ms ease-out both;
}
@keyframes ring { from { transform: translate(-50%, -50%) scale(0.3); opacity: 1; } to { transform: translate(-50%, -50%) scale(1.6); opacity: 0; } }
.fx-flash {
  position: fixed; inset: 0;
  background: radial-gradient(circle at 50% 50%, rgba(255, 216, 77, 0.4), transparent 65%);
  animation: flash 600ms ease-out both;
}
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

/* KO tear-apart */
.tear-wrap { position: absolute; pointer-events: none; }
.tear-holder { position: absolute; inset: 0; }
.tear-holder .card { box-shadow: none; }
.tear-h-left {
  clip-path: polygon(0 0, 56% 0, 44% 18%, 58% 34%, 46% 52%, 57% 70%, 45% 86%, 52% 100%, 0 100%);
  animation: tearLeft 800ms cubic-bezier(0.4, 0, 0.8, 0.4) both;
}
.tear-h-right {
  clip-path: polygon(56% 0, 100% 0, 100% 100%, 52% 100%, 45% 86%, 57% 70%, 46% 52%, 58% 34%, 44% 18%);
  animation: tearRight 800ms cubic-bezier(0.4, 0, 0.8, 0.4) both;
}
@keyframes tearLeft {
  0% { transform: none; opacity: 1; }
  20% { transform: translate(-6px, 0) rotate(-3deg); }
  100% { transform: translate(-55%, 80%) rotate(-28deg); opacity: 0; }
}
@keyframes tearRight {
  0% { transform: none; opacity: 1; }
  20% { transform: translate(6px, 0) rotate(3deg); }
  100% { transform: translate(55%, 80%) rotate(28deg); opacity: 0; }
}
.tear-flash {
  position: absolute; left: 50%; top: 0; bottom: 0; width: 4px;
  transform: translateX(-50%) rotate(4deg);
  background: linear-gradient(180deg, transparent, #ffd84d, #fff, #ffd84d, transparent);
  animation: tearFlash 300ms ease-out both;
}
@keyframes tearFlash { 0% { opacity: 0; scale: 1 0.3; } 40% { opacity: 1; scale: 1 1.1; } 100% { opacity: 0; } }

/* coin flip */
.coin {
  position: fixed; left: 50%; top: 42%;
  transform: translate(-50%, -50%);
  width: 4.4rem; height: 4.4rem;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #ffe9b8, #e8a013 60%, #b97607);
  border: 3px solid #8b5a10;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  display: flex; align-items: center; justify-content: center;
  color: #7a4a08; font-size: 1.7rem;
  animation: coinSpin 750ms cubic-bezier(0.3, 0.1, 0.3, 1);
  z-index: 110;
}
@keyframes coinSpin {
  0% { transform: translate(-50%, -50%) rotateY(0) scale(0.4); }
  100% { transform: translate(-50%, -50%) rotateY(1800deg) scale(1); }
}
.coin.done { animation: pop 250ms cubic-bezier(0.34, 1.56, 0.64, 1); }
.coin-result { font-family: var(--font-display); font-weight: 800; font-size: 0.85rem; color: #5e3a06; letter-spacing: 0.02em; }

/* turn banner */
.turn-banner {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-display); font-weight: 800;
  font-size: clamp(1.5rem, 6vw, 2.6rem);
  color: var(--gold-soft);
  background: rgba(28, 17, 10, 0.92);
  border: 2px solid rgba(246, 199, 92, 0.5);
  border-radius: var(--radius-full);
  padding: 0.5rem 2rem;
  box-shadow: 0 14px 50px rgba(0, 0, 0, 0.6);
  animation: banner 1100ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
  white-space: nowrap;
  z-index: 40;
}
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
}

/* ============ desktop refinements ============ */
@media (min-width: 760px) {
  .board { padding: 0.8rem 1.2rem; gap: 0.45rem; }
  .side-meta { font-size: 0.78rem; }
  .player-name { font-size: 0.95rem; }
  .log { font-size: 0.74rem; }
  .hand-dock { padding: 0.4rem 0.8rem 0.5rem; }
}
@media (max-height: 620px) {
  .hand { min-height: 84px; }
  .hand .card-wrap { width: clamp(64px, 16vw, 84px); }
  .active-slot { width: clamp(92px, 22vw, 140px); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
