:root {
    --rescue-night: #101922;
    --rescue-blue: #1f5f8b;
    --rescue-sky: #8ed6ff;
    --rescue-sun: #ffd36b;
    --rescue-fire: #ff7f50;
    --rescue-fire-deep: #f04f42;
    --rescue-cream: #fff8ef;
    --rescue-ink: #173041;
    --rescue-line: rgba(255, 248, 239, 0.18);
    --rescue-shadow: 0 24px 60px rgba(7, 15, 25, 0.28);
}

* {
    box-sizing: border-box;
}

body {
    color: var(--rescue-cream);
    font-family: "Manrope", "Outfit", sans-serif;
}

body::before {
    background:
        radial-gradient(circle at 14% 18%, rgba(255, 127, 80, 0.14), transparent 24%),
        radial-gradient(circle at 84% 14%, rgba(142, 214, 255, 0.14), transparent 18%),
        linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.015) 1px, transparent 1px);
    background-size: auto, auto, 36px 36px, 36px 36px;
}

.rescue-page {
    padding: 112px 0 72px;
}

.rescue-main-shell {
    min-height: calc(100vh - 148px);
}

.rescue-main-grid,
.rescue-notes-grid {
    display: grid;
    gap: 24px;
}

.rescue-main-grid {
    grid-template-columns: minmax(300px, 0.38fr) minmax(0, 1fr);
    align-items: start;
}

.rescue-side-panel,
.rescue-stage-card,
.note-card {
    border: 1px solid var(--rescue-line);
    background: linear-gradient(180deg, rgba(24, 39, 54, 0.92), rgba(13, 22, 32, 0.94));
    box-shadow: var(--rescue-shadow);
}

.rescue-side-panel,
.rescue-stage-card,
.note-card {
    padding: 28px;
}

.rescue-side-panel {
    display: flex;
    flex-direction: column;
    gap: 22px;
}

.side-top {
    display: grid;
    gap: 16px;
}

.rescue-kicker {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--rescue-sky);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.rescue-side-panel h1,
.rescue-stage-card h2,
.overlay-card h3,
.note-card h3 {
    margin: 0;
    color: var(--rescue-cream);
    font-family: "Outfit", "Manrope", sans-serif;
}

.rescue-side-panel h1 {
    font-size: clamp(2.4rem, 3.3vw, 4.2rem);
    line-height: 0.94;
}

.rescue-lead,
.stage-status,
.stage-caption,
.overlay-card p,
.note-card p,
.control-list {
    color: rgba(255, 248, 239, 0.8);
}

.rescue-lead {
    margin: 0;
    line-height: 1.75;
}

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

.quick-card,
.hud-pill,
.best-pill,
.sound-toggle-btn,
.control-block,
.overlay-note {
    border: 1px solid rgba(255, 248, 239, 0.14);
    background: rgba(255, 255, 255, 0.05);
}

.quick-card {
    min-height: 108px;
    padding: 16px 18px;
    border-radius: 22px;
    display: grid;
    gap: 8px;
}

.quick-card span,
.best-pill span,
.hud-pill span {
    color: rgba(255, 248, 239, 0.72);
    font-size: 0.8rem;
}

.quick-card strong {
    line-height: 1.45;
}

.control-block {
    border-radius: 26px;
    padding: 18px 20px;
}

.control-list {
    margin: 12px 0 0;
    padding-left: 18px;
    display: grid;
    gap: 10px;
    line-height: 1.6;
}

.stage-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.best-pill {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    border-radius: 999px;
    padding: 0 16px;
}

.best-pill strong {
    font-size: 1rem;
}

