:root {
    --color-bg-start: #f3e5f5;
    --color-bg-end: #e8d5f2;
    --color-panel: rgba(255, 255, 255, 0.95);
    --color-border: #c8a8d8;
    --color-text: #4a2c5a;
    --color-correct: #66bb6a;
    --color-present: #ffb74d;
    --color-absent: #b0bec5;
    --color-accent: #9c27b0;
    --color-tile-bg: #ffffff;
    --color-tile-border: #d1c4e9;
    --color-key-bg: #f3e5f5;
    --color-key-text: #151515;
}

* {
    box-sizing: border-box;
}

html {
    background-color: #E9E7E0;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #E9E7E0;
    color: #ffffff;
    display: flex;
    justify-content: center;
}

body.modal-open {
    overflow: hidden;
    touch-action: none;
    height: 100%;
    overscroll-behavior: contain;
}

.hidden {
    display: none !important;
}

.home-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: url('assets/bgstart.png') no-repeat center center;
    background-size: cover;
    background-color: #E9E7E0;
    padding: 48px 16px;
    text-align: center;
    z-index: 20;
    overflow: hidden;
}

.home-content {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 32px;
    max-width: 320px;
    width: 100%;
    z-index: 1;
}

.home-title {
    margin: 0;
    font-size: clamp(2.5rem, 8vw, 3.5rem);
    font-weight: 900;
    letter-spacing: 0.08em;
    color: #1f1f1f;
    text-shadow: 0 6px 12px rgba(0, 0, 0, 0.18);
}

.home-start-button {
    width: min(280px, 80vw);
    height: 64px;
    border: none;
    border-radius: 999px;
    font-size: 1.2rem;
    font-weight: 700;
    color: #ffffff;
    background: url('assets/btngreen.png') no-repeat center center;
    background-size: 100% 100%;
    cursor: pointer;
    box-shadow: 0 12px 16px rgba(0, 0, 0, 0.12);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.home-start-button:hover,
.home-start-button:focus {
    transform: translateY(-2px);
    box-shadow: 0 16px 20px rgba(0, 0, 0, 0.16);
    outline: none;
}

.home-start-button:active {
    transform: translateY(0);
    box-shadow: 0 10px 14px rgba(0, 0, 0, 0.18);
}

.game-container {
    width: min(100%, 520px);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 0;
    background: #E9E7E0;
    gap: 0;
    position: relative;
}

/* 上方背景图片区域 */
.game-header {
    min-height: 210px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 16px 18px 12px;
    padding-top: calc(constant(safe-area-inset-top) + 16px);
    padding-top: calc(env(safe-area-inset-top, 0) + 16px);
    background-image: url('assets/bgheader.png');
    background-position: top center;
    background-repeat: no-repeat;
    background-size: cover;
    position: relative;
    box-sizing: border-box;
}

/* 游戏内容区域 */
.game-content {
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 20px 18px 28px;
    gap: 8px;
    flex: 1;
}

.info-bar {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    width: 100%;
    max-width: 460px;
    flex: 1;
    height: 100%;
}

.info-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.game-title-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 12px;
}

.game-title-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.game-title-group .user-profile,
.game-title-group .rank-button {
    align-self: flex-end;
}

.user-profile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: 0;
    text-align: center;
}

.user-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.12);
    border: 2px solid rgba(255, 255, 255, 0.8);
}

.user-name {
    font-size: 1rem;
    font-weight: 700;
    color: #3b2c4f;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
    text-align: center;
}

.game-title {
    margin: 0;
    font-family: "SF Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-weight: 900;
    font-style: normal;
    font-size: 28px;
    line-height: 1;
    letter-spacing: 0;
    text-align: center;
    color: #151515;
    leading-trim: none;
    text-shadow: none;
    flex: none;
}

