/* EVs Trainer — design tokens from HANDOFF §5.7 */

/* Self-hosted fonts (SIL OFL 1.1, latin subset; licenses in fonts/OFL-*.txt) */
@font-face {
    font-family: "Chakra Petch";
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("../fonts/chakra-petch-600.woff2") format("woff2");
}

@font-face {
    font-family: "Chakra Petch";
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url("../fonts/chakra-petch-700.woff2") format("woff2");
}

@font-face {
    font-family: "IBM Plex Sans";
    font-style: normal;
    font-weight: 100 700;
    font-display: swap;
    src: url("../fonts/ibm-plex-sans-variable.woff2") format("woff2");
}

@font-face {
    font-family: "IBM Plex Mono";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/ibm-plex-mono-400.woff2") format("woff2");
}

@font-face {
    font-family: "IBM Plex Mono";
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("../fonts/ibm-plex-mono-600.woff2") format("woff2");
}

:root {
    color-scheme: light;
    --bg: #eef0f3;
    --surface: #ffffff;
    --surface-2: #f5f6f8;
    --line: #d9dde3;
    --fg: #1b1f26;
    --muted: #5b6472;
    --accent: #c8202f;
    --accent-soft: #fbe4e6;
    --ok: #1f7a45;
    --warn: #a85b00;
    --bad: #b3261e;
    --stat-0: #e0453a;
    --stat-1: #e9862a;
    --stat-2: #d6b21f;
    --stat-3: #3f7fd9;
    --stat-4: #3aa864;
    --stat-5: #d6508f;
    --font-display: "Chakra Petch", system-ui, sans-serif;
    --font-text: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
    --radius: 12px;
    --gutter: 16px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #12151a;
        --surface: #1b2028;
        --surface-2: #222833;
        --line: #323a47;
        --fg: #e9ecf1;
        --muted: #9aa4b3;
        --accent: #ff4d5a;
        --accent-soft: #3a1a1e;
        --ok: #5ccf8a;
        --warn: #f0a646;
        --bad: #ff7a70;
        --stat-0: #ff6b60;
        --stat-1: #ffa155;
        --stat-2: #e8c94a;
        --stat-3: #6fa6ff;
        --stat-4: #5fd08a;
        --stat-5: #ff7ab4;
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #12151a;
    --surface: #1b2028;
    --surface-2: #222833;
    --line: #323a47;
    --fg: #e9ecf1;
    --muted: #9aa4b3;
    --accent: #ff4d5a;
    --accent-soft: #3a1a1e;
    --ok: #5ccf8a;
    --warn: #f0a646;
    --bad: #ff7a70;
    --stat-0: #ff6b60;
    --stat-1: #ffa155;
    --stat-2: #e8c94a;
    --stat-3: #6fa6ff;
    --stat-4: #5fd08a;
    --stat-5: #ff7ab4;
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font-text);
    font-size: 16px;
    line-height: 1.4;
    -webkit-text-size-adjust: 100%;
}

#app {
    max-width: 560px;
    margin: 0 auto;
    min-height: 100dvh;
}

.boot {
    padding: 40vh var(--gutter) 0;
    text-align: center;
    font-family: var(--font-display);
    color: var(--muted);
}

button, input, select, textarea {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
    min-height: 44px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--surface-2);
    padding: 0 14px;
}

button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
}

button.danger {
    background: var(--bad);
    border-color: var(--bad);
    color: #fff;
}

button:disabled {
    opacity: .5;
    cursor: not-allowed;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

input, select, textarea {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    min-height: 44px;
    width: 100%;
}

input[inputmode="numeric"] {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    text-align: center;
    padding: 10px 4px;
}

input[aria-invalid="true"] {
    border-color: var(--bad);
}

/* Header */
.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px var(--gutter);
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
}

.app-header .left, .app-header .right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.app-header .left {
    min-width: 0;
}

.title {
    margin: 0;
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 700;
    letter-spacing: .02em;
    white-space: nowrap;
    flex-shrink: 0;
}

.title .accent {
    color: var(--accent);
}

@media (max-width: 400px) {
    .title { font-size: 17px; }
}

@media (max-width: 370px) {
    .title { font-size: 15px; }
}

.icon-button {
    min-width: 44px;
    padding: 0 10px;
    font-size: 20px;
    background: transparent;
    border-color: transparent;
}

