:root {
  color-scheme: dark;
  --ink: #f8f2df;
  --muted: #c4bda7;
  --shadow: #251636;
  --panel: #5b3d88;
  --panel-dark: #372255;
  --panel-light: #7752aa;
  --gold: #ffd45d;
  --orange: #e76f42;
  --green: #46b06f;
  --blue: #4ea6d8;
  --line: #251833;
  font-family: "Trebuchet MS", "Arial Rounded MT Bold", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 12%, rgba(255, 212, 93, 0.16), transparent 28%),
    linear-gradient(135deg, #24315f 0%, #34205c 42%, #201738 100%);
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.dex {
  width: min(1180px, 100%);
  height: min(760px, calc(100dvh - 36px));
  min-height: min(620px, calc(100dvh - 36px));
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 12px;
  padding: 16px;
  border: 5px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(#6d4ca0, #4b3376 48%, #33204f),
    var(--panel);
  box-shadow: 0 18px 0 rgba(0, 0, 0, 0.28), inset 0 0 0 3px rgba(255, 255, 255, 0.14);
}

.dex-header {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px;
  border: 4px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffbf5a, #df6e35);
  box-shadow: inset 0 4px rgba(255, 255, 255, 0.24), inset 0 -5px rgba(85, 36, 38, 0.26);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark,
.round-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 3px solid var(--line);
  border-radius: 50%;
  background: linear-gradient(#fff0a0, #f6b842);
  color: #392049;
  font-weight: 900;
  box-shadow: inset 0 3px rgba(255, 255, 255, 0.4), 0 3px rgba(0, 0, 0, 0.2);
}

.round-button {
  padding: 0;
  font-size: 20px;
}

.eyebrow,
h1,
h2,
h3,
p {
  margin: 0;
}

.eyebrow {
  color: #4d2640;
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}

h1 {
  color: #fff7d2;
  font-size: 34px;
  line-height: 0.95;
  text-shadow: 0 4px 0 #6d2b3e;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 170px 150px;
  gap: 10px;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 3px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff4d4;
  color: #2f2042;
  font-weight: 900;
  outline: none;
  box-shadow: inset 0 -4px rgba(120, 82, 50, 0.18);
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid #9ee8ff;
  outline-offset: 2px;
}

.content {
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(260px, 300px) minmax(0, 1fr);
  gap: 12px;
}

.monster-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 10px;
  border: 4px solid var(--line);
  border-radius: 8px;
  background: #2d1f49;
}

.list-item {
  min-height: 66px;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  grid-template-rows: 1fr auto;
  gap: 2px 10px;
  align-items: center;
  padding: 6px 8px;
  border: 3px solid #201532;
  border-radius: 8px;
  background: linear-gradient(180deg, #7350a6, #513477);
  color: var(--ink);
  text-align: left;
  box-shadow: inset 0 3px rgba(255, 255, 255, 0.12);
}

.list-item.active {
  background: linear-gradient(180deg, #ffd667, #e66d3a);
  color: #392049;
  transform: translateX(2px);
}

.thumb {
  grid-row: 1 / 3;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border: 3px solid #201532;
  border-radius: 8px;
  background: #f2e6c0;
}

.thumb img {
  width: 46px;
  height: 46px;
  object-fit: contain;
  image-rendering: auto;
}

.list-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
  font-weight: 900;
}

.list-tier,
.tier-stars {
  color: #4a315f;
  font-size: 13px;
  line-height: 1;
}

.list-tier .filled,
.tier-stars .filled {
  color: var(--gold);
  text-shadow: 0 2px 0 #7f3b37;
}

.detail {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(210px, 0.9fr) minmax(0, 1.1fr);
  gap: 12px;
}

.portrait-panel,
.info-panel {
  min-width: 0;
  min-height: 0;
  border: 4px solid var(--line);
  border-radius: 8px;
  background: #fff0cb;
  color: #392049;
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.35);
}

.portrait-panel {
  display: grid;
  grid-template-rows: 1fr auto;
  overflow: hidden;
}

.monster-stage {
  min-height: 0;
  display: grid;
  place-items: center;
  background:
    linear-gradient(45deg, rgba(78, 166, 216, 0.26) 25%, transparent 25% 50%, rgba(78, 166, 216, 0.26) 50% 75%, transparent 75%),
    #f9d990;
  background-size: 34px 34px;
}

.monster-art {
  width: min(78%, 320px);
  height: min(78%, 320px);
  object-fit: contain;
  filter: drop-shadow(0 12px 0 rgba(52, 32, 74, 0.18));
}

.variant-toggle,
.level-tabs {
  display: flex;
  gap: 8px;
  padding: 10px;
}

.variant-toggle button,
.level-tabs button {
  flex: 1;
  min-height: 38px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: #6b4a98;
  color: var(--ink);
  font-weight: 900;
  box-shadow: inset 0 3px rgba(255, 255, 255, 0.15);
}

.variant-toggle button.selected,
.level-tabs button.selected {
  background: linear-gradient(#5ac982, #2d935a);
  color: #fff7d2;
}

.info-panel {
  overflow: auto;
  padding: 14px;
}

.name-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.name-row .eyebrow {
  color: #87503b;
}

h2 {
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: clamp(28px, 3vw, 38px);
  line-height: 1;
  color: #392049;
}

.tier-stars {
  min-width: 92px;
  padding-top: 6px;
  font-size: 16px;
  text-align: right;
}

.type-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.type-badge {
  min-width: 84px;
  padding: 7px 12px;
  border: 3px solid #201532;
  border-radius: 999px;
  background: var(--type, #6b4a98);
  color: #fffbe6;
  font-weight: 900;
  text-align: center;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.28);
}

.facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.facts div {
  min-height: 64px;
  display: grid;
  place-items: center;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(#ffe5a4, #efb75f);
}

.facts span {
  color: #7a4a3d;
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}

.facts strong {
  font-size: 24px;
}

.stats {
  display: grid;
  gap: 8px;
}

.stat-row {
  min-height: 34px;
  display: grid;
  grid-template-columns: 86px 1fr 48px;
  gap: 10px;
  align-items: center;
  font-weight: 900;
}

.stat-track {
  height: 16px;
  overflow: hidden;
  border: 3px solid var(--line);
  border-radius: 999px;
  background: #d7bd86;
}

.stat-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--blue));
}

.stat-empty,
.empty,
.loading {
  padding: 18px;
  color: var(--muted);
  font-weight: 900;
  text-align: center;
}

.ability {
  margin-top: 14px;
  padding: 12px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: #f9d990;
}

.ability h3 {
  margin-bottom: 4px;
  color: #392049;
}

.ability-text {
  color: #392049;
  font-size: 18px;
  font-weight: 900;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.evolution-panel {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.evolution-item {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 66px;
  padding: 8px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: #d9e88f;
  cursor: pointer;
}

.evolution-item img {
  width: 54px;
  height: 54px;
  object-fit: contain;
  image-rendering: pixelated;
}

.evolution-item span,
.evolution-item em {
  display: block;
  color: #5f3d65;
  font-size: 12px;
  font-style: normal;
  font-weight: 900;
  text-transform: uppercase;
}

.evolution-item strong {
  display: block;
  color: #392049;
  font-size: 18px;
  line-height: 1.05;
  overflow-wrap: anywhere;
}

dialog {
  width: min(620px, calc(100% - 24px));
  border: 4px solid var(--line);
  border-radius: 8px;
  background: #fff0cb;
  color: #392049;
  padding: 18px;
}

dialog::backdrop {
  background: rgba(15, 10, 26, 0.72);
}

.close {
  position: absolute;
  top: 10px;
  right: 10px;
}

dl {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 8px 12px;
  margin: 18px 0 0;
}

dt {
  font-weight: 900;
}

dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

@media (max-width: 900px) {
  .shell {
    display: block;
    padding: 10px;
  }

  .dex {
    height: auto;
    min-height: calc(100dvh - 20px);
  }

  .toolbar,
  .content,
  .detail {
    grid-template-columns: 1fr;
  }

  .monster-list {
    max-height: 260px;
  }

  .detail {
    min-height: 0;
  }

  .portrait-panel {
    min-height: 320px;
  }

  .monster-stage {
    min-height: 240px;
  }
}

@media (max-width: 520px) {
  .shell {
    padding: 6px;
  }

  .dex {
    min-height: calc(100dvh - 12px);
    gap: 8px;
    padding: 8px;
    border-width: 3px;
  }

  h1 {
    font-size: 25px;
  }

  h2 {
    font-size: 30px;
  }

  .dex-header {
    align-items: flex-start;
    min-height: 62px;
    padding: 8px;
    border-width: 3px;
  }

  .brand {
    gap: 8px;
  }

  .brand-mark,
  .round-button {
    width: 38px;
    height: 38px;
    border-width: 2px;
  }

  .eyebrow {
    font-size: 11px;
  }

  input,
  select {
    min-height: 40px;
    border-width: 2px;
  }

  .monster-list {
    max-height: 210px;
    padding: 7px;
    border-width: 3px;
  }

  .list-item {
    min-height: 56px;
    grid-template-columns: 44px minmax(0, 1fr);
    border-width: 2px;
  }

  .thumb {
    width: 44px;
    height: 44px;
    border-width: 2px;
  }

  .thumb img {
    width: 39px;
    height: 39px;
  }

  .list-name {
    font-size: 16px;
  }

  .portrait-panel {
    min-height: 270px;
    border-width: 3px;
  }

  .monster-stage {
    min-height: 205px;
  }

  .monster-art {
    width: min(72%, 210px);
    height: min(72%, 210px);
  }

  .info-panel {
    padding: 10px;
    border-width: 3px;
  }

  .name-row {
    display: grid;
    gap: 4px;
  }

  .tier-stars {
    min-width: 0;
    text-align: left;
  }

  .facts,
  .stat-row {
    grid-template-columns: 1fr;
  }

  .stat-row {
    gap: 4px;
  }

  .level-tabs,
  .variant-toggle {
    gap: 6px;
    padding: 8px;
  }

  .level-tabs button,
  .variant-toggle button {
    min-height: 34px;
    border-width: 2px;
    font-size: 14px;
  }

  .ability {
    padding: 10px;
    border-width: 2px;
  }

  .ability-text {
    font-size: 16px;
  }
}
