:root {
    --game-width: 1616px;
    --green: #7df7b9;
}

body {
    height: 100vh;
    padding: 14px 12px;
    overflow: hidden;
}

.shell {
    width: min(1560px, 100%);
    height: calc(100vh - 28px);
    margin: 0 auto;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 12px;
}

.topbar,
.game-view {
    width: min(var(--game-width), 100%);
    justify-self: center;
}

.topbar {
    padding: 20px 24px;
}

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

.game-view {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 14px;
    align-items: start;
    min-height: 0;
}

.panel,
.info-card {
    border: 1px solid var(--ui-line);
    border-radius: var(--ui-radius-md);
    background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.02)), var(--ui-panel);
    box-shadow: var(--ui-shadow);
}

.stage-panel,
.side-column {
    display: grid;
    gap: 14px;
    min-height: 0;
}

.stage-panel {
    padding: 14px;
    align-content: start;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.panel-head h2,
.section h3,
p {
    margin: 0;
}

.stage-wrap {
    position: relative;
    overflow: hidden;
    min-height: 0;
    border: 1px solid var(--ui-line);
    border-radius: 0;
    background: #060b16;
    box-shadow: none;
}

canvas {
    width: 100%;
    height: auto;
    min-height: 0;
    display: block;
    border-radius: 0;
    background: #060b16;
}

.stage-stats {
    position: absolute;
    left: 14px;
    top: 14px;
    z-index: 5;
    display: grid;
    grid-template-columns: repeat(3, minmax(68px, auto));
    gap: 8px;
}

.stage-score {
    position: absolute;
    right: 14px;
    top: 14px;
    z-index: 5;
}

.stage-stats div,
.stage-score {
    min-height: 52px;
    display: grid;
    gap: 2px;
    align-content: center;
    padding: 8px 12px;
    border: 1px solid rgba(181, 220, 255, 0.18);
    border-radius: 10px;
    background: rgba(5, 14, 28, 0.78);
    backdrop-filter: blur(8px);
}

.stage-stats span,
.stage-score span,
.stage-xp-head span {
    display: block;
    color: var(--ui-muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.stage-stats strong,
.stage-score strong {
    display: block;
    color: var(--ui-accent);
    font-size: 22px;
}

.stage-score strong {
    min-width: 116px;
    text-align: right;
}

.section {
    display: grid;
    gap: 12px;
    padding: 16px;
}

.stage-xp {
    position: absolute;
    left: 14px;
    right: 14px;
    bottom: 14px;
    z-index: 5;
    display: grid;
    gap: 7px;
    padding: 10px 12px;
    border: 1px solid rgba(181, 220, 255, 0.18);
    border-radius: 12px;
    background: rgba(5, 14, 28, 0.76);
    backdrop-filter: blur(8px);
}

.stage-xp-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.xp-bar {
    height: 12px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.09);
}

.xp-bar span {
    width: 0%;
    height: 100%;
    display: block;
    border-radius: inherit;
    transition: width 120ms ease;
}

.side-column {
    align-content: start;
    overflow: auto;
}

.section-head {
    min-height: 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.section-head h3 {
    line-height: 1.15;
}

.mini-button {
    min-height: 26px;
    padding: 0 9px;
    border: 1px solid var(--ui-line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--ui-text);
    font: inherit;
    font-size: 12px;
    font-weight: 900;
    cursor: pointer;
}

.ranking-section {
    gap: 8px;
    padding-top: 12px;
    max-height: 260px;
    min-height: 0;
    overflow: auto;
}

.ranking-list {
    display: grid;
    gap: 8px;
}

.ranking-item {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, 0.075);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
}

.ranking-rank {
    color: #ffd166;
    font-weight: 1000;
    text-align: center;
}

.ranking-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 900;
}

.ranking-score {
    color: var(--ui-accent);
    font-weight: 1000;
}

.ranking-empty {
    padding: 14px;
    border: 1px dashed var(--ui-line);
    border-radius: 12px;
    color: var(--ui-muted);
    background: rgba(255, 255, 255, 0.03);
    text-align: center;
}

.xp-bar span {
    background: linear-gradient(90deg, var(--green), var(--ui-accent));
}

.skill-list {
    display: grid;
    gap: 8px;
}

.skill-row {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, 0.075);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
}

.skill-icon {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 11px;
    background: rgba(102, 229, 255, 0.12);
    color: var(--ui-accent);
    font-size: 18px;
    font-weight: 1000;
    line-height: 1;
}

.skill-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 900;
}

