:root {
  --bg: #0b0714;
  --navy: #12102a;
  --violet: #2a1848;
  --dusk: #4a1c6e;
  --gold: #d4af37;
  --gold-bright: #f0d78c;
  --gold-dim: #8a7020;
  --ember: #ff6b35;
  --tide: #2a9d8f;
  --gale: #8ecae6;
  --radiant: #f3e5c1;
  --umbral: #7b2cbf;
  --hp: #c23b4a;
  --hp-fill: #e85a6a;
  --atb: #5ec8d8;
  --text: #f4efe6;
  --muted: #b8a99a;
  --safe-t: max(12px, env(safe-area-inset-top));
  --safe-b: max(14px, env(safe-area-inset-bottom));
  --safe-x: max(14px, env(safe-area-inset-left), env(safe-area-inset-right));
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { background: #07050e; }
body {
  font-family: Nunito, "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 800px at 50% 0%, #1a1030 0%, #07050e 55%);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#stage {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#device {
  position: relative;
  width: min(100vw, 390px);
  height: min(100vh, 844px);
  background: var(--bg);
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(212, 175, 55, 0.18);
}

@media (min-width: 520px) {
  html[data-shell="desktop"] #device {
    width: 390px;
    height: 844px;
    border-radius: 34px;
    border: 3px solid #c9a227;
    box-shadow:
      0 0 0 8px #16101c,
      0 28px 80px rgba(0, 0, 0, 0.65),
      0 0 70px rgba(180, 120, 40, 0.12);
  }
}

#app, .screen { width: 100%; height: 100%; }
.screen {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

h1, h2, h3, .wordmark, .top-title, .binder-name, .d-name, .rc-name, .uc-name {
  font-family: Cinzel, Palatino, "Times New Roman", serif;
  font-weight: 700;
  letter-spacing: 0.04em;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  background: none;
}
button:disabled { opacity: 0.45; cursor: default; }

/* Filigree corners */
.c {
  position: absolute;
  width: 11px;
  height: 11px;
  pointer-events: none;
  border: 1.5px solid var(--gold);
  z-index: 2;
}
.c.tl { top: 4px; left: 4px; border-right: 0; border-bottom: 0; }
.c.tr { top: 4px; right: 4px; border-left: 0; border-bottom: 0; }
.c.bl { bottom: 4px; left: 4px; border-right: 0; border-top: 0; }
.c.br { bottom: 4px; right: 4px; border-left: 0; border-top: 0; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-t) + 6px) var(--safe-x) 8px;
  z-index: 5;
  background: linear-gradient(180deg, rgba(7, 5, 14, 0.82), rgba(7, 5, 14, 0));
}
.binder-name, .top-title {
  font-size: 15px;
  color: var(--gold-bright);
  margin: 0;
  flex: 1;
  min-width: 0;
}
.top-spacer { flex: 1; }
.icon-btn {
  min-width: 48px;
  min-height: 48px;
  font-size: 28px;
  line-height: 1;
  color: var(--gold-bright);
}
.currencies { display: flex; gap: 6px; flex-shrink: 0; }
.cur {
  font-size: 11px;
  font-weight: 700;
  padding: 6px 8px;
  border-radius: 999px;
  background: rgba(18, 16, 42, 0.75);
  border: 1px solid rgba(212, 175, 55, 0.28);
  white-space: nowrap;
}
.cur.dust { color: var(--gold-bright); }
.cur.shard { color: #c9a6ff; }
.cur.stam { color: #8fd4c8; }

/* Buttons */
.gold-btn {
  min-height: 52px;
  padding: 10px 18px;
  border-radius: 12px;
  background: linear-gradient(180deg, #f0d78c, #b8922a);
  color: #1a1206;
  font-family: Cinzel, Palatino, serif;
  font-weight: 700;
  letter-spacing: 0.06em;
  box-shadow: 0 4px 0 #6d5410, 0 8px 20px rgba(0, 0, 0, 0.35);
  border: 1px solid #ffe7a3;
}
.gold-btn.alt {
  background: linear-gradient(180deg, #3d265c, #241436);
  color: var(--gold-bright);
  border-color: var(--gold-dim);
  box-shadow: 0 4px 0 #140c1e, 0 8px 20px rgba(0, 0, 0, 0.35);
}
.gold-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #6d5410; }
.gold-btn small { display: block; font-family: Nunito, sans-serif; font-weight: 600; letter-spacing: 0; opacity: 0.8; }

.toast {
  position: absolute;
  left: 50%;
  bottom: 88px;
  transform: translate(-50%, 12px);
  background: rgba(18, 16, 42, 0.94);
  border: 1px solid var(--gold-dim);
  color: var(--gold-bright);
  padding: 10px 16px;
  border-radius: 10px;
  opacity: 0;
  transition: 0.25s;
  z-index: 20;
  font-size: 14px;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Portraits */
.port {
  position: relative;
  overflow: hidden;
  background: linear-gradient(160deg, var(--violet), #0d0a16);
  border: 1px solid rgba(212, 175, 55, 0.35);
}
.port.el-ember { background: linear-gradient(160deg, #5a2010, #1a0a08); }
.port.el-tide { background: linear-gradient(160deg, #0d3b40, #071218); }
.port.el-gale { background: linear-gradient(160deg, #1c3344, #0b1016); }
.port.el-radiant { background: linear-gradient(160deg, #4a3a18, #1a140c); }
.port.el-umbral { background: linear-gradient(160deg, #2a1450, #0c0816); }
.port img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 18%;
  z-index: 1;
}
.port img.miss { display: none; }
.port-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: Cinzel, serif;
  font-size: 28px;
  color: var(--gold-bright);
  opacity: 0.75;
}
.port.sm { width: 44px; height: 44px; border-radius: 8px; flex-shrink: 0; }
.port.sm .port-fallback { font-size: 16px; }
.port.fight { width: 58px; height: 58px; border-radius: 8px; flex-shrink: 0; }
.port.wide { width: 100%; height: 88px; }

.stars { color: var(--gold); letter-spacing: 1px; font-size: 12px; }
.stars.r5 { color: #ffe7a3; text-shadow: 0 0 8px rgba(240, 215, 140, 0.6); }
.el-pip {
  display: inline-block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--el) 22%, #0b0714);
  color: var(--el);
  border: 1px solid color-mix(in srgb, var(--el) 50%, transparent);
}

/* ===== TITLE ===== */
.title-screen { background: #0b0714; }
.title-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 42%;
  pointer-events: none;
}
.title-art.miss { display: none; }
.title-veil {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(11, 7, 20, 0.2) 20%, rgba(11, 7, 20, 0.55) 55%, #0b0714 92%);
  pointer-events: none;
}
.title-content {
  position: relative;
  z-index: 2;
  margin-top: auto;
  padding: 0 var(--safe-x) 8px;
  text-align: center;
}
.title-kicker, .hub-kicker, .lore-kicker {
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 0 6px;
}
.wordmark {
  margin: 0;
  font-size: 40px;
  letter-spacing: 0.18em;
  background: linear-gradient(180deg, #fff6d2, #d4af37);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: none;
  filter: drop-shadow(0 2px 12px rgba(212, 175, 55, 0.35));
}
.gold-rule {
  width: 88px;
  height: 2px;
  margin: 10px auto;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}
.title-sub { margin: 0; color: var(--muted); font-size: 14px; }
.tap-begin {
  position: relative;
  z-index: 2;
  margin: 22px var(--safe-x) 8px;
  min-height: 52px;
  border: 1px solid var(--gold);
  color: var(--gold-bright);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-size: 13px;
  font-family: Cinzel, serif;
  animation: pulse 1.8s ease-in-out infinite;
}
.quiet-reset {
  position: relative;
  z-index: 3;
  margin: 0 auto calc(var(--safe-b) + 8px);
  font-size: 12px;
  color: var(--muted);
  min-height: 40px;
  opacity: 0.7;
}
@keyframes pulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; text-shadow: 0 0 12px rgba(240, 215, 140, 0.5); }
}

/* ===== HUB ===== */
.hub-screen { background: #120c1c; }
.hub-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 60%;
}
.hub-art.miss { display: none; }
.hub-veil {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(11, 7, 20, 0.45) 0%, rgba(11, 7, 20, 0.15) 30%, rgba(11, 7, 20, 0.72) 68%, #0b0714 100%);
}
.hub-hero { position: relative; z-index: 2; padding: 8px var(--safe-x) 12px; }
.hub-hero h2 { margin: 0; font-size: 26px; color: var(--gold-bright); }
.districts {
  position: relative;
  z-index: 2;
  margin-top: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 8px var(--safe-x) calc(var(--safe-b) + 12px);
}
.district {
  position: relative;
  min-height: 78px;
  padding: 12px 12px 12px 10px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(180deg, rgba(30, 18, 52, 0.78), rgba(12, 8, 22, 0.88));
  border: 1px solid rgba(212, 175, 55, 0.38);
  border-radius: 14px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}
.district.story { grid-column: 1 / -1; min-height: 88px; }
.district .d-ico { font-size: 22px; width: 36px; text-align: center; }
.d-name { display: block; font-size: 16px; color: var(--gold-bright); }
.d-sub { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.district.soon { opacity: 0.55; }
.soon-badge {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  border: 1px solid var(--gold-dim);
  padding: 2px 6px;
  border-radius: 999px;
}
.district:active:not(.soon) { transform: scale(0.98); }

/* ===== COLLECTION ===== */
.collection-screen {
  background: radial-gradient(800px 400px at 50% 0%, #24143c, #0b0714 60%);
}
.col-count {
  margin: 0;
  padding: 0 var(--safe-x) 8px;
  color: var(--muted);
  font-size: 12px;
}
.unit-grid {
  flex: 1;
  overflow: auto;
  padding: 0 var(--safe-x) calc(var(--safe-b) + 12px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.unit-card {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(212, 175, 55, 0.32);
  background: #14101f;
}
.unit-card.r5 { border-color: #f0d78c; box-shadow: 0 0 16px rgba(212, 175, 55, 0.2); }
.unit-card .port { height: 124px; border: 0; border-bottom: 1px solid rgba(212, 175, 55, 0.2); }
.uc-body { padding: 8px 10px 10px; }
.uc-name { font-size: 14px; }
.uc-title { font-size: 10px; color: var(--muted); margin: 2px 0 6px; }
.uc-role { font-size: 10px; color: var(--muted); margin-top: 4px; }

/* ===== GATE ===== */
.gate-screen {
  background:
    radial-gradient(circle at 50% 28%, rgba(90, 40, 140, 0.35), transparent 46%),
    linear-gradient(180deg, #140c22, #0b0714);
}
.gate-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 0 4px;
  min-height: 210px;
}
.gate-stage.big { flex: 1; }
.hub-screen { overflow-y: auto; }
.ritual { position: relative; width: 176px; height: 176px; }
.ritual::before {
  content: '';
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  border: 1px dashed rgba(240, 215, 140, 0.35);
}
.ritual .ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(212, 175, 55, 0.45);
  box-shadow: 0 0 28px rgba(212, 175, 55, 0.2), inset 0 0 28px rgba(90, 40, 140, 0.35);
  background: repeating-conic-gradient(from 0deg, rgba(212,175,55,0.15) 0 6deg, transparent 6deg 18deg);
}
.ritual .ring.inner { inset: 22px; border-color: rgba(201, 166, 255, 0.45); background: none; }
.ritual .sigil {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  color: var(--gold-bright);
  text-shadow: 0 0 16px rgba(240, 215, 140, 0.7);
}
.ritual.spin .outer { animation: spin 3.2s linear infinite; }
.ritual.spin .inner { animation: spin 2.2s linear infinite reverse; }
.ritual.spin .sigil { animation: pulse 0.9s ease-in-out infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.gate-flavor { color: var(--muted); font-size: 13px; }
.gate-flavor.pulse { animation: pulse 1s infinite; color: var(--gold-bright); }

.rates-card {
  position: relative;
  margin: 0 var(--safe-x) 10px;
  padding: 12px 14px 10px;
  border: 1px solid rgba(212, 175, 55, 0.3);
  border-radius: 12px;
  background: rgba(18, 16, 42, 0.7);
}
.rates-row { display: flex; justify-content: space-between; font-size: 13px; padding: 3px 0; }
.rates-row b { color: var(--gold-bright); }
.pity-line { margin-top: 6px; font-size: 11px; color: var(--muted); }

.pay-toggle {
  display: flex;
  gap: 8px;
  padding: 0 var(--safe-x);
}
.tog {
  flex: 1;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid rgba(212, 175, 55, 0.25);
  background: rgba(18, 16, 42, 0.7);
  font-size: 13px;
  font-weight: 700;
}
.tog.on { border-color: var(--gold); color: var(--gold-bright); background: rgba(60, 40, 20, 0.45); }

.summon-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 10px var(--safe-x) calc(var(--safe-b) + 12px);
}

.reveal-screen {
  background: radial-gradient(700px 360px at 50% 0%, #3a1c5c, #0b0714 62%);
}
.reveal-screen.got5 {
  background: radial-gradient(700px 360px at 50% 0%, #5a3a10, #0b0714 62%);
}
.reveal-head { text-align: center; padding: calc(var(--safe-t) + 10px) 16px 6px; }
.reveal-head h2 { margin: 0; font-size: 20px; color: var(--gold-bright); }
.reveal-grid {
  flex: 1;
  overflow: auto;
  padding: 8px var(--safe-x);
  display: grid;
  gap: 8px;
}
.reveal-grid.n1 { grid-template-columns: 1fr; }
.reveal-grid.n10 { grid-template-columns: 1fr 1fr; }
.reveal-card {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: #14101f;
  border: 1px solid rgba(212, 175, 55, 0.3);
  animation: cardIn 0.45s ease both;
}
.reveal-card.r5 {
  border-color: #f0d78c;
  box-shadow: 0 0 18px rgba(240, 215, 140, 0.35);
}
.reveal-card .port.wide { height: 80px; }
.rc-body { padding: 6px 8px 8px; }
.rc-name { font-size: 13px; }
.rc-title { font-size: 10px; color: var(--muted); margin-bottom: 4px; }
.dupe-tag, .new-tag { font-size: 10px; margin-top: 4px; }
.dupe-tag { color: var(--gold); }
.new-tag { color: #8fd4c8; }
.done-btn { margin: 8px var(--safe-x) calc(var(--safe-b) + 12px); }
@keyframes cardIn {
  from { opacity: 0; transform: translateY(16px) scale(0.92); }
  to { opacity: 1; transform: none; }
}

/* ===== STORY ===== */
.story-screen {
  background: linear-gradient(180deg, #1a1028, #0b0714);
}
.lore-card {
  position: relative;
  flex: 1;
  margin: 8px var(--safe-x) calc(var(--safe-b) + 12px);
  padding: 18px 16px 16px;
  border: 1px solid rgba(212, 175, 55, 0.35);
  border-radius: 14px;
  background: rgba(18, 16, 42, 0.78);
  overflow: auto;
}
.lore-card h2 { margin: 0 0 10px; color: var(--gold-bright); font-size: 26px; }
.lore-card p { margin: 0 0 10px; line-height: 1.5; color: #ddd4c6; font-size: 14px; }
.node {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 0 12px;
  border-top: 1px solid rgba(212, 175, 55, 0.18);
}
.node-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 10px var(--gold);
}
.node strong { display: block; }
.node em { font-style: normal; font-size: 12px; color: var(--muted); }
.story-team { display: flex; gap: 10px; margin: 8px 0 16px; }
.story-unit { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 10px; color: var(--muted); }
.fight-btn { width: 100%; }

/* ===== BATTLE ===== */
.battle-screen {
  background: #14080c;
}
.battle-head {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  z-index: 6;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(var(--safe-t) + 6px) var(--safe-x) 10px;
  font-family: Cinzel, serif;
  color: var(--gold-bright);
  font-size: 14px;
  background: linear-gradient(180deg, rgba(10, 6, 12, 0.72) 0%, rgba(10, 6, 12, 0) 100%);
  pointer-events: none;
}
.battle-head > * { pointer-events: auto; }
.auto-btn {
  min-height: 40px;
  min-width: 88px;
  padding: 0 12px;
  border: 1px solid var(--gold-dim);
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.12em;
  font-weight: 800;
  color: var(--muted);
  background: rgba(12, 8, 16, 0.55);
}
.auto-btn.on { color: #1a1206; background: var(--gold); border-color: var(--gold-bright); }

/* Circular stone plate — image already has the elevated camera */
.arena {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 70% at 50% 6%, #d47a42 0%, #7a3224 32%, #1a0c10 72%);
}
.arena-plate {
  position: absolute;
  left: 50%;
  top: 46%;
  width: 158%;
  aspect-ratio: 1792 / 1008;
  transform: translate(-50%, -50%);
  z-index: 1;
}
.arena-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
  pointer-events: none;
  filter: saturate(1.05) contrast(1.04);
}
.arena-veil {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 52%, transparent 42%, rgba(12, 6, 10, 0.22) 100%);
  z-index: 1;
}
.stage {
  position: absolute;
  inset: 0;
  z-index: 2;
}

/* Standing token — feet pinned to --x/--y on the plate */
.fighter {
  position: absolute;
  width: 92px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0;
  background: none;
  border: none;
  transform: translate(-50%, -90%) scale(var(--s, 1));
  transform-origin: 50% 90%;
  cursor: pointer;
  will-change: transform;
}
.fighter::before {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 4px;
  width: 52px;
  height: 16px;
  transform: translateX(-50%) scaleY(0.72);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.38);
  filter: blur(1px);
  z-index: 0;
  pointer-events: none;
}

.model-wrap {
  position: relative;
  z-index: 1;
  transition: transform 0.16s ease-out;
}
.model-wrap.lunging { z-index: 8; }
.fighter:has(.lunging) { z-index: 12 !important; }

.model {
  --face: 1;
  position: relative;
  width: 84px;
  height: 132px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  overflow: visible;
}
.model.ally { --face: 1; }
.model.foe,
.model.crystal { --face: -1; }
.model.ally.flip { --face: -1; }
.model.foe.flip,
.model.crystal.flip { --face: 1; }

.model-body {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  height: 118px;
  object-fit: contain;
  object-position: bottom center;
  border-radius: 0;
  pointer-events: none;
  transform-origin: center bottom;
  transform: scaleX(var(--face, 1));
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.55)) contrast(1.05) saturate(1.06);
}
.model-body.miss { display: none; }
.model .port-fallback {
  display: none;
  z-index: 0;
  bottom: 12px;
  font-size: 26px;
  pointer-events: none;
}
.model:has(.model-body.miss) .port-fallback { display: flex; }

/* Stand on the stone — hide the old gold disc */
.battle-screen .model-pedestal { display: none; }
.model-shadow {
  position: absolute;
  left: 50%;
  bottom: 2px;
  width: 46px;
  height: 10px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  filter: blur(3px);
  z-index: 0;
}

.model-face { display: none; }

.fighter:not(.dead) .model.ally .model-body {
  animation: idleBob 2.6s ease-in-out infinite;
}
.fighter[data-slot="1"] .model.ally .model-body { animation-delay: 0.55s; }
.fighter[data-slot="2"] .model.ally .model-body { animation-delay: 0.3s; }
.fighter[data-slot="3"] .model.ally .model-body { animation-delay: 0.9s; }
@keyframes idleBob {
  0%, 100% { transform: translateY(0) scaleX(var(--face, 1)); }
  50% { transform: translateY(-3px) scaleX(var(--face, 1)); }
}

.model.foe .model-body,
.model.crystal .model-body {
  height: 112px;
  margin-bottom: 6px;
}
.fighter:not(.dead) .model.foe .model-body,
.fighter:not(.dead) .model.crystal .model-body {
  animation: crystalFloat 2.8s ease-in-out infinite;
}
.fighter[data-slot="1"] .model.foe .model-body,
.fighter[data-slot="1"] .model.crystal .model-body { animation-delay: 0.7s; }
.fighter[data-slot="3"] .model.foe .model-body,
.fighter[data-slot="3"] .model.crystal .model-body { animation-delay: 1.1s; }
@keyframes crystalFloat {
  0%, 100% { transform: translateY(0) scaleX(var(--face, -1)); }
  50% { transform: translateY(-7px) scaleX(var(--face, -1)); }
}

.fighter.acting { z-index: 10 !important; }
.fighter.acting::before {
  background: rgba(240, 215, 140, 0.42);
  box-shadow: 0 0 12px 4px rgba(240, 215, 140, 0.45);
  filter: none;
}
.fighter.acting .model-body {
  filter:
    drop-shadow(0 0 6px var(--gold-bright))
    drop-shadow(0 0 14px rgba(240, 215, 140, 0.7));
}
.fighter.dead {
  opacity: 0.4;
  filter: grayscale(0.92);
  pointer-events: none;
}
.fighter.dead .model-wrap {
  transform: translateY(14px) scale(0.92);
}
.fighter.dead .model-body {
  animation: none !important;
  transform: scaleX(var(--face, 1));
}
.fighter.boss .model-body {
  filter:
    drop-shadow(0 0 6px #c9a6ff)
    drop-shadow(0 0 16px rgba(123, 44, 191, 0.7));
}
.fighter.boss.acting .model-body,
.fighter.cast .model-body {
  filter:
    drop-shadow(0 0 10px rgba(240, 215, 140, 0.95))
    drop-shadow(0 0 22px rgba(123, 44, 191, 0.5));
}
.fighter.hit .model-wrap {
  animation: hitShake 0.28s ease;
}
@keyframes hitShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); filter: brightness(2.1); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

/* Green overhead HP — SW World Arena */
.overhead {
  position: relative;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin-bottom: 2px;
  pointer-events: none;
}
.oh-row {
  display: flex;
  align-items: center;
  gap: 3px;
}
.lv-badge {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 32%, #3a3224, #16100c);
  border: 1px solid #c9a227;
  color: #f0d78c;
  font-size: 8px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
.fighter .bar {
  width: 50px;
  height: 6px;
  background: #1a140c;
  border: 1px solid rgba(0, 0, 0, 0.65);
  border-radius: 1px;
  overflow: hidden;
  margin: 0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}
.fighter .bar.atb {
  width: 42px;
  height: 3px;
  background: #0e1a1e;
  margin: 0;
}
.bar i { display: block; height: 100%; width: 0; transition: width 0.12s linear; }
.bar.hp i { background: linear-gradient(180deg, #c6ff5a 0%, #4cbf12 55%, #2f8a0c 100%); }
.bar.atb i { background: linear-gradient(90deg, #3aa8b8, #8ef0ff); }
.f-name { display: none; }
.f-tags {
  position: absolute;
  left: 50%;
  top: 20px;
  transform: translateX(-50%);
  min-height: 0;
  text-align: center;
  pointer-events: none;
  z-index: 5;
  white-space: nowrap;
}
.f-tags em {
  font-style: normal;
  font-size: 8px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold-bright);
  margin: 0 2px;
  text-shadow: 0 1px 2px #000;
}
.float-layer { position: absolute; inset: 0; pointer-events: none; z-index: 9; }
.floater {
  position: absolute;
  left: 50%;
  top: 8%;
  transform: translateX(-50%);
  font-weight: 800;
  font-size: 15px;
  animation: rise 900ms ease-out forwards;
  text-shadow: 0 1px 4px #000;
}
.floater.dmg { color: #ffd0d4; }
.floater.adv { color: #ffd36a; }
.floater.heal { color: #8ef0c4; }
.floater.buff { color: #c9a6ff; font-size: 12px; }
@keyframes rise {
  to { transform: translate(-50%, -36px); opacity: 0; }
}

.fighter.targeted::before {
  background: rgba(240, 215, 140, 0.38);
  box-shadow: 0 0 14px 3px rgba(240, 215, 140, 0.7);
  border: 2px solid var(--gold-bright);
  filter: none;
  width: 58px;
  height: 18px;
}
.fighter.targeted .bar.hp {
  box-shadow: 0 0 8px rgba(198, 255, 90, 0.7);
}

.action-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 8;
  padding: 8px var(--safe-x) calc(var(--safe-b) + 10px);
  background: linear-gradient(180deg, transparent, rgba(11, 7, 20, 0.92) 22%);
}
.action-bar.hidden { visibility: hidden; pointer-events: none; }
.acting-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  margin-bottom: 8px;
  color: var(--muted);
  line-height: 1.35;
}
.acting-label strong { color: var(--gold-bright); font-family: Cinzel, serif; }
.port.act-port {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  flex-shrink: 0;
}
.port.act-port .port-fallback { font-size: 18px; }
.act-meta { min-width: 0; flex: 1; }
.act-name { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.act-meta small { display: block; font-size: 11px; color: var(--muted); }
.act-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ===== RESULT ===== */
.result-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--safe-x);
  background: radial-gradient(600px 400px at 50% 30%, #2a1848, #0b0714);
}
.result-screen.win { background: radial-gradient(600px 400px at 50% 30%, #3a2a10, #0b0714); }
.result-card {
  position: relative;
  width: 100%;
  padding: 22px 18px 18px;
  border: 1px solid rgba(212, 175, 55, 0.4);
  border-radius: 14px;
  background: rgba(18, 16, 42, 0.88);
}
.result-card h2 { margin: 0 0 10px; color: var(--gold-bright); }
.result-card p { color: #ddd4c6; line-height: 1.5; margin: 0 0 16px; }
.result-card .gold-btn { width: 100%; }


/* ===== SW-like additions ===== */
.cur.mana { color: #9ad4ff; }
.currencies { gap: 4px; }
.cur { font-size: 10px; padding: 5px 6px; }

.island-hub .hub-hero h2 { font-size: 22px; }
.hub-art, .hub-veil { pointer-events: none; }
.island {
  position: relative;
  z-index: 3;
  flex: 1;
  min-height: 0;
}
.pin {
  position: absolute;
  min-width: 72px;
  min-height: 56px;
  padding: 6px 8px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  background: linear-gradient(180deg, rgba(30, 18, 52, 0.92), rgba(12, 8, 22, 0.94));
  border: 1.5px solid rgba(212, 175, 55, 0.55);
  border-radius: 14px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}
.pin:active { filter: brightness(1.18); }
.pin-ico { font-size: 18px; line-height: 1; }
.pin-name { font-family: Cinzel, Palatino, serif; font-size: 12px; color: var(--gold-bright); }
.pin-sub { font-size: 9px; color: var(--muted); }
.pin-battle { top: 8%; left: 50%; transform: translateX(-50%); min-width: 96px; min-height: 64px; }
.pin-gate { top: 34%; left: 8%; }
.pin-temple { top: 32%; right: 8%; }
.pin-box { bottom: 18%; left: 8%; }
.pin-arena { bottom: 18%; right: 8%; }
.pin-shop { top: 52%; left: 50%; transform: translateX(-50%); opacity: 0.72; min-width: 64px; }
.pin-shop:active { filter: brightness(1.18); }
.hub-dock {
  position: relative;
  z-index: 4;
  padding: 6px var(--safe-x) calc(var(--safe-b) + 10px);
}
.rest-btn {
  width: 100%;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid rgba(212, 175, 55, 0.4);
  background: rgba(18, 16, 42, 0.78);
  color: var(--gold-bright);
  font-weight: 800;
  letter-spacing: 0.06em;
}

/* Scenario / dungeon path */
.scenario-screen, .dungeon-screen, .arena-screen {
  background: linear-gradient(180deg, #1a1028, #0b0714);
}
.sc-lead {
  margin: 0;
  padding: 0 var(--safe-x) 8px;
  color: var(--muted);
  font-size: 12px;
}
.scenario-map {
  flex: 1;
  overflow: auto;
  padding: 4px var(--safe-x) calc(var(--safe-b) + 12px);
}
.sc-path {
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
}
.sc-path::before {
  content: '';
  position: absolute;
  left: 22px;
  top: 12px;
  bottom: 12px;
  width: 2px;
  background: linear-gradient(180deg, var(--gold), rgba(212, 175, 55, 0.15));
}
.sc-node {
  position: relative;
  z-index: 1;
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  text-align: left;
  border-radius: 14px;
  border: 1px solid rgba(212, 175, 55, 0.35);
  background: rgba(18, 16, 42, 0.82);
}
.sc-node.open { border-color: var(--gold); }
.sc-node.cleared { border-color: #8fd4c8; }
.sc-node.locked { opacity: 0.42; }
.sc-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 10px var(--gold);
  flex-shrink: 0;
}
.sc-node.cleared .sc-dot { background: #8fd4c8; box-shadow: 0 0 10px #8fd4c8; }
.sc-node.locked .sc-dot { background: #555; box-shadow: none; }
.sc-meta { flex: 1; min-width: 0; }
.sc-meta strong { display: block; font-family: Cinzel, serif; color: var(--gold-bright); }
.sc-meta em { font-style: normal; font-size: 11px; color: var(--muted); }
.sc-go { font-size: 16px; color: var(--gold-bright); }
.arena-card { margin: 16px var(--safe-x); }

/* Battle skills + targeting */
.act-btns.skills-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}
.skill-btn {
  min-height: 64px;
  padding: 6px 4px;
  font-size: 11px;
  letter-spacing: 0.03em;
  line-height: 1.2;
}
.skill-btn .sk-cd,
.skill-btn small {
  display: block;
  font-family: Nunito, sans-serif;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0;
  opacity: 0.78;
  margin-top: 3px;
}
.target-hint {
  margin: 0 0 6px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

/* Box */
.box-screen .team-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 0 var(--safe-x) 8px;
}
.team-slot {
  min-height: 72px;
  border-radius: 10px;
  border: 1px dashed rgba(212, 175, 55, 0.4);
  background: rgba(18, 16, 42, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 9px;
  color: var(--muted);
}
.team-slot .port.sm { width: 40px; height: 40px; }
.team-slot.empty { font-size: 22px; color: var(--gold-dim); }
.box-grid { grid-template-columns: repeat(3, 1fr); }
.box-card {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(212, 175, 55, 0.3);
  background: #14101f;
  padding: 0 0 6px;
  text-align: left;
}
.box-card .port { height: 88px; border: 0; }
.box-card.r5 { border-color: #f0d78c; }
.box-card.on-team { outline: 2px solid var(--gold); }
.box-meta { padding: 4px 6px 0; display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.box-name { padding: 2px 6px 0; font-family: Cinzel, serif; font-size: 11px; }

.unit-sheet {
  position: absolute;
  inset: 0;
  z-index: 12;
  background: rgba(7, 5, 14, 0.55);
  display: flex;
  align-items: flex-end;
}
.sheet-card {
  position: relative;
  width: 100%;
  max-height: 86%;
  overflow: auto;
  padding: 16px 14px 18px;
  border-radius: 16px 16px 0 0;
  background: #16101f;
  border-top: 1px solid rgba(212, 175, 55, 0.4);
}
.sheet-close {
  position: absolute;
  top: 6px;
  right: 8px;
  min-width: 44px;
  min-height: 44px;
  font-size: 24px;
  color: var(--gold-bright);
}
.sheet-head { display: flex; gap: 10px; align-items: center; padding-right: 36px; }
.port.sheet-port { width: 72px; height: 72px; border-radius: 10px; flex-shrink: 0; }
.sheet-stats { margin: 10px 0 6px; font-size: 13px; color: var(--gold-bright); }
.sheet-skills { margin: 0 0 10px; padding-left: 16px; font-size: 12px; color: #ddd4c6; }
.sheet-team { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; font-size: 12px; }
.mini-slot {
  min-width: 40px;
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid rgba(212, 175, 55, 0.35);
}
.mini-slot.on { background: var(--gold); color: #1a1206; font-weight: 800; }
.sheet-lab { margin: 0 0 6px; font-size: 12px; color: var(--muted); }
.crest-slots {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.crest-slot {
  min-height: 64px;
  border-radius: 10px;
  border: 1px dashed rgba(212, 175, 55, 0.4);
  background: rgba(18, 16, 42, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 10px;
  color: var(--muted);
}
.crest-slot.filled { border-style: solid; color: var(--text); }
.crest-slot b { color: var(--gold-bright); }
.crest-picker { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.crest-pick {
  min-height: 48px;
  text-align: left;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(212, 175, 55, 0.3);
  background: rgba(18, 16, 42, 0.8);
  display: flex;
  flex-direction: column;
}
.loot-list { margin: 0 0 14px; padding-left: 18px; color: #ddd4c6; font-size: 13px; }
.pay-toggle .tog { font-size: 11px; padding: 0 4px; }

/* ===== MOBILE SHELL (JS sets html[data-shell]) =====
   Landscape playfield. No gold phone bezel.
   Physical portrait: CSS-rotate #device 90° so the game is still landscape. */
html[data-shell="mobile"],
html[data-shell="mobile"] body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

html[data-shell="mobile"] #stage {
  padding: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  position: relative;
}

html[data-shell="mobile"] #device {
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

/* Already landscape: fill the screen. */
@media (orientation: landscape) {
  html[data-shell="mobile"] #device {
    width: 100vw;
    width: 100dvw;
    height: 100vh;
    height: 100dvh;
  }
}

/* Held portrait: rotate the landscape play surface so it still fills the screen.
   rotate(90deg) maps game-top → physical-right, which becomes physical-top
   when the player then turns the phone left into real landscape. */
@media (orientation: portrait) {
  html[data-shell="mobile"] {
    --safe-t: max(12px, env(safe-area-inset-left));
    --safe-b: max(14px, env(safe-area-inset-right));
    --safe-x: max(14px, env(safe-area-inset-top), env(safe-area-inset-bottom));
  }
  html[data-shell="mobile"] #device {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100vh;
    width: 100dvh;
    height: 100vw;
    height: 100dvw;
    transform: translate(-50%, -50%) rotate(90deg);
    transform-origin: center center;
  }
}

/* Screens sit in a short landscape box — let them scroll instead of clipping.
   Battle stays overflow:hidden (tokens are absolutely positioned). */
html[data-shell="mobile"] .screen:not(.battle-screen) {
  overflow-y: auto;
}

/* Wider floor, less empty orange sky. Always landscape-shaped on mobile. */
html[data-shell="mobile"] .arena-plate {
  width: 110%;
  top: 50%;
}

/* Hub pins were laid out for a tall portrait island. In the landscape
   shell they overlap, so switch to a compact 3-column grid. */
html[data-shell="mobile"] .island {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 4px var(--safe-x) 8px;
  min-height: 0;
}
html[data-shell="mobile"] .pin {
  position: relative;
  top: auto;
  left: auto;
  right: auto;
  bottom: auto;
  transform: none;
  min-width: 0;
  width: 100%;
  min-height: 52px;
}
html[data-shell="mobile"] .hub-hero {
  padding-bottom: 4px;
}
html[data-shell="mobile"] .island-hub .hub-hero h2 {
  font-size: 20px;
}

/* Use the extra landscape width on grids. */
html[data-shell="mobile"] .unit-grid {
  grid-template-columns: repeat(3, 1fr);
}
html[data-shell="mobile"] .box-grid {
  grid-template-columns: repeat(4, 1fr);
}
html[data-shell="mobile"] .reveal-grid.n10 {
  grid-template-columns: repeat(5, 1fr);
}

/* Gate / story stay usable in a short landscape box. */
html[data-shell="mobile"] .gate-stage {
  min-height: 0;
  padding: 4px 0;
}
html[data-shell="mobile"] .ritual {
  width: 132px;
  height: 132px;
}
html[data-shell="mobile"] .summon-btns {
  padding-top: 6px;
}
