:root {
    color-scheme: dark;
    --bg: #101819;
    --sidebar: #132021;
    --panel: #172526;
    --border: #2c403e;
    --ink: #f4f2df;
    --muted: #abc1b8;
    --gold: #f4cf80;
    --teal: #8ed0b1;
    font: 15px/1.5 system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); }
a { color: var(--teal); text-decoration: none; }
a:hover { color: var(--gold); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button, a, input, select, textarea, summary { outline-offset: 4px; }
:focus-visible { outline: 2px solid var(--gold); }
h1, h2, p, dl, dd { margin: 0; }
h1, .hero h2, .login h1 { font-family: Georgia, serif; font-weight: 700; }
h1 { font-size: clamp(2.1rem, 4vw, 3.45rem); line-height: 1.1; }
h2 { font-size: 1.23rem; line-height: 1.3; }
small { color: var(--muted); }
input, select, textarea {
    min-width: 0; padding: .65rem .8rem; background: #101a1a; color: var(--ink);
    border: 1px solid var(--border); border-radius: 8px;
}
input::placeholder { color: #9db4aa; }
textarea { min-height: 5rem; resize: vertical; }
label { font-size: .9rem; font-weight: 650; display: grid; align-content: start; gap: .34rem; }
label small { font-weight: normal; }
.primary, .secondary {
    border-radius: 8px; display: inline-flex; justify-content: center; align-items: center;
    gap: .65rem; padding: .68rem .95rem; font-weight: 700; line-height: 1.35;
}
.primary { border: 1px solid var(--gold); background: var(--gold); color: #241d0f; }
.primary:hover { background: #ffe2a6; color: #241d0f; }
.secondary { border: 1px solid var(--border); background: #1d302e; color: var(--ink); }
.secondary:hover { border-color: var(--teal); }
.text-button, .close { color: var(--muted); padding: 0; border: 0; background: transparent; }
.text-button:hover, .close:hover { color: var(--ink); }
.sidebar {
    display: flex; flex-direction: column; gap: 2.3rem; position: fixed; inset: 0 auto 0 0;
    width: 238px; padding: 1.8rem 1.15rem 1.2rem; border-right: 1px solid var(--border);
    background: var(--sidebar);
}
.brand { display: inline-flex; gap: .72rem; align-items: center; color: var(--ink); font-family: Georgia, serif; font-size: 1.45rem; font-weight: 700; }
.brand small { display: block; color: var(--teal); font: 700 .66rem/1.4 system-ui, sans-serif; letter-spacing: .15em; }
.leaf, .avatar { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 11px; background: #263e36; color: var(--gold); flex: 0 0 auto; }
.leaf { border: 1px solid #536447; }
nav { display: grid; gap: .3rem; }
.nav-link { color: var(--muted); padding: .72rem .7rem; border-radius: 8px; display: flex; gap: .7rem; align-items: center; font-weight: 650; }
.nav-link span { width: 1.05rem; color: var(--teal); text-align: center; }
.nav-link.active { background: #29433c; color: var(--ink); }
.nav-link.active span { color: var(--gold); }
.profile { margin-top: auto; display: flex; gap: .7rem; align-items: center; border-top: 1px solid var(--border); padding-top: 1rem; }
.profile form { font-size: .83rem; }
.content { margin-left: 238px; padding: 2rem clamp(1.25rem, 4vw, 3.5rem) 3rem; max-width: 1700px; }
.page-header { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.eyebrow { color: var(--teal); font-size: .72rem; letter-spacing: .19em; font-weight: 800; margin-bottom: .55rem; }
.landscape {
    background-color: #152d29;
    background-image: linear-gradient(90deg,#122622f5 1%,#142a27af 42%,#142a2720 85%), url('forest.webp'), radial-gradient(ellipse at 75% 22%,#57734a,#193f38 44%,#142524 75%);
    background-size: cover; background-position: center, center 58%, center;
}
.hero { display: flex; align-items: center; min-height: 325px; border: 1px solid #35544b; border-radius: 16px; padding: 2rem clamp(1.35rem, 5vw, 3.4rem); margin-bottom: 1rem; }
.hero h2 { font-size: clamp(2.4rem, 5.4vw, 4.1rem); line-height: 1; margin: .2rem 0 1.4rem; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(205px, 100%), 1fr)); gap: .75rem; margin: 1rem 0 1.25rem; }
.metrics > div { border: 1px solid var(--border); background: var(--panel); border-radius: 12px; padding: 1.05rem; display: grid; gap: .15rem; }
.metrics small { font-weight: 800; text-transform: uppercase; font-size: .67rem; letter-spacing: .1em; }
.metrics strong { color: var(--gold); font-size: clamp(1.3rem, 2.25vw, 2rem); overflow-wrap: anywhere; }
.metrics i { font-size: .83rem; font-style: normal; color: var(--muted); }
.metrics span { color: var(--muted); font-size: .82rem; }
.panel { border: 1px solid var(--border); background: var(--panel); border-radius: 14px; padding: clamp(.9rem, 3vw, 1.35rem); }
.section-header, .actions { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .65rem; }
.section-header { margin-bottom: .9rem; }
.section-header h2 small { margin-left: .4rem; }
.roster, .skill-grid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(min(255px, 100%), 1fr)); }
.character-card { display: flex; align-items: center; gap: .75rem; padding: .75rem; border: 1px solid var(--border); border-radius: 10px; color: var(--ink); background: #142020; }
.character-card:hover { border-color: var(--teal); }
.character-card strong, .character-card small, td small, .item small { display: block; }
.portrait {
    background: linear-gradient(145deg,hsl(var(--tone) 26% 32%),hsl(var(--tone) 22% 20%)); color: #fff3d3;
    font: bold 1.4rem Georgia, serif; display: grid; place-items: center; overflow: hidden;
    width: 43px; height: 43px; border-radius: 9px; flex: 0 0 auto;
}
.portrait img { width: 100%; height: 100%; object-fit: contain; }
.level { margin-left: auto; padding: .24rem .48rem; color: var(--gold); background: #2c3225; border-radius: 6px; font-size: .77rem; font-weight: 750; white-space: nowrap; }
.back-link { display: inline-block; margin-bottom: .75rem; }
.character-detail { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 1rem; margin-bottom: 1rem; }
.character-detail .character-card { flex: 1 1 225px; max-width: 425px; }
.character-detail .portrait { width: 72px; height: 72px; }
.item { border-top: 1px solid var(--border); padding: .75rem 0; }
.item summary { display: flex; justify-content: space-between; align-items: center; cursor: pointer; gap: .5rem; }
.item summary::before { content: '▸'; color: var(--teal); }
.item[open] summary::before { content: '▾'; }
.item-stats, .skill-levels { display: grid; gap: .65rem; margin: .8rem 0; }
.item-stats { grid-template-columns: repeat(auto-fit, minmax(min(160px, 100%), 1fr)); }
dt { color: var(--teal); font-weight: 700; font-size: .85rem; }
dd { white-space: pre-line; overflow-wrap: anywhere; }
.filter-row { color: var(--muted); }
.skill-grid { grid-template-columns: repeat(auto-fill, minmax(min(325px, 100%), 1fr)); align-items: start; }
.skill { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; display: flex; flex-direction: column; gap: .55rem; }
.skill-heading { display: flex; align-items: center; gap: .65rem; }
.skill-heading h2 { font-size: 1rem; }
.skill-icon { position: relative; display: grid; place-items: center; width: 34px; height: 34px; flex: 0 0 auto; background: #2c4339; color: var(--gold); border-radius: 8px; }
.skill-icon img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
progress { width: 100%; accent-color: var(--teal); height: 8px; }
.skill p, .skill details { font-size: .87rem; }
.skill details .skill-levels { max-block-size: 10rem; overflow: auto; }
.skill-actions { display: flex; align-items: center; gap: .5rem; margin-top: var(--skill-card-space, 0px); min-block-size: 2rem; }
.skill-toggle-form { flex: none; margin-inline-start: auto; }
.skill-actions .skill-level-form { gap: .35rem; align-items: center; }
.skill-level-form label { display: flex; flex-wrap: wrap; align-items: center; }
.skill-level-form select, .skill-level-form button { padding: .25rem .4rem; min-block-size: 2rem; font-size: .8rem; }
.skill-grid-measuring .skill-levels { display: none; }
.skill-grid-measuring .skill-actions { margin-top: 0; }
.skill-toggle { inline-size: 2rem; block-size: 2rem; padding: 0; border-radius: 6px; font-size: 1.15rem; }
summary { cursor: pointer; color: var(--teal); }
.inline-form, .filters { display: flex; flex-wrap: wrap; gap: .65rem; align-items: end; }
.source, .empty { color: var(--muted); padding-top: .9rem; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { border-bottom: 1px solid var(--border); padding: .7rem .5rem; }
th { color: var(--muted); font-size: .78rem; }
dialog { width: min(620px, calc(100% - 2rem)); max-height: calc(100% - 2rem); overflow: auto; background: var(--panel); color: var(--ink); border: 1px solid #466359; border-radius: 14px; padding: 1.3rem; }
dialog::backdrop { background: #050c0bd4; }
.close { font-size: 1.6rem; line-height: 1; }
.stack { display: grid; gap: .8rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(142px, 100%), 1fr)); gap: .75rem; }
.danger { color: #f6ad98; margin-top: .85rem; }
.notice { background: #24453a; border: 1px solid #4a7767; padding: .65rem .9rem; border-radius: 8px; margin-bottom: .9rem; }
.notice.error { background: #472b28; border-color: #a87066; }
.notice ul { margin: 0; padding-left: 1rem; }
.guest { min-height: 100svh; display: grid; align-content: center; justify-items: center; padding: 1.25rem; }
.guest .notice { width: min(960px, 100%); }
.login { width: min(960px, 100%); display: grid; grid-template-columns: 1.15fr 1fr; min-height: 530px; border-radius: 18px; overflow: hidden; border: 1px solid var(--border); box-shadow: 0 25px 90px #0006; }
.login-art { display: flex; flex-direction: column; justify-content: space-between; padding: clamp(1.5rem, 4vw, 2.9rem); gap: 3rem; }
.login-art h1 { margin-bottom: .8rem; }
.login-art p:last-child { color: var(--muted); }
.login-form { display: grid; align-content: center; gap: 1.25rem; padding: clamp(1.5rem, 4vw, 3rem); background: var(--panel); }
.login-form h2 { font-family: Georgia, serif; font-size: 1.7rem; }
.login-form .primary { margin-top: .25rem; justify-content: space-between; }
@media (max-width: 820px) {
    .sidebar { position: static; width: auto; gap: .75rem; padding: .7rem 1rem; border-right: 0; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: 1fr auto; }
    nav { grid-column: 1 / -1; grid-row: 2; display: flex; overflow: auto; }
    .nav-link { white-space: nowrap; font-size: .86rem; }
    .profile { grid-column: 2; grid-row: 1; border: 0; padding: 0; }
    .profile .avatar { display: none; }
    .content { margin-left: 0; }
}
@media (max-width: 600px) {
    .login { grid-template-columns: 1fr; min-height: auto; }
    .login-art { min-height: 260px; gap: 2rem; }
    .page-header { align-items: start; flex-direction: column; }
    .hero { min-height: 270px; }
}

.loadout { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(190px, 1fr); gap: 1rem; margin-bottom: 1.35rem; }
.equipment-board { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-template-rows: repeat(6, minmax(56px, auto)); align-self: start; gap: 5px; background: #101a19; border: 1px solid var(--border); border-radius: 12px; padding: .55rem; }
.equipment-slot { grid-column: var(--column); grid-row: var(--row); display: grid; place-content: center; justify-items: center; gap: .2rem; min-width: 0; min-height: 56px; background: #1b2c2a; border: 1px solid var(--border); border-radius: 7px; color: var(--muted); padding: .15rem; }
.equipment-slot:hover, .equipment-portrait:hover { border-color: var(--gold); }
.equipment-slot.occupied { background: #27372a; border-color: #687550; }
.equipment-slot small { font-size: clamp(.52rem, .85vw, .7rem); line-height: 1.1; overflow-wrap: anywhere; }
.slot-plus { font-size: 1.1rem; color: var(--teal); }
.slot-item { font-size: .55rem; overflow-wrap: anywhere; line-height: 1; color: var(--ink); }
.equipment-slot img { width: 30px; height: 28px; max-width: 100%; object-fit: contain; image-rendering: pixelated; }
.equipment-portrait { grid-area: 1 / 3 / 5 / 6; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .35rem; min-width: 0; text-align: center; color: var(--ink); background: radial-gradient(ellipse, #304b38, #172526 72%); border: 1px solid var(--border); border-radius: 9px; padding: .3rem; }
.equipment-portrait img { width: min(100%, 140px); height: 138px; object-fit: contain; image-rendering: pixelated; }
.equipment-portrait small { font-size: .68rem; }
.portrait-letter { font: 3rem Georgia, serif; color: var(--gold); }
.set-bonuses h3 { margin-top: 0; }
.set-card { border: 1px solid var(--border); border-radius: 8px; padding: .55rem; margin-bottom: .5rem; }
.set-card summary span { color: var(--muted); margin-left: .45rem; font-size: .78rem; }
.set-card ul { list-style: none; padding: 0; margin: .45rem 0 0; display: grid; gap: .4rem; }
.set-card li { display: grid; color: var(--muted); font-size: .75rem; }
.set-card .tier-active strong { color: var(--gold); }
@media (max-width: 1150px) { .loadout { grid-template-columns: 1fr; } }

.potential-fields { min-width: 0; display: grid; gap: .65rem; margin: 0; padding: .8rem; border: 1px solid var(--border); border-radius: 8px; }
.potential-fields legend { padding: 0 .35rem; font-weight: 700; }
.potential-line { display: grid; grid-template-columns: minmax(0, 2fr) minmax(4.75rem, .75fr) minmax(0, 1fr); align-items: end; gap: .5rem; }
.potential-line input:disabled { opacity: .55; }
dialog .select2-container--default .select2-selection--single,
dialog .select2-container--default .select2-dropdown,
dialog .select2-container--default .select2-search--dropdown .select2-search__field {
    background: #101a1a; color: var(--ink); border-color: var(--border); border-radius: 8px;
}
dialog .select2-container--default .select2-selection--single { height: 43px; }
dialog .select2-container--default .select2-selection--single .select2-selection__rendered { line-height: 41px; color: var(--ink); }
dialog .select2-container--default .select2-selection--single .select2-selection__placeholder { color: var(--muted); }
dialog .select2-container--default .select2-selection--single .select2-selection__arrow { height: 41px; }
dialog .select2-container--default .select2-results__option[aria-selected="true"] { background: var(--panel); }
dialog .select2-container--default .select2-results__option--highlighted[aria-selected] { background: #29433c; color: var(--ink); }
@media (max-width: 540px) { .potential-line { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .potential-line label:first-child { grid-column: 1 / -1; } }

.planner-toolbar { display: flex; align-items: end; justify-content: space-between; flex-wrap: wrap; gap: .75rem; }
.planner { grid-template-columns: minmax(0, 1fr); }
.planner .metrics { margin-bottom: 0; }
.metrics > div:has([data-fit-total]) { container-type: inline-size; }
.metrics [data-fit-total] {
    font-variant-numeric: tabular-nums;
    font-size: min(clamp(1.3rem, 2.25vw, 2rem), var(--total-fit-size, calc(100cqi / 16.5)));
    min-width: 0;
    white-space: nowrap;
}
.planner .section-header { margin-bottom: 0; }
.planner-save { position: sticky; top: 0; z-index: 2; padding: .5rem 0; background: var(--bg); }
.planner .panel .section-header { margin-bottom: .65rem; }
.planner-note { color: var(--muted); font-size: .9rem; }
.planner-table th { white-space: nowrap; }
.planner-table tbody th { font-size: .9rem; color: var(--ink); }
.planner-table tbody th small { display: block; font-weight: 400; }
.planner-table input[type="number"] { width: 6rem; }
.planner-table input[data-plan-reward] { width: 10.5rem; }
.planner-table input[type="checkbox"] { width: 1.1rem; height: 1.1rem; accent-color: var(--teal); }
.planner-table [data-plan-row-daily], .planner-table [data-plan-row-week] { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

.link-loadout { margin-bottom: 1.25rem; }
.link-loadout h3 { margin-top: 1rem; font-size: .95rem; }
.link-selection { display: flex; flex-wrap: wrap; gap: .45rem; list-style: none; padding: 0; margin: .75rem 0; }
.link-selection li { display: inline-flex; align-items: baseline; gap: .45rem; padding: .35rem .6rem; border: 1px solid var(--border); border-radius: 7px; background: var(--panel); }
.link-bonuses { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); gap: .6rem; margin: .6rem 0 0; }
.link-bonuses > div { padding: .65rem .8rem; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); }
.link-bonuses dt { font-size: .8rem; }
.link-bonuses dd { margin: .2rem 0 0; color: var(--gold); font-size: 1.25rem; font-weight: 800; }
.skill-active, .skill:target { border-color: var(--gold); }
