/* ============================================================
   BINDERS — creature fusion game
   Mobile-first, portrait, dark mystical theme
   ============================================================ */

:root {
  --bg: #0b0a1a;
  --bg2: #14122b;
  --panel: #1b1838;
  --panel2: #241f47;
  --ink: #ece9ff;
  --muted: #9b94c4;
  --line: #34305f;
  --accent: #b07bff;
  --accent2: #6ee7ff;
  --gold: #ffd76a;
  --good: #6bf0a8;
  --bad: #ff7b9c;

  --ember: #ff7a4d;
  --tide: #4db8ff;
  --verdant: #6bdc7a;
  --gale: #cdd6ff;
  --void: #b07bff;

  --tap: 46px;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(1200px 600px at 20% -10%, #2a1f55 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 10%, #163a4d 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

button { font-family: inherit; cursor: pointer; color: inherit; }

#fxCanvas {
  position: fixed; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 60;
}

.app {
  position: relative;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(20,18,43,.4), rgba(11,10,26,.4));
}

/* ===================== TOP BAR ===================== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 10px 12px;
  background: linear-gradient(180deg, rgba(27,24,56,.95), rgba(27,24,56,.6));
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.topbar__title { display: flex; flex-direction: column; align-items: center; line-height: 1; }
.brand { font-weight: 800; letter-spacing: 3px; font-size: 18px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.act-label { font-size: 11px; color: var(--gold); letter-spacing: 1px; margin-top: 3px; }
.topbar__right { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  min-width: var(--tap); min-height: var(--tap);
  border: 1px solid var(--line); background: var(--panel2);
  border-radius: 12px; font-size: 18px; display: grid; place-items: center;
  transition: transform .12s ease, background .2s;
}
.icon-btn.small { min-width: 38px; min-height: 38px; font-size: 16px; }
.icon-btn:active { transform: scale(.9); background: var(--panel); }

.hint-pill {
  display: flex; align-items: center; gap: 5px;
  min-height: var(--tap); padding: 0 12px;
  border: 1px solid var(--line); background: var(--panel2);
  border-radius: 999px; font-weight: 700; font-size: 14px;
}
.hint-pill__icon { color: var(--gold); }
.hint-pill:active { transform: scale(.95); }

/* ===================== OBJECTIVE BANNER ===================== */
.objective-banner {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; font-size: 13px;
  background: linear-gradient(90deg, rgba(176,123,255,.18), rgba(110,231,255,.12));
  border-bottom: 1px solid var(--line);
}
.objective-banner__tag {
  font-size: 9px; font-weight: 800; letter-spacing: 1.5px;
  color: var(--bg); background: var(--gold); padding: 3px 6px; border-radius: 6px;
}
.objective-banner__text { flex: 1; color: var(--ink); }
.objective-banner__progress { color: var(--accent2); font-weight: 700; font-variant-numeric: tabular-nums; }
.objective-banner.pulse { animation: bannerPulse 1.6s ease; }
@keyframes bannerPulse {
  0%,100% { background: linear-gradient(90deg, rgba(176,123,255,.18), rgba(110,231,255,.12)); }
  40% { background: linear-gradient(90deg, rgba(255,215,106,.35), rgba(176,123,255,.3)); }
}

/* ===================== SCREENS ===================== */
.screens { position: relative; flex: 1; overflow: hidden; }
.screen {
  position: absolute; inset: 0; display: none;
  flex-direction: column; padding: 12px;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.screen--active { display: flex; animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: none; } }

/* ===================== ALTAR ===================== */
.altar {
  background: radial-gradient(120% 120% at 50% 0%, rgba(176,123,255,.18), transparent 70%), var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 14px; text-align: center; box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.altar__slots { display: flex; align-items: center; justify-content: center; gap: 14px; }
.slot {
  width: 92px; height: 92px; border-radius: 20px;
  border: 2px dashed var(--line); background: var(--panel2);
  display: grid; place-items: center; position: relative;
  transition: transform .18s cubic-bezier(.3,1.6,.5,1), border-color .2s, box-shadow .2s;
}
.slot__placeholder { font-size: 30px; color: var(--muted); }
.slot.filled { border-style: solid; border-color: var(--accent); box-shadow: 0 0 18px rgba(176,123,255,.4); }
.slot.dropTarget { border-color: var(--accent2); box-shadow: 0 0 22px rgba(110,231,255,.6); transform: scale(1.08); }
.slot .creature-face { width: 100%; height: 100%; }
.altar__plus { font-size: 22px; color: var(--muted); }

.bind-btn {
  margin-top: 16px; width: 70%; max-width: 260px; min-height: 52px;
  border: none; border-radius: 14px; font-weight: 800; letter-spacing: 2px; font-size: 16px;
  color: #1a1030; background: linear-gradient(90deg, #4a4470, #5a5488);
  opacity: .5; transition: transform .12s, opacity .2s, box-shadow .2s;
}
.bind-btn:not(:disabled) {
  opacity: 1; color: #190a2e;
  background: linear-gradient(90deg, var(--gold), #ffb14d);
  box-shadow: 0 0 24px rgba(255,215,106,.5);
  animation: bindReady 1.4s ease-in-out infinite;
}
@keyframes bindReady { 0%,100%{ transform: scale(1);} 50%{ transform: scale(1.04);} }
.bind-btn:not(:disabled):active { transform: scale(.94); }

.bind-flavor { color: var(--muted); font-size: 12px; margin: 12px 0 0; min-height: 16px; }
.bind-flavor.dud { color: var(--bad); animation: shake .4s; }
@keyframes shake {
  10%,90%{transform:translateX(-2px);} 30%,70%{transform:translateX(4px);} 50%{transform:translateX(-5px);}
}

/* charging fx on altar */
.altar.charging::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 30%, rgba(255,215,106,.5), transparent 60%);
  animation: charge .7s ease forwards; pointer-events: none;
}
@keyframes charge { from { opacity: 0; transform: scale(.6);} 60%{opacity:1;} to { opacity: 0; transform: scale(1.6);} }

