:root {
    color-scheme: light;
    --flap-bg: #f8fbff;
    --flap-side-bg: #eef7ff;
    --flap-board-bg: linear-gradient(180deg, #50c8ff 0%, #8ce6ff 52%, #86d972 52%, #43a853 100%);
    --flap-ink: #231f25;
    --flap-muted: #6f6570;
    --flap-line: #e5dce5;
    --flap-panel: rgba(255, 255, 255, 0.9);
    --flap-pink: #f657b5;
    --flap-blue: #2878f0;
    --flap-green: #14a86a;
    --flap-gold: #ffb82e;
    --flap-violet: #7d59e8;
    --game-header-side-bg: var(--flap-side-bg);
    --game-header-center-bg: #fff;
    --game-header-accent: var(--flap-pink);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
    margin: 0;
    touch-action: manipulation;
}

body {
    color: var(--flap-ink);
    font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
    letter-spacing: 0;
    -webkit-text-size-adjust: 100%;
    background:
        linear-gradient(
            to right,
            var(--flap-side-bg) 0,
            var(--flap-side-bg) calc((100% - var(--game-content-width)) / 2),
            var(--flap-bg) calc((100% - var(--game-content-width)) / 2),
            var(--flap-bg) calc((100% + var(--game-content-width)) / 2),
            var(--flap-side-bg) calc((100% + var(--game-content-width)) / 2),
            var(--flap-side-bg) 100%
        );
}

button,
a {
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

.flap-shell {
    display: grid;
    place-items: start center;
    min-height: 100vh;
    padding: 6px 0 max(14px, env(safe-area-inset-bottom));
}

.flap-stage {
    width: 100%;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

.flap-hud {
    position: absolute;
    top: 16px;
    right: 16px;
    left: 78px;
    z-index: 3;
    display: grid;
    grid-template-columns: minmax(60px, 1fr) minmax(48px, 0.75fr) minmax(56px, 0.9fr) minmax(44px, 0.62fr);
    gap: 7px;
    pointer-events: none;
}

.flap-hud > div,
.flap-global-panel {
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.64);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.82),
        0 10px 24px rgba(40, 120, 240, 0.08);
    backdrop-filter: blur(14px) saturate(1.08);
    -webkit-backdrop-filter: blur(14px) saturate(1.08);
}

.flap-hud > div {
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
    min-height: 42px;
    padding: 7px 6px;
    border-color: rgba(255, 255, 255, 0.72);
    color: #fff;
    background:
        linear-gradient(145deg, rgba(255, 255, 255, 0.44), rgba(255, 255, 255, 0.12) 46%, rgba(112, 197, 255, 0.24)),
        rgba(22, 116, 218, 0.3);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.76),
        inset 0 -10px 18px rgba(20, 86, 171, 0.16),
        0 8px 20px rgba(8, 64, 154, 0.14);
}

.flap-hud > div::before {
    content: "";
    position: absolute;
    inset: 1px 1px auto;
    height: 44%;
    border-radius: 7px 7px 16px 16px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.44), rgba(255, 255, 255, 0));
    pointer-events: none;
}

.flap-hud > div:first-child {
    padding-left: 7px;
}

.flap-hud-icon {
    position: relative;
    flex: 0 0 auto;
    color: rgba(222, 246, 255, 0.92);
    font-size: 15px;
    font-weight: 900;
    line-height: 1;
    text-shadow: 0 1px 2px rgba(5, 55, 126, 0.42);
}

.flap-hud strong {
    position: relative;
    min-width: 0;
    color: #fff;
    font-size: 20px;
    line-height: 1.03;
    white-space: nowrap;
    text-shadow:
        0 1px 0 rgba(5, 36, 98, 0.72),
        0 2px 8px rgba(4, 60, 144, 0.28),
        0 0 12px rgba(255, 255, 255, 0.42);
}

.flap-hud > div:not(:first-child) strong {
    font-size: 16px;
}

