* { box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  margin: 0;
  font-family: Arial, "Noto Sans Hebrew", sans-serif;
  background: radial-gradient(circle at top, #2d2454, #11131f 62%, #080913);
  color: #f7f2ff;
}

.global-sound-toggle{
  position:fixed;
  z-index:200;
  top:10px;
  left:10px;
  min-height:38px;
  padding:8px 12px !important;
  border-radius:999px !important;
  background:rgba(11,13,28,.78) !important;
  border:1px solid rgba(244,191,98,.30) !important;
  color:#fff5df !important;
  box-shadow:0 10px 26px rgba(0,0,0,.28);
  backdrop-filter:blur(10px);
}

.online-modal-box{
  width:min(560px,92vw);
  text-align:right;
}

.modal-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-bottom:16px;
}

.modal-head h2{
  margin:0;
  color:#fff5df;
}

.online-status{
  min-height:54px;
  display:flex;
  align-items:center;
  justify-content:center;
  border:1px solid rgba(255,255,255,.16);
  border-radius:14px;
  background:rgba(255,255,255,.07);
  color:#fff;
  font-weight:900;
}

.online-status.busy::before{
  content:"";
  width:18px;
  height:18px;
  margin-left:10px;
  border:3px solid rgba(255,255,255,.24);
  border-top-color:#ffd166;
  border-radius:50%;
  animation:spin .8s linear infinite;
}

.online-status.ok{
  color:#78f5ad;
}

.online-status.error{
  color:#ffb4b4;
  border-color:rgba(255,120,120,.45);
  background:rgba(120,20,20,.18);
}

.online-battle-status{
  position:absolute;
  left:50%;
  top:50%;
  transform:translate(-50%,-50%);
  z-index:14;
  min-height:34px;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:7px 16px;
  border-radius:999px;
  border:1px solid rgba(255,209,102,.45);
  background:rgba(16,18,31,.82);
  color:#fff5df;
  font-weight:900;
  box-shadow:0 10px 26px rgba(0,0,0,.28);
  pointer-events:none;
}

.online-steps{
  display:grid;
  grid-template-columns:repeat(3,1fr);
  gap:8px;
  margin-top:14px;
  color:#d8ddff;
  font-size:.9rem;
}

.online-steps span{
  border:1px solid rgba(255,255,255,.12);
  border-radius:12px;
  padding:9px 8px;
  text-align:center;
  background:rgba(255,255,255,.05);
}

