:root {
    --bg: #f6f4ef;
    --surface: #ffffff;
    --surface-2: #f0ede6;
    --text: #1f1d1a;
    --muted: #6b665d;
    --border: #e2ddd3;
    --accent: #6d4bd8;
    --accent-soft: #ece6ff;
    --good: #2f9e5b;
    --low: #d38b16;
    --critical: #d1453b;
    --warn-soft: #fde8e6;
    --armor: #2f6fbf;
    --magic: #8a4fd0;
    --divine: #b8860b;
    --damage: #c75f12;
    --heart: #d1453b;
    --class: var(--accent);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #16151a;
        --surface: #1f1e25;
        --surface-2: #2a2932;
        --text: #ecebf0;
        --muted: #9d9aa8;
        --border: #34333d;
        --accent: #a28bff;
        --accent-soft: #2f2852;
        --good: #49c27c;
        --low: #e8a33a;
        --critical: #ef6a5f;
        --warn-soft: #43201e;
        --armor: #6fa8ec;
        --magic: #b48cf0;
        --divine: #e8c35a;
        --damage: #f09a50;
        --heart: #ef6a5f;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: var(--accent); }

h1 { font-size: 1.8rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
h3 { font-size: .95rem; margin: 1rem 0 .4rem; }

.topbar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: .75rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand { font-weight: 700; color: var(--text); text-decoration: none; }

.topbar nav { display: flex; gap: .25rem; }

.topbar nav a {
    padding: .35rem .75rem;
    border-radius: 999px;
    color: var(--muted);
    text-decoration: none;
}

.topbar nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

main { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

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

code {
    padding: 0 .3rem;
    border-radius: 4px;
    background: var(--surface-2);
    font: .85em ui-monospace, "SF Mono", Menlo, monospace;
}
.small { font-size: .85rem; color: var(--muted); }
.empty { color: var(--muted); font-style: italic; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem 1.1rem;
}

.chip {
    display: inline-block;
    padding: .05rem .5rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
    background: var(--surface-2);
    color: var(--muted);
    vertical-align: middle;
}

.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.warn { background: var(--warn-soft); color: var(--critical); }

/* Party */

.party {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.member {
    display: flex;
    flex-direction: column;
    gap: .75rem;
    color: inherit;
    text-decoration: none;
    transition: border-color .15s, transform .15s;
}

.member:hover { border-color: var(--accent); transform: translateY(-2px); }

.member-head { display: flex; justify-content: space-between; align-items: flex-start; }
.member-head h2 { margin: 0; font-size: 1.25rem; }

.subclass-line { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }

.armor-row { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; font-weight: 600; }

/* Health */

.hp-label { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); }
.hp-label strong { color: var(--text); }

.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: .2rem; }
.fill { height: 100%; border-radius: 999px; }
.fill.good { background: var(--good); }
.fill.low { background: var(--low); }
.fill.critical { background: var(--critical); }
.fill.accent { background: var(--accent); }

/* Stats */

.stats { display: grid; grid-template-columns: repeat(6, 1fr); gap: .35rem; }

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: .35rem 0;
    border-radius: 8px;
    background: var(--surface-2);
}

.stat-name { font-size: .7rem; font-weight: 700; color: var(--muted); letter-spacing: .04em; }
.stat-mod { font-size: 1.1rem; font-weight: 700; }
.stat-value { font-size: .7rem; color: var(--muted); }

.stat.debilitated { background: var(--warn-soft); }
.stat.debilitated .stat-mod { color: var(--critical); }

/* Character sheet */

.back { display: inline-block; margin-bottom: .75rem; text-decoration: none; }

.sheet {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 1rem;
    /* Cards side by side match the taller one */
    align-items: stretch;
}

.sheet .wide { grid-column: 1 / -1; }

.sheet .stats { margin-bottom: .5rem; }

.pairs { display: grid; grid-template-columns: auto 1fr; gap: .25rem 1rem; margin: .75rem 0 0; }
.pairs dt { color: var(--muted); }
.pairs dd { margin: 0; font-weight: 600; }

ul.plain, ul.moves { list-style: none; margin: .5rem 0 0; padding: 0; }
ul.plain li { padding: .2rem 0; }

ul.moves { display: grid; gap: .6rem; }
.wide ul.moves { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }

ul.moves li { padding: .6rem .75rem; border-radius: 8px; background: var(--surface-2); }
ul.moves li.locked { opacity: .55; }

.move-name { font-weight: 600; display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }

ul.moves summary { cursor: pointer; list-style: none; display: grid; gap: .15rem; }
ul.moves summary::-webkit-details-marker { display: none; }
ul.moves summary .move-name::before { content: "▸"; color: var(--muted); transition: transform .15s; }
ul.moves details[open] > summary .move-name::before { transform: rotate(90deg); }

/* One line of the description while closed, so a list of moves is readable at a glance */
.preview {
    font-size: .82rem;
    color: var(--muted);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    padding-left: 1rem;
}
.preview br { display: none; }
.preview:empty, details[open] .preview { display: none; }
details > .small { margin-top: .4rem; }

.callout {
    margin: .75rem 0 0;
    padding: .6rem .75rem;
    border-left: 3px solid var(--accent);
    background: var(--accent-soft);
    border-radius: 0 8px 8px 0;
}

/* Roll stats */

.table-card { padding: 0; overflow-x: auto; margin-top: 1rem; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: .6rem .9rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.spread { width: 35%; min-width: 140px; }

.spread-bar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--surface-2); }

