.game-page {
    overflow: hidden;
}

.game-shell {
    width: min(1160px, calc(100% - 24px));
    height: 100vh;
    padding: 8px 0 10px;
    display: flex;
    flex-direction: column;
}

.game-header {
    min-height: 48px;
    margin-bottom: 8px;
    padding: 7px 15px;
    border-color: #efd7e0;
    border-radius: 15px;
    color: #38262f;
    background: #fff3f7;
    box-shadow: 0 8px 24px rgba(76, 31, 51, .1);
}

.game-header > a {
    color: #c83f6c;
    font-size: .78rem;
}

.game-header > div:nth-child(2) {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 9px;
    white-space: nowrap;
}

.game-header h1 {
    color: #38262f;
    font-size: 1rem;
}

.game-header p {
    margin: 0;
    color: #8c6876;
    font-size: .68rem;
}

.game-header p::before {
    content: "· ";
}

.scoreboard span {
    display: flex;
    align-items: baseline;
    gap: 4px;
    color: #80616e;
    white-space: nowrap;
}

.scoreboard b {
    display: inline;
    color: #38262f;
    font-size: .86rem;
}

.game-grid {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 210px minmax(420px, 550px) 220px;
    gap: 14px;
    align-items: start;
    justify-content: center;
}

.reveal-panel {
    grid-column: 1;
    grid-row: 1;
    padding: 9px;
    border-radius: 20px;
}

.reveal-board {
    width: 100%;
    border-radius: 13px;
}

.reveal-panel > p {
    margin: 9px 3px 2px;
    font-size: .72rem;
    line-height: 1.45;
}

.play-panel {
    grid-column: 2;
    grid-row: 1;
    padding: 11px;
    border-radius: 22px;
}

.rhythm-stage {
    height: calc(100vh - 174px);
    min-height: 420px;
}

.start-overlay button {
    width: 180px;
    height: 180px;
    aspect-ratio: 1;
    justify-self: center;
    padding: 18px;
    line-height: 1.15;
}

.key-controls {
    gap: 9px;
    margin-top: 10px;
}

.key-controls button {
    min-height: 62px;
    border: 1px solid #ff9bbb;
    border-radius: 15px;
    color: #fff;
    background: linear-gradient(145deg, #ff8fb3, #e64d80);
    box-shadow: 0 8px 20px rgba(230, 77, 128, .22);
}

.key-controls button strong {
    font-size: 1.25rem;
    text-shadow: none;
}

.key-controls button.pressed {
    border-color: #fff;
    background: #d93d72;
}

.key-image-previews {
    position: absolute;
    z-index: 6;
    right: 15px;
    bottom: 7px;
    left: 15px;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
    pointer-events: none;
}

.key-image-slot {
    width: 82px;
    height: 82px;
    justify-self: center;
    display: grid;
    place-items: center;
    overflow: hidden;
    border: 0;
    color: #fff;
    background: transparent;
    box-shadow: none;
    opacity: 0;
}

.key-image-slot.active { opacity: 1; }

.key-image-slot img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
}

.key-image-slot strong {
    font-size: 1.1rem;
}

.key-image-slot.pop {
    animation: slot-pop .24s ease;
}

.rhythm-stage .hit-line {
    bottom: 98px;
}

.rhythm-stage .judgement {
    top: 46%;
    bottom: auto;
    font-size: clamp(1.7rem, 4vw, 2.6rem);
    text-shadow: 0 4px 20px rgba(0,0,0,.55);
}

.combo-counter {
    position: absolute;
    z-index: 5;
    top: calc(46% + 48px);
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    color: #fff;
    font-size: .9rem;
    font-weight: 900;
    letter-spacing: .06em;
    text-shadow: 0 3px 14px rgba(0,0,0,.65);
    white-space: nowrap;
    transition: opacity .15s;
}

.combo-counter.show { opacity: 1; }

.combo-callout {
    position: absolute;
    z-index: 7;
    top: 26%;
    left: 50%;
    width: min(84%, 390px);
    padding: 13px 18px;
    transform: translate(-50%,-10px) scale(.85);
    border: 1px solid rgba(255,255,255,.35);
    border-radius: 18px;
    opacity: 0;
    color: #fff;
    background: linear-gradient(135deg,rgba(240,100,145,.96),rgba(171,52,112,.94));
    box-shadow: 0 15px 45px rgba(240,100,145,.38);
    text-align: center;
    pointer-events: none;
}