@keyframes spin{
  to{transform:rotate(360deg)}
}
.app { width: min(1280px, 98vw); height: 100vh; margin: 0 auto; padding: 14px 0; }
.screen { display: none; height: 100%; }
.screen.active { display: block; }
.hidden { display: none !important; }
h1,h2,h3,p { margin-top: 0; }
h1 { font-size: 42px; margin-bottom: 8px; }
h2 { margin-bottom: 5px; }
h3 { margin-bottom: 8px; }
.subtitle { color: #cfc7ef; font-size: 16px; }
button { border: none; border-radius: 13px; padding: 11px 16px; cursor: pointer; font-weight: 800; }
.primary-btn { background: #ffd166; color: #191724; }
.ghost-btn { color: #fff; background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.18); }
.big-btn { font-size: 20px; padding: 18px 28px; }
.home-actions { display: flex; gap: 16px; margin-top: 24px; }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.card {
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.08);
  border-radius: 16px;
  padding: 14px;
  min-height: 126px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.22);
  cursor: pointer;
  transition: transform .15s ease, background .15s ease, border-color .15s ease, opacity .15s ease;
}
.card:hover { transform: translateY(-3px); background: rgba(255,255,255,0.14); border-color: rgba(255,255,255,0.32); }
.card.disabled { pointer-events:none; opacity:.52; }
.card.selected { background: rgba(255,209,102,.22); border-color:#ffd166; box-shadow:0 0 0 2px rgba(255,209,102,.32),0 10px 30px rgba(0,0,0,.25); }
.card.locked-card { opacity:.45; filter:grayscale(1); cursor:not-allowed; }
.card h3 { margin-bottom: 8px; font-size: 18px; }
.card p { font-size: 14px; margin-bottom: 8px; }
.card small { color:#d4ccef; }
.profile-box, .character-preview {
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 18px;
  padding: 18px;
  margin: 18px 0;
}
.profile-box input {
  min-width: 320px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 12px;
  padding: 14px;
  background: rgba(0,0,0,.25);
  color:#fff;
  font-size:18px;
  margin-left: 10px;
}
.sorting-stage { height:70vh; display:grid; place-items:center; align-content:center; gap:22px; }
.hat { font-size:120px; animation:hatWiggle 1s infinite ease-in-out; }
@keyframes hatWiggle { 0%,100%{transform:rotate(-5deg) scale(1)} 50%{transform:rotate(5deg) scale(1.08)} }
.sorting-text { font-size: 28px; font-weight: 900; color:#ffd166; }
.house-raven { background: radial-gradient(circle at top, rgba(80,120,255,.28), rgba(255,255,255,.07)); }
.house-serpent { background: radial-gradient(circle at top, rgba(40,180,105,.28), rgba(255,255,255,.07)); }
.house-badger { background: radial-gradient(circle at top, rgba(255,205,64,.28), rgba(255,255,255,.07)); }
.house-lion { background: radial-gradient(circle at top, rgba(255,80,65,.28), rgba(255,255,255,.07)); }
.preview-grid { display:grid; grid-template-columns:120px 1fr; gap:18px; align-items:center; }
.preview-avatar { font-size:86px; text-align:center; }
.setup-title { margin: 20px 0 10px; font-size: 24px; }
.start-game-wrap { margin-top: 18px; text-align:center; display:flex; gap:10px; justify-content:center; flex-wrap:wrap; }
.top-bar { display:flex; align-items:flex-start; justify-content:space-between; gap:14px; height:64px; margin-bottom:10px; }
.top-actions { display:flex; gap:8px; }
.battle-layout { height: calc(100vh - 92px); display:grid; grid-template-columns:280px 1fr 280px; gap:12px; min-height:0; }
.right-panel { display:grid; grid-template-rows:1fr 1fr; gap:12px; min-height:0; }
.info-card,.log-panel { background:rgba(255,255,255,.08); border:1px solid rgba(255,255,255,.14); border-radius:18px; padding:12px; overflow:hidden; }
.arena-column { display:grid; grid-template-rows:38px 1fr 172px; gap:10px; min-height:0; }
.turn-badge { justify-self:center; align-self:center; color:#191724; background:#ffd166; border-radius:999px; padding:8px 16px; font-weight:900; box-shadow:0 8px 24px rgba(0,0,0,.22); }
.arena { position:relative; min-height:0; background:linear-gradient(180deg,rgba(255,255,255,.08),rgba(255,255,255,.035)); border:1px solid rgba(255,255,255,.13); border-radius:24px; display:grid; grid-template-rows:1fr 86px 1fr; overflow:hidden; }
.fighter-visual { position:relative; display:grid; place-items:center; min-height:0; }
.enemy-visual { align-items:end; padding-bottom:8px; }
.player-visual { align-items:start; padding-top:8px; }
.avatar { font-size: clamp(58px,8vh,92px); filter: drop-shadow(0 14px 16px rgba(0,0,0,.35)); z-index:2; }
.stand-shadow { width:120px; height:20px; background:rgba(0,0,0,.25); border-radius:50%; position:absolute; bottom:8px; filter:blur(2px); }
.player-visual .stand-shadow { top:102px; bottom:auto; }
.spell-lane { position:relative; border-top:1px dashed rgba(255,255,255,.16); border-bottom:1px dashed rgba(255,255,255,.16); }
.hand-section { min-height:0; overflow:hidden; }
.hand-section h3 { margin-bottom:8px; }
.spell-hand { display:grid; grid-template-columns:repeat(3,1fr); gap:10px; }
.spell-hand .card { min-height:126px; padding:12px; }
.hp-wrap,.xp-wrap { height:14px; background:rgba(0,0,0,.35); border-radius:999px; overflow:hidden; margin:8px 0 6px; }
.hp-bar { height:100%; width:100%; background:linear-gradient(90deg,#ff4d6d,#ffd166); transition:width .35s ease; }
.xp-bar { height:100%; width:0%; background:linear-gradient(90deg,#8ec5ff,#ffd166); transition:width .7s ease; }
.large-xp { height:22px; margin:18px 0; }
.stats { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:6px; margin-top:8px; }
.stat { background:rgba(0,0,0,.18); border-radius:9px; padding:6px 8px; color:#efeaff; font-size:13px; }
.buffs { min-height:22px; margin-top:8px; color:#9df3c4; font-size:13px; }
.negative { color:#ff7b7b!important; }
.positive { color:#9df3c4!important; }
.spell-attack { border-color:rgba(255,82,82,.75); }
.spell-defense { border-color:rgba(92,225,230,.75); }
.spell-buff { border-color:rgba(255,209,102,.75); }
.spell-control { border-color:rgba(180,120,255,.75); }
#battle-log { height:calc(100% - 36px); overflow:auto; color:#e5dcff; line-height:1.45; font-size:13px; }
.log-line { border-bottom:1px solid rgba(255,255,255,.08); padding:6px 0; }
.effect-layer { position:absolute; inset:0; pointer-events:none; display:grid; place-items:center; font-size:58px; opacity:0; z-index:3; }
.flash-hit { animation:hitFlash .65s ease; }
.flash-shield { animation:shieldFlash .75s ease; }
.flash-heal { animation:healFlash .75s ease; }
.flash-miss { animation:missFlash .7s ease; }
.luck-flash { animation:luckFlash .85s ease; }
.deflect { animation:deflectFlash .9s ease; }
@keyframes hitFlash { 0%{opacity:0;transform:scale(.8);background:rgba(255,77,109,0)} 25%{opacity:1;transform:scale(1.08);background:rgba(255,77,109,.25)} 100%{opacity:0;transform:scale(1.2);background:rgba(255,77,109,0)} }
@keyframes shieldFlash { 0%{opacity:0;transform:scale(.8);background:rgba(92,225,230,0)} 25%{opacity:1;transform:scale(1.04);background:rgba(92,225,230,.2)} 100%{opacity:0;transform:scale(1.18);background:rgba(92,225,230,0)} }
@keyframes healFlash { 0%{opacity:0;transform:scale(.8);background:rgba(157,243,196,0)} 25%{opacity:1;transform:scale(1.04);background:rgba(157,243,196,.18)} 100%{opacity:0;transform:scale(1.18);background:rgba(157,243,196,0)} }
@keyframes missFlash { 0%{opacity:0;transform:translateX(0) scale(.9)} 30%{opacity:1;transform:translateX(16px) scale(1.05)} 100%{opacity:0;transform:translateX(-28px) scale(1.1)} }
@keyframes luckFlash { 0%{opacity:0;transform:scale(.8);background:rgba(255,209,102,0)} 30%{opacity:1;transform:scale(1.1);background:rgba(255,209,102,.24)} 100%{opacity:0;transform:scale(1.2);background:rgba(255,209,102,0)} }
@keyframes deflectFlash { 0%{opacity:0;transform:scale(.85);background:rgba(92,225,230,0)} 30%{opacity:1;transform:scale(1.08);background:rgba(92,225,230,.28)} 100%{opacity:0;transform:scale(1.25);background:rgba(92,225,230,0)} }
.projectile { position:absolute; left:50%; top:50%; font-size:48px; z-index:4; opacity:0; }
.projectile.hidden { display:none; }
.projectile.to-enemy { display:block; animation:flyUp .62s ease; }
.projectile.to-player { display:block; animation:flyDown .62s ease; }
.projectile.miss-enemy { display:block; animation:missUp .75s ease; }
.projectile.miss-player { display:block; animation:missDown .75s ease; }
@keyframes flyUp { 0%{opacity:0;transform:translate(-50%,50px) scale(.6)} 15%{opacity:1} 100%{opacity:0;transform:translate(-50%,-64px) scale(1.15)} }
@keyframes flyDown { 0%{opacity:0;transform:translate(-50%,-64px) scale(.6)} 15%{opacity:1} 100%{opacity:0;transform:translate(-50%,50px) scale(1.15)} }
@keyframes missUp { 0%{opacity:0;transform:translate(-50%,50px) scale(.6)} 15%{opacity:1} 100%{opacity:0;transform:translate(120px,-70px) rotate(24deg) scale(1)} }
@keyframes missDown { 0%{opacity:0;transform:translate(-50%,-64px) scale(.6)} 15%{opacity:1} 100%{opacity:0;transform:translate(-150px,54px) rotate(-24deg) scale(1)} }
.floating-text { position:absolute; left:50%; top:50%; transform:translate(-50%,-50%); color:#fff; font-weight:900; font-size:24px; text-shadow:0 2px 14px rgba(0,0,0,.55); z-index:5; }
.floating-text.hidden { display:none; }
.modal { position:fixed; inset:0; background:rgba(0,0,0,.68); display:grid; place-items:center; z-index:50; }
.modal.hidden { display:none; }
.modal-box { width:min(980px,92vw); max-height:min(720px,88vh); background:#181a2e; color:#fff; border:1px solid rgba(255,255,255,.18); border-radius:22px; padding:20px; overflow:auto; }
.victory-box { text-align:center; max-width:620px; height:auto; }
.modal-head { display:flex; justify-content:space-between; gap:12px; align-items:center; }
.spellbook-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(210px,1fr)); gap:12px; margin-top:14px; }
.book-card { border-radius:16px; padding:12px; border:1px solid rgba(255,255,255,.14); background:rgba(255,255,255,.08); }
.book-card.locked { opacity:.45; filter:grayscale(1); }
.profile-mini { background:rgba(255,255,255,.06); border-radius:12px; padding:8px; margin-top:8px; font-size:13px; color:#e9e2ff; }
@media (max-width:900px) { html,body{overflow:auto}.app{height:auto}.battle-layout{height:auto;grid-template-columns:1fr}.right-panel{grid-template-rows:auto auto}.arena-column{grid-template-rows:38px 430px auto}.log-panel{height:180px} }

/* v12 turn highlighting */
.turn-badge {
  font-size: 12px !important;
  padding: 5px 11px !important;
  opacity: 0.82;
}

.info-card.active-turn {
  border-color: #ffd166 !important;
  box-shadow:
    0 0 0 2px rgba(255, 209, 102, 0.32),
    0 0 26px rgba(255, 209, 102, 0.24),
    0 10px 30px rgba(0,0,0,0.22);
  transform: scale(1.015);
}

.info-card.active-turn h3::before {
  content: "⚡ ";
  color: #ffd166;
}

.fighter-visual.active-turn-visual .avatar {
  filter:
    drop-shadow(0 0 14px rgba(255, 209, 102, 0.75))
    drop-shadow(0 14px 16px rgba(0,0,0,0.35));
}

.info-card {
  transition: box-shadow .18s ease, transform .18s ease, border-color .18s ease;
}

/* v13 clearer dodge / protection feedback */
.dodge-left .avatar {
  animation: dodgeLeft .72s ease;
}

.dodge-right .avatar {
  animation: dodgeRight .72s ease;
}

@keyframes dodgeLeft {
  0% { transform: translateX(0); }
  35% { transform: translateX(-42px) rotate(-4deg); }
  100% { transform: translateX(0); }
}

@keyframes dodgeRight {
  0% { transform: translateX(0); }
  35% { transform: translateX(42px) rotate(4deg); }
  100% { transform: translateX(0); }
}

.blocked-log {
  color: #9df3c4;
  font-weight: 800;
}

.miss-log,
.negative-log {
  color: #ff7b7b;
  font-weight: 800;
}

/* v14 polish */
.turn-badge { display: none !important; }
.battle-layout.log-collapsed { grid-template-columns: 280px 1fr 0px !important; }
.battle-layout.log-collapsed .log-panel { display: none !important; }
.battle-layout:not(.log-collapsed) { grid-template-columns: 280px 1fr 280px !important; }
.info-card { padding: 16px 16px 22px !important; }
.player-info { padding-bottom: 34px !important; }
.right-panel { padding-bottom: 14px; }
.arena-column { grid-template-rows: 0px 1fr 172px !important; }
@media (max-width: 900px) {
  .battle-layout.log-collapsed, .battle-layout:not(.log-collapsed) { grid-template-columns: 1fr !important; }
}

/* v17 emergency layout fix: restore battle arena */
.battle-layout {
  height: calc(100vh - 92px) !important;
  display: grid !important;
  grid-template-columns: 280px minmax(620px, 1fr) 0px !important;
  gap: 12px !important;
  min-height: 0 !important;
}

.battle-layout.log-collapsed {
  grid-template-columns: 280px minmax(620px, 1fr) 0px !important;
}

.battle-layout.log-collapsed .log-panel {
  display: none !important;
}

.battle-layout:not(.log-collapsed) {
  grid-template-columns: 280px minmax(620px, 1fr) 280px !important;
}

.arena-column {
  display: grid !important;
  grid-template-rows: minmax(430px, 1fr) 172px !important;
  gap: 10px !important;
  min-height: 0 !important;
}

.turn-badge {
  display: none !important;
}

.arena {
  display: grid !important;
  height: 100% !important;
  min-height: 430px !important;
  grid-template-rows: 1fr 86px 1fr !important;
}

.hand-section {
  min-height: 0 !important;
  overflow: hidden !important;
}

.spell-hand {
  display: grid !important;
  grid-template-columns: repeat(3, 1fr) !important;
  gap: 10px !important;
}

.right-panel {
  min-height: 0 !important;
}

@media (max-width: 900px) {
  html, body { overflow: auto !important; }
  .app { height: auto !important; }
  .battle-layout,
  .battle-layout.log-collapsed,
  .battle-layout:not(.log-collapsed) {
    height: auto !important;
    grid-template-columns: 1fr !important;
  }
  .arena-column {
    grid-template-rows: 430px auto !important;
  }
}

/* v18 spellbook book layout + clearer feedback */
.spellbook-book {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 16px;
  min-height: 430px;
}

.book-page {
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 18px;
  background: rgba(255,255,255,.065);
  padding: 16px;
  box-shadow: inset 0 0 30px rgba(0,0,0,.16);
}

.book-page h3 {
  color: #ffd166;
  margin-bottom: 12px;
}

.book-spell {
  border-bottom: 1px solid rgba(255,255,255,.10);
  padding: 10px 0;
}

.book-spell:last-child {
  border-bottom: 0;
}

.book-spell.locked {
  opacity: .45;
  filter: grayscale(1);
}

.spellbook-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  margin-top: 14px;
}

.spellbook-nav button {
  min-width: 90px;
}

@media (max-width: 760px) {
  .spellbook-book {
    grid-template-columns: 1fr;
  }
}

/* v19 spellbook fix */
.spellbook-book {
  min-height: 520px !important;
}
.book-page {
  min-height: 500px;
}
.spellbook-nav {
  position: sticky;
  bottom: 0;
  background: #181a2e;
  padding: 8px 0 0;
  margin-top: 8px !important;
}
.spellbook-nav button {
  min-width: 70px !important;
  padding: 8px 12px !important;
}


/* v20 additions */
.spellbook-summary{background:rgba(255,255,255,.08);border:1px solid rgba(255,255,255,.16);border-radius:16px;padding:12px;margin:10px 0 16px;line-height:1.6}
.spellbook-all{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px;max-height:52vh;overflow:auto;padding-inline-end:4px}
.items-title{margin:18px 0 8px}
.spell-item{border-color:rgba(255,255,255,.25)}
@media(max-width:720px){.spellbook-all{grid-template-columns:1fr}}

/* v20b redesigned spellbook */
.spellbook-spell-list{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:10px;max-height:46vh;overflow:auto;padding:4px 4px 10px}
.book-spell-tile{border:1px solid rgba(255,255,255,.18);background:rgba(255,255,255,.08);color:inherit;border-radius:16px;padding:12px 10px;text-align:center;cursor:pointer;transition:.18s ease;font-family:inherit}
.book-spell-tile:hover,.book-spell-tile.selected{transform:translateY(-1px);background:rgba(255,255,255,.16);border-color:rgba(255,255,255,.42)}
.book-spell-tile.locked{opacity:.42;filter:grayscale(1)}
.book-icon{display:block;font-size:28px;line-height:1.1;margin-bottom:6px}
.book-name{display:block;font-weight:800;margin-bottom:4px}
.book-knowledge{display:block;font-size:12px;opacity:.8}
.spellbook-detail{margin-top:14px;padding:16px;border-radius:18px;background:rgba(0,0,0,.22);border:1px solid rgba(255,255,255,.18);line-height:1.7}
.spellbook-detail h3{margin:0 0 8px}.spellbook-detail p{margin:0 0 8px}.spellbook-detail small{opacity:.82}

/* v20c polish: matching spellbook scroll and temporary stat coloring */
.spellbook-spell-list{
  scrollbar-width: thin;
  scrollbar-color: rgba(255,209,102,.75) rgba(0,0,0,.22);
}
.spellbook-spell-list::-webkit-scrollbar{width:10px;height:10px}
.spellbook-spell-list::-webkit-scrollbar-track{background:rgba(0,0,0,.22);border-radius:999px;border:1px solid rgba(255,255,255,.10)}
.spellbook-spell-list::-webkit-scrollbar-thumb{background:linear-gradient(180deg,rgba(255,209,102,.95),rgba(188,128,44,.95));border-radius:999px;border:2px solid rgba(20,12,5,.9)}
.spellbook-spell-list::-webkit-scrollbar-thumb:hover{background:linear-gradient(180deg,rgba(255,225,145,.98),rgba(214,151,57,.98))}
.stat.stat-up{color:#7CFFB2;border-color:rgba(124,255,178,.55);background:rgba(34,197,94,.12);box-shadow:0 0 0 1px rgba(124,255,178,.08) inset}
.stat.stat-down{color:#FF8A8A;border-color:rgba(255,92,92,.55);background:rgba(239,68,68,.12);box-shadow:0 0 0 1px rgba(255,92,92,.08) inset}
.buffs:empty{display:none}

/* v20d actual fixes */
.spell-hand{
  grid-template-columns:repeat(4,minmax(0,1fr)) !important;
  gap:10px !important;
  align-items:stretch !important;
}
.spell-hand .card{min-height:116px !important;padding:10px !important;}
.hand-section{overflow:visible !important;}
.stat.stat-up{color:#7CFFB2 !important;border-color:rgba(124,255,178,.65) !important;background:rgba(34,197,94,.14) !important;box-shadow:0 0 0 1px rgba(124,255,178,.10) inset !important;}
.stat.stat-down{color:#FF8A8A !important;border-color:rgba(255,92,92,.65) !important;background:rgba(239,68,68,.14) !important;box-shadow:0 0 0 1px rgba(255,92,92,.10) inset !important;}
.buffs{display:none !important;}
@media(max-width:720px){.spell-hand{grid-template-columns:repeat(2,minmax(0,1fr)) !important;}}

/* v20e polish: consistent stat cards and permanent stats are not temporary colors */
.right-panel{
  grid-template-rows: minmax(0,1fr) minmax(0,1fr) !important;
  gap: 12px !important;
  padding-bottom: 0 !important;
}
.info-card,
.player-info,
.enemy-info{
  padding: 16px 16px 18px !important;
  min-height: 0 !important;
}
.info-card .stats{
  margin-bottom: 0 !important;
}
.character-preview .stat.stat-up,
.character-preview .stat.stat-down{
  color:#efeaff !important;
  border-color:transparent !important;
  background:rgba(0,0,0,.18) !important;
  box-shadow:none !important;
}
.spellbook-spell-list,
#battle-log,
.modal-box{
  scrollbar-width: thin;
  scrollbar-color: rgba(255,209,102,.78) rgba(0,0,0,.24);
}
.spellbook-spell-list::-webkit-scrollbar,
#battle-log::-webkit-scrollbar,
.modal-box::-webkit-scrollbar{width:10px;height:10px}
.spellbook-spell-list::-webkit-scrollbar-track,
#battle-log::-webkit-scrollbar-track,
.modal-box::-webkit-scrollbar-track{background:rgba(0,0,0,.22);border-radius:999px;border:1px solid rgba(255,255,255,.10)}
.spellbook-spell-list::-webkit-scrollbar-thumb,
#battle-log::-webkit-scrollbar-thumb,
.modal-box::-webkit-scrollbar-thumb{background:linear-gradient(180deg,rgba(255,209,102,.95),rgba(188,128,44,.95));border-radius:999px;border:2px solid rgba(20,12,5,.9)}
.spellbook-spell-list::-webkit-scrollbar-thumb:hover,
#battle-log::-webkit-scrollbar-thumb:hover,
.modal-box::-webkit-scrollbar-thumb:hover{background:linear-gradient(180deg,rgba(255,225,145,.98),rgba(214,151,57,.98))}

/* v20g: fix battle stat card spacing and spellbook layout */
.right-panel{
  display:flex !important;
  flex-direction:column !important;
  grid-template-rows:none !important;
  justify-content:flex-start !important;
  align-content:flex-start !important;
  gap:10px !important;
  min-height:0 !important;
  padding-bottom:22px !important;
  overflow:visible !important;
}
.info-card.enemy-info,
.info-card.player-info{
  flex:0 0 auto !important;
  height:auto !important;
  min-height:0 !important;
  max-height:none !important;
  overflow:visible !important;
}
.info-card.enemy-info{
  padding-bottom:16px !important;
  margin-bottom:0 !important;
}
.info-card.player-info{
  padding-bottom:24px !important;
  margin-bottom:18px !important;
}
.info-card .stats{
  margin-bottom:0 !important;
}
.info-card .stats .stat:last-child,
.info-card .stats .stat:nth-last-child(2){
  margin-bottom:0 !important;
}
#spellbook-modal .subtitle{
  display:none !important;
}
#spellbook-content.spellbook-grid{
  display:grid !important;
  grid-template-columns:minmax(0,2fr) minmax(250px,0.85fr) !important;
  gap:18px !important;
  align-items:stretch !important;
  margin-top:18px !important;
}
.spellbook-spell-list{
  grid-template-columns:repeat(2,minmax(140px,1fr)) !important;
  max-height:56vh !important;
  min-height:0 !important;
}
.spellbook-detail{
  margin-top:0 !important;
  min-height:100% !important;
}
@media(max-width:900px){
  #spellbook-content.spellbook-grid{grid-template-columns:1fr !important;}
  .spellbook-spell-list{grid-template-columns:repeat(auto-fit,minmax(140px,1fr)) !important;}
}

/* v20h: wand label polish */
.profile-mini{
  display:flex !important;
  align-items:center !important;
  justify-content:center !important;
  gap:6px !important;
  width:max-content !important;
  max-width:100% !important;
  margin:10px auto 0 !important;
  padding:6px 10px !important;
  border-radius:999px !important;
  background:rgba(255,255,255,.05) !important;
  color:rgba(233,226,255,.88) !important;
  font-size:12px !important;
  line-height:1 !important;
  white-space:nowrap !important;
  overflow:hidden !important;
  text-overflow:ellipsis !important;
}
.profile-mini .wand-text{
  display:inline-block !important;
  white-space:nowrap !important;
  overflow:hidden !important;
  text-overflow:ellipsis !important;
  max-width:100% !important;
}

/* v20i: remove battle help text and fix wand label width/centering */
#battle-subtitle{
  display:none !important;
}
.top-bar{
  height:auto !important;
  min-height:0 !important;
  margin-bottom:6px !important;
  align-items:center !important;
}
.top-bar h2{
  margin-bottom:0 !important;
}
.profile-mini{
  grid-column:1 / -1 !important;
  width:100% !important;
  max-width:none !important;
  justify-self:stretch !important;
  margin:12px auto 0 !important;
  padding:7px 12px !important;
  overflow:visible !important;
  text-overflow:clip !important;
  white-space:nowrap !important;
  text-align:center !important;
}
.profile-mini .wand-text{
  display:block !important;
  width:100% !important;
  max-width:none !important;
  overflow:visible !important;
  text-overflow:clip !important;
  white-space:nowrap !important;
  text-align:center !important;
}

/* v21 mobile-first battle UX */
@media (max-width: 720px) {
  html, body {
    height: auto !important;
    min-height: 100% !important;
    overflow: auto !important;
  }

  body {
    -webkit-text-size-adjust: 100%;
  }

  .app {
    width: 100vw !important;
    min-height: 100vh !important;
    height: auto !important;
    padding: 8px 8px 110px !important;
  }

  h1 { font-size: 30px !important; }
  h2 { font-size: 20px !important; }

  #screen-battle.active {
    display: flex !important;
    flex-direction: column !important;
    min-height: 100vh !important;
  }

  .top-bar {
    position: sticky !important;
    top: 0 !important;
    z-index: 20 !important;
    background: rgba(17, 19, 31, .94) !important;
    backdrop-filter: blur(10px) !important;
    border: 1px solid rgba(255,255,255,.10) !important;
    border-radius: 16px !important;
    padding: 8px !important;
    margin-bottom: 8px !important;
  }

  .top-actions {
    gap: 6px !important;
    flex-wrap: nowrap !important;
  }

  .top-actions .ghost-btn {
    padding: 9px 10px !important;
    font-size: 12px !important;
    border-radius: 11px !important;
    white-space: nowrap !important;
  }

  #battle-title {
    font-size: 17px !important;
    white-space: nowrap !important;
  }

  #log-toggle-btn {
    display: none !important;
  }

  .battle-layout,
  .battle-layout.log-collapsed,
  .battle-layout:not(.log-collapsed) {
    display: flex !important;
    flex-direction: column !important;
    height: auto !important;
    min-height: 0 !important;
    gap: 8px !important;
    grid-template-columns: none !important;
  }

  .right-panel,
  .arena-column {
    display: contents !important;
  }

  .enemy-info { order: 1 !important; }
  .arena { order: 2 !important; }
  .player-info { order: 3 !important; }
  .hand-section { order: 4 !important; }
  .log-panel { order: 5 !important; display: none !important; }

  .info-card.enemy-info,
  .info-card.player-info {
    width: 100% !important;
    padding: 10px 12px 12px !important;
    margin: 0 !important;
    border-radius: 16px !important;
  }

  .info-card h3 {
    font-size: 16px !important;
    margin-bottom: 4px !important;
  }

  .info-card p {
    font-size: 12px !important;
    margin-bottom: 4px !important;
  }

  .hp-wrap, .xp-wrap {
    height: 10px !important;
    margin: 5px 0 4px !important;
  }

  .stats {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 5px !important;
    margin-top: 6px !important;
  }

  .stat {
    font-size: 11px !important;
    padding: 5px 6px !important;
    border-radius: 8px !important;
    text-align: center !important;
    white-space: nowrap !important;
  }

  .profile-mini {
    display: none !important;
  }

  .arena {
    min-height: 260px !important;
    height: 34vh !important;
    max-height: 340px !important;
    grid-template-rows: 1fr 50px 1fr !important;
    border-radius: 18px !important;
  }

  .avatar {
    font-size: clamp(48px, 13vw, 74px) !important;
  }

  .spell-lane {
    min-height: 50px !important;
  }

  .stand-shadow {
    width: 92px !important;
    height: 14px !important;
  }

  .player-visual .stand-shadow {
    top: 82px !important;
  }

  .hand-section {
    position: sticky !important;
    bottom: 0 !important;
    z-index: 25 !important;
    margin: 0 -8px -110px !important;
    padding: 10px 8px max(12px, env(safe-area-inset-bottom)) !important;
    background: linear-gradient(180deg, rgba(17,19,31,.55), rgba(17,19,31,.98) 28%) !important;
    border-top: 1px solid rgba(255,255,255,.14) !important;
    overflow: visible !important;
  }

  .hand-section h3 {
    display: none !important;
  }

  .spell-hand,
  .spell-hand[style] {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 6px !important;
  }

  .spell-hand .card {
    min-height: 74px !important;
    padding: 8px 6px !important;
    border-radius: 14px !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
  }

  .spell-hand .card h3 {
    font-size: 12px !important;
    line-height: 1.18 !important;
    margin: 0 !important;
  }

  .spell-hand .card p,
  .spell-hand .card small {
    display: none !important;
  }

  .spell-hand .card:active {
    transform: scale(.98) !important;
  }

  .modal-box {
    width: 94vw !important;
    max-height: 88vh !important;
    padding: 14px !important;
    border-radius: 18px !important;
  }

  #spellbook-content.spellbook-grid {
    display: block !important;
    margin-top: 10px !important;
  }

  .spellbook-spell-list {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    max-height: 58vh !important;
    gap: 8px !important;
  }

  .book-spell-tile {
    padding: 10px 8px !important;
    border-radius: 14px !important;
  }

  .book-icon { font-size: 24px !important; }
  .book-name { font-size: 13px !important; }
  .book-knowledge { font-size: 11px !important; }

  .spellbook-detail {
    margin-top: 10px !important;
    padding: 12px !important;
    min-height: 0 !important;
    border-radius: 14px !important;
  }

  .spellbook-detail p {
    font-size: 13px !important;
    line-height: 1.45 !important;
  }
}

/* v21b mobile polish: one-screen battle and readable compact hand */
@media (max-width: 720px) {
  html, body { overflow: hidden !important; height: 100dvh !important; min-height: 100dvh !important; }
  .app {
    height: 100dvh !important;
    min-height: 100dvh !important;
    overflow: hidden !important;
    padding: 6px 8px 90px !important;
  }
  #screen-battle.active {
    height: calc(100dvh - 96px) !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }
  .top-bar {
    position: relative !important;
    top: auto !important;
    min-height: 48px !important;
    height: 48px !important;
    padding: 6px 8px !important;
    margin-bottom: 6px !important;
    align-items: center !important;
  }
  .top-actions .ghost-btn { padding: 8px 9px !important; font-size: 12px !important; }
  #battle-title { font-size: 16px !important; line-height: 1.1 !important; }
  .battle-layout,
  .battle-layout.log-collapsed,
  .battle-layout:not(.log-collapsed) { gap: 6px !important; height: 100% !important; overflow: hidden !important; }

  .info-card.enemy-info,
  .info-card.player-info {
    padding: 8px 10px 10px !important;
    border-radius: 15px !important;
    flex: 0 0 auto !important;
  }
  .info-card h3 { font-size: 15px !important; margin-bottom: 2px !important; }
  .info-card p { font-size: 11px !important; margin-bottom: 3px !important; }
  .hp-wrap { height: 9px !important; margin: 4px 0 3px !important; }
  .stats { gap: 4px !important; margin-top: 5px !important; }
  .stat { font-size: 10.5px !important; padding: 4px 5px !important; border-radius: 8px !important; }

  /* During battle, level and XP are not needed in the player card. */
  .player-info .xp-wrap,
  #player-xp { display: none !important; }

  .arena {
    height: clamp(176px, 26dvh, 215px) !important;
    min-height: 176px !important;
    max-height: 215px !important;
    grid-template-rows: 1fr 34px 1fr !important;
    border-radius: 16px !important;
    flex: 0 1 auto !important;
  }
  .avatar { font-size: clamp(42px, 11vw, 58px) !important; }
  .spell-lane { min-height: 34px !important; }
  .stand-shadow { width: 80px !important; height: 11px !important; }
  .player-visual .stand-shadow { top: 68px !important; }

  .hand-section {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    margin: 0 !important;
    padding: 8px 8px max(10px, env(safe-area-inset-bottom)) !important;
    min-height: 86px !important;
    background: linear-gradient(180deg, rgba(17,19,31,.70), rgba(17,19,31,.99) 35%) !important;
  }
  .spell-hand,
  .spell-hand[style] { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; gap: 6px !important; }
  .spell-hand .card {
    min-height: 64px !important;
    height: 64px !important;
    padding: 6px 4px !important;
    border-radius: 13px !important;
    overflow: hidden !important;
  }
  .spell-hand .card h3 {
    display: block !important;
    color: #fff !important;
    font-size: 11px !important;
    line-height: 1.15 !important;
    max-width: 100% !important;
    white-space: normal !important;
    overflow-wrap: anywhere !important;
    text-align: center !important;
  }
  .spell-hand .card p,
  .spell-hand .card small { display: none !important; }
}

/* v21c: restore mobile page scrolling while keeping the hand fixed at the bottom. */
@media (max-width: 720px) {
  html, body {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    height: auto !important;
    min-height: 100dvh !important;
  }
  .app {
    height: auto !important;
    min-height: 100dvh !important;
    overflow: visible !important;
    padding-bottom: 108px !important;
  }
  #screen-battle.active,
  .battle-layout,
  .battle-layout.log-collapsed,
  .battle-layout:not(.log-collapsed) {
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }
  .hand-section {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 50 !important;
  }
}


/* v22: real pixel-art arena and diagonal combat staging */
.arena {
  background-image: linear-gradient(180deg, rgba(5,7,16,.10), rgba(5,7,16,.18)), var(--arena-bg, url("assets/battle_arena.png")) !important;
  background-size: cover !important;
  background-position: center center !important;
  display: block !important;
  position: relative !important;
  overflow: hidden !important;
  min-height: 430px;
}
.spell-lane {
  position: absolute !important;
  inset: 0 !important;
  border: 0 !important;
  min-height: 0 !important;
  pointer-events: none !important;
  z-index: 6 !important;
}
.fighter-visual {
  position: absolute !important;
  display: block !important;
  min-height: 0 !important;
  padding: 0 !important;
  z-index: 3;
  transition: filter .2s ease;
}
.enemy-visual {
  right: 9% !important;
  top: 10% !important;
  width: 27% !important;
  max-width: 260px !important;
  min-width: 112px !important;
  z-index: 3;
}
.player-visual {
  left: 4% !important;
  bottom: 4% !important;
  width: 34% !important;
  max-width: 310px !important;
  min-width: 135px !important;
  z-index: 5;
}
.avatar {
  font-size: 0 !important;
  line-height: 0 !important;
  filter: none !important;
  position: relative !important;
  z-index: 2 !important;
}
.fighter-img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  image-rendering: auto;
  filter: drop-shadow(0 18px 18px rgba(0,0,0,.55));
}
.enemy-img {
  transform: scaleX(-1);
  filter: drop-shadow(0 12px 14px rgba(0,0,0,.48));
}
.stand-shadow {
  position: absolute !important;
  left: 50% !important;
  transform: translateX(-50%) !important;
  bottom: -3% !important;
  width: 65% !important;
  height: 10% !important;
  background: rgba(0,0,0,.35) !important;
  border-radius: 50% !important;
  filter: blur(5px) !important;
  z-index: 1 !important;
}
.player-visual .stand-shadow { top: auto !important; bottom: -4% !important; }
.effect-layer {
  position: absolute !important;
  inset: -10% !important;
  z-index: 8 !important;
  border-radius: 22px;
}
.projectile {
  position: absolute !important;
  left: 18% !important;
  top: 76% !important;
  font-size: clamp(28px, 5vw, 52px) !important;
  z-index: 9 !important;
  opacity: 0;
  transform-origin: center;
  text-shadow: 0 0 18px rgba(255,209,102,.75), 0 0 30px rgba(255,77,109,.35);
}
.projectile.to-enemy { display:block; animation:flyDiagToEnemy .68s cubic-bezier(.18,.78,.22,1); }
.projectile.to-player { display:block; animation:flyDiagToPlayer .68s cubic-bezier(.18,.78,.22,1); }
.projectile.miss-enemy { display:block; animation:missDiagToEnemy .78s ease; }
.projectile.miss-player { display:block; animation:missDiagToPlayer .78s ease; }
@keyframes flyDiagToEnemy {
  0% { opacity:0; transform:translate(0,0) scale(.55) rotate(-25deg); }
  14% { opacity:1; }
  72% { opacity:1; transform:translate(56vw,-46vh) scale(1.05) rotate(22deg); }
  100% { opacity:0; transform:translate(61vw,-50vh) scale(1.18) rotate(34deg); }
}
@keyframes flyDiagToPlayer {
  0% { opacity:0; left: 72%; top: 23%; transform:translate(0,0) scale(.55) rotate(155deg); }
  14% { opacity:1; }
  72% { opacity:1; left: 72%; top: 23%; transform:translate(-52vw,47vh) scale(1.05) rotate(196deg); }
  100% { opacity:0; left: 72%; top: 23%; transform:translate(-57vw,51vh) scale(1.18) rotate(206deg); }
}
@keyframes missDiagToEnemy {
  0% { opacity:0; transform:translate(0,0) scale(.55) rotate(-25deg); }
  16% { opacity:1; }
  100% { opacity:0; transform:translate(64vw,-28vh) scale(.9) rotate(52deg); }
}
@keyframes missDiagToPlayer {
  0% { opacity:0; left:72%; top:23%; transform:translate(0,0) scale(.55) rotate(155deg); }
  16% { opacity:1; }
  100% { opacity:0; left:72%; top:23%; transform:translate(-62vw,30vh) scale(.9) rotate(125deg); }
}
.enemy-visual.hit-knock { animation:enemyHitKnock .42s ease; }
.player-visual.hit-knock { animation:playerHitKnock .42s ease; }
@keyframes enemyHitKnock {
  0%,100% { translate:0 0; filter:brightness(1); }
  22% { translate:8px -5px; filter:brightness(1.55); }
  45% { translate:-4px 3px; }
  70% { translate:3px 0; }
}
@keyframes playerHitKnock {
  0%,100% { translate:0 0; filter:brightness(1); }
  22% { translate:-9px 6px; filter:brightness(1.55); }
  45% { translate:5px -2px; }
  70% { translate:-3px 0; }
}

@media (max-width: 720px) {
  .arena {
    height: clamp(260px, 36dvh, 360px) !important;
    min-height: 260px !important;
    max-height: 360px !important;
    background-position: center center !important;
    border-radius: 18px !important;
  }
  .enemy-visual {
    right: 7% !important;
    top: 10% !important;
    width: 31% !important;
    min-width: 92px !important;
  }
  .player-visual {
    left: 2% !important;
    bottom: 3% !important;
    width: 39% !important;
    min-width: 116px !important;
  }
  .projectile {
    left: 21% !important;
    top: 77% !important;
    font-size: 30px !important;
  }
  @keyframes flyDiagToEnemy {
    0% { opacity:0; transform:translate(0,0) scale(.55) rotate(-25deg); }
    14% { opacity:1; }
    72% { opacity:1; transform:translate(54vw,-25vh) scale(1.05) rotate(22deg); }
    100% { opacity:0; transform:translate(58vw,-28vh) scale(1.18) rotate(34deg); }
  }
  @keyframes flyDiagToPlayer {
    0% { opacity:0; left: 72%; top: 24%; transform:translate(0,0) scale(.55) rotate(155deg); }
    14% { opacity:1; }
    72% { opacity:1; left: 72%; top: 24%; transform:translate(-52vw,26vh) scale(1.05) rotate(196deg); }
    100% { opacity:0; left: 72%; top: 24%; transform:translate(-56vw,29vh) scale(1.18) rotate(206deg); }
  }
  @keyframes missDiagToEnemy {
    0% { opacity:0; transform:translate(0,0) scale(.55) rotate(-25deg); }
    16% { opacity:1; }
    100% { opacity:0; transform:translate(58vw,-12vh) scale(.9) rotate(52deg); }
  }
  @keyframes missDiagToPlayer {
    0% { opacity:0; left:72%; top:24%; transform:translate(0,0) scale(.55) rotate(155deg); }
    16% { opacity:1; }
    100% { opacity:0; left:72%; top:24%; transform:translate(-58vw,14vh) scale(.9) rotate(125deg); }
  }
}


/* v22b: precise arena depth, projectile paths, and cleaner hit feedback */
.arena { isolation: isolate !important; }
.enemy-visual {
  right: 14% !important;
  top: 17% !important;
  width: 26% !important;
  z-index: 2 !important;
}
.player-visual { z-index: 4 !important; }
.spell-lane {
  z-index: 3 !important;
  overflow: visible !important;
}
.effect-layer {
  z-index: 5 !important;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  border-radius: 0 !important;
}
.flash-hit,
.flash-shield,
.flash-heal,
.flash-miss,
.luck-flash,
.deflect {
  background: transparent !important;
  box-shadow: none !important;
  border: 0 !important;
}
@keyframes hitFlashClean { 0%{opacity:0;transform:scale(.72)} 22%{opacity:1;transform:scale(1.05);filter:drop-shadow(0 0 14px rgba(255,77,109,.85))} 100%{opacity:0;transform:scale(1.24)} }
@keyframes shieldFlashClean { 0%{opacity:0;transform:scale(.75)} 25%{opacity:1;transform:scale(1.08);filter:drop-shadow(0 0 16px rgba(92,225,230,.8))} 100%{opacity:0;transform:scale(1.22)} }
@keyframes healFlashClean { 0%{opacity:0;transform:scale(.75)} 25%{opacity:1;transform:scale(1.08);filter:drop-shadow(0 0 16px rgba(157,243,196,.75))} 100%{opacity:0;transform:scale(1.22)} }
@keyframes missFlashClean { 0%{opacity:0;transform:translateX(0) scale(.86)} 30%{opacity:1;transform:translateX(12px) scale(1.03)} 100%{opacity:0;transform:translateX(-22px) scale(1.08)} }
.flash-hit, .luck-flash { animation:hitFlashClean .55s ease !important; }
.flash-shield, .deflect { animation:shieldFlashClean .65s ease !important; }
.flash-heal { animation:healFlashClean .65s ease !important; }
.flash-miss { animation:missFlashClean .58s ease !important; }

.projectile {
  position: absolute !important;
  display: block;
  z-index: 3 !important;
  opacity: 0;
  width: auto !important;
  height: auto !important;
  min-width: 0 !important;
  min-height: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  border: 0 !important;
  outline: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  pointer-events: none !important;
  transform: translate(-50%,-50%) scale(.45) rotate(var(--angle, 0deg));
  text-shadow: 0 0 14px rgba(255,209,102,.9), 0 0 28px rgba(255,77,109,.45);
  will-change: transform, opacity;
}
.projectile.hidden { display:none !important; }
.projectile.hit-vector { animation:flyVectorHit .72s cubic-bezier(.18,.78,.22,1) forwards !important; }
.projectile.miss-vector { animation:flyVectorMiss .82s cubic-bezier(.23,.68,.25,1) forwards !important; }
.projectile.to-enemy,
.projectile.to-player,
.projectile.miss-enemy,
.projectile.miss-player { animation: none !important; }
@keyframes flyVectorHit {
  0% { opacity:0; transform:translate(-50%,-50%) translate(0,0) scale(.45) rotate(calc(var(--angle,0deg) - 18deg)); }
  10% { opacity:1; }
  78% { opacity:1; transform:translate(-50%,-50%) translate(calc(var(--dx) * .95), calc(var(--dy) * .95)) scale(1.03) rotate(calc(var(--angle,0deg) + 10deg)); }
  100% { opacity:0; transform:translate(-50%,-50%) translate(var(--dx), var(--dy)) scale(1.16) rotate(calc(var(--angle,0deg) + 18deg)); }
}
@keyframes flyVectorMiss {
  0% { opacity:0; transform:translate(-50%,-50%) translate(0,0) scale(.45) rotate(calc(var(--angle,0deg) - 16deg)); }
  10% { opacity:1; }
  72% { opacity:1; }
  100% { opacity:0; transform:translate(-50%,-50%) translate(var(--dx), var(--dy)) scale(.9) rotate(calc(var(--angle,0deg) + 36deg)); }
}
.enemy-visual .stand-shadow {
  bottom: -1% !important;
  width: 72% !important;
  height: 12% !important;
}
@media (max-width: 720px) {
  .enemy-visual {
    right: 12% !important;
    top: 16% !important;
    width: 30% !important;
  }
  .projectile { font-size: 30px !important; }
}

.arena {
  position: relative;
  overflow: hidden;
}

.duel-projectile {
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
}

/* החלשה */
.fx-debuff {
  filter: hue-rotate(-40deg) saturate(0.6);
  transform: scale(0.95);
  transition: all 0.3s ease;
}

/* חיזוק */
.fx-buff {
  filter: hue-rotate(80deg) saturate(1.4);
  transform: scale(1.05);
  transition: all 0.3s ease;
}

/* ריפוי */
.fx-heal {
  filter: drop-shadow(0 0 10px rgba(0,255,100,0.8));
  transform: scale(1.08);
}

/* מגן */
.fx-shield {
  filter: drop-shadow(0 0 12px rgba(0,150,255,0.9));
  transform: scale(1.06);
}

/* v23 balance/mobile/audio fixes */
.sound-toggle{
  min-width: 88px;
}

@media (max-width: 720px) {
  .top-actions {
    gap: 5px !important;
  }
  .top-actions .ghost-btn {
    padding: 7px 7px !important;
    font-size: 11px !important;
  }
  .sound-toggle {
    min-width: 70px !important;
  }
  .info-card h3 {
    font-size: 14px !important;
    line-height: 1.1 !important;
  }
  .info-card p,
  #enemy-level,
  #enemy-hp,
  #player-house,
  #player-hp,
  #player-xp {
    font-size: 10.5px !important;
    line-height: 1.2 !important;
  }
  .stat {
    font-size: 9.7px !important;
    padding: 3px 4px !important;
  }
  .turn-badge {
    font-size: 12px !important;
    padding: 6px 11px !important;
  }
  .enemy-visual {
    right: 18% !important;
    top: 23% !important;
    width: 29% !important;
    min-width: 88px !important;
  }
  .player-visual {
    left: 3% !important;
    bottom: 4% !important;
    width: 37% !important;
    min-width: 110px !important;
  }
  .spell-hand .card h3 {
    font-size: 10.2px !important;
    line-height: 1.1 !important;
  }
}

/* v24: balance + mobile polish */
:root{
  --gold:#ffd166;
  --panel:rgba(255,255,255,.09);
  --panel-strong:rgba(255,255,255,.13);
}
body{
  background:
    radial-gradient(circle at 18% 12%, rgba(255,209,102,.16), transparent 34%),
    radial-gradient(circle at 80% 18%, rgba(128,93,255,.18), transparent 36%),
    linear-gradient(135deg,#120d21 0%,#1b1730 42%,#0b1224 100%) !important;
}
.card,.info-card,.arena,.modal-box{
  backdrop-filter: blur(10px);
}
.card{
  transition: transform .16s ease, border-color .16s ease, background .16s ease, box-shadow .16s ease;
}
.card:not(.disabled):hover{
  transform: translateY(-2px);
  border-color: rgba(255,209,102,.55);
  box-shadow: 0 14px 30px rgba(0,0,0,.24);
}
.spell-hand .card h3{
  font-size: clamp(15px,1.6vw,18px);
  margin-bottom: 6px;
}
.spell-hand .card p{
  font-size: clamp(12px,1.15vw,14px);
  line-height: 1.35;
}
.top-actions .sound-toggle{
  border-color: rgba(255,209,102,.45) !important;
}
.fighter-img{
  max-width: min(34vw,220px);
  max-height: min(30vh,220px);
  object-fit: contain;
}
.enemy-img{
  transform: translate(-10px, 10px) scale(1.02);
}
.player-visual .fighter-img{
  max-height: min(25vh,190px);
}
.arena::before{
  content:"";
  position:absolute;
  inset:0;
  pointer-events:none;
  background:
    radial-gradient(ellipse at center, transparent 28%, rgba(0,0,0,.16) 100%),
    linear-gradient(90deg, transparent, rgba(255,255,255,.04), transparent);
  z-index:0;
}
.fighter-visual,.spell-lane{z-index:1;}
@media(max-width:900px){
  .top-bar{
    height:auto !important;
    align-items:stretch !important;
    flex-direction:column !important;
    gap:8px !important;
  }
  .top-bar h2{font-size:20px !important; line-height:1.15 !important;}
  .top-actions{
    display:grid !important;
    grid-template-columns:repeat(4,minmax(0,1fr));
    gap:6px !important;
  }
  .top-actions button{
    font-size:11px !important;
    padding:7px 5px !important;
    min-height:34px !important;
  }
  .battle-layout,
  .battle-layout.log-collapsed,
  .battle-layout:not(.log-collapsed){
    gap:8px !important;
  }
  .right-panel{
    display:grid !important;
    grid-template-columns:1fr 1fr !important;
    gap:8px !important;
    padding-bottom:4px !important;
  }
  .info-card.enemy-info,
  .info-card.player-info{
    margin:0 !important;
    padding:10px !important;
  }
  .info-card h3{font-size:15px !important; margin-bottom:3px !important;}
  .info-card p{font-size:11px !important; margin:3px 0 !important;}
  .stats{gap:4px !important; grid-template-columns:repeat(2,minmax(0,1fr)) !important;}
  .stat{font-size:10.5px !important; padding:4px 5px !important; border-radius:7px !important;}
  .arena-column{grid-template-rows:390px auto !important; gap:8px !important;}
  .arena{min-height:390px !important; grid-template-rows:1fr 64px 1fr !important; border-radius:18px !important;}
  .fighter-img{max-width:170px !important; max-height:155px !important;}
  .enemy-img{transform: translate(-28px, 24px) scale(.98) !important;}
  .enemy-visual{padding-bottom:20px !important;}
  .player-visual{padding-top:4px !important;}
  .stand-shadow{width:92px !important; height:14px !important; bottom:18px !important;}
  .player-visual .stand-shadow{top:88px !important;}
  .hand-section h3{font-size:15px !important; margin:4px 0 6px !important;}
  .spell-hand{gap:7px !important;}
  .spell-hand .card{min-height:96px !important; padding:8px !important;}
  .spell-hand .card h3{font-size:13px !important;}
  .spell-hand .card p{font-size:11px !important; line-height:1.25 !important;}
  .spell-hand .card small{font-size:10px !important;}
  .profile-mini{font-size:10px !important; padding:5px 7px !important;}
  .modal-box{padding:14px !important; width:94vw !important;}
}
@media(max-width:520px){
  .right-panel{grid-template-columns:1fr !important;}
  .arena-column{grid-template-rows:360px auto !important;}
  .arena{min-height:360px !important;}
  .fighter-img{max-width:150px !important; max-height:138px !important;}
  .enemy-img{transform: translate(-34px, 28px) scale(.96) !important;}
  .spell-hand{grid-template-columns:repeat(2,minmax(0,1fr)) !important;}
}

/* v28 local two-player flow */
.pvp-grid{
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:18px;
  width:min(1100px,100%);
  margin:20px auto;
}
.pvp-select-card{
  display:flex;
  flex-direction:column;
  gap:12px;
}
.pvp-current{
  border:1px solid rgba(255,255,255,.16);
  border-radius:14px;
  padding:10px 12px;
  background:rgba(255,255,255,.06);
}
.pvp-create-row{
  display:grid;
  grid-template-columns:1fr auto;
  gap:8px;
}
.pvp-create-row input{
  min-width:0;
  border-radius:12px;
  border:1px solid rgba(255,255,255,.18);
  background:rgba(0,0,0,.28);
  color:inherit;
  padding:10px 12px;
  font:inherit;
}
.compact-save-list{
  max-height:42vh;
  overflow:auto;
  padding-inline:4px;
}
.card.disabled{
  opacity:.42;
  pointer-events:none;
}
@media (max-width:760px){
  .pvp-grid{grid-template-columns:1fr;gap:12px;margin-top:12px;}
  .pvp-create-row{grid-template-columns:1fr;}
  .compact-save-list{max-height:32vh;}
}

/* v30: per-enemy arena backgrounds and clearer enemy action feedback */
.arena{
  background-size: cover !important;
  background-position: center center !important;
}
.combat-cue{
  position:absolute;
  transform:translate(-50%,-50%);
  z-index:12;
  pointer-events:none;
  max-width:min(260px,60vw);
  padding:7px 12px;
  border-radius:999px;
  background:rgba(6,8,18,.72);
  border:1px solid rgba(255,255,255,.22);
  color:#fff;
  font-weight:900;
  font-size:clamp(13px,2.2vw,19px);
  line-height:1.15;
  text-align:center;
  white-space:nowrap;
  text-shadow:0 2px 10px rgba(0,0,0,.65);
  box-shadow:0 10px 26px rgba(0,0,0,.26);
}
.combat-cue.enemy-attack{
  background:rgba(70,17,24,.78);
  border-color:rgba(255,97,97,.42);
}
.combat-cue.enemy-shield{
  background:rgba(19,43,72,.78);
  border-color:rgba(130,193,255,.45);
}
.combat-cue.enemy-buff{
  background:rgba(31,76,42,.78);
  border-color:rgba(126,255,160,.42);
}
.combat-cue.enemy-control{
  background:rgba(63,40,92,.78);
  border-color:rgba(208,159,255,.42);
}
@media(max-width:720px){
  .combat-cue{font-size:12px; padding:6px 9px; max-width:72vw;}
}


/* v31 character type controls */
.character-type-select{
  width:100%;
  border:1px solid rgba(255,255,255,.18);
  background:rgba(8,10,22,.72);
  color:#fff;
  border-radius:14px;
  padding:12px 14px;
  font:inherit;
  outline:none;
}
.pvp-create-row .character-type-select{
  min-width:110px;
  flex:0 0 120px;
}
.preview-wizard-img{
  width:82px;
  height:82px;
  object-fit:contain;
  vertical-align:middle;
  filter:drop-shadow(0 10px 16px rgba(0,0,0,.35));
}
.combat-cue{
  max-width:220px;
  padding-inline:10px;
  white-space:normal;
  text-align:center;
  line-height:1.15;
}
@media (max-width: 720px){
  .pvp-create-row{flex-wrap:wrap;}
  .pvp-create-row .character-type-select{flex:1 1 100%;}
  .preview-wizard-img{width:64px;height:64px;}
  .combat-cue{max-width:160px;font-size:.86rem;}
}


/* v32: restore player/enemy visual proportions after character variants */
.player-visual{
  left: 3% !important;
  bottom: 1% !important;
  width: 41% !important;
  max-width: 390px !important;
  min-width: 180px !important;
  z-index: 5 !important;
}
.enemy-visual{
  right: 9% !important;
  top: 12% !important;
  width: 23% !important;
  max-width: 220px !important;
  min-width: 96px !important;
}
.player-visual .fighter-img{
  max-width: min(41vw, 390px) !important;
  max-height: min(44vh, 300px) !important;
}
.enemy-visual .fighter-img{
  max-width: min(26vw, 220px) !important;
  max-height: min(29vh, 215px) !important;
}
@media(max-width:720px){
  .player-visual{left:2% !important; bottom:0 !important; width:44% !important; min-width:145px !important;}
  .enemy-visual{right:6% !important; top:16% !important; width:25% !important;}
  .player-visual .fighter-img{max-width:190px !important; max-height:180px !important;}
  .enemy-visual .fighter-img{max-width:145px !important; max-height:135px !important;}
}
@media(max-width:520px){
  .player-visual .fighter-img{max-width:170px !important; max-height:160px !important;}
  .enemy-visual .fighter-img{max-width:130px !important; max-height:122px !important;}
}

/* v33: code/UI positioning pass - larger near player, enemy grounded better */
.arena{
  overflow: hidden !important;
}
.player-visual{
  left: -1% !important;
  bottom: -19% !important;
  width: 58% !important;
  max-width: 560px !important;
  min-width: 250px !important;
  z-index: 5 !important;
}
.player-visual .fighter-img{
  max-width: min(58vw, 560px) !important;
  max-height: min(72vh, 520px) !important;
}
.player-visual .stand-shadow{
  display: none !important;
}
.enemy-visual{
  right: 15% !important;
  top: 18% !important;
  width: 22% !important;
  max-width: 215px !important;
  min-width: 96px !important;
}
.enemy-visual .fighter-img{
  max-width: min(24vw, 215px) !important;
  max-height: min(31vh, 220px) !important;
}
.combat-cue.player-action{
  background:rgba(31,24,78,.80);
  border-color:rgba(255,209,102,.45);
  box-shadow:0 0 28px rgba(255,209,102,.16), 0 10px 26px rgba(0,0,0,.28);
}
@media(max-width:720px){
  .player-visual{
    left:-4% !important;
    bottom:-14% !important;
    width:58% !important;
    min-width:205px !important;
  }
  .player-visual .fighter-img{
    max-width:260px !important;
    max-height:275px !important;
  }
  .enemy-visual{
    right:13% !important;
    top:23% !important;
    width:25% !important;
  }
  .enemy-visual .fighter-img{
    max-width:145px !important;
    max-height:150px !important;
  }
}
@media(max-width:520px){
  .player-visual{
    left:-6% !important;
    bottom:-13% !important;
    min-width:190px !important;
  }
  .player-visual .fighter-img{
    max-width:230px !important;
    max-height:245px !important;
  }
  .enemy-visual{
    right:12% !important;
    top:24% !important;
  }
  .enemy-visual .fighter-img{
    max-width:128px !important;
    max-height:136px !important;
  }
}

/* v34 mobile restoration and battle composition fixes */
@media (max-width: 720px){
  html, body{
    height:100%;
    overflow:hidden !important;
  }
  body{
    overscroll-behavior:none;
  }
  .app{
    width:100vw !important;
    height:100dvh !important;
    padding:10px 8px !important;
    overflow:hidden !important;
  }
  h1{font-size:30px !important; line-height:1.05 !important; text-align:center;}
  .subtitle{font-size:16px !important; text-align:center;}

  /* Home: keep the 3 game-mode buttons inside the viewport */
  #screen-home{overflow:hidden !important; padding-inline:2px;}
  #screen-home .home-actions{
    display:grid !important;
    grid-template-columns:repeat(3,minmax(0,1fr)) !important;
    gap:8px !important;
    width:100% !important;
    margin-top:22px !important;
    direction:rtl;
  }
  #screen-home .big-btn{
    width:100% !important;
    min-width:0 !important;
    font-size:20px !important;
    line-height:1.15 !important;
    padding:18px 6px !important;
    min-height:112px !important;
    white-space:normal !important;
    overflow-wrap:anywhere;
    border-radius:16px !important;
  }

  /* Character setup: no tiny floating character in the details card */
  #screen-setup{
    overflow:auto !important;
    padding-bottom:10px !important;
  }
  #screen-setup .character-preview{
    padding:14px !important;
    margin:12px 0 !important;
  }
  #screen-setup .preview-grid{
    display:grid !important;
    grid-template-columns:1fr !important;
    gap:8px !important;
    text-align:center !important;
  }
  #screen-setup .preview-avatar{
    order:2;
    height:105px !important;
    overflow:hidden !important;
    display:flex !important;
    justify-content:center !important;
    align-items:flex-start !important;
    font-size:58px !important;
    opacity:.95;
  }
  #screen-setup .preview-wizard-img{
    width:150px !important;
    height:150px !important;
    object-fit:contain !important;
    transform:translateY(-8px) !important;
  }
  #screen-setup .preview-grid > div:last-child{order:1;}
  #screen-setup .preview-grid h2{font-size:26px !important; margin-bottom:6px !important;}
  #screen-setup .preview-grid p{font-size:18px !important; line-height:1.25 !important;}
  #screen-setup .stats{gap:6px !important;}
  #screen-setup .stat{font-size:16px !important; padding:8px !important;}

  /* Battle screen: compact no-scroll mobile layout */
  #screen-battle{
    height:100dvh !important;
    overflow:hidden !important;
  }
  #screen-battle .top-bar{
    height:78px !important;
    min-height:78px !important;
    display:flex !important;
    flex-direction:column !important;
    align-items:stretch !important;
    gap:5px !important;
    margin-bottom:5px !important;
    padding:0 !important;
  }
  #screen-battle .top-bar > div:first-child{
    display:flex !important;
    align-items:center !important;
    justify-content:space-between !important;
    gap:8px !important;
    min-height:25px !important;
  }
  #screen-battle .top-bar h2{
    font-size:18px !important;
    margin:0 !important;
    line-height:1.1 !important;
    white-space:nowrap !important;
  }
  #battle-subtitle{display:none !important;}
  #screen-battle .top-actions{
    display:grid !important;
    grid-template-columns:repeat(4,minmax(0,1fr)) !important;
    gap:5px !important;
  }
  #screen-battle .top-actions button{
    font-size:11px !important;
    padding:7px 3px !important;
    min-height:34px !important;
    border-radius:12px !important;
    white-space:nowrap !important;
  }

  #battle-layout{
    height:calc(100dvh - 93px) !important;
    max-height:calc(100dvh - 93px) !important;
    display:flex !important;
    flex-direction:column !important;
    gap:5px !important;
    overflow:hidden !important;
    min-height:0 !important;
  }
  #battle-layout .right-panel,
  #battle-layout .arena-column{
    display:contents !important;
  }
  #battle-layout .enemy-info{order:1;}
  #battle-layout .turn-badge{display:none !important;}
  #battle-layout .arena{order:2;}
  #battle-layout .player-info{order:3;}
  #battle-layout .hand-section{order:4;}
  #battle-layout .log-panel{display:none !important;}

  #battle-layout .info-card{
    flex:0 0 auto !important;
    min-height:0 !important;
    margin:0 !important;
    padding:7px 9px !important;
    border-radius:14px !important;
    overflow:hidden !important;
  }
  #battle-layout .info-card h3{
    font-size:18px !important;
    line-height:1.05 !important;
    margin:0 0 2px !important;
  }
  #battle-layout .info-card p{
    font-size:12px !important;
    line-height:1.1 !important;
    margin:2px 0 !important;
  }
  #battle-layout .hp-wrap,
  #battle-layout .xp-wrap{
    height:10px !important;
    margin:4px 0 !important;
  }
  #battle-layout .stats{
    grid-template-columns:repeat(3,minmax(0,1fr)) !important;
    gap:3px !important;
    margin-top:4px !important;
  }
  #battle-layout .stat{
    font-size:10.5px !important;
    padding:3px 4px !important;
    border-radius:7px !important;
    line-height:1.1 !important;
  }
  #battle-layout .buffs{
    display:none !important;
  }
  #player-xp{display:none !important;}

  #battle-layout .arena{
    flex:1 1 auto !important;
    min-height:250px !important;
    height:auto !important;
    max-height:none !important;
    border-radius:16px !important;
    grid-template-rows:1fr !important;
    position:relative !important;
  }
  #battle-layout .spell-lane{
    position:absolute !important;
    inset:0 !important;
    border:0 !important;
    z-index:6 !important;
  }
  #battle-layout .fighter-visual{
    position:absolute !important;
    display:block !important;
    place-items:initial !important;
    min-height:0 !important;
    padding:0 !important;
  }
  #battle-layout .player-visual{
    left:-8% !important;
    bottom:-25% !important;
    width:58% !important;
    min-width:210px !important;
    max-width:310px !important;
    height:auto !important;
    z-index:4 !important;
  }
  #battle-layout .player-visual .fighter-img{
    width:100% !important;
    max-width:none !important;
    max-height:none !important;
    height:auto !important;
    object-fit:contain !important;
  }
  #battle-layout .enemy-visual{
    right:8% !important;
    top:19% !important;
    width:31% !important;
    min-width:110px !important;
    max-width:170px !important;
    height:auto !important;
    z-index:4 !important;
  }
  #battle-layout .enemy-visual .fighter-img{
    width:100% !important;
    max-width:none !important;
    max-height:none !important;
    height:auto !important;
    object-fit:contain !important;
  }
  #battle-layout .stand-shadow{display:none !important;}

  #battle-layout .hand-section{
    flex:0 0 auto !important;
    min-height:0 !important;
    overflow:hidden !important;
  }
  #battle-layout .hand-section h3{
    display:none !important;
  }
  #battle-layout .spell-hand,
  #battle-layout .spell-hand[style]{
    display:grid !important;
    grid-template-columns:repeat(4,minmax(0,1fr)) !important;
    gap:5px !important;
  }
  #battle-layout .spell-hand .card{
    min-height:82px !important;
    padding:7px 5px !important;
    border-radius:14px !important;
    display:flex !important;
    flex-direction:column !important;
    justify-content:center !important;
    align-items:center !important;
    text-align:center !important;
  }
  #battle-layout .spell-hand .card h3{
    font-size:12px !important;
    margin:0 !important;
    line-height:1.12 !important;
  }
  #battle-layout .spell-hand .card p,
  #battle-layout .spell-hand .card small{
    display:none !important;
  }
}

