/**
 * The interface layer over the world canvas. `#hud` covers the viewport, so
 * it stays `pointer-events: none` and only leaf controls opt back in — never
 * put `pointer-events: auto` on a container, or map panning dies near the
 * corners. Sizes are design pixels (frames 1512x914); `--ui-scale` shrinks
 * each group as a whole.
 */

#hud {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
    --ui-scale: 1;
}

#hud.is-disabled {
    pointer-events: none;
}

/* --- Corner groups --- */

.hud-group  {
    position: absolute;
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 32px;
    pointer-events: none;
    transform: scale(var(--ui-scale));
}

.hud-group--top-left {
    top: 0;
    left: 0;
    transform-origin: top left;
}

.hud-group--top-right {
    top: 0;
    right: 0;
    align-items: flex-end;
    transform-origin: top right;
}

.hud-group--bottom-left {
    bottom: 0;
    left: 0;
    transform-origin: bottom left;
}

.hud-group--bottom-right {
    bottom: 0;
    right: 0;
    align-items: flex-end;
    transform-origin: bottom right;
}

/*
 * Scaling about bottom-center keeps `left: 50%` intact and the translate pulls
 * the bar back by half its width — centred at any scale.
 */
.hud-group--bottom-center {
    bottom: 0;
    left: 50%;
    align-items: center;
    transform-origin: bottom center;
    transform: translateX(-50%) scale(var(--ui-scale));
}

/* --- Cloud vignette around the board --- */

.hud-frame {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    pointer-events: none;
}

.hud-frame--fallback {
    background:
        radial-gradient(ellipse at center, transparent 62%, rgba(255, 248, 220, 0.18) 78%, rgba(139, 90, 43, 0.22) 100%),
        linear-gradient(to bottom, rgba(255, 255, 255, 0.08), transparent 22%, transparent 82%, rgba(60, 30, 10, 0.18));
    box-shadow: inset 0 0 80px rgba(90, 45, 10, 0.22), inset 0 0 160px rgba(255, 250, 230, 0.12);
    opacity: 0.9;
}

/* --- Wordmark --- */

.hud-logo img {
    display: block;
    max-width: 320px;
    height: auto;
}

.hud-logo--text {
    font-size: 44px;
    line-height: 1.05;
    font-weight: 700;
    color: var(--logo-ink);
    text-shadow: 0 2px 0 #fff, 0 0 12px rgba(255, 255, 255, 0.7);
    max-width: 6em;
}

/* --- Resource counters --- */

.hud-resources {
    display: flex;
    /*
     * Wrapping is not optional: a game may start the player on eight
     * resources (Age of Wisdom does), and eight pills do not fit one row.
     * The gap is wider than a plain row would need because every pill's icon
     * hangs off its left edge and must not reach the pill before it.
     */
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px 6px;
    max-width: min(1100px, 62vw);
    pointer-events: none;
}


.hud-pill {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 132px;
    height: 40px;
    padding: 0 12px 0 6px;
    border-radius: 10px;
    color: #fff;
    font-size: 18px;
    font-weight: 700;
    /*
     * Rounded display faces like "Baloo 2" (main.css) carry a tall internal
     * line-height metric — with the default `normal`, the text box runs
     * taller than the pill and the value spills past the art's bottom
     * edge. Pinning it to the font size keeps the glyph box predictable
     * regardless of which font actually loads.
     */
    line-height: 1;
    text-shadow: 0 2px 2px rgba(0, 0, 0, 0.55);
    /* Fallback wood, replaced by the sprite when it is present. */
    background: linear-gradient(var(--pill-top), var(--pill-bottom));
    border: 2px solid var(--pill-edge);
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.18), 0 12px 22px rgba(56, 29, 11, 0.24);
    transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
}

.hud-pill:hover {
    transform: translateY(-1px) scale(1.02);
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.18), inset 0 -2px 0 rgba(0, 0, 0, 0.14), 0 12px 22px rgba(56, 29, 11, 0.24);
}

.hud-pill--art {
    background: none;
    border: 0;
    box-shadow: none;
    background-size: 100% 100%;
    background-repeat: no-repeat;
}