/* ===================== TRAYS / INVENTORY ===================== */
.source-tray, .inventory { margin-top: 12px; }
.tray-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px; font-weight: 700; color: var(--ink); margin-bottom: 8px;
  padding: 0 2px;
}
.tray-head__hint { font-size: 11px; color: var(--muted); font-weight: 500; }

.source-list { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.inventory-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
}

/* creature chip */
.chip-creature {
  position: relative; background: var(--panel2);
  border: 1px solid var(--line); border-radius: 14px;
  padding: 8px 4px 6px; text-align: center; min-height: 80px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  transition: transform .12s, box-shadow .2s, border-color .2s;
  touch-action: none;
}
.source-list .chip-creature { min-width: 72px; flex: 0 0 auto; }
.chip-creature:active { transform: scale(.92); }
.chip-creature.dragging { opacity: .3; }
.chip-creature .emoji { font-size: 28px; line-height: 1; filter: drop-shadow(0 2px 4px rgba(0,0,0,.5)); }
.chip-creature .cname { font-size: 10px; color: var(--muted); max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-creature .count {
  position: absolute; top: -6px; right: -6px;
  background: var(--accent); color: #1a1030; font-size: 11px; font-weight: 800;
  min-width: 20px; height: 20px; border-radius: 999px; display: grid; place-items: center;
  border: 2px solid var(--bg);
}
.chip-creature.aff-Ember   { box-shadow: inset 0 0 0 1px rgba(255,122,77,.4); }
.chip-creature.aff-Tide    { box-shadow: inset 0 0 0 1px rgba(77,184,255,.4); }
.chip-creature.aff-Verdant { box-shadow: inset 0 0 0 1px rgba(107,220,122,.4); }
.chip-creature.aff-Gale    { box-shadow: inset 0 0 0 1px rgba(205,214,255,.4); }
.chip-creature.aff-Void    { box-shadow: inset 0 0 0 1px rgba(176,123,255,.5); }
.chip-creature.unexplored::before {
  content: ""; position: absolute; inset: -1px; border-radius: 14px;
  box-shadow: 0 0 0 2px var(--accent2), 0 0 14px rgba(110,231,255,.5);
  animation: glowPulse 1.6s ease-in-out infinite; pointer-events: none;
}
@keyframes glowPulse { 0%,100%{opacity:.35;} 50%{opacity:1;} }

.empty-note { color: var(--muted); font-size: 12px; padding: 8px 2px; }

/* ===================== TREE ===================== */
.tree-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-bottom: 8px;
}
.completion { flex: 1; }
.completion__bar { height: 8px; background: var(--panel2); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.completion__fill { display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .6s ease; }
.completion__text { font-size: 11px; color: var(--muted); }
.zoom-controls { display: flex; align-items: center; gap: 6px; }
.reveal-btn {
  min-height: 38px; padding: 0 10px; border-radius: 12px; font-size: 12px; font-weight: 700;
  border: 1px solid var(--gold); background: rgba(255,215,106,.12); color: var(--gold);
}
.reveal-btn:active { transform: scale(.94); }
.reveal-btn:disabled { opacity: .4; }

.tree-viewport {
  flex: 1; overflow: auto; -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line); border-radius: var(--radius);
  background:
    radial-gradient(600px 300px at 50% 0%, rgba(176,123,255,.08), transparent 70%),
    var(--bg2);
  touch-action: pan-x pan-y;
}
.tree-canvas { transform-origin: 0 0; padding: 10px 6px 30px; width: max-content; min-width: 100%; }