.info-button {
    width: 24px;
    height: 24px;
    border: none;
    background-color: transparent;
    background-image: url('assets/infor.png');
    background-repeat: no-repeat;
    background-position: center;
    background-size: 16px 16px;
    cursor: pointer;
    padding: 0;
    margin: 0;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.info-button:hover,
.info-button:focus-visible {
    transform: scale(1.05);
    outline: none;
}

.rank-button {
    width: 52px;
    height: 52px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 50%;
    background-color: #ffffff;
    background-image: url('assets/rank.png');
    background-repeat: no-repeat;
    background-position: center;
    background-size: 40px 40px;
    cursor: pointer;
    box-shadow: none;
    transition: transform 0.2s ease, filter 0.2s ease;
    padding: 0;
    flex-shrink: 0;
}

.rank-button:hover,
.rank-button:focus-visible {
    transform: translateY(-2px);
    filter: brightness(0.95);
    outline: none;
}

.rank-button:focus {
    outline: none;
}

.rank-button:active {
    transform: translateY(0);
    filter: brightness(0.9);
}

.game-message {
    font-size: 0.95rem;
    color: var(--color-text);
    min-height: 24px;
    text-align: center;
    background: rgba(255, 255, 255, 0.8);
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid var(--color-border);
    box-shadow: none;
}

.leaderboard-screen {
    position: fixed;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: stretch;
    background: #E9E7E0;
    z-index: 30;
    overflow: hidden;
}

.leaderboard-screen--scrollable {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    scrollbar-width: none;
}

.leaderboard-screen--scrollable::-webkit-scrollbar {
    width: 0;
    height: 0;
}

.leaderboard-wrapper {
    width: min(520px, 100vw);
    height: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    background: #E9E7E0;
    min-height: 0;
    overflow: hidden;
}

.leaderboard-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: clamp(180px, 22vh, 210px);
    padding: calc(env(safe-area-inset-top, 0) + 16px) clamp(18px, 6vw, 24px) clamp(18px, 6vw, 24px);
    background: url('assets/bgheader.png') no-repeat top center;
    background-size: cover;
}

.round-back-button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background-color: #ffffff;
    background-image: url('assets/back.png');
    background-repeat: no-repeat;
    background-position: center;
    background-size: 60%;
    cursor: pointer;
    padding: 0;
    box-shadow: none;
    overflow: visible;
    z-index: 1;
    transition: filter 0.2s ease;
}

.round-back-button:focus {
    outline: none;
    filter: brightness(0.92);
}

.round-back-button:hover {
    filter: brightness(0.9);
}

.leaderboard-back-button {
    position: absolute;
    top: 50%;
    left: clamp(16px, 5vw, 24px);
    transform: translateY(-50%);
}

.leaderboard-back-button::after,
.leaderboard-back-button::before {
    content: none;
}

.leaderboard-title {
    margin: 0;
    font-size: 1.75rem;
    font-weight: 900;
    color: #1f1f1f;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    text-align: center;
    width: 100%;
}

@media (max-width: 1024px) {
    .leaderboard-title {
        font-size: 1.8rem;
    }
}

@media (max-width: 768px) {
    .leaderboard-title {
        font-size: 1.6rem;
        letter-spacing: 0.08em;
    }
}

.leaderboard-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0 20px calc(24px + env(safe-area-inset-bottom, 0));
    min-height: 0;
    overflow: hidden;
}

.info-screen {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 35;
    pointer-events: none;
}

.info-screen:not(.hidden) {
    pointer-events: auto;
}

.info-screen-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
}

.info-rule-sheet {
    position: relative;
    width: min(340px, 92%);
    max-height: calc(100% - 48px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1;
}

.info-rule-image {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 18px;
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.25);
}

.info-dismiss-button {
    position: absolute;
    top: clamp(8px, 3vw, 16px);
    right: clamp(8px, 3vw, 16px);
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.92);
    color: #151515;
    font-size: 20px;
    font-weight: 600;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
    cursor: pointer;
    transition: filter 0.2s ease;
}

.info-dismiss-button:hover,
.info-dismiss-button:focus-visible {
    filter: brightness(0.95);
    outline: none;
}

.leaderboard-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 24px 0;
    min-height: 0;
    overflow: hidden;
}

.leaderboard-loading,
.leaderboard-empty {
    padding: 32px 12px;
    text-align: center;
    font-size: 1rem;
    color: rgba(47, 47, 47, 0.7);
}

