:root {
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    padding: 40px 20px;
    font-family: system-ui, -apple-system, sans-serif;
    background: #121212;
    color: #e0e0e0;
    line-height: 1.5;
}

.card {
    width: 100%;
    max-width: 980px;
    margin: auto;
    padding: 30px;
    border-radius: 8px;
    background: #1e1e1e;
    box-shadow: 0 4px 12px #0008;
}

.header-container,
.header-images,
.label-row {
    display: flex;
    align-items: center;
}

.header-container {
    gap: 15px;
    margin-bottom: 24px;
}

.header-images {
    gap: 8px;
}

.icon {
    width: 40px;
    height: 40px;
    object-fit: contain;
    image-rendering: pixelated;
}

h1 {
    margin: 0;
    font-size: 1.4rem;
    color: #fff;
}

h2 {
    margin: 0 0 14px;
    font-size: 1.1rem;
    color: #fff;
}

p {
    margin: 0 0 18px;
}

a {
    color: #80bfff;
}

a:hover {
    color: #b3d9ff;
}

.description {
    margin-bottom: 24px;
    font-size: .9rem;
    color: #ccc;
}

.tabs {
    display: flex;
    gap: 6px;
    padding-bottom: 10px;
    margin-bottom: 26px;
    border-bottom: 1px solid #404040;
}

.tabs button {
    flex: 1;
    background: #2d2d2d;
    color: #ccc;
    border-bottom: 3px solid transparent;
}

.tabs button[aria-selected="true"] {
    background: #173653;
    border-bottom-color: #80bfff;
    color: #fff;
}

#panel-save {
    max-width: 580px;
    margin: auto;
}

#panel-walkthrough {
    max-width: 720px;
    margin: auto;
}

.form-row {
    display: flex;
    gap: 16px;
    margin-bottom: 18px;
    align-items: flex-end;
}

.form-group {
    min-width: 0;
    margin-bottom: 18px;
}

.form-row>.form-group {
    flex: 1;
    margin-bottom: 0;
}

fieldset {
    min-width: 0;
    padding: 0;
    margin: 0;
    border: 0;
}

label,
legend {
    display: block;
    margin-bottom: 8px;
    font-size: .9rem;
    font-weight: 600;
    color: #ccc;
}

.section-title {
    font-size: 1rem;
    color: #fff;
    margin-bottom: 16px;
}

.label-row {
    gap: 8px;
    margin-bottom: 8px;
}

.label-row label {
    margin-bottom: 0;
}

input[type="text"],
select {
    display: block;
    width: 100%;
    height: 44px;
    padding: 10px;
    font: inherit;
    font-size: .95rem;
    background: #2d2d2d;
    color: #fff;
    border: 1px solid #555;
    border-radius: 4px;
}

input::placeholder {
    color: #a3a3a3;
}

:focus-visible {
    outline: 2px solid #80bfff;
    outline-offset: 3px;
}

input[aria-invalid="true"] {
    border-color: #ff8585;
}

.gender-toggle {
    display: flex;
    height: 44px;
    border-radius: 4px;
    background: #2d2d2d;
    border: 1px solid #555;
}

.gender-toggle input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.toggle-option {
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: center;
    margin: 0;
    cursor: pointer;
    border-radius: 3px;
}

.gender-toggle input:checked+label {
    background: #0066cc;
    color: #fff;
}

.gender-toggle input:focus-visible+label {
    outline: 2px solid #80bfff;
    outline-offset: 3px;
}

.help-text {
    color: #b3b3b3;
    font-size: .82rem;
    margin: 4px 0 18px;
}

#trainer-name-preview {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.info-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 3px;
    margin: -4px 0;
    background: transparent;
    color: #80bfff;
    flex: none;
}

.info-button svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 1.8;
    fill: none;
    stroke-linecap: round;
}

.info-button .info-dot {
    fill: currentColor;
    stroke: none;
}

.info-button[aria-expanded="true"] {
    background: #173653;
}

.help-box {
    padding: 12px;
    border: 1px solid #555;
    border-radius: 4px;
    background: #2d2d2d;
    font-size: .85rem;
}

button {
    padding: 11px 14px;
    min-height: 44px;
    border: 0;
    border-radius: 4px;
    font: inherit;
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
}

.info-button {
    min-height: 28px;
}

button:disabled {
    opacity: .55;
    cursor: default;
}

.btn-primary {
    background: #0066cc;
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: #0052a3;
}

.btn-secondary {
    background: #383838;
    color: #f0f0f0;
}

.btn-secondary:hover:not(:disabled),
.tabs button:hover {
    background: #444;
}

.button-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 26px;
}

.button-group button {
    flex: 1;
}

.button-field button {
    width: 100%;
}

#status {
    margin-top: 16px;
    font-size: .9rem;
    text-align: center;
}

#finder-status,
#calibration-status {
    margin-top: 18px;
    font-size: .9rem;
}

.walkthrough-pane {
    max-height: 60vh;
    min-height: 240px;
    overflow-y: auto;
    padding: 22px;
    background: #252525;
    border: 1px solid #444;
    border-radius: 6px;
    scrollbar-gutter: stable;
}

.walkthrough-pane ol {
    padding-left: 24px;
    margin: 0 0 26px;
}

