:root {
    --dex-col: 1;
    --dex-small: #3581dd;
    --dex-medium: #e53d4a;
    --dex-large: #25df48;
    --dex-boost: #e53d4a;
    --dex-degradation: #3581dd;
}
@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) { --dex-large: #12a632; }
}
:root[data-theme="light"] { --dex-large: #12a632; }

.dex-icon-sm { width: 20px; height: 20px; object-fit: contain; vertical-align: middle; }
.dex-icon { width: 24px; height: 24px; object-fit: contain; flex: none; }
.dex-poke-icon { width: 32px; height: 32px; object-fit: contain; flex: none; }
.dex-muted { color: var(--wa-muted); }
.dex-pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.dex-num { font-variant-numeric: tabular-nums; }
.dex-nowrap { white-space: nowrap; }

.dex-types { display: inline-flex; flex-wrap: wrap; gap: 4px; vertical-align: middle; }
.dex-type { display: inline-flex; align-items: center; justify-content: center; min-width: 72px; height: 18px; padding: 0 6px; border-radius: 9px; color: #fff; font-size: .7rem; font-weight: 700; line-height: 1; white-space: nowrap; text-shadow: 0 0 2px rgba(0, 0, 0, .55); }
.dex-type-xs { min-width: 48px; height: 14px; font-size: .6rem; border-radius: 7px; padding: 0 4px; }
.dex-type-md { min-width: 90px; height: 22px; font-size: .8rem; border-radius: 11px; }

.dex-game { display: inline-flex; min-width: 80px; height: 18px; border-radius: 9px; overflow: hidden; font-size: .68rem; font-weight: 700; vertical-align: middle; flex: none; }
.dex-game > span { flex: 1; display: inline-flex; align-items: center; justify-content: center; padding: 0 5px; white-space: nowrap; border-right: 1px solid rgba(127, 127, 127, .25); }
.dex-game > span:last-child { border-right: 0; }

.dex-gens { display: inline-flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.dex-toolbar-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.dex-chip-img { width: 18px; height: 18px; object-fit: contain; }
.dex-select { font-weight: 600; }

.dex-cards { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(100%, calc(320px * var(--dex-col))), 1fr)); margin: 12px 0; }
.dex-card { position: relative; display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 2px 10px; padding: 10px; background: var(--wa-surface); border: 1px solid var(--wa-border); border-radius: var(--wa-radius); box-shadow: var(--wa-shadow); content-visibility: auto; contain-intrinsic-size: auto 120px; }
.dex-card:hover { border-color: var(--wa-accent); }
.dex-card-num { grid-row: 1; grid-column: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .7rem; }
.dex-card-main { grid-row: 1; grid-column: 2; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.dex-card-title { font-weight: 700; color: var(--wa-text); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dex-card-title::after { content: ""; position: absolute; inset: 0; border-radius: var(--wa-radius); }
.dex-card-sub { font-size: .7rem; color: var(--wa-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dex-card-stats { grid-row: 1; grid-column: 3; display: grid; grid-template-columns: auto auto auto auto; gap: 0 6px; font-size: .7rem; align-self: center; }
.dex-card-stats b { font-weight: 700; }
.dex-card-stats span { text-align: right; font-variant-numeric: tabular-nums; }
.dex-card-flags { grid-row: 2; grid-column: 2 / 4; }
.dex-card-weak { grid-row: 3; grid-column: 2 / 4; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.dex-card-weak[hidden] { display: none; }
.dex-card .dex-flags, .dex-card .wa-btn, .dex-card button { position: relative; z-index: 1; }
.dex-card.wa-filtered, .dex-card.wa-excluded { display: none; }

.dex-flags { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.dex-flag { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 3px; border: 0; border-radius: 6px; background: none; cursor: pointer; color: var(--wa-text); }
.dex-flag:hover { background: var(--wa-surface-2); }
.dex-flag img { width: 22px; height: 22px; object-fit: contain; }
.dex-flag .dex-mask { display: block; width: 20px; height: 20px; background: currentColor; -webkit-mask: var(--dex-mask) center / contain no-repeat; mask: var(--dex-mask) center / contain no-repeat; }
.dex-mask-Circle { --dex-mask: url('../img/Flag_Circle.png'); }
.dex-mask-Triangle { --dex-mask: url('../img/Flag_Triangle.png'); }
.dex-mask-Square { --dex-mask: url('../img/Flag_Square.png'); }
.dex-mask-Heart { --dex-mask: url('../img/Flag_Heart.png'); }
.dex-mask-Star { --dex-mask: url('../img/Flag_Star.png'); }
.dex-mask-Rhombus { --dex-mask: url('../img/Flag_Rhombus.png'); }
.dex-flag[data-level="0"] { color: var(--wa-muted); }
.dex-flag[data-level="1"] { color: var(--dex-small); }
.dex-flag[data-level="2"] { color: var(--dex-medium); }
.dex-flag[data-level="3"] { color: var(--dex-large); }
.dex-flags-lg .dex-flag { width: 38px; height: 38px; }
.dex-flags-lg .dex-flag img, .dex-flags-lg .dex-flag .dex-mask { width: 28px; height: 28px; }

.dex-hero { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 8px 0 16px; text-align: center; }
.dex-artwork { width: 224px; height: 224px; object-fit: contain; }
.dex-hero h1 { margin: 0; }
.dex-nav { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 4px 0; }
.dex-nav a { display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: 48%; color: var(--wa-text); text-decoration: none; font-size: .9rem; }
.dex-nav a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dex-sections { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr)); align-items: start; }
.dex-sections > .wa-card { margin: 0; overflow: hidden; padding: 0; }
.dex-section-title { margin: 0; padding: 10px 12px; background: var(--wa-accent); color: var(--wa-accent-text); font-size: .95rem; text-align: center; }
.dex-section-body { padding: 10px 12px; }
.dex-rows { width: 100%; border-collapse: collapse; font-size: .85rem; }
.dex-rows th, .dex-rows td { padding: 6px 8px; border-bottom: 1px solid var(--wa-border); text-align: left; vertical-align: middle; }
.dex-rows tr:last-child th, .dex-rows tr:last-child td { border-bottom: 0; }
.dex-rows th { width: 40%; font-weight: 600; }
.dex-rows td.num { text-align: right; font-variant-numeric: tabular-nums; }
.dex-list-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--wa-border); color: var(--wa-text); text-decoration: none; }
.dex-list-row:last-child { border-bottom: 0; }
a.dex-list-row:hover { background: var(--wa-surface-2); }
.dex-list-row .dex-grow { flex: 1; min-width: 0; }
.dex-list-row small { display: block; color: var(--wa-muted); }
.dex-trigger { flex: 0 0 34%; font-size: .78rem; text-align: center; color: var(--wa-muted); }
.dex-game-row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px; align-items: start; padding: 8px 12px; border-bottom: 1px solid var(--wa-border); font-size: .85rem; }
.dex-game-row:last-child { border-bottom: 0; }
.dex-game-row .dex-game { margin-top: 1px; }

.dex-weakness { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--wa-border); }
.dex-weakness-head { padding: 6px; text-align: center; font-weight: 700; background: var(--wa-surface-2); }
.dex-weakness-list { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; background: var(--wa-surface); min-height: 34px; }

.dex-calc-head { display: grid; grid-template-columns: auto 80px minmax(0, 1fr); gap: 8px; align-items: center; padding: 8px 12px; }
.dex-calc-head input, .dex-calc-head select { width: 100%; }
.dex-stat { border-top: 1px solid var(--wa-border); }
.dex-stat-main { display: grid; grid-template-columns: 112px minmax(0, 1fr) 40px 20px; gap: 6px; align-items: center; width: 100%; padding: 6px 12px; border: 0; background: none; color: var(--wa-text); font: inherit; font-size: .85rem; cursor: pointer; text-align: left; }
.dex-stat-main:hover { background: var(--wa-surface-2); }
.dex-stat-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dex-stat-name.dex-boost { color: var(--dex-boost); }
.dex-stat-name.dex-degradation { color: var(--dex-degradation); }
.dex-stat-bar { height: 10px; background: var(--wa-surface-2); border: 1px solid var(--wa-border); border-radius: 3px; overflow: hidden; }
.dex-stat-bar span { display: block; height: 100%; width: 0; background: #2da44e; }
.dex-stat-value { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.dex-stat-detail { display: grid; grid-template-columns: 64px minmax(0, 1fr) 64px; gap: 4px 8px; align-items: center; padding: 4px 12px 10px; font-size: .8rem; }
.dex-stat-detail input[type="range"] { width: 100%; accent-color: var(--wa-accent); }
.dex-stat-detail input[type="number"] { width: 64px; padding: 4px 6px; text-align: right; }
.dex-stat-detail label { text-align: right; color: var(--wa-muted); }
.dex-calc-foot { display: flex; align-items: center; gap: 12px; padding: 6px 12px; border-top: 1px solid var(--wa-border); background: var(--wa-surface-2); font-size: .85rem; }
.dex-calc-foot .wa-iconbtn { margin-left: auto; width: 32px; height: 32px; }
.dex-chevron { transition: transform .15s ease; color: var(--wa-muted); }
[aria-expanded="true"] > .dex-chevron { transform: rotate(180deg); }

.dex-images { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; padding: 10px 12px; }
.dex-images figure { margin: 0; text-align: center; font-size: .75rem; }
.dex-images figcaption { padding: 2px 4px; background: var(--wa-surface-2); border-radius: 4px; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dex-images .dex-pair { display: flex; justify-content: center; gap: 4px; }
.dex-images img { width: 64px; height: 64px; object-fit: contain; image-rendering: auto; }

.dex-move-table { table-layout: fixed; }
.dex-move-table th, .dex-move-table td { padding: 6px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dex-move-table .dex-col-src { width: 64px; }
.dex-move-table .dex-col-type { width: 84px; }
.dex-move-table .dex-col-num { width: 52px; text-align: right; }
.dex-move-table .dex-col-cat { width: 44px; text-align: center; }
.dex-move-table .dex-col-exp { width: 44px; text-align: center; padding: 2px; }
.dex-move-table td.dex-move-name a { color: var(--wa-text); text-decoration: none; }
.dex-move-table td.dex-move-name a:hover { text-decoration: underline; }
.dex-move-table .dex-step { font-weight: 700; }
.dex-move-table tr.dex-move-extra td { white-space: normal; background: var(--wa-surface-2); }
.dex-move-table .wa-table-wrap, .dex-move-wrap { overflow-x: auto; }
.dex-move-table .dex-type { min-width: 0; width: 100%; max-width: 84px; }
.dex-rows th a { color: inherit; text-decoration: none; }
.dex-rows th a:hover { text-decoration: underline; }
.dex-breed-group { margin: 6px 0; }
.dex-breed-group h4 { margin: 4px 0; font-size: .8rem; }
.dex-breed-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px; }
.dex-breed-grid a { display: flex; align-items: center; gap: 6px; padding: 2px 4px; border-radius: 6px; background: var(--wa-surface); color: var(--wa-text); text-decoration: none; font-size: .78rem; min-width: 0; }
.dex-breed-grid a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dex-breed-grid img { width: 24px; height: 24px; }
.dex-games-wrap { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; padding: 4px 0; }
.dex-gen-tabs { position: sticky; top: var(--wa-topbar-h); z-index: 5; background: var(--wa-bg); }

.dex-team-list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(100%, calc(320px * var(--dex-col))), 1fr)); margin: 12px 0; }
.dex-team-card { display: flex; flex-direction: column; gap: 8px; padding: 10px; background: var(--wa-surface); border: 1px solid var(--wa-border); border-radius: var(--wa-radius); box-shadow: var(--wa-shadow); color: var(--wa-text); text-decoration: none; cursor: pointer; text-align: left; font: inherit; }
.dex-team-card:hover { border-color: var(--wa-accent); }
.dex-team-head { display: flex; align-items: center; gap: 8px; }
.dex-team-head strong { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dex-team-members { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; }
.dex-team-member { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .62rem; text-align: center; min-width: 0; }
.dex-team-member span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dex-team-member .dex-poke-icon { width: 40px; height: 40px; }
.dex-team-member .dex-badge-shiny { position: absolute; top: -2px; right: 0; width: 14px; height: 14px; }
.dex-team-member .dex-badge-item { position: absolute; top: 22px; right: 0; width: 18px; height: 18px; }
.dex-team-note { font-size: .75rem; color: var(--wa-muted); overflow-wrap: anywhere; white-space: pre-wrap; }
.dex-team-add { align-items: center; justify-content: center; min-height: 110px; color: var(--wa-muted); }
.dex-team-add img { width: 42px; height: 42px; }

.dex-editor { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr)); align-items: start; }
.dex-editor > .wa-card { margin: 0; }
.dex-field-head { display: flex; justify-content: space-between; align-items: baseline; margin: 8px 0 4px; font-weight: 600; }
.dex-field-head small { font-weight: 400; color: var(--wa-muted); }
.dex-editor textarea { width: 100%; min-height: 80px; resize: vertical; }
.dex-editor input[type="text"], .dex-editor select { width: 100%; }
.dex-member { display: flex; flex-direction: column; gap: 6px; }
.dex-member-head { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.dex-member-head input { font-weight: 700; }
.dex-genders { display: inline-flex; gap: 6px; align-items: center; }
.dex-genders label { display: inline-flex; align-items: center; gap: 2px; font-weight: 700; cursor: pointer; }
.dex-slot { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 8px; border: 1px solid var(--wa-border); border-radius: 8px; background: var(--wa-surface-2); color: var(--wa-text); font: inherit; text-align: left; cursor: pointer; min-height: 40px; }
.dex-slot:hover { border-color: var(--wa-accent); }
.dex-slot .dex-grow { flex: 1; min-width: 0; }
.dex-slot small { display: block; font-size: .72rem; color: var(--wa-muted); overflow-wrap: anywhere; }
.dex-slot-empty { justify-content: center; color: var(--wa-muted); font-style: italic; }
.dex-move-slot { display: grid; grid-template-columns: minmax(0, 1fr) 84px 40px 24px 44px; gap: 6px; align-items: center; }
.dex-move-slot.dex-slot-empty { display: flex; }
.dex-expander { display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; padding: 6px; border: 1px solid var(--wa-border); border-radius: 8px; background: var(--wa-surface-2); color: var(--wa-text); font: inherit; font-weight: 600; cursor: pointer; }
.dex-checks { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; }
.dex-checks label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.dex-checks img { width: 28px; height: 28px; object-fit: contain; }
.dex-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 16px 0; }
.dex-actions .wa-btn { flex-direction: column; gap: 4px; padding: 10px; }
.dex-actions .wa-btn img { width: 24px; height: 24px; }
.dex-uncovered { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 8px 0; }