.leaderboard-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding-right: 6px;
    width: 100%;
    scrollbar-width: none;
    scrollbar-color: transparent transparent;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.leaderboard-list::-webkit-scrollbar {
    width: 0;
    height: 0;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
}

.leaderboard-rank {
    width: 28px;
    text-align: center;
    font-size: 1rem;
    font-weight: 700;
    color: #d17c00;
}

.leaderboard-item:nth-child(1) .leaderboard-rank {
    color: #f9a825;
}

.leaderboard-item:nth-child(2) .leaderboard-rank {
    color: #a3a8b3;
}

.leaderboard-item:nth-child(3) .leaderboard-rank {
    color: #ce7d45;
}

.leaderboard-card {
    flex: 1;
    width: 100%;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    column-gap: clamp(12px, 3vw, 16px);
    padding: 12px 18px;
    border-radius: 20px;
    background: url('assets/bglist.png') center/cover no-repeat;
    box-shadow: none;
    border: none;
}

.leaderboard-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid rgba(0, 0, 0, 0.05);
    display: block;
}

.leaderboard-info {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    column-gap: clamp(10px, 2.6vw, 16px);
    min-width: 0;
}

.leaderboard-name-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 1rem;
    font-weight: 700;
    color: #1f1f1f;
    min-width: 0;
}

.leaderboard-name {
    font-weight: 700;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard-vip-icon {
    height: 18px;
    width: auto;
}

.leaderboard-stats {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    min-width: 96px;
    padding-left: clamp(8px, 2vw, 14px);
    text-align: right;
}

.leaderboard-stat-label {
    font-weight: 600;
    white-space: nowrap;
    font-size: 0.9rem;
    color: rgba(47, 47, 47, 0.7);
    text-align: right;
}

.leaderboard-stat-value {
    font-weight: 700;
    font-family: "SF Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-style: normal;
    font-size: clamp(1.15rem, 4vw, 1.4rem);
    line-height: 1.2;
    letter-spacing: -0.2px;
    text-align: right;
    color: #00D387;
    leading-trim: none;
    white-space: nowrap;
    min-width: 47px;
    min-height: 21px;
    font-variant-numeric: tabular-nums;
}

.summary-level,
.summary-time {
    font-family: "SF Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-weight: 700;
    font-style: normal;
    font-size: 16px;
    line-height: 21px;
    letter-spacing: -0.4px;
    text-align: center;
    color: #00D387;
    leading-trim: none;
}

.board {
    width: min(100%, 375px);
    margin: 0 auto;
    padding: 20.5px clamp(0px, calc((100% - 272px) / 2), 51.5px);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: none;
}

.board-row {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    column-gap: 8px;
}

.tile {
    aspect-ratio: 1;
    border-radius: 8px;
    border: none;
    background: url('assets/word1.png') no-repeat center center;
    background-size: cover;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.5rem, 7.4vw, 1.6rem);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0;
    transition: border-color 0.2s ease, background-color 0.2s ease, transform 0.2s ease;
    will-change: transform;
    box-shadow: none;
}

.tile.active {
    box-shadow: none;
}

.tile.correct {
    background: url('assets/word4.png') no-repeat center center;
    background-size: cover;
    color: #ffffff;
}

.tile.hint-letter {
    border: 1px solid rgba(0, 211, 135, 0.6);
}

.tile.present {
    background: url('assets/word3.png') no-repeat center center;
    background-size: cover;
    color: #ffffff;
}

.tile.absent {
    background: url('assets/word2.png') no-repeat center center;
    background-size: cover;
    color: #8F8F8F;
}

.tile.flip {
    animation: flip 0.45s ease;
}

@keyframes flip {
    0% {
        transform: rotateX(0);
    }
    50% {
        transform: rotateX(-90deg);
    }
    100% {
        transform: rotateX(0);
    }
}

.board-row.shake {
    animation: shake 0.32s ease;
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(-6px);
    }
    75% {
        transform: translateX(6px);
    }
}

.keyboard {
    --keyboard-key-width: 32px;
    --keyboard-wide-key-width: 54px;
    --keyboard-prop-size: 44px;
    --keyboard-submit-width: 195px;
    --keyboard-key-height: 48px;
    width: min(100%, 375px);
    min-height: 248px;
    margin: 16px auto 0;
    padding: 2px 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 6px;
    background: none;
    box-sizing: border-box;
}