.tier-block { margin-bottom: 14px; }
.tier-head {
  display: flex; align-items: center; gap: 8px; margin: 4px 4px 8px;
  font-size: 12px; color: var(--muted); position: sticky; left: 0;
}
.tier-head .tier-name { font-weight: 800; color: var(--ink); letter-spacing: 1px; }
.tier-bar { flex: 1; height: 5px; background: var(--panel2); border-radius: 999px; overflow: hidden; max-width: 120px; }
.tier-bar span { display: block; height: 100%; background: var(--accent2); }

.node-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.tnode {
  width: 86px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--panel); padding: 8px 4px; text-align: center;
  position: relative; transition: transform .12s, box-shadow .2s, opacity .3s;
}
.tnode:active { transform: scale(.94); }
.tnode .temoji { font-size: 26px; line-height: 1.1; }
.tnode .tname { font-size: 9.5px; margin-top: 3px; min-height: 22px; display: flex; align-items: center; justify-content: center; }
.tnode .trecipe { font-size: 11px; margin-top: 2px; color: var(--muted); min-height: 14px; }

.tnode.discovered { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(176,123,255,.25); }
.tnode.discovered .tname { color: var(--ink); }
.tnode.locked { opacity: .85; }
.tnode.locked .temoji { filter: grayscale(1) brightness(.5); }
.tnode.locked .tname { color: var(--muted); }
.tnode.sealed { opacity: .3; filter: grayscale(.8); }
.tnode.sealed .temoji { filter: grayscale(1) brightness(.35); }
.tnode.bindable {
  border-color: var(--gold);
  animation: nodePulse 1.5s ease-in-out infinite;
}
@keyframes nodePulse {
  0%,100% { box-shadow: 0 0 0 1px rgba(255,215,106,.4); }
  50% { box-shadow: 0 0 14px rgba(255,215,106,.7); }
}
.tnode .lock-ico { position: absolute; top: 4px; right: 6px; font-size: 11px; opacity: .7; }
.tnode.justUnlocked { animation: unlockPop .8s cubic-bezier(.2,1.6,.4,1); }
@keyframes unlockPop { 0%{ transform: scale(.4); opacity:0;} 60%{transform: scale(1.12);} 100%{transform: scale(1);} }

.region-seal {
  display: flex; align-items: center; gap: 8px; margin: 0 4px 8px;
  font-size: 11px; color: var(--gold);
  background: rgba(255,215,106,.08); border: 1px dashed rgba(255,215,106,.4);
  border-radius: 10px; padding: 6px 10px;
}
.region-unfurl { animation: unfurl .9s ease; }
@keyframes unfurl { from { opacity:0; transform: scaleY(.6); } to { opacity:1; transform: none; } }

/* ===================== ACTS ===================== */
.acts-list { display: flex; flex-direction: column; gap: 12px; }
.act-card {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); padding: 14px; position: relative; overflow: hidden;
}
.act-card.current { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(255,215,106,.3); }
.act-card.locked { opacity: .55; }
.act-card.done::after { content: "✓ COMPLETE"; position: absolute; top: 10px; right: 12px; font-size: 10px; font-weight: 800; color: var(--good); letter-spacing: 1px; }
.act-card__no { font-size: 11px; color: var(--accent2); letter-spacing: 2px; font-weight: 800; }
.act-card__title { font-size: 17px; margin: 2px 0 6px; }
.act-card__desc { font-size: 13px; color: var(--muted); line-height: 1.5; margin: 0 0 10px; }
.act-card__obj { font-size: 12px; color: var(--gold); display: flex; align-items: center; gap: 6px; }

/* ===================== ACHIEVEMENTS ===================== */
.achv-list { display: flex; flex-direction: column; gap: 10px; }
.achv {
  display: flex; gap: 12px; align-items: center;
  border: 1px solid var(--line); border-radius: 14px; background: var(--panel); padding: 12px;
}
.achv.earned { border-color: var(--good); }
.achv.locked { opacity: .55; }
.achv__ico { font-size: 28px; width: 44px; text-align: center; }
.achv.locked .achv__ico { filter: grayscale(1); }
.achv__body { flex: 1; }
.achv__name { font-weight: 700; font-size: 14px; }
.achv__name .check { color: var(--good); }
.achv__desc { font-size: 12px; color: var(--muted); }
.achv__bonus { font-size: 11px; color: var(--accent2); margin-top: 3px; }