.sound-toggle-btn {
    min-height: 44px;
    border-radius: 999px;
    padding: 0 16px;
    color: var(--rescue-cream);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.sound-toggle-btn:hover {
    transform: translateY(-1px);
    border-color: rgba(255, 211, 107, 0.36);
}

.stage-status {
    margin: 0;
    padding: 0 2px;
    font-size: 0.96rem;
    line-height: 1.65;
}

.stage-hud {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.hud-pill {
    border-radius: 22px;
    min-height: 86px;
    padding: 14px 16px;
}

.hud-pill span {
    display: block;
    margin-bottom: 8px;
}

.hud-pill strong {
    font-size: 1.2rem;
}

.rescue-stage-card {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.stage-card-head {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: end;
    justify-content: space-between;
}

.stage-card-head h2 {
    font-size: clamp(1.9rem, 2.7vw, 3rem);
}

.stage-caption {
    margin: 0;
    max-width: 34ch;
    line-height: 1.55;
    text-align: right;
}

.orientation-guard {
    display: none;
    margin-top: 18px;
    padding: 14px 18px;
    border-radius: 20px;
    border: 1px dashed rgba(255, 211, 107, 0.4);
    background: rgba(255, 211, 107, 0.08);
    color: var(--rescue-sun);
    font-weight: 700;
}

.orientation-guard p {
    margin: 0;
}

.stage-shell {
    position: relative;
    margin-top: 18px;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow: hidden;
    border-radius: 34px;
    border: 1px solid rgba(255, 248, 239, 0.16);
    background:
        linear-gradient(180deg, rgba(78, 171, 255, 0.18), rgba(8, 22, 34, 0.92)),
        linear-gradient(90deg, rgba(255, 127, 80, 0.16), rgba(255, 127, 80, 0));
    min-height: 0;
}

#rescueCanvas {
    display: block;
    width: min(100%, calc((100vh - 360px) * 1.6));
    max-width: 100%;
    max-height: min(72vh, 760px);
    height: auto;
    aspect-ratio: 16 / 10;
}

.stage-shell.feedback-catch,
.stage-shell.feedback-rescue,
.stage-shell.feedback-wave,
.stage-shell.feedback-pause {
    box-shadow: inset 0 0 0 1px rgba(255, 248, 239, 0.1), 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.stage-shell.feedback-catch {
    box-shadow: inset 0 0 0 1px rgba(142, 214, 255, 0.48), 0 0 28px rgba(142, 214, 255, 0.16);
}

.stage-shell.feedback-rescue,
.stage-shell.feedback-wave {
    box-shadow: inset 0 0 0 1px rgba(255, 211, 107, 0.52), 0 0 34px rgba(255, 127, 80, 0.18);
}

.stage-shell.feedback-miss {
    animation: rescue-shake 240ms ease;
}

.feedback-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.feedback-pop {
    position: absolute;
    top: 16%;
    left: 50%;
    transform: translate(-50%, 0);
    border-radius: 999px;
    padding: 10px 16px;
    border: 1px solid rgba(255, 248, 239, 0.14);
    background: rgba(12, 28, 42, 0.82);
    color: var(--rescue-cream);
    font-weight: 800;
    letter-spacing: 0.04em;
    animation: feedback-float 900ms ease forwards;
}

.feedback-pop.catch {
    color: var(--rescue-sky);
}

.feedback-pop.rescue,
.feedback-pop.wave {
    color: var(--rescue-sun);
}

.feedback-pop.miss {
    color: #ffb1b1;
}

.feedback-pop.pause {
    color: rgba(255, 248, 239, 0.82);
}

.overlay {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 28px;
    background: rgba(8, 18, 28, 0.4);
    backdrop-filter: blur(10px);
}

.overlay.active {
    display: flex;
}

.overlay-card {
    width: min(100%, 560px);
    padding: 28px;
    border-radius: 28px;
    border: 1px solid rgba(255, 248, 239, 0.16);
    background: linear-gradient(180deg, rgba(12, 28, 42, 0.92), rgba(21, 40, 55, 0.92));
    box-shadow: 0 18px 40px rgba(4, 10, 16, 0.34);
}

.overlay-card.compact {
    width: min(100%, 420px);
}

.overlay-card h3 {
    margin-top: 0;
    font-size: clamp(1.8rem, 3vw, 2.3rem);
}

.overlay-card p {
    margin: 14px 0 0;
    line-height: 1.8;
}

.overlay-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin-top: 22px;
}

.rescue-primary-btn,
.rescue-secondary-btn {
    min-height: 48px;
    border-radius: 999px;
    padding: 0 20px;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.rescue-primary-btn {
    border: none;
    color: var(--rescue-ink);
    background: linear-gradient(135deg, var(--rescue-sun), var(--rescue-fire));
}

.rescue-secondary-btn {
    border: 1px solid rgba(255, 248, 239, 0.2);
    color: var(--rescue-cream);
    background: rgba(255, 255, 255, 0.08);
}

.rescue-primary-btn:hover,
.rescue-secondary-btn:hover {
    transform: translateY(-2px);
}

.overlay-note {
    border-radius: 16px;
    padding: 10px 14px;
    font-size: 0.9rem;
    line-height: 1.5;
}

.rescue-notes-section {
    margin-top: 28px;
}

.rescue-notes-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.note-card h3 {
    margin-top: 0;
    font-size: 1.35rem;
}

.note-card p {
    margin: 14px 0 0;
    line-height: 1.75;
}

@keyframes feedback-float {
    0% {
        opacity: 0;
        transform: translate(-50%, 18px) scale(0.92);
    }

    18% {
        opacity: 1;
        transform: translate(-50%, 0) scale(1);
    }

    100% {
        opacity: 0;
        transform: translate(-50%, -40px) scale(1.02);
    }
}

@keyframes rescue-shake {
    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-8px);
    }

    75% {
        transform: translateX(8px);
    }
}

@media (max-width: 1180px) {
    .rescue-main-grid,
    .rescue-notes-grid {
        grid-template-columns: 1fr;
    }

    .rescue-stage-card {
        min-height: 0;
    }

    .stage-caption {
        text-align: left;
    }

    .stage-hud {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    .rescue-page {
        padding-top: 108px;
    }

    .rescue-side-panel,
    .rescue-stage-card,
    .note-card {
        padding: 22px;
    }

    .rescue-quick-grid {
        grid-template-columns: 1fr;
    }

    .stage-hud {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .stage-shell {
        padding: 10px;
    }

    #rescueCanvas {
        width: 100%;
        max-height: none;
    }
}

@media (orientation: portrait) and (max-width: 900px) {
    .orientation-guard {
        display: block;
    }
}