@media (max-width: 390px){
  #battle-layout .arena{min-height:225px !important;}
  #battle-layout .player-visual{left:-10% !important; bottom:-17% !important; min-width:190px !important;}
  #battle-layout .enemy-visual{right:7% !important; top:20% !important; width:30% !important; min-width:98px !important;}
  #battle-layout .spell-hand .card{min-height:74px !important; padding:6px 4px !important;}
  #battle-layout .spell-hand .card h3{font-size:11px !important;}
  #battle-layout .stat{font-size:9.7px !important; padding:3px !important;}
}

/* v34 desktop/mobile spellbook: keep list position when choosing a spell */
#spellbook-content .spellbook-spell-list{
  scroll-behavior:auto !important;
  overflow-anchor:none;
}

/* v35 mobile tune: restore battle fit, visible spell names, better fighter scale */
@media (max-width: 720px){
  /* Home buttons: keep all 3 visible and balanced */
  #screen-home .home-actions{
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 7px !important;
    padding-inline: 0 !important;
  }
  #screen-home .big-btn{
    min-height: 96px !important;
    padding: 14px 4px !important;
    font-size: clamp(16px, 5.2vw, 20px) !important;
  }

  /* Setup card: larger house icon and a bigger cropped character bust */
  #screen-setup .preview-avatar{
    order: 2 !important;
    height: 128px !important;
    overflow: hidden !important;
    position: relative !important;
    align-items: flex-start !important;
    justify-content: center !important;
    isolation: isolate;
  }
  #screen-setup .preview-wizard-img{
    width: 230px !important;
    height: 230px !important;
    max-width: none !important;
    max-height: none !important;
    object-fit: contain !important;
    transform: translateY(-20px) !important;
    z-index: 1;
  }
  #screen-setup .preview-house-icon{
    position: absolute !important;
    right: 14px !important;
    bottom: 8px !important;
    font-size: 58px !important;
    line-height: 1 !important;
    z-index: 2;
    filter: drop-shadow(0 8px 14px rgba(0,0,0,.42));
  }

  /* Battle: compact vertical rhythm, no scrolling needed */
  #screen-battle .top-bar{
    height: 72px !important;
    min-height: 72px !important;
    margin-bottom: 4px !important;
  }
  #battle-layout{
    height: calc(100dvh - 86px) !important;
    max-height: calc(100dvh - 86px) !important;
    gap: 4px !important;
  }
  #battle-layout .info-card{
    padding: 5px 8px !important;
    border-radius: 13px !important;
  }
  #battle-layout .info-card h3{
    font-size: 17px !important;
    margin: 0 0 1px !important;
  }
  #battle-layout .info-card p{
    font-size: 11px !important;
    margin: 1px 0 !important;
  }
  #battle-layout .hp-wrap,
  #battle-layout .xp-wrap{
    height: 8px !important;
    margin: 3px 0 !important;
  }
  #battle-layout .stats{
    gap: 2px !important;
    margin-top: 3px !important;
  }
  #battle-layout .stat{
    font-size: 10px !important;
    padding: 2px 3px !important;
    border-radius: 6px !important;
  }

  #battle-layout .arena{
    flex: 0 0 clamp(230px, 38dvh, 300px) !important;
    min-height: 230px !important;
    max-height: 300px !important;
    overflow: hidden !important;
  }
  #battle-layout .player-visual{
    left: -15% !important;
    bottom: -37% !important;
    width: 74% !important;
    min-width: 250px !important;
    max-width: 390px !important;
  }
  #battle-layout .enemy-visual{
    right: 12% !important; /* larger value = slightly more left */
    top: 23% !important;
    width: 38% !important;
    min-width: 132px !important;
    max-width: 210px !important;
  }

  #battle-layout .hand-section{
    flex: 0 0 auto !important;
  }
  #battle-layout .spell-hand,
  #battle-layout .spell-hand[style]{
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 4px !important;
  }
  #battle-layout .spell-hand .card{
    min-height: 70px !important;
    height: 70px !important;
    padding: 6px 4px !important;
    justify-content: center !important;
    align-items: center !important;
    overflow: hidden !important;
  }
  #battle-layout .spell-hand .card h3{
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    color: #fff !important;
    font-size: 11.5px !important;
    line-height: 1.18 !important;
    margin: 0 !important;
    max-width: 100% !important;
    overflow-wrap: anywhere !important;
    text-shadow: 0 2px 8px rgba(0,0,0,.55);
  }
  #battle-layout .spell-hand .card p,
  #battle-layout .spell-hand .card small{
    display: none !important;
  }
}