/* ===================== BOTTOM NAV ===================== */
.bottom-nav {
  display: flex; border-top: 1px solid var(--line);
  background: linear-gradient(0deg, rgba(27,24,56,.98), rgba(27,24,56,.8));
  padding-bottom: var(--safe-b);
}
.nav-btn {
  flex: 1; min-height: 56px; border: none; background: transparent;
  color: var(--muted); font-size: 11px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  transition: color .2s, transform .1s;
}
.nav-btn .nav-ico { font-size: 20px; transition: transform .2s; }
.nav-btn--active { color: var(--ink); }
.nav-btn--active .nav-ico { transform: translateY(-2px) scale(1.15); }
.nav-btn:active { transform: scale(.92); }

/* ===================== OVERLAYS ===================== */
.overlay {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center; padding: 20px;
  background: rgba(6,5,16,.78); backdrop-filter: blur(4px);
  animation: fadeIn .2s ease;
}
.overlay[hidden] { display: none; }

.story-card, .discovery-card, .detail-card, .menu-card {
  width: 100%; max-width: 380px; border-radius: 20px;
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid var(--line); box-shadow: var(--shadow); padding: 22px;
  position: relative;
}

/* story */
.story-card { text-align: left; animation: cardRise .35s cubic-bezier(.2,1.2,.4,1); }
@keyframes cardRise { from { transform: translateY(20px); opacity: 0;} to { transform: none; opacity:1;} }
.story-card__speaker { font-size: 11px; letter-spacing: 2px; color: var(--accent2); font-weight: 800; margin-bottom: 10px; }
.story-card__text { font-size: 16px; line-height: 1.6; color: var(--ink); margin: 0 0 18px; min-height: 64px; }
.story-card__footer { display: flex; justify-content: space-between; align-items: center; }

/* discovery */
.discovery-card { text-align: center; animation: discoveryRise .5s cubic-bezier(.2,1.4,.4,1); }
@keyframes discoveryRise { from{ transform: scale(.6) translateY(30px); opacity:0;} to { transform:none; opacity:1;} }
.discovery-card__eyebrow { font-size: 11px; letter-spacing: 3px; font-weight: 800; color: var(--gold); }
.discovery-card__art { font-size: 84px; line-height: 1; margin: 12px 0 6px; animation: floaty 2.4s ease-in-out infinite; filter: drop-shadow(0 6px 16px rgba(176,123,255,.6)); }
@keyframes floaty { 0%,100%{ transform: translateY(0);} 50%{ transform: translateY(-8px);} }
.discovery-card__name { margin: 0 0 10px; font-size: 24px; }
.discovery-card__meta { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-bottom: 12px; }
.discovery-card__meta .chip {
  font-size: 11px; padding: 4px 10px; border-radius: 999px;
  background: var(--panel2); border: 1px solid var(--line); color: var(--muted);
}
.discovery-card__lore { font-size: 13px; color: var(--muted); font-style: italic; line-height: 1.5; margin: 0 0 18px; }

/* detail */
.detail-card { text-align: center; }
.detail-card__art { font-size: 64px; margin: 6px 0; }
.detail-card__name { margin: 0 0 8px; font-size: 22px; }
.detail-card__meta { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-bottom: 12px; }
.detail-card__meta .chip { font-size: 11px; padding: 4px 10px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); }
.detail-card__lore { font-size: 13px; color: var(--muted); font-style: italic; line-height: 1.5; }
.detail-card__recipe, .detail-card__children { margin-top: 14px; font-size: 12px; color: var(--muted); }
.detail-card__recipe .recipe-row, .detail-card__children .child-row {
  display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; margin-top: 6px;
}
.mini-creature { display: inline-flex; flex-direction: column; align-items: center; font-size: 10px; }
.mini-creature .me { font-size: 24px; }
.detail-close { position: absolute; top: 10px; right: 10px; }

/* menu */
.menu-card { text-align: center; }
.menu-card h2 { margin: 0 0 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; background-clip: text; color: transparent; letter-spacing: 2px; }
.menu-card__tag { font-size: 13px; color: var(--muted); margin: 0 0 18px; }
.menu-card__credit { font-size: 11px; color: var(--muted); margin: 16px 0 0; line-height: 1.5; }

/* buttons */
.primary-btn {
  min-height: 48px; padding: 0 22px; border: none; border-radius: 12px; font-weight: 800; font-size: 15px;
  color: #190a2e; background: linear-gradient(90deg, var(--gold), #ffb14d);
  box-shadow: 0 6px 18px rgba(255,215,106,.35); transition: transform .12s;
}
.primary-btn:active { transform: scale(.94); }
.ghost-btn {
  min-height: 44px; padding: 0 18px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel2); color: var(--ink); font-weight: 600; font-size: 14px;
}
.danger-btn {
  min-height: 44px; padding: 0 18px; border: 1px solid var(--bad); border-radius: 12px;
  background: rgba(255,123,156,.1); color: var(--bad); font-weight: 700; font-size: 14px;
}
.full { width: 100%; margin-top: 10px; }

