/*
  Market Quest — "the night market after the lanterns come on".
  Deep indigo dusk, warm lantern gold, and striped stall awnings.
  Tablet-first: nothing smaller than a 44px touch target, no hover-only affordances.
*/

:root {
    --dusk-deep: #0F0A22;
    --dusk: #191233;
    --stall: #241A47;
    --stall-raised: #2E2257;
    --cream: #FFF3DC;
    --cream-dim: #C8BDE0;
    --lantern: #FFC24B;
    --mint: #4FD8B6;
    --coral: #FF6F7D;
    --violet: #7C5CFF;

    --radius: 18px;
    --radius-sm: 12px;
    --tap: 48px;

    --display: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
    --body: "Nunito", "Segoe UI", system-ui, sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    min-height: 100dvh;
    background:
        radial-gradient(1200px 700px at 50% -10%, #2A1E52 0%, transparent 60%),
        radial-gradient(800px 500px at 90% 110%, #3A1F4E 0%, transparent 65%),
        var(--dusk-deep);
    color: var(--cream);
    font-family: var(--body);
    font-size: 17px;
    line-height: 1.45;
    -webkit-text-size-adjust: 100%;
}

.shell {
    max-width: 900px;
    margin: 0 auto;
    padding: 16px 16px 96px;
}

h1,
h2,
h3 {
    font-family: var(--display);
    font-weight: 600;
    letter-spacing: -0.01em;
    margin: 0 0 8px;
}

h1 {
    font-size: 2rem;
}

h2 {
    font-size: 1.35rem;
}

p {
    margin: 0 0 12px;
}

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

:focus-visible {
    outline: 3px solid var(--lantern);
    outline-offset: 3px;
}

/* ---------- buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--tap);
    padding: 12px 22px;
    border: none;
    border-radius: 999px;
    font-family: var(--display);
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--dusk-deep);
    background: var(--lantern);
    cursor: pointer;
    text-decoration: none;
    transition: transform 120ms ease, filter 120ms ease;
}

.btn:hover:not(:disabled) {
    filter: brightness(1.06);
}

.btn:active:not(:disabled) {
    transform: translateY(2px);
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn--ghost {
    background: transparent;
    color: var(--cream);
    box-shadow: inset 0 0 0 2px rgba(255, 243, 220, 0.28);
}

.btn--violet {
    background: var(--violet);
    color: #FFF;
}

.btn--danger {
    background: var(--coral);
    color: var(--dusk-deep);
}

.btn--block {
    width: 100%;
}

.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

/* ---------- title screen ---------- */

.title {
    text-align: center;
    padding: 4vh 0 0;
}

/* The splash artwork includes the lettering, so the banner replaces the old emoji mark and
   text heading rather than sitting alongside them. */
.title__banner {
    margin: 0 0 20px;
}

.title__banner img {
    display: block;
    width: 100%;
    max-width: 760px;
    height: auto;
    margin: 0 auto;
    border-radius: var(--radius);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

.title__tagline {
    color: var(--cream-dim);
    max-width: 30ch;
    margin: 0 auto 32px;
}

.title .btn-row {
    justify-content: center;
}

/* ---------- status bar ---------- */

.status {
    position: sticky;
    top: 0;
    z-index: 5;
    background: linear-gradient(180deg, var(--dusk) 78%, rgba(25, 18, 51, 0.86) 100%);
    border-radius: 0 0 var(--radius) var(--radius);
    padding: 10px 14px 12px;
    margin: -16px -16px 16px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.status__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.status__place {
    font-family: var(--display);
    font-size: 1.15rem;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.status__place span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.status__cash {
    font-family: var(--display);
    font-size: 1.3rem;
    color: var(--lantern);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.status__grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 10px;
}

.stat {
    background: rgba(255, 243, 220, 0.07);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    text-align: center;
}

.stat__label {
    display: block;
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--cream-dim);
}

.stat__value {
    display: block;
    font-family: var(--display);
    font-size: 1rem;
    font-variant-numeric: tabular-nums;
}

.stat__value--debt {
    color: var(--coral);
}

.stat__value--good {
    color: var(--mint);
}

/* The day track is the one piece of ambient decoration: lanterns burning down. */
.daytrack {
    height: 6px;
    border-radius: 999px;
    background: rgba(255, 243, 220, 0.12);
    margin-top: 10px;
    overflow: hidden;
}

.daytrack__fill {
    height: 100%;
    background: linear-gradient(90deg, var(--lantern), var(--coral));
    transition: width 240ms ease;
}

.section-title {
    font-family: var(--display);
    font-size: 0.95rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--cream-dim);
    margin: 4px 2px 10px;
}

/* ---------- market ---------- */

.market {
    display: grid;
    gap: 12px;
}

@media (min-width: 700px) {
    .market {
        grid-template-columns: 1fr 1fr;
    }
}

.stall {
    position: relative;
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    min-height: 86px;
    padding: 18px 14px 14px;
    border: none;
    border-radius: var(--radius);
    background: var(--stall);
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    overflow: hidden;
    transition: transform 120ms ease, background 120ms ease;
}

.stall:hover {
    background: var(--stall-raised);
}

.stall:active {
    transform: translateY(2px);
}

/* Signature: every stall wears its own striped awning. */
.stall__awning {
    position: absolute;
    inset: 0 0 auto 0;
    height: 10px;
    background-image: repeating-linear-gradient(
        90deg,
        var(--awning) 0 14px,
        rgba(255, 243, 220, 0.85) 14px 28px
    );
}

.stall__glyph {
    font-size: 2rem;
    line-height: 1;
    flex: 0 0 auto;
}

.stall__body {
    flex: 1 1 auto;
    min-width: 0;
}

.stall__name {
    font-family: var(--display);
    font-size: 1.1rem;
    display: block;
}

.stall__owned {
    font-size: 0.85rem;
    color: var(--cream-dim);
}

.stall__tag {
    flex: 0 0 auto;
    position: relative;
    background: var(--cream);
    color: var(--dusk-deep);
    font-family: var(--display);
    font-size: 1.25rem;
    font-variant-numeric: tabular-nums;
    padding: 8px 14px 8px 22px;
    border-radius: 6px 999px 999px 6px;
}

/* the punched hole in the price tag */
.stall__tag::before {
    content: "";
    position: absolute;
    left: 8px;
    top: 50%;
    width: 7px;
    height: 7px;
    margin-top: -3.5px;
    border-radius: 50%;
    background: var(--stall);
}

.stall__tag--up {
    background: var(--mint);
}

.stall__tag--down {
    background: var(--coral);
}

.stall__flag {
    position: absolute;
    top: 14px;
    right: 12px;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--cream-dim);
}

/* ---------- action bar ---------- */

.actionbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 6;
    display: flex;
    gap: 10px;
    justify-content: center;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, rgba(15, 10, 34, 0) 0%, var(--dusk-deep) 40%);
}