/*
 * A bare counter: the icon and the number, no wooden plate. Fourteen of
 * them fit one row where five plated ones did; the label lives in the
 * resources window, which is a click away on the ☰ pill.
 */
.hud-pill--bare {
    min-width: 0;
    height: 40px;
    padding: 0 8px 0 0;
    gap: 2px;
    border: 0;
    background: none;
    box-shadow: none;
    text-shadow: 0 2px 3px rgba(0, 0, 0, 0.75), 0 0 6px rgba(0, 0, 0, 0.45);
}

.hud-pill--bare:hover {
    transform: translateY(-1px) scale(1.04);
    box-shadow: none;
}

.hud-pill--bare .hud-pill__icon {
    width: 40px;
    height: 38px;
    margin-left: 0;
}

.hud-pill--bare .hud-pill__label {
    display: none;
}

.hud-pill--bare .hud-pill__value {
    margin-left: 0;
    font-size: 17px;
}
/* Counter icons overhang the pill edges, so .hud-pill must not clip overflow. */
.hud-pill__icon {
    flex: none;
    width: 48px;
    height: 46px;
    object-fit: contain;
    margin-left: -14px;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
}

.hud-pill__label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    opacity: 0.9;
    font-weight: 700;
}

.hud-pill--more {
    min-width: 40px;
    justify-content: center;
    padding: 0;
    font-size: 18px;
    font-family: inherit;
    cursor: pointer;
}

.hud-pill--more:hover {
    filter: brightness(1.08);
}

.hud-pill--more:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.hud-pill__value {
    margin-left: auto;
}

/* The session clock only exists for games that authored a positive limit. */
.hud-session {
    align-self: flex-end;
    padding: 6px 14px;
    border-radius: 8px;
    background: var(--well);
    border: 2px solid var(--edge);
    color: var(--text);
    font-size: 18px;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
}


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

.hud-button {
    position: relative;
    pointer-events: auto;
    width: 92px;
    height: 92px;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: transform 0.12s ease;
}

/* 40% smaller than the other corner buttons. */
.hud-button[data-action='options'] {
    width: 55.2px;
    height: 55.2px;
}

.hud-button img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.hud-button--text {
    border-radius: 50%;
    background: linear-gradient(var(--btn-top), var(--btn-bottom));
    border: 3px solid var(--btn-edge);
    color: var(--text);
    font-family: inherit;
    font-size: 15px;
    text-transform: capitalize;
}

.hud-button:hover {
    transform: translateY(-2px) scale(1.04);
}

.hud-button:active {
    transform: translateY(0) scale(0.98);
}

.hud-button:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
}

.hud-button.is-active {
    transform: translateY(-1px) scale(1.04);
    filter: drop-shadow(0 0 10px rgba(255, 201, 73, 0.55))
        drop-shadow(0 2px 6px rgba(90, 40, 10, 0.35)) brightness(1.08);
}

.hud-button.is-active:hover {
    filter: drop-shadow(0 0 14px rgba(255, 201, 73, 0.7))
        drop-shadow(0 4px 8px rgba(90, 40, 10, 0.4)) brightness(1.12);
}

@media (prefers-reduced-motion: reduce) {
    .hud-button.is-active {
        transform: none;
        filter: drop-shadow(0 0 8px rgba(255, 201, 73, 0.45));
    }
}

.hud-button.is-muted {
    opacity: 0.65;
}

/*
 * Quest counter on the book button. The reference frame hangs it off the
 * icon's lower-left corner, clear of the art rather than on top of it, so the
 * button stays `overflow: visible` and the chip overhangs.
 */
.hud-badge {
    position: absolute;
    left: -6px;
    bottom: 6px;
    min-width: 30px;
    height: 30px;
    padding: 0 7px;
    border-radius: 15px;
    display: grid;
    place-items: center;
    background: linear-gradient(var(--cta-top), var(--cta-bottom));
    border: 2px solid var(--cta-edge);
    box-shadow: inset 0 2px 0 var(--inner-light);
    color: var(--text-strong);
    font-size: 17px;
    font-weight: 700;
    line-height: 1;
    text-shadow: 0 2px 2px rgba(0, 0, 0, 0.45);
    pointer-events: none;
}

/* --- Planner banner (bottom-left, above the corner stack) --- */

