*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #0d1117;
    --bg-card: #161b22;
    --bg-card-hover: #1c2333;
    --border: #30363d;
    --border-focus: #a855f7;
    --text: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent: #a855f7;
    --accent-hover: #9333ea;
    --accent-subtle: rgba(168, 85, 247, 0.1);
    --accent-amber: #f59e0b;
    --danger: #f87171;
    --success: #4ade80;
    --slider-track: #30363d;
    --slider-fill: #a855f7;
    --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --radius: 8px;
    --radius-sm: 4px;
    --transition: 0.2s ease;
}

/* ===== Pokémon Themes ===== */
[data-theme="gengar"] {
    --bg: #0a0e14;
    --bg-card: #161b22;
    --bg-card-hover: #1c2333;
    --border: #30363d;
    --border-focus: #c084fc;
    --text: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent: #c084fc;
    --accent-hover: #a78bfa;
    --accent-subtle: rgba(192, 132, 252, 0.12);
    --accent-amber: #f59e0b;
    --danger: #f87171;
    --success: #4ade80;
}

[data-theme="pikachu"] {
    --bg: #0d0d0d;
    --bg-card: #1a1a1a;
    --bg-card-hover: #222222;
    --border: #333333;
    --border-focus: #facc15;
    --text: #e6edf3;
    --text-secondary: #a0a0a0;
    --text-muted: #707070;
    --accent: #facc15;
    --accent-hover: #eab308;
    --accent-subtle: rgba(250, 204, 21, 0.12);
    --accent-amber: #f97316;
    --danger: #f87171;
    --success: #4ade80;
}

[data-theme="charizard"] {
    --bg: #120a0a;
    --bg-card: #1f1212;
    --bg-card-hover: #2a1818;
    --border: #3d2020;
    --border-focus: #ef4444;
    --text: #e6edf3;
    --text-secondary: #a08383;
    --text-muted: #705858;
    --accent: #ef4444;
    --accent-hover: #dc2626;
    --accent-subtle: rgba(239, 68, 68, 0.12);
    --accent-amber: #f59e0b;
    --danger: #f87171;
    --success: #4ade80;
}

[data-theme="mewtwo"] {
    --bg: #0b0d1a;
    --bg-card: #13162e;
    --bg-card-hover: #1b1f3a;
    --border: #2a2e4a;
    --border-focus: #818cf8;
    --text: #e6edf3;
    --text-secondary: #9499b8;
    --text-muted: #6a6e8a;
    --accent: #818cf8;
    --accent-hover: #6366f1;
    --accent-subtle: rgba(129, 140, 248, 0.12);
    --accent-amber: #f59e0b;
    --danger: #f87171;
    --success: #4ade80;
}

[data-theme="gardevoir"] {
    --bg: #120a12;
    --bg-card: #1f1420;
    --bg-card-hover: #2a1a2c;
    --border: #3d2030;
    --border-focus: #f472b6;
    --text: #e6edf3;
    --text-secondary: #a08390;
    --text-muted: #705868;
    --accent: #f472b6;
    --accent-hover: #ec4899;
    --accent-subtle: rgba(244, 114, 182, 0.12);
    --accent-amber: #f59e0b;
    --danger: #fb7185;
    --success: #4ade80;
}

[data-theme="alcremie"] {
    --bg: #0b0b0e;
    --bg-card: #16161f;
    --bg-card-hover: #1e1e2e;
    --border: #3a2a4a;
    --border-focus: #e879f9;
    --text: #e6edf3;
    --text-secondary: #b0a0c0;
    --text-muted: #807080;
    --accent: #a78bfa;
    --accent-hover: #8b5cf6;
    --accent-subtle: rgba(167, 139, 250, 0.15);
    --accent-amber: #f59e0b;
    --danger: #f87171;
    --success: #4ade80;
}

/* Rainbow card borders (mask technique — no z-index stacking context) */
[data-theme="alcremie"] .card {
    position: relative;
    background: var(--bg-card);
    border: none;
}