.walkthrough-pane li {
    padding-left: 4px;
    margin-bottom: 16px;
}

#panel-finder>.description {
    margin-bottom: 18px;
}

.finder-trainer-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
    gap: 12px;
    align-items: end;
}

.finder-trainer-row>.form-group,
.finder-panel .form-group {
    margin-bottom: 0;
}

.finder-panels {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-top: 18px;
}

.finder-panel {
    min-width: 0;
    padding: 18px;
    border: 1px solid #404040;
    border-radius: 6px;
    background: #232323;
}

.finder-panel-heading {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 4px 12px;
    margin-bottom: 16px;
}

.finder-panel-title {
    display: flex;
    flex: 1;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 12px;
    min-width: 0;
}

.finder-panel h2 {
    margin: 0;
    font-size: 1rem;
}

.finder-reset {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 30px;
    height: 30px;
    min-height: 30px;
    padding: 4px;
}

.finder-reset svg {
    display: block;
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.finder-range-note {
    font-size: .78rem;
    color: #b3b3b3;
}

.finder-search-grid,
.hidden-power-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 12px;
    align-items: end;
}

.finder-panel label,
.finder-panel .label-row {
    margin-bottom: 6px;
    font-size: .85rem;
}

.finder-panel .label-row {
    gap: 4px;
}

.finder-panel .label-row label {
    margin-bottom: 0;
}

.finder-panel .help-box {
    margin: 12px 0 0;
}

.finder-note {
    margin: 10px 0 0;
    font-size: .78rem;
}

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

.iv-range legend {
    margin-bottom: 6px;
    font-size: .85rem;
    color: #e0e0e0;
}

.iv-range-inputs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
}

.iv-range-inputs>div {
    min-width: 0;
}

.iv-range label {
    margin-bottom: 4px;
    color: #b3b3b3;
    font-size: .72rem;
    font-weight: 400;
}

.iv-range input {
    min-width: 0;
    padding: 8px 4px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.finder-hidden-power {
    padding-top: 16px;
    margin-top: 18px;
    border-top: 1px solid #404040;
}

.finder-hidden-power h3 {
    margin: 0 0 12px;
    font-size: .9rem;
    color: #e0e0e0;
}

.finder-actionbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 20px;
    margin-top: 18px;
}

.finder-limits {
    margin: 0;
    font-size: .78rem;
}

.finder-actions {
    flex-wrap: nowrap;
    margin: 0;
}

.finder-actions button {
    flex: none;
    min-width: 132px;
}

.calibration-panel {
    margin-top: 24px;
}

.calibration-settings-grid,
.calibration-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px 12px;
    align-items: end;
}

.calibration-stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-top: 18px;
}

#calibration-result-rows button {
    white-space: nowrap;
    padding: 8px 10px;
}

table {
    border-collapse: collapse;
    width: 100%;
}

caption {
    text-align: left;
    font-size: .82rem;
    color: #b3b3b3;
    padding-bottom: 12px;
}

th,
td {
    padding: 10px 8px;
    text-align: left;
    border-bottom: 1px solid #444;
    font-size: .85rem;
}

th {
    color: #ddd;
    font-weight: 600;
}

.table-scroll {
    max-height: 480px;
    overflow: auto;
    border: 1px solid #444;
    border-radius: 4px;
}

.results-table {
    min-width: 900px;
}

.advance-heading {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.results-table caption {
    padding: 12px;
}

.results-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #2d2d2d;
}

.results-table tbody tr:nth-child(even) {
    background: #252525;
}

.results-table .shiny-row {
    box-shadow: inset 3px 0 #e5cf72;
}

.pid {
    font-family: ui-monospace, monospace;
}

.pagination {
    display: flex;
    gap: 16px;
    justify-content: space-between;
    align-items: center;
    margin-top: 16px;
    font-size: .85rem;
}

.error {
    color: #ff8585;
}

.success {
    color: #81d48a;
}

footer {
    margin-top: 30px;
    padding-top: 16px;
    border-top: 1px solid #383838;
    text-align: center;
    font-size: .85rem;
    color: #b3b3b3;
}

@media (max-width: 820px) {
    .finder-panels {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 640px) {
    body {
        padding: 16px 10px;
    }

    .card {
        padding: 20px 14px;
    }

    .tabs {
        gap: 4px;
    }

    .tabs button {
        padding: 10px 6px;
        font-size: .82rem;
    }

    .form-row {
        flex-wrap: wrap;
    }

    .form-row>.form-group {
        flex-basis: calc(50% - 8px);
    }

    .button-field {
        flex-basis: 100% !important;
    }

    .finder-trainer-row,
    .iv-grid,
    .calibration-settings-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .calibration-settings-grid>.form-group:first-child {
        grid-column: 1 / -1;
    }

    .finder-trainer-row>button {
        grid-column: 1 / -1;
    }

    .finder-panel {
        padding: 14px 12px;
    }

    .finder-actions {
        width: 100%;
    }

    .walkthrough-pane {
        padding: 16px;
    }

    .button-group button {
        flex-basis: 100%;
    }

    .finder-actions button {
        flex: 1 1 0;
        min-width: 0;
    }
}

@media (prefers-reduced-motion: no-preference) {
    button {
        transition: background-color .15s;
    }
}