/* ===== 全域 ===== */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Shippori Mincho', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    background:
        radial-gradient(circle at 15% 20%, rgba(255, 214, 232, 0.55), transparent 40%),
        radial-gradient(circle at 85% 80%, rgba(207, 232, 255, 0.6), transparent 45%),
        linear-gradient(160deg, #fdf3ff 0%, #eef4ff 50%, #fff0f6 100%);
    background-attachment: fixed;
    padding: 20px;
}

button {
    font-family: 'Shippori Mincho', sans-serif;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
    outline: 3px solid rgba(92, 45, 145, 0.6);
    outline-offset: 2px;
}

/* ===== 遊戲畫布 ===== */
#gameCanvas {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 20px;
    box-shadow:
        0 20px 60px rgba(80, 30, 120, 0.25),
        0 4px 16px rgba(80, 30, 120, 0.15);
    border: 4px solid #fff;
    background: #fff;
}

/* ===== 音樂按鈕（圓形，中央音符） ===== */
#BGM {
    position: fixed;
    top: 18px;
    right: 18px;
    width: 60px;
    height: 60px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: linear-gradient(145deg, #7b4dff, #4a2bd0);
    color: #fff;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(74, 43, 208, 0.45);
    z-index: 100;
    transition: transform 0.3s ease, box-shadow 0.3s ease, background 0.3s ease;
}

#BGM:hover {
    transform: scale(1.12);
    box-shadow: 0 10px 28px rgba(74, 43, 208, 0.55);
}

#BGM:active {
    transform: scale(0.95);
}

#BGM.playing {
    background: linear-gradient(145deg, #ff5fa2, #d63b8a);
    box-shadow: 0 6px 22px rgba(214, 59, 138, 0.5);
}

#musicIcon {
    font-size: 22px;
    will-change: transform;
}

/* ===== 彈窗（共用底層） ===== */
.screen-overlay {
    position: fixed;
    inset: 0;
    display: none;
    justify-content: center;
    align-items: center;
    background-color: rgba(24, 15, 45, 0.6);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 1000;
    padding: 20px;
    text-align: center;
    animation: fadeIn 0.25s ease;
}

#customModal {
    z-index: 3000;
}