[data-theme="alcremie"] .card::before {
    content: '';
    position: absolute;
    inset: 0;
    padding: 2px;
    background: conic-gradient(#ff6b9d, #ffd93d, #6bcb77, #4d96ff, #b06ab3, #ff6b9d);
    border-radius: var(--radius);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    mask-composite: exclude;
    opacity: 0.85;
    pointer-events: none;
}

/* Animated gradient on primary buttons */
[data-theme="alcremie"] .btn-primary {
    background: linear-gradient(135deg, #ff6b9d, #ffd93d, #6bcb77, #4d96ff, #b06ab3);
    background-size: 300% 300%;
    animation: alcremieShift 4s ease infinite;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

[data-theme="alcremie"] .btn-primary:hover {
    filter: brightness(1.15);
}

[data-theme="alcremie"] .btn-primary:disabled {
    filter: grayscale(0.5) brightness(0.7);
}

/* Rainbow secondary buttons */
[data-theme="alcremie"] .btn-secondary {
    border: 1px solid transparent;
    background-clip: padding-box;
    position: relative;
}

[data-theme="alcremie"] .btn-secondary::before {
    content: '';
    position: absolute;
    inset: 0;
    padding: 1px;
    background: conic-gradient(#ff6b9d, #ffd93d, #6bcb77, #4d96ff, #b06ab3, #ff6b9d);
    border-radius: var(--radius-sm);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    mask-composite: exclude;
    pointer-events: none;
}

/* Rainbow mode toggle */
[data-theme="alcremie"] .mode-toggle {
    border: 1px solid transparent;
    background-clip: padding-box;
    position: relative;
    background: var(--bg);
}

[data-theme="alcremie"] .mode-toggle::before {
    content: '';
    position: absolute;
    inset: 0;
    padding: 1px;
    background: conic-gradient(#ff6b9d, #ffd93d, #6bcb77, #4d96ff, #b06ab3, #ff6b9d);
    border-radius: var(--radius);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    mask-composite: exclude;
    pointer-events: none;
}

[data-theme="alcremie"] .mode-btn.active {
    background: linear-gradient(135deg, #ff6b9d, #ffd93d, #6bcb77, #4d96ff, #b06ab3);
    background-size: 300% 300%;
    animation: alcremieShift 4s ease infinite;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

/* Rainbow slider thumbs */
[data-theme="alcremie"] .ev-row input[type="range"]::-webkit-slider-thumb {
    background: linear-gradient(135deg, #ff6b9d, #ffd93d, #6bcb77, #4d96ff, #b06ab3);
    border: none;
    box-shadow: 0 0 8px rgba(255, 107, 157, 0.5);
}

[data-theme="alcremie"] .ev-row input[type="range"]::-moz-range-thumb {
    background: linear-gradient(135deg, #ff6b9d, #ffd93d, #6bcb77, #4d96ff, #b06ab3);
    border: none;
    box-shadow: 0 0 8px rgba(255, 107, 157, 0.5);
}

/* Rainbow focus rings */
[data-theme="alcremie"] input[type="text"]:focus,
[data-theme="alcremie"] input[type="number"]:focus,
[data-theme="alcremie"] select:focus {
    border-color: transparent;
    box-shadow: 0 0 0 3px rgba(255, 107, 157, 0.3), 0 0 12px rgba(255, 107, 157, 0.15);
    background-image: linear-gradient(var(--bg), var(--bg)), conic-gradient(#ff6b9d, #ffd93d, #6bcb77, #4d96ff, #b06ab3, #ff6b9d);
    background-origin: padding-box, border-box;
    background-clip: padding-box, border-box;
}

/* Rainbow spinner */
[data-theme="alcremie"] .spinner {
    border: 3px solid transparent;
    border-top-color: #ff6b9d;
    border-right-color: #ffd93d;
    border-bottom-color: #6bcb77;
    border-left-color: #4d96ff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    background: none;
    width: 28px;
    height: 28px;
}

/* Rainbow gradient text for card titles */
[data-theme="alcremie"] .card-title,
[data-theme="alcremie"] .card-title-row > span {
    background: linear-gradient(135deg, #ff6b9d, #ffd93d, #6bcb77, #4d96ff, #b06ab3);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: alcremieShift 4s ease infinite;
    font-weight: 700;
}

/* Rainbow "Berichan's" header */
[data-theme="alcremie"] header h1:first-child {
    background: linear-gradient(135deg, #ff6b9d, #ffd93d, #6bcb77, #4d96ff, #b06ab3) !important;
    background-size: 200% 200% !important;
    -webkit-background-clip: text !important;
    background-clip: text !important;
    -webkit-text-fill-color: transparent !important;
    animation: alcremieShift 4s ease infinite !important;
    font-weight: 800;
}

/* Rainbow radio buttons when checked */
[data-theme="alcremie"] .shiny-option input[type="radio"]:checked {
    border-color: #ff6b9d;
    background: linear-gradient(135deg, #ff6b9d, #ffd93d, #6bcb77, #4d96ff, #b06ab3);
    box-shadow: inset 0 0 0 3px var(--bg);
}

[data-theme="alcremie"] .shiny-option input[type="radio"]:focus-visible {
    outline: 2px solid #ff6b9d;
    outline-offset: 2px;
}

/* Rainbow sprite/preview placeholders */
[data-theme="alcremie"] .sprite-placeholder {
    border-color: transparent;
    background: linear-gradient(var(--bg), var(--bg)), conic-gradient(#ff6b9d, #ffd93d, #6bcb77, #4d96ff, #b06ab3, #ff6b9d);
    background-origin: padding-box, border-box;
    background-clip: padding-box, border-box;
    border: 2px solid transparent;
}

[data-theme="alcremie"] .thumb-placeholder {
    border: 1px solid transparent;
    background: linear-gradient(var(--bg), var(--bg)), conic-gradient(#ff6b9d, #ffd93d, #6bcb77, #4d96ff, #b06ab3, #ff6b9d);
    background-origin: padding-box, border-box;
    background-clip: padding-box, border-box;
}

/* Rainbow legality result borders */
[data-theme="alcremie"] .legality-result .lr-message {
    border-left-color: #b06ab3;
}

[data-theme="alcremie"] .legality-result .lr-warning {
    border-left-color: #ff6b9d;
}

[data-theme="alcremie"] .legality-result .lr-ok {
    border-left-color: #6bcb77;
}

[data-theme="alcremie"] .legality-result .lr-suggestions-title {
    border-left-color: #ffd93d;
}

/* Rainbow modal header */
[data-theme="alcremie"] .modal-header {
    border-bottom: 1px solid transparent;
    background-image: linear-gradient(var(--bg-card), var(--bg-card)), conic-gradient(#ff6b9d, #ffd93d, #6bcb77, #4d96ff, #b06ab3, #ff6b9d);
    background-origin: padding-box, border-box;
    background-clip: padding-box, border-box;
}

/* Rainbow library item hover */
[data-theme="alcremie"] .library-item:hover {
    background: linear-gradient(135deg, rgba(255, 107, 157, 0.08), rgba(255, 217, 61, 0.08), rgba(107, 203, 119, 0.08), rgba(77, 150, 255, 0.08), rgba(176, 106, 179, 0.08));
}

/* Rainbow combobox dropdown */
[data-theme="alcremie"] .combobox-dropdown {
    border: 1px solid transparent;
    background: linear-gradient(var(--bg-card), var(--bg-card)), conic-gradient(#ff6b9d, #ffd93d, #6bcb77, #4d96ff, #b06ab3, #ff6b9d);
    background-origin: padding-box, border-box;
    background-clip: padding-box, border-box;
}

[data-theme="alcremie"] .combobox-option:hover {
    background: linear-gradient(135deg, rgba(255, 107, 157, 0.15), rgba(255, 217, 61, 0.15), rgba(107, 203, 119, 0.15), rgba(77, 150, 255, 0.15), rgba(176, 106, 179, 0.15)) !important;
}

/* Rainbow combobox toggle */
[data-theme="alcremie"] .combobox-toggle {
    border: 1px solid #4a3a5a;
    border-left: none;
    color: #b06ab3;
}

[data-theme="alcremie"] .combobox-toggle:hover {
    background: linear-gradient(135deg, rgba(255, 107, 157, 0.15), rgba(255, 217, 61, 0.15), rgba(107, 203, 119, 0.15), rgba(77, 150, 255, 0.15), rgba(176, 106, 179, 0.15));
    color: #fff;
}

/* Rainbow banner */
[data-theme="alcremie"] .banner-offline {
    border: 1px solid transparent;
    background: linear-gradient(rgba(248, 113, 113, 0.08), rgba(248, 113, 113, 0.08)), conic-gradient(#ff6b9d, #ffd93d, #6bcb77, #4d96ff, #b06ab3, #ff6b9d);
    background-origin: padding-box, border-box;
    background-clip: padding-box, border-box;
    color: #ff9d9d;
}

/* Rainbow footer links */
[data-theme="alcremie"] .footer-link a {
    background: linear-gradient(135deg, #ff6b9d, #ffd93d, #6bcb77, #4d96ff, #b06ab3);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: alcremieShift 4s ease infinite;
    font-weight: 600;
}

[data-theme="alcremie"] .footer-link a:hover {
    text-decoration: underline;
    -webkit-text-fill-color: transparent;
}

/* Rainbow FAQ */
[data-theme="alcremie"] .faq-section details {
    border: 1px solid transparent;
    background: linear-gradient(var(--bg-card), var(--bg-card)), conic-gradient(#ff6b9d, #ffd93d, #6bcb77, #4d96ff, #b06ab3, #ff6b9d);
    background-origin: padding-box, border-box;
    background-clip: padding-box, border-box;
}

[data-theme="alcremie"] .faq-section details[open] {
    border-color: transparent;
}

/* Rainbow select arrow */
[data-theme="alcremie"] select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23b06ab3' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}

/* Rainbow moves error */
[data-theme="alcremie"] .moves-error {
    border-color: #ff6b9d;
    background: rgba(255, 107, 157, 0.1);
}

@keyframes alcremieShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

.container {
    max-width: 720px;
    margin: 0 auto;
    padding: 24px 16px 64px;
}

header {
    text-align: center;
    margin-bottom: 32px;
}

.header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.header-row > div:first-child {
    flex: 1;
    text-align: center;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text);
}

header p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 4px;
}

.lang-selector-container {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    margin-top: 4px;
}

.lang-selector-container .lang-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0;
    white-space: nowrap;
}

.lang-selector {
    font-size: 0.75rem;
    padding: 4px 24px 4px 8px;
    min-width: 100px;
    background-position: right 6px center;
    background-size: 10px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    transition: border-color var(--transition);
}

.card-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.form-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.form-row > * {
    flex: 1;
    min-width: 140px;
}

.form-group {
    margin-bottom: 12px;
}

.form-group:last-child {
    margin-bottom: 0;
}

label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

input[type="text"],
input[type="number"],
select {
    width: 100%;
    padding: 8px 12px;
    font-size: 0.875rem;
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

input[type="text"]::placeholder,
input[type="number"]::placeholder {
    color: var(--text-muted);
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 32px;
}

.shiny-group {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 4px 0;
}

.shiny-option {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: color var(--transition);
}

.shiny-option input[type="radio"] {
    appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-radius: 50%;
    transition: border-color var(--transition), background var(--transition);
    cursor: pointer;
    position: relative;
}

.shiny-option input[type="radio"]:checked {
    border-color: var(--accent);
    background: var(--accent);
    box-shadow: inset 0 0 0 3px var(--bg);
}

.shiny-option input[type="radio"]:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.shiny-option.active {
    color: var(--text);
}

.ev-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 16px;
}

.ev-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ev-row label {
    width: 36px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0;
    flex-shrink: 0;
}

.ev-row input[type="range"] {
    flex: 1;
    height: 4px;
    appearance: none;
    background: var(--slider-track);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.ev-row input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--bg-card);
    cursor: pointer;
    transition: transform 0.15s ease;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.ev-row input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.ev-row input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--bg-card);
    cursor: pointer;
}

.ev-value {
    width: 36px;
    text-align: right;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.ev-total {
    grid-column: 1 / -1;
    text-align: center;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    padding-top: 4px;
}

.ev-total .over {
    color: var(--danger);
    font-weight: 600;
}

.iv-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.iv-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.iv-item label {
    width: 32px;
    font-size: 0.75rem;
    font-weight: 600;
    margin: 0;
    flex-shrink: 0;
}

.iv-item input[type="number"] {
    width: 64px;
    padding: 4px 8px;
    text-align: center;
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
}

.moves-grid {
    display: grid;
    gap: 8px;
}

.moves-error {
    margin-top: 8px;
    padding: 6px 10px;
    font-size: 0.8125rem;
    color: var(--danger);
    background: rgba(248, 113, 113, 0.1);
    border: 1px solid rgba(248, 113, 113, 0.3);
    border-radius: var(--radius-sm);
}

.move-slot {
    display: flex;
    align-items: center;
    gap: 8px;
}

.move-slot .slot-label {
    width: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    flex-shrink: 0;
    text-align: right;
}

.move-slot input {
    flex: 1;
}

.move-slot.error .combobox-input-wrapper {
    border: 1px solid var(--danger);
    border-radius: var(--radius-sm);
}

.move-slot.error .combobox-input-wrapper .combobox-input,
.move-slot.error .combobox-input-wrapper .combobox-toggle {
    border-color: var(--danger);
}

.move-slot.error .slot-label {
    color: var(--danger);
}

.mode-toggle {
    display: flex;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 3px;
    margin-bottom: 20px;
    transition: opacity var(--transition);
}

.mode-toggle.hidden {
    display: none;
}

.mode-btn {
    flex: 1;
    padding: 8px 16px;
    font-size: 0.8125rem;
    font-weight: 500;
    font-family: var(--font);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    background: transparent;
    color: var(--text-secondary);
}

.mode-btn:hover {
    color: var(--text);
}

.mode-btn.active {
    background: var(--accent);
    color: #fff;
}

.submit-section {
    overflow: hidden;
    transition: opacity var(--transition), max-height 0.3s ease, margin-bottom 0.3s ease;
    max-height: 0;
    opacity: 0;
    pointer-events: none;
}

.submit-section.visible {
    max-height: 240px;
    opacity: 1;
    pointer-events: auto;
    margin-bottom: 0;
}

.submit-section .card {
    margin-bottom: 0;
}

.preview-area {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    min-height: 80px;
}

.preview-area pre {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.8125rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text);
}

.preview-empty {
    color: var(--text-muted);
    font-size: 0.875rem;
    font-style: italic;
}

.actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.prefix-toggle {
    margin-bottom: 12px;
}

.footer-link {
    margin-bottom: 12px;
    text-align: center;
}

.footer-link a {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.8125rem;
    font-weight: 500;
}

.footer-link a:hover {
    text-decoration: underline;
}

.prefix-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8125rem;
    color: var(--text-muted);
    cursor: pointer;
}

.prefix-checkbox input[type="checkbox"] {
    cursor: pointer;
}

.prefix-value-disp {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    color: var(--accent);
    font-weight: 600;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: var(--font);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition), color var(--transition), opacity var(--transition);
    text-decoration: none;
    line-height: 1;
}

.btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-card-hover);
    color: var(--text);
    border-color: var(--text-muted);
}

.result-message {
    margin-top: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    display: none;
    animation: fadeIn 0.2s ease;
}

.result-message.success {
    display: block;
    background: rgba(74, 222, 128, 0.1);
    border: 1px solid rgba(74, 222, 128, 0.3);
    color: var(--success);
}

.result-message.error {
    display: block;
    background: rgba(248, 113, 113, 0.1);
    border: 1px solid rgba(248, 113, 113, 0.3);
    color: var(--danger);
}

.banner {
    text-align: center;
    padding: 8px 16px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
}

.banner-offline {
    background: rgba(248, 113, 113, 0.08);
    border: 1px solid rgba(248, 113, 113, 0.2);
    color: var(--danger);
}

.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    color: var(--text-muted);
    gap: 12px;
}

.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #2d2d2d;
    color: #fff;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 0.8125rem;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    opacity: 0;
    transition: opacity 0.25s ease, transform 0.25s ease;
    pointer-events: none;
    z-index: 100;
}

.toast.show {
    opacity: 1;
}

footer {
    text-align: center;
    padding: 24px 0;
    color: var(--text-muted);
    font-size: 0.75rem;
}

footer a {
    color: var(--text-secondary);
    text-decoration: none;
}

footer a:hover {
    color: var(--text);
}

.species-row {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.species-thumb {
    width: 56px;
    height: 56px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.thumb-img {
    width: 56px;
    height: 56px;
    image-rendering: pixelated;
}

.thumb-placeholder {
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: var(--text-muted);
}

.preview-sprite {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 120px;
    margin-bottom: 12px;
}

.preview-img {
    width: 120px;
    height: 120px;
    image-rendering: pixelated;
    border-radius: var(--radius-sm);
}

.sprite-placeholder {
    width: 120px;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 2rem;
}

@media (max-width: 600px) {
    .container {
        padding: 16px 12px 48px;
    }

    .card {
        padding: 16px;
    }

    .ev-grid {
        grid-template-columns: 1fr;
    }

    .iv-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .form-row {
        flex-direction: column;
    }

    .form-row > * {
        min-width: auto;
    }

    .actions {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }

    .card-title-row .btn-xs {
        width: auto;
        flex-shrink: 0;
        padding: 4px 10px;
    }

    .toolbar {
        flex-wrap: wrap;
    }

    .toolbar .btn {
        flex: 1;
        min-width: 0;
    }

    .header-row {
        flex-direction: column;
        align-items: center;
    }

    .header-row > div:first-child {
        width: 100%;
    }

    .lang-selector-container {
        margin-top: 6px;
    }

    input[type="text"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px;
    }

    header h1 {
        font-size: 1.25rem;
    }

    .species-row {
        gap: 8px;
    }

    .species-thumb,
    .thumb-placeholder {
        width: 48px;
        height: 48px;
    }

    .thumb-img {
        width: 48px;
        height: 48px;
    }

    .preview-sprite {
        min-height: 100px;
    }

    .preview-img,
    .sprite-placeholder {
        width: 100px;
        height: 100px;
    }
}

.legality-result {
    margin-top: 12px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    line-height: 1.6;
    animation: fadeIn 0.2s ease;
}

.legality-result.valid {
    background: rgba(74, 222, 128, 0.1);
    border: 1px solid rgba(74, 222, 128, 0.3);
    color: var(--success);
}

.legality-result.invalid {
    background: rgba(248, 113, 113, 0.1);
    border: 1px solid rgba(248, 113, 113, 0.3);
    color: var(--danger);
}

.legality-result .lr-title {
    font-weight: 600;
    margin-bottom: 4px;
}

.legality-result .lr-message {
    color: var(--text-secondary);
    margin: 2px 0;
    padding-left: 8px;
    border-left: 2px solid var(--border);
}

.legality-result .lr-section {
    margin: 4px 0 2px;
    padding: 2px 0;
}

.legality-result .lr-warning {
    color: var(--danger);
    border-left-color: var(--danger);
}

.legality-result .lr-ok {
    color: var(--success);
    border-left-color: var(--success);
}

.legality-checking {
    color: var(--text-secondary);
    font-style: italic;
}

.legality-result .lr-suggestions-title {
    margin-top: 8px;
    font-weight: 600;
    color: var(--accent-amber);
    border-left: 2px solid var(--accent-amber);
    padding-left: 8px;
}

.legality-result .lr-suggestion {
    color: var(--text-secondary);
    border-left-color: var(--accent-amber);
    padding: 4px 8px;
    margin: 2px 0;
    background: rgba(245, 158, 11, 0.05);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}

.combobox {
    position: relative;
}

.combobox-input-wrapper {
    display: flex;
    align-items: stretch;
}

.combobox-input {
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
}

.combobox-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    border: 1px solid var(--border);
    border-left: none;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    background: var(--bg);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.625rem;
    line-height: 1;
    padding: 0;
    transition: color var(--transition), background var(--transition);
    flex-shrink: 0;
}

.combobox-toggle:hover {
    background: var(--bg-card-hover);
    color: var(--text);
}

.combobox-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 50;
    max-height: 240px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.combobox-option {
    padding: 8px 12px;
    font-size: 0.875rem;
    cursor: pointer;
    color: var(--text);
    transition: background var(--transition);
}

.combobox-option:hover {
    background: var(--accent-subtle);
    color: var(--text);
}

.combobox-no-results {
    padding: 12px;
    font-size: 0.8125rem;
    color: var(--text-muted);
    text-align: center;
    font-style: italic;
}

/* Toolbar */
.toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.toolbar .btn {
    flex: 0 0 auto;
}

/* Card title row (header + inline action button) */
.card-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.card-title-row > span {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
}

/* Extra-small button */
.btn-xs {
    padding: 4px 10px;
    font-size: 0.75rem;
    border-radius: var(--radius-sm);
}

/* Small button */
.btn-sm {
    padding: 6px 14px;
    font-size: 0.8125rem;
}

/* Modal overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.15s ease;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 90%;
    max-width: 480px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.modal-wide {
    max-width: 560px;
}

.modal-sm {
    max-width: 360px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text);
}

.modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    justify-content: flex-end;
}

.modal-cancel {
    min-width: 80px;
}

/* Import textarea */
.import-textarea {
    width: 100%;
    min-height: 160px;
    padding: 12px;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.8125rem;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    resize: vertical;
    outline: none;
}

.import-textarea:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

.import-error {
    margin-top: 8px;
    padding: 8px 12px;
    font-size: 0.8125rem;
    color: var(--danger);
    background: rgba(248, 113, 113, 0.1);
    border: 1px solid rgba(248, 113, 113, 0.3);
    border-radius: var(--radius-sm);
}

/* Library search */
.library-search {
    width: 100%;
    padding: 8px 12px;
    font-size: 0.875rem;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    margin-bottom: 12px;
}

.library-search:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

/* Library list */
.library-list {
    max-height: 320px;
    overflow-y: auto;
}

.library-empty {
    text-align: center;
    padding: 24px;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-style: italic;
}

.library-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition);
}

.library-item:hover {
    background: var(--bg-card-hover);
}

.library-item-info {
    flex: 1;
    min-width: 0;
}

.library-item-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.library-item-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.library-item-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.library-item-actions .btn {
    padding: 4px 8px;
    font-size: 0.7rem;
    min-width: auto;
}

/* Save set name input */
.save-set-name {
    width: 100%;
    padding: 8px 12px;
    font-size: 0.875rem;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    margin-top: 4px;
}

.save-set-name:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

/* SEO intro section */
.seo-intro {
    text-align: center;
    padding: 12px 20px;
    margin-bottom: 20px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* FAQ section */
.faq-section {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.faq-section h2 {
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.faq-section details {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    transition: border-color var(--transition);
}

.faq-section details[open] {
    border-color: var(--text-muted);
}

.faq-section summary {
    padding: 12px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
}

.faq-section summary::-webkit-details-marker {
    display: none;
}

.faq-section summary::before {
    content: '+';
    display: inline-block;
    width: 20px;
    height: 20px;
    text-align: center;
    font-size: 1rem;
    color: var(--text-muted);
    flex-shrink: 0;
    transition: transform var(--transition);
}

.faq-section details[open] > summary::before {
    content: '−';
}

.faq-section p {
    padding: 0 16px 12px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    line-height: 1.6;
}