.actionbar .btn {
    flex: 1 1 0;
    max-width: 240px;
}

/* ---------- cards and dialogs ---------- */

.backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 16px;
    background: rgba(9, 6, 20, 0.72);
}

@media (min-width: 700px) {
    .backdrop {
        align-items: center;
    }
}

.sheet {
    width: 100%;
    max-width: 560px;
    max-height: 88dvh;
    overflow-y: auto;
    background: var(--stall);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
    animation: rise 180ms ease-out;
}

@keyframes rise {
    from {
        transform: translateY(14px);
        opacity: 0;
    }
}

.sheet__glyph {
    font-size: 2.6rem;
    line-height: 1;
    display: block;
    margin-bottom: 6px;
}

.sheet__meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255, 243, 220, 0.12);
    font-variant-numeric: tabular-nums;
}

.sheet__meta:last-of-type {
    border-bottom: none;
    margin-bottom: 12px;
}

.sheet__meta dt {
    color: var(--cream-dim);
}

.sheet__meta dd {
    margin: 0;
    font-family: var(--display);
}

.sheet--good {
    box-shadow: 0 0 0 3px var(--mint), 0 24px 60px rgba(0, 0, 0, 0.55);
}

.sheet--bad {
    box-shadow: 0 0 0 3px var(--coral), 0 24px 60px rgba(0, 0, 0, 0.55);
}