.flap-hud strong.flap-hud-composite {
    display: inline-flex;
    align-items: baseline;
    justify-content: center;
    gap: 1px;
}

.flap-hud-number {
    line-height: 1;
}

.flap-hud-affix {
    flex: 0 0 auto;
    font-size: 0.8em;
    font-weight: 800;
    line-height: 1;
    opacity: 0.92;
}

.flap-hud-unit {
    margin-left: 1px;
    font-size: 0.78em;
}

.flap-hud-prefix {
    margin-right: 1px;
}

.flap-board-wrap {
    position: relative;
    overflow: hidden;
    padding: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

.flap-canvas {
    display: block;
    width: 100%;
    aspect-ratio: 0.62903226;
    border-radius: 0;
    background: #69d5ff;
    box-shadow: none;
    cursor: pointer;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.flap-overlay {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: grid;
    place-items: center;
    border-radius: 0;
    background: rgba(26, 38, 78, 0.22);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.flap-overlay[hidden] {
    display: none;
}

.flap-overlay-panel {
    display: grid;
    justify-items: center;
    gap: 12px;
    width: min(82%, 288px);
    padding: 20px 18px;
    border: 1px solid rgba(255, 255, 255, 0.78);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.88);
    box-shadow: 0 18px 42px rgba(30, 60, 120, 0.22);
}

.start-hero {
    display: grid;
    place-items: center;
    width: 92px;
    height: 92px;
}

.start-hero img {
    display: block;
    width: 78px;
    height: 78px;
    object-fit: contain;
}

.flap-overlay-panel > strong {
    color: var(--flap-ink);
    font-size: 24px;
    line-height: 1.15;
}

.flap-overlay-panel > span {
    color: var(--flap-blue);
    font-size: 11px;
    font-weight: 900;
}

#resultKicker {
    display: none;
}

.result-panel > strong {
    font-size: 20px;
    line-height: 1.18;
}

.flap-overlay-panel button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    border: 0;
    border-radius: 8px;
    color: #fff;
    font: inherit;
    font-size: 13px;
    font-weight: 900;
    text-decoration: none;
    background: var(--flap-pink);
    box-shadow: 0 7px 16px rgba(216, 100, 142, 0.18);
    cursor: pointer;
}

.flap-overlay-panel button {
    min-width: 112px;
    padding-right: 22px;
    padding-left: 22px;
}

.result-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    margin: 0;
}

.result-stats > div {
    min-width: 0;
    padding: 9px 10px;
    border-radius: 8px;
    background: #f8fbff;
}

.result-stats dt {
    margin: 0 0 2px;
    color: var(--flap-muted);
    font-size: 10px;
    font-weight: 900;
}

.result-stats dd {
    margin: 0;
    color: var(--flap-ink);
    font-size: 16px;
    font-weight: 900;
    line-height: 1.15;
}

.current-cast-button {
    position: absolute;
    top: 16px;
    left: 14px;
    z-index: 4;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    width: 50px;
    height: 42px;
    padding: 4px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.72);
    border-radius: 8px;
    color: var(--flap-ink);
    font: inherit;
    font-size: 13px;
    font-weight: 900;
    background:
        linear-gradient(145deg, rgba(255, 255, 255, 0.44), rgba(255, 255, 255, 0.12) 46%, rgba(112, 197, 255, 0.24)),
        rgba(22, 116, 218, 0.3);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.76),
        inset 0 -10px 18px rgba(20, 86, 171, 0.16),
        0 8px 20px rgba(8, 64, 154, 0.14);
    cursor: pointer;
}

.current-cast-button::before {
    content: "";
    position: absolute;
    inset: 1px 1px auto;
    height: 44%;
    border-radius: 7px 7px 16px 16px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.44), rgba(255, 255, 255, 0));
    pointer-events: none;
}

.current-cast-button img {
    position: relative;
    flex: 0 0 auto;
    display: block;
    width: 34px;
    height: 34px;
    object-fit: contain;
    filter: drop-shadow(0 1px 3px rgba(5, 55, 126, 0.18));
}