.keyboard-row {
    --keyboard-key-gap: clamp(0px, (100% - (var(--keyboard-key-width) * 10)) / 9, 12px);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;
    width: 100%;
    gap: var(--keyboard-key-gap);
}

.keyboard-row.submit-row {
    gap: 0;
}

.key-button {
    flex: 0 0 auto;
    width: var(--keyboard-key-width);
    height: var(--keyboard-key-height);
    border-radius: 8px;
    border: none;
    background: url('assets/key1.png') no-repeat center center;
    background-size: cover;
    color: var(--color-key-text);
    font-family: "SF Compact Rounded", "SF Pro Rounded", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-weight: 700;
    font-style: normal;
    font-size: 24px;
    line-height: 25px;
    letter-spacing: -0.2px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    padding: calc(var(--keyboard-key-height) * (10 / 48)) 0 calc(var(--keyboard-key-height) * (13 / 48));
    margin: 0;
    leading-trim: none;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    box-shadow: none;
}

.key-button.tap-feedback:not(.correct):not(.present):not(.absent):not([data-key="DEL"]):not(.submit-button) {
    background: url('assets/key3.png') no-repeat center center;
    background-size: cover;
}

.key-button.wide {
    width: var(--keyboard-wide-key-width);
}

.key-button[data-key="DEL"] {
    background-image: url('assets/del.png');
    background-size: cover;
    color: transparent;
    font-size: 0;
}

.submit-row {
    margin-top: 0;
}

/* 道具按钮容器 */
.submit-controls {
    --submit-spacing: clamp(0px, (100% - (var(--keyboard-prop-size) * 2 + var(--keyboard-submit-width))) / 4, 25px);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: var(--submit-spacing);
    padding: 0 var(--submit-spacing);
    margin: 0;
    width: 100%;
}

.prop-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: var(--keyboard-prop-size);
}

.prop-label {
    font-family: "SF Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-weight: 400;
    font-style: normal;
    font-size: 8px;
    line-height: 11px;
    letter-spacing: 0;
    color: #151515;
    text-align: center;
    display: block;
}

/* 道具按钮基本样式 */
.prop-button {
    width: var(--keyboard-prop-size);
    height: var(--keyboard-prop-size);
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    background-repeat: no-repeat;
    background-position: center center;
    background-size: cover;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    box-shadow: none;
    transition: transform 0.2s ease;
}

.prop-button:hover {
    transform: translateY(-2px);
    box-shadow: none;
}

.prop-button:active {
    transform: translateY(0);
    box-shadow: none;
}

/* 左侧道具按钮 */
.prop-button.left {
    background-image: url('assets/hinta.png');
}

/* 右侧道具按钮 */
.prop-button.right {
    background-image: url('assets/hinte.png');
}

/* 角标样式 */
.prop-button .badge {
    position: absolute;
    top: -8px;
    right: -8px;
    min-width: 18px;
    height: 18px;
    padding: 0 3px;
    background-color: #ff6961;
    border-radius: 999px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    box-shadow: none;
    pointer-events: none;
    z-index: 1;
}

.prop-button .badge.badge-ad {
    background-color: #00d387;
    color: #083e27;
    font-size: 0.65rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.prop-button.is-animating {
    animation: propPulse 0.3s ease;
}

@keyframes propPulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.12);
    }
    100% {
        transform: scale(1);
    }
}

.key-button.prop-disabled {
    filter: saturate(0.7);
}

.key-button.prop-eliminate {
    animation: propEliminate 0.45s ease forwards;
}

@keyframes propEliminate {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(0, 211, 135, 0);
    }
    45% {
        transform: scale(1.12);
        box-shadow: 0 0 20px 0 rgba(0, 211, 135, 0.6);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(0, 211, 135, 0);
    }
}

.key-button.submit-button {
    width: var(--keyboard-submit-width);
    height: 64px;
    background: url('assets/submit.png') no-repeat center center;
    background-size: cover;
    border: none;
    padding: 0;
    margin: 0;
    flex: none;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1;
    color: transparent;
    font-size: 0;
    letter-spacing: normal;
    transition: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    box-shadow: none;
}

