:root {
  --bg: #1d1f24;
  --panel: #2a2d34;
  --panel2: #33373f;
  --ink: #f1efe9;
  --muted: #a9a59c;
  --line: #43474f;
  --grass: #5b8c32;
  --grass-dark: #3f6b20;
  --dirt: #8b5a2b;
  --gold: #f2c14e;
  --red: #e0584f;
  --blue: #5aa9e6;
  --purple: #b18cf0;
  --radius: 10px;
  --max: 1100px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 16px; line-height: 1.5;
}
.wrap { max-width: var(--max); margin: 0 auto; padding: 0 16px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.between { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
button { font: inherit; cursor: pointer; }

/* Header */
.top { background: linear-gradient(var(--grass) 0 60%, var(--dirt) 60% 100%); border-bottom: 4px solid #5c3a1a; padding: 12px 0 10px; position: sticky; top: 0; z-index: 10; }
.logo {
  margin: 0; font-size: clamp(24px, 5vw, 34px); letter-spacing: 1px; color: #fff;
  text-shadow: 3px 3px 0 #2b2b2b; font-family: "Courier New", monospace; font-weight: 900; flex: 1;
}
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button {
  border: 2px solid #1b1b1b; background: #c6c6c6; color: #222; padding: 6px 12px; border-radius: 4px;
  box-shadow: inset -2px -3px 0 #8b8b8b, inset 2px 2px 0 #fff; font-weight: 700;
}
.tabs button[aria-selected="true"] { background: var(--gold); box-shadow: inset -2px -3px 0 #b8871c, inset 2px 2px 0 #fff3c4; }
#count-badge:not(:empty) { background: var(--red); color: #fff; border-radius: 999px; padding: 0 7px; font-size: 12px; margin-left: 2px; }

main { padding: 20px 16px 40px; }
h2 { margin: 6px 0 12px; font-size: 24px; }
h3 { margin: 0 0 8px; font-size: 18px; }
.panel { background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius); padding: 16px; }

/* Buttons */
.btn {
  border: 2px solid #111; background: #8f8f8f; color: #fff; padding: 10px 16px; border-radius: 4px; font-weight: 800;
  box-shadow: inset -3px -4px 0 #555, inset 3px 3px 0 #bdbdbd; text-shadow: 1px 1px 0 #333;
}
.btn.go { background: var(--grass); box-shadow: inset -3px -4px 0 var(--grass-dark), inset 3px 3px 0 #86b957; font-size: 20px; padding: 12px 22px; }
.btn.gold { background: #d9a531; box-shadow: inset -3px -4px 0 #9c731b, inset 3px 3px 0 #f5d27e; }
.btn.red { background: #b8433b; box-shadow: inset -3px -4px 0 #7f2a24, inset 3px 3px 0 #e3827a; }
.btn:disabled { filter: grayscale(1); opacity: .5; cursor: not-allowed; }

/* Lab */
.lab { display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: stretch; }
.slot { text-align: center; }
.slot canvas, .result canvas, .mob-card canvas { image-rendering: pixelated; image-rendering: crisp-edges; display: block; margin: 0 auto; }
.slot .name { font-size: 20px; font-weight: 900; margin-top: 6px; min-height: 30px; }
.slot.empty canvas { opacity: .25; }
.plus { align-self: center; font-size: 42px; font-weight: 900; color: var(--gold); text-shadow: 2px 2px 0 #000; }
.picker { margin-top: 16px; }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.pick {
  background: var(--panel2); border: 2px solid var(--line); border-radius: 8px; color: var(--ink); padding: 6px 4px; text-align: center;
}
.pick canvas { image-rendering: pixelated; display: block; margin: 0 auto; }
.pick span { display: block; font-size: 13px; font-weight: 700; margin-top: 2px; }
.pick[data-slot="a"] { border-color: var(--blue); background: #243a4e; }
.pick[data-slot="b"] { border-color: var(--red); background: #4a2a28; }
.pick .tag { font-size: 11px; font-weight: 800; }
.hint { text-align: center; margin: 12px 0; }

.result { margin-top: 18px; display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 16px; align-items: start; }
.result .picture { text-align: center; background: repeating-conic-gradient(#3a3e46 0 25%, #33363d 0 50%) 0 0 / 24px 24px; border-radius: var(--radius); padding: 14px; border: 2px solid var(--line); }
.fusion-name { font-size: clamp(26px, 5vw, 36px); font-weight: 900; margin: 0; color: var(--gold); text-shadow: 2px 2px 0 #000; font-family: "Courier New", monospace; }
.parents { margin: 2px 0 10px; }
.parents b.a { color: var(--blue); } .parents b.b { color: var(--red); }

/* Stats */
.stats { display: grid; gap: 8px; }
.stat { display: grid; grid-template-columns: 110px 1fr 90px; gap: 8px; align-items: center; }
.stat .label { font-weight: 800; }
.stat .value { text-align: right; font-variant-numeric: tabular-nums; }
.meter { height: 14px; background: #15161a; border: 2px solid #111; border-radius: 3px; overflow: hidden; }
.meter i { display: block; height: 100%; }
.meter.hp i { background: var(--red); }
.meter.atk i { background: #e98a33; }
.meter.spd i { background: var(--blue); }
.meter.size i { background: var(--purple); }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; margin-top: 12px; }
.fact { background: var(--panel2); border-radius: 8px; padding: 8px 10px; }
.fact b { display: block; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 800; }
.badge.passive { background: #2f5d2a; color: #b8f0a8; }
.badge.neutral { background: #5d552a; color: #f0e3a8; }
.badge.hostile { background: #5d2a2a; color: #f0b0a8; }
.badge.boss { background: #452a5d; color: #d8b8f5; }
.compare { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 14px; }
.compare th, .compare td { border-bottom: 1px solid var(--line); padding: 6px; text-align: left; vertical-align: top; }
.compare th { color: var(--muted); font-weight: 700; }
.compare td.fusion { color: var(--gold); font-weight: 800; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* Chart */
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.filters button { border: 2px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 999px; padding: 4px 12px; font-weight: 700; }
.filters button[aria-pressed="true"] { background: var(--gold); color: #222; border-color: var(--gold); }
.chart-wrap { overflow-x: auto; border: 2px solid var(--line); border-radius: var(--radius); }
table.chart { border-collapse: collapse; width: 100%; min-width: 760px; font-size: 14px; }
table.chart th, table.chart td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.chart th { background: var(--panel2); position: sticky; top: 0; cursor: pointer; white-space: nowrap; }
table.chart tr:hover td { background: #30343b; }
table.chart canvas { image-rendering: pixelated; display: block; }

/* Collection */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.mob-card { background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius); padding: 12px; text-align: center; }
.mob-card h3 { margin: 6px 0 0; color: var(--gold); font-family: "Courier New", monospace; }
.mob-card .card-actions { display: flex; gap: 6px; justify-content: center; margin-top: 8px; }
.mob-card .btn { padding: 6px 10px; font-size: 14px; }
.empty-note { text-align: center; padding: 40px 10px; }

.foot { color: var(--muted); font-size: 12px; padding-bottom: 30px; text-align: center; }

@media (max-width: 720px) {
  .lab { grid-template-columns: 1fr 1fr; }
  .plus { display: none; }
  .result { grid-template-columns: 1fr; }
  .stat { grid-template-columns: 84px 1fr 70px; }
}