@media (max-width: 390px){
  #battle-layout .arena{
    flex-basis: clamp(220px, 36dvh, 275px) !important;
    min-height: 220px !important;
  }
  #battle-layout .player-visual{
    left: -17% !important;
    bottom: -38% !important;
    width: 78% !important;
    min-width: 245px !important;
  }
  #battle-layout .enemy-visual{
    right: 11% !important;
    top: 24% !important;
    width: 39% !important;
    min-width: 125px !important;
  }
  #battle-layout .spell-hand .card{
    min-height: 66px !important;
    height: 66px !important;
  }
  #battle-layout .spell-hand .card h3{font-size: 10.5px !important;}
}

/* v36: requested mobile code fixes only
   - setup character moved left and house icon enlarged
   - battle vertical spacing restored a bit
   - enemy slightly smaller, a touch up and right */
@media (max-width: 720px){
  #screen-setup .preview-avatar{
    justify-content:flex-start !important;
    direction:ltr !important;
    padding-left:0 !important;
  }
  #screen-setup .preview-wizard-img{
    width:238px !important;
    height:238px !important;
    transform:translate(-42px,-14px) scale(1.03) !important;
  }
  #screen-setup .preview-house-icon{
    font-size:70px !important;
    right:18px !important;
    bottom:10px !important;
  }

  #battle-layout,
  #battle-layout.log-collapsed,
  #battle-layout:not(.log-collapsed){
    gap:7px !important;
  }

  #battle-layout .arena{
    flex:0 1 clamp(224px, 36dvh, 292px) !important;
    min-height:224px !important;
    max-height:292px !important;
  }
  #battle-layout .enemy-visual{
    right:5.5% !important;
    top:17.5% !important;
    width:28% !important;
    min-width:102px !important;
    max-width:158px !important;
  }
}

@media (max-width:390px){
  #screen-setup .preview-wizard-img{
    width:230px !important;
    height:230px !important;
    transform:translate(-40px,-12px) scale(1.02) !important;
  }
  #screen-setup .preview-house-icon{
    font-size:66px !important;
  }
  #battle-layout,
  #battle-layout.log-collapsed,
  #battle-layout:not(.log-collapsed){
    gap:6px !important;
  }
  #battle-layout .arena{
    flex-basis:clamp(218px, 35dvh, 270px) !important;
    min-height:218px !important;
  }
  #battle-layout .enemy-visual{
    right:5% !important;
    top:18% !important;
    width:28% !important;
    min-width:94px !important;
    max-width:145px !important;
  }
}


/* v38: mobile flow, setup summary and troll-only grounding fixes */
.character-choice{
  display:inline-flex;
  gap:8px;
  padding:4px;
  border-radius:14px;
  background:rgba(0,0,0,.20);
  border:1px solid rgba(255,255,255,.14);
  vertical-align:middle;
}
.choice-btn{
  border-radius:12px;
  padding:11px 16px;
  background:rgba(255,255,255,.10);
  color:#fff;
  border:1px solid rgba(255,255,255,.14);
}
.choice-btn.active{
  background:rgba(255,209,102,.28);
  border-color:#ffd166;
  color:#fff7d8;
  box-shadow:0 0 0 2px rgba(255,209,102,.18);
}
.character-choice.compact .choice-btn{padding:9px 12px; min-width:48px;}
.setup-summary-row{
  display:grid;
  grid-template-columns:auto auto auto minmax(120px,1fr);
  gap:10px;
  align-items:center;
  margin-bottom:12px;
  font-size:18px;
}
.setup-summary-row strong{font-size:22px;}
.setup-xp{
  height:12px;
  border-radius:999px;
  overflow:hidden;
  background:rgba(0,0,0,.34);
  border:1px solid rgba(255,255,255,.10);
}
.setup-xp>div{
  height:100%;
  background:linear-gradient(90deg,#8ec5ff,#ffd166);
}

/* Only the troll is moved off the sinks. Other enemies keep their current position. */
.enemy-visual.enemy-key-troll{
  right:21% !important;
  top:28% !important;
}

@media (max-width:720px){
  /* Fully re-enable mobile scrolling. */
  html, body{
    height:auto !important;
    min-height:100% !important;
    overflow:auto !important;
  }
  body{overscroll-behavior:auto !important;}
  .app{
    height:auto !important;
    min-height:100dvh !important;
    overflow:visible !important;
  }
  .screen,
  .screen.active{
    height:auto !important;
    min-height:100dvh !important;
    overflow:visible !important;
  }
  #screen-home,
  #screen-battle,
  #battle-layout,
  #battle-layout.log-collapsed,
  #battle-layout:not(.log-collapsed){
    height:auto !important;
    max-height:none !important;
    overflow:visible !important;
  }
  #battle-layout .hand-section{overflow:visible !important;}

  .profile-box{display:flex; flex-direction:column; gap:10px; align-items:stretch;}
  .profile-box input{min-width:0 !important; width:100%; margin-left:0;}
  .character-choice{display:flex; width:100%;}
  .choice-btn{flex:1; font-size:16px;}
  .pvp-create-row{grid-template-columns:1fr !important;}
  .pvp-create-row .character-choice{width:100%;}

  #screen-setup .character-preview{padding:12px !important;}
  #screen-setup .preview-grid{gap:4px !important;}
  #screen-setup .setup-summary-row{
    grid-template-columns:auto auto auto minmax(72px,1fr);
    gap:6px;
    font-size:13px;
    text-align:right;
    margin-bottom:8px;
  }
  #screen-setup .setup-summary-row strong{font-size:16px;}
  #screen-setup .setup-xp{height:9px;}
  #screen-setup .preview-avatar{
    height:122px !important;
    justify-content:flex-start !important;
    align-items:flex-start !important;
    direction:ltr !important;
    padding-left:0 !important;
  }
  #screen-setup .preview-wizard-img{
    width:230px !important;
    height:230px !important;
    transform:translate(-46px,-18px) scale(1.04) !important;
  }
  #screen-setup .preview-house-icon{
    font-size:74px !important;
    right:14px !important;
    bottom:8px !important;
  }
  #screen-setup .preview-grid h2,
  #screen-setup .preview-grid p{display:none !important;}

  #battle-layout .enemy-visual.enemy-key-troll{
    right:20% !important;
    top:34% !important;
    width:30% !important;
  }
}