#customModal.modal-show {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ===== 彈窗面板 ===== */
.panel {
    background: linear-gradient(150deg, #ffffff 0%, #fdf3ff 100%);
    border-radius: 24px;
    padding: 34px 40px;
    box-shadow: 0 24px 70px rgba(40, 15, 80, 0.4);
    max-width: 560px;
    width: 100%;
    max-height: 88vh;
    overflow-y: auto;
    animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.panel h2 {
    margin: 0 0 12px;
    font-size: 34px;
    color: #4a2bd0;
}

.panel p {
    font-size: 22px;
    color: #3a2a5a;
    margin: 0 0 18px;
    line-height: 1.6;
    word-break: break-all;
}

/* ===== 按鈕群組 ===== */
.btn-row {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin: 10px 0;
}

.upload-row {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin: 14px 0;
}

/* ===== 氣泡按鈕 ===== */
.bubbly-button {
    font-family: 'Shippori Mincho', sans-serif;
    display: inline-block;
    font-size: 18px;
    padding: 0.55em 1.2em;
    margin: 0;
    -webkit-appearance: none;
    appearance: none;
    background-color: #ff0081;
    color: #fff;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    position: relative;
    transition: transform ease-in 0.1s, box-shadow ease-in 0.25s;
    box-shadow: 0 2px 25px rgba(255, 0, 130, 0.4);
}

.bubbly-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 30px rgba(255, 0, 130, 0.5);
}

.bubbly-button:focus {
    outline: 0;
}

.bubbly-button:before,
.bubbly-button:after {
    position: absolute;
    content: '';
    display: none;
    width: 140%;
    height: 100%;
    left: -20%;
    z-index: -1000;
    transition: all ease-in-out 0.5s;
    background-repeat: no-repeat;
}

.bubbly-button:before {
    top: -75%;
    background-image:
        radial-gradient(circle, #ff0081 20%, transparent 20%),
        radial-gradient(circle, transparent 20%, #ff0081 20%, transparent 30%),
        radial-gradient(circle, #ff0081 20%, transparent 20%),
        radial-gradient(circle, #ff0081 20%, transparent 20%),
        radial-gradient(circle, transparent 10%, #ff0081 15%, transparent 20%),
        radial-gradient(circle, #ff0081 20%, transparent 20%),
        radial-gradient(circle, #ff0081 20%, transparent 20%),
        radial-gradient(circle, #ff0081 20%, transparent 20%),
        radial-gradient(circle, #ff0081 20%, transparent 20%);
    background-size: 10% 10%, 20% 20%, 15% 15%, 20% 20%, 18% 18%, 10% 10%, 15% 15%, 10% 10%, 18% 18%;
}

.bubbly-button:after {
    bottom: -75%;
    background-image:
        radial-gradient(circle, #ff0081 20%, transparent 20%),
        radial-gradient(circle, #ff0081 20%, transparent 20%),
        radial-gradient(circle, transparent 10%, #ff0081 15%, transparent 20%),
        radial-gradient(circle, #ff0081 20%, transparent 20%),
        radial-gradient(circle, #ff0081 20%, transparent 20%),
        radial-gradient(circle, #ff0081 20%, transparent 20%),
        radial-gradient(circle, #ff0081 20%, transparent 20%);
    background-size: 15% 15%, 20% 20%, 18% 18%, 20% 20%, 15% 15%, 10% 10%, 20% 20%;
}

.bubbly-button:active {
    transform: scale(0.9);
    background-color: #d1006e;
    box-shadow: 0 2px 25px rgba(255, 0, 130, 0.2);
}

.bubbly-button.animate:before {
    display: block;
    animation: topBubbles ease-in-out 0.75s forwards;
}

.bubbly-button.animate:after {
    display: block;
    animation: bottomBubbles ease-in-out 0.75s forwards;
}

.bubbly-button.disabled {
    background-color: #aaa;
    box-shadow: none;
    cursor: not-allowed;
}

@keyframes topBubbles {
    0% {
        background-position: 5% 90%, 10% 90%, 10% 90%, 15% 90%, 25% 90%, 25% 90%, 40% 90%, 55% 90%, 70% 90%;
    }
    50% {
        background-position: 0% 80%, 0% 20%, 10% 40%, 20% 0%, 30% 30%, 22% 50%, 50% 50%, 65% 20%, 90% 30%;
    }
    100% {
        background-position: 0% 70%, 0% 10%, 10% 30%, 20% -10%, 30% 20%, 22% 40%, 50% 40%, 65% 10%, 90% 20%;
        background-size: 0% 0%, 0% 0%, 0% 0%, 0% 0%, 0% 0%, 0% 0%;
    }
}

@keyframes bottomBubbles {
    0% {
        background-position: 10% -10%, 30% 10%, 55% -10%, 70% -10%, 85% -10%, 70% -10%, 70% 0%;
    }
    50% {
        background-position: 0% 80%, 20% 80%, 45% 60%, 60% 100%, 75% 70%, 95% 60%, 105% 0%;
    }
    100% {
        background-position: 0% 90%, 20% 90%, 45% 70%, 60% 110%, 75% 80%, 95% 70%, 110% 10%;
        background-size: 0% 0%, 0% 0%, 0% 0%, 0% 0%, 0% 0%, 0% 0%;
    }
}

/* ===== 暱稱輸入框 ===== */
#nicknameInput {
    width: 240px;
    padding: 11px 14px;
    font-size: 16px;
    border: 2px solid #ddd;
    border-radius: 12px;
    outline: none;
    transition: all 0.3s ease;
}

#nicknameInput:focus {
    border-color: #5c9bf7;
    box-shadow: 0 0 10px rgba(92, 159, 247, 0.5);
}

#nicknameInput::placeholder {
    color: #999;
    font-style: italic;
}

#nicknameInput:hover {
    border-color: #b0b0b0;
}

/* ===== 排行榜 ===== */
#leaderboardScreen ul {
    list-style-type: none;
    padding: 0;
    margin: 0;
}

#leaderboardScreen li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid #f0e6fa;
    font-size: 18px;
    color: #3a2a5a;
}

#leaderboardScreen li:last-child {
    border-bottom: none;
}

#leaderboardScreen li:nth-child(even) {
    background: rgba(124, 77, 255, 0.05);
    border-radius: 10px;
}

#leaderboardScreen li .rank {
    min-width: 42px;
    font-weight: bold;
    color: #7b4dff;
}

#leaderboardScreen li .name {
    flex: 1;
    text-align: left;
}

#leaderboardScreen li .pts {
    color: #d63b8a;
    font-weight: bold;
    white-space: nowrap;
}

#leaderboardScreen li.empty {
    justify-content: center;
    color: #999;
    font-style: italic;
}

.closeLeaderboard {
    position: absolute;
    top: 14px;
    right: 14px;
    background: #ff4747;
    color: white;
    border: none;
    width: 38px;
    height: 38px;
    line-height: 1;
    cursor: pointer;
    font-size: 16px;
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(255, 71, 71, 0.35);
    transition: background 0.3s ease, transform 0.3s ease;
}

.closeLeaderboard:hover {
    background: #ff3030;
    transform: scale(1.12) rotate(90deg);
}

.closeLeaderboard:active {
    transform: scale(0.95);
}

/* ===== 分享彈窗 ===== */
.share-url-text {
    font-size: 14px !important;
    color: #777 !important;
    background: #f4f0fa;
    border-radius: 8px;
    padding: 8px 12px;
    word-break: break-all;
}

#shareOptions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin: 16px 0 20px;
}

.share-option {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-width: 220px;
    text-decoration: none;
    color: #fff;
    font-size: 17px;
    background: linear-gradient(145deg, #7b4dff, #4a2bd0);
    padding: 11px 20px;
    border-radius: 30px;
    box-shadow: 0 4px 14px rgba(74, 43, 208, 0.35);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.share-option:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(74, 43, 208, 0.45);
}

.share-option i {
    font-size: 20px;
}

/* ===== 自訂提示彈窗 ===== */
.modal-box {
    max-width: 380px;
    padding: 28px 30px;
}

.modal-box p {
    margin: 0 0 22px;
    font-size: 20px;
}

/* ===== 頁尾 ===== */
footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    text-align: center;
    background: linear-gradient(180deg, rgba(30, 20, 55, 0.85), rgba(20, 12, 40, 0.95));
    backdrop-filter: blur(4px);
    padding: 10px;
    z-index: 500;
}

#returnButton {
    font-size: 16px;
    padding: 8px 18px;
    background-color: #ffcc00;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    color: #000;
    font-weight: bold;
    transition: background-color 0.3s ease, transform 0.2s ease;
}

#returnButton:hover {
    background-color: #ffaa00;
    transform: scale(1.05);
}

#copyright {
    font-size: 13px;
    color: #cfc5e6;
    margin: 5px 0 0;
}

@media (max-width: 640px) {
    .panel {
        padding: 24px 18px;
    }

    .panel h2 {
        font-size: 26px;
    }

    .panel p {
        font-size: 18px;
    }

    .bubbly-button {
        font-size: 16px;
    }

    #nicknameInput {
        width: 100%;
    }
}
