/* Chester's Game - candlelit dice tray. Offline-safe: system font stacks only, no external assets. */

:root {
    --ink: #1a0d12;
    --ink-deep: #120809;
    --velvet: #3a121c;
    --velvet-deep: #250a11;
    --seam: rgba(214, 170, 120, 0.22);
    --walnut: #4a2c1a;
    --walnut-light: #6e4428;
    --bone: #ece2cb;
    --bone-dim: #b5a68b;
    --brass: #c9a04a;
    --brass-bright: #ecd08a;
    --verdigris: #6fa596;
    --ash: #7a6e68;
    --danger: #e08a7a;

    --font-serif: "Palatino Linotype", "Book Antiqua", Palatino, "URW Palladio L", "P052", Georgia, serif;

    --die-size: 168px;
    --check-size: 64px;
    --gutter: clamp(16px, 6vw, 128px);
    --page-max: 2200px;
    --radius-tray: 22px;
    --radius-small: 6px;

    --text-small: 0.875rem;
    --text-body: 1rem;
    --text-title: 1.375rem;
    --text-value: 4.25rem;

    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    background: var(--ink-deep);
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--bone);
    font-family: var(--font-serif);
    font-size: var(--text-body);
    line-height: 1.5;
    background:
        radial-gradient(1200px 700px at 12% -10%, rgba(201, 140, 60, 0.18), transparent 60%),
        radial-gradient(900px 600px at 100% 110%, rgba(111, 165, 150, 0.08), transparent 60%),
        var(--ink);
}

.page {
    --page-gap: 22px;
    --tab-tuck: 9px;              /* how far an inactive tab slides under the tray's top rim */
    --layer-tab-behind: 0;
    --layer-tray: 1;
    --layer-tab-front: 2;
    --layer-tab-focus: 3;
    /* fluid: grows with the screen up to a wide cap; the gutter sits INSIDE the cap (border-box), so it adds to the centring space on wide screens */
    max-width: var(--page-max);
    margin: 0 auto;
    padding: 28px var(--gutter) 40px;
    display: grid;
    gap: var(--page-gap);
}

.panel {
    display: grid;
    gap: var(--page-gap);
    min-width: 0;
}

h1, h2 {
    margin: 0;
    font-weight: normal;
}

button, select {
    font: inherit;
    color: inherit;
}

:focus-visible {
    outline: 2px solid var(--brass-bright);
    outline-offset: 3px;
}

kbd {
    font-family: var(--font-serif);
    font-size: 0.85em;
    padding: 1px 7px;
    border: 1px solid rgba(236, 226, 203, 0.35);
    border-bottom-width: 2px;
    border-radius: 4px;
}

/* ---------- masthead ---------- */

.masthead {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px 24px;
}

.wordmark {
    font-style: italic;
    font-size: clamp(2.25rem, 6vw, 3.75rem);
    line-height: 1;
    letter-spacing: -0.01em;
    color: var(--bone);
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6), 0 0 28px rgba(201, 160, 74, 0.28);
}

.preset-picker {
    display: flex;
    align-items: center;
    gap: 12px;
}

.preset-picker-label {
    font-size: var(--text-small);
    color: var(--bone-dim);
    font-style: italic;
}

.preset-picker select,
.brass-select {
    appearance: none;
    min-width: 200px;
    padding: 8px 40px 8px 14px;
    font-size: 1.125rem;
    color: var(--bone);
    background:
        linear-gradient(45deg, transparent 50%, var(--brass) 50%) right 20px center / 7px 7px no-repeat,
        linear-gradient(-45deg, transparent 50%, var(--brass) 50%) right 14px center / 7px 7px no-repeat,
        var(--velvet-deep);
    border: 1px solid rgba(201, 160, 74, 0.5);
    border-radius: var(--radius-small);
    cursor: pointer;
}

/* ---------- the tray ---------- */