@media (max-width:390px){
  #screen-setup .setup-summary-row{font-size:12px; grid-template-columns:auto auto auto minmax(60px,1fr);}
  #screen-setup .setup-summary-row strong{font-size:15px;}
  #screen-setup .preview-wizard-img{
    width:220px !important;
    height:220px !important;
    transform:translate(-44px,-16px) scale(1.03) !important;
  }
  #screen-setup .preview-house-icon{font-size:70px !important;}
  #battle-layout .enemy-visual.enemy-key-troll{
    right:19% !important;
    top:35% !important;
  }
}


/* v39: cleaner setup screen with central game menu and wand popup */
#screen-setup #setup-title,
#screen-setup #setup-subtitle,
#screen-setup .setup-title,
#screen-setup #wand-list{
  display:none !important;
}
#screen-setup{
  padding-top:10px;
}
#screen-setup .character-preview{
  max-width:980px;
  margin:0 auto 18px !important;
  padding:18px 22px !important;
  min-height:0 !important;
}
.setup-topline{
  display:grid;
  grid-template-columns:auto auto auto minmax(180px,1fr);
  gap:12px;
  align-items:center;
  margin-bottom:14px;
  font-size:18px;
}
.setup-topline strong{font-size:24px;}
#screen-setup .preview-grid{
  grid-template-columns:260px 1fr !important;
  gap:20px !important;
  align-items:center !important;
}
#screen-setup .preview-avatar{
  position:relative;
  height:190px !important;
  overflow:hidden;
  display:flex !important;
  align-items:flex-start !important;
  justify-content:flex-start !important;
  direction:ltr !important;
}
#screen-setup .preview-wizard-img{
  width:270px !important;
  height:270px !important;
  transform:translate(-54px,-16px) scale(1.04) !important;
  object-fit:contain;
  max-width:none !important;
}
#screen-setup .preview-house-icon{
  position:absolute;
  right:8px !important;
  bottom:10px !important;
  font-size:84px !important;
  filter:drop-shadow(0 8px 16px rgba(0,0,0,.38));
}
.setup-details{
  display:grid;
  gap:12px;
  align-content:center;
}
.setup-stat-list{
  display:grid;
  grid-template-columns:repeat(3,minmax(0,1fr));
  gap:8px;
}
.setup-stat-list span{
  background:rgba(0,0,0,.20);
  border:1px solid rgba(255,255,255,.06);
  border-radius:12px;
  padding:10px 12px;
  color:#efeaff;
  font-size:15px;
}
.selected-wand-btn{
  width:100%;
  display:grid;
  grid-template-columns:auto 1fr auto;
  gap:12px;
  align-items:center;
  text-align:right;
  border-radius:18px;
  border:1px solid rgba(255,209,102,.58);
  background:rgba(255,209,102,.13);
  color:#fff;
  padding:14px 16px;
  box-shadow:0 10px 28px rgba(0,0,0,.18);
}
.wand-current-icon{font-size:28px;}
.wand-current-text{display:grid; gap:3px;}
.wand-current-text strong{font-size:18px;}
.wand-current-text small{font-size:13px; color:#dcd4ef; font-weight:600;}
.wand-change{
  color:#ffd166;
  font-size:13px;
  border:1px solid rgba(255,209,102,.45);
  border-radius:999px;
  padding:5px 10px;
}
#screen-setup .start-game-wrap{
  max-width:760px;
  margin:10px auto 0 !important;
  padding:16px;
  border-radius:22px;
  background:rgba(255,255,255,.065);
  border:1px solid rgba(255,255,255,.13);
  box-shadow:0 14px 36px rgba(0,0,0,.18);
  gap:12px !important;
}
#screen-setup .start-game-wrap button{
  min-width:142px;
  padding:14px 18px;
  font-size:16px;
}
.wand-modal-box{max-width:820px;}
.wand-picker-grid{margin-top:16px;}
.wand-choice-card{min-height:120px;}

@media (max-width:720px){
  #screen-setup{padding:12px 8px 18px !important;}
  #screen-setup .character-preview{
    padding:12px !important;
    margin:0 0 12px !important;
  }
  .setup-topline{
    grid-template-columns:auto auto auto minmax(70px,1fr) !important;
    gap:6px !important;
    font-size:12px !important;
    margin-bottom:8px !important;
  }
  .setup-topline strong{font-size:15px !important;}
  #screen-setup .preview-grid{
    grid-template-columns:126px 1fr !important;
    gap:8px !important;
  }
  #screen-setup .preview-avatar{
    height:132px !important;
  }
  #screen-setup .preview-wizard-img{
    width:220px !important;
    height:220px !important;
    transform:translate(-56px,-13px) scale(1.02) !important;
  }
  #screen-setup .preview-house-icon{
    font-size:58px !important;
    right:0 !important;
    bottom:8px !important;
  }
  .setup-stat-list{
    grid-template-columns:repeat(2,minmax(0,1fr)) !important;
    gap:5px !important;
  }
  .setup-stat-list span{
    padding:6px 7px !important;
    font-size:11px !important;
    border-radius:9px !important;
  }
  .selected-wand-btn{
    grid-template-columns:auto 1fr !important;
    padding:8px 10px !important;
    border-radius:13px !important;
    gap:8px !important;
  }
  .wand-current-icon{font-size:22px !important;}
  .wand-current-text strong{font-size:13px !important;}
  .wand-current-text small{display:none !important;}
  .wand-change{display:none !important;}
  #screen-setup .start-game-wrap{
    margin:10px 0 0 !important;
    padding:10px !important;
    display:grid !important;
    grid-template-columns:repeat(2,minmax(0,1fr));
  }
  #screen-setup .start-game-wrap button{
    min-width:0 !important;
    width:100% !important;
    padding:11px 8px !important;
    font-size:13px !important;
  }
  #start-adventure-btn{grid-column:1 / -1;}
  .wand-picker-grid{
    grid-template-columns:1fr !important;
    gap:10px !important;
  }
  .wand-choice-card{min-height:94px !important; padding:12px !important;}
}

@media (min-width:721px){
  #screen-setup .screen-actions-spacer{display:none;}
}

/* v40: final code/UI fixes
   - troll only: more left and lower, including mobile
   - stronger centered home screen
   - spell/action speech bubble at top of arena
*/
.enemy-visual.enemy-key-troll{
  right:30% !important;
  top:35% !important;
}

#screen-home{
  min-height:calc(100dvh - 40px);
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  text-align:center;
  padding:32px 18px !important;
}
#screen-home h1{
  font-size:clamp(46px, 7vw, 86px);
  letter-spacing:.05em;
  line-height:.95;
  margin:0;
  text-shadow:0 16px 40px rgba(0,0,0,.36);
}
#screen-home .subtitle{
  margin-top:16px;
  font-size:clamp(18px, 2.1vw, 26px);
  color:#ded7ef;
}
#screen-home .home-actions{
  width:min(780px, 100%);
  justify-content:center;
  margin-top:34px;
}
#screen-home .big-btn{
  position:relative;
  min-width:190px;
  min-height:118px;
  border-radius:26px;
  font-size:24px;
  box-shadow:0 22px 60px rgba(0,0,0,.22), inset 0 1px 0 rgba(255,255,255,.18);
}
#screen-home .big-btn:hover{
  transform:translateY(-2px);
}
#screen-home #save-list{
  width:min(820px, 100%);
  margin-top:28px;
}

.combat-cue{
  border-radius:18px !important;
  background:rgba(4,5,12,.88) !important;
  border:1px solid rgba(255,255,255,.20) !important;
  box-shadow:0 16px 38px rgba(0,0,0,.36), 0 0 22px rgba(255,209,102,.10) !important;
  padding:10px 16px 12px !important;
  color:#fff !important;
  font-size:clamp(16px,2vw,24px) !important;
  max-width:min(340px,70vw) !important;
  line-height:1.15 !important;
  white-space:normal !important;
  text-align:center !important;
}
.combat-cue::after{
  content:"";
  position:absolute;
  bottom:-9px;
  width:18px;
  height:18px;
  background:rgba(4,5,12,.88);
  border-right:1px solid rgba(255,255,255,.18);
  border-bottom:1px solid rgba(255,255,255,.18);
  transform:rotate(45deg);
}
.combat-cue.player::after{left:24px;}
.combat-cue.enemy::after{right:24px;}
.combat-cue.player-action,
.combat-cue.enemy-attack,
.combat-cue.enemy-shield,
.combat-cue.enemy-buff,
.combat-cue.enemy-control{
  background:rgba(4,5,12,.88) !important;
}
.combat-cue.enemy-attack{border-color:rgba(255,95,95,.54) !important;}
.combat-cue.enemy-shield{border-color:rgba(138,194,255,.54) !important;}
.combat-cue.enemy-buff{border-color:rgba(126,255,160,.50) !important;}
.combat-cue.enemy-control{border-color:rgba(208,159,255,.50) !important;}
.combat-cue.player-action{border-color:rgba(255,209,102,.58) !important;}

@media (max-width:720px){
  #screen-home{
    min-height:100dvh !important;
    justify-content:center !important;
    overflow:visible !important;
    padding:28px 12px !important;
  }
  #screen-home h1{
    font-size:clamp(34px, 10.5vw, 52px) !important;
    line-height:1 !important;
  }
  #screen-home .subtitle{
    font-size:clamp(15px, 4.6vw, 19px) !important;
    margin-top:12px !important;
  }
  #screen-home .home-actions{
    grid-template-columns:repeat(3,minmax(0,1fr)) !important;
    gap:8px !important;
    margin-top:24px !important;
  }
  #screen-home .big-btn{
    min-width:0 !important;
    min-height:94px !important;
    padding:14px 6px !important;
    border-radius:18px !important;
    font-size:clamp(16px, 5vw, 20px) !important;
  }
  #battle-layout .enemy-visual.enemy-key-troll{
    right:28% !important;
    top:35% !important;
    width:30% !important;
  }
  .combat-cue{
    font-size:14px !important;
    padding:8px 12px 10px !important;
    max-width:72vw !important;
    border-radius:15px !important;
  }
  .combat-cue.player::after{left:18px;}
  .combat-cue.enemy::after{right:18px;}
}

@media (max-width:390px){
  #battle-layout .enemy-visual.enemy-key-troll{
    right:27% !important;
    top:36% !important;
  }
}

/* v41 fix: the redesigned home screen must not stay visible after navigation */
#screen-home:not(.active){
  display:none !important;
}
#screen-home.active{
  display:flex !important;
}

/* Keep the New Game / Continue / PvP screens safely visible above the home layout */
#screen-new-name.active,
#screen-setup.active,
#screen-pvp-setup.active,
#screen-sorting.active,
#screen-battle.active,
#screen-game-over.active{
  display:block !important;
}

@media (max-width:720px){
  #screen-home:not(.active){display:none !important;}
  #screen-home.active{display:flex !important;}
}

/* v42: code-only positioning tune
   - lower the player so mostly upper body is visible
   - lower the troll a little more and move it left, without changing other enemies */
#battle-layout .player-visual,
.player-visual{
  bottom:-26% !important;
}

#battle-layout .enemy-visual.enemy-key-troll,
.enemy-visual.enemy-key-troll{
  right:34% !important;
  top:39% !important;
}

@media (max-width:720px){
  #battle-layout .player-visual,
  .player-visual{
    bottom:-24% !important;
  }
  #battle-layout .enemy-visual.enemy-key-troll,
  .enemy-visual.enemy-key-troll{
    right:32% !important;
    top:39% !important;
  }
}

@media (max-width:390px){
  #battle-layout .player-visual,
  .player-visual{
    bottom:-23% !important;
  }
  #battle-layout .enemy-visual.enemy-key-troll,
  .enemy-visual.enemy-key-troll{
    right:31% !important;
    top:40% !important;
  }
}

/* v45: adventure map, centered setup, and cleaner progression */
#screen-setup.active{
  display:flex !important;
  flex-direction:column;
  justify-content:center;
  min-height:100%;
}
.adventure-map-wrap{
  min-height:100%;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:22px;
  padding:24px 10px;
}
.adventure-map-head{text-align:center;}
.adventure-map-head h1{margin-bottom:8px;}
.adventure-map-grid{
  width:min(980px,96vw);
  display:grid;
  grid-template-columns:repeat(5,minmax(115px,1fr));
  gap:14px;
  direction:ltr;
}
.adventure-node{
  min-height:128px;
  border-radius:20px;
  padding:12px 10px;
  display:grid;
  place-items:center;
  gap:5px;
  position:relative;
  color:#fff;
  background:linear-gradient(180deg,rgba(255,255,255,.13),rgba(255,255,255,.055));
  border:1px solid rgba(255,255,255,.16);
  box-shadow:0 14px 34px rgba(0,0,0,.25);
  cursor:pointer;
}
.adventure-node.unlocked{border-color:rgba(255,209,102,.68);}
.adventure-node.done{background:linear-gradient(180deg,rgba(157,243,196,.18),rgba(255,255,255,.055)); border-color:rgba(157,243,196,.45);}
.adventure-node.locked{opacity:.52; filter:grayscale(1); cursor:not-allowed;}
.adventure-node .node-number{
  position:absolute;
  top:8px;
  left:9px;
  width:28px;
  height:28px;
  border-radius:999px;
  display:grid;
  place-items:center;
  background:rgba(0,0,0,.28);
  color:#ffd166;
  font-weight:900;
}
.adventure-node .node-avatar{font-size:36px; line-height:1;}
.adventure-node strong{font-size:16px; text-align:center; direction:rtl;}
.adventure-node small{font-size:12px; color:#d8d0ef; direction:rtl;}
.adventure-map-actions{margin-top:0 !important;}

/* v45: if there is a shield, harmful control spells are visually deflected; keep cue on top */
.combat-cue{z-index:8;}

@media (max-width:720px){
  #screen-setup.active{display:block !important; min-height:100dvh;}
  .adventure-map-wrap{justify-content:flex-start; padding:18px 8px 28px;}
  .adventure-map-grid{
    width:100%;
    grid-template-columns:repeat(3,minmax(0,1fr));
    gap:10px;
  }
  .adventure-node{min-height:104px; border-radius:16px; padding:10px 6px;}
  .adventure-node .node-avatar{font-size:28px;}
  .adventure-node strong{font-size:13px;}
  .adventure-node small{font-size:10px;}
}

/* v46: code-only visual direction refresh
   Inspired by: clean deckbuilder clarity + dark magical gold UI + polished card game panels.
   No generated images, only CSS/layout styling. */
:root{
  --hb-bg:#050814;
  --hb-bg2:#0b1020;
  --hb-panel:rgba(18,24,42,.86);
  --hb-panel2:rgba(28,28,54,.76);
  --hb-line:rgba(226,190,108,.30);
  --hb-line-soft:rgba(255,255,255,.13);
  --hb-gold:#d7a84d;
  --hb-gold2:#ffd773;
  --hb-text:#f6f1e4;
  --hb-muted:#c8bfdc;
  --hb-red:#ff546f;
  --hb-blue:#76b8ff;
  --hb-purple:#9d6cff;
}

html,body{
  background:
    radial-gradient(circle at 52% -12%, rgba(111,78,168,.32), transparent 42%),
    radial-gradient(circle at 7% 8%, rgba(215,168,77,.12), transparent 30%),
    linear-gradient(135deg,#080912 0%,#11122a 48%,#050711 100%) !important;
  color:var(--hb-text);
}
body::before{
  content:"";
  position:fixed;
  inset:0;
  pointer-events:none;
  background:
    linear-gradient(rgba(255,255,255,.022) 1px, transparent 1px),
    linear-gradient(90deg,rgba(255,255,255,.018) 1px, transparent 1px);
  background-size:42px 42px;
  opacity:.25;
  z-index:-1;
}
.app{width:min(1480px,98vw) !important;}

button,.primary-btn,.ghost-btn{
  letter-spacing:.01em;
  box-shadow:inset 0 1px 0 rgba(255,255,255,.12), 0 10px 24px rgba(0,0,0,.22);
  transition:transform .16s ease, box-shadow .16s ease, border-color .16s ease, background .16s ease;
}
button:hover{transform:translateY(-1px);}
.primary-btn{
  background:linear-gradient(180deg,var(--hb-gold2),#c9912e) !important;
  color:#17110a !important;
  border:1px solid rgba(255,225,126,.72) !important;
}
.ghost-btn{
  background:linear-gradient(180deg,rgba(255,255,255,.13),rgba(255,255,255,.055)) !important;
  border:1px solid rgba(255,255,255,.18) !important;
  color:#f9f4e8 !important;
}
.card,.info-card,.log-panel,.character-preview,.profile-box,.modal-box{
  background:
    linear-gradient(180deg,rgba(255,255,255,.105),rgba(255,255,255,.045)),
    radial-gradient(circle at 70% 0%,rgba(215,168,77,.12),transparent 34%) !important;
  border:1px solid var(--hb-line-soft) !important;
  box-shadow:0 20px 50px rgba(0,0,0,.28), inset 0 1px 0 rgba(255,255,255,.08) !important;
  backdrop-filter:blur(10px);
}
.card.selected,.info-card.active-turn,.adventure-node.unlocked,
.selected-wand-btn,.wand-choice-card.selected{
  border-color:rgba(255,215,115,.72) !important;
  box-shadow:0 0 0 1px rgba(255,215,115,.28),0 20px 50px rgba(0,0,0,.30),0 0 34px rgba(215,168,77,.14) !important;
}

/* Home: more polished, centered, and game-like */
#screen-home.active{
  display:flex !important;
  justify-content:center !important;
  align-items:center !important;
  gap:20px !important;
  min-height:calc(100dvh - 20px) !important;
}
#screen-home::before{
  content:"⚜";
  display:grid;
  place-items:center;
  width:58px;
  height:58px;
  border-radius:999px;
  margin-bottom:2px;
  color:var(--hb-gold2);
  border:1px solid rgba(255,215,115,.38);
  background:rgba(0,0,0,.22);
  box-shadow:0 0 34px rgba(215,168,77,.18);
  font-size:26px;
}
#screen-home h1{
  font-family:Georgia, 'Times New Roman', serif !important;
  color:#fff4d7;
  text-shadow:0 8px 26px rgba(0,0,0,.45),0 0 24px rgba(215,168,77,.12) !important;
}
#screen-home h1::after{
  content:"";
  display:block;
  width:min(360px,72vw);
  height:1px;
  margin:18px auto 0;
  background:linear-gradient(90deg,transparent,var(--hb-gold),transparent);
}
#screen-home .home-actions{
  padding:18px;
  border:1px solid rgba(255,255,255,.13);
  border-radius:28px;
  background:rgba(12,14,30,.54);
  box-shadow:0 26px 70px rgba(0,0,0,.25), inset 0 1px 0 rgba(255,255,255,.08);
}
#screen-home .big-btn{
  min-height:104px !important;
  display:grid;
  place-items:center;
  isolation:isolate;
}
#screen-home .big-btn::before{
  display:block;
  font-size:26px;
  margin-bottom:6px;
  opacity:.95;
}
#new-game-btn::before{content:"⚔️";}
#continue-game-btn::before{content:"📖";}
#pvp-game-btn::before{content:"👥";}