.combo-callout strong,.combo-callout span { display: block; }
.combo-callout strong { font-size: 1.3rem; letter-spacing: .08em; }
.combo-callout span { margin-top: 3px; font-size: .72rem; }
.combo-callout.show { animation: combo-callout 1.2s ease both; }

.side-column {
    grid-column: 3;
    grid-row: 1;
    display: grid;
    gap: 14px;
}

.side-column .leaderboard {
    position: static;
    grid-column: auto;
    grid-row: auto;
    padding: 16px;
    border-radius: 22px;
}

.leaderboard .player-name {
    display: block;
    margin-bottom: 2px;
    color: #ff91b5;
    font-size: .78rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.key-preview {
    padding: 10px;
    border: 1px solid #3b2a40;
    border-radius: 22px;
    color: #ae9dad;
    background: #241827;
    text-align: center;
    font-size: .74rem;
}

.side-column .hit-visual {
    position: static;
    width: 100%;
    margin-top: 9px;
    transform: none;
    border-radius: 17px;
    background: #19101c;
    overflow: hidden;
}

.side-column .hit-visual img {
    border-radius: 17px;
}

.side-column .hit-visual strong {
    color: #6f5b6c;
    font-size: 3rem;
}

.side-column .hit-visual.pop {
    animation: preview-pop .28s ease;
}

#resultDialog {
    max-width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
    padding: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    overflow: auto;
}

.result-modal {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 4px;
}

.result-reveal {
    position: relative;
    width: min(500px, calc(100vw - 40px), calc(100vh - 330px));
    min-width: 280px;
    aspect-ratio: 1;
    overflow: hidden;
    border: 7px solid #fff;
    border-radius: 4px;
    background: #2d2130;
    box-shadow: 0 22px 70px rgba(0, 0, 0, .42);
}

.result-reveal > img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.result-cover-grid {
    z-index: 1;
}

.result-card {
    width: min(430px, calc(100vw - 38px));
    margin-top: 12px;
    padding: 24px 30px;
    border-radius: 26px;
    background: #fff;
    box-shadow: 0 24px 70px rgba(0, 0, 0, .38);
}

.result-card h2 {
    margin-bottom: 16px;
}

.score-breakdown {
    display: grid;
    grid-template-columns: repeat(3,1fr);
    gap: 7px;
    margin-top: 10px;
}

.score-breakdown > div {
    padding: 9px 5px;
    border-radius: 12px;
    background: #fff3f7;
}