.tray {
    position: relative;
    z-index: var(--layer-tray);
    padding: 14px;
    border-radius: var(--radius-tray);
    background:
        repeating-linear-gradient(92deg, rgba(0, 0, 0, 0.16) 0 2px, transparent 2px 9px, rgba(255, 220, 170, 0.05) 9px 11px, transparent 11px 23px),
        linear-gradient(180deg, var(--walnut-light), var(--walnut) 40%, #3a2213);
    box-shadow:
        0 30px 60px -20px rgba(0, 0, 0, 0.8),
        inset 0 1px 0 rgba(255, 220, 170, 0.25),
        inset 0 -2px 0 rgba(0, 0, 0, 0.4);
}

.tray-bar {
    display: flex;
    justify-content: flex-end;
    padding: 0 4px 12px;
}

/* ---------- tabs: walnut folder tabs rising from the tray ---------- */

.tabs {
    display: flex;
    gap: 6px;
    padding: 0 var(--radius-tray);
    margin-bottom: calc(-1 * var(--page-gap));
    /* no z-index here: the tabs must interleave with the tray (inactive behind, active in front) */
}

.tab {
    position: relative;
    z-index: var(--layer-tab-behind);
    top: var(--tab-tuck);
    padding: 10px 24px 12px;
    font-size: 1.125rem;
    font-style: italic;
    color: var(--bone-dim);
    background:
        repeating-linear-gradient(92deg, rgba(0, 0, 0, 0.2) 0 2px, transparent 2px 9px, rgba(255, 220, 170, 0.04) 9px 11px, transparent 11px 23px),
        linear-gradient(180deg, #4a2c1a, #2f1b0f);
    border: 0;
    border-radius: 14px 14px 0 0;
    box-shadow: inset 0 1px 0 rgba(255, 220, 170, 0.12), inset 0 -6px 8px -6px rgba(0, 0, 0, 0.6);
    cursor: pointer;
    transition: color 150ms ease, top 150ms ease;
}

.tab:hover {
    color: var(--bone);
}

/* a keyboard-focused tucked tab comes forward so its whole focus outline shows */
.tab:focus-visible {
    z-index: var(--layer-tab-focus);
}

.tab[aria-selected="true"] {
    z-index: var(--layer-tab-front);
    top: 0;
    color: var(--bone);
    background:
        repeating-linear-gradient(92deg, rgba(0, 0, 0, 0.16) 0 2px, transparent 2px 9px, rgba(255, 220, 170, 0.05) 9px 11px, transparent 11px 23px),
        linear-gradient(180deg, #7a4c2e, var(--walnut-light));
    box-shadow: inset 0 1px 0 rgba(255, 220, 170, 0.3);
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.5);
}

/* ---------- damage calculator ---------- */

.calc {
    display: grid;
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
}

/* on very wide screens the form keeps a sensible width and the resolution's lines stay readable */
@media (min-width: 1800px) {
    .calc {
        grid-template-columns: minmax(0, 720px) minmax(0, 1fr);
    }

    .calc-check-row,
    .calc-outcome {
        max-width: 900px;
    }
}

.field-pair {
    max-width: 480px;
}

.calc-sheet {
    display: grid;
    align-content: start;
    gap: 20px;
    padding: 24px;
    border-right: 2px dashed var(--seam);
}

.field {
    display: grid;
    gap: 6px;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.field-label {
    padding: 0;
    font-size: 1.0625rem;
    font-style: italic;
    color: var(--bone);
}

.field-hint,
.calc-preview {
    max-width: 64ch;
}

.field-hint {
    margin: 0;
    font-size: var(--text-small);
    color: var(--bone-dim);
}

.field-input {
    width: 100%;
    min-width: 0;
    padding: 8px 12px;
    font: inherit;
    font-size: 1.125rem;
    color: var(--bone);
    background: rgba(0, 0, 0, 0.3);
    border: 0;
    border-bottom: 2px solid rgba(201, 160, 74, 0.45);
    border-radius: var(--radius-small) var(--radius-small) 0 0;
    font-variant-numeric: lining-nums tabular-nums;
}

.field-input::placeholder {
    color: rgba(181, 166, 139, 0.55);
    font-style: italic;
}

.field-input:focus {
    border-bottom-color: var(--brass-bright);
    background: rgba(0, 0, 0, 0.42);
}

.field-input[aria-invalid="true"] {
    border-bottom-color: var(--danger);
}

.field-input--large {
    max-width: 220px;
    font-size: 1.75rem;
    font-weight: bold;
    color: var(--brass-bright);
}

.field-with-unit,
.resist-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
}

.field-with-unit {
    max-width: 140px;
}

.field-unit {
    color: var(--bone-dim);
}

.field-pair {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.resist-list,
.modifier-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 8px;
}

.resist-row {
    grid-template-columns: minmax(0, 150px) auto auto;
    justify-content: start;
}

/* a modifier slip: name + hint, value, unit, remove; the left edge says whether it reaches the copied result */
.modifier-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 96px) auto auto;
    align-items: center;
    gap: 8px 10px;
    padding: 8px 10px 8px 14px;
    background: rgba(0, 0, 0, 0.2);
    border-left: 3px solid var(--brass);
    border-radius: 0 var(--radius-small) var(--radius-small) 0;
}

.modifier-row[data-copied="false"] {
    border-left-color: var(--verdigris);
}

.modifier-label {
    display: grid;
    min-width: 0;
}

.modifier-name {
    font-style: italic;
    color: var(--bone);
}

.modifier-hint {
    font-size: 0.8125rem;
    line-height: 1.35;
    color: var(--bone-dim);
}

.modifier-row.is-repeat .modifier-hint {
    display: none;
}

.modifier-add .brass-select {
    min-width: 0;
    font-size: 1rem;
    padding-block: 6px;
}

.modifier-add {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 14px;
}

.row-remove {
    width: 34px;
    height: 34px;
    font-size: 1.25rem;
    line-height: 1;
    color: var(--bone-dim);
    background: transparent;
    border: 1px solid rgba(236, 226, 203, 0.2);
    border-radius: 999px;
    cursor: pointer;
}

.row-remove:hover {
    color: var(--danger);
    border-color: rgba(224, 138, 122, 0.6);
}

.text-button {
    justify-self: start;
    padding: 4px 0;
    font-style: italic;
    color: var(--brass-bright);
    background: transparent;
    border: 0;
    border-bottom: 1px dashed rgba(236, 208, 138, 0.6);
    cursor: pointer;
}

.toggle-field {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-self: start;
    gap: 12px;
    font-size: 1.0625rem;
    font-style: italic;
    cursor: pointer;
}

.toggle-field input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

.toggle-box {
    position: relative;
    width: 24px;
    height: 24px;
    border: 2px solid rgba(201, 160, 74, 0.7);
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.3);
}

.toggle-field input:checked + .toggle-box {
    background: var(--brass);
    border-color: var(--brass-bright);
}

.toggle-field input:checked + .toggle-box::after {
    content: "";
    position: absolute;
    left: 6px;
    top: 1px;
    width: 7px;
    height: 13px;
    border: solid #2a1406;
    border-width: 0 3px 3px 0;
    transform: rotate(45deg);
}

.toggle-field input:focus-visible + .toggle-box {
    outline: 2px solid var(--brass-bright);
    outline-offset: 3px;
}

.calc-problem {
    margin: 0;
    color: var(--danger);
}

.calc-problem:empty,
.calc-preview:empty {
    display: none;
}

.calc-preview {
    margin: 0;
    font-size: var(--text-small);
    font-style: italic;
    color: var(--bone-dim);
}

.calc-resolution {
    display: grid;
    align-content: start;
    padding: 12px 24px 24px;
}

.calc-check {
    padding: 12px 0 14px;
    border-bottom: 2px dashed var(--seam);
    transition: opacity 300ms ease;
}

.calc-check-title {
    margin-bottom: 6px;
    font-size: 1.0625rem;
    font-style: italic;
}

.calc-check-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 12px;
}

.calc-resolution[data-crit-skipped] .calc-check--crit {
    opacity: 0.4;
}

.calc-outcome {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 20px;
    padding-top: 18px;
}

.calc-breakdown {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 4px;
}

.calc-step {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    padding-bottom: 4px;
    font-size: var(--text-small);
    color: var(--bone-dim);
    border-bottom: 1px dotted rgba(236, 226, 203, 0.18);
}

.calc-step-value {
    color: var(--bone);
    font-variant-numeric: lining-nums tabular-nums;
}

.calc-final {
    display: grid;
    justify-items: end;
    min-width: 7rem;
}

