* {
    box-sizing: border-box;
}

html,
body {
    width: var(--app-width, 100vw);
    height: var(--app-height, 100vh);
    margin: 0;
    padding: 0;
    overflow: hidden;
    overscroll-behavior: none;
    font-family: "Comic Sans MS", "YouYuan", "Microsoft YaHei", sans-serif;
    color: #23412d;
    background: #dff2dd;
    position: fixed;
    inset: 0;
}

#game-shell {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--app-width, 100vw);
    height: var(--app-height, 100vh);
    overflow: hidden;
    touch-action: none;
}

body.keyboard-open .player-form {
    width: min(calc(100vw - 32px), 342px);
}

body.keyboard-open .rank-panel {
    opacity: .28;
    pointer-events: none;
}

body.keyboard-open .modal-backdrop {
    align-items: start;
    place-items: start center;
    height: var(--visual-height, var(--app-height, 100vh));
    padding-top: max(14px, env(safe-area-inset-top));
    overflow-y: auto;
}

canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    touch-action: none;
}

.home-screen {
    position: absolute;
    z-index: 3;
    inset: 0;
    display: grid;
    align-items: center;
    justify-items: center;
    padding: 0 28px;
    background-color: #bfe7d4;
    background-image: url("home.webp");
    background-position: center;
    background-repeat: no-repeat;
    background-size: auto 100%;
}

.home-content {
    width: min(78vw, 292px);
    display: grid;
    justify-items: center;
    gap: 12px;
    margin-top: 112px;
}

.home-start-button {
    width: 100%;
    min-height: 54px;
    font-size: 22px;
}

.rules-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
    color: #31523a;
    font-size: 12px;
    line-height: 1.35;
    background: rgba(255, 252, 226, .88);
    border: 3px solid rgba(255, 255, 245, .94);
    border-radius: 10px;
    box-shadow:
        0 3px 0 rgba(126, 132, 78, .42),
        0 9px 18px rgba(50, 85, 58, .16);
    backdrop-filter: blur(4px);
}

.rules-table th,
.rules-table td {
    padding: 7px 8px;
    border-bottom: 1px solid rgba(126, 143, 86, .24);
    text-align: left;
    vertical-align: middle;
}

.rules-table tr:last-child th,
.rules-table tr:last-child td {
    border-bottom: 0;
}

.rules-table th {
    width: 26%;
    color: #6f7746;
    font-weight: 800;
    white-space: nowrap;
}

.rules-table td {
    font-weight: 700;
}

.hud {
    position: absolute;
    z-index: 2;
    border: 3px solid rgba(255, 255, 245, .96);
    border-radius: 12px;
    background: rgba(247, 244, 214, .82);
    box-shadow:
        0 3px 0 rgba(126, 132, 78, .48),
        0 10px 22px rgba(50, 85, 58, .18);
    backdrop-filter: blur(4px);
}

.top-hud {
    top: max(10px, env(safe-area-inset-top));
    left: 12px;
    right: 12px;
    min-width: 0;
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
}

#health {
    display: flex;
    gap: 2px;
    min-width: 72px;
    color: #e85245;
    font-size: 24px;
    line-height: 1;
    text-shadow:
        0 2px 0 rgba(255, 255, 245, .95),
        0 3px 3px rgba(99, 74, 47, .18);
}

.heart.lost {
    color: rgba(111, 119, 70, .42);
    transform: scale(.9);
    text-shadow: 0 2px 0 rgba(255, 255, 245, .75);
}

.score-pill,
.timer-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-width: 74px;
    font-weight: 700;
    white-space: nowrap;
    text-align: center;
    color: #fffef2;
    text-shadow:
        -1px -1px 0 #6f7746,
        1px -1px 0 #6f7746,
        -1px 1px 0 #6f7746,
        1px 1px 0 #6f7746,
        0 2px 0 rgba(68, 78, 43, .55);
}

.hud-icon {
    width: 25px;
    height: 25px;
    flex: 0 0 25px;
    background-position: center;
    background-repeat: no-repeat;
    background-size: contain;
    filter: drop-shadow(0 2px 0 rgba(255, 255, 245, .92)) drop-shadow(0 3px 3px rgba(99, 74, 47, .2));
}