.current-cast-button span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cast-picker {
    display: flex;
    gap: 7px;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
}

.cast-picker::-webkit-scrollbar {
    display: none;
}

.cast-button {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
}

.cast-button[aria-pressed="true"] {
    border-color: var(--flap-green);
    background: rgba(238, 253, 245, 0.34);
}

.cast-button img {
    display: block;
    width: 34px;
    height: 34px;
    object-fit: contain;
}

.flap-modal {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    align-items: end;
    justify-items: center;
    padding: 16px 10px max(16px, env(safe-area-inset-bottom));
}

.flap-modal[hidden] {
    display: none;
}

.flap-modal-backdrop {
    position: absolute;
    inset: 0;
    border: 0;
    background: rgba(20, 24, 42, 0.34);
    cursor: pointer;
}

.flap-modal-panel {
    position: relative;
    z-index: 1;
    width: min(100%, 430px);
    max-height: 72vh;
    max-height: min(72svh, 420px);
    overflow: auto;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.72);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 18px 44px rgba(30, 60, 120, 0.24);
    backdrop-filter: blur(16px) saturate(1.08);
    -webkit-backdrop-filter: blur(16px) saturate(1.08);
}

.flap-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.flap-modal-head h2 {
    margin: 0;
    color: var(--flap-ink);
    font-size: 15px;
    line-height: 1.2;
}

.flap-modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    color: var(--flap-ink);
    background: #f3f4f6;
    cursor: pointer;
    box-sizing: border-box;
    flex-shrink: 0;
}


.cast-picker--modal {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
    gap: 8px;
    overflow: visible;
}

.cast-picker--modal .cast-button {
    display: flex;
    width: auto;
    height: auto;
    min-height: 58px;
    gap: 7px;
    justify-content: flex-start;
    padding: 8px;
    border-radius: 8px;
    color: var(--flap-ink);
    font: inherit;
    font-size: 12px;
    font-weight: 900;
    background: rgba(248, 251, 255, 0.86);
}

.cast-picker--modal .cast-button img {
    width: 38px;
    height: 38px;
}

.cast-picker--modal .cast-button span {
    min-width: 0;
    overflow: hidden;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.flap-global-panel {
    box-sizing: border-box;
    width: 100%;
    margin-top: 8px;
    padding: 10px;
}

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

.flap-global-panel-head span {
    color: var(--flap-ink);
    font-size: 13px;
    font-weight: 900;
}

.flap-global-panel-head small {
    min-width: 0;
    color: var(--flap-muted);
    font-size: 10px;
    font-weight: 800;
    text-align: right;
}

.flap-global-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin: 8px 0 0;
}

.flap-global-grid > div {
    min-width: 0;
    padding: 8px 9px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.58);
}

.flap-global-grid dt {
    margin: 0 0 2px;
    color: var(--flap-muted);
    font-size: 10px;
    font-weight: 900;
}

.flap-global-grid dd {
    margin: 0;
    color: var(--flap-ink);
    font-size: 16px;
    font-weight: 900;
    line-height: 1.15;
}

@media (max-width: 374px) {
    .flap-stage {
        width: 100%;
    }

    .flap-hud {
        top: 14px;
        right: 14px;
        left: 72px;
        grid-template-columns: minmax(52px, 1fr) minmax(40px, 0.75fr) minmax(46px, 0.88fr) minmax(40px, 0.62fr);
        gap: 5px;
    }

    .flap-hud > div {
        min-height: 40px;
        gap: 3px;
        padding-right: 5px;
        padding-left: 5px;
    }

    .flap-hud > div:first-child {
        padding-left: 5px;
    }

    .flap-hud-icon {
        font-size: 14px;
    }

    .flap-hud strong {
        font-size: 16px;
    }

    .flap-hud > div:not(:first-child) strong {
        font-size: 13px;
    }

    .current-cast-button {
        top: 14px;
        left: 13px;
        width: 46px;
        height: 40px;
    }

    .current-cast-button img {
        width: 32px;
        height: 32px;
    }

    .flap-global-grid dd {
        font-size: 15px;
    }
}