.strong { background: var(--good); }
.weak { background: var(--low); }
.miss { background: var(--critical); }

.legend { display: flex; gap: 1rem; margin-top: .6rem; font-size: .85rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .35rem; vertical-align: middle; }

/* Summary tiles */

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: .75rem;
    margin-top: 1rem;
}

.tile { display: flex; flex-direction: column; gap: .1rem; padding: .75rem .9rem; }
.tile-label { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.tile strong { font-size: 1.4rem; font-variant-numeric: tabular-nums; }

.resource-chips { display: flex; flex-wrap: wrap; gap: .3rem; }
/* Class and subclass on one line, the pill shortening rather than wrapping so every card's header is the same height */
.class-line { display: flex; align-items: center; gap: .45rem; min-width: 0; white-space: nowrap; }
.class-line .chip { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.member-head > div:first-child { min-width: 0; }
.member-extra { display: flex; flex-direction: column; gap: .5rem; padding-top: .75rem; border-top: 1px solid var(--border); }
.member-foot { display: flex; flex-wrap: wrap; gap: .9rem; margin-top: auto; padding-top: .5rem; border-top: 1px solid var(--border); }

ul.moves li.active { outline: 2px solid var(--accent); }

.jar-contents { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .25rem; }
.item-meta { display: flex; gap: .6rem; align-items: baseline; white-space: nowrap; }
strong.over { color: var(--critical); }
.sheet .bar { margin-bottom: .25rem; }

/* Character header */

.hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 1rem 2rem;
    align-items: center;
    margin-bottom: 1rem;
}

.hero h1 { margin: 0; }
.hero-chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem; }
.hero-chips:empty { display: none; }
.bonds { margin-top: .5rem; }

.hero-vitals {
    display: grid;
    grid-template-columns: minmax(180px, 1.6fr) repeat(auto-fit, minmax(90px, 1fr));
    gap: .6rem;
}

.vital {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: .05rem;
    padding: .55rem .75rem;
    border-radius: 10px;
    background: var(--surface-2);
}

.vital strong { font-size: 1.35rem; line-height: 1.2; }
.vital-hp .hp-label strong { font-size: 1.1rem; }

@media (max-width: 1000px) {
    .hero { grid-template-columns: 1fr; }
}

.hero-bonuses { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: .35rem; }

