:root,
[data-theme="dark"] {
    --bg: #000000;
    --panel: #0d0d0d;
    --sheet: #161616;
    --field: #1f1f1f;
    --line: #262626;
    --line-strong: #333333;
    --text: #ffffff;
    --muted: #a8a8a8;
    --primary-bg: #ffffff;
    --primary-text: #000000;
    --placeholder: #1c1c1c;
    --link: #8fb4ff;
    --error: #ff7b72;
    --male: #6fa8ff;
    --female: #f0506e;

    --t-normal: #a8a878;  --t-fire: #f08030;     --t-water: #6890f0;    --t-electric: #f8d030;
    --t-grass: #78c850;   --t-ice: #98d8d8;      --t-fighting: #e0584a; --t-poison: #c060c0;
    --t-ground: #e0c068;  --t-flying: #c4b8ff;   --t-psychic: #f85888;  --t-bug: #a8b820;
    --t-rock: #d0a070;    --t-ghost: #a283b0;    --t-dragon: #8a66ff;   --t-dark: #a08878;
    --t-steel: #b8b8d0;   --t-fairy: #ee99ac;    --t-stellar: #7ec8ff;

    --s-hp: #ff5a5a; --s-atk: #f08030; --s-def: #f8d030; --s-spa: #6890f0; --s-spd: #78c850; --s-spe: #f85888;
    color-scheme: dark;
}

[data-theme="light"] {
    --bg: #ffffff;
    --panel: #f4f5f7;
    --sheet: #ffffff;
    --field: #ffffff;
    --line: #e2e5ea;
    --line-strong: #c9ced6;
    --text: #1b2430;
    --muted: #5b6573;
    --primary-bg: #1b2430;
    --primary-text: #ffffff;
    --placeholder: #e3e8ee;
    --link: #2f5fb8;
    --error: #a1261f;
    --male: #2f5fb8;
    --female: #b4235f;

    --t-normal: #6b6a52;  --t-fire: #b9531a;     --t-water: #2f5fb8;    --t-electric: #8f7000;
    --t-grass: #3d7a26;   --t-ice: #23787a;      --t-fighting: #b02a24; --t-poison: #8a2f8a;
    --t-ground: #7a5418;  --t-flying: #8058c0;   --t-psychic: #b8245e;  --t-bug: #5f6e10;
    --t-rock: #8a5a3c;    --t-ghost: #5a4570;    --t-dragon: #4a28c8;   --t-dark: #4a3a30;
    --t-steel: #5a6478;   --t-fairy: #a8467a;    --t-stellar: #2e6e9e;

    --s-hp: #c62828; --s-atk: #b9531a; --s-def: #8a6d00; --s-spa: #2f5fb8; --s-spd: #3d7a26; --s-spe: #b8245e;
    color-scheme: light;
}

:root {
    --header: 48px;
    --serif: "Noto Serif", "Noto Serif JP", "Times New Roman", serif;
    --mono: "Noto Sans Mono", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--serif);
    font-size: 15px;
    line-height: 23px;
}