.score-icon {
    background-image: url("data:image/svg+xml,%3Csvg width='64' height='64' viewBox='0 0 64 64' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M19 55h26c2.8 0 5-2.2 5-5v-5H14v5c0 2.8 2.2 5 5 5Z' fill='%23c87918'/%3E%3Cpath d='M17 13h30v9c0 10.5-6.7 19.6-15 19.6S17 32.5 17 22v-9Z' fill='%23ffc942'/%3E%3Cpath d='M17 13h30v8H17z' fill='%23ffdd68'/%3E%3Cpath d='M16 17H8v6c0 7.5 5.4 13.7 12.5 15.1l2.2-6.2C17.8 31.3 14 27.1 14 22v-2h2v-3Zm32 0h8v6c0 7.5-5.4 13.7-12.5 15.1l-2.2-6.2C46.2 31.3 50 27.1 50 22v-2h-2v-3Z' fill='%23f0ad24'/%3E%3Cpath d='M28 41h8v9h-8z' fill='%23e19a1f'/%3E%3Cpath d='M22 50h20v6H22z' fill='%23ffcf4d'/%3E%3Cpath d='M23.5 14.5c-1.6 8 .2 15.3 5 20.2' fill='none' stroke='%23fff3a8' stroke-width='4' stroke-linecap='round'/%3E%3Cpath d='M17 13h30v9c0 10.5-6.7 19.6-15 19.6S17 32.5 17 22v-9Z' fill='none' stroke='%238b5c10' stroke-width='3' stroke-linejoin='round'/%3E%3Cpath d='M16 17H8v6c0 7.5 5.4 13.7 12.5 15.1M48 17h8v6c0 7.5-5.4 13.7-12.5 15.1M22 55h20' fill='none' stroke='%238b5c10' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.timer-icon {
    background-image: url("data:image/svg+xml,%3Csvg width='64' height='64' viewBox='0 0 64 64' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M24 8h16v7H24z' fill='%23f68435' stroke='%236b7d92' stroke-width='3' stroke-linejoin='round'/%3E%3Ccircle cx='32' cy='36' r='22' fill='%23f8fbff' stroke='%236b7d92' stroke-width='4'/%3E%3Ccircle cx='32' cy='36' r='16' fill='%23e8f7ff' stroke='%232b95d6' stroke-width='5'/%3E%3Cpath d='M32 36V24M32 36l-9 8' fill='none' stroke='%23f68435' stroke-width='5' stroke-linecap='round'/%3E%3Cpath d='M32 18v4M32 50v4M18 36h4M42 36h4' stroke='%232b95d6' stroke-width='4' stroke-linecap='round'/%3E%3Ccircle cx='32' cy='36' r='4' fill='%232b95d6'/%3E%3Cpath d='M18 15 10 23M46 15l8 8' stroke='%236b7d92' stroke-width='4' stroke-linecap='round'/%3E%3C/svg%3E");
}

.time-unit {
    margin-left: -2px;
}

.player-form {
    position: relative;
    width: min(calc(100vw - 48px), 342px);
    display: grid;
    gap: 10px;
    padding: 20px 18px;
    text-align: center;
}

.player-form h1,
.profile-dialog h2 {
    margin: 0;
    color: #3e6d35;
    font-size: 28px;
    line-height: 1.15;
    text-shadow:
        0 2px 0 #fff8d7,
        0 4px 0 rgba(154, 160, 91, .28);
}

.player-form p,
.reward-tip {
    margin: -2px 0 4px;
    font-size: 14px;
    line-height: 1.45;
    color: rgba(35, 65, 45, .78);
}

.reward-tip {
    color: #8d3b2d;
    font-weight: 700;
}

input {
    min-width: 0;
    height: 40px;
    max-width: 100%;
    padding: 9px 10px;
    color: #23412d;
    font-size: 16px;
    border: 2px solid rgba(126, 143, 86, .55);
    border-radius: 10px;
    background: rgba(255, 255, 250, .95);
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, .75);
}

button {
    min-height: 40px;
    padding: 8px 14px;
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: 0;
    border: 3px solid rgba(255, 255, 245, .96);
    border-radius: 9px;
    background: #a7a16f;
    box-shadow:
        0 2px 0 rgba(95, 107, 66, .58),
        0 6px 12px rgba(48, 70, 39, .18);
    text-shadow: 0 1px 1px rgba(67, 74, 42, .45);
    cursor: pointer;
}

.icon-button {
    min-width: 48px;
    min-height: 36px;
    padding: 5px 10px;
    font-size: 13px;
    background: #9f9c68;
}

.secondary-button {
    color: #727342;
    border-color: rgba(255, 255, 245, .96);
    background: rgba(246, 245, 219, .94);
    text-shadow: none;
}

button:active {
    transform: translateY(2px);
    box-shadow:
        0 1px 0 rgba(95, 107, 66, .5),
        0 3px 8px rgba(48, 70, 39, .16);
}

button:focus-visible {
    outline: 2px solid rgba(126, 148, 83, .75);
    outline-offset: 2px;
}

.rank-panel {
    left: 12px;
    right: 12px;
    bottom: max(10px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-width: 0;
    gap: 10px;
    padding: 10px;
}

.rank-panel h3 {
    margin: 0 0 6px;
    font-size: 14px;
}

.rank-panel ol {
    height: 58px;
    margin: 0;
    padding-left: 20px;
    overflow: auto;
}

.rank-panel li {
    margin: 3px 0;
    font-size: 12px;
    line-height: 1.25;
}

.result-panel {
    top: 50%;
    left: 24px;
    right: 24px;
    transform: translateY(-50%);
    padding: 22px 18px;
    text-align: center;
}

.result-panel h2 {
    margin: 0 0 8px;
    font-size: 26px;
}

.result-panel p {
    margin: 0 0 14px;
    font-weight: 700;
}

.modal-backdrop {
    position: absolute;
    z-index: 4;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(21, 48, 32, .32);
}

.profile-dialog {
    position: relative;
    width: min(100%, 320px);
    display: grid;
    gap: 10px;
    padding: 18px;
    text-align: center;
}

.dialog-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

[hidden] {
    display: none !important;
}

@media (max-width: 380px) {
    .player-form {
        left: 18px;
        right: 18px;
    }

    input {
        padding-inline: 8px;
        font-size: 16px;
    }

    button {
        padding-inline: 8px;
    }

    .top-hud {
        gap: 6px;
        padding-inline: 8px;
    }

    #health {
        min-width: 62px;
        font-size: 20px;
    }

    .score-pill,
    .timer-pill,
    .icon-button {
        font-size: 12px;
    }
}