/* Section links stay in view while scrolling the sheet */
.jump {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    gap: .35rem;
    overflow-x: auto;
    scrollbar-width: none;
    margin: 0 -1.5rem 1rem;
    padding: .5rem 1.5rem;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.jump a {
    flex: none;
    padding: .25rem .7rem;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: .85rem;
    text-decoration: none;
}

.jump a:hover { border-color: var(--accent); color: var(--accent); }
.jump .count { color: var(--muted); font-size: .75rem; margin-left: .15rem; }

.sheet section[id] { scroll-margin-top: 3.5rem; }

.card-head { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: .5rem 1rem; margin-bottom: .5rem; }
.card-head h2 { margin: 0; }
.tools { display: flex; gap: .4rem; align-items: center; }

.filter, .tool {
    font: inherit;
    font-size: .85rem;
    padding: .3rem .7rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
}

.filter { width: 14rem; max-width: 100%; }
.filter:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.tool { cursor: pointer; white-space: nowrap; }
.tool:hover { border-color: var(--accent); color: var(--accent); }
a.tool { text-decoration: none; display: inline-block; }
.over-note { color: var(--critical); margin: .35rem 0 0; }

ul.meters { list-style: none; margin: .5rem 0 0; padding: 0; display: grid; gap: .8rem; }
ul.meters .small { margin-top: .2rem; }

ul.items {
    list-style: none;
    margin: .5rem 0 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: .4rem;
}

ul.items li {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: .75rem;
    padding: .45rem .65rem;
    border-radius: 8px;
    background: var(--surface-2);
}

.item-name { display: flex; flex-direction: column; }

li[hidden] { display: none !important; }

/* Signed-in viewer and live updates */

.viewer { margin-left: auto; display: flex; align-items: center; gap: .9rem; font-size: .85rem; }

.live { display: inline-flex; align-items: center; gap: .6rem; color: var(--muted); }
.live i { position: relative; width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 0 var(--good); }
.live.off i { background: var(--muted); }

/* A ring that ripples out every few seconds while connected, so the dot reads as live */
.live i::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--good);
    animation: live-ping 2.4s cubic-bezier(0, 0, .2, 1) infinite;
}

.live.off i::after { animation: none; opacity: 0; }

/* A bigger flash when an update lands */
.live.pulse i { animation: live-pulse 1s ease-out; }

@keyframes live-ping {
    0% { transform: scale(1); opacity: .7; }
    70%, 100% { transform: scale(2.8); opacity: 0; }
}

@keyframes live-pulse {
    from { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 70%, transparent); }
    to { box-shadow: 0 0 0 10px transparent; }
}

@media (prefers-reduced-motion: reduce) {
    .live i::after, .live.pulse i { animation: none; }
}

.me { display: inline-flex; align-items: center; gap: .45rem; color: var(--text); text-decoration: none; font-weight: 600; }
.me img { border-radius: 50%; }
a.me:hover span { color: var(--accent); }
.signout { color: var(--muted); }

tr.mine td { background: var(--accent-soft); }
tr.mine td:first-child { box-shadow: inset 3px 0 0 var(--accent); }

.notice { max-width: 560px; margin: 3rem auto; padding: 1.5rem 1.75rem; }
.notice h1 { font-size: 1.4rem; margin-bottom: .75rem; }

/* Reference pages */

.lookup-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: .75rem;
    margin-top: .5rem;
}

.lookup-card { display: flex; flex-direction: column; gap: .45rem; color: inherit; text-decoration: none; transition: border-color .15s, transform .15s; }
.lookup-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.lookup-card h3 { margin: 0; font-size: 1.05rem; }
.played-by { color: var(--class); }