.status {
    font-size: 18px;
    min-width: 28px;
    text-align: center;
}

.toggle {
    font-family: var(--font-display);
    font-size: 13px;
    text-transform: uppercase;
    padding: 0 8px;
    white-space: nowrap;
}

.toggle[aria-pressed="true"] {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 700;
}

/* Menu */
.menu-panel {
    position: fixed;
    left: max(var(--gutter), calc(50vw - 280px + var(--gutter)));
    top: 60px;
    max-height: calc(100dvh - 76px);
    overflow-y: auto;
    z-index: 30;
    width: min(320px, calc(100vw - 2 * var(--gutter)));
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
    padding: 6px;
}

.menu-panel ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.menu-panel button {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: transparent;
    border-color: transparent;
    text-align: left;
}

.menu-panel button:hover, .menu-panel button[aria-current="true"] {
    background: var(--surface-2);
}

.menu-panel .mark {
    color: var(--accent);
    margin-right: 6px;
}

.menu-panel hr {
    border: 0;
    border-top: 1px solid var(--line);
    margin: 6px 0;
}

.menu-panel .group-label {
    font-family: var(--font-display);
    font-size: 12px;
    text-transform: uppercase;
    color: var(--muted);
    padding: 6px 14px 2px;
}

.menu-panel .choices {
    display: flex;
    gap: 4px;
    padding: 4px 8px;
}

.menu-panel .choices button {
    justify-content: center;
    border-color: var(--line);
}

.menu-panel .choices button[aria-pressed="true"] {
    border-color: var(--accent);
    color: var(--accent);
}

.menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 25;
    background: transparent;
    border: 0;
    border-radius: 0;
}

/* Page */
.page {
    padding: 12px var(--gutter) 96px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
}

.card h2, .section-title {
    margin: 0 0 10px;
    font-family: var(--font-display);
    font-size: 15px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.section-title {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.card-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}

.card-head h2 {
    margin: 0;
}

.muted {
    color: var(--muted);
}

.num {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

.empty {
    text-align: center;
}

.empty .actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

/* Tabs */
.tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 4px;
    gap: 4px;
}

.tab {
    font-family: var(--font-display);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    background: transparent;
    border-color: transparent;
}

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

.tab-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* EV summary: the current species sprite is the title */
.card-head h2.summary-who {
    display: flex;
    line-height: 0;
}

.summary .card-head {
    align-items: center;
    gap: 6px;
}

.summary .totals {
    margin-left: auto;
    white-space: nowrap;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 10px;
}

.mini {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 8px;
    background: var(--surface-2);
}

.mini .label {
    font-family: var(--font-display);
    font-size: 12px;
    color: var(--muted);
}

.mini .value {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 15px;
}

.mini.done {
    border-color: var(--ok);
}

.mini.over {
    border-color: var(--bad);
}

.bar {
    height: 4px;
    border-radius: 2px;
    background: var(--line);
    margin-top: 6px;
    overflow: hidden;
}

.bar > span {
    display: block;
    height: 100%;
}

/* Search */
.search-row {
    display: flex;
    gap: 8px;
}

.segmented {
    display: flex;
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    flex-shrink: 0;
}

.segmented button {
    border: 0;
    border-radius: 0;
    background: var(--surface);
    font-family: var(--font-display);
    font-size: 13px;
    text-transform: uppercase;
}

.segmented button[aria-pressed="true"] {
    background: var(--accent);
    color: #fff;
}

.segmented button:disabled {
    opacity: 0.45;
    cursor: default;
}

/* Opponent grid */
.opponent-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.opponent-grid .grid-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--muted);
    padding: 16px;
}

.opponent {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    text-align: left;
    padding: 8px 8px;
    min-height: 56px;
    background: var(--surface);
    border-radius: 10px;
    border: 1px solid var(--line);
}

.opponent .info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1 1 auto;
    min-width: 0;
}

.opponent .row1 {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.opponent .name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1 1 auto;
    min-width: 0;
}

.opponent .count {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    color: var(--muted);
    font-size: 13px;
    flex-shrink: 0;
}

