/* ============================================================
   Clash Arena — оформление
   ============================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --blue: #2b6ede;
  --blue-d: #17458f;
  --gold: #ffb320;
  --gold-d: #c47a06;
  --purple: #8c46d8;
  --bg: #12203c;
  --panel: #1d3160;
  --panel-2: #24407a;
  --text: #eaf1ff;
}

html, body {
  height: 100%;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 50% 0%, #2a4a8c 0%, var(--bg) 60%, #0b1425 100%);
  overflow: hidden;
  user-select: none;
}

#app { height: 100%; display: flex; justify-content: center; }

/* ---------------- иконки ---------------- */
.ic {
  width: 1.05em; height: 1.05em; display: inline-block; vertical-align: -0.17em;
  fill: currentColor; flex: none;
}
.ic.gold { color: var(--gold); }
.ic.crown { color: #ffd75e; }

.screen {
  display: none;
  width: 100%;
  max-width: 520px;
  height: 100%;
  flex-direction: column;
  position: relative;
}
.screen.active { display: flex; }

/* ---------------- верхняя панель ---------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  background: linear-gradient(180deg, #24407a, #17284d);
  border-bottom: 2px solid #0d1a33;
  flex: 0 0 auto;
}
.tb-left { display: flex; align-items: center; gap: 10px; }
.king-badge {
  width: 40px; height: 46px;
  background: linear-gradient(180deg, #ffd75e, #d98b09);
  clip-path: polygon(50% 0, 100% 22%, 100% 78%, 50% 100%, 0 78%, 0 22%);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: #4c2a00; font-size: 18px;
  box-shadow: 0 2px 0 #8c5500;
}
.tb-nick { font-weight: 700; font-size: 15px; }
.xp-bar { width: 90px; height: 7px; background: #0e1c38; border-radius: 4px; margin-top: 4px; overflow: hidden; }
.xp-bar i { display: block; height: 100%; background: linear-gradient(90deg, #63e6ff, #2b8bff); }
.tb-right { display: flex; gap: 8px; }
.res {
  display: flex; align-items: center; gap: 6px;
  background: #0f1e3c; border: 2px solid #2c4d8f; border-radius: 20px;
  padding: 5px 12px; font-weight: 700; font-size: 14px;
}
.res .ic { width: 17px; height: 17px; }
.res-gold .ic { color: #ffcf4d; }
.res-trophy .ic { color: #ffcf4d; }

/* ---------------- вкладки ---------------- */
.tab-body { flex: 1 1 auto; overflow-y: auto; padding: 12px; }
.tab-page { display: none; }
.tab-page.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

.tabbar {
  display: flex; flex: 0 0 auto;
  background: linear-gradient(180deg, #24407a, #14264a);
  border-top: 2px solid #0d1a33;
}
.tabbar .tab {
  flex: 1; padding: 10px 0 12px; background: none; border: 0; color: #9fb6dd;
  font-size: 12px; font-weight: 700; cursor: pointer; display: flex;
  flex-direction: column; align-items: center; gap: 3px; font-family: inherit;
}
.tabbar .tab .ic { width: 24px; height: 24px; opacity: .75; }
.tabbar .tab.active { color: #fff; background: rgba(255,255,255,.08); }
.tabbar .tab.active .ic { opacity: 1; color: var(--gold); transform: scale(1.08); }

/* ---------------- арена-карточка ---------------- */
.arena-card {
  display: flex; gap: 14px; align-items: center;
  background: linear-gradient(135deg, var(--panel-2), var(--panel));
  border: 2px solid #3b62b0; border-radius: 16px; padding: 14px;
  box-shadow: 0 4px 0 #0d1a33;
}
.arena-thumb {
  width: 62px; height: 62px; flex: none; border-radius: 12px; overflow: hidden;
  border: 2px solid #4a76c9; box-shadow: 0 3px 8px rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; color: #6f86ad;
}
.arena-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.arena-thumb .ic { width: 34px; height: 34px; }
.arena-meta { flex: 1; }
.arena-name { font-size: 18px; font-weight: 800; }
.arena-sub { font-size: 12px; color: #9fb6dd; margin-bottom: 7px; }
.arena-progress { height: 9px; background: #0e1c38; border-radius: 6px; overflow: hidden; }
.arena-progress i { display: block; height: 100%; background: linear-gradient(90deg, #ffd75e, #ff9a1f); }
.arena-next { font-size: 11px; color: #cfe0ff; margin-top: 5px; }

/* ---------------- превью колоды ---------------- */
.deck-preview {
  display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; margin: 14px 0;
}

/* ---------------- кнопки ---------------- */
.btn {
  font-family: inherit; font-weight: 800; color: #fff; border: 0; cursor: pointer;
  border-radius: 12px; padding: 12px; font-size: 15px;
  transition: transform .08s;
}
.btn:active { transform: translateY(2px); }
.btn.disabled, .btn:disabled { filter: grayscale(.8) brightness(.7); pointer-events: none; }
.btn-blue { background: linear-gradient(180deg, #4b90ff, var(--blue)); box-shadow: 0 4px 0 var(--blue-d); }
.btn-gold { background: linear-gradient(180deg, #ffcb4d, var(--gold)); box-shadow: 0 4px 0 var(--gold-d); color: #4a2c00; }
.btn-purple { background: linear-gradient(180deg, #a765e8, var(--purple)); box-shadow: 0 4px 0 #5b2794; }
.btn-grey { background: linear-gradient(180deg, #7c8ba5, #566379); box-shadow: 0 4px 0 #39424f; }
.btn-big { width: 100%; padding: 16px; display: flex; flex-direction: column; gap: 3px; }
.bb-title { font-size: 22px; letter-spacing: .5px; }
.bb-sub { font-size: 11px; font-weight: 600; opacity: .85; }
.battle-buttons { display: flex; flex-direction: column; gap: 10px; }
.battle-row { display: flex; gap: 10px; }
.btn-small { flex: 1; font-size: 13px; padding: 10px 6px; }
.btn-small small { display: block; font-size: 10px; opacity: .8; font-weight: 600; }

.stats-strip {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 16px;
}
.stats-strip > div {
  background: rgba(255,255,255,.06); border-radius: 10px; padding: 9px 4px; text-align: center;
}
.stats-strip b { display: block; font-size: 17px; }
.stats-strip span { font-size: 10px; color: #9fb6dd; }

.reset-link {
  display: block; margin: 18px auto 8px; background: none; border: 0; cursor: pointer;
  color: #6f86ad; font-size: 11px; font-family: inherit; text-decoration: underline;
}

/* ---------------- заголовки секций ---------------- */
.sec-title {
  font-size: 14px; margin: 16px 0 8px; display: flex; align-items: center;
  justify-content: space-between; color: #cfe0ff; text-transform: uppercase;
  letter-spacing: .6px;
}
.sec-title small { font-size: 11px; color: #93a9cf; text-transform: none; letter-spacing: 0; }
.mini-btn {
  font-family: inherit; font-size: 11px; font-weight: 700; padding: 5px 10px;
  border-radius: 8px; border: 0; cursor: pointer;
  background: linear-gradient(180deg, #ffcb4d, #ffb320); color: #4a2c00;
  display: inline-flex; align-items: center; gap: 4px;
}
.mini-btn .ic { width: 13px; height: 13px; }
.buy-btn { display: flex; align-items: center; justify-content: center; gap: 4px; }
.buy-btn .ic { width: 13px; height: 13px; }
.mi-up-info .ic { width: 13px; height: 13px; }
.loot-gold .ic { width: 20px; height: 20px; }
.res-rewards b .ic { width: 15px; height: 15px; }
.res-crowns .ic { width: 20px; height: 20px; }
.arena-next .ic { width: 12px; height: 12px; }

/* ---------------- карты ---------------- */
.deck-grid, .collection, .shop-grid {
  /* minmax(0,…) — иначе длинное название карты растягивает колонку и сетка вылезает */
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px;
}

.card { cursor: pointer; transition: transform .1s; }
.card:active { transform: scale(.95); }
.card-inner {
  position: relative; border-radius: 9px; overflow: hidden;
  background: linear-gradient(180deg, #4a628f, #2b3d63);
  border: 2px solid #7c93bd; padding-bottom: 4px;
  box-shadow: 0 3px 0 rgba(0,0,0,.35);
}
.rar-common  .card-inner { border-color: #b6c4d4; background: linear-gradient(180deg, #5b6f92, #313f5f); }
.rar-rare    .card-inner { border-color: #ff9f2e; background: linear-gradient(180deg, #8a6a3c, #4a3a24); }
.rar-epic    .card-inner { border-color: #c559ff; background: linear-gradient(180deg, #6b3d94, #38214f); }
.rar-legendary .card-inner {
  border-color: #4ee1ff;
  background: linear-gradient(140deg, #2b6f8a, #6b3d94 45%, #8a5a2b);
}
.card-art {
  position: relative; aspect-ratio: 1 / 1; display: flex;
  align-items: center; justify-content: center; overflow: hidden;
}
.card-art img {
  width: 108%; height: 108%; object-fit: contain; display: block;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,.45));
}
.art-stub {
  font-size: 20px; font-weight: 800; color: rgba(255,255,255,.55); letter-spacing: 1px;
}
.card.mini .card-art { aspect-ratio: 1 / 1; }
.card-name {
  font-size: 8.5px; text-align: center; font-weight: 700; padding: 0 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card.mini .card-name { display: none; }
.card-cost {
  position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  background: radial-gradient(circle at 40% 30%, #e07bff, #9c27b0);
  border: 1.5px solid #fff; border-radius: 50%;
  font-size: 11px; font-weight: 800; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.card-lvl { font-size: 8px; text-align: center; color: #ffe9a8; font-weight: 700; }
.card-prog {
  position: relative; height: 10px; margin: 3px 4px 0; background: #0e1c38;
  border-radius: 5px; overflow: hidden;
}
.card-prog i { display: block; height: 100%; background: linear-gradient(90deg, #63e6ff, #2b8bff); }
.card-prog span {
  position: absolute; inset: 0; font-size: 7.5px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; text-shadow: 0 1px 2px #000;
}
.card-badge {
  position: absolute; bottom: 2px; right: 2px; font-size: 8px; font-weight: 800;
  background: rgba(0,0,0,.7); padding: 2px 4px; border-radius: 5px;
  display: flex; align-items: center; gap: 2px;
}
.card-badge .ic { width: 9px; height: 9px; }
.card.locked .card-inner { filter: grayscale(.85) brightness(.55); }
.card.locked .card-badge { filter: none; }
.card.selected .card-inner { border-color: #ffe066; box-shadow: 0 0 0 3px rgba(255,224,102,.6); }
.card.in-deck .card-inner { outline: 2px solid rgba(120,255,160,.55); }
.card-up {
  position: absolute; top: 2px; right: 2px; z-index: 2;
  background: #37c94a; border-radius: 50%; width: 16px; height: 16px;
  display: flex; align-items: center; justify-content: center; color: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.card-up .ic { width: 11px; height: 11px; }

/* ---------------- магазин ---------------- */
.shop-item { display: flex; flex-direction: column; gap: 4px; align-items: stretch; }
.shop-qty { text-align: center; font-size: 11px; font-weight: 700; color: #ffe9a8; }
.buy-btn {
  font-family: inherit; font-size: 11px; font-weight: 800; padding: 6px 2px;
  border: 0; border-radius: 8px; cursor: pointer;
  background: linear-gradient(180deg, #ffcb4d, #ffb320); color: #4a2c00;
  box-shadow: 0 2px 0 var(--gold-d);
}
.buy-btn.disabled { filter: grayscale(.85) brightness(.75); pointer-events: none; }
.shop-item.sold { opacity: .5; }

.chest-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding-bottom: 20px; }
.chest {
  background: linear-gradient(135deg, var(--panel-2), var(--panel));
  border: 2px solid #3b62b0; border-radius: 14px; padding: 12px; text-align: center;
  box-shadow: 0 3px 0 #0d1a33;
}
.chest-ic .ic { width: 44px; height: 44px; filter: drop-shadow(0 3px 4px rgba(0,0,0,.5)); }
.chest-silver .chest-ic { color: #cdd8e6; }
.chest-golden .chest-ic { color: #ffc23d; }
.chest-magical .chest-ic { color: #c25cff; }
.chest-legendary .chest-ic { color: #4ee1ff; }
.chest-name { font-size: 12px; font-weight: 800; margin: 4px 0 2px; }
.chest-sub { font-size: 10px; color: #9fb6dd; margin-bottom: 8px; }

/* ---------------- модалка ---------------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(4,10,22,.75);
  display: none; align-items: center; justify-content: center; padding: 16px; z-index: 50;
  backdrop-filter: blur(3px);
}
.modal-back.open { display: flex; }
.modal {
  position: relative; width: 100%; max-width: 420px; max-height: 86vh; overflow-y: auto;
  background: linear-gradient(180deg, #26437f, #16294f);
  border: 2px solid #4a76c9; border-radius: 18px; padding: 18px;
  box-shadow: 0 10px 40px rgba(0,0,0,.6);
  animation: pop .18s ease;
}
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
.modal-close {
  position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; border: 0;
  border-radius: 50%; background: #ff5252; color: #fff; cursor: pointer; z-index: 3;
  display: flex; align-items: center; justify-content: center;
}
.modal-close .ic { width: 15px; height: 15px; }
.mi-head { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 12px; }
.mi-head .card { width: 84px; flex: 0 0 84px; pointer-events: none; }
.mi-head h3 { font-size: 18px; }
.mi-rar { font-size: 12px; font-weight: 700; margin: 2px 0 6px; }
.mi-desc { font-size: 12px; color: #cfe0ff; line-height: 1.4; }
.mi-stats { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 5px; margin-bottom: 12px; }
.mi-stats > div {
  display: flex; justify-content: space-between; background: rgba(255,255,255,.07);
  border-radius: 7px; padding: 5px 8px; font-size: 11px;
}
.mi-stats span { color: #9fb6dd; }
.mi-up {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: rgba(0,0,0,.25); border-radius: 12px; padding: 10px 12px;
}
.mi-up-info { font-size: 12px; line-height: 1.6; }
.mi-up-info .ok { color: #7dff9a; font-weight: 700; margin-right: 8px; }
.mi-up-info .no { color: #ff8a8a; font-weight: 700; margin-right: 8px; }

.loot-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 12px 0; }
.loot { text-align: center; }
.loot b { font-size: 11px; color: #ffe9a8; }
.loot .card { pointer-events: none; }
.loot-gold { text-align: center; font-size: 18px; font-weight: 800; color: #ffd75e; margin-bottom: 12px; }
#loot-ok { width: 100%; }

.res-title { text-align: center; font-size: 26px; margin-bottom: 6px; }
.res-title.win { color: #7dff9a; }
.res-title.lose { color: #ff8a8a; }
.res-crowns { text-align: center; font-size: 20px; font-weight: 800; margin-bottom: 12px; }
.res-rewards { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; margin-bottom: 12px; }
.res-rewards > div {
  background: rgba(255,255,255,.07); border-radius: 10px; padding: 8px; text-align: center;
}
.res-rewards span { display: block; font-size: 10px; color: #9fb6dd; }
.res-rewards b { font-size: 16px; }
.res-unlock { text-align: center; font-weight: 800; color: #ffd75e; }
.res-buttons { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }

/* ---------------- тост ---------------- */
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: rgba(10,20,40,.94); border: 2px solid #4a76c9; color: #fff;
  padding: 9px 16px; border-radius: 20px; font-size: 13px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 90; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============================================================
   ЭКРАН БОЯ
   ============================================================ */
.battle-wrap { display: flex; flex-direction: column; height: 100%; }

.battle-top {
  display: flex; align-items: center; justify-content: space-between;
  /* слева оставляем место под кнопку «сдаться» */
  padding: 6px 12px 6px 40px;
  background: linear-gradient(180deg, #24407a, #16294f);
  flex: 0 0 auto;
}
.quit-btn {
  position: absolute; left: 8px; top: 8px; width: 26px; height: 26px; z-index: 5;
  border: 0; border-radius: 50%; background: rgba(255,82,82,.85); color: #fff;
  font-weight: 800; font-size: 13px; cursor: pointer; font-family: inherit;
}
.crowns .cr { display: inline-flex; align-items: center; gap: 4px; }
.crowns .cr .ic { width: 17px; height: 17px; }
.pname .ic { width: 12px; height: 12px; color: var(--gold); }
.battle-top { position: relative; }
.crowns { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.crowns .cr { font-weight: 800; font-size: 15px; }
.pname { color: #bcd0f0; font-size: 11px; }
.timer { text-align: center; }
#battle-timer { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.phase { font-size: 9px; color: #ffd75e; font-weight: 800; height: 12px; }

.canvas-holder {
  flex: 1 1 auto; position: relative; display: flex;
  align-items: center; justify-content: center; overflow: hidden;
  background: #0b1425;
}
#arena { display: block; touch-action: none; }

.battle-overlay {
  position: absolute; top: 40%; left: 0; right: 0; text-align: center;
  font-size: 24px; font-weight: 900; color: #ffd75e; text-shadow: 0 3px 8px #000;
  opacity: 0; transition: .25s; pointer-events: none; letter-spacing: 1px;
}
.battle-overlay.show { opacity: 1; }

.battle-bottom {
  flex: 0 0 auto; display: grid; grid-template-columns: 62px 1fr;
  gap: 8px; padding: 8px 10px 10px;
  background: linear-gradient(180deg, #24407a, #14264a);
  align-items: end;
}
.next-card { grid-row: 1; }
.nc-label { font-size: 9px; color: #9fb6dd; text-align: center; margin-bottom: 2px; }
.hand { grid-row: 1; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.elixir-bar {
  grid-column: 1 / -1; position: relative; height: 20px; border-radius: 10px;
  background: #2a1740; border: 2px solid #532a7a; overflow: hidden; margin-top: 6px;
}
.elixir-bar i {
  display: block; height: 100%; width: 50%;
  background: linear-gradient(180deg, #e07bff, #a72fd6);
  transition: width .1s linear;
}
.elixir-ticks { position: absolute; inset: 0; display: flex; }
.elixir-ticks span { flex: 1; border-right: 1px solid rgba(0,0,0,.35); }
.elixir-bar b {
  position: absolute; right: 8px; top: 0; line-height: 16px; font-size: 12px;
  font-weight: 800; text-shadow: 0 1px 2px #000;
}

.hand-card {
  position: relative; border-radius: 9px; cursor: pointer;
  background: linear-gradient(180deg, #5b6f92, #313f5f);
  border: 2px solid #b6c4d4; padding: 6px 2px 4px; text-align: center;
  box-shadow: 0 3px 0 rgba(0,0,0,.4); transition: transform .1s;
}
.hand-card.rar-rare { border-color: #ff9f2e; background: linear-gradient(180deg, #8a6a3c, #4a3a24); }
.hand-card.rar-epic { border-color: #c559ff; background: linear-gradient(180deg, #6b3d94, #38214f); }
.hand-card.rar-legendary { border-color: #4ee1ff; background: linear-gradient(140deg, #2b6f8a, #6b3d94 45%, #8a5a2b); }
.hc-art { height: 42px; display: flex; align-items: center; justify-content: center; }
.hc-art img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 2px 3px rgba(0,0,0,.5)); }
.hc-art .art-stub { font-size: 16px; }
.hc-name { font-size: 8px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hc-cost {
  position: absolute; top: -6px; left: -4px; width: 19px; height: 19px;
  background: radial-gradient(circle at 40% 30%, #e07bff, #9c27b0);
  border: 1.5px solid #fff; border-radius: 50%; font-size: 11px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.hand-card.small { padding: 4px 2px; }
.hand-card.small .hc-art { height: 30px; }
.hand-card.picked { transform: translateY(-8px) scale(1.06); box-shadow: 0 0 0 3px #ffe066; }
.hand-card.cant { filter: grayscale(.75) brightness(.6); }

@media (max-width: 380px) {
  .card-art { font-size: 25px; }
  .hc-art { font-size: 23px; }
}