.calc-final-value {
    font-size: 4.5rem;
    line-height: 1;
    font-weight: bold;
    color: var(--brass-bright);
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.55), 0 0 22px rgba(201, 160, 74, 0.35);
    font-variant-numeric: lining-nums;
}

.calc-final-value.is-revealed {
    animation: stamp 520ms cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.calc-resolution[data-outcome="idle"] .calc-final-value,
.calc-resolution[data-outcome="rolling"] .calc-final-value {
    color: rgba(236, 226, 203, 0.25);
    text-shadow: none;
}

.calc-resolution[data-outcome="dodged"] .calc-final-value {
    font-size: 3rem;
    font-style: italic;
    color: var(--verdigris);
    text-shadow: 0 0 18px rgba(111, 165, 150, 0.35);
}

.calc-final-caption {
    font-size: var(--text-small);
    font-style: italic;
    color: var(--bone-dim);
    text-align: right;
}

.lanes {
    --lane-count: 3;
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(var(--lane-count), minmax(0, 1fr));
    grid-template-rows: auto 1fr auto;
}

/* the velvet lining shared by the dice tray and the calculator */
.lanes,
.calc,
.cabinet {
    border-radius: calc(var(--radius-tray) - 8px);
    overflow: hidden;
    background:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .35 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
        radial-gradient(120% 90% at 50% 30%, var(--velvet), var(--velvet-deep));
    box-shadow: inset 0 6px 18px rgba(0, 0, 0, 0.7), inset 0 0 0 1px rgba(0, 0, 0, 0.5);
}

.lane {
    display: grid;
    grid-row: span 3;
    grid-template-rows: subgrid;   /* head, body and check strip line up across lanes */
    min-width: 0;
    padding: 20px 20px 0;
    transition: background-color 400ms ease;
}

.lane + .lane {
    border-left: 2px dashed var(--seam);
}

.lane-head {
    display: grid;
    gap: 2px;
}

.lane-title {
    font-size: var(--text-title);
    font-style: italic;
    line-height: 1.2;
}

.lane-odds {
    margin: 0;
    font-size: var(--text-small);
    color: var(--bone-dim);
}

.lane-body {
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 4px;
    padding: 10px 0 14px;
}

.lane-dice {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    transition: opacity 400ms ease, filter 400ms ease;
}

.die {
    display: block;
    width: var(--die-size);
    height: var(--die-size);
}

.die--check {
    width: var(--check-size);
    height: var(--check-size);
}

.lane-value {
    display: block;
    min-height: 1.15em;
    font-size: var(--text-value);
    line-height: 1.1;
    font-weight: bold;
    text-align: center;
    color: var(--brass-bright);
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.55), 0 0 22px rgba(201, 160, 74, 0.35);
    font-variant-numeric: lining-nums;
}

.lane[data-state="idle"] .lane-value,
.lane[data-state="rolling"] .lane-value {
    color: rgba(236, 226, 203, 0.25);
    text-shadow: none;
}

.lane[data-state="idle"] .lane-dice {
    opacity: 0.55;
}

.lane[data-state="skipped"] {
    background-color: rgba(10, 4, 6, 0.35);
}

.lane[data-state="skipped"] .lane-dice {
    opacity: 0.28;
    filter: grayscale(1) brightness(0.7);
}

.lane[data-state="skipped"] .lane-title {
    color: var(--ash);
    text-decoration: line-through;
    text-decoration-color: rgba(122, 110, 104, 0.6);
}

.lane[data-state="skipped"] .lane-value {
    font-size: 1.5rem;
    font-weight: normal;
    font-style: italic;
    color: var(--bone-dim);
    text-shadow: none;
    padding-top: 0.6em;
}