.opponent .yields {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.opponent .trainers {
    font-size: 12px;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ev-tag {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 6px;
    color: #fff;
    white-space: nowrap;
}

.stat-0 { background: var(--stat-0); }
.stat-1 { background: var(--stat-1); }
.stat-2 { background: var(--stat-2); color: #1b1f26; }
.stat-3 { background: var(--stat-3); }
.stat-4 { background: var(--stat-4); }
.stat-5 { background: var(--stat-5); }

.bump {
    animation: bump .25s ease-out;
}

.bump-alt {
    animation: bump-alt .25s ease-out;
}

@keyframes bump {
    0% { transform: scale(1); }
    40% { transform: scale(.95); background: var(--accent-soft); }
    100% { transform: scale(1); }
}

@keyframes bump-alt {
    0% { transform: scale(1); }
    40% { transform: scale(.95); background: var(--accent-soft); }
    100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    .bump, .bump-alt { animation: none; }
    * { scroll-behavior: auto; }
}

/* Collapsible sections */
details.card > summary {
    cursor: pointer;
    font-family: var(--font-display);
    text-transform: uppercase;
    font-size: 15px;
    letter-spacing: .04em;
    min-height: 32px;
    list-style-position: inside;
}

details.card[open] > summary {
    margin-bottom: 10px;
}

.history {
    list-style: none;
    margin: 0;
    padding: 0;
}

.history li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 4px 0;
    border-bottom: 1px solid var(--line);
}

.history li:last-child {
    border-bottom: 0;
}

.history .meta {
    font-family: var(--font-mono);
    color: var(--muted);
    font-size: 13px;
}

/* IV table */
.iv-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 13px;
}

.iv-table th, .iv-table td {
    padding: 6px 1px;
    text-align: center;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

@media (max-width: 400px) {
    .iv-table {
        font-size: 12px;
        letter-spacing: -0.02em;
    }
}

.iv-table th {
    font-family: var(--font-display);
    color: var(--muted);
    font-weight: 600;
}

.iv-table tr.final td, .iv-table tr.final th {
    font-weight: 700;
    background: var(--accent-soft);
}

.iv-table .bad {
    color: var(--bad);
    font-weight: 700;
}

.iv-table .remove {
    min-height: 44px;
    min-width: 44px;
    padding: 0;
    background: transparent;
    border-color: transparent;
}

.table-scroll {
    overflow-x: auto;
}

/* Forms */
.form-grid {
    display: grid;
    gap: 10px;
}

.field label, .field .label {
    display: block;
    font-family: var(--font-display);
    font-size: 12px;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 4px;
}

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

.six .cell label {
    text-align: center;
}

.two {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.hint {
    font-size: 13px;
    color: var(--muted);
}

.warn {
    color: var(--warn);
    font-size: 13px;
}

.error {
    color: var(--bad);
    font-size: 13px;
}

.row-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.species-block {
    border-top: 1px dashed var(--line);
    padding-top: 10px;
}

textarea {
    min-height: 120px;
    font-family: var(--font-mono);
    font-size: 13px;
}

/* Toast */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(16px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 40;
    width: min(528px, calc(100vw - 2 * var(--gutter)));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--fg);
    color: var(--bg);
    border-radius: var(--radius);
    padding: 8px 8px 8px 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}

.toast button {
    background: transparent;
    color: var(--bg);
    border-color: color-mix(in srgb, var(--bg) 40%, transparent);
    font-weight: 600;
    flex-shrink: 0;
}

/* Blazor error UI */
#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* Backup / file picker */
.file-button {
    position: relative;
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 14px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--surface-2);
    cursor: pointer;
}

.file-button input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    min-height: 0;
    padding: 0;
}