@media (max-height: 680px) {
    .flap-stage {
        width: 100%;
    }

    .flap-board-wrap {
        padding: 0;
    }

    .flap-overlay {
        inset: 0;
    }
}

.flap-modal-close .modal-close-icon {
    flex-shrink: 0;
    pointer-events: none;
    display: block;
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Male page only: keep the retry explanation compact and the touch target generous. */
.male-flap .result-panel {
    gap: 8px;
    max-height: 100%;
    overflow-y: auto;
    border-color: #edc972;
    box-shadow: inset 0 1px 0 #fff4c9, 0 12px 32px rgba(24, 42, 80, 0.24);
}
.male-flap #resultKicker {
    display: block;
    color: #946212;
    letter-spacing: 0.12em;
}
.male-flap .result-hint,
.male-flap .result-progress {
    margin: 0;
    font-size: 12px;
    line-height: 1.5;
    text-align: center;
}
.male-flap .result-progress {
    color: #835713;
    font-weight: 800;
}
.male-flap #retryButton {
    width: 100%;
    min-height: 48px;
    background: linear-gradient(135deg, #ba591f, #8d306e);
    border: 1px solid #ffe19b;
}
.male-flap .result-stats {
    gap: 5px;
}
.male-flap .result-stats > div {
    padding: 6px 8px;
}

.male-flap {
    --flap-side-bg: #e8eef6;
    --flap-gold: #ffe08a;
}
.male-flap .flap-shell {
    padding: 4px 0 max(10px, env(safe-area-inset-bottom));
}
.male-flap .flap-board-wrap {
    padding: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}
.male-flap .flap-overlay {
    inset: 0;
}
.male-flap .flap-hud {
    gap: 4px;
}
.male-flap .flap-hud > div {
    min-height: 38px;
    border-color: rgba(255, 224, 138, 0.5);
    background: linear-gradient(145deg, rgba(42, 69, 102, 0.94), rgba(17, 32, 57, 0.94));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 3px 7px rgba(14, 32, 54, 0.16);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}
.male-flap .flap-hud > div::before {
    display: none;
}
.male-flap .flap-hud > div:first-child {
    border-color: #ffe08a;
}
.male-flap .flap-hud > div:first-child strong,
.male-flap .flap-hud > div:first-child .flap-hud-icon {
    color: #ffe08a;
}
.male-flap .flap-hud > div:nth-child(2) .flap-hud-icon {
    color: #ff9cce;
}
.male-flap .result-medal {
    width: 100%;
    margin: 0;
    padding: 8px 6px;
    border: 1px solid #c8d4e4;
    border-radius: 8px;
    color: #294363;
    background: #eaf1f8;
    font-size: 12px;
    font-weight: 900;
    line-height: 1.4;
    text-align: center;
}
.male-flap .result-medal[data-rank="5"] {
    border-color: #d9a57a;
    background: #fff0e1;
    color: #875028;
}
.male-flap .result-medal[data-rank="10"] {
    border-color: #9ebad4;
    background: linear-gradient(120deg, #edf5ff, #fff, #d9e7f5);
}
.male-flap .result-medal[data-rank="20"] {
    border-color: #c99b36;
    color: #79530d;
    background: linear-gradient(120deg, #ffe08a, #fff8d9, #f9d373);
}
.male-flap .result-stats > div:first-child {
    background: #fff2cc;
}
.male-flap .result-stats > div:first-child dd {
    font-size: 22px;
    color: #775214;
}

/* Keep ranking secondary and its score feedback outside the action. */
.male-flap #resultOverlay .game-ranking-open {
    box-sizing: border-box;
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 44px;
    margin: 0;
    padding: 10px 12px;
    border: 1px solid currentColor;
    border-radius: 8px;
    color: var(--flap-ink);
    background: #fff;
    box-shadow: none;
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.5;
    text-align: center;
    text-shadow: none;
    letter-spacing: normal;
    white-space: normal;
    overflow-wrap: anywhere;
}

.male-flap #resultOverlay .game-ranking-open > span {
    margin: 0;
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
}