.lane-value.is-revealed {
    animation: stamp 520ms cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

@keyframes stamp {
    0% { opacity: 0; transform: scale(1.7); filter: blur(4px); }
    60% { opacity: 1; filter: blur(0); }
    100% { opacity: 1; transform: scale(1); }
}

/* the chance check: deliberately separate from the result above it */

.lane-check {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    margin: 0 -20px;
    padding: 10px 20px 14px;
    min-height: 82px;
    background: rgba(0, 0, 0, 0.22);
    border-top: 2px dashed var(--seam);
}

.lane-check--always {
    grid-template-columns: minmax(0, 1fr);
}

.check-dice {
    display: flex;
}

.check-info {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.check-text {
    margin: 0;
    font-size: var(--text-small);
    line-height: 1.35;
    color: var(--bone-dim);
}

[data-check="passed"] .check-text {
    color: var(--verdigris);
}

.check-meter {
    position: relative;
    height: 8px;
    border-radius: 4px;
    background: rgba(236, 226, 203, 0.1);
}

.check-meter-fill {
    position: absolute;
    inset: 0 auto 0 0;
    width: var(--threshold);
    border-radius: 4px;
    background: linear-gradient(90deg, rgba(111, 165, 150, 0.35), rgba(111, 165, 150, 0.7));
}

.check-meter-mark {
    position: absolute;
    top: -5px;
    left: var(--roll, 0%);
    width: 3px;
    height: 18px;
    margin-left: -1.5px;
    border-radius: 2px;
    background: var(--bone);
    box-shadow: 0 0 8px rgba(236, 226, 203, 0.7);
    opacity: 0;
}

.check-meter-mark.is-shown {
    opacity: 1;
    animation: mark-drop 380ms ease-out both;
}

[data-check="failed"] .check-meter-mark {
    background: var(--danger);
    box-shadow: 0 0 8px rgba(224, 138, 122, 0.7);
}

@keyframes mark-drop {
    0% { opacity: 0; transform: translateY(-10px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* ---------- loot table card ---------- */

.lane--table .lane-body {
    grid-template-columns: minmax(0, 1fr);
    justify-items: stretch;
    align-content: start;
    gap: 12px;
}

.loot-summary {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: center;
    gap: 4px 16px;
}

.lane--table .lane-value {
    font-size: 3rem;
}

.loot-count {
    margin: 0;
    color: var(--bone-dim);
    font-style: italic;
}

.loot-grid {
    --loot-die: 132px;
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, var(--loot-die));
    justify-content: center;
    gap: 10px 8px;
}

.loot-grid[data-density="one"] {
    --loot-die: 176px;
}

.loot-grid[data-density="some"] {
    --loot-die: 100px;
}

.loot-grid[data-density="many"] {
    --loot-die: 74px;
}

.loot-tile {
    display: grid;
    justify-items: center;
}

.die--loot {
    width: var(--loot-die);
    height: var(--loot-die);
}

.loot-number {
    margin-top: -6px;
    font-size: 1.375rem;
    font-weight: bold;
    line-height: 1.2;
    color: var(--brass-bright);
    font-variant-numeric: lining-nums;
}

.loot-grid[data-density="many"] .loot-number {
    font-size: 1.05rem;
}

.loot-number.is-revealed {
    animation: stamp 420ms cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

/* item results: the settled die gives way to a painted item that anchors the effect popover */
.loot-visual {
    position: relative;
    width: var(--loot-die);
    height: var(--loot-die);
}

.loot-item {
    position: absolute;
    inset: 0;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 14px;
    cursor: pointer;
}

.loot-item:hover,
.loot-item:focus-visible {
    background: radial-gradient(closest-side, rgba(236, 208, 138, 0.18), transparent);
}

.loot-item:focus-visible {
    outline-offset: -2px;   /* keep the ring off the name caption below */
}

.loot-item.is-revealed {
    animation: item-appear 380ms cubic-bezier(0.2, 1.3, 0.4, 1) both;
}

@keyframes item-appear {
    0% { opacity: 0; transform: translateY(6px) scale(0.6); }
    100% { opacity: 1; transform: none; }
}

.loot-art {
    display: block;
    width: 100%;
    height: 100%;
}

.loot-tile--item {
    align-content: start;
}

.loot-caption {
    display: grid;
    justify-items: center;
    max-width: var(--loot-die);
    margin-top: -4px;
    text-align: center;
    line-height: 1.2;
}

.loot-name {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 0.875rem;
    font-style: italic;
    color: var(--bone);
}

.loot-face {
    font-size: 0.75rem;
    color: var(--bone-dim);
    font-variant-numeric: lining-nums;
}

.loot-grid[data-density="many"] .loot-name {
    font-size: 0.75rem;
}

.loot-effects {
    margin-top: 6px;
    padding-top: 12px;
    border-top: 2px dashed var(--seam);
}

.loot-effects-title {
    margin: 0 0 8px;
    font-size: 1.0625rem;
    font-style: italic;
    font-weight: normal;
}

.loot-effects-list {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 4px 16px;
    margin: 0;
    font-size: var(--text-small);
}

.loot-effects-list dt {
    font-style: italic;
    color: var(--bone);
}

.loot-effects-list dd {
    margin: 0;
    color: var(--bone-dim);
}

.loot-effects-list dd.is-unknown,
.effect-popover-text.is-unknown {
    font-style: italic;
    opacity: 0.6;
}

.effect-popover {
    position: fixed;
    z-index: 50;
    max-width: 260px;
    padding: 10px 14px;
    background: #2a1118;
    border: 1px solid rgba(201, 160, 74, 0.55);
    border-radius: 8px;
    box-shadow: 0 14px 30px -8px rgba(0, 0, 0, 0.8);
    pointer-events: none;
}

.effect-popover p {
    margin: 0;
}

.effect-popover-name {
    font-style: italic;
    color: var(--brass-bright);
}

.effect-popover-text {
    font-size: var(--text-small);
    color: var(--bone);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.loot-rows {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 6px;
}

.loot-row {
    display: grid;
    grid-template-columns: 2.6em minmax(0, 1fr) auto;
    align-items: baseline;
    gap: 8px;
    padding: 4px 10px;
    font-size: var(--text-small);
    color: var(--bone-dim);
    border: 1px solid rgba(236, 226, 203, 0.12);
    border-radius: var(--radius-small);
    transition: background-color 250ms ease, border-color 250ms ease, color 250ms ease;
}

.loot-row-range {
    font-variant-numeric: lining-nums tabular-nums;
}

.loot-row-label {
    color: var(--bone);
    font-style: italic;
}

.loot-row.is-selected {
    color: var(--bone);
    border-color: var(--brass);
    background: rgba(201, 160, 74, 0.16);
}

.loot-row.is-selected .loot-row-label {
    color: var(--brass-bright);
}

/* ---------- roll button and multiplier ---------- */

.controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 12px 36px;
}

.roll-group {
    display: grid;
    justify-items: center;
    gap: 6px;
}

.multiplier {
    display: grid;
    justify-items: center;
    gap: 4px;
}

.multiplier-label {
    font-size: var(--text-small);
    font-style: italic;
    color: var(--bone-dim);
}

.multiplier-stepper {
    display: inline-flex;
    align-items: center;
    border: 1px solid rgba(201, 160, 74, 0.6);
    border-radius: 999px;
    background: var(--velvet-deep);
}

.multiplier-step {
    width: 44px;
    height: 44px;
    font-size: 1.375rem;
    line-height: 1;
    color: var(--brass-bright);
    background: transparent;
    border: 0;
    border-radius: 999px;
    cursor: pointer;
}

.multiplier-step:hover:not(:disabled) {
    background: rgba(201, 160, 74, 0.16);
}

.multiplier-step:disabled {
    opacity: 0.3;
    cursor: default;
}

.multiplier-value {
    min-width: 3em;
    text-align: center;
    font-size: 1.25rem;
    font-weight: bold;
    color: var(--brass-bright);
    font-variant-numeric: lining-nums tabular-nums;
}

.roll-button {
    min-width: 280px;
    padding: 14px 40px;
    font-size: 1.5rem;
    font-style: italic;
    color: #2a1406;
    background: linear-gradient(180deg, var(--brass-bright), var(--brass) 55%, #9c7630);
    border: 0;
    border-radius: 999px;
    box-shadow:
        inset 0 0 0 2px rgba(255, 245, 210, 0.45),
        inset 0 0 0 5px rgba(120, 84, 30, 0.35),
        0 10px 26px -8px rgba(201, 160, 74, 0.55),
        0 3px 0 #5d4116;
    cursor: pointer;
    transition: transform 120ms ease, box-shadow 120ms ease;
}

.roll-button:hover {
    transform: translateY(-1px);
}

.roll-button:active {
    transform: translateY(2px);
    box-shadow: inset 0 0 0 2px rgba(255, 245, 210, 0.45), inset 0 0 0 5px rgba(120, 84, 30, 0.35), 0 1px 0 #5d4116;
}

[data-rolling] .roll-button {
    animation: candle 900ms ease-in-out infinite alternate;
}

@keyframes candle {
    from { filter: brightness(1); }
    to { filter: brightness(1.15); }
}

.roll-hint {
    margin: 0;
    font-size: var(--text-small);
    color: var(--bone-dim);
}

/* ---------- result + history ---------- */

.records {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
    gap: 22px;
}

.section-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 14px;
    margin-bottom: 10px;
}

.section-head h2 {
    font-size: var(--text-title);
    font-style: italic;
}

.copy-button,
.history-copy {
    padding: 4px 14px;
    font-size: var(--text-small);
    color: var(--brass-bright);
    background: transparent;
    border: 1px solid rgba(201, 160, 74, 0.6);
    border-radius: 999px;
    cursor: pointer;
}

.copy-button:hover,
.history-copy:hover {
    background: rgba(201, 160, 74, 0.14);
}

.copy-button:disabled {
    opacity: 0.4;
    cursor: default;
    background: transparent;
}

.copy-status {
    font-size: var(--text-small);
    color: var(--verdigris);
}

.copy-status.is-shown {
    animation: mark-drop 260ms ease-out both;
}

.result-text,
.history-text {
    margin: 0;
    font-family: var(--font-serif);
    white-space: pre-wrap;
    user-select: text;
}

.result-text {
    padding: 16px 20px;
    font-size: 1.125rem;
    line-height: 1.6;
    background: rgba(236, 226, 203, 0.06);
    border: 1px solid rgba(236, 226, 203, 0.16);
    border-left: 4px solid var(--brass);
    border-radius: var(--radius-small);
}

.result-text.is-empty {
    color: var(--bone-dim);
    font-style: italic;
}

.history-empty {
    margin: 0;
    color: var(--bone-dim);
    font-style: italic;
}

.history {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 10px;
}

.history-item {
    display: grid;
    align-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid rgba(236, 226, 203, 0.12);
    border-radius: var(--radius-small);
}

.history-item:first-child {
    border-color: rgba(201, 160, 74, 0.45);
}

.history-text {
    font-size: var(--text-small);
    line-height: 1.45;
    color: var(--bone-dim);
}

.history-copy {
    justify-self: start;
    padding: 2px 12px;
}

/* ---------- help ---------- */

.help {
    max-width: 72ch;
    color: var(--bone-dim);
    font-size: 0.95rem;
}

.help summary {
    cursor: pointer;
    color: var(--bone);
    font-style: italic;
}

.help ul {
    padding-left: 1.2em;
}

/* ---------- objects tab: the specimen cabinet ---------- */

.segmented {
    display: inline-flex;
    padding: 3px;
    background: var(--velvet-deep);
    border: 1px solid rgba(201, 160, 74, 0.55);
    border-radius: 999px;
}

.segmented-option {
    padding: 6px 20px;
    font-size: 1.0625rem;
    font-style: italic;
    color: var(--bone-dim);
    background: transparent;
    border: 0;
    border-radius: 999px;
    cursor: pointer;
}

.segmented-option[aria-selected="true"] {
    color: #2a1406;
    background: linear-gradient(180deg, var(--brass-bright), var(--brass));
}

.cabinet {
    padding: 20px 24px 24px;
}

.cabinet-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 20px;
    margin-bottom: 18px;
}

.cabinet-search {
    flex: 0 1 320px;
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chip {
    padding: 4px 14px;
    font-size: var(--text-small);
    color: var(--bone-dim);
    background: transparent;
    border: 1px solid rgba(201, 160, 74, 0.4);
    border-radius: 999px;
    cursor: pointer;
}

.chip[aria-pressed="true"] {
    color: var(--brass-bright);
    background: rgba(201, 160, 74, 0.2);
    border-color: var(--brass);
}

.cabinet-select {
    display: flex;
    align-items: center;
    gap: 8px;
}

.cabinet-select-label {
    font-size: var(--text-small);
    font-style: italic;
    color: var(--bone-dim);
}

.cabinet-select .brass-select {
    min-width: 180px;
    font-size: 1rem;
    padding-block: 6px;
}

.object-group + .object-group {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 2px dashed var(--seam);
}

.object-group-title {
    margin: 0 0 10px;
    font-size: var(--text-title);
    font-style: italic;
    font-weight: normal;
}

.object-group-count {
    margin-left: 10px;
    font-size: var(--text-small);
    font-style: normal;
    color: var(--bone-dim);
}

.object-group-empty {
    margin: 0;
    font-style: italic;
    color: var(--bone-dim);
}

.object-grid {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 4px 22px;
}

.object-card {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    align-items: start;
    gap: 12px;
    padding: 8px 0;
}

.object-art {
    display: block;
    width: 72px;
    height: 72px;
}

.object-text {
    display: grid;
    gap: 2px;
    padding-top: 6px;
}

.object-name {
    margin: 0;
    font-size: 1.0625rem;
    font-style: italic;
    font-weight: normal;
    color: var(--bone);
}

.object-effect,
.recipe-effect {
    margin: 0;
    font-size: var(--text-small);
    line-height: 1.4;
    color: var(--bone-dim);
}

.object-effect.is-unknown,
.recipe-effect.is-unknown {
    font-style: italic;
    opacity: 0.6;
}

.object-effect.is-drawback:not(.is-unknown) {
    color: var(--danger);
}

.effect-label {
    font-style: italic;
}

.object-price {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    font-size: var(--text-small);
    color: var(--brass-bright);
    font-variant-numeric: lining-nums;
}

.coin-glyph {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #fff1b8, var(--brass) 55%, #7a5a1e);
    box-shadow: 0 0 0 1px rgba(28, 10, 14, 0.8);
}

.object-recipes {
    margin-top: 2px;
    font-size: var(--text-small);
}

.cabinet-count {
    margin: 0 0 4px;
    font-size: var(--text-small);
    font-style: italic;
    color: var(--bone-dim);
}

.recipe-focus {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 16px;
    margin-bottom: 12px;
    padding: 8px 14px;
    background: rgba(111, 165, 150, 0.12);
    border-left: 3px solid var(--verdigris);
    border-radius: 0 var(--radius-small) var(--radius-small) 0;
}

.recipe-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 720px), 1fr));
    column-gap: 36px;
}

/* one recipe reads as an equation: ingredients + ingredients = result */
.recipe {
    display: grid;
    grid-template-columns: auto auto minmax(0, 260px);
    justify-content: start;
    align-items: center;
    gap: 12px;
    padding: 14px 0;
    border-top: 2px dashed var(--seam);
}

.recipe-ingredients {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 10px;
}

.recipe-part {
    display: grid;
    grid-template-columns: 60px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    margin: 0;
    max-width: 250px;
}

.recipe-art {
    display: block;
    width: 60px;
    height: 60px;
}

.recipe-result {
    grid-template-columns: 76px minmax(0, 1fr);
    padding: 6px 10px 6px 4px;
    background: rgba(201, 160, 74, 0.08);
    border-radius: 12px;
}

.recipe-result .recipe-art {
    width: 76px;
    height: 76px;
}

.recipe-caption {
    display: grid;
    gap: 2px;
}

.recipe-name {
    font-style: italic;
    color: var(--bone);
}

.recipe-result .recipe-name {
    font-size: 1.125rem;
    color: var(--brass-bright);
}

.recipe-count {
    font-style: normal;
    font-weight: bold;
    color: var(--brass-bright);
}

.recipe-operator {
    font-size: 1.75rem;
    line-height: 1;
    color: var(--brass);
}

.recipe-equals {
    font-size: 2.25rem;
}

/* ---------- objects tab: speculation ---------- */

.spec {
    --line-known: var(--brass);
    --line-guess: var(--bone-dim);
    --line-failed: var(--danger);
    --line-confirmed: var(--verdigris);
    --node-w: 196px;
    --col-gap: 64px;
    --spec-art: 56px;
    --spec-target-art: 72px;
}

.spec-chart[data-density="wide"] {
    --node-w: 220px;
    --col-gap: 80px;
}

.spec-chart[data-density="compact"] {
    --node-w: 176px;
    --col-gap: 44px;
    --spec-art: 48px;
    --spec-target-art: 64px;
}

/* minmax(0, 1fr) / min-width: 0 let the max-content stage shrink, so the page never scrolls sideways */
.spec-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 22px;
}