.file-button:focus-within {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.backup.inline {
    margin-top: 8px;
}

.backup.inline .row-actions {
    justify-content: center;
}

/* Species picker */
.species-picker {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.species-options {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.species-option .num {
    font-size: 12px;
    margin-right: 4px;
}

.line {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.species-chip {
    display: flex;
    flex-direction: column;
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface-2);
}

.species-chip + .species-chip::before {
    content: none;
}

.species-chip .name {
    font-weight: 600;
}

.species-chip .base-stats {
    font-size: 12px;
}

.evolutions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.evolutions .label {
    font-family: var(--font-display);
    font-size: 12px;
    text-transform: uppercase;
    color: var(--muted);
}

button.link, button.change-species {
    align-self: flex-start;
    background: transparent;
    border-color: transparent;
    color: var(--accent);
    padding: 0 4px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* Pokémon sprites (FireRed/LeafGreen, 64×64) with a colored badge underneath as fallback */
.sprite {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
    width: var(--sprite-size);
    height: var(--sprite-size);
    border-radius: 10px;
    overflow: hidden;
}

.sprite .badge {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--badge);
    color: #fff;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 11px;
    letter-spacing: .02em;
}

.sprite.badge-dark .badge {
    color: #1b1f26;
}

.sprite img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    background: var(--surface-2);
    opacity: 0;
    transition: opacity .2s ease-out;
}

.sprite img.loaded {
    opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
    .sprite img { transition: none; }
}

.species-option {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px 4px 4px;
}

/* Each species of the line is a toggle: the pressed one is the current form */
.species-chip {
    padding: 0;
    border: none;
    background: none;
}

button.species-current {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 4px 10px 4px 4px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface-2);
    color: inherit;
    font: inherit;
    text-align: left;
}

button.species-current[aria-pressed="true"] {
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.species-chip .chip-text {
    display: flex;
    flex-direction: column;
}

.menu-panel .who {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.menu-panel button.pokemon-item {
    min-height: 52px;
}

.menu-panel .pokemon-item .nature {
    font-size: 12px;
}

.menu-credits {
    margin: 4px 0 2px;
    padding: 0 14px;
    font-size: 11px;
    color: var(--muted);
}

.menu-version {
    margin: 0 0 4px;
    padding: 0 14px;
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--muted);
}

.menu-credits a {
    color: var(--accent);
}

/* Manual EV edit */
.summary .edit-evs {
    min-height: 44px;
    padding: 0 10px;
    white-space: nowrap;
}

/* Exp. Share holder (spec 012) */
.exp-share-field {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}

.exp-share-field select {
    min-height: 44px;
    min-width: 0;
}

.exp-share-self {
    margin: 6px 0 0;
}

.ev-editor {
    display: grid;
    gap: 10px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed var(--line);
}

.ev-editor h3 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 15px;
}

.ev-editor .history-choice {
    display: grid;
    gap: 4px;
    margin: 0;
    padding: 0;
    border: 0;
}

.ev-editor .history-choice input[type=radio] {
    flex: none;
    width: 20px;
    height: 20px;
    min-height: 0;
    margin: 0;
    padding: 0;
    accent-color: var(--accent);
}

.ev-editor .history-choice label {
    display: flex;
    text-transform: none;
    color: var(--fg);
    font-family: inherit;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    font-size: 14px;
}

.ev-editor .row-actions button {
    min-height: 44px;
}

.confirm-box {
    display: grid;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--bad);
    border-radius: 10px;
    background: color-mix(in srgb, var(--bad) 8%, transparent);
}

.confirm-box .message {
    margin: 0;
    font-size: 14px;
}

.history .what.adjustment {
    font-style: italic;
}

/* Known IVs */
.known-ivs .row-actions {
    margin-top: 10px;
}

.known-ivs .row-actions button {
    min-height: 44px;
}

.iv-table td.known .value::after {
    content: "*";
    color: var(--accent);
}

.iv-table td.known.bad .value::after {
    color: var(--bad);
}

/* Edit level note */
.iv-table .edit {
    min-height: 44px;
    padding: 0 4px;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    white-space: nowrap;
    text-decoration: underline dotted var(--accent);
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
}

.level-form.editing {
    border-color: var(--accent);
}

.level-form .row-actions button {
    min-height: 44px;
}

/* Capture evaluation */
.capture-view {
    display: grid;
    gap: 12px;
}

.capture-view .card-head .close-capture,
.capture-view .row-actions button,
.capture-species .change-species {
    min-height: 44px;
}

.capture-species {
    display: flex;
    align-items: center;
    gap: 10px;
}

.capture-species .name {
    flex: 1;
    font-family: var(--font-display);
    font-weight: 700;
}

.capture-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.capture-table th, .capture-table td {
    padding: 4px 6px;
    text-align: left;
    border-bottom: 1px solid var(--line);
}

.capture-table thead th {
    font-family: var(--font-display);
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
}

.capture-table .range {
    font-family: var(--font-mono);
    white-space: nowrap;
}

.capture-table .grade-great, .capture-table .grade-good {
    color: var(--ok);
    font-weight: 600;
}