/* ===================== TOASTS ===================== */
.toast-stack {
  position: fixed; left: 0; right: 0; bottom: calc(72px + var(--safe-b));
  z-index: 90; display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none; padding: 0 16px;
}
.toast {
  max-width: 420px; width: 100%;
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(90deg, var(--panel2), var(--panel));
  border: 1px solid var(--gold); border-radius: 14px; padding: 10px 14px;
  box-shadow: var(--shadow); animation: toastIn .4s cubic-bezier(.2,1.4,.4,1);
}
.toast.out { animation: toastOut .4s ease forwards; }
@keyframes toastIn { from{ transform: translateY(20px); opacity:0;} to{ transform:none; opacity:1;} }
@keyframes toastOut { to{ transform: translateY(20px); opacity:0;} }
.toast__ico { font-size: 24px; }
.toast__body { flex: 1; }
.toast__title { font-weight: 800; font-size: 13px; color: var(--gold); }
.toast__sub { font-size: 11px; color: var(--muted); }

/* ===================== DRAG LAYER ===================== */
.drag-layer { position: fixed; inset: 0; z-index: 70; pointer-events: none; }
.drag-ghost {
  position: absolute; width: 80px; height: 80px; border-radius: 16px;
  background: var(--panel2); border: 2px solid var(--accent2);
  display: grid; place-items: center; font-size: 34px;
  box-shadow: 0 12px 30px rgba(0,0,0,.5); transform: translate(-50%,-50%) scale(1.1);
  transition: transform .08s;
}

/* screen flash on discovery */
.flash {
  position: fixed; inset: 0; z-index: 75; pointer-events: none;
  background: radial-gradient(circle at 50% 45%, rgba(255,255,255,.9), rgba(176,123,255,.2) 40%, transparent 70%);
  animation: flashAnim .5s ease forwards;
}
@keyframes flashAnim { from{ opacity: .9;} to{ opacity: 0;} }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ============================================================
   COMBAT / SURVIVAL UI (merge & survive rework)
   ============================================================ */
.stat-pill {
  display: flex; align-items: center; gap: 4px; min-height: 40px; padding: 0 10px;
  border: 1px solid var(--line); background: var(--panel2); border-radius: 999px;
  font-weight: 800; font-size: 14px; font-variant-numeric: tabular-nums;
}
.stat-pill__icon { font-size: 13px; }
#nexusPill { border-color: rgba(255,123,156,.5); }
#chargePill { border-color: rgba(255,215,106,.5); }
.stat-pill.flash-good { animation: pillGood .5s ease; }
.stat-pill.flash-bad { animation: pillBad .5s ease; }
@keyframes pillGood { 50% { background: rgba(107,240,168,.35); transform: scale(1.12); } }
@keyframes pillBad { 50% { background: rgba(255,123,156,.4); transform: scale(1.12); } }

/* battlefield */
.battlefield {
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  background: radial-gradient(120% 80% at 50% 0%, rgba(255,123,156,.12), transparent 55%),
              radial-gradient(120% 80% at 50% 100%, rgba(110,231,255,.12), transparent 55%),
              var(--panel);
}
.battlefield.shake { animation: shake .3s; }
.bf-side { padding: 8px 10px; min-height: 96px; }
.bf-enemy { background: linear-gradient(180deg, rgba(255,123,156,.08), transparent); }
.bf-player { background: linear-gradient(0deg, rgba(110,231,255,.08), transparent); }
.bf-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); margin: 2px 2px 6px; }
.bf-head b { color: var(--ink); }
.bf-meta { font-size: 11px; color: var(--muted); }
.wave-kind { color: var(--bad); font-weight: 800; font-size: 10px; letter-spacing: 1px; }
.bf-divider { display: flex; align-items: center; justify-content: center; position: relative; height: 26px; }
.bf-divider::before { content: ""; position: absolute; left: 12px; right: 12px; height: 1px; background: var(--line); }
.bf-divider span {
  position: relative; z-index: 1; font-size: 11px; font-weight: 800; letter-spacing: 2px;
  color: var(--gold); background: var(--panel); padding: 2px 12px; border-radius: 999px; border: 1px solid var(--line);
}
.bf-divider span.fight { color: var(--bad); border-color: var(--bad); animation: bindReady 1s infinite; }

.unit-row { display: flex; gap: 6px; overflow-x: auto; min-height: 70px; align-items: stretch; padding-bottom: 2px; }
.unit-row.empty::after { content: "— no units —"; color: var(--muted); font-size: 12px; align-self: center; margin: 0 auto; }