.spec-main {
    min-width: 0;
}

.spec-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 6px 24px;
}

.spec-title {
    margin: 0;
    font-size: var(--text-title);
    font-style: italic;
    font-weight: normal;
}

.spec-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 18px;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: var(--text-small);
    color: var(--bone-dim);
}

.spec-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.spec-bill {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 14px;
    margin: 10px 0 6px;
    font-size: var(--text-small);
    color: var(--bone-dim);
}

.spec-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-style: italic;
    color: var(--bone);
    white-space: nowrap;
}

.spec-chip-art {
    width: 28px;
    height: 28px;
}

.spec-chart {
    overflow-x: auto;   /* last resort: the chart scrolls inside its card, the page never does */
}

.spec-chart[data-layout="tree"] .spec-steps,
.spec-chart[data-layout="steps"] .spec-stage {
    display: none;
}

/* the stage: node cards on a grid, edges in an SVG overlay underneath */
.spec-stage {
    position: relative;
    display: grid;
    column-gap: var(--col-gap);
    row-gap: 14px;
    width: max-content;
    margin: 0 auto;
    padding: 40px 4px 8px 0;
}

.spec-edges {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: visible;
}

.spec-shelf {
    grid-column: 1;
    margin: -8px -10px;
    border: 1px dashed var(--seam);
    border-radius: 14px;
    background: rgba(0, 0, 0, 0.18);
}