/* Setup/profile: cleaner RPG panel */
#screen-setup.active{
  gap:18px !important;
}
#character-preview{
  width:min(1180px,96vw) !important;
  margin-inline:auto !important;
  padding:20px 24px !important;
  border-color:rgba(215,168,77,.22) !important;
}
.setup-topline{
  display:grid !important;
  grid-template-columns:auto auto auto minmax(180px,1fr) !important;
  gap:14px !important;
  align-items:center !important;
  color:#fff4d7 !important;
  font-size:18px !important;
}
.setup-topline strong{font-size:24px;color:#fff;}
.setup-xp{
  height:12px !important;
  border-radius:999px !important;
  overflow:hidden !important;
  background:rgba(0,0,0,.35) !important;
}
.setup-xp>div{height:100%;background:linear-gradient(90deg,var(--hb-blue),var(--hb-gold2));}
#character-preview .preview-grid{
  grid-template-columns:minmax(210px,310px) 1fr !important;
  align-items:end !important;
}
.preview-avatar{
  position:relative !important;
  min-height:230px !important;
  overflow:hidden !important;
  border-radius:20px !important;
}
.preview-wizard-img{
  position:absolute !important;
  left:-12px !important;
  bottom:-48px !important;
  width:min(270px,42vw) !important;
  max-width:none !important;
  filter:drop-shadow(0 18px 24px rgba(0,0,0,.38));
}
.preview-house-icon{
  position:absolute !important;
  right:16px !important;
  bottom:28px !important;
  font-size:64px !important;
  filter:drop-shadow(0 12px 18px rgba(0,0,0,.34));
}
.setup-stat-list{
  display:grid !important;
  grid-template-columns:repeat(3,minmax(120px,1fr)) !important;
  gap:8px !important;
}
.setup-stat-list span{
  background:rgba(0,0,0,.20) !important;
  border-radius:12px !important;
  padding:10px 12px !important;
  text-align:center;
}
.selected-wand-btn{
  margin-top:14px !important;
  width:100% !important;
  display:grid !important;
  grid-template-columns:52px 1fr auto !important;
  align-items:center !important;
  gap:12px !important;
  border-radius:17px !important;
  padding:12px 16px !important;
  color:#fff !important;
  background:linear-gradient(90deg,rgba(215,168,77,.20),rgba(255,255,255,.06)) !important;
}
.wand-current-icon{font-size:34px !important;}
.wand-current-text{display:flex; flex-direction:column; gap:4px; text-align:right;}
.wand-current-text small{color:var(--hb-muted);}
.wand-change{color:var(--hb-gold2); border:1px solid rgba(255,215,115,.42); padding:6px 12px; border-radius:999px;}
#screen-setup .start-game-wrap{
  background:rgba(10,13,28,.70) !important;
  border:1px solid rgba(255,255,255,.12);
  border-radius:24px;
  padding:16px !important;
  width:min(780px,96vw) !important;
  margin-inline:auto !important;
  box-shadow:0 18px 44px rgba(0,0,0,.22);
}

/* Adventure map: stronger progression board */
.adventure-map-head h1{
  font-family:Georgia,'Times New Roman',serif;
  color:#fff1c7;
}
.adventure-map-grid{
  padding:18px !important;
  border-radius:26px;
  border:1px solid rgba(255,215,115,.16);
  background:
    radial-gradient(circle at 50% 100%,rgba(215,168,77,.11),transparent 42%),
    linear-gradient(180deg,rgba(255,255,255,.07),rgba(255,255,255,.025));
  box-shadow:0 24px 70px rgba(0,0,0,.28), inset 0 1px 0 rgba(255,255,255,.08);
}
.adventure-node{
  min-height:142px !important;
  overflow:hidden;
}
.adventure-node::after{
  content:"";
  position:absolute;
  inset:auto -12px -24px -12px;
  height:54px;
  background:radial-gradient(ellipse at center,rgba(0,0,0,.40),transparent 65%);
  opacity:.65;
}
.adventure-node.unlocked:hover{transform:translateY(-3px);}
.adventure-node.done .node-number{background:rgba(157,243,196,.20); color:#9df3c4;}
.adventure-node .node-avatar{font-size:44px !important; z-index:1;}
.adventure-node strong,.adventure-node small,.adventure-node .node-number{z-index:1;}

/* Battle polish: more card-game clarity without changing logic */
.top-bar{
  align-items:center !important;
  padding:0 4px;
}
#battle-title{
  font-family:Georgia,'Times New Roman',serif;
  color:#fff3d0;
  letter-spacing:.03em;
}
.arena{
  border-color:rgba(255,215,115,.22) !important;
  box-shadow:0 24px 70px rgba(0,0,0,.30), inset 0 1px 0 rgba(255,255,255,.08) !important;
}
.info-card h3{font-size:22px;color:#fff;}
.hp-wrap,.xp-wrap{background:rgba(0,0,0,.42) !important;}
.spell-hand .card{
  min-height:140px !important;
  border-radius:20px !important;
  display:flex;
  flex-direction:column;
  justify-content:center;
  gap:6px;
  position:relative;
  overflow:hidden;
}
.spell-hand .card::before{
  content:"";
  position:absolute;
  inset:0;
  background:radial-gradient(circle at 50% 0%,rgba(255,255,255,.12),transparent 46%);
  opacity:.7;
  pointer-events:none;
}
.spell-hand .card h3{font-size:20px;color:#fff;}
.spell-attack{background:linear-gradient(180deg,rgba(120,30,44,.52),rgba(255,255,255,.045)) !important;}
.spell-defense{background:linear-gradient(180deg,rgba(34,86,112,.42),rgba(255,255,255,.045)) !important;}
.spell-buff{background:linear-gradient(180deg,rgba(115,83,28,.42),rgba(255,255,255,.045)) !important;}
.spell-control{background:linear-gradient(180deg,rgba(70,40,130,.48),rgba(255,255,255,.045)) !important;}
.combat-cue{
  min-width:170px !important;
  background:linear-gradient(180deg,rgba(8,8,14,.94),rgba(11,10,18,.88)) !important;
  color:#fff2cc !important;
  border-color:rgba(255,215,115,.38) !important;
}

@media (max-width:720px){
  .app{width:100vw !important; padding:8px 8px 18px !important;}
  #screen-home .home-actions{
    display:grid !important;
    grid-template-columns:1fr !important;
    width:min(360px,94vw) !important;
    padding:12px !important;
  }
  #screen-home .big-btn{
    min-height:72px !important;
    font-size:19px !important;
    border-radius:17px !important;
  }
  #screen-home .big-btn::before{display:inline; margin:0 0 0 8px; font-size:20px;}
  #character-preview{padding:14px !important;}
  .setup-topline{
    grid-template-columns:auto auto auto !important;
    row-gap:8px !important;
    font-size:14px !important;
  }
  .setup-topline strong{font-size:19px;}
  .setup-xp{grid-column:1 / -1;}
  #character-preview .preview-grid{
    grid-template-columns:1fr !important;
  }
  .preview-avatar{min-height:170px !important;}
  .preview-wizard-img{left:4px !important; bottom:-52px !important; width:210px !important;}
  .preview-house-icon{right:18px !important; bottom:34px !important; font-size:56px !important;}
  .setup-stat-list{grid-template-columns:repeat(2,minmax(0,1fr)) !important;}
  .selected-wand-btn{grid-template-columns:42px 1fr auto !important;}
  .wand-current-icon{font-size:28px !important;}
  .adventure-map-grid{
    padding:10px !important;
  }
  .adventure-node{min-height:108px !important;}
  .adventure-node .node-avatar{font-size:30px !important;}
  .top-bar{
    position:sticky;
    top:0;
    z-index:20;
    border-radius:0 0 18px 18px;
    background:rgba(7,9,20,.86);
    backdrop-filter:blur(10px);
  }
  .spell-hand .card{
    min-height:112px !important;
    padding:10px !important;
  }
  .spell-hand .card h3{font-size:16px !important;}
}


/* battle-redesign-v1: real battle screen UI, based on the stable game logic */
#screen-battle {
  --gold: #f4bf62;
  --gold-soft: rgba(244, 191, 98, .42);
  --panel: rgba(12, 15, 31, .78);
  --panel-strong: rgba(19, 19, 38, .92);
  --ink: #f8f0dd;
  --muted: rgba(248, 240, 221, .70);
  --line: rgba(244, 191, 98, .20);
  position: relative;
  padding: 10px 0 0;
  overflow: hidden;
}

#screen-battle::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 26% 16%, rgba(244,191,98,.14), transparent 24%),
    radial-gradient(circle at 78% 22%, rgba(108,86,255,.15), transparent 26%),
    radial-gradient(circle at 50% 110%, rgba(4,7,18,.95), transparent 44%);
  z-index: -1;
}

#screen-battle .top-bar {
  position: absolute;
  top: 10px;
  inset-inline: 0;
  z-index: 12;
  display: flex !important;
  justify-content: flex-start !important;
  align-items: center !important;
  gap: 12px;
  padding: 0 8px !important;
  margin: 0 !important;
  pointer-events: none;
}

#screen-battle .top-bar > div:first-child {
  display: none !important;
}

#screen-battle .top-actions {
  pointer-events: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-start;
  align-items: center;
}

#screen-battle .top-actions .ghost-btn {
  min-height: 42px;
  padding: 10px 16px !important;
  border-radius: 14px !important;
  border: 1px solid rgba(244,191,98,.28) !important;
  color: var(--ink) !important;
  background:
    linear-gradient(180deg, rgba(255,255,255,.09), rgba(255,255,255,.035)),
    rgba(12, 13, 29, .58) !important;
  box-shadow: 0 10px 24px rgba(0,0,0,.24), inset 0 1px 0 rgba(255,255,255,.06);
  backdrop-filter: blur(10px);
}

#screen-battle .top-actions .ghost-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(244,191,98,.62) !important;
  box-shadow: 0 14px 30px rgba(0,0,0,.32), 0 0 18px rgba(244,191,98,.10);
}

#screen-battle #battle-layout,
#screen-battle #battle-layout.log-collapsed,
#screen-battle #battle-layout:not(.log-collapsed) {
  height: calc(100vh - 24px) !important;
  display: grid !important;
  direction: ltr;
  grid-template-columns: minmax(0, 1fr) 318px !important;
  grid-template-areas: "arena hud" !important;
  gap: 18px !important;
  padding-top: 58px;
  min-height: 680px;
}

#screen-battle .arena-column {
  direction: rtl;
  grid-area: arena;
  min-width: 0;
  min-height: 0;
  display: grid !important;
  grid-template-rows: minmax(0, 1fr) auto !important;
  gap: 14px !important;
}

#screen-battle .right-panel {
  direction: rtl;
  grid-area: hud;
  display: grid !important;
  grid-template-rows: auto auto !important;
  align-content: start;
  gap: 16px !important;
  min-width: 0;
  padding: 0 !important;
  overflow: visible !important;
}

#screen-battle .log-panel { display: none !important; }

#screen-battle .arena {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: 438px !important;
  height: 100% !important;
  display: block !important;
  border-radius: 28px;
  border: 1px solid rgba(244,191,98,.22);
  background-image:
    linear-gradient(180deg, rgba(1,3,10,.10), rgba(1,3,10,.50)),
    radial-gradient(circle at 48% 46%, rgba(244,191,98,.12), transparent 20%),
    var(--arena-bg);
  background-size: cover;
  background-position: center;
  box-shadow:
    0 22px 70px rgba(0,0,0,.42),
    0 0 0 1px rgba(255,255,255,.035) inset,
    0 0 42px rgba(244,191,98,.06) inset;
}

#screen-battle .arena::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(3,5,13,.48), transparent 24%, transparent 70%, rgba(3,5,13,.34)),
    radial-gradient(circle at 26% 68%, rgba(255,211,115,.12), transparent 22%),
    linear-gradient(180deg, rgba(255,255,255,.03), transparent 38%, rgba(0,0,0,.28));
  z-index: 1;
}

#screen-battle .arena::after {
  content: "";
  position: absolute;
  inset: auto 18px 16px 18px;
  height: 34%;
  pointer-events: none;
  background: linear-gradient(0deg, rgba(3,5,14,.44), transparent);
  z-index: 1;
}

#screen-battle .fighter-visual {
  position: absolute !important;
  z-index: 3;
  display: block !important;
  width: auto;
  height: auto;
  filter: drop-shadow(0 22px 24px rgba(0,0,0,.46));
}

#screen-battle .fighter-visual .avatar {
  font-size: unset !important;
  width: auto !important;
  height: auto !important;
  display: block !important;
  transform-origin: center bottom;
}

#screen-battle .fighter-img {
  display: block;
  height: auto;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

#screen-battle .player-visual {
  left: -3%;
  bottom: -16%;
}

#screen-battle .player-visual .wizard-img {
  width: min(410px, 34vw) !important;
  max-width: none !important;
}

#screen-battle .enemy-visual {
  right: 13%;
  bottom: 18%;
}

#screen-battle .enemy-visual .enemy-img {
  width: min(230px, 18vw) !important;
  max-width: none !important;
}

#screen-battle .enemy-visual.enemy-key-troll {
  right: 27% !important;
  bottom: 6% !important;
}

#screen-battle .enemy-visual.enemy-key-troll .enemy-img {
  width: min(260px, 20vw) !important;
}

#screen-battle .stand-shadow {
  position: absolute;
  left: 50%;
  bottom: 2%;
  transform: translateX(-50%);
  width: 72%;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(0,0,0,.48), transparent 70%);
  filter: blur(4px);
  z-index: -1;
}

#screen-battle .spell-lane {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
}

#screen-battle .projectile { z-index: 9; }
#screen-battle .effect-layer { z-index: 10; }
#screen-battle .floating-text { z-index: 11; }

#screen-battle .combat-cue {
  position: absolute;
  z-index: 13;
  min-width: 128px;
  max-width: 280px;
  padding: 12px 18px;
  border-radius: 18px;
  color: #fff5e0;
  font-weight: 900;
  font-size: 21px;
  text-align: center;
  background:
    linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.025)),
    rgba(5, 6, 13, .88);
  border: 1px solid rgba(244,191,98,.55);
  box-shadow: 0 18px 44px rgba(0,0,0,.50), 0 0 22px rgba(244,191,98,.12) inset;
  backdrop-filter: blur(8px);
  pointer-events: none;
}

#screen-battle .combat-cue::after {
  content: "";
  position: absolute;
  bottom: -10px;
  width: 18px;
  height: 18px;
  transform: rotate(45deg);
  background: rgba(5, 6, 13, .88);
  border-right: 1px solid rgba(244,191,98,.50);
  border-bottom: 1px solid rgba(244,191,98,.50);
}

#screen-battle .combat-cue.player::after { left: 24px; }
#screen-battle .combat-cue.enemy::after { right: 24px; }

#screen-battle .info-card.enemy-info,
#screen-battle .info-card.player-info {
  position: relative;
  overflow: hidden !important;
  border-radius: 24px !important;
  padding: 18px 18px 16px !important;
  background:
    radial-gradient(circle at 90% 0%, rgba(244,191,98,.13), transparent 28%),
    linear-gradient(180deg, rgba(255,255,255,.07), rgba(255,255,255,.028)),
    rgba(15, 16, 33, .74) !important;
  border: 1px solid rgba(244,191,98,.22) !important;
  box-shadow:
    0 18px 42px rgba(0,0,0,.30),
    0 0 0 1px rgba(255,255,255,.035) inset !important;
  backdrop-filter: blur(14px);
}

#screen-battle .info-card.enemy-info::before,
#screen-battle .info-card.player-info::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(255,255,255,.09), transparent 35%, rgba(0,0,0,.15));
}

#screen-battle .info-card h3 {
  position: relative;
  z-index: 1;
  margin: 0 0 2px;
  color: #fff8e8;
  font-size: 30px;
  letter-spacing: -.02em;
}

#screen-battle .info-card p {
  position: relative;
  z-index: 1;
  color: var(--muted);
  margin: 0 0 8px;
  font-weight: 700;
}

#screen-battle .hp-wrap,
#screen-battle .xp-wrap {
  position: relative;
  z-index: 1;
  height: 13px !important;
  margin: 10px 0 7px !important;
  border-radius: 999px;
  background: rgba(0,0,0,.42) !important;
  border: 1px solid rgba(255,255,255,.05);
}

#screen-battle .hp-bar {
  background: linear-gradient(90deg, #ff4369, #ff9360 52%, #ffe271) !important;
  box-shadow: 0 0 16px rgba(255,112,88,.22);
}

#screen-battle .xp-bar {
  background: linear-gradient(90deg, #5d8cff, #91dcff, #ffe271) !important;
}

#screen-battle .stats {
  position: relative;
  z-index: 1;
  grid-template-columns: repeat(2, minmax(0,1fr)) !important;
  gap: 7px !important;
}

#screen-battle .stat {
  border-radius: 12px !important;
  padding: 8px 10px !important;
  background: rgba(2,4,14,.34) !important;
  border: 1px solid rgba(255,255,255,.045) !important;
  color: rgba(255,255,255,.90) !important;
  font-weight: 800;
}

#screen-battle .profile-mini {
  margin-top: 10px !important;
  background: rgba(244,191,98,.08) !important;
  border: 1px solid rgba(244,191,98,.14) !important;
  color: rgba(255,246,218,.88) !important;
}

#screen-battle .hand-section {
  position: relative;
  overflow: visible !important;
  padding: 0 4px 6px;
}

#screen-battle #hand-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 20px;
  text-shadow: 0 2px 18px rgba(0,0,0,.38);
}

#screen-battle #hand-title::before,
#screen-battle #hand-title::after {
  content: "";
  width: min(90px, 12vw);
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(244,191,98,.55), transparent);
}

#screen-battle .spell-hand {
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0,1fr)) !important;
  gap: 14px !important;
  align-items: stretch !important;
}