.male-flap #resultOverlay [data-game-ranking-feedback] {
    width: 100%;
    color: var(--flap-ink);
    text-align: center;
}

.male-flap #resultOverlay [data-game-ranking-feedback]:not(:has(.game-ranking-feedback:not([hidden]))) {
    display: none;
}

.male-flap #resultOverlay [data-game-ranking-feedback] .game-ranking-feedback {
    margin: 0;
    color: inherit;
    font-family: inherit;
    font-size: 12px;
    font-weight: 400;
    line-height: 1.5;
}

.male-flap #resultOverlay {
    align-items: safe center;
    min-height: 0;
}

.male-flap #resultOverlay > :first-child {
    box-sizing: border-box;
    min-width: 0;
    min-height: 0;
    max-height: 100%;
    overflow-y: auto;
    overscroll-behavior-y: contain;
}

/* Keep pause inside the ground strip; do not reduce the flight canvas. */
.flap-pause-button {
    position: absolute;
    right: 12px;
    bottom: 4px;
    z-index: 4;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 2px solid #fff;
    border-radius: 12px;
    background: #593e69;
    color: #fff;
    font: 900 24px sans-serif;
    cursor: pointer;
    touch-action: manipulation;
}
.male-flap .flap-pause-button {
    background: #152b47;
    border-color: #ffe08a;
    color: #ffe08a;
}
.flap-pause-button:focus-visible,
.flap-pause-overlay button:focus-visible {
    outline: 3px solid #f06cae;
    outline-offset: 2px;
}
.flap-pause-overlay { z-index: 6; }
.flap-pause-overlay button { min-height: 44px; }
.flap-effects {
    position: absolute;
    bottom: 4px;
    left: 12px;
    right: 66px;
    z-index: 3;
    display: flex;
    justify-content: flex-end;
    gap: 3px;
    pointer-events: none;
}
.flap-effects > span {
    flex: 0 0 auto;
    padding: 3px 5px;
    border-radius: 5px;
    background: #fff5fc;
    color: #493355;
    font: 700 10px/1.3 sans-serif;
    white-space: nowrap;
}
.male-flap .flap-effects > span {
    background: #152b47;
    color: #ffe08a;
}
.flap-pause-button[hidden], .flap-effects[hidden], .flap-effects > [hidden] { display: none; }

/* Keep the original touch board and compact HUD; the fixed captain needs no picker. */
.male-flap .flap-hud {
    left: 14px;
    grid-template-columns: minmax(60px, 1fr) minmax(48px, .75fr) minmax(56px, .9fr) minmax(44px, .62fr);
}
.male-flap .flap-hud > div:nth-child(2) .flap-hud-icon { color: #ffe08a; }
.flap-shell { align-content: start; min-height: 0; }
.dragon-instructions { margin: 0; font-size: 13px; line-height: 1.6; text-align: center; }
.flap-overlay-panel button { min-height: 44px; color: #2a2328; background: #f3f4f6; box-shadow: none; }
.male-flap #retryButton { color: #2a2328; background: #f3f4f6; border: 0; }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

.dragon-course-label { justify-self: start; font-size: 12px; font-weight: 700; }
.dragon-course-picker {
    width: 100%; min-height: 44px; padding: 8px;
    border: 1px solid #d9dce1; border-radius: 8px;
    color: #2a2328; background: #f3f4f6; font: inherit; font-size: 14px;
}
.dragon-course-name { margin: 0; color: #6e626a; font-size: 12px; text-align: center; }
.start-panel { max-height: 100%; overflow-y: auto; gap: 8px; }
.start-panel > strong { font-size: 20px; }
#changeCourseButton { width: 100%; }