.capture-table .grade-fair {
    color: var(--warn);
}

.capture-table .grade-poor, .capture-table .bad {
    color: var(--bad);
}

.capture-table tr.importance-ignored th,
.capture-table tr.importance-ignored td.range,
.capture-table tr.importance-ignored td.grade {
    opacity: 0.45;
}

.capture-table tr.importance-main th {
    color: var(--accent);
}

.capture-table .importance {
    min-height: 44px;
    min-width: 84px;
    padding: 0 8px;
    font-size: 13px;
}

.capture-table tr.importance-counts .importance {
    border-color: var(--accent);
    color: var(--accent);
}

.capture-table tr.importance-main .importance {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 700;
}

.capture-verdict {
    display: grid;
    gap: 4px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
}

.capture-verdict p {
    margin: 0;
}

.capture-verdict .label {
    font-family: var(--font-display);
    color: var(--muted);
}

.capture-verdict .verdict {
    font-size: 17px;
}

.empty .actions .capture {
    min-height: 44px;
}

.best-capture {
    display: grid;
    gap: 6px;
    padding: 10px 12px;
    border: 1px dashed var(--line);
    border-radius: 10px;
}

.best-capture h3 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 14px;
    text-transform: uppercase;
    color: var(--muted);
}

.best-capture p {
    margin: 0;
}

.best-capture .compare {
    font-weight: 700;
}

.best-capture .compare-better {
    color: var(--ok);
}

.best-capture .compare-worse {
    color: var(--bad);
}

/* Desktop layout (feature 007). Below 1024 px nothing here applies: the phone layout stays as is. */
@media (hover: hover) {
    .opponent:hover {
        border-color: var(--accent);
        background: var(--surface-2);
    }

    button:not(:disabled):hover {
        filter: brightness(0.97);
    }
}

@media (min-width: 1024px) {
    #app {
        max-width: 1440px;
    }

    .page {
        padding: 16px 24px 96px;
    }

    .opponent:focus-visible {
        outline-width: 3px;
    }

    .toast {
        left: auto;
        right: 24px;
        transform: none;
        width: 420px;
    }
}

/* Layout regions: neutral columns on the phone (same gaps as the tab panel). */
.ev-layout, .ev-summary-area {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

@media (min-width: 1024px) {
    .ev-layout {
        display: grid;
        grid-template-columns: 340px minmax(0, 1fr);
        column-gap: 20px;
        row-gap: 12px;
        align-items: start;
    }

    .ev-layout > * {
        grid-column: 2;
    }

    /* The summary stays in view while the opponent list scrolls (below the sticky header). */
    .ev-layout > .ev-summary-area {
        grid-column: 1;
        grid-row: 1 / span 20;
        position: sticky;
        top: 72px;
    }

    .opponent-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }
}

