/* ============ Arena Royale — original styling ============ */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #101b33;
  --bg2: #1b2a4a;
  --panel: #22345c;
  --panel-light: #2e4370;
  --gold: #ffcc44;
  --text: #eef3ff;
  --text-dim: #9fb0d0;
  --blue: #4da6ff;
  --red: #ff5566;
  --green: #4dd97a;
  --common: #6f89a8;
  --rare: #ff9f43;
  --epic: #b06ee8;
  --legendary: #58d3f7;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

#app { display: flex; flex-direction: column; height: 100dvh; max-width: 560px; margin: 0 auto; }
#screens { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 14px 14px 8px; }
.screen { display: none; animation: fadein .18s ease; }
.screen.active { display: block; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: none; } }

.screen-title { font-size: 17px; margin: 14px 0 8px; display: flex; align-items: center; gap: 8px; }
.screen-title:first-child { margin-top: 2px; }

/* ---------- Tab bar ---------- */
#tabbar {
  display: flex; background: #0c1526; border-top: 2px solid #060d1a;
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; background: none; border: none; color: var(--text-dim);
  font-size: 22px; padding: 8px 0 6px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tab span { font-size: 11px; font-weight: 600; }
.tab.active { color: var(--gold); }

/* ---------- Home ---------- */
.home-top { display: flex; justify-content: space-between; margin-bottom: 12px; }
.pill {
  background: var(--panel); border-radius: 20px; padding: 6px 14px;
  font-weight: 700; font-size: 14px; border: 1px solid #35507f;
}
.home-arena {
  background: linear-gradient(160deg, var(--panel-light), var(--panel));
  border: 2px solid #3b5a8f; border-radius: 18px;
  text-align: center; padding: 26px 16px 20px; margin-bottom: 18px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.home-arena-emoji { font-size: 64px; filter: drop-shadow(0 6px 10px rgba(0,0,0,.4)); }
.home-arena-name { font-size: 20px; font-weight: 800; margin-top: 8px; }
.home-trophies { font-size: 26px; font-weight: 900; color: var(--gold); margin-top: 6px; }
.home-trophy-next { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

.battle-btn {
  display: block; width: 100%; padding: 16px; font-size: 22px; font-weight: 900;
  color: #3a2500; background: linear-gradient(180deg, #ffe08a, #ffb824);
  border: none; border-radius: 14px; cursor: pointer;
  box-shadow: 0 5px 0 #b97f10, 0 10px 20px rgba(0,0,0,.35);
  transition: transform .06s;
}
.battle-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #b97f10; }
.battle-btn.small { width: auto; padding: 10px 40px; font-size: 17px; margin: 14px auto 0; }
.battle-btn.friend {
  margin-top: 10px; padding: 12px; font-size: 17px; color: #08284a;
  background: linear-gradient(180deg, #8ec5ff, #3f8fe0);
  box-shadow: 0 4px 0 #22578f, 0 8px 16px rgba(0,0,0,.3);
}
.battle-btn.friend:active { box-shadow: 0 1px 0 #22578f; }

/* ---------- multiplayer modal ---------- */
#mp-root {
  position: fixed; inset: 0; z-index: 80; background: rgba(5,10,20,.75);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.mp-box { text-align: center; }
.mp-title { font-size: 20px; margin-bottom: 4px; }
.mp-sub { font-size: 12px; color: var(--text-dim); margin-bottom: 16px; }
.mp-panel { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.mp-panel button { padding: 12px; border-radius: 10px; border: none; font-weight: 800; font-size: 15px; cursor: pointer; }
.mp-code {
  font-size: 38px; font-weight: 900; letter-spacing: 10px; color: var(--gold);
  background: #16233f; border: 2px dashed #3b5a8f; border-radius: 12px; padding: 12px 6px 12px 16px;
  user-select: text; -webkit-user-select: text;
}
.mp-hint { font-size: 12px; color: var(--text-dim); }
.mp-status { font-size: 13px; font-weight: 700; color: var(--blue); min-height: 18px; }
#mp-code-input {
  padding: 12px; border-radius: 10px; border: 2px solid #3b5a8f; background: #16233f;
  color: var(--text); font-size: 20px; font-weight: 800; text-align: center;
  letter-spacing: 6px; text-transform: uppercase; outline: none; width: 100%;
}
#mp-code-input:focus { border-color: var(--gold); }
.mp-box .mbtn-close { width: 100%; padding: 11px; border-radius: 10px; border: none; font-weight: 800; cursor: pointer; }

.home-deck-preview { display: flex; gap: 5px; margin-top: 18px; justify-content: center; flex-wrap: wrap; }
.home-deck-preview .cardface { width: 48px; }

/* ---------- Cards ---------- */
.deck-elixir { font-size: 12px; color: #d48aff; font-weight: 700; margin-left: auto; }
#collection-count { font-size: 12px; color: var(--text-dim); margin-left: auto; }

.deck-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.collection-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding-bottom: 10px; }

.cardface {
  position: relative; border-radius: 10px; aspect-ratio: 3/4;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; border: 2px solid #000; overflow: hidden;
  background: linear-gradient(160deg, #46608f, #2c3f66);
  transition: transform .08s;
}
.cardface:active { transform: scale(.95); }
.cardface.rarity-common { border-color: var(--common); }
.cardface.rarity-rare { border-color: var(--rare); }
.cardface.rarity-epic { border-color: var(--epic); }
.cardface.rarity-legendary { border-color: var(--legendary); box-shadow: 0 0 10px rgba(88,211,247,.45); }
.cardface .emoji { font-size: clamp(26px, 8vw, 40px); line-height: 1.1; filter: drop-shadow(0 3px 4px rgba(0,0,0,.5)); }
.cardface img.art { width: 78%; height: auto; pointer-events: none; filter: drop-shadow(0 3px 4px rgba(0,0,0,.45)); }
.cardface .cname { font-size: 9px; font-weight: 700; text-align: center; margin-top: 3px; padding: 0 2px; }
.cardface .cost {
  position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #e070ff, #8b1fb5);
  border: 1px solid #fff; font-size: 12px; font-weight: 900;
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.cardface .lvl {
  position: absolute; bottom: 3px; right: 4px; font-size: 9px; font-weight: 800; color: var(--gold);
}
.cardface.locked { filter: grayscale(1) brightness(.55); }
.cardface.selected { outline: 3px solid var(--gold); }
.cardface .upg-dot {
  position: absolute; top: 3px; right: 3px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--green); border: 1px solid #fff;
}
.card-progress {
  position: absolute; bottom: 0; left: 0; right: 0; height: 5px; background: rgba(0,0,0,.55);
}
.card-progress > div { height: 100%; background: var(--blue); }

/* ---------- Trophy road ---------- */
.road-list { display: flex; flex-direction: column; gap: 10px; padding-bottom: 10px; }
.road-item {
  background: var(--panel); border: 2px solid #35507f; border-radius: 14px; padding: 12px 14px;
  display: flex; gap: 14px; align-items: center;
}
.road-item.current { border-color: var(--gold); background: linear-gradient(160deg, #3a4f80, var(--panel)); }
.road-item.locked { opacity: .55; }
.road-emoji { font-size: 38px; }
.road-info { flex: 1; }
.road-name { font-weight: 800; font-size: 15px; }
.road-req { font-size: 12px; color: var(--gold); font-weight: 700; }
.road-unlocks { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.road-unlocks .u {
  background: #16233f; border-radius: 6px; padding: 3px; border: 1px solid #35507f;
  display: inline-flex; align-items: center; justify-content: center;
}
.road-unlocks .u img.art { width: 24px; height: 24px; display: block; }
.road-badge { font-size: 11px; font-weight: 800; color: var(--green); }

/* ---------- Profile ---------- */
.profile-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 20px; }
.stat-box { background: var(--panel); border-radius: 12px; padding: 12px; border: 1px solid #35507f; }
.stat-box .k { font-size: 11px; color: var(--text-dim); font-weight: 600; }
.stat-box .v { font-size: 20px; font-weight: 900; margin-top: 2px; }
.danger-btn {
  width: 100%; padding: 12px; border-radius: 10px; border: none; cursor: pointer;
  background: #7c2330; color: #ffd9dd; font-weight: 800; font-size: 14px;
}

/* ---------- Battle overlay ---------- */
.hidden { display: none !important; }

#battle-root {
  position: fixed; inset: 0; z-index: 50; background: #0a1322;
  display: flex; flex-direction: column; max-width: 560px; margin: 0 auto;
}
#battle-hud-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px; gap: 10px;
}
.hud-timer { font-size: 18px; font-weight: 900; color: var(--gold); min-width: 60px; text-align: center; }
.hud-timer.overtime { color: var(--red); }
.hud-crowns { font-weight: 800; font-size: 15px; }
#hud-enemy-crowns { color: #ff8f9a; }
#hud-player-crowns { color: #7fc4ff; }
#btn-forfeit { background: none; border: none; font-size: 18px; cursor: pointer; }

#battle-canvas-wrap { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; }
#battle-canvas { touch-action: none; border-radius: 6px; max-width: 100%; max-height: 100%; }

#battle-hud-bottom { padding: 4px 10px calc(8px + env(safe-area-inset-bottom)); }
#hud-next { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.next-label { font-size: 10px; color: var(--text-dim); font-weight: 700; }
#hud-hand { display: flex; gap: 6px; }
.hand-card {
  flex: 1; aspect-ratio: 3/4; border-radius: 10px; border: 2px solid #35507f; position: relative;
  background: linear-gradient(160deg, #46608f, #2c3f66);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; max-width: 90px;
}
.hand-card .emoji { font-size: clamp(24px, 9vw, 40px); }
.hand-card img.art { width: 74%; height: auto; pointer-events: none; filter: drop-shadow(0 3px 4px rgba(0,0,0,.45)); }
#hud-hand .hand-card { animation: dealin .2s ease; }
@keyframes dealin { from { transform: translateY(14px) scale(.85); opacity: 0; } to { transform: none; opacity: 1; } }
#hud-hand .hand-card.selected { animation: none; }
.hand-card .cost {
  position: absolute; top: -6px; left: -6px; width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #e070ff, #8b1fb5);
  border: 2px solid #fff; font-size: 12px; font-weight: 900; color: #fff;
  display: flex; align-items: center; justify-content: center; z-index: 2;
}
.hand-card.selected { border-color: var(--gold); box-shadow: 0 0 12px rgba(255,204,68,.6); transform: translateY(-6px); }
.hand-card.unaffordable { filter: brightness(.5) saturate(.4); }
.hand-card.mini { width: 34px; flex: none; }
.hand-card.mini .emoji { font-size: 18px; }
.hand-card.mini img.art { width: 80%; }
.hand-card.mini .cost { width: 15px; height: 15px; font-size: 9px; top: -4px; left: -4px; border-width: 1px; }

#hud-elixir {
  margin-top: 6px; height: 20px; background: #131f38; border-radius: 10px; border: 1px solid #35507f;
  position: relative; overflow: hidden;
}
#elixir-fill {
  height: 100%; width: 50%;
  background: linear-gradient(90deg, #a13ecf, #e070ff);
  border-radius: 10px 0 0 10px; transition: width .1s linear;
}
#hud-elixir.double #elixir-fill { background: linear-gradient(90deg, #d0389f, #ff7ad9); }
#elixir-num {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 900; color: #fff; text-shadow: 0 1px 2px #000;
}

#battle-banner {
  position: absolute; top: 40%; left: 0; right: 0; text-align: center;
  font-size: 30px; font-weight: 900; color: var(--gold);
  text-shadow: 0 3px 8px #000; pointer-events: none; z-index: 60;
  animation: bannerpop .5s ease;
}
@keyframes bannerpop { from { transform: scale(.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- Results ---------- */
#results-root {
  position: fixed; inset: 0; z-index: 70; background: rgba(5, 10, 20, .82);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.results-box {
  background: linear-gradient(170deg, var(--panel-light), var(--panel));
  border: 2px solid #3b5a8f; border-radius: 18px; padding: 24px 22px;
  width: 100%; max-width: 360px; text-align: center;
  box-shadow: 0 16px 50px rgba(0,0,0,.6);
  animation: fadein .25s ease;
}
.results-title { font-size: 30px; font-weight: 900; }
.results-title.win { color: var(--gold); }
.results-title.loss { color: var(--red); }
.results-title.draw { color: var(--text-dim); }
.results-crowns { font-size: 26px; margin: 8px 0 14px; letter-spacing: 4px; }
.results-rows { display: flex; flex-direction: column; gap: 8px; text-align: left; }
.results-row {
  background: #182645; border-radius: 10px; padding: 9px 12px;
  display: flex; justify-content: space-between; font-weight: 700; font-size: 14px;
}
.results-row .val { color: var(--gold); }
.results-cards { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-top: 4px; }
.results-cards .cardface { width: 52px; }

/* ---------- Modal ---------- */
#modal-root {
  position: fixed; inset: 0; z-index: 80; background: rgba(5,10,20,.75);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-box {
  background: linear-gradient(170deg, var(--panel-light), var(--panel));
  border: 2px solid #3b5a8f; border-radius: 16px; padding: 20px;
  width: 100%; max-width: 340px; animation: fadein .2s ease;
}
.modal-head { display: flex; gap: 14px; align-items: center; margin-bottom: 12px; }
.modal-head .emoji { font-size: 48px; }
.modal-head img.art { width: 60px; height: 60px; filter: drop-shadow(0 3px 4px rgba(0,0,0,.45)); }
.modal-head h3 { font-size: 20px; }
.modal-rarity { font-size: 12px; font-weight: 800; text-transform: uppercase; }
.modal-rarity.common { color: var(--common); } .modal-rarity.rare { color: var(--rare); }
.modal-rarity.epic { color: var(--epic); } .modal-rarity.legendary { color: var(--legendary); }
.modal-desc { font-size: 13px; color: var(--text-dim); margin-bottom: 12px; line-height: 1.4; }
.stat-table { width: 100%; font-size: 13px; border-collapse: collapse; margin-bottom: 14px; }
.stat-table td { padding: 5px 4px; border-bottom: 1px solid #31497a; }
.stat-table td:last-child { text-align: right; font-weight: 800; }
.modal-actions { display: flex; gap: 8px; }
.modal-actions button {
  flex: 1; padding: 11px; border-radius: 10px; border: none; font-weight: 800;
  font-size: 14px; cursor: pointer;
}
.mbtn-upgrade { background: linear-gradient(180deg, #7ee89a, #33b45c); color: #05300f; }
.mbtn-upgrade:disabled { filter: grayscale(.8) brightness(.6); cursor: default; }
.mbtn-use { background: linear-gradient(180deg, #7ab8ff, #2f7fd6); color: #06213d; }
.mbtn-close { background: #3a4f80; color: var(--text); }

@media (min-width: 561px) {
  #app, #battle-root { border-left: 2px solid #060d1a; border-right: 2px solid #060d1a; }
}
