#splash {
    padding: 24px;
    text-align: center;
    background: radial-gradient(ellipse 80% 60% at 50% 40%, rgba(108, 99, 255, .12) 0%, transparent 70%);
}

.menu-corner {
    position: fixed;
    z-index: 11;
    display: flex;
    gap: 10px;
    pointer-events: none;
}

.menu-corner > * {
    pointer-events: auto;
}

.menu-corner.top-right {
    top: max(16px, env(safe-area-inset-top));
    right: max(16px, env(safe-area-inset-right));
}

.game-active .menu-corner {
    display: none !important;
}

#hud {
    position: fixed;
    inset: 0;
    pointer-events: none;
    padding: 0;
    z-index: 5;
}

#hud > * {
    pointer-events: auto;
}

.hud-left {
    position: absolute;
    left: max(var(--hud-score-left), env(safe-area-inset-left));
    top: max(var(--hud-score-top), env(safe-area-inset-top));
    width: var(--hud-score-width);
    max-width: none;
    z-index: 2;
}

.stat-card {
    width: 100%;
    padding: var(--hud-score-pad-y) var(--hud-score-pad-x);
    border-radius: var(--hud-panel-radius);
    background: var(--hud-panel-bg);
    backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    border: 1px solid var(--hud-panel-border);
    box-shadow: var(--hud-panel-shadow);
}

.stat-row {
    display: flex;
    align-items: center;
    gap: 7.8%;
    min-height: var(--hud-score-icon-size);
}

.stat-row + .stat-row {
    margin-top: var(--hud-score-row-gap);
    padding-top: var(--hud-score-row-gap);
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.stat-copy {
    display: flex;
    flex-direction: column;
    gap: 0.25em;
    min-width: 0;
}

.stat-icon {
    width: var(--hud-score-icon-size);
    height: var(--hud-score-icon-size);
    min-width: 34px;
    min-height: 34px;
    max-width: 58px;
    max-height: 58px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    background: rgba(4, 8, 18, 0.62);
    border: 1px solid currentColor;
    box-shadow: 0 0 20px color-mix(in srgb, currentColor 28%, transparent);
}

.stat-icon span {
    display: block;
    width: 48%;
    height: 48%;
    background: currentColor;
}

.stat-icon-score {
    color: var(--purple);
}

.stat-icon-score span {
    clip-path: polygon(50% 0%, 62% 35%, 100% 35%, 69% 57%, 81% 96%, 50% 72%, 19% 96%, 31% 57%, 0% 35%, 38% 35%);
}

.stat-icon-best {
    color: var(--cyan);
}

.stat-icon-best span {
    width: 58%;
    height: 46%;
    clip-path: polygon(0% 100%, 0% 34%, 25% 58%, 44% 0%, 62% 58%, 100% 26%, 86% 100%);
}

.stat-icon-combo {
    color: var(--jade);
}

.stat-icon-combo span {
    width: 52%;
    height: 52%;
    border: 0.42em solid currentColor;
    border-radius: 50%;
    background: transparent;
    position: relative;
}

.stat-icon-combo span::after {
    content: '';
    position: absolute;
    inset: 28%;
    border-radius: 50%;
    background: currentColor;
}

.stat-icon-streak {
    color: var(--gold);
}

.stat-icon-streak span {
    width: 46%;
    height: 62%;
    clip-path: polygon(50% 0%, 74% 24%, 82% 46%, 72% 42%, 78% 62%, 62% 100%, 68% 68%, 50% 82%, 32% 68%, 38% 100%, 22% 62%, 28% 42%, 18% 46%, 26% 24%);
}

.stat-label {
    font-size: var(--hud-score-label-size);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0;
    color: var(--text);
    line-height: 1;
}

.stat-value {
    font-family: var(--font-num);
    font-size: var(--hud-score-value-size);
    font-weight: 700;
    line-height: 1.1;
    color: var(--text);
}

.stat-value.gold { color: var(--gold); }
.stat-value.indigo { color: var(--indigo); }
.stat-value.jade { color: var(--jade); }

.hud-center-top {
    position: absolute;
    top: max(var(--hud-xp-top), env(safe-area-inset-top));
    left: var(--hud-xp-left);
    transform: translateX(-50%);
    width: var(--hud-xp-width);
    max-width: none;
    z-index: 1;
}

.level-xp-card {
    width: 100%;
    min-height: var(--hud-xp-height);
    padding: var(--hud-xp-pad-y) var(--hud-xp-pad-x);
    display: flex;
    align-items: center;
    gap: var(--hud-xp-gap);
    border-radius: var(--hud-panel-radius);
    background: var(--hud-panel-bg);
    backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    border: 1px solid var(--hud-panel-border);
    box-shadow: var(--hud-panel-shadow);
}

.level-hex-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
    gap: 2px;
}

.level-hex {
    width: var(--hud-level-hex-size);
    height: var(--hud-level-hex-size);
    min-width: 48px;
    min-height: 48px;
    max-width: 96px;
    max-height: 96px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.level-hex svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.level-hex-inner {
    position: relative;
    z-index: 1;
    text-align: center;
}

.level-hex-num {
    font-family: var(--font-num);
    font-size: calc(var(--hud-level-hex-size) * 0.42);
    font-weight: 800;
    color: var(--gold);
    line-height: 1.1;
}

.level-xp-right {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.level-xp-header {
    display: grid;
    grid-template-columns: minmax(18%, 1fr) minmax(16%, 0.8fr) minmax(34%, 1fr);
    align-items: center;
    column-gap: 4%;
    margin-bottom: var(--hud-xp-bar-top-gap);
}

.level-xp-title {
    font-size: var(--hud-xp-title-size);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0;
    color: var(--gold);
    line-height: 1;
    white-space: nowrap;
}

.level-title {
    color: var(--text);
    justify-self: start;
}

.xp-title {
    justify-self: center;
}

.level-xp-nums {
    font-family: var(--font-num);
    font-size: var(--hud-xp-num-size);
    color: var(--text);
    font-weight: 600;
    line-height: 1;
    justify-self: end;
    white-space: nowrap;
}

.xp-bar-wrap {
    height: var(--hud-xp-bar-height);
    min-height: 8px;
    max-height: 18px;
    border-radius: 99px;
    background: rgba(255, 255, 255, .11);
    overflow: visible;
    position: relative;
}

.xp-bar-fill {
    height: 100%;
    border-radius: 99px;
    background: linear-gradient(90deg, var(--gold), #FFB700);
    box-shadow: 0 0 14px rgba(255, 215, 0, .7);
    transition: width .35s var(--ease-out);
    position: relative;
}

.xp-bar-fill::after {
    content: none;
}

.xp-gain {
    position: absolute;
    right: 0;
    bottom: calc(100% + 5px);
    font-family: var(--font-num);
    font-size: .78rem;
    font-weight: 800;
    color: var(--gold);
    opacity: 0;
    transform: translateY(4px);
    transition: opacity .2s, transform .3s var(--ease-out);
    white-space: nowrap;
    pointer-events: none;
}

.xp-gain.show { opacity: 1; transform: translateY(0); }

.hud-right {
    position: absolute;
    top: 2px;
    right: max(var(--hud-controls-right), env(safe-area-inset-right));
    display: flex;
    flex-direction: column;
    gap: var(--hud-controls-gap);
    width: var(--hud-controls-width);
    max-width: none;
    align-items: stretch;
    z-index: 2;
}

.hud-bottom {
    position: absolute;
    bottom: max(14px, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    width: min(560px, calc(100vw - 28px));
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 3;
    pointer-events: none;
}

.hud-bottom > * {
    pointer-events: auto;
}

.q-type-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 16px;
    border-radius: 100px;
    font-size: .78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    width: fit-content;
    transition: background .3s, color .3s, border-color .3s, opacity .2s, left .28s var(--ease-out), top .28s var(--ease-out);
    border: 1px solid var(--border);
    color: var(--text-muted);
    background: var(--surface);
    /* Positioned dynamically by UIManager.positionQTypeBadge() to sit just
       below the active node on the canvas. left/top are set in JS as px
       values; this rule only supplies a safe fallback + the anchor. */
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, 0);
    z-index: 4;
    pointer-events: none;
    backdrop-filter: blur(10px) saturate(1.4);
    -webkit-backdrop-filter: blur(10px) saturate(1.4);
}

.q-type-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.answer-shell {
    min-height: 68px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 10px 16px;
    border-radius: var(--radius);
    background: var(--surface);
    backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    border: 1px solid var(--border);
}

.answer-display {
    font-family: var(--font-num);
    font-size: clamp(1.4rem, 5.5vw, 2.2rem);
    font-weight: 700;
    text-align: left;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.answer-display.placeholder {
    color: var(--text-muted);
    font-weight: 400;
    font-size: clamp(1rem, 3.5vw, 1.3rem);
}

.keypad {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    transition: max-height .35s var(--ease-out), opacity .25s, transform .35s var(--ease-out);
    max-height: 0;
    opacity: 0;
    transform: translateY(16px);
    pointer-events: none;
    overflow: hidden;
}

.keypad.visible {
    max-height: 600px;
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
    overflow: visible;
}

.keypad-landscape-wrap {
    display: none;
    position: absolute;
    bottom: max(10px, env(safe-area-inset-bottom));
    right: max(14px, env(safe-area-inset-right));
    width: min(380px, 48vw);
    z-index: 5;
    pointer-events: auto;
}

.keypad-landscape-wrap .keypad {
    max-height: 600px;
    opacity: 1;
    transform: none;
    pointer-events: auto;
    overflow: visible;
    display: grid;
    gap: 6px;
}

.keypad-landscape-wrap.visible {
    display: block;
}

.answer-reveal {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, 0);
    display: none;
    align-items: center;
    gap: 8px;
    z-index: 4;
    pointer-events: none;
    width: max-content;
    transition: left .28s var(--ease-out), top .28s var(--ease-out);
}

.answer-reveal.show {
    display: flex;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(4, 8, 18, .7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    transition: opacity .3s;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-panel {
    width: min(640px, 95vw);
    max-height: 88vh;
    overflow-y: auto;
    padding: 24px;
    border-radius: var(--radius-lg);
    background: rgba(8, 15, 30, .92);
    border: 1px solid var(--border2);
    box-shadow: var(--glow-i), 0 32px 80px rgba(0, 0, 0, .6);
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.modal-title {
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -.02em;
    color: var(--gold);
}

.toast-stack {
    position: fixed;
    left: 50%;
    top: 12%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    z-index: 20;
    width: min(440px, 90vw);
}

#gameover {
    padding: 24px;
    text-align: center;
    background: radial-gradient(ellipse 70% 50% at 50% 50%, rgba(255, 71, 87, .08) 0%, transparent 70%);
}