#screen-battle .battle-spell-card {
  position: relative;
  min-height: 172px !important;
  padding: 12px 12px 13px !important;
  overflow: hidden;
  border-radius: 22px !important;
  cursor: pointer;
  background:
    radial-gradient(circle at 50% 26%, var(--card-glow, rgba(170,120,255,.22)), transparent 42%),
    linear-gradient(180deg, rgba(255,255,255,.075), rgba(255,255,255,.026)),
    rgba(13, 13, 28, .88) !important;
  border: 1px solid var(--card-border, rgba(180,120,255,.58)) !important;
  box-shadow:
    0 18px 34px rgba(0,0,0,.28),
    0 0 0 1px rgba(255,255,255,.045) inset,
    0 0 24px var(--card-shadow, rgba(180,120,255,.10)) inset !important;
  display: grid;
  grid-template-rows: 22px 52px auto 1fr;
  transform: translateY(0);
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease, filter .18s ease;
}

#screen-battle .battle-spell-card::before {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 17px;
  border: 1px solid rgba(255,255,255,.055);
  pointer-events: none;
}

#screen-battle .battle-spell-card::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .65;
  background:
    radial-gradient(circle at 12% 0%, rgba(255,255,255,.18), transparent 22%),
    linear-gradient(145deg, rgba(255,255,255,.04), transparent 38%, rgba(0,0,0,.26));
}

#screen-battle .battle-spell-card:hover:not(.disabled) {
  transform: translateY(-6px) scale(1.012);
  border-color: var(--card-border-hover, rgba(255,209,102,.82)) !important;
  box-shadow:
    0 26px 46px rgba(0,0,0,.40),
    0 0 0 1px rgba(255,255,255,.06) inset,
    0 0 32px var(--card-shadow, rgba(180,120,255,.18)) inset !important;
}

#screen-battle .battle-spell-card.disabled {
  opacity: .55;
  filter: grayscale(.35);
  cursor: default;
}

#screen-battle .spell-card-top,
#screen-battle .spell-card-art,
#screen-battle .battle-spell-card h3,
#screen-battle .battle-spell-card p {
  position: relative;
  z-index: 1;
}

#screen-battle .spell-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

#screen-battle .spell-card-cost {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: #241703;
  font-weight: 1000;
  background: linear-gradient(180deg, #fff1a9, #d59332);
  border: 1px solid rgba(255,255,255,.30);
  box-shadow: 0 8px 18px rgba(0,0,0,.28);
}

#screen-battle .spell-card-type {
  font-size: 11px;
  color: rgba(255,255,255,.68);
  font-weight: 800;
}

#screen-battle .spell-card-art {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin: 4px auto 2px;
  border-radius: 18px;
  font-size: 30px;
  background:
    radial-gradient(circle at 50% 35%, rgba(255,255,255,.24), transparent 34%),
    radial-gradient(circle, var(--card-glow, rgba(180,120,255,.30)), rgba(0,0,0,.10) 70%);
  box-shadow: 0 10px 20px rgba(0,0,0,.28), 0 0 20px var(--card-shadow, rgba(180,120,255,.10));
}

#screen-battle .battle-spell-card h3 {
  margin: 3px 0 5px !important;
  text-align: center;
  font-size: 20px !important;
  color: #fff7e6;
}

#screen-battle .battle-spell-card p {
  margin: 0 !important;
  color: rgba(255,255,255,.76) !important;
  font-size: 13px;
  line-height: 1.45;
  text-align: center;
}

#screen-battle .spell-attack {
  --card-border: rgba(255, 78, 98, .62);
  --card-border-hover: rgba(255, 100, 114, .92);
  --card-glow: rgba(255, 58, 86, .30);
  --card-shadow: rgba(255, 58, 86, .16);
}
#screen-battle .spell-defense {
  --card-border: rgba(92, 225, 230, .62);
  --card-border-hover: rgba(128, 245, 255, .94);
  --card-glow: rgba(92, 225, 230, .26);
  --card-shadow: rgba(92, 225, 230, .15);
}
#screen-battle .spell-buff {
  --card-border: rgba(255, 209, 102, .62);
  --card-border-hover: rgba(255, 224, 130, .95);
  --card-glow: rgba(255, 209, 102, .26);
  --card-shadow: rgba(255, 209, 102, .14);
}
#screen-battle .spell-control {
  --card-border: rgba(184, 120, 255, .68);
  --card-border-hover: rgba(207, 155, 255, .96);
  --card-glow: rgba(150, 86, 255, .30);
  --card-shadow: rgba(150, 86, 255, .16);
}
#screen-battle .spell-item {
  --card-border: rgba(244, 191, 98, .72);
  --card-border-hover: rgba(255, 228, 144, .98);
  --card-glow: rgba(244, 191, 98, .28);
  --card-shadow: rgba(244, 191, 98, .15);
}

#screen-battle .hit-knock .avatar {
  animation: brv1HitKnock .38s ease;
}

@keyframes brv1HitKnock {
  0% { transform: translateX(0) scale(1); }
  32% { transform: translateX(12px) scale(.985); }
  100% { transform: translateX(0) scale(1); }
}

@media (max-width: 980px) {
  #screen-battle {
    overflow: visible;
  }
  #screen-battle #battle-layout,
  #screen-battle #battle-layout.log-collapsed,
  #screen-battle #battle-layout:not(.log-collapsed) {
    height: auto !important;
    min-height: 0 !important;
    display: grid !important;
    grid-template-columns: 1fr !important;
    grid-template-areas: "hud" "arena" !important;
    padding-top: 72px;
    gap: 10px !important;
  }
  #screen-battle .top-bar {
    position: sticky;
    top: 6px;
    padding: 6px 0 !important;
    background: rgba(8, 9, 20, .70);
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 18px;
    backdrop-filter: blur(10px);
  }
  #screen-battle .top-actions {
    width: 100%;
    justify-content: center;
  }
  #screen-battle .top-actions .ghost-btn {
    flex: 1 1 0;
    min-width: 0;
    padding: 9px 6px !important;
    font-size: 12px;
  }
  #screen-battle .right-panel {
    grid-template-columns: 1fr !important;
    gap: 9px !important;
  }
  #screen-battle .info-card.enemy-info,
  #screen-battle .info-card.player-info {
    border-radius: 18px !important;
    padding: 10px 12px !important;
  }
  #screen-battle .info-card h3 {
    font-size: 24px;
  }
  #screen-battle .stats {
    grid-template-columns: repeat(3, minmax(0,1fr)) !important;
    gap: 5px !important;
  }
  #screen-battle .stat {
    padding: 5px 7px !important;
    font-size: 12px;
    text-align: center;
  }
  #screen-battle .arena-column {
    grid-template-rows: auto auto !important;
  }
  #screen-battle .arena {
    min-height: 315px !important;
    height: 315px !important;
    border-radius: 20px;
  }
  #screen-battle .player-visual {
    left: -8%;
    bottom: -18%;
  }
  #screen-battle .player-visual .wizard-img {
    width: min(250px, 62vw) !important;
  }
  #screen-battle .enemy-visual {
    right: 11%;
    bottom: 22%;
  }
  #screen-battle .enemy-visual .enemy-img {
    width: min(140px, 34vw) !important;
  }
  #screen-battle .enemy-visual.enemy-key-troll {
    right: 27% !important;
    bottom: 9% !important;
  }
  #screen-battle .enemy-visual.enemy-key-troll .enemy-img {
    width: min(150px, 38vw) !important;
  }
  #screen-battle .spell-hand {
    grid-template-columns: repeat(4, minmax(118px, 1fr)) !important;
    gap: 10px !important;
    overflow-x: auto;
    padding: 2px 2px 10px;
    scrollbar-width: thin;
  }
  #screen-battle .battle-spell-card {
    min-height: 128px !important;
    padding: 9px !important;
    border-radius: 18px !important;
    grid-template-rows: 18px 42px auto 1fr;
  }
  #screen-battle .spell-card-art {
    width: 44px;
    height: 44px;
    font-size: 24px;
    border-radius: 14px;
  }
  #screen-battle .spell-card-cost {
    width: 23px;
    height: 23px;
    border-radius: 8px;
    font-size: 12px;
  }
  #screen-battle .spell-card-type {
    display: none;
  }
  #screen-battle .battle-spell-card h3 {
    font-size: 15px !important;
    margin-bottom: 2px !important;
  }
  #screen-battle .battle-spell-card p {
    font-size: 11px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  #screen-battle .combat-cue {
    min-width: 96px;
    max-width: 210px;
    padding: 9px 13px;
    font-size: 16px;
    border-radius: 15px;
  }
}

@media (max-width: 430px) {
  #screen-battle #battle-layout,
  #screen-battle #battle-layout.log-collapsed,
  #screen-battle #battle-layout:not(.log-collapsed) {
    padding-top: 62px;
  }
  #screen-battle .top-actions { gap: 6px; }
  #screen-battle .top-actions .ghost-btn { font-size: 11px; min-height: 38px; }
  #screen-battle .arena { height: 288px !important; min-height: 288px !important; }
  #screen-battle .player-visual .wizard-img { width: min(230px, 68vw) !important; }
  #screen-battle .enemy-visual .enemy-img { width: min(128px, 34vw) !important; }
  #screen-battle .enemy-visual.enemy-key-troll .enemy-img { width: min(142px, 40vw) !important; }
  #screen-battle .stats { grid-template-columns: repeat(2, minmax(0,1fr)) !important; }
  #screen-battle .spell-hand { grid-template-columns: repeat(4, 112px) !important; }
}

/* v49: battle-redesign refinement
   Focus: cleaner combat UX, no duplicate card metadata, working battle log, less empty gap. */
#screen-battle #battle-layout,
#screen-battle #battle-layout.log-collapsed,
#screen-battle #battle-layout:not(.log-collapsed) {
  grid-template-columns: minmax(0, 1fr) 292px !important;
  gap: 10px !important;
  padding-inline: 14px !important;
  padding-bottom: 14px !important;
}

#screen-battle .right-panel {
  gap: 12px !important;
}

#screen-battle .info-card.enemy-info,
#screen-battle .info-card.player-info {
  padding: 16px 16px 14px !important;
}

#screen-battle .arena-column {
  grid-template-rows: minmax(0, 1fr) auto !important;
  gap: 10px !important;
}

#screen-battle #hand-title {
  display: none !important;
}

#screen-battle .hand-section {
  padding: 0 0 2px !important;
  margin: 0 !important;
  overflow: visible !important;
}

#screen-battle .spell-hand {
  grid-template-columns: repeat(4, minmax(132px, 1fr)) !important;
  gap: 12px !important;
  align-items: stretch !important;
}

#screen-battle .battle-spell-card {
  min-height: 118px !important;
  padding: 13px 12px 14px !important;
  display: grid !important;
  grid-template-rows: 1fr auto !important;
  place-items: center !important;
  gap: 8px !important;
  overflow: hidden !important;
}

#screen-battle .spell-card-top,
#screen-battle .spell-card-cost,
#screen-battle .spell-card-type,
#screen-battle .battle-spell-card p {
  display: none !important;
}

#screen-battle .spell-card-art {
  width: 62px !important;
  height: 62px !important;
  margin: 0 auto !important;
  border-radius: 20px !important;
  font-size: 34px !important;
}

#screen-battle .battle-spell-card h3 {
  margin: 0 !important;
  font-size: clamp(18px, 1.6vw, 24px) !important;
  line-height: 1.05 !important;
  text-align: center !important;
  color: #fff7e6 !important;
}

#screen-battle .arena {
  min-height: 430px !important;
}

/* Restore the battle log as a floating drawer instead of breaking the battle grid. */
#screen-battle .log-panel {
  display: none !important;
}

#screen-battle #battle-layout:not(.log-collapsed) .log-panel {
  display: block !important;
  position: fixed !important;
  left: 18px !important;
  bottom: 18px !important;
  width: min(390px, calc(100vw - 36px)) !important;
  max-height: min(360px, 55vh) !important;
  z-index: 80 !important;
  padding: 16px !important;
  border-radius: 22px !important;
  background: rgba(9, 10, 24, .92) !important;
  border: 1px solid rgba(244,191,98,.28) !important;
  box-shadow: 0 24px 70px rgba(0,0,0,.48), inset 0 1px 0 rgba(255,255,255,.06) !important;
  backdrop-filter: blur(14px) !important;
}

#screen-battle #battle-layout:not(.log-collapsed) .log-panel h3 {
  margin: 0 0 10px !important;
  color: #f4bf62 !important;
}

#screen-battle #battle-layout:not(.log-collapsed) #battle-log {
  height: auto !important;
  max-height: calc(min(360px, 55vh) - 64px) !important;
  overflow: auto !important;
}

@media (max-width: 980px) {
  #screen-battle #battle-layout,
  #screen-battle #battle-layout.log-collapsed,
  #screen-battle #battle-layout:not(.log-collapsed) {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
    padding-inline: 8px !important;
    padding-bottom: 10px !important;
  }
  #screen-battle .arena {
    min-height: 305px !important;
    height: 305px !important;
  }
  #screen-battle .spell-hand {
    grid-template-columns: repeat(4, minmax(98px, 1fr)) !important;
    gap: 8px !important;
    overflow-x: auto !important;
    padding-bottom: 8px !important;
  }
  #screen-battle .battle-spell-card {
    min-height: 92px !important;
    padding: 9px 8px 10px !important;
    border-radius: 17px !important;
    gap: 5px !important;
  }
  #screen-battle .spell-card-art {
    width: 42px !important;
    height: 42px !important;
    border-radius: 14px !important;
    font-size: 24px !important;
  }
  #screen-battle .battle-spell-card h3 {
    font-size: 13.5px !important;
    white-space: normal !important;
  }
  #screen-battle #battle-layout:not(.log-collapsed) .log-panel {
    left: 10px !important;
    right: 10px !important;
    bottom: 10px !important;
    width: auto !important;
    max-height: 45vh !important;
  }
}

@media (max-width: 430px) {
  #screen-battle .arena { height: 282px !important; min-height: 282px !important; }
  #screen-battle .spell-hand { grid-template-columns: repeat(4, 94px) !important; }
  #screen-battle .battle-spell-card { min-height: 86px !important; }
  #screen-battle .spell-card-art { width: 38px !important; height: 38px !important; font-size: 22px !important; }
  #screen-battle .battle-spell-card h3 { font-size: 12.5px !important; }
}

/* v50 HUD refinement: level/house only, no XP bar in battle side card */
#screen-battle .info-card #player-house,
#screen-battle .info-card #enemy-level{
  margin: 2px 0 10px !important;
  color: rgba(255,246,224,.86) !important;
  font-size: 15px !important;
  font-weight: 850 !important;
}
#screen-battle .level-meta{
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  line-height: 1;
}
#screen-battle .meta-level{
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(0,0,0,.22);
  border: 1px solid rgba(255,255,255,.07);
}
#screen-battle .meta-house{
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  font-size: 20px;
  background: linear-gradient(180deg, rgba(244,191,98,.22), rgba(244,191,98,.06));
  border: 1px solid rgba(244,191,98,.24);
  box-shadow: 0 8px 18px rgba(0,0,0,.22);
}
#screen-battle .player-info .xp-wrap,
#screen-battle .player-info #player-xp{
  display: none !important;
}
#screen-battle .info-card h3{
  margin-bottom: 6px !important;
}
#screen-battle .player-info,
#screen-battle .enemy-info{
  padding-top: 16px !important;
}

/* v50 Spellbook detail: more useful now that battle cards are minimal */
.spellbook-full-info{
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: grid;
  gap: 8px;
}
.spellbook-full-info li{
  padding: 9px 11px;
  border-radius: 12px;
  background: rgba(0,0,0,.18);
  border: 1px solid rgba(255,255,255,.07);
  color: rgba(255,255,255,.86);
  line-height: 1.45;
}
.spellbook-full-info b{
  color: #ffd66f;
}

@media (max-width: 980px){
  #screen-battle .info-card #player-house,
  #screen-battle .info-card #enemy-level{
    font-size: 12.5px !important;
    margin-bottom: 7px !important;
  }
  #screen-battle .meta-level{padding: 4px 8px;}
  #screen-battle .meta-house{width:24px;height:24px;font-size:16px;border-radius:8px;}
}

/* v51: combat HUD clarity + real mobile battle fit
   - Restore live stat buff/debuff colors.
   - Shorten level meta.
   - Rebuild mobile battle order without touching game logic. */
#screen-battle .stat.stat-up,
#screen-battle .stats .stat.stat-up{
  color:#75ffb2 !important;
  background:linear-gradient(180deg, rgba(30,185,98,.28), rgba(20,110,70,.16)) !important;
  border-color:rgba(117,255,178,.62) !important;
  box-shadow:0 0 0 1px rgba(117,255,178,.12) inset, 0 0 16px rgba(45,210,120,.10) !important;
}
#screen-battle .stat.stat-down,
#screen-battle .stats .stat.stat-down{
  color:#ff8a8a !important;
  background:linear-gradient(180deg, rgba(210,50,64,.28), rgba(125,20,38,.16)) !important;
  border-color:rgba(255,112,112,.62) !important;
  box-shadow:0 0 0 1px rgba(255,112,112,.12) inset, 0 0 16px rgba(255,55,75,.10) !important;
}
#screen-battle .level-meta{gap:8px !important;}
#screen-battle .meta-level{
  font-size:14px !important;
  padding:5px 10px !important;
  min-width:auto !important;
  color:#ffe7a7 !important;
  background:rgba(244,191,98,.12) !important;
  border-color:rgba(244,191,98,.24) !important;
}
#screen-battle .meta-house{margin-inline-start:2px;}