.score-breakdown span,.score-breakdown b { display: block; }
.score-breakdown span { color: #8c7885; font-size: .62rem; }
.score-breakdown b { margin-top: 2px; font-size: .9rem; }

.milestone-summary { margin-top: 10px; padding: 10px 12px; border: 1px solid #f1dce4; border-radius: 13px; text-align: left; }
.milestone-summary h3 { margin: 0 0 5px; color: #d94d7b; font-size: .78rem; }
.milestone-summary p { display: flex; justify-content: space-between; gap: 8px; margin: 0; padding: 4px 0; font-size: .67rem; }
.milestone-summary p + p { border-top: 1px solid #f4e6eb; }
.milestone-summary p b { color: #d94d7b; white-space: nowrap; }
.milestone-summary .empty { justify-content: center; color: #8c7885; }

.highscore-entry {
    margin-top: 14px;
    padding: 13px;
    border: 1px solid #f3d6e0;
    border-radius: 16px;
    background: #fff6f9;
    text-align: left;
}

.highscore-entry label {
    display: block;
    margin-bottom: 7px;
    color: #d94d7b;
    font-size: .72rem;
    font-weight: 900;
    letter-spacing: .06em;
}

.highscore-entry > div {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 7px;
}

.highscore-entry input {
    min-width: 0;
    border: 1px solid #ead7de;
    border-radius: 11px;
    padding: 10px 11px;
    color: #2a2030;
    background: #fff;
    outline: none;
}

.highscore-entry input:focus {
    border-color: #f06491;
    box-shadow: 0 0 0 3px rgba(240, 100, 145, .13);
}

.highscore-entry button {
    border: 0;
    border-radius: 11px;
    padding: 0 14px;
    color: #fff;
    background: #f06491;
    font-weight: 800;
    cursor: pointer;
}

.highscore-entry button:disabled {
    opacity: .55;
    cursor: wait;
}

.highscore-entry small {
    display: block;
    min-height: 1.2em;
    margin-top: 6px;
    color: #8c7885;
    font-size: .68rem;
}

@keyframes preview-pop {
    50% { transform: scale(1.06) rotate(-2deg); }
}

@keyframes slot-pop {
    50% { transform: translateY(-3px) scale(1.08); }
}

@keyframes combo-callout {
    0% { opacity: 0; transform: translate(-50%,-12px) scale(.78); }
    18%,75% { opacity: 1; transform: translate(-50%,0) scale(1); }
    100% { opacity: 0; transform: translate(-50%,-5px) scale(.94); }
}

@media (max-width: 980px) {
    .game-grid {
        grid-template-columns: 180px minmax(390px, 1fr) 180px;
    }

    .side-column .leaderboard {
        display: block;
    }
}

@media (min-width: 761px) and (max-height: 850px),
       (min-width: 761px) and (orientation: landscape) and (pointer: coarse) {
    .game-page {
        overflow: auto;
    }

    .game-shell {
        height: 100vh;
        height: 100dvh;
        min-height: 360px;
    }

    .game-header {
        min-height: 42px;
        padding-block: 5px;
    }

    .rhythm-stage {
        height: calc(100vh - 160px);
        height: calc(100dvh - 160px);
        min-height: 220px;
        max-height: none;
    }

    .start-overlay button {
        width: 130px;
        height: 130px;
        padding: 12px;
        font-size: 1rem;
    }

    .start-overlay small {
        margin-top: 8px;
        font-size: .68rem;
    }

    .key-controls button {
        min-height: 48px;
    }

    .key-image-slot {
        width: 58px;
        height: 58px;
    }

    .rhythm-stage .hit-line {
        bottom: 74px;
    }
}

@media (max-width: 760px) {
    .game-page {
        overflow: auto;
    }

    .game-shell {
        width: 100%;
        height: auto;
        padding: 0;
    }

    .game-header {
        position: sticky;
        top: 0;
        z-index: 20;
        min-height: 0;
        margin: 0;
        padding: 6px 10px;
        grid-template-columns: auto minmax(0, 1fr);
        gap: 5px 10px;
        border-radius: 0 0 13px 13px;
    }

    .game-header > a {
        font-size: .7rem;
        white-space: nowrap;
    }

    .game-header > div:nth-child(2) {
        display: flex;
        min-width: 0;
        justify-content: flex-end;
        gap: 5px;
        overflow: hidden;
    }

    .game-header h1 {
        max-width: 42vw;
        font-size: .8rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .game-header p {
        flex: 0 0 auto;
        font-size: .56rem;
    }

    .scoreboard {
        grid-column: 1 / -1;
        justify-content: center;
        gap: 13px;
        padding-top: 4px;
        border-top: 1px solid #efdce3;
    }

    .scoreboard span {
        font-size: .56rem;
    }

    .scoreboard b {
        font-size: .72rem;
    }

    .game-grid {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0;
    }

    .reveal-panel,
    .play-panel,
    .side-column {
        grid-column: 1;
        width: 100%;
        order: initial;
    }

    .reveal-panel {
        grid-row: 2;
        padding: 9px;
    }

    .reveal-board {
        width: 170px;
        margin: auto;
    }

    .play-panel {
        grid-row: 1;
        padding: 7px;
        border-radius: 0 0 18px 18px;
    }

    .side-column {
        grid-row: 3;
        padding: 8px;
    }

    .rhythm-stage {
        height: calc(100vh - 178px);
        height: calc(100dvh - 178px);
        min-height: 360px;
        max-height: none;
    }

    .start-overlay button {
        width: 160px;
        height: 160px;
    }

    .key-controls button {
        min-height: 58px;
    }

    .key-image-previews {
        right: 11px;
        bottom: 8px;
        left: 11px;
        gap: 0;
    }

    .key-image-slot {
        width: 72px;
        height: 72px;
    }

    .rhythm-stage .hit-line {
        bottom: 88px;
    }

    .side-column .hit-visual {
        width: min(220px, 70vw);
        margin-inline: auto;
    }

    .result-reveal {
        width: min(calc(100vw - 34px), calc(100vh - 330px));
        min-width: 230px;
    }

    .result-card {
        padding: 20px 18px;
    }
}