dialog.dex-picker { max-width: min(96vw, 760px); padding: 0; }
dialog.dex-picker .dex-picker-head { position: sticky; top: 0; z-index: 2; display: flex; gap: 8px; align-items: center; padding: 12px; background: var(--wa-surface); border-bottom: 1px solid var(--wa-border); }
dialog.dex-picker .dex-picker-head h2 { margin: 0; font-size: 1rem; flex: none; }
dialog.dex-picker .dex-picker-head .wa-search { flex: 1; margin: 0; min-width: 0; }
dialog.dex-picker .dex-picker-body { max-height: min(70vh, 640px); overflow-y: auto; padding: 8px 12px 12px; }
.dex-pick { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border: 0; border-bottom: 1px solid var(--wa-border); background: none; color: var(--wa-text); font: inherit; text-align: left; cursor: pointer; }
.dex-pick:hover { background: var(--wa-surface-2); }
.dex-pick .dex-grow { flex: 1; min-width: 0; }
.dex-pick small { display: block; font-size: .72rem; color: var(--wa-muted); overflow-wrap: anywhere; }
.dex-pick-stats { display: grid; grid-template-columns: auto auto auto auto; gap: 0 6px; font-size: .68rem; flex: none; }
.dex-pick-stats span { text-align: right; }
.dex-pick-move { display: grid; grid-template-columns: 56px minmax(0, 1fr) 84px 40px 24px 44px 32px; gap: 6px; align-items: center; }
.dex-picker-section { margin: 12px 0 4px; font-weight: 700; font-size: .85rem; color: var(--wa-muted); }