.spec-shelf-caption {
    position: absolute;
    top: 8px;
    left: 0;
    margin: 0;
    font-size: var(--text-small);
    font-style: italic;
    color: var(--bone-dim);
}

.spec-edge {
    fill: none;
    stroke-width: 2;
}

.spec-edge[data-kind="known"] {
    stroke: var(--line-known);
    opacity: 0.75;
}

.spec-edge[data-kind="guess"] {
    stroke: var(--line-guess);
    stroke-dasharray: 7 6;
    opacity: 0.8;
}

.spec-edge[data-kind="failed"] {
    stroke: var(--line-failed);
    stroke-dasharray: 7 6;
    opacity: 0.55;
}

.spec-junction[data-kind="known"] {
    fill: var(--line-known);
}

.spec-junction[data-kind="guess"],
.spec-junction[data-kind="failed"] {
    fill: var(--velvet-deep);
    stroke-width: 2;
}

.spec-junction[data-kind="guess"] {
    stroke: var(--line-guess);
}

.spec-junction[data-kind="failed"] {
    stroke: var(--line-failed);
}

/* node card */
.spec-node {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: var(--spec-art) minmax(0, 1fr);
    align-items: start;
    align-self: center;
    gap: 4px 10px;
    padding: 8px 10px 8px 6px;
    border-radius: 12px;
    border: 1px solid transparent;
}

.spec-node[data-kind="known"] {
    border: 1px solid rgba(201, 160, 74, 0.4);
    background: rgba(0, 0, 0, 0.22);
}

.spec-node[data-kind="guess"] {
    border: 1.5px dashed rgba(236, 226, 203, 0.42);
    background: rgba(236, 226, 203, 0.035);
}

.spec-node[data-kind="failed"] {
    border: 1.5px dashed rgba(224, 138, 122, 0.55);
    background: rgba(224, 138, 122, 0.05);
}

.spec-node[data-kind="failed"] .spec-art {
    opacity: 0.6;
}

.spec-node.is-target {
    --spec-art: var(--spec-target-art);
    background: rgba(201, 160, 74, 0.1);
}

.spec-node.is-selected {
    box-shadow: 0 0 0 2px var(--brass-bright), 0 0 22px rgba(201, 160, 74, 0.3);
}

.spec-art-button {
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 8px;
    cursor: help;
}

.spec-art {
    display: block;
    width: var(--spec-art);
    height: var(--spec-art);
}

.spec-node-text {
    display: grid;
    gap: 2px;
    min-width: 0;
    padding-top: 4px;
}

.spec-name {
    padding: 0;
    font: inherit;
    font-size: 1rem;
    font-style: italic;
    text-align: left;
    color: var(--bone);
    background: transparent;
    border: 0;
}

