:root {
  --arena-top: #332370;
  --arena-bottom: #0f1733;
  --arena-glow: #7347d9;
  --panel-fill: #1f2647;
  --panel-border-top: #ffd666;
  --panel-border-bottom: #a67314;
  --card-slot-fill: #141a2e;
  --card-slot-border: #59618c;
  --text-primary: #faf2e0;
  --text-secondary: #adb2d1;
  --text-muted: #7a809e;
  --accent-gold: #ffd147;
  --accent-gold-deep: #d99414;
  --accent-elixir: #c75cfa;
  --include: #6beb94;
  --exclude: #fa7373;
  --rank-gold: #ffd138;
  --rank-silver: #c7d1e6;
  --rank-bronze: #e09447;
  --rank-default: #384262;
  --tab-bar-bg: rgba(15, 23, 51, 0.94);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--arena-bottom);
  color: var(--text-primary);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  padding: 0;
}

img {
  display: block;
  max-width: 100%;
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(900px 480px at 100% -5%, rgba(115, 71, 217, 0.35), transparent 60%),
    radial-gradient(700px 420px at 0% 100%, rgba(199, 92, 250, 0.12), transparent 55%),
    linear-gradient(155deg, var(--arena-top), var(--arena-bottom) 58%);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(12px);
  background: rgba(15, 23, 51, 0.88);
  border-bottom: 1px solid rgba(89, 97, 140, 0.35);
  padding: 12px 16px 8px;
}

.topbar-title {
  margin: 0;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.subtabs {
  display: flex;
  gap: 0;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  margin-top: 10px;
  padding: 0 4px 2px;
  border-bottom: 1px solid rgba(89, 97, 140, 0.35);
}

.subtabs::-webkit-scrollbar {
  display: none;
}

.subtab {
  flex: 0 0 auto;
  min-width: 88px;
  padding: 8px 16px 10px;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  position: relative;
  white-space: nowrap;
}

.subtab[aria-selected="true"] {
  color: var(--accent-gold);
  font-weight: 700;
}

.subtab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: 0;
  height: 3px;
  border-radius: 999px;
  background: var(--accent-gold);
}

.trophy-stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 10px;
  padding-bottom: 4px;
}

.trophy-stepper .label {
  min-width: 5.5rem;
  text-align: center;
  color: var(--accent-gold);
  font-weight: 700;
}

.stepper-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid rgba(255, 209, 71, 0.45);
  color: var(--accent-gold);
  display: grid;
  place-items: center;
  background: rgba(31, 38, 71, 0.7);
}

.stepper-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-top: 6px;
}

.stepper-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
}

.stepper-dots span.active {
  background: var(--accent-gold);
}

.main {
  flex: 1;
  padding: 12px 16px calc(88px + var(--safe-bottom));
  width: min(960px, 100%);
  margin: 0 auto;
}

.summary {
  margin: 0 0 12px;
  color: var(--text-secondary);
  font-size: 0.92rem;
  line-height: 1.5;
}

.updated {
  margin: -4px 0 14px;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.status {
  margin: 48px 16px;
  text-align: center;
  color: var(--text-secondary);
  line-height: 1.6;
}

.status.error {
  color: #ff8c8c;
}

.deck-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

@media (max-width: 520px) {
  .deck-grid {
    grid-template-columns: 1fr;
  }
}

.deck-panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 40%),
    var(--panel-fill);
  border-radius: 18px;
  border: 1px solid var(--panel-border-bottom);
  box-shadow:
    inset 0 1px 0 var(--panel-border-top),
    0 8px 20px rgba(0, 0, 0, 0.25);
  padding: 8px;
}

.deck-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 8px;
  min-height: 32px;
}

.rank-badge {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 800;
  color: #1a1408;
  background: var(--rank-default);
  color: var(--text-primary);
}

.rank-badge.r1 {
  background: var(--rank-gold);
  color: #2a2108;
}
.rank-badge.r2 {
  background: var(--rank-silver);
  color: #243048;
}
.rank-badge.r3 {
  background: var(--rank-bronze);
  color: #2a1808;
}

.player-name {
  flex: 1;
  min-width: 0;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.elixir {
  flex: 0 0 auto;
  color: var(--accent-elixir);
  font-size: 0.78rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 2px;
}

.card-slot {
  aspect-ratio: 78 / 94;
  border-radius: 10px;
  background: var(--card-slot-fill);
  border: 1px solid var(--card-slot-border);
  overflow: hidden;
  position: relative;
}

.card-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-slot.unknown {
  display: grid;
  place-items: center;
  color: var(--text-muted);
  font-size: 0.65rem;
}

.load-more {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 209, 71, 0.35);
  color: var(--accent-gold);
  background: rgba(31, 38, 71, 0.65);
  font-weight: 700;
}

/* Card usage */
.usage-layout {
  display: grid;
  gap: 20px;
}

@media (min-width: 760px) {
  .usage-layout {
    grid-template-columns: 280px 1fr;
    align-items: start;
  }
}

.chart-wrap {
  background: var(--panel-fill);
  border-radius: 18px;
  border: 1px solid var(--card-slot-border);
  padding: 16px;
  display: grid;
  place-items: center;
}

.donut {
  width: min(240px, 70vw);
  height: min(240px, 70vw);
  border-radius: 50%;
  position: relative;
}

.donut-hole {
  position: absolute;
  inset: 28%;
  border-radius: 50%;
  background: var(--arena-bottom);
  display: grid;
  place-items: center;
  text-align: center;
  padding: 8px;
}

.donut-hole strong {
  font-size: 0.95rem;
  color: var(--accent-gold);
}

.donut-hole span {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.legend {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 12px;
  background: rgba(31, 38, 71, 0.75);
  border: 1px solid rgba(89, 97, 140, 0.4);
}

.legend-item .thumb {
  width: 36px;
  height: 44px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--card-slot-fill);
  border: 1px solid var(--card-slot-border);
  flex: 0 0 auto;
}

.legend-item .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.legend-meta {
  min-width: 0;
}

.legend-meta .name {
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.legend-meta .rate {
  color: var(--accent-gold);
  font-size: 0.85rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
}

/* Tab bar */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 8px 12px calc(8px + var(--safe-bottom));
  background: var(--tab-bar-bg);
  border-top: 1px solid rgba(89, 97, 140, 0.45);
  backdrop-filter: blur(14px);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 4px;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
}

.tab[aria-selected="true"] {
  color: var(--accent-gold);
}

.tab svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.footer-note {
  margin: 28px 0 8px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.72rem;
  line-height: 1.5;
}

.footer-note a {
  color: var(--text-secondary);
}
