:root {
    --container-max-width: 460px;
    --card-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
    --border-color: rgba(255, 255, 255, 0.15);
    --accent: #ffce54;
    --bg-top: #4a4f45;
    --bg-bottom: #111211;
}

* {
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
}

html,
body {
    height: 100%;
    min-height: 100dvh;
}

body {
    background: radial-gradient(circle at 25% 20%, var(--bg-top) 0%, #2a2d27 50%, var(--bg-bottom) 100%);
    margin: 0;
    padding: 20px 12px;
    color: #ffffff;
    font-family: Arial, sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    overflow: hidden;
}

#container {
    width: min(100%, var(--container-max-width));
    height: min(720px, calc(100dvh - 32px));
    background: linear-gradient(180deg, rgba(44, 47, 42, 0.8), rgba(9, 9, 9, 0.85));
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 24px 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow: hidden;
}

.title h1 {
    margin: 0;
    font-size: clamp(26px, 8vw, 34px);
}

.title p {
    margin: 6px 0 0;
    color: #d7d7d7;
    font-size: clamp(14px, 4vw, 17px);
}

.tabs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
    gap: 8px;
}

.tab-btn {
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    border-radius: 999px;
    padding: 10px 0;
    font-size: 15px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.tab-btn.active {
    background: #ffffff;
    color: #111;
}

.tab-panels {
    flex: 1;
    min-height: 0;
    position: relative;
}

.tab-panel {
    display: none;
    flex-direction: column;
    gap: 18px;
    min-height: 0;
    overflow-y: auto;
    padding-right: 4px;
}

.tab-panel.active {
    display: flex;
}

#tab-game {
    flex: 1;
    overflow: hidden;
    padding-right: 0;
    gap: 20px;
}

.player-card {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    background: rgba(0, 0, 0, 0.25);
    text-align: left;
}

.player-card__label {
    font-size: 15px;
    margin-bottom: 8px;
    color: #d7d7d7;
}

.username-form {
    display: flex;
    gap: 8px;
}

.username-form input {
    flex: 1;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    padding: 10px 14px;
    font-size: 15px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    user-select: text;
}

.username-form button {
    border-radius: 999px;
    border: none;
    background: #ffffff;
    color: #111;
    padding: 0 18px;
    font-weight: bold;
    cursor: pointer;
}

.username-feedback {
    font-size: 13px;
    color: var(--accent);
    min-height: 18px;
    margin: 6px 0 0;
}

.player-stats {
    font-size: 16px;
    font-weight: bold;
    text-align: center;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.25);
}

.game-counters {
    display: flex;
    gap: 12px;
}

.counter-card {
    flex: 1;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 12px 14px;
    background: rgba(0, 0, 0, 0.32);
}

.counter-label {
    margin: 0 0 4px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #d3d3d3;
}

#hp,
#stats {
    font-size: clamp(18px, 4vw, 24px);
    font-weight: bold;
    letter-spacing: 0.5px;
}

.stone-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-bottom: 8px;
    position: relative;
}

#stone {
    width: min(70vw, 360px);
    max-width: 380px;
    cursor: pointer;
    transition: transform 0.08s ease-out;
    touch-action: none;
}

#stone:focus {
    outline: none;
}

#stone:active {
    transform: scale(0.94);
}

#pickaxe {
    position: absolute;
    width: 154px;
    height: 154px;
    top: 13%;
    right: 9%;
    pointer-events: none;
    transform-origin: bottom left;
    opacity: 0;
    filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.6));
    z-index: 2;
}

#pickaxe::before,
#pickaxe::after {
    content: "";
    position: absolute;
    border-radius: 999px;
}

#pickaxe::before {
    width: 14px;
    height: 110px;
    background: linear-gradient(180deg, #8b5726, #3e1f0a);
    left: 60%;
    bottom: 6px;
    transform: rotate(-25deg);
}

#pickaxe::after {
    width: 112px;
    height: 22px;
    background: linear-gradient(90deg, #c6cdd3, #6a7985);
    left: 2px;
    top: 38px;
    border-radius: 30% 70% 45% 25%;
    transform-origin: left center;
    transform: rotate(-18deg);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
    clip-path: polygon(0% 50%, 10% 20%, 28% 0%, 75% 12%, 100% 40%, 100% 60%, 75% 88%, 28% 100%, 10% 80%);
}