[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
a { color: var(--link); }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.primary {
    height: 38px;
    padding: 0 16px;
    border: 0;
    border-radius: 4px;
    background: var(--primary-bg);
    color: var(--primary-text);
    font-weight: 700;
}
.secondary {
    height: 38px;
    padding: 0 14px;
    border: 1px solid var(--line-strong);
    border-radius: 4px;
    background: transparent;
}
.icon-button {
    width: 34px;
    height: 34px;
    flex: none;
    border: 1px solid var(--line-strong);
    border-radius: 4px;
    background: transparent;
    font-size: 16px;
    line-height: 1;
}
.link-button {
    padding: 0;
    border: 0;
    background: none;
    text-align: left;
    text-decoration: underline;
    text-underline-offset: 3px;
}
.status { margin: 0; min-height: 23px; color: var(--muted); }
.status.error { color: var(--error); }

.site-header {
    position: sticky;
    top: 0;
    z-index: 20;
    height: var(--header);
    padding: 0 12px 0 16px;
    display: flex;
    align-items: center;
    background: #000000;
    color: #ffffff;
    border-bottom: 1px solid #262626;
}
.site-title { font-size: 18px; line-height: 26px; font-weight: 700; color: #ffffff; text-decoration: none; }
.site-title:hover { text-decoration: underline; text-underline-offset: 4px; }
.header-actions { margin-left: auto; display: flex; gap: 8px; }
.site-header .icon-button { border-color: #333333; color: #ffffff; }

.site-menu {
    position: absolute;
    top: var(--header);
    right: 12px;
    min-width: 220px;
    padding: 8px;
    background: var(--sheet);
    color: var(--text);
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
}
.site-menu a,
.site-menu button {
    padding: 8px;
    border: 0;
    border-radius: 4px;
    background: none;
    color: var(--text);
    text-align: left;
    text-decoration: none;
}
.site-menu a:hover,
.site-menu button:hover { background: var(--field); }

.panel { display: flex; flex-direction: column; gap: 12px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-head h2 { margin: 0; font-size: 16px; line-height: 24px; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { color: var(--muted); font-size: 13px; line-height: 18px; }
.field input,
.field select {
    height: 36px;
    padding: 0 8px;
    border: 1px solid var(--line-strong);
    border-radius: 4px;
    background: var(--field);
}
.help { margin: 8px 0 0; color: var(--muted); font-size: 13px; line-height: 20px; }
.credits-link { margin-top: auto; align-self: flex-start; color: var(--muted); font-size: 13px; }
.help-link { align-self: flex-start; font-size: 13px; line-height: 20px; }

.editor { display: flex; height: calc(100dvh - var(--header)); }
.paste-box {
    flex: 1;
    min-width: 0;
    height: 100%;
    margin: 0;
    padding: 12px 16px;
    border: 0;
    resize: none;
    background: var(--bg);
    color: var(--text);
    font-family: var(--mono);
    font-size: 14px;
    line-height: 22px;
}
.paste-box:focus-visible { outline: none; }

.details {
    width: 300px;
    flex: none;
    padding: 16px;
    background: var(--panel);
    border-left: 1px solid var(--line);
    overflow-y: auto;
}
.details-rail {
    display: none;
    width: 48px;
    flex: none;
    padding-top: 10px;
    justify-content: center;
    align-items: flex-start;
    background: var(--panel);
    border-left: 1px solid var(--line);
}
.rail-collapsed .details { display: none; }
.rail-collapsed .details-rail { display: flex; }

.mobile-bar { display: none; }
.backdrop { display: none; }

.result {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 240px;
    gap: 32px;
    padding: 20px 16px 48px;
}
.team-heading { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 8px; }
.team-heading > div { flex: 1; min-width: 0; }
.team-title { margin: 0; font-size: 24px; line-height: 32px; overflow-wrap: anywhere; }
.team-meta { margin: 2px 0 0; color: var(--muted); }
.actions-button { display: none; font-weight: 700; }

.actions {
    position: sticky;
    top: calc(var(--header) + 20px);
    align-self: start;
}
.action-list { display: flex; flex-direction: column; gap: 8px; }
.note { margin: -6px 0 0; color: var(--muted); font-size: 13px; line-height: 18px; }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.setting-label { color: var(--muted); }
.segmented { display: flex; border: 1px solid var(--line-strong); border-radius: 4px; overflow: hidden; }
.segmented button { padding: 3px 10px; border: 0; background: transparent; }
.segmented button[aria-pressed="true"] { background: var(--primary-bg); color: var(--primary-text); font-weight: 700; }

.about {
    width: min(560px, calc(100vw - 32px));
    padding: 20px 24px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: var(--sheet);
    color: var(--text);
}
.about::backdrop { background: rgba(0, 0, 0, 0.6); }
.about h3 { margin: 20px 0 6px; font-size: 16px; line-height: 24px; }
.about p { margin: 12px 0 0; }
.about ul { margin: 0; padding-left: 20px; }
.about li + li { margin-top: 6px; }

.sprite-box { position: relative; flex: none; }
.sprite { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
.sprite-missing { background: var(--placeholder); border-radius: 4px; }
.item-icon {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 24px;
    height: 24px;
    background-repeat: no-repeat;
}

.set-name { margin: 0; font-size: inherit; font-weight: 700; overflow-wrap: anywhere; }
.set-body { margin: 0; font-family: inherit; white-space: pre-wrap; overflow-wrap: anywhere; }
.set-body .line { display: block; }
.label, .dash, .unknown { color: var(--muted); }
.unknown { font-style: italic; }
.gender-m { color: var(--male); }
.gender-f { color: var(--female); }
.untranslated { text-decoration: underline dotted var(--muted); text-underline-offset: 3px; }

[data-layout="vertical"] .team {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 24px;
    align-items: start;
}
[data-layout="vertical"] .set {
    display: flex;
    align-items: flex-start;
    gap: 15px;
    padding: 15px 0;
    font-size: 16px;
    line-height: 25px;
}
[data-layout="vertical"] .sprite-box { width: 144px; height: 144px; }
[data-layout="vertical"] .item-icon { transform: scale(1.5); transform-origin: bottom right; }
[data-layout="vertical"] .set-text { flex: 1; min-width: 0; }

[data-layout="horizontal"] .team {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 24px 20px;
    align-items: start;
    margin-top: 12px;
}
[data-layout="horizontal"] .set { display: flow-root; font-size: 15px; line-height: 24px; }
[data-layout="horizontal"] .sprite-box { float: left; width: 96px; height: 96px; margin: 0 12px 4px 0; }

.type-normal { color: var(--t-normal); }     .type-fire { color: var(--t-fire); }
.type-water { color: var(--t-water); }       .type-electric { color: var(--t-electric); }
.type-grass { color: var(--t-grass); }       .type-ice { color: var(--t-ice); }
.type-fighting { color: var(--t-fighting); } .type-poison { color: var(--t-poison); }
.type-ground { color: var(--t-ground); }     .type-flying { color: var(--t-flying); }
.type-psychic { color: var(--t-psychic); }   .type-bug { color: var(--t-bug); }
.type-rock { color: var(--t-rock); }         .type-ghost { color: var(--t-ghost); }
.type-dragon { color: var(--t-dragon); }     .type-dark { color: var(--t-dark); }
.type-steel { color: var(--t-steel); }       .type-fairy { color: var(--t-fairy); }
.type-stellar { color: var(--t-stellar); }

[data-stat-colours="on"] .stat-hp { color: var(--s-hp); }
[data-stat-colours="on"] .stat-atk { color: var(--s-atk); }
[data-stat-colours="on"] .stat-def { color: var(--s-def); }
[data-stat-colours="on"] .stat-spa { color: var(--s-spa); }
[data-stat-colours="on"] .stat-spd { color: var(--s-spd); }
[data-stat-colours="on"] .stat-spe { color: var(--s-spe); }

.set:lang(ja)      { font-family: "Noto Serif", "Noto Serif JP", serif; }
.set:lang(ko)      { font-family: "Noto Serif", "Noto Serif KR", serif; }
.set:lang(zh-Hant) { font-family: "Noto Serif", "Noto Serif TC", serif; }
.set:lang(zh-Hans) { font-family: "Noto Serif", "Noto Serif SC", serif; }

@media (max-width: 720px) {
    .icon-button { width: 44px; height: 44px; font-size: 18px; }
    .site-header { padding-right: 6px; }
    .site-title { font-size: 17px; }
    .header-actions { gap: 6px; }
    .site-menu { left: 0; right: 0; border-radius: 0 0 8px 8px; }
    .site-menu a, .site-menu button { padding: 12px 8px; font-size: 16px; }

    .paste-box, .field input, .field select { font-size: 16px; }
    .field input, .field select { height: 44px; }

    .editor { flex-direction: column; }
    .paste-box { height: auto; flex: 1; padding: 12px 14px; line-height: 24px; }
    .details-rail, .rail-collapsed .details-rail { display: none; }

    .mobile-bar {
        display: flex;
        gap: 10px;
        flex: none;
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        background: var(--panel);
        border-top: 1px solid var(--line);
    }
    .mobile-bar button { height: 44px; }
    .mobile-bar .primary { flex: 1; font-size: 16px; }

    .details, .actions,
    .rail-collapsed .details {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 40;
        width: auto;
        max-height: 85dvh;
        padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
        background: var(--sheet);
        border: 0;
        border-top: 1px solid var(--line-strong);
        border-radius: 14px 14px 0 0;
        overflow-y: auto;
        transform: translateY(110%);
        transition: transform 0.2s ease;
    }
    body[data-sheet="details"] .details,
    body[data-sheet="actions"] .actions { transform: none; }
    .details .primary { height: 48px; font-size: 16px; }

    .backdrop { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, 0.6); }

    .result { display: block; padding: 14px 14px 32px; }
    .actions-button { display: block; }
    .actions { top: auto; }
    .action-list .link-button {
        height: 48px;
        border-bottom: 1px solid var(--line);
        text-decoration: none;
        font-size: 16px;
    }
    .note { margin: 4px 0 0; }
    .layout-setting { display: none; }
    .setting .segmented button { padding: 8px 14px; }

    [data-layout] .team { display: block; margin-top: 0; }
    [data-layout] .set {
        display: flow-root;
        padding: 14px 0;
        border-bottom: 1px solid var(--line);
        font-size: 15px;
        line-height: 24px;
    }
    [data-layout] .sprite-box { float: left; width: 96px; height: 96px; margin: 0 12px 4px 0; }
    [data-layout] .item-icon { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}