:root {
    --plank: #24140c;
    --oak: #5a3820;
    --brass: #b08a32;
    --chalk: #efe4cc;
    --slate: #243040;
    --slate-edge: #1a222c;
    --wax: #7a1c18;
    --ink: #120a06;
    --lamp: #e4b45c;
    --moss: #4a6a38;
    /* Fixed-width digits for anything numeric; sibling family of Source Sans 3. */
    --nums: "Source Code Pro", ui-monospace, monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
    margin: 0;
    min-height: 100%;
    background:
        radial-gradient(ellipse at 20% 0%, rgba(228, 180, 92, 0.12), transparent 42%),
        repeating-linear-gradient(90deg, #2a160e 0 14px, #23120b 14px 28px);
    color: var(--chalk);
    font-family: "Source Sans 3", sans-serif;
}

.lamp {
    position: fixed;
    inset: 0 auto auto 12%;
    width: 220px;
    height: 180px;
    background: radial-gradient(circle, rgba(228, 180, 92, 0.28), transparent 70%);
    pointer-events: none;
    z-index: 0;
}

.sign {
    position: relative;
    z-index: 1;
    margin: 1.25rem auto 0;
    max-width: 980px;
    background: linear-gradient(#6a4326, #4a2e18);
    border: 4px solid #1a0e08;
    box-shadow: 0 10px 0 #140a06, inset 0 0 0 2px var(--brass);
    text-align: center;
    padding: 1rem 1.25rem 0.85rem;
}

.rings {
    display: flex;
    justify-content: space-around;
    margin-top: -1.6rem;
}
.rings span {
    width: 14px;
    height: 14px;
    border: 3px solid #8a8a8a;
    border-radius: 50%;
    background: #2a2a2a;
    display: block;
}

.sign h1 {
    font-family: "IM Fell DW Pica", serif;
    font-size: clamp(2rem, 5vw, 3.1rem);
    font-weight: 400;
    margin: 0.35rem 0 0;
    color: #f3e2b8;
    letter-spacing: 0.04em;
}

.tag, .hint, .chalk-intro {
    margin: 0.2rem 0 0;
    color: #d8c49a;
    font-size: 0.95rem;
}

.sign-links {
    display: flex;
    gap: 1rem;
    justify-content: center;
    align-items: center;
    margin-top: 0.6rem;
    font-size: 0.92rem;
}

.sign-links a, .sign-links button {
    color: var(--lamp);
    background: none;
    border: 0;
    cursor: pointer;
    font: inherit;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.ledger, .counter > section, .proclamation {
    position: relative;
    z-index: 1;
}

.ledger {
    max-width: 420px;
    margin: 2rem auto;
    background: #d8c7a4;
    color: var(--ink);
    padding: 1.25rem 1.4rem;
    box-shadow: 6px 8px 0 #140a06;
    transform: rotate(-0.4deg);
}

.ledger h2, .holes h2, .sack h2 {
    font-family: "IM Fell DW Pica", serif;
    margin: 0 0 0.4rem;
}

.ledger form, #deal-form {
    display: grid;
    gap: 0.65rem;
}

label { display: grid; gap: 0.2rem; font-weight: 600; }
input {
    font: inherit;
    padding: 0.4rem 0.5rem;
    border: 1px solid #6a5434;
    background: #f4ead4;
}

button[type="submit"], #collect, .tab, .deal-btn {
    font: inherit;
    cursor: pointer;
    background: var(--wax);
    color: #f7e7d0;
    border: 2px solid #3a0c0a;
    padding: 0.45rem 0.8rem;
}

.err { color: #8b1e1e; margin: 0; }

.boards {
    max-width: 1200px;
    margin: 1.25rem auto 0.5rem;
    display: grid;
    grid-template-columns: minmax(300px, 1fr) minmax(300px, 1.1fr);
    gap: 0.85rem;
    padding: 0 0.75rem;
    position: relative;
    z-index: 1;
}

.board {
    background: #ead9b0;
    color: var(--ink);
    box-shadow: 4px 5px 0 #140a06;
}

.board h2 {
    font-family: "IM Fell DW Pica", serif;
    font-weight: 400;
    font-size: 1.25rem;
    margin: 0 0 0.45rem;
}

.board-foot {
    margin: 0.4rem 0 0;
    font-size: 0.82rem;
    color: #6a5434;
}

.proclamation {
    padding: 0.8rem 1.1rem 0.7rem 4.4rem;
    position: relative;
}

.proclamation::before {
    content: "";
    position: absolute;
    left: 0.85rem;
    top: 1rem;
    width: 2.4rem;
    height: 2.4rem;
    background: radial-gradient(circle at 30% 30%, #c43a32, var(--wax) 62%, #4a0e0c);
    border-radius: 50%;
    box-shadow: 0 0 0 3px #f0d9a0 inset;
}

.news {
    padding: 0.8rem 1.1rem 0.7rem;
}

.news ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.news-item {
    display: flex;
    align-items: baseline;
    gap: 0.45rem;
    padding: 0.24rem 0;
    border-bottom: 1px dotted #b09a6a;
    font-size: 0.92rem;
}

.news-item:last-child { border-bottom: 0; }

.news-head { flex: 1; }

.news-eta {
    font-family: var(--nums);
    font-size: 0.72rem;
    color: #6a5434;
    white-space: nowrap;
}

.news-past { opacity: 0.55; }

.proc-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    padding: 0.2rem 0;
}

.proc-label {
    font-weight: 700;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.1rem 0.45rem;
    border-radius: 2px;
    white-space: nowrap;
}

.proc-label.pays { background: var(--moss); color: #f0ead4; }
.proc-label.glut { background: #8a94a2; color: #14181e; }

.chip {
    background: #f6ecd4;
    border: 1px solid #b09a6a;
    padding: 0.1rem 0.5rem;
    border-radius: 2px;
    font-size: 0.92rem;
    font-weight: 600;
}

.chip-none { font-weight: 400; font-style: italic; border-style: dashed; }

.chg {
    font-family: var(--nums);
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}

/* CSS-drawn triangles instead of unicode ▲/▼ — consistent size and baseline. */
.chg-arrow {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 0.28em solid transparent;
    border-right: 0.28em solid transparent;
    margin-right: 0.2em;
}

.chg.up .chg-arrow { border-bottom: 0.46em solid currentColor; }
.chg.down .chg-arrow { border-top: 0.46em solid currentColor; }

.chg.up { color: #8fd06a; }
.chg.down { color: #e88a70; }

.board .chg.up, dialog .chg.up { color: #3a7a1e; }
.board .chg.down, dialog .chg.down { color: #a83a20; }

.movers {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.45rem;
    padding: 0.35rem 0.5rem;
    margin: 0.2rem 0 0.4rem;
    background: rgba(228, 180, 92, 0.08);
    border: 1px dashed rgba(228, 180, 92, 0.35);
    font-size: 0.86rem;
}

.movers-label {
    font-weight: 700;
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--lamp);
}

.mover { color: var(--chalk); white-space: nowrap; }

.counter {
    max-width: 1200px;
    margin: 0 auto 2.5rem;
    display: grid;
    grid-template-columns: minmax(180px, 0.9fr) minmax(280px, 1.4fr) minmax(180px, 0.85fr);
    gap: 0.85rem;
    padding: 0 0.75rem;
}

.sack, .holes {
    background: #3a2416;
    border: 3px solid #140a06;
    padding: 0.75rem;
    min-height: 24rem;
}

.col-left {
    display: grid;
    gap: 0.85rem;
    align-content: start;
}

.collect-panel { min-height: 0; }

/* Jump above the bank when something is waiting to be collected. */
.collect-panel.has-items {
    order: -1;
    border-color: var(--brass);
    box-shadow: 0 0 0 1px rgba(176, 138, 50, 0.4);
}

.collect-actions {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.btn-quiet {
    font: inherit;
    cursor: pointer;
    background: transparent;
    color: #d8c49a;
    border: 1px solid #6a5434;
    padding: 0.45rem 0.8rem;
}

.btn-quiet:hover { outline: 1px solid var(--lamp); }

.bank-tools { margin: 0.5rem 0 0.2rem; display: grid; gap: 0.35rem; }

.bank-tools input[type="search"] {
    width: 100%;
    background: #2a1810;
    border: 1px solid #6a5434;
    color: var(--chalk);
    padding: 0.4rem 0.5rem;
}

.bank-tools input[type="search"]::placeholder { color: #9a8664; }

.bank-opts {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: #d8c49a;
}

.bank-opts .opt { display: flex; align-items: center; gap: 0.3rem; font-weight: 400; }

.bank-opts select {
    font: inherit;
    font-size: 0.8rem;
    background: #2a1810;
    color: var(--chalk);
    border: 1px solid #6a5434;
    padding: 0.15rem 0.3rem;
}

.slate .bank-tools input[type="search"],
.slate .bank-opts select {
    background: #1c2630;
    border-color: #6a7a88;
    color: var(--chalk);
}

.slate .bank-tools input[type="search"]::placeholder { color: #8a9aaa; }
.slate .bank-opts { color: #c8d0d8; }

.cat {
    margin: 0.55rem 0 0.1rem;
    font-family: "IM Fell DW Pica", serif;
    font-weight: 400;
    font-size: 0.95rem;
    color: var(--lamp);
    border-bottom: 1px dashed rgba(228, 180, 92, 0.35);
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.cat small { font-family: var(--nums); font-size: 0.7rem; color: #b8a888; }

.item-name { min-width: 0; }

.item-qty, .item-unit, .item-total {
    font-family: var(--nums);
    text-align: right;
    white-space: nowrap;
}

.item-qty { color: #d8c49a; font-size: 0.82rem; }

.item-unit {
    color: var(--lamp);
    font-weight: 600;
    font-size: 0.8rem;
}

.item-total {
    color: #9a8664;
    font-size: 0.74rem;
}

.trade-row { grid-template-columns: auto 1fr auto; }

.trade-when { color: #9aa8b8; font-family: var(--nums); font-size: 0.74rem; white-space: nowrap; }

.trade-row small { color: #9aa8b8; }

.slate {
    background: var(--slate);
    border: 10px solid #3a2a1c;
    box-shadow: inset 0 0 0 2px #6a7a88, 0 8px 0 #140a06;
    padding: 0.75rem 0.85rem 1rem;
    min-height: 24rem;
}

.slate-tabs { display: flex; gap: 0.4rem; margin-bottom: 0.6rem; }
.tab { background: #1c2630; color: var(--chalk); border-color: #0e141a; }
.tab.on { background: var(--brass); color: var(--ink); border-color: #6a5018; }

.chalk-intro {
    font-style: italic;
    color: var(--chalk);
}

.grid {
    display: grid;
    gap: 0.3rem;
    margin-top: 0.5rem;
}

/* Fixed columns (name | qty | unit price | total) so the numbers form clean,
   scannable columns across rows instead of packing against the right edge. */
.item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 2rem 4rem 3.5rem;
    column-gap: 0.4rem;
    align-items: baseline;
    text-align: left;
    padding: 0.25rem 0.35rem;
    background: #2a1810;
    border: 1px solid #140a06;
    cursor: pointer;
    color: #f0d9a0;
    font-size: 0.92rem;
}

.item:hover, .item:focus { outline: 1px solid var(--lamp); }

.yard-group { margin: 0.7rem 0 0.3rem; }
.yard-group h3 {
    font-family: "IM Fell DW Pica", serif;
    font-weight: 400;
    letter-spacing: 0.03em;
    margin: 0;
    font-size: 1.1rem;
    border-bottom: 1px dashed #8aa0b4;
}

.row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 0.45rem;
    align-items: center;
    font-size: 0.92rem;
    padding: 0.24rem 0;
    border-bottom: 1px dotted rgba(239, 228, 204, 0.15);
}

/* Warehouse rows: fixed spark + button columns so names, sparklines, and
   buttons align vertically down the list; stock counts right-align against
   the sparkline column. */
.yard-row {
    grid-template-columns: minmax(0, 1fr) 88px 5.4rem 5.4rem;
    column-gap: 0.5rem;
}

.yard-row button { width: 100%; padding-inline: 0.3rem; }

.btn-price { font-family: var(--nums); font-size: 0.74rem; }

.row-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.1rem 0.6rem;
    min-width: 0;
}

.row-head .row-name { min-width: 0; }

.row-stock {
    margin-left: auto;
    text-align: right;
    color: #9aa8b8;
    font-family: var(--nums);
    font-size: 0.72rem;
    white-space: nowrap;
}

.spark {
    width: 88px;
    height: 24px;
    overflow: visible;
    display: block;
}

.spark-fill { fill: rgba(196, 180, 138, 0.12); }
.spark-line {
    fill: none;
    stroke: #c4b48a;
    stroke-width: 1.35;
    stroke-linejoin: round;
    stroke-linecap: round;
}
.spark-up .spark-fill { fill: rgba(143, 208, 106, 0.16); }
.spark-up .spark-line { stroke: #8fd06a; }
.spark-down .spark-fill { fill: rgba(232, 138, 112, 0.16); }
.spark-down .spark-line { stroke: #e88a70; }

.spark-bead {
    fill: var(--lamp);
    transform-box: fill-box;
    transform-origin: center;
    animation: spark-breathe 2.8s ease-in-out infinite;
}

.spark-virgin .spark-line {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    animation: spark-draw 0.85s ease forwards;
}

.spark-ticked .spark-bead {
    animation: spark-flash 0.75s ease-out;
}

.spark-ticked .spark-line {
    filter: drop-shadow(0 0 3px currentColor);
}

@keyframes spark-draw {
    to { stroke-dashoffset: 0; }
}
@keyframes spark-breathe {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}
@keyframes spark-flash {
    0% { transform: scale(1); }
    35% { transform: scale(2.15); }
    100% { transform: scale(1); }
}

.book-row { grid-template-columns: 1fr auto auto; }

.row button {
    font-family: "Source Sans 3", sans-serif;
    font-size: 0.8rem;
    padding: 0.22rem 0.55rem;
    cursor: pointer;
    white-space: nowrap;
}

.btn-sell {
    background: #26382a;
    color: #c2e6ae;
    border: 1px solid #4a6a38;
}

.btn-buy {
    background: #3c2a20;
    color: #f0cfa8;
    border: 1px solid #8a5c2a;
}

.btn-sell:hover, .btn-buy:hover { outline: 1px solid var(--lamp); }

.badge {
    font-family: "Source Sans 3", sans-serif;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.05rem 0.3rem;
    border-radius: 2px;
    vertical-align: 1px;
    white-space: nowrap;
}

.badge-wanted { background: var(--lamp); color: var(--ink); }
.badge-glut { background: #8a94a2; color: #14181e; }
.badge-shortage { background: #a83a20; color: #f7e7d0; }
.badge-surplus { background: #4a6a88; color: #eef4f8; }

.rail-sub { margin-top: 1.2rem; padding-top: 0.9rem; border-top: 1px dashed rgba(239, 228, 204, 0.25); }

.contract {
    background: #2a1810;
    border: 1px solid #140a06;
    padding: 0.5rem 0.6rem;
    margin-top: 0.45rem;
    font-size: 0.88rem;
}

.c-head {
    font-family: "IM Fell DW Pica", serif;
    font-size: 1rem;
    color: #f0d9a0;
}

.c-body { margin: 0.15rem 0 0.3rem; color: var(--chalk); }

.c-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.78rem;
    color: #b8a888;
}

.c-foot button {
    font: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    background: var(--moss);
    color: #f0ead4;
    border: 1px solid #2a4218;
    padding: 0.2rem 0.6rem;
}

.c-foot button:hover { outline: 1px solid var(--lamp); }

#deal-chart {
    width: 100%;
    height: 80px;
    background: #f4ead4;
    border: 1px solid #b09a6a;
}

.chart-label {
    font-family: "Source Sans 3", sans-serif;
    font-size: 9px;
    fill: #8a7444;
}

.ticket {
    margin-top: 0.8rem;
    background: #efe4cc;
    color: var(--ink);
    padding: 0.6rem;
    font-size: 0.9rem;
}

.lb-row {
    display: flex;
    align-items: baseline;
    gap: 0.45rem;
    margin-top: 0.45rem;
    font-size: 0.92rem;
}

.lb-rank {
    font-family: "IM Fell DW Pica", serif;
    color: var(--brass);
    min-width: 1rem;
    text-align: right;
}

.lb-name { flex: 1; color: #f0d9a0; font-weight: 600; }

.lb-worth { color: var(--chalk); font-weight: 600; font-family: var(--nums); font-size: 0.84rem; }

.lb-sub {
    margin-left: 1.45rem;
    font-family: var(--nums);
    font-size: 0.7rem;
    color: #b8a888;
}

.pit-search { margin-bottom: 0.6rem; }
.pit-search input { width: 100%; }

dialog {
    border: 4px solid #140a06;
    background: #d8c7a4;
    color: var(--ink);
    padding: 1rem;
    box-shadow: 8px 10px 0 #140a06;
}

dialog::backdrop { background: rgba(10, 6, 4, 0.65); }

/* Confirm is the loud, labeled action; Back is quiet. Confirm stays first in
   the DOM so Enter submits it; row-reverse puts it visually on the right. */
#deal-form menu {
    display: flex;
    flex-direction: row-reverse;
    justify-content: flex-start;
    gap: 0.6rem;
    margin: 0.4rem 0 0;
    padding: 0;
}

#deal-go {
    background: var(--moss);
    border: 2px solid #2a4218;
    color: #f0ead4;
    font-weight: 700;
    padding: 0.55rem 1.1rem;
}

#deal-go:hover { outline: 2px solid var(--lamp); }

.btn-back {
    background: transparent !important;
    color: #6a5434 !important;
    border: 1px solid #b09a6a !important;
    padding: 0.55rem 0.9rem;
}

.btn-back:hover { outline: 1px solid #6a5434; }

.preview { font-weight: 600; min-height: 2.4rem; }

.deal-head {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.2rem;
}

.deal-head h3 { margin: 0; font-family: "IM Fell DW Pica", serif; font-weight: 400; font-size: 1.3rem; }

/* Authentic 32px cache-rendered item icon, integer-scaled to stay crisp,
   on a dark inventory-style slot. */
.deal-icon {
    box-sizing: content-box;
    width: 64px;
    height: 64px;
    image-rendering: pixelated;
    padding: 5px;
    background: #3a2416;
    border: 1px solid #140a06;
    box-shadow: inset 0 0 0 1px #6a4326;
}

@media (max-width: 860px) {
    .counter { grid-template-columns: 1fr; }
    .boards { grid-template-columns: 1fr; }
    .sign { margin: 2rem 0.75rem 0; }
}

/* Too narrow for four warehouse columns: drop the sparkline, keep the
   aligned buttons. */
@media (max-width: 560px) {
    .yard-row { grid-template-columns: minmax(0, 1fr) 5.7rem 5.7rem; }
    .yard-row .spark { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .lamp { display: none; }
    .spark-bead, .spark-virgin .spark-line, .spark-ticked .spark-bead {
        animation: none;
    }
    .spark-ticked .spark-line { filter: none; }
}