button.spec-name {
    cursor: pointer;
}

button.spec-name:hover {
    color: var(--brass-bright);
}

.spec-node.is-target .spec-name {
    font-size: 1.125rem;
    color: var(--brass-bright);
}

.spec-count {
    font-style: normal;
    font-weight: bold;
    color: var(--brass-bright);
}

.spec-effect {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin: 0;
    font-size: var(--text-small);
    line-height: 1.4;
    color: var(--bone-dim);
}

.spec-effect.is-full {
    display: block;
}

.spec-effect.is-unknown {
    font-style: italic;
    opacity: 0.6;
}

.spec-no-recipe,
.spec-all-failed {
    margin: 0;
    font-size: 0.8rem;
    font-style: italic;
    color: var(--bone-dim);
}

.spec-all-failed {
    grid-column: 1 / -1;
}

/* cycler */
.spec-cycler {
    grid-column: 1 / -1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    padding-top: 6px;
    border-top: 1px dashed var(--seam);
}

.spec-cycle-step {
    flex: none;
    width: 30px;
    height: 30px;
    padding: 0;
    font-size: 0.8rem;
    color: var(--brass-bright);
    background: var(--velvet-deep);
    border: 1px solid rgba(201, 160, 74, 0.55);
    border-radius: 50%;
    cursor: pointer;
}

.spec-cycle-step:hover {
    border-color: var(--brass-bright);
}

.spec-cycle-label {
    display: grid;
    justify-items: center;
    gap: 2px;
    text-align: center;
}

.spec-cycle-idea {
    font-size: var(--text-small);
    color: var(--bone);
}

.spec-cycle-meta {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.pips {
    display: inline-flex;
    gap: 3px;
}

.pips i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    box-shadow: inset 0 0 0 1px var(--brass);
}

.pips i.is-filled {
    background: var(--brass-bright);
}

.badge {
    padding: 0 8px;
    font-size: 0.75rem;
    line-height: 1.6;
    border: 1px solid;
    border-radius: 999px;
}

.badge[data-status="untested"] {
    color: var(--bone-dim);
    border-color: rgba(181, 166, 139, 0.5);
}

.badge[data-status="failed"] {
    color: var(--danger);
    border-color: rgba(224, 138, 122, 0.6);
    text-decoration: line-through;
}

.badge[data-status="confirmed"] {
    color: var(--verdigris);
    border-color: var(--verdigris);
}

/* steps layout: the numbered brewing order */
.spec-steps {
    margin: 12px 0 0;
    padding: 0;
    list-style: none;
}

.spec-step {
    position: relative;
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 6px 12px;
    padding-bottom: 18px;
}

.spec-step:not(:last-child)::after {
    content: "";
    position: absolute;
    top: 32px;
    bottom: 2px;
    left: 14px;
    border-left: 2px solid var(--line-known);
    opacity: 0.6;
}

.spec-step[data-kind="guess"]:not(:last-child)::after,
.spec-step[data-kind="failed"]:not(:last-child)::after {
    border-left: 2px dashed var(--line-guess);
}

.spec-step-number {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    font-size: var(--text-small);
    color: var(--brass-bright);
    border: 1px solid var(--brass);
    border-radius: 50%;
}

.spec-step[data-kind="guess"] > .spec-step-number,
.spec-step[data-kind="failed"] > .spec-step-number {
    color: var(--bone);
    border: 1px dashed var(--bone-dim);
}

.spec-step-body {
    display: grid;
    gap: 8px;
    min-width: 0;
}

.spec-step-line,
.spec-equation {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
    margin: 0;
    color: var(--bone);
    font-style: italic;
}

.spec-unit {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.spec-unit-art {
    width: 40px;
    height: 40px;
}

.spec-equation .spec-unit-art {
    width: 36px;
    height: 36px;
}

.spec-operator {
    font-style: normal;
    color: var(--brass);
}

.spec-used-in {
    margin: 0;
    font-size: 0.8rem;
    font-style: italic;
    color: var(--bone-dim);
}

.spec-why summary {
    cursor: pointer;
    font-style: italic;
    color: var(--brass-bright);
}

.spec-why[open] {
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.18);
    border-radius: 10px;
}

/* side cards: detail and test plan */
.spec-side {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
    gap: 22px;
    align-items: start;
}

#speculation-view[data-layout="steps"] .spec-detail {
    display: none;   /* in steps the same content opens inside each step's "Why this guess" */
}

.spec-card {
    padding: 16px 18px;
    border-radius: 14px;
    background: rgba(0, 0, 0, 0.22);
    border: 1px solid rgba(201, 160, 74, 0.3);
}

.spec-card-title {
    margin: 0 0 8px;
    font-size: 1.125rem;
    font-style: italic;
    font-weight: normal;
    color: var(--brass-bright);
}

.spec-why .spec-card-title {
    margin-top: 10px;
}

.spec-detail-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    margin: 0 0 10px;
    font-size: var(--text-small);
    color: var(--bone-dim);
}

.spec-card p,
.spec-why p,
.spec-reasons {
    max-width: 62ch;
}

.spec-detail-text,
.spec-condition,
.spec-reasons,
.spec-outcome {
    margin: 10px 0 0;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--bone);
}

.spec-condition {
    font-style: italic;
}

.spec-reasons {
    padding-left: 1.2em;
}

.spec-outcome[data-status="failed"] {
    color: var(--danger);
}

.spec-outcome[data-status="confirmed"] {
    color: var(--verdigris);
}

.spec-risk {
    margin: 10px 0 0;
    padding-left: 10px;
    font-size: var(--text-small);
    color: var(--bone-dim);
    border-left: 3px solid var(--danger);
}

.spec-cost,
.spec-plan-cost {
    margin: 8px 0 0;
    font-size: var(--text-small);
    color: var(--bone-dim);
}

.spec-others-title {
    margin: 12px 0 4px;
    font-size: var(--text-small);
    font-style: italic;
    color: var(--bone-dim);
}