@media (max-width: 760px){
  html, body{overflow:auto !important;}
  body:has(#screen-battle.active){overflow:hidden !important;}
  #screen-battle.active{
    height:100dvh !important;
    min-height:100dvh !important;
    overflow:hidden !important;
    padding:0 8px 0 !important;
    display:flex !important;
    flex-direction:column !important;
    gap:6px !important;
  }
  #screen-battle .top-bar{
    position:sticky !important;
    top:0 !important;
    z-index:120 !important;
    flex:0 0 auto !important;
    padding:0 8px !important;
    margin:0 -2px 0 !important;
    min-height:30px !important;
    height:32px !important;
    border-radius:0 0 18px 18px !important;
    background:rgba(8,10,24,.94) !important;
    backdrop-filter:blur(12px) !important;
    box-shadow:0 12px 28px rgba(0,0,0,.22) !important;
  }
  #screen-battle .top-bar > div:first-child{display:none !important;}
  #screen-battle .top-actions{
    width:100% !important;
    display:grid !important;
    grid-template-columns:repeat(3, minmax(0,1fr)) !important;
    gap:6px !important;
  }
  #screen-battle .top-actions .ghost-btn{
    min-height:26px !important;
    height:26px !important;
    padding:2px 4px !important;
    border-radius:10px !important;
    font-size:10px !important;
    line-height:1 !important;
    white-space:nowrap !important;
  }
  #screen-battle #battle-layout,
  #screen-battle #battle-layout.log-collapsed,
  #screen-battle #battle-layout:not(.log-collapsed){
    flex:1 1 auto !important;
    min-height:0 !important;
    height:auto !important;
    overflow:hidden !important;
    padding:0 !important;
    margin:0 !important;
    display:flex !important;
    flex-direction:column !important;
    gap:6px !important;
  }
  #screen-battle .right-panel,
  #screen-battle .arena-column{display:contents !important;}
  #screen-battle .enemy-info{order:1 !important;}
  #screen-battle .arena{order:2 !important;}
  #screen-battle .player-info{order:3 !important;}
  #screen-battle .hand-section{order:4 !important;}
  #screen-battle .turn-badge{display:none !important;}

  #screen-battle .info-card.enemy-info,
  #screen-battle .info-card.player-info{
    flex:0 0 auto !important;
    padding:8px 10px !important;
    border-radius:15px !important;
    min-height:0 !important;
    display:grid !important;
    grid-template-columns:auto auto minmax(90px, 1fr) 78px !important;
    align-items:center !important;
    column-gap:6px !important;
    row-gap:3px !important;
    background:linear-gradient(145deg, rgba(41,35,60,.90), rgba(18,19,39,.90)) !important;
  }
  #screen-battle .info-card h3{
    display:inline-flex !important;
    align-items:center !important;
    margin:0 !important;
    font-size:18px !important;
    line-height:1 !important;
    vertical-align:middle !important;
  }
  #screen-battle .info-card #enemy-level,
  #screen-battle .info-card #player-house{
    display:inline-flex !important;
    align-items:center !important;
    margin:0 !important;
    vertical-align:middle !important;
  }
  #screen-battle .level-meta{gap:5px !important;}
  #screen-battle .meta-level{
    font-size:11px !important;
    padding:3px 6px !important;
    border-radius:999px !important;
  }
  #screen-battle .meta-house{
    width:22px !important;
    height:22px !important;
    font-size:14px !important;
    border-radius:7px !important;
  }
  #screen-battle .hp-wrap{
    display:block !important;
    width:100% !important;
    height:10px !important;
    margin:0 !important;
    vertical-align:middle !important;
  }
  #screen-battle .info-card > p[id$='-hp']{
    display:block !important;
    width:78px !important;
    margin:0 !important;
    font-size:10.5px !important;
    line-height:1 !important;
    color:rgba(255,246,225,.86) !important;
    vertical-align:middle !important;
    white-space:nowrap !important;
  }
  #screen-battle .stats{
    grid-column:1 / -1 !important;
    grid-template-columns:repeat(3, minmax(0,1fr)) !important;
    gap:4px !important;
    margin-top:2px !important;
  }
  #screen-battle .stat{
    font-size:10px !important;
    padding:4px 5px !important;
    border-radius:8px !important;
    line-height:1.05 !important;
    text-align:center !important;
  }
  #screen-battle .profile-mini{display:none !important;}
  #screen-battle .buffs{display:none !important;}

  #screen-battle .arena{
    flex:1 1 auto !important;
    min-height:0 !important;
    height:auto !important;
    max-height:none !important;
    border-radius:18px !important;
    margin:0 !important;
    overflow:hidden !important;
    background-position:center center !important;
  }
  #screen-battle .player-visual{
    left:-13% !important;
    bottom:-19% !important;
  }
  #screen-battle .player-visual .wizard-img{
    width:min(245px, 66vw) !important;
  }
  #screen-battle .enemy-visual{
    right:6% !important;
    bottom:23% !important;
  }
  #screen-battle .enemy-visual .enemy-img{
    width:min(128px, 34vw) !important;
  }
  #screen-battle .enemy-visual.enemy-key-troll{
    right:20% !important;
    bottom:8% !important;
  }
  #screen-battle .online-battle-status{
    min-height:28px !important;
    padding:5px 11px !important;
    font-size:12px !important;
    max-width:80vw;
    text-align:center;
  }
  #screen-battle .combat-cue{
    min-width:72px !important;
    max-width:148px !important;
    padding:7px 10px !important;
    border-radius:13px !important;
    font-size:13px !important;
  }
  #screen-battle .floating-text{
    font-size:16px !important;
    max-width:78vw;
    text-align:center;
  }
  .global-sound-toggle{
    top:8px;
    left:8px;
    min-height:32px;
    padding:6px 9px !important;
    font-size:11px !important;
  }
  #screen-battle .enemy-visual.enemy-key-troll .enemy-img{
    width:min(145px, 38vw) !important;
  }

  #screen-battle .hand-section{
    position:sticky !important;
    bottom:0 !important;
    z-index:110 !important;
    flex:0 0 auto !important;
    padding:8px 0 calc(8px + env(safe-area-inset-bottom)) !important;
    margin:0 -2px !important;
    background:linear-gradient(180deg, rgba(12,12,28,.10), rgba(9,10,24,.96) 28%, rgba(9,10,24,.98)) !important;
    border-top:1px solid rgba(244,191,98,.16) !important;
    overflow:visible !important;
  }
  #screen-battle .spell-hand{
    display:grid !important;
    grid-template-columns:repeat(4, minmax(0,1fr)) !important;
    gap:6px !important;
    overflow:visible !important;
    padding:0 2px !important;
  }
  #screen-battle .battle-spell-card{
    min-width:0 !important;
    min-height:76px !important;
    padding:7px 4px 8px !important;
    border-radius:15px !important;
    gap:4px !important;
  }
  #screen-battle .spell-card-art{
    width:34px !important;
    height:34px !important;
    border-radius:12px !important;
    font-size:20px !important;
  }
  #screen-battle .battle-spell-card h3{
    font-size:11px !important;
    line-height:1.05 !important;
    max-width:100% !important;
    overflow:hidden !important;
    text-overflow:ellipsis !important;
    white-space:nowrap !important;
  }
}

@media (max-width: 380px){
  #screen-battle .top-actions .ghost-btn{font-size:9px !important; padding-inline:2px !important;}
  #screen-battle .info-card h3{font-size:16px !important;}
  #screen-battle .stat{font-size:9.2px !important; padding:3px 4px !important;}
  #screen-battle .battle-spell-card{min-height:70px !important;}
  #screen-battle .spell-card-art{width:30px !important;height:30px !important;font-size:18px !important;}
  #screen-battle .battle-spell-card h3{font-size:10px !important;}
}

/* Google Cloud Save */
.google-cloud-panel{
  width:min(760px, 100%);
  margin:18px auto 22px;
  padding:14px;
  border:1px solid rgba(255,214,105,.24);
  border-radius:20px;
  background:linear-gradient(135deg, rgba(255,255,255,.08), rgba(255,255,255,.025));
  display:grid;
  grid-template-columns:1fr auto auto auto;
  gap:10px;
  align-items:center;
  box-shadow:0 18px 45px rgba(0,0,0,.18);
}
.google-cloud-copy{display:flex;flex-direction:column;gap:4px;text-align:right}
.google-cloud-copy strong{color:#ffd46b;font-size:1.02rem}
.google-cloud-copy span{opacity:.78;font-size:.88rem;line-height:1.35}
.google-cloud-status{grid-column:1 / -1;font-size:.85rem;opacity:.78;text-align:center}
.google-cloud-status.ok{color:#8affb8;opacity:1}
.google-cloud-status.warn{color:#ffd46b;opacity:1}
.google-cloud-status.error{color:#ff7b8a;opacity:1}
.google-cloud-status.busy{color:#b9d8ff;opacity:1}
@media (max-width:700px){
  .google-cloud-panel{grid-template-columns:1fr;gap:10px;text-align:center;margin:12px auto 16px;padding:12px}
  .google-cloud-copy{text-align:center}
.google-cloud-panel button{width:100%}
}

/* v55: global leaderboard and home polish */
body {
  background:
    radial-gradient(circle at 18% 8%, rgba(255, 209, 102, .14), transparent 30%),
    radial-gradient(circle at 86% 18%, rgba(92, 225, 230, .12), transparent 28%),
    linear-gradient(145deg, #121623 0%, #1f2434 48%, #0b0d15 100%) !important;
}

#screen-home {
  padding: clamp(18px, 4vw, 48px);
  position: relative;
}

#screen-home h1 {
  font-size: clamp(42px, 8vw, 92px);
  line-height: .9;
  letter-spacing: 0;
  max-width: 980px;
  color: #fff7df;
  text-shadow: 0 16px 34px rgba(0,0,0,.35);
}

#screen-home .subtitle {
  font-size: clamp(16px, 2vw, 22px);
  color: #dce9ff;
}

.home-actions {
  display: grid !important;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px !important;
  max-width: 980px;
}

.home-actions .big-btn {
  border-radius: 8px;
  min-height: 72px;
  box-shadow: 0 12px 26px rgba(0,0,0,.24);
}

.primary-btn,
.ghost-btn,
.metric-btn {
  border-radius: 8px !important;
}

.danger-btn,
.save-delete-btn {
  border-color: rgba(255,123,138,.42) !important;
  color: #ffb9c2 !important;
}

.save-delete-btn {
  margin-top: 10px;
  padding: 7px 10px;
  min-height: 0;
  font-size: 12px;
  background: rgba(255,123,138,.10);
}

.leaderboard-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  padding: 18px 0 12px;
}

.leaderboard-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 12px;
}

.metric-btn {
  background: rgba(255,255,255,.09);
  color: #fff;
  border: 1px solid rgba(255,255,255,.16);
  padding: 10px 13px;
}

.metric-btn.active {
  background: #ffd166;
  color: #171923;
  border-color: #ffd166;
}

.leaderboard-status {
  min-height: 28px;
  margin: 8px 0 12px;
  color: #dce9ff;
}

.leaderboard-status.ok { color: #8affb8; }
.leaderboard-status.warn { color: #ffd46b; }
.leaderboard-status.error { color: #ff7b8a; }
.leaderboard-status.busy { color: #b9d8ff; }

.leaderboard-my-rank {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 8px 0 12px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid rgba(255,209,102,.42);
  background: rgba(255,209,102,.12);
  color: #fff7df;
}

.leaderboard-my-rank strong { color: #ffd166; font-size: 18px; }
.leaderboard-my-rank span { color: #eaf2ff; }
.leaderboard-my-rank.busy { border-color: rgba(185,216,255,.36); background: rgba(185,216,255,.10); }
.leaderboard-my-rank.missing { border-color: rgba(255,123,138,.36); background: rgba(255,123,138,.10); }

.leaderboard-table-wrap {
  overflow: auto;
  max-height: calc(100vh - 230px);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 8px;
  background: rgba(8, 10, 18, .54);
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.leaderboard-table th,
.leaderboard-table td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255,255,255,.09);
  text-align: right;
}

.leaderboard-table th {
  position: sticky;
  top: 0;
  background: #202536;
  color: #ffd166;
  z-index: 1;
}

.leaderboard-table tr.active-player-row {
  background: linear-gradient(90deg, rgba(255,209,102,.38), rgba(92,225,230,.20));
  outline: 3px solid rgba(255,209,102,.9);
  box-shadow: inset 0 0 0 999px rgba(255,209,102,.05);
}

.leaderboard-table tr.active-player-row .rank-cell::after {
  content: " · אתה";
  color: #8affb8;
  font-size: 13px;
}

.leaderboard-table td small {
  display: block;
  color: #b9d8ff;
  margin-top: 2px;
}

.rank-cell,
.score-cell {
  font-weight: 900;
  color: #fff7df;
}

.empty-leaderboard {
  text-align: center !important;
  color: #dce9ff;
  padding: 28px !important;
}

.loading-row::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 8px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.25);
  border-top-color: #ffd166;
  animation: leaderboardSpin .8s linear infinite;
}

@keyframes leaderboardSpin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  #screen-home { padding: 18px 8px; }
  .home-actions { grid-template-columns: 1fr 1fr; }
  .home-actions .big-btn { min-height: 58px; font-size: 16px; padding: 12px; }
  .leaderboard-head { align-items: stretch; flex-direction: column; }
  .leaderboard-head .ghost-btn { align-self: flex-start; }
  .leaderboard-table-wrap { max-height: none; }
}

/* v56: home screen UX repair */
#screen-home.active {
  display: grid !important;
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
  align-content: start;
  gap: 12px;
  min-height: 100%;
  overflow: hidden !important;
  padding: clamp(16px, 3vw, 34px) !important;
}

#screen-home::before,
#screen-home h1::after,
#screen-home .big-btn::before {
  pointer-events: none;
}

#screen-home h1 {
  font-size: clamp(38px, 6.4vw, 76px) !important;
  margin: 0 !important;
  max-width: 1040px;
}

#screen-home .subtitle {
  margin: 0 0 2px !important;
  max-width: 760px;
}

#screen-home .google-cloud-panel {
  width: min(920px, 100%) !important;
  margin: 4px 0 2px auto !important;
  border-radius: 8px !important;
  padding: 12px !important;
  box-shadow: 0 12px 30px rgba(0,0,0,.18) !important;
}

#screen-home .home-actions {
  width: min(980px, 100%) !important;
  max-width: none !important;
  margin: 6px 0 4px auto !important;
  display: grid !important;
  grid-template-columns: repeat(4, minmax(120px, 1fr)) !important;
  align-items: stretch !important;
}

#screen-home .home-actions .big-btn {
  min-height: 58px !important;
  padding: 12px 14px !important;
  font-size: clamp(15px, 1.5vw, 18px) !important;
}

#screen-home #save-list {
  width: 100% !important;
  max-width: 1180px !important;
  min-height: 0;
  max-height: none !important;
  overflow: auto !important;
  padding: 4px 4px 18px !important;
  margin: 4px 0 0 !important;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)) !important;
  align-content: start;
  scrollbar-width: thin;
}

#screen-home #save-list.hidden {
  display: none !important;
}

#screen-home #save-list .card {
  min-height: 104px !important;
  border-radius: 8px !important;
}

@media (max-width: 900px) {
  #screen-home.active {
    height: auto !important;
    min-height: 100dvh;
    overflow: auto !important;
    padding: 14px 10px 22px !important;
  }

  #screen-home .google-cloud-panel {
    grid-template-columns: 1fr !important;
    margin: 4px 0 !important;
  }

  #screen-home .home-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }

  #screen-home #save-list {
    overflow: visible !important;
    padding-bottom: 28px !important;
    grid-template-columns: 1fr !important;
  }
}

@media (max-height: 720px) and (min-width: 901px) {
  #screen-home.active {
    gap: 8px;
    padding-top: 14px !important;
    padding-bottom: 14px !important;
  }

  #screen-home h1 {
    font-size: clamp(34px, 5vw, 58px) !important;
  }

  #screen-home .google-cloud-panel {
    padding: 10px !important;
  }

  #screen-home .home-actions .big-btn {
    min-height: 50px !important;
  }
}

/* v57: replace the ceremonial home screen with a clean game dashboard */
#screen-home.active {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 420px);
  grid-template-rows: auto auto auto minmax(0, 1fr);
  grid-template-areas:
    "title cloud"
    "subtitle cloud"
    "actions actions"
    "saves saves";
  align-items: start !important;
  justify-content: stretch !important;
  gap: 18px !important;
  width: min(1180px, calc(100vw - 40px)) !important;
  min-height: auto !important;
  height: calc(100dvh - 28px) !important;
  margin: 0 auto !important;
  padding: 24px 0 !important;
  text-align: right !important;
  overflow: hidden !important;
}

#screen-home::before,
#screen-home h1::after {
  content: none !important;
  display: none !important;
}

#screen-home h1 {
  grid-area: title;
  font-family: Arial, "Noto Sans Hebrew", sans-serif !important;
  font-size: clamp(42px, 6vw, 72px) !important;
  line-height: .92 !important;
  letter-spacing: 0 !important;
  margin: 0 !important;
  max-width: 760px !important;
  color: #fff5d6 !important;
  text-shadow: 0 10px 28px rgba(0,0,0,.34) !important;
}

#screen-home .subtitle {
  grid-area: subtitle;
  margin: -8px 0 0 !important;
  padding-top: 0;
  max-width: 660px !important;
  font-size: 18px !important;
  color: #d9e4f6 !important;
}

#screen-home .google-cloud-panel {
  grid-area: cloud;
  width: 100% !important;
  margin: 0 !important;
  padding: 14px !important;
  display: grid !important;
  grid-template-columns: 1fr auto !important;
  gap: 10px !important;
  border-radius: 8px !important;
  background: rgba(12, 17, 29, .76) !important;
  border: 1px solid rgba(255,255,255,.14) !important;
  box-shadow: 0 14px 34px rgba(0,0,0,.22) !important;
  backdrop-filter: none !important;
}

#screen-home .google-cloud-copy {
  text-align: right !important;
}

#screen-home .google-cloud-copy strong {
  font-size: 16px !important;
  color: #ffd166 !important;
}

#screen-home .google-cloud-copy span {
  font-size: 13px !important;
  line-height: 1.35 !important;
  color: rgba(245,248,255,.74) !important;
}

#screen-home .google-cloud-panel button {
  min-width: 126px;
  height: 42px;
  align-self: center;
}

#screen-home .google-cloud-status {
  grid-column: 1 / -1;
  text-align: right !important;
  border-top: 1px solid rgba(255,255,255,.08);
  padding-top: 8px;
}

#screen-home .home-actions {
  grid-area: actions;
  width: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  gap: 10px !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}

#screen-home .home-actions .big-btn {
  min-width: 0 !important;
  min-height: 78px !important;
  padding: 14px 12px !important;
  border-radius: 8px !important;
  font-size: 18px !important;
  display: grid !important;
  place-items: center !important;
  gap: 6px !important;
  box-shadow: 0 12px 28px rgba(0,0,0,.22) !important;
}

#screen-home .home-actions .big-btn::before {
  display: block !important;
  margin: 0 !important;
  font-size: 24px !important;
  line-height: 1 !important;
}

#leaderboard-btn::before{content:"🏆";}

#screen-home #save-list {
  grid-area: saves;
  width: 100% !important;
  max-width: none !important;
  min-height: 0 !important;
  max-height: none !important;
  margin: 0 !important;
  padding: 14px !important;
  overflow: auto !important;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)) !important;
  gap: 10px !important;
  align-content: start !important;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 8px;
  background: rgba(7, 10, 18, .42);
}

#screen-home #save-list:not(.hidden)::before {
  content: "הדמויות שלך";
  grid-column: 1 / -1;
  color: #ffd166;
  font-weight: 900;
  font-size: 16px;
  padding: 0 2px 4px;
}

#screen-home #save-list .card {
  min-height: 112px !important;
  padding: 14px !important;
  border-radius: 8px !important;
  background: rgba(255,255,255,.075) !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
}

#screen-home #save-list .card h3 {
  font-size: 19px !important;
}

@media (max-width: 860px) {
  #screen-home.active {
    width: min(100%, calc(100vw - 20px)) !important;
    height: auto !important;
    min-height: 100dvh !important;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto auto;
    grid-template-areas:
      "title"
      "subtitle"
      "cloud"
      "actions"
      "saves";
    padding: 18px 0 24px !important;
    overflow: auto !important;
  }

  #screen-home h1 {
    font-size: clamp(36px, 12vw, 58px) !important;
  }

  #screen-home .subtitle {
    grid-area: subtitle;
    padding-top: 0;
    margin-bottom: 0 !important;
    font-size: 16px !important;
  }

  #screen-home .google-cloud-panel {
    grid-template-columns: 1fr !important;
  }

  #screen-home .google-cloud-panel button {
    width: 100%;
  }

  #screen-home .home-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  #screen-home .home-actions .big-btn {
    min-height: 64px !important;
    font-size: 16px !important;
  }

  #screen-home #save-list {
    overflow: visible !important;
    grid-template-columns: 1fr !important;
  }
}
