.top-hud {
    --hud-ink: #f7f3df;
    --hud-muted: #b9d3e0;
    --hud-line: #3d6276;
    position: fixed;
    inset: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) auto max(10px, env(safe-area-inset-left));
    z-index: 50;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 12px 20px;
    width: min(calc(100% - 20px), 1176px);
    margin-inline: auto;
    padding: 9px 12px 9px 16px;
    border: 1px solid var(--hud-line);
    border-radius: 14px;
    background: #11283b;
    box-shadow: 0 3px 0 #091a2a;
    color: var(--hud-ink);
    line-height: 1.2;
}

.top-hud [hidden] { display: none; }

#hud-island-name {
    margin: 0 0 4px;
    color: var(--hud-ink);
    font-size: clamp(17px, 2vw, 23px);
    font-weight: 900;
    letter-spacing: -0.02em;
    overflow-wrap: anywhere;
}

.hud-location-meta {
    display: flex;
    align-items: baseline;
    gap: 5px;
    color: var(--hud-muted);
    font-size: 12px;
    font-weight: 650;
}

#hud-player-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#hud-progress {
    flex-shrink: 0;
    color: #f8e4a7;
}

.hud-stats,
.hud-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hud-stats { gap: 12px; }

.hud-xp-box {
    display: grid;
    gap: 3px;
    width: clamp(124px, 13vw, 184px);
}