.key-button.submit-button:hover:not(:disabled) {
    background: url('assets/submit.png') no-repeat center center;
    background-size: cover;
    transform: none;
    box-shadow: none;
}

.key-button.submit-button:disabled {
    cursor: not-allowed;
    background: url('assets/submit.png') no-repeat center center;
    background-size: cover;
}

.key-button.submit-button.is-not-word {
    background: url('assets/notaword.png') no-repeat center center;
    background-size: cover;
}

.key-button.submit-button.is-not-word:disabled {
    background: url('assets/notaword.png') no-repeat center center;
    background-size: cover;
}

.key-button:hover:not(.submit-button):not([data-key="DEL"]) {
    transform: translateY(-1px) scale(1.01);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}

.key-button:active:not(.submit-button):not([data-key="DEL"]) {
    background: url('assets/key2.png') no-repeat center center;
    background-size: cover;
    transform: scale(0.94);
    box-shadow: 0 14px 22px rgba(0, 0, 0, 0.24);
}

@media (hover: none) {
    .key-button:hover:not(.submit-button):not([data-key="DEL"]) {
        transform: none;
        box-shadow: none;
    }

    .key-button:active:not(.submit-button):not([data-key="DEL"]) {
        transform: scale(0.9);
        box-shadow: 0 18px 28px rgba(0, 0, 0, 0.28);
    }
}

.key-button.correct {
    background: url('assets/key5.png') no-repeat center center;
    background-size: cover;
    color: #ffffff;
}

.key-button.present {
    background: url('assets/key4.png') no-repeat center center;
    background-size: cover;
    color: #ffffff;
}

.key-button.absent {
    background: url('assets/key2.png') no-repeat center center;
    background-size: cover;
    color: #8F8F8F;
}

.key-button:disabled:not(.submit-button):not([data-key="DEL"]) {
    background: url('assets/key2.png') no-repeat center center;
    background-size: cover;
    color: #8F8F8F;
    cursor: not-allowed;
    pointer-events: none;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    padding: 0;
    background: rgba(0, 0, 0, 0.78);
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 999;
}

.modal-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.modal-dialog {
    flex: 1;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
}

.modal-card {
    --modal-padding-block: clamp(48px, 12vh, 110px);
    --modal-padding-inline: clamp(20px, 7vw, 64px);
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(24px, 7vh, 40px);
    padding: calc(var(--modal-padding-block) + env(safe-area-inset-top, 0))
             calc(var(--modal-padding-inline) + env(safe-area-inset-right, 0))
             calc(var(--modal-padding-block) + env(safe-area-inset-bottom, 0))
             calc(var(--modal-padding-inline) + env(safe-area-inset-left, 0));
    background: url('assets/bgwin.png') center/cover no-repeat;
    position: relative;
    overflow: hidden;
}

.modal-card::before {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(15, 24, 38, 0.72);
    z-index: 0;
}

.modal-card > * {
    position: relative;
    z-index: 1;
}

.modal-title {
    margin: 0;
    font-size: clamp(2.2rem, 8vw, 3.4rem);
    font-weight: 900;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #f5f7ff;
    text-shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
}

.modal-word {
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: min(323px, 86vw);
    aspect-ratio: 323 / 90;
    border-radius: clamp(20px, 5vw, 28px);
    position: relative;
}

.modal-overlay.is-victory .modal-word {
    background: url('assets/bgwin.png') center/cover no-repeat;
}

.modal-word-label {
    margin: 0;
    position: absolute;
    top: -42px;
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
    font-size: clamp(1.1rem, 3.6vw, 1.6rem);
    font-weight: 700;
    color: #f5f7ff;
    letter-spacing: 0.04em;
    text-transform: none;
}

.modal-word-value {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 clamp(4px, 1vw, 12px);
    font-family: "SF Compact Rounded", "SF Pro Rounded", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-weight: 700;
    font-style: normal;
    font-size: clamp(2.8rem, 11vw, 3.75rem);
    line-height: 1;
    letter-spacing: -0.4px;
    text-transform: uppercase;
    text-align: center;
    color: #00d387;
}