.spec-others {
    display: grid;
    gap: 4px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.spec-others li {
    display: flex;
    align-items: center;
    gap: 10px;
}

.spec-plan {
    display: grid;
    gap: 14px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.spec-plan-item {
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 0 12px;
}

.spec-plan-item.is-next > .spec-step-number {
    color: #2a1406;
    background: var(--brass);
}

.spec-plan-body {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.spec-plan-title {
    padding: 0;
    font: inherit;
    font-style: italic;
    text-align: left;
    color: var(--bone);
    background: transparent;
    border: 0;
    cursor: pointer;
}

.spec-plan-title:hover {
    color: var(--brass-bright);
}

.spec-plan-cost {
    margin: 0;
}

.spec-plan-wait,
.spec-plan-note {
    margin: 0;
    font-size: var(--text-small);
    font-style: italic;
    color: var(--bone-dim);
}

/* ---------- wide screens: bigger dice, the extra width goes to more columns ---------- */

@media (min-width: 1800px) {
    :root {
        --die-size: 200px;
        --check-size: 72px;
        --text-value: 5rem;
    }

    .spec-layout {
        grid-template-columns: minmax(0, 1fr) 420px;
        align-items: start;
    }

    .spec-side {
        grid-template-columns: minmax(0, 1fr);
        position: sticky;
        top: 16px;
    }

    .loot-grid {
        --loot-die: 150px;
    }

    .loot-grid[data-density="some"] {
        --loot-die: 116px;
    }

    .loot-grid[data-density="many"] {
        --loot-die: 88px;
    }
}

/* ---------- narrower screens ---------- */

@media (max-width: 860px) {
    :root {
        --die-size: 112px;
        --check-size: 56px;
        --text-value: 3.5rem;
    }

    .lanes {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: none;
    }

    .lane + .lane {
        border-left: 0;
        border-top: 2px dashed var(--seam);
    }

    .lane {
        grid-row: auto;
        grid-template-columns: auto minmax(0, 1fr);
        grid-template-rows: auto auto auto;
        column-gap: 12px;
        padding: 12px 16px 0;
    }

    .lane-head {
        grid-column: 1 / -1;
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        justify-content: space-between;
        gap: 0 12px;
    }

    .lane-body {
        grid-column: 1 / -1;
        grid-template-columns: auto minmax(0, 1fr);
        justify-items: start;
        align-items: center;
        gap: 14px;
        padding: 0 0 4px;
    }

    .history {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }

    .lane-value {
        text-align: left;
    }

    .lane[data-state="skipped"] .lane-value {
        padding-top: 0;
        font-size: 1.25rem;
    }

    .lane-check {
        grid-column: 1 / -1;
        margin: 0 -16px;
        padding: 6px 16px 8px;
        min-height: 0;
    }

    .lane-check--always {
        padding-block: 8px;
    }

    .records {
        grid-template-columns: minmax(0, 1fr);
    }

    .controls {
        position: sticky;
        bottom: 0;
        z-index: 2;
        margin: 0 calc(-1 * var(--gutter));
        padding: 12px var(--gutter) 14px;
        background: linear-gradient(180deg, rgba(26, 13, 18, 0), rgba(26, 13, 18, 0.92) 30%, var(--ink));
    }

    .controls {
        flex-wrap: nowrap;
        gap: 12px;
    }

    .roll-group {
        flex: 1 1 auto;
        justify-items: stretch;
    }

    .roll-button {
        width: 100%;
        min-width: 0;
    }

    .multiplier-label {
        font-size: 0.75rem;
    }

    .multiplier-step {
        width: 38px;
        height: 38px;
    }

    .multiplier-value {
        min-width: 2.4em;
    }

    .loot-grid {
        --loot-die: 92px;
    }

    .loot-grid[data-density="one"] {
        --loot-die: 128px;
    }

    .loot-grid[data-density="some"] {
        --loot-die: 70px;
    }

    .loot-grid[data-density="many"] {
        --loot-die: 54px;
    }

    .loot-number {
        margin-top: -4px;
        font-size: 1.125rem;
    }

    .loot-grid[data-density="many"] .loot-number {
        font-size: 0.95rem;
    }

    .loot-rows {
        grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    }

    /* stack name over effect so long names don't squeeze the effect column */
    .loot-effects-list {
        grid-template-columns: minmax(0, 1fr);
        gap: 0;
    }

    .loot-effects-list dd {
        margin-bottom: 8px;
    }

    .roll-hint {
        display: none;
    }
}

@media (max-width: 420px) {
    :root {
        --die-size: 88px;
        --check-size: 48px;
        --text-value: 3rem;
    }

    .page {
        --page-gap: 18px;   /* the tabs tuck into the tray by exactly this gap */
        padding-top: 20px;
    }

    .tray {
        padding: 10px;
        border-radius: 18px;
    }

    /* three Objects-tab views fit the tray bar at 375px */
    .segmented-option {
        padding: 6px 12px;
    }
}

@media (max-width: 860px) {
    .spec-cycle-step {
        width: 36px;
        height: 36px;
    }

    .calc {
        grid-template-columns: minmax(0, 1fr);
    }

    .calc-sheet {
        padding: 18px 16px;
        border-right: 0;
        border-bottom: 2px dashed var(--seam);
    }

    .calc-resolution {
        padding: 6px 16px 18px;
    }

    .calc-final-value {
        font-size: 3.5rem;
    }

    .cabinet {
        padding: 16px 14px 18px;
    }

    .cabinet-search {
        flex-basis: 100%;
    }

    .object-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    /* recipe equations stack: ingredients, then "=", then the result */
    .recipe {
        grid-template-columns: minmax(0, 1fr);
        justify-items: start;
        gap: 6px;
    }

    .recipe-ingredients {
        flex-direction: column;
        align-items: flex-start;
    }

    .recipe-operator {
        padding-left: 22px;
        font-size: 1.375rem;
    }

    .recipe-part,
    .recipe-result {
        max-width: none;
    }

    /* flex instead of grid here: a spanning hint would otherwise widen the value column of the first row only */
    .modifier-row {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
    }

    .modifier-label {
        flex: 1 0 100%;
    }

    .modifier-row .row-input {
        width: 120px;
    }

    .tabs {
        padding: 0 10px;
        gap: 4px;
    }

    .tab {
        padding: 9px 14px 11px;
        font-size: 1rem;
    }

    .tray-bar {
        justify-content: stretch;
    }

    .preset-picker {
        flex: 1;
    }

    .preset-picker select {
        flex: 1;
        min-width: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 1ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 1ms !important;
    }
}