.hud-rank-label,
.hud-coins-count > span {
    color: var(--hud-muted);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.hud-rank-label { color: #a7e6f3; }

.hud-xp-numbers {
    display: flex;
    align-items: baseline;
    gap: 3px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

#hud-xp-text,
#hud-coins-value {
    font-size: clamp(20px, 2.2vw, 26px);
    font-weight: 900;
    line-height: 1;
}

.hud-xp-unit,
.hud-xp-target {
    color: var(--hud-muted);
    font-size: 11px;
    font-weight: 700;
}

.hud-xp-target { margin-inline-start: auto; }

.hud-xp-track {
    height: 7px;
    overflow: hidden;
    border: 1px solid #4a6d7f;
    border-radius: 6px;
    background: #091c2c;
}

.hud-xp-fill {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: #5fd4d8;
    box-shadow: inset 0 1px 0 #c0f1eb;
    transition: width 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.hud-coins {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 46px;
    min-width: 100px;
    padding: 4px 8px;
    border-radius: 10px;
    background: #2e3336;
    color: #ffe097;
    font-variant-numeric: tabular-nums;
}

.hud-coin-icon {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
}

.hud-coins-count { display: grid; gap: 2px; }
.hud-coins-count > span { color: #eace9b; }

.hud-actions {
    padding-inline-start: 13px;
    border-inline-start: 1px solid var(--hud-line);
}

.hud-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    min-width: 44px;
    padding: 4px 10px;
    border: 1px solid #507488;
    border-radius: 8px;
    background: #203f52;
    color: var(--hud-ink);
    font: inherit;
    font-size: 13px;
    font-weight: 800;
    text-align: center;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}

.hud-btn svg {
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.hud-btn-voyage {
    color: #2a1d0a;
    background: #ffd16d;
    border-color: #e3a844;
}

@media (hover: hover) {
    .hud-btn:hover { background: #315871; border-color: #8eb5c8; }
    .hud-btn-voyage:hover { background: #ffe19b; border-color: #f2bc61; }
}

.hud-btn:active { transform: translateY(1px); background: #152f42; }
.hud-btn-voyage:active { background: #f1ba54; }

.hud-btn:focus-visible {
    outline: 2px solid #ffe197;
    outline-offset: 2px;
}

.hud-xp-box.is-bumped #hud-xp-text { animation: hud-xp-gain 0.42s ease-out; }
.hud-coins.is-bumped .hud-coin-icon { animation: hud-coin-gain 0.44s ease-out; }
.hud-coins.is-spent .hud-coin-icon { animation: hud-coin-spend 0.38s ease-out; }

@keyframes hud-xp-gain {
    45% { transform: translateY(-2px) scale(1.08); color: #8ff5eb; }
}

@keyframes hud-coin-gain {
    42% { transform: translateY(-4px) rotate(-10deg); filter: brightness(1.24); }
}

@keyframes hud-coin-spend {
    45% { transform: translateY(3px) rotate(12deg); filter: brightness(0.86); }
}

@media (max-width: 1050px) {
    .top-hud { gap: 8px 12px; padding-inline: 10px; }
    .hud-location-meta { display: grid; gap: 2px; }
    .hud-meta-divider { display: none; }
    #hud-progress { overflow-wrap: anywhere; }
    .hud-stats { gap: 8px; }
    .hud-actions { gap: 5px; padding-inline-start: 8px; }
    .hud-btn { padding-inline: 8px; font-size: 12px; }
}

@media (max-width: 790px) {
    .top-hud { grid-template-columns: minmax(0, 1fr) auto; }
    .hud-location-meta { display: flex; }
    .hud-meta-divider { display: inline; }

    .hud-actions {
        grid-column: 1 / -1;
        padding: 6px 0 0;
        border-inline-start: 0;
        border-top: 1px solid var(--hud-line);
        flex-wrap: wrap;
    }

    .hud-btn { flex: 1 1 auto; }
}

@media (max-width: 470px) {
    .top-hud { inset-inline: 6px; width: calc(100% - 12px); gap: 5px 7px; padding: 7px; }
    #hud-island-name { font-size: 16px; }
    .hud-location-meta { display: grid; gap: 2px; font-size: 11px; }
    .hud-meta-divider { display: none; }
    .hud-xp-box { width: clamp(86px, 26vw, 104px); }
    .hud-xp-numbers { flex-wrap: wrap; row-gap: 1px; }
    .hud-xp-target { font-size: 10px; }
    .hud-stats { gap: 6px; }
    .hud-coins { min-width: 64px; gap: 3px; padding-inline: 4px; }
    .hud-coin-icon { width: 27px; height: 27px; }
    .hud-coins-count > span { font-size: 8px; }
    .hud-actions { flex-wrap: nowrap; }
    .hud-btn { flex: 1 0 0; flex-direction: column; gap: 2px; padding-inline: 2px; font-size: 11px; }
    .hud-btn svg { width: 17px; height: 17px; }
}

@media (max-width: 350px) and (orientation: portrait) {
    .hud-location { display: contents; }
    #hud-island-name { grid-area: 1 / 1; font-size: 15px; }
    .hud-stats { grid-area: 1 / 2; }
    .hud-location-meta { grid-area: 2 / 1 / 3 / -1; display: flex; }
    .hud-meta-divider { display: inline; }
    .hud-actions { grid-row: 3; }
    .hud-btn { font-size: 10px; }
}

@media (max-height: 520px) and (orientation: landscape) {
    .top-hud { inset-block-start: max(5px, env(safe-area-inset-top)); padding-block: 4px; }
    #hud-island-name { font-size: 16px; }
    .hud-location-meta { font-size: 11px; }
    .hud-xp-box { width: 108px; gap: 2px; }
    .hud-xp-track { height: 6px; }
    #hud-xp-text, #hud-coins-value { font-size: 20px; }
    .hud-coins { min-height: 44px; min-width: 82px; }
    .hud-coin-icon { width: 29px; height: 29px; }
    .hud-btn { padding-inline: 7px; }
}

@media (max-width: 790px) and (max-height: 520px) and (orientation: landscape) {
    .top-hud { grid-template-columns: minmax(0, 1fr) auto auto; gap: 7px; padding-inline: 8px; }
    #hud-island-name { font-size: 15px; }
    .hud-location-meta { display: grid; font-size: 10px; }
    .hud-meta-divider { display: none; }
    .hud-xp-box { width: 90px; }
    .hud-coins { min-width: 72px; gap: 4px; padding-inline: 4px; }
    .hud-coin-icon { width: 26px; height: 26px; }
    .hud-coins-count > span { font-size: 8px; }
    .hud-actions { grid-column: auto; padding: 0 0 0 7px; border-top: 0; border-inline-start: 1px solid var(--hud-line); }
    .hud-btn { padding-inline: 6px; }
    .hud-btn span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
}

@media (prefers-reduced-motion: reduce) {
    .hud-btn,
    .hud-xp-fill { transition: none; }
    .hud-xp-box.is-bumped #hud-xp-text,
    .hud-coins.is-bumped .hud-coin-icon,
    .hud-coins.is-spent .hud-coin-icon { animation: none; }
}