@media (max-width: 599px) {
    .dex-card { grid-template-columns: 40px minmax(0, 1fr) auto; gap: 2px 8px; padding: 8px; }
    .dex-card-stats { font-size: .65rem; gap: 0 4px; }
    .dex-flag { width: 28px; height: 28px; }
    .dex-flag .dex-mask { width: 18px; height: 18px; }
    .dex-stat-main { grid-template-columns: 96px minmax(0, 1fr) 36px 18px; padding: 6px 10px; }
    .dex-stat-detail { grid-template-columns: 52px minmax(0, 1fr) 58px; padding: 4px 10px 10px; }
    .dex-stat-detail input[type="number"] { width: 58px; }
    .dex-move-slot { grid-template-columns: minmax(0, 1fr) 72px 34px 22px 40px; gap: 4px; font-size: .8rem; }
    .dex-pick-move { grid-template-columns: 44px minmax(0, 1fr) 72px 34px 22px 40px; gap: 4px; font-size: .78rem; }
    .dex-pick-move .dex-col-ap { display: none; }
    .dex-pick-stats { display: none; }
    .dex-type { min-width: 60px; }
    .dex-move-table { font-size: .8rem; }
    .dex-move-table th, .dex-move-table td { padding: 6px 4px; }
    .dex-move-table .dex-col-type { width: 60px; }
    .dex-move-table .dex-col-src { width: 50px; }
    .dex-move-table .dex-col-num { width: 42px; }
    .dex-move-table .dex-col-cat { width: 30px; }
    .dex-move-table .dex-col-exp { width: 34px; }
    .dex-move-table .dex-col-ap { display: none; }
    .dex-move-table .dex-type { font-size: .6rem; padding: 0 2px; }
}