/*
 * The medallion overhangs the plaque's left edge in the reference art, so the
 * banner is inset by half the icon and the row must not clip its overflow.
 */
.hud-planner {
    pointer-events: auto;
    display: flex;
    align-items: center;
    margin-bottom: 6px;
}

.hud-planner__icon {
    width: 72px;
    height: 72px;
    object-fit: contain;
    flex: none;
    z-index: 1;
    filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.35));
}

.hud-planner__banner {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 168px;
    min-height: 46px;
    margin-left: -18px;
    padding: 6px 16px 6px 26px;
    line-height: 1.15;
    background: linear-gradient(var(--plaque-top), var(--plaque-bottom));
    border: 2px solid var(--plaque-edge);
    border-radius: 8px;
}

/* The sprite carries its own border and torn edge. */
.hud-planner__banner--art {
    background: none;
    border: 0;
    border-radius: 0;
    background-size: 100% 100%;
    background-repeat: no-repeat;
}

.hud-planner__title {
    color: var(--era);
    font-size: 19px;
    font-weight: 700;
    text-shadow: 0 2px 2px rgba(0, 0, 0, 0.45);
}

.hud-planner__subtitle {
    display: flex;
    gap: 5px;
    color: #fff;
    font-size: 14px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.hud-planner__count {
    color: var(--era);
    font-weight: 700;
}

/* The art spells the tally out as one lowercase phrase after the count. */
.hud-planner__label {
    text-transform: lowercase;
}

/* --- Level / era bar --- */

.hud-level {
    pointer-events: auto;
    display: flex;
    align-items: stretch;
    gap: 4px;
    cursor: pointer;}

.hud-level:hover {
    filter: brightness(1.06);
}

.hud-level:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
}

/*
 * No border here: the era thumbnails ship with their own wooden frame drawn
 * into the art, so a CSS border added a second, near-black outline around a
 * frame that was already finished — the dark line that made the pair look
 * like a focus ring. `contain` for the same reason: `cover` cropped that
 * frame's own corners to fill the box.
 */
.hud-level__icon {
    width: 56px;
    height: 56px;
    object-fit: contain;
    flex: none;
}
.hud-level__text {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 8px 28px;
    min-width: 190px;
    background: linear-gradient(var(--plaque-top), var(--plaque-bottom));
     /* No border: flat translucent slab, no outline. */
    box-shadow: inset 0 2px 0 var(--inner-light-soft);
    line-height: 1.2;
    overflow: hidden;
}

.hud-level__text::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 5px;
    width: var(--level-progress, 0%);
    background: #2fb8e0;
    transition: width 0.4s ease;
    pointer-events: none;
}

.hud-level__text.is-binary::before {
    width: 100%;
    opacity: 0.6;
}

@media (prefers-reduced-motion: reduce) {
    .hud-level__text::before {
        transition: none;
    }
}

.hud-level__value {
    color: #fff;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-shadow: 0 2px 2px rgba(0, 0, 0, 0.5);
}

.hud-level__era {
    color: var(--era);
    font-size: 15px;
 }

.hud-level__next {
    font-size: 12px;
    color: var(--text-dim);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Home sits inline with the resource pills, not in a corner stack. */
.hud-button--inline {
    width: 48px;
    height: 48px;
}

/* --- Debug readout --- */

/* Top centre: the bottom edge now belongs to the level bar.
 * Hidden by default — it is a development readout, not game chrome (the
 * reference frames show nothing there). Append #debug=1 to the URL hash to
 * restore it; its textContent keeps updating either way, so tooling that
 * reads the cell under the cursor is unaffected. */
#hudDebug {
    display: none;
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.6);
    color: var(--debug-ink);
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 13px;
    pointer-events: none;
}

#gameContainer[data-debug='1'] #hudDebug {
    display: block;
}

/*
 * A counter that has just gone up. Short and small on purpose: this fires on
 * every collection, so anything showier would wear out within a minute.
 */
@keyframes pill-gain {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.07); filter: brightness(1.18); }
    100% { transform: scale(1); }
}

.hud-pill.is-gaining {
    animation: pill-gain 420ms ease-out;
}

@media (prefers-reduced-motion: reduce) {
    .hud-pill.is-gaining {
        animation: none;
    }
}