.skill-desc,
.section p {
    color: var(--ui-muted);
    font-size: 13px;
    line-height: 1.55;
}

.skill-level {
    color: var(--green);
    font-weight: 900;
}

.key {
    display: inline-flex;
    min-height: 28px;
    align-items: center;
    margin-right: 6px;
    padding: 0 9px;
    border: 1px solid var(--ui-line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--ui-text);
    font-size: 12px;
    font-weight: 900;
}

.start-layer,
.overlay {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(3, 8, 18, 0.78);
    backdrop-filter: blur(8px);
}

.overlay {
    position: fixed;
}

.start-layer[hidden],
.overlay[hidden] {
    display: none;
}

.overlay-card {
    width: min(720px, 100%);
    display: grid;
    gap: 14px;
    padding: 26px;
    border: 1px solid var(--ui-line);
    border-radius: var(--ui-radius-md);
    background: rgba(8, 20, 38, 0.96);
    text-align: left;
    box-shadow: var(--ui-shadow);
}

.start-card {
    width: min(620px, 100%);
}

.overlay-kicker {
    color: var(--green);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.overlay-title {
    font-size: clamp(30px, 5vw, 48px);
    font-weight: 1000;
    line-height: 1.05;
}

.overlay-text {
    color: var(--ui-muted);
    line-height: 1.65;
}

.buttons.left {
    display: flex;
    justify-content: flex-start;
    gap: 10px;
}

.buttons.left .secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--ui-text);
    border-color: var(--ui-line);
}

.buttons.left .secondary:hover {
    background: rgba(102, 229, 255, 0.14);
}

.toast {
    position: absolute;
    left: 50%;
    top: 22px;
    z-index: 6;
    transform: translateX(-50%);
    min-width: 260px;
    padding: 13px 18px;
    border: 1px solid rgba(125, 247, 185, 0.34);
    border-radius: 999px;
    background: rgba(5, 14, 28, 0.9);
    color: var(--green);
    font-weight: 900;
    text-align: center;
}

.upgrade-card {
    width: min(900px, 100%);
}

.bonus-upgrade {
    background: rgba(18, 11, 36, 0.78);
}

.bonus-upgrade .upgrade-card {
    border-color: rgba(255, 209, 102, 0.34);
    background: linear-gradient(180deg, rgba(38, 26, 58, 0.96), rgba(8, 20, 37, 0.96));
}

.upgrade-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.upgrade-option {
    min-height: 210px;
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr);
    gap: 12px;
    align-items: start;
    justify-items: stretch;
    padding: 16px;
    border: 1px solid var(--ui-line);
    border-radius: var(--ui-radius-sm);
    background: rgba(255, 255, 255, 0.055);
    color: var(--ui-text);
    text-align: left;
    cursor: pointer;
}

.upgrade-option:hover,
.upgrade-option:focus-visible {
    border-color: var(--ui-line-strong);
    outline: none;
    transform: translateY(-1px);
}

.upgrade-option.double-upgrade {
    border-color: rgba(255, 209, 102, 0.72);
    background: linear-gradient(180deg, rgba(78, 55, 22, 0.9), rgba(13, 24, 38, 0.92));
}

.upgrade-option.double-upgrade .upgrade-level {
    color: #ffd166;
}

.upgrade-option .skill-icon {
    width: 44px;
    height: 44px;
    color: var(--ui-accent);
    font-size: 20px;
}

.upgrade-copy {
    min-width: 0;
    display: grid;
    gap: 9px;
    justify-items: start;
    text-align: left;
}

.upgrade-name {
    display: block;
    font-size: 20px;
    font-weight: 1000;
    line-height: 1.2;
}

.upgrade-desc {
    display: block;
    color: var(--ui-muted);
    font-size: 14px;
    line-height: 1.55;
}

.upgrade-level {
    display: block;
    color: var(--green);
    font-size: 13px;
    font-weight: 900;
}

@media (max-width: 1120px) {
    .game-view {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 760px) {
    .topbar {
        padding: 22px 18px;
    }

    .upgrade-grid {
        grid-template-columns: 1fr;
    }

    .stage-stats {
        right: 126px;
        left: 10px;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .stage-score {
        right: 10px;
        top: 10px;
    }

    .stage-stats div {
        min-width: 0;
        padding: 7px 8px;
    }

    .stage-score {
        min-width: 104px;
        padding: 7px 8px;
    }

    .stage-stats strong {
        font-size: 18px;
    }

    .stage-score strong {
        min-width: 88px;
        font-size: 18px;
    }

    .overlay-card {
        padding: 20px;
    }
}