/* battle unit card */
.ucard {
  flex: 0 0 auto; width: 58px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel2); padding: 5px 3px 4px; text-align: center; position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  transition: transform .12s, box-shadow .2s, opacity .3s;
}
.ucard .ue { font-size: 24px; line-height: 1; }
.ucard .un { font-size: 8px; color: var(--muted); max-width: 52px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ucard .uatk { font-size: 9px; color: var(--gold); font-weight: 700; }
.ucard .hp-bar { width: 100%; height: 5px; border-radius: 999px; background: #3a2030; overflow: hidden; margin-top: 1px; }
.ucard .hp-fill { display: block; height: 100%; background: linear-gradient(90deg, var(--good), #3bd17f); transition: width .35s ease; }
.bf-enemy .ucard .hp-fill { background: linear-gradient(90deg, var(--bad), #ff5277); }
.ucard.aff-Ember   { border-color: rgba(255,122,77,.5); }
.ucard.aff-Tide    { border-color: rgba(77,184,255,.5); }
.ucard.aff-Verdant { border-color: rgba(107,220,122,.5); }
.ucard.aff-Gale    { border-color: rgba(205,214,255,.5); }
.ucard.aff-Void    { border-color: rgba(176,123,255,.6); }
.ucard.hit { animation: hitFlash .3s; }
@keyframes hitFlash { 0%,100%{ transform: none; } 30% { transform: translateX(3px) scale(1.06); box-shadow: 0 0 14px rgba(255,255,255,.6); } }
.ucard.boss { width: 78px; box-shadow: 0 0 0 1px var(--gold); }
.ucard.boss .ue { font-size: 34px; }
.dmg-float {
  position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
  font-size: 13px; font-weight: 900; color: #fff; text-shadow: 0 1px 4px #000;
  animation: dmgFloat .7s ease forwards; pointer-events: none; z-index: 2;
}
.dmg-float.crit { color: var(--gold); font-size: 15px; }
@keyframes dmgFloat { to { transform: translate(-50%,-22px); opacity: 0; } }

/* compact merge altar */
.merge-altar {
  margin-top: 12px; background: radial-gradient(120% 120% at 50% 0%, rgba(176,123,255,.16), transparent 70%), var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-align: center;
}
.merge-altar .altar__slots { display: flex; align-items: center; justify-content: center; gap: 10px; }
.merge-altar .slot { width: 62px; height: 62px; border-radius: 14px; }
.merge-altar .slot__placeholder { font-size: 22px; }
.merge-go {
  min-height: 46px; padding: 0 16px; border: none; border-radius: 12px; font-weight: 800; letter-spacing: 1px;
  color: #190a2e; background: linear-gradient(90deg, #4a4470, #5a5488); opacity: .5; transition: transform .12s, opacity .2s, box-shadow .2s;
}
.merge-go:not(:disabled) { opacity: 1; background: linear-gradient(90deg, var(--accent), var(--accent2)); box-shadow: 0 0 16px rgba(176,123,255,.5); }
.merge-go:not(:disabled):active { transform: scale(.94); }

/* deployed-state on reserve chip */
.chip-creature .deploy-hint { position: absolute; bottom: -6px; left: 50%; transform: translateX(-50%);
  font-size: 8px; color: var(--accent2); background: var(--bg); padding: 0 4px; border-radius: 6px; opacity: 0; }
.chip-creature:active .deploy-hint { opacity: 1; }
.chip-creature .uatk { font-size: 9px; color: var(--gold); font-weight: 700; }

/* army card recall affordance */
#armyRow .ucard { cursor: pointer; }
#armyRow .ucard::after { content: "↩"; position: absolute; top: 1px; right: 3px; font-size: 9px; color: var(--muted); }

/* result + gameover overlays */
.result-card { width: 100%; max-width: 360px; border-radius: 20px; text-align: center;
  background: linear-gradient(180deg, var(--panel2), var(--panel)); border: 1px solid var(--line);
  box-shadow: var(--shadow); padding: 26px 22px; animation: discoveryRise .4s cubic-bezier(.2,1.3,.4,1); }
.result-card__big { font-size: 30px; font-weight: 900; letter-spacing: 2px;
  background: linear-gradient(90deg, var(--good), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.result-card__big.lose { background: linear-gradient(90deg, var(--bad), #ff9d6a); -webkit-background-clip: text; background-clip: text; color: transparent; }
.result-card__text { font-size: 14px; color: var(--ink); line-height: 1.5; margin: 12px 0; }
.result-card__rewards { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 18px; }
.result-card__rewards .chip { font-size: 12px; padding: 6px 12px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); color: var(--accent2); }

/* how-to in menu */
.how-to { text-align: left; margin: 14px 0; }
.how-to p { font-size: 12.5px; color: var(--muted); line-height: 1.5; margin: 6px 0; }
.how-to b { color: var(--ink); }

/* ============================================================
   STRATEGIC LAYER (roster / synergy / telegraph rework)
   ============================================================ */
#tokenPill { border-color: rgba(176,123,255,.6); }

/* enemy telegraph */
.threat-label { font-weight: 800; font-size: 13px; color: var(--bad); letter-spacing: .5px; }
.threat-label.boss { color: var(--gold); }
.threat-hint {
  font-size: 11px; color: var(--muted); margin: 0 2px 6px;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.threat-hint .weak-to {
  background: rgba(107,240,168,.14); border: 1px solid rgba(107,240,168,.5);
  color: var(--good); border-radius: 999px; padding: 2px 8px; font-weight: 700;
}
.threat-hint .arch-tag {
  background: rgba(255,123,156,.14); border: 1px solid rgba(255,123,156,.5);
  color: var(--bad); border-radius: 999px; padding: 2px 8px; font-weight: 700; letter-spacing: .5px;
}

/* synergy bar */
.synergy-bar { display: flex; gap: 6px; flex-wrap: wrap; min-height: 22px; margin: 2px 0 4px; }
.synergy-chip {
  font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--accent2); background: rgba(110,231,255,.12); color: var(--accent2);
}
.synergy-chip.strong { border-color: var(--gold); background: rgba(255,215,106,.16); color: var(--gold); }
.synergy-hint { font-size: 10px; color: var(--muted); align-self: center; }

/* roster chip fielded state */
.chip-creature.fielded { border-color: var(--good); box-shadow: 0 0 0 2px rgba(107,240,168,.5); }
.chip-creature.fielded::after {
  content: "✓ FIELDED"; position: absolute; top: -7px; left: 50%; transform: translateX(-50%);
  font-size: 7px; font-weight: 800; letter-spacing: .5px; color: #0c1a12;
  background: var(--good); padding: 1px 5px; border-radius: 6px;
}
.chip-creature.cant-field { opacity: .55; }
.chip-creature .aff-dot { position: absolute; top: 4px; left: 5px; width: 8px; height: 8px; border-radius: 50%; }
.aff-dot.Ember { background: var(--ember); } .aff-dot.Tide { background: var(--tide); }
.aff-dot.Verdant { background: var(--verdant); } .aff-dot.Gale { background: var(--gale); }
.aff-dot.Void { background: var(--void); }

/* ============================================================
   v4 — decluttered UI, obvious affinities, cleavers
   ============================================================ */
.build-controls { display: flex; gap: 8px; margin-top: 12px; }
.build-controls .bind-btn { margin-top: 0; width: auto; flex: 1; }
.bind-open {
  min-height: 52px; padding: 0 16px; border-radius: 14px; font-weight: 800; font-size: 14px;
  border: 1px solid var(--accent); background: rgba(176,123,255,.16); color: var(--accent2);
  display: flex; align-items: center; gap: 4px; white-space: nowrap;
}
.bind-open:active { transform: scale(.95); }
.bind-open:disabled { opacity: .45; }
.bind-open #bindCountLbl { color: var(--gold); }

/* during battle: show ONLY the battlefield */
#screen-defense.in-battle .build-only { display: none !important; }
#screen-defense.in-battle .battlefield { animation: fadeIn .2s ease; }
#screen-defense.in-battle .unit-row { min-height: 86px; }
#screen-defense.in-battle .ucard { width: 66px; }
#screen-defense.in-battle .ucard .ue { font-size: 30px; }

/* affinity badge — make every unit's affinity obvious */
.ucard { padding-top: 16px; }
.aff-badge {
  position: absolute; top: -7px; left: -6px; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px; line-height: 1;
  border: 2px solid var(--bg); box-shadow: 0 1px 4px rgba(0,0,0,.5); z-index: 2;
}
.aff-badge.Ember { background: var(--ember); } .aff-badge.Tide { background: var(--tide); }
.aff-badge.Verdant { background: var(--verdant); } .aff-badge.Gale { background: var(--gale); }
.aff-badge.Void { background: var(--void); }
.bf-enemy .ucard { border-width: 2px; }
.bf-enemy .ucard.aff-Ember   { border-color: var(--ember);   background: linear-gradient(180deg, rgba(255,122,77,.20), var(--panel2)); }
.bf-enemy .ucard.aff-Tide    { border-color: var(--tide);    background: linear-gradient(180deg, rgba(77,184,255,.20), var(--panel2)); }
.bf-enemy .ucard.aff-Verdant { border-color: var(--verdant); background: linear-gradient(180deg, rgba(107,220,122,.20), var(--panel2)); }
.bf-enemy .ucard.aff-Gale    { border-color: var(--gale);    background: linear-gradient(180deg, rgba(205,214,255,.20), var(--panel2)); }
.bf-enemy .ucard.aff-Void    { border-color: var(--void);    background: linear-gradient(180deg, rgba(176,123,255,.22), var(--panel2)); }
.ucard .un { font-weight: 600; }

/* cleaver marker (hits the whole line; fragile) */
.ucard.cleave { box-shadow: 0 0 0 2px var(--bad), 0 0 12px rgba(255,123,156,.5); }
.cleave-badge {
  position: absolute; top: -7px; right: -6px; font-size: 12px; z-index: 2;
  background: var(--bad); color: #2a0a12; border-radius: 50%; width: 20px; height: 20px;
  display: grid; place-items: center; border: 2px solid var(--bg); animation: glowPulse 1.2s infinite;
}
.ucard.struck-all { animation: hitFlash .3s; }

/* bind overlay panel */
.bind-card {
  width: 100%; max-width: 420px; max-height: 86vh; overflow-y: auto;
  border-radius: 20px; background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid var(--line); box-shadow: var(--shadow); padding: 20px; position: relative;
  animation: cardRise .3s cubic-bezier(.2,1.2,.4,1);
}
.bind-card__title { margin: 0 0 4px; font-size: 20px; }
.bind-card__sub { font-size: 12px; color: var(--muted); margin: 0 0 14px; line-height: 1.5; }
.bind-card .merge-altar { margin-top: 0; }
.bind-roster-head { font-size: 13px; font-weight: 700; margin: 14px 0 8px; }
.bind-roster .chip-creature.slotted { border-color: var(--accent2); box-shadow: 0 0 0 2px rgba(110,231,255,.5); }

/* ============================================================
   v5 — inline merge dock (always visible, no menu)
   ============================================================ */
#mergeAltar.merge-altar { margin-top: 10px; padding: 10px 12px; }
#mergeAltar .altar__slots { gap: 8px; flex-wrap: wrap; }
#mergeAltar .slot { width: 54px; height: 54px; border-radius: 12px; }
#mergeAltar .slot__placeholder { font-size: 20px; }
#mergeAltar .altar__plus { font-size: 18px; }
#mergeAltar .merge-go { min-height: 44px; margin-left: auto; }
#mergeAltar .bind-flavor { margin-top: 8px; }
.slot.dropTarget { border-color: var(--accent2) !important; box-shadow: 0 0 18px rgba(110,231,255,.6); transform: scale(1.1); }
/* a chip you can bind right now (incl. with its own kind) gently pulses */
.chip-creature.unexplored { box-shadow: 0 0 0 1px var(--gold), 0 0 10px rgba(255,215,106,.35); }

/* ============================================================
   v6 — readable combat: attacker / target / hit markers
   ============================================================ */
/* WIND-UP: an attacker lifts + glows and shows a ⚔ */
.ucard.attacking { box-shadow: 0 0 0 2px var(--gold), 0 0 14px rgba(255,215,106,.55); z-index: 3; }
.bf-player .ucard.attacking { transform: translateY(-7px) scale(1.06); }
.bf-enemy  .ucard.attacking { transform: translateY(7px) scale(1.06); }
.ucard .atk-badge {
  position: absolute; top: -8px; right: -7px; z-index: 4; font-size: 11px; font-weight: 900;
  width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center;
  background: var(--gold); color: #2a1a00; border: 2px solid var(--bg);
}
/* a target about to be struck shows a crosshair ring */
.ucard.targeted { box-shadow: 0 0 0 2px var(--bad); }
.ucard.targeted::after {
  content: "✕"; position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 22px; color: rgba(255,123,156,.85); font-weight: 900; pointer-events: none; animation: glowPulse .6s ease-in-out infinite;
}
/* IMPACT: a stronger, longer red flash + a big floating damage number */
.ucard.hit { animation: hitStruck .55s ease; }
@keyframes hitStruck {
  0% { transform: scale(1); box-shadow: 0 0 0 3px var(--bad), 0 0 18px rgba(255,123,156,.8); }
  35% { transform: scale(1.12) translateX(3px); box-shadow: 0 0 0 3px #fff, 0 0 22px rgba(255,255,255,.9); }
  100% { transform: scale(1); box-shadow: none; }
}
.ucard .dmg-float {
  position: absolute; top: -16px; left: 50%; transform: translateX(-50%);
  font-size: 20px; font-weight: 900; color: #fff;
  text-shadow: 0 0 6px #000, 0 2px 3px #000; z-index: 6; pointer-events: none;
  animation: dmgRise .9s ease-out forwards;
}
.ucard .dmg-float.crit { color: var(--gold); font-size: 24px; }
@keyframes dmgRise { 0% { opacity: 0; transform: translate(-50%, 4px) scale(.6); } 20% { opacity: 1; transform: translate(-50%,-6px) scale(1.1); } 100% { opacity: 0; transform: translate(-50%,-30px) scale(1); } }

/* primitives strip: a touch bigger so they're easy drag targets */
#essenceStrip .chip-creature { min-width: 76px; }
#essenceStrip .chip-creature .emoji { font-size: 30px; }