.modal-completion {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #f5f7ff;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.modal-overlay.is-failure .modal-card::before {
    background: rgba(15, 24, 38, 0.82);
}

.modal-overlay.is-failure .modal-word {
    background: none;
    width: min(343px, 90vw);
    aspect-ratio: 343 / 72;
}

.modal-overlay.is-failure .modal-word-value {
    font-size: clamp(2.4rem, 10vw, 3.6rem);
    color: #f7f9ff;
}

.modal-overlay.is-failure .modal-word-label {
    color: #f7f9ff;
}

.modal-actions {
    width: min(360px, 86vw);
    display: flex;
    flex-direction: column;
    gap: 18px;
    align-items: center;
    margin-top: auto;
    padding-bottom: clamp(32px, 10vh, 72px);
}

.modal-button {
    width: min(280px, 82vw);
    height: 58px;
    border: none;
    border-radius: 999px;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    background-size: 100% 100%;
    background-repeat: no-repeat;
    background-position: center;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.modal-button:hover,
.modal-button:focus {
    transform: translateY(-2px);
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.3);
    outline: none;
}

.modal-button:active {
    transform: translateY(0);
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
}

.modal-button-share {
    background-image: url('assets/btnwhite.png');
    color: #0aa86a;
    gap: 12px;
}

.modal-button-primary {
    background-image: url('assets/btngreen.png');
    color: #ffffff;
}

.modal-button-icon {
    width: 22px;
    height: 22px;
    object-fit: contain;
    display: block;
}

.modal-button-label {
    display: inline-block;
}

@media (max-width: 768px) {
    .game-header {
        min-height: 180px;
        padding: 14px 12px;
        padding-top: calc(constant(safe-area-inset-top) + 14px);
        padding-top: calc(env(safe-area-inset-top, 0) + 14px);
    }
    
    .game-content {
        padding: 12px 8px 20px;
        gap: 6px;
    }

    .tile {
        font-size: clamp(1rem, 4vw, 1.3rem);
    }

    .prop-button .badge {
        width: 18px;
        height: 18px;
        font-size: 0.65rem;
        top: -6px;
        right: -6px;
    }

    .game-title {
        font-size: 1.8rem;
    }

    .user-avatar {
        width: 40px;
        height: 40px;
    }

    .user-name {
        max-width: 110px;
        font-size: 0.95rem;
    }

    .rank-button {
        width: 42px;
        height: 42px;
    }

    .leaderboard-main {
        padding: 0 16px calc(20px + env(safe-area-inset-bottom, 0));
    }

    .leaderboard-body {
        padding: 20px 0;
    }

    .leaderboard-card {
        padding: 12px 14px;
    }

    .leaderboard-avatar {
        width: 48px;
        height: 48px;
    }

    .game-message {
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .game-header {
        min-height: 150px;
        padding: 12px 10px;
        padding-top: calc(constant(safe-area-inset-top) + 12px);
        padding-top: calc(env(safe-area-inset-top, 0) + 12px);
    }
    
    .game-content {
        padding: 10px 6px 16px;
        gap: 5px;
    }

    .tile {
        font-size: clamp(1.5rem, 7.4vw, 1.6rem);
    }

    .prop-button .badge {
        width: 18px;
        height: 18px;
        font-size: 0.65rem;
        top: -5px;
        right: -5px;
    }

    .game-title {
        font-size: 1.6rem;
    }

    .user-avatar {
        width: 36px;
        height: 36px;
    }

    .user-name {
        max-width: 96px;
        font-size: 0.9rem;
    }

    .rank-button {
        width: 38px;
        height: 38px;
    }

    .leaderboard-header {
        padding: calc(env(safe-area-inset-top, 12px) + 10px) 16px 12px;
    }

    .leaderboard-main {
        padding: 0 14px calc(16px + env(safe-area-inset-bottom, 0));
    }

    .leaderboard-body {
        padding: 18px 0;
    }

    .leaderboard-card {
        padding: 10px 12px;
        border-radius: 18px;
    }

    .leaderboard-avatar {
        width: 44px;
        height: 44px;
    }

}