.iv-layout, .settings-layout, .capture-columns, .capture-inputs, .capture-output {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

@media (min-width: 1024px) {
    .iv-layout, .settings-layout {
        display: grid;
        grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
        column-gap: 20px;
        row-gap: 12px;
        align-items: start;
    }

    /* IVs: table and known IVs on the left, the level form on the right. */
    .iv-layout > .level-form {
        grid-column: 2;
        grid-row: 1 / span 2;
        position: sticky;
        top: 72px;
    }

    /* Settings: the Pokémon form on the left, backup / import / delete on the right. */
    .settings-layout > :first-child {
        grid-column: 1;
        grid-row: 1 / span 3;
    }

    .settings-layout > :not(:first-child) {
        grid-column: 2;
    }

    /* Capture: fields and actions on the left, result and best so far on the right. */
    .capture-columns {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
        column-gap: 24px;
        row-gap: 12px;
        align-items: start;
    }

    .capture-columns > .capture-inputs {
        grid-column: 1;
        grid-row: 1;
    }

    .capture-columns > .capture-actions {
        grid-column: 1;
        grid-row: 2;
    }

    .capture-columns > .capture-output {
        grid-column: 2;
        grid-row: 1 / span 2;
    }
}

/* Desktop with a mouse: the capture result can be denser than the 44 px touch targets of the phone. */
@media (min-width: 1024px) and (hover: hover) and (pointer: fine) {
    .capture-table th, .capture-table td {
        padding: 2px 6px;
    }

    .capture-table .importance,
    .capture-output .row-actions button,
    .best-capture .row-actions button {
        min-height: 34px;
    }
}

/* Side panel with the Pokémon in training: only from 1280 px (spec 007, US3). */
.pokemon-sidebar {
    display: none;
}

.pokemon-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

@media (min-width: 1280px) {
    #app {
        max-width: 1700px;
    }

    .app-body {
        display: grid;
        grid-template-columns: 240px minmax(0, 1fr);
        align-items: start;
        column-gap: 8px;
        padding-left: 16px;
    }

    .pokemon-sidebar {
        display: flex;
        flex-direction: column;
        gap: 6px;
        position: sticky;
        top: 72px;
        max-height: calc(100dvh - 88px);
        overflow-y: auto;
        margin-top: 16px;
        padding: 10px 6px;
        background: var(--surface);
        border: 1px solid var(--line);
        border-radius: var(--radius);
    }

    .pokemon-sidebar h2 {
        margin: 0 8px 4px;
        font-family: var(--font-display);
        font-size: 13px;
        text-transform: uppercase;
        color: var(--muted);
    }

    .pokemon-sidebar button.pokemon-item {
        width: 100%;
        min-height: 52px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 6px;
        background: transparent;
        border-color: transparent;
        text-align: left;
    }

    .pokemon-sidebar button.pokemon-item[aria-current="true"] {
        background: var(--surface-2);
        border-color: var(--accent);
    }

    .pokemon-sidebar .who {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        min-width: 0;
    }

    .pokemon-sidebar .mark {
        color: var(--accent);
    }

    /* 240 px is too narrow for sprite, name, nature and total: the panel shows the total, the menu the nature. */
    .pokemon-sidebar .nature {
        display: none;
    }

    .pokemon-sidebar .who {
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }

    .pokemon-sidebar .pokemon-item .num {
        flex: none;
    }

    .pokemon-sidebar .add {
        margin-top: 4px;
    }

    /* The side panel already lists the Pokémon: the menu keeps only its other actions. */
    .menu-panel .pokemon-list,
    .menu-panel .pokemon-list + hr {
        display: none;
    }
}

@media (min-width: 1280px) and (hover: hover) {
    .pokemon-sidebar button.pokemon-item:hover {
        background: var(--surface-2);
    }
}

/* Sync screen (spec 008) */
.sync-view {
    display: grid;
    gap: 12px;
    max-width: 720px;
}

.sync-view p {
    margin: 0;
}

.sync-view .steps {
    margin: 0;
    padding-left: 20px;
    display: grid;
    gap: 6px;
}

.sync-view .steps a, .sync-view .gist-link {
    color: var(--accent);
    font-weight: 600;
}

.sync-view .connected {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 17px;
}

.sync-view .row-actions button, .sync-view .close-sync {
    min-height: 44px;
}

.status-button {
    min-width: 44px;
    padding: 0;
    background: transparent;
    border-color: transparent;
}

/* Where to train (spec 013) */
.guide-view {
    display: grid;
    gap: 12px;
}

.guide-controls {
    display: grid;
    gap: 8px;
}

.guide-controls .segmented button {
    flex: 1;
}

.guide-tips {
    margin: 0;
    padding-left: 18px;
    display: grid;
    gap: 4px;
}

.guide-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 10px;
}

.guide-head {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 4px 8px;
}

.guide-head .who {
    font-weight: 600;
}

.guide-entry .marks {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.guide-entry .mark {
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--surface-2);
}

.guide-entry .stages {
    list-style: none;
    margin: 8px 0 0;
    padding: 0;
    display: grid;
    gap: 6px;
}

.guide-entry .stage {
    display: grid;
    gap: 2px;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid var(--line);
}

.guide-entry .stage.best {
    border-color: var(--accent);
}

.guide-entry .stage .label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
}

.guide-entry .stage.requires-e4 .label {
    color: var(--accent);
}

.guide-entry .stage .evs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
}

.guide-entry .stage .main {
    font-weight: 700;
}

.guide-entry .stage .also {
    color: var(--muted);
}

.guide-entry .waste {
    margin: 8px 0 0;
}

.open-guide {
    justify-self: start;
}

@media (min-width: 900px) {
    .guide-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .guide-controls {
        grid-template-columns: 1fr 1fr;
    }
}