.jump-filter { margin-left: auto; flex: 0 1 13rem; min-width: 7rem; }
a.chip { text-decoration: none; }
.chip.good { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
ul.moves li.owned { box-shadow: inset 3px 0 0 var(--good); }

.spell-list { margin-bottom: 1rem; }
.spell-list h3 { margin: 1rem 0 .4rem; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.kit-base { margin: .35rem 0 .5rem; }
.kit-choices li { padding: .15rem 0; }

[data-filter-group][hidden] { display: none !important; }
.hero .muted a, .hero-main > .muted a { color: inherit; text-decoration-color: var(--accent); }
.hero-main > .muted a.class-name { color: var(--class); text-decoration-color: color-mix(in srgb, var(--class) 50%, transparent); }

/* Class colors: each class sets --class, which cards, headers, chips and bars pick up */

.cls-ranger { --class: #2e7d4a; }
.cls-paladin { --class: #a87b0a; }
.cls-druid { --class: #5f9010; }
.cls-battlemaster { --class: #4c6480; }
.cls-channeler { --class: #0b8299; }
.cls-necromancer { --class: #7d4bb5; }
.cls-slayer { --class: #b3262e; }
.cls-templar { --class: #c0620c; }
.cls-shaman { --class: #16806e; }
.cls-captain { --class: #1d3f73; }
.cls-collector { --class: #a33a86; }
.cls-lantern { --class: #c0365e; }
.cls-mechanic { --class: #8a5a30; }
.cls-skydancer { --class: #1f86c9; }
.cls-survivor { --class: #5f6b2e; }
.cls-walker { --class: #3f5aa8; }
.cls-golem { --class: #66625b; }
.cls-barbarian { --class: #9c3d1c; }
.cls-bard { --class: #b0457a; }
.cls-cleric { --class: #8c7a2b; }
.cls-fighter { --class: #5a5f6b; }
.cls-immolator { --class: #d4480f; }
.cls-thief { --class: #3d4a45; }
.cls-wizard { --class: #4a3fa8; }

@media (prefers-color-scheme: dark) {
    .cls-ranger { --class: #5cc27e; }
    .cls-paladin { --class: #e6b84a; }
    .cls-druid { --class: #9bd040; }
    .cls-battlemaster { --class: #9aafca; }
    .cls-channeler { --class: #48c4dc; }
    .cls-necromancer { --class: #b58ce8; }
    .cls-slayer { --class: #f06b72; }
    .cls-templar { --class: #f2a052; }
    .cls-shaman { --class: #4ac6ae; }
    .cls-captain { --class: #5f86c9; }
    .cls-collector { --class: #e27cc2; }
    .cls-lantern { --class: #f27a98; }
    .cls-mechanic { --class: #c99a6a; }
    .cls-skydancer { --class: #6cbcf2; }
    .cls-survivor { --class: #a7b46a; }
    .cls-walker { --class: #8aa0ec; }
    .cls-golem { --class: #aca69c; }
    .cls-barbarian { --class: #e07a52; }
    .cls-bard { --class: #ec8ab8; }
    .cls-cleric { --class: #d8c46a; }
    .cls-fighter { --class: #a6adbd; }
    .cls-immolator { --class: #ff8a4c; }
    .cls-thief { --class: #8fa89e; }
    .cls-wizard { --class: #9c92f0; }
}

.class-name { color: var(--class); font-weight: 600; }
.chip.class { background: color-mix(in srgb, var(--class) 16%, transparent); color: var(--class); }
.fill.class { background: var(--class); }

/* A stripe along the top in the class color */
.member, .lookup-card[class*="cls-"], .hero[class*="cls-"] { box-shadow: inset 0 4px 0 var(--class); }
.member:hover, .lookup-card[class*="cls-"]:hover { border-color: var(--class); }
.member.mine { border-color: var(--accent); box-shadow: inset 0 4px 0 var(--class), 0 0 0 1px var(--accent); }

/* A soft wash of the class color behind a character's or class's name */
.hero[class*="cls-"] {
    background:
        linear-gradient(120deg, color-mix(in srgb, var(--class) 15%, transparent), transparent 55%),
        var(--surface);
}

/* Stat icons */

.icon { flex: none; vertical-align: -2px; }
.icon-heart { color: var(--heart); }
.icon-shield { color: var(--armor); }
.icon-magic { color: var(--magic); }
.icon-divine { color: var(--divine); }
.icon-sword { color: var(--damage); }
.tile-label { display: inline-flex; align-items: center; gap: .3rem; }
.vital.armor { box-shadow: inset 3px 0 0 var(--armor); }
.vital.magic { box-shadow: inset 3px 0 0 var(--magic); }
.vital.divine { box-shadow: inset 3px 0 0 var(--divine); }
.vital.damage { box-shadow: inset 3px 0 0 var(--damage); }
.vital.heart { box-shadow: inset 3px 0 0 var(--heart); }
.armor-row span { display: inline-flex; align-items: center; gap: .3rem; }
.hp-label > span:first-child { display: inline-flex; align-items: center; gap: .3rem; }

/* Dice sums */

.section-title { margin-top: 2rem; }

.dice-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
    margin-top: .75rem;
}

.dice-grid h3 { margin-top: 0; }

.dice-chart { display: grid; grid-template-columns: repeat(11, 1fr); gap: 4px; align-items: end; }
.dice-col { display: flex; flex-direction: column; align-items: center; gap: .15rem; }
.dice-track { position: relative; width: 100%; height: 110px; background: var(--surface-2); border-radius: 4px; }
.dice-bar { position: absolute; bottom: 0; left: 0; right: 0; border-radius: 4px 4px 0 0; }
.dice-expected { position: absolute; left: -2px; right: -2px; height: 2px; background: var(--text); opacity: .55; }
.dice-count { font-size: .7rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.dice-sum { font-size: .8rem; font-weight: 700; }

.legend i.expected { height: 2px; background: var(--text); opacity: .55; }

/* Session calendar */

.calendar {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: .75rem;
    margin: .75rem 0 1.25rem;
}

.cal-month { padding: .75rem; }
.cal-month h3 { margin: 0 0 .5rem; }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; text-align: center; }
.cal-weekday { font-size: .65rem; font-weight: 700; color: var(--muted); }

.cal-day {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
    border-radius: 6px;
    font-size: .75rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.cal-day.played {
    background: var(--accent);
    opacity: var(--busy, 1);
    color: var(--surface);
    font-weight: 700;
    text-decoration: none;
}

.cal-day.played:hover, .cal-day.played:focus-visible { opacity: 1; outline: 2px solid var(--accent); outline-offset: 1px; }
.cal-day.today { outline: 1px solid var(--accent); color: var(--accent); }

button.cal-day { border: 0; padding: 0; font: inherit; font-size: .75rem; cursor: pointer; }

/* Placed next to its day by app.js */
.cal-pop {
    position: fixed;
    inset: auto;
    margin: 0;
    padding: .75rem .9rem;
    min-width: 190px;
    color: var(--text);
    box-shadow: 0 8px 24px rgb(0 0 0 / .25);
}

.cal-pop dl { display: grid; grid-template-columns: 1fr auto; gap: .2rem 1rem; margin: .5rem 0 0; font-size: .85rem; }
.cal-pop dt { color: var(--muted); }
.cal-pop dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.cal-pop dd.lucky { color: var(--good); font-weight: 700; }
.cal-pop dd.unlucky { color: var(--critical); font-weight: 700; }

tr.dm-row td { background: var(--surface-2); }

td.lucky { color: var(--good); font-weight: 700; }
td.unlucky { color: var(--critical); font-weight: 700; }

@media (max-width: 600px) {
    main { padding: 1rem; }
    .topbar { padding: .75rem 1rem; gap: .5rem .75rem; flex-wrap: wrap; }
    .viewer { gap: .6rem; }
    .me span:not(.chip) { display: none; }
    .sheet { grid-template-columns: 1fr; }
    .wide ul.moves { grid-template-columns: 1fr; }
    .dice-grid { grid-template-columns: 1fr; }
    .tiles { grid-template-columns: repeat(2, 1fr); }
    .hero { grid-template-columns: 1fr; }
    .hero-vitals { grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); }
    .vital-hp { grid-column: 1 / -1; }
    .jump { margin: 0 -1rem 1rem; padding: .5rem 1rem; }
    .filter { width: 100%; }
    .jump-filter { width: 10rem; }
    .tools { width: 100%; }
}