#pickaxe.swing {
    animation: pickaxe-swing 0.35s ease-out;
}

@keyframes pickaxe-swing {
    0% {
        opacity: 0;
        transform: rotate(35deg) translate(-10px, -45px);
    }
    30% {
        opacity: 1;
        transform: rotate(-22deg) translate(-8px, 6px);
    }
    55% {
        opacity: 1;
        transform: rotate(-8deg) translate(-2px, 14px);
    }
    100% {
        opacity: 0;
        transform: rotate(28deg) translate(18px, -24px);
    }
}

#spark {
    position: absolute;
    width: 120px;
    height: 120px;
    top: 48%;
    left: 52%;
    transform: translate(-50%, -50%) rotate(-25deg);
    pointer-events: none;
    opacity: 0;
    mix-blend-mode: screen;
    z-index: 3;
}

#spark::before,
#spark::after {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle, rgba(255, 243, 188, 0.95) 0%, rgba(255, 160, 69, 0.8) 35%, rgba(255, 160, 69, 0) 70%);
    border-radius: 50%;
}

#spark::after {
    inset: 25px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.9) 0%, rgba(255, 215, 120, 0.7) 50%, rgba(255, 167, 69, 0) 100%);
    filter: blur(1px);
}

#spark.flash {
    animation: spark-pop 0.22s ease-out;
}

@keyframes spark-pop {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.25) rotate(-10deg);
    }
    40% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1) rotate(-35deg);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(1.2) rotate(-45deg);
    }
}

.prisoner-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

#prisoner {
    width: min(50vw, 220px);
    opacity: 0.97;
}

#score {
    color: var(--accent);
}

img {
    user-select: none;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
}

.ranking-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.ranking-header h2 {
    margin: 0;
    font-size: 20px;
}

.ranking-header button {
    border: none;
    border-radius: 999px;
    padding: 8px 16px;
    font-weight: bold;
    cursor: pointer;
}

.ranking-list {
    margin: 0;
    padding-left: 0;
    padding-right: 6px;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 16px;
}

.ranking-list .empty {
    list-style: none;
    padding-left: 0;
    color: #bcbcbc;
}

.ranking-divider {
    list-style: none;
    text-align: center;
    color: #9c9c9c;
    letter-spacing: 10px;
    font-size: 20px;
}

.ranking-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.2);
}

.ranking-item.me {
    border-color: #ffffff;
}

.ranking-item__name {
    font-weight: bold;
    flex: 1;
}

.ranking-item__score {
    color: var(--accent);
    white-space: nowrap;
}

.invite-actions {
    display: flex;
    gap: 10px;
}

.invite-actions button {
    flex: 1;
    border-radius: 12px;
    border: none;
    padding: 12px;
    font-weight: bold;
    cursor: pointer;
}

.invite-link {
    width: 100%;
    border-radius: 12px;
    border: 1px dashed var(--border-color);
    padding: 12px;
    font-size: 15px;
    text-align: center;
    user-select: text;
    word-break: break-all;
    white-space: pre-wrap;
}

.small-hint {
    font-size: 13px;
    color: #d7d7d7;
}

.merits-text {
    font-size: 16px;
    color: #f7f7f7;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    background: rgba(0, 0, 0, 0.25);
    line-height: 1.5;
    text-align: center;
}

@media (max-width: 480px) {
    body {
        padding: 12px;
        overflow: hidden;
    }

    #container {
        height: calc(100dvh - 24px);
        padding: 20px 16px;
    }

    .username-form {
        flex-direction: column;
    }

    .username-form button,
    .invite-actions button {
        width: 100%;
    }

    .game-counters {
        flex-direction: column;
    }

    #stone {
        width: min(80vw, 360px);
    }

    #pickaxe {
        width: 121px;
        height: 121px;
        top: 10%;
        right: 4%;
    }

    #spark {
        width: 95px;
        height: 95px;
        top: 46%;
        left: 50%;
    }
}