.story {
    margin: 0 0 14px;
    font-size: 1.05rem;
}

.story--effect {
    color: var(--lantern);
    font-weight: 700;
}

/* ---------- forms ---------- */

.field {
    display: block;
    margin-bottom: 14px;
}

.field__label {
    display: block;
    font-size: 0.82rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--cream-dim);
    margin-bottom: 6px;
}

.input {
    width: 100%;
    min-height: var(--tap);
    padding: 10px 14px;
    border: 2px solid rgba(255, 243, 220, 0.22);
    border-radius: var(--radius-sm);
    background: rgba(9, 6, 20, 0.5);
    color: var(--cream);
    font-family: var(--display);
    font-size: 1.35rem;
    font-variant-numeric: tabular-nums;
}

.input:focus {
    border-color: var(--lantern);
    outline: none;
}

.choicegroup {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.chip {
    min-height: var(--tap);
    padding: 10px 20px;
    border: 2px solid rgba(255, 243, 220, 0.22);
    border-radius: 999px;
    background: transparent;
    color: var(--cream);
    font-family: var(--display);
    font-size: 1rem;
    cursor: pointer;
}

.chip[aria-pressed="true"] {
    background: var(--lantern);
    border-color: var(--lantern);
    color: var(--dusk-deep);
}

.alert {
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    margin-bottom: 12px;
    background: rgba(255, 111, 125, 0.16);
    box-shadow: inset 0 0 0 2px var(--coral);
}

.alert--ok {
    background: rgba(79, 216, 182, 0.14);
    box-shadow: inset 0 0 0 2px var(--mint);
}

/* ---------- news banner ---------- */

.news {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    background: rgba(255, 194, 75, 0.14);
    box-shadow: inset 0 0 0 2px rgba(255, 194, 75, 0.5);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 14px;
}

/* ---------- results and leaderboard ---------- */

.results__total {
    font-family: var(--display);
    font-size: clamp(2.6rem, 12vw, 4rem);
    line-height: 1;
    color: var(--lantern);
    font-variant-numeric: tabular-nums;
}

.results__banner {
    display: inline-block;
    background: var(--mint);
    color: var(--dusk-deep);
    font-family: var(--display);
    font-size: 1.2rem;
    padding: 8px 18px;
    border-radius: 999px;
    margin: 12px 0;
}

.panel {
    background: var(--stall);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}

.ledger {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

.ledger th,
.ledger td {
    text-align: left;
    padding: 10px 8px;
    border-bottom: 1px solid rgba(255, 243, 220, 0.12);
}

.ledger th {
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--cream-dim);
    font-weight: 700;
}

.ledger td:last-child,
.ledger th:last-child {
    text-align: right;
}

.ledger tr[data-you="true"] td {
    color: var(--lantern);
    font-weight: 800;
}

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

.empty {
    color: var(--cream-dim);
    padding: 24px 0;
    text-align: center;
}

/* ---------- developer panel ---------- */

.dev {
    margin-top: 24px;
    border-radius: var(--radius-sm);
    background: rgba(255, 243, 220, 0.06);
    box-shadow: inset 0 0 0 2px rgba(124, 92, 255, 0.6);
    padding: 12px 14px;
    font-family: ui-monospace, "Cascadia Mono", Menlo, monospace;
    font-size: 0.85rem;
}

.dev summary {
    cursor: pointer;
    font-family: var(--display);
    font-size: 1rem;
}

.dev .btn,
.dev .input {
    font-size: 0.9rem;
    min-height: 40px;
}

.dev__log {
    max-height: 220px;
    overflow: auto;
    white-space: pre-wrap;
    background: rgba(9, 6, 20, 0.6);
    border-radius: 8px;
    padding: 10px;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        transition-duration: 0.001ms !important;
    }
}
