* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Comic Sans MS", "Trebuchet MS", sans-serif;
    background: linear-gradient(160deg, #93c5fd 0%, #a78bfa 55%, #f9a8d4 100%);
    color: #1e1b4b;
}

.game-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
}

.card {
    width: min(760px, 100%);
    background: #ffffff;
    border-radius: 24px;
    padding: 24px;
    box-shadow: 0 20px 45px rgba(30, 27, 75, 0.25);
    text-align: center;
}

h1 {
    margin: 0 0 8px;
    font-size: clamp(1.8rem, 4vw, 2.4rem);
}

.subtitle {
    margin: 0 0 18px;
    font-size: 1.1rem;
    color: #4338ca;
    font-weight: 700;
}

.hidden {
    display: none;
}

.setup-panel {
    display: grid;
    justify-items: center;
}

.setup-panel.hidden {
    display: none;
}

#playerNameInput {
    width: min(320px, 100%);
    padding: 11px 12px;
    border-radius: 10px;
    border: 2px solid #a5b4fc;
    font-size: 1rem;
    font-weight: 700;
    color: #312e81;
    margin-bottom: 16px;
    text-align: center;
}

.top-bar {
    display: grid;
    grid-template-columns: repeat(3, minmax(110px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.stat {
    background: #eef2ff;
    border: 2px solid #c7d2fe;
    border-radius: 14px;
    padding: 10px;
    font-size: 1rem;
}

.table-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 700;
}

#tableSelect,
#modeSelect,
#orderSelect {
    width: min(320px, 100%);
    padding: 11px 12px;
    border-radius: 10px;
    border: 2px solid #a5b4fc;
    font-size: 1rem;
    font-weight: 700;
    color: #312e81;
    margin-bottom: 16px;
}

.game-panel {
    margin-top: 6px;
}

.player-row {
    margin-bottom: 10px;
    font-size: 1rem;
    color: #4338ca;
    font-weight: 700;
}

.question-box {
    background: #f8fafc;
    border: 3px dashed #a78bfa;
    border-radius: 16px;
    padding: 18px;
}

.question {
    font-size: clamp(2.2rem, 7vw, 3.4rem);
    font-weight: 700;
}

.input-wrap {
    margin-top: 18px;
}

#answerInput {
    width: min(320px, 100%);
    border: 3px solid #818cf8;
    border-radius: 14px;
    padding: 12px 14px;
    text-align: center;
    font-size: clamp(1.5rem, 6vw, 2.2rem);
    font-weight: 700;
    color: #312e81;
}

#answerInput:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.2);
}

.timer-wrap {
    margin-top: 14px;
}

.timer-label {
    font-size: 0.95rem;
    color: #3730a3;
    font-weight: 700;
    margin-bottom: 6px;
}

.timer-bar {
    width: 100%;
    max-width: 520px;
    height: 14px;
    border-radius: 999px;
    background: #e0e7ff;
    margin: 0 auto;
    overflow: hidden;
}

.timer-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #22c55e, #84cc16);
    transition: width 0.1s linear, background 0.2s ease;
}

.timer-fill.warning {
    background: linear-gradient(90deg, #f97316, #ef4444);
}

.feedback {
    min-height: 34px;
    margin: 16px 0 8px;
    font-size: 1.1rem;
    font-weight: 700;
}

.feedback.good {
    color: #047857;
}

.feedback.bad {
    color: #b91c1c;
}

.feedback.end {
    color: #4c1d95;
}

.actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 12px;
}

button {
    border: 0;
    border-radius: 12px;
    padding: 10px 18px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
}

.primary-btn {
    background: #0ea5e9;
    color: #fff;
}

.primary-btn:disabled {
    background: #bfdbfe;
    cursor: not-allowed;
}

#restartBtn {
    background: #fde047;
    color: #713f12;
}

#saveBtn {
    background: #34d399;
    color: #064e3b;
}

.stars-panel {
    margin-top: 14px;
}

.stars-panel h3 {
    margin: 0 0 10px;
    color: #4338ca;
}

.table-stars {
    display: grid;
    grid-template-columns: repeat(5, minmax(80px, 1fr));
    gap: 8px;
}

.star-box {
    border: 2px solid #c7d2fe;
    border-radius: 10px;
    padding: 8px 4px;
    background: #f8fafc;
}

.star-box.awarded {
    animation: starRewardPop 0.9s ease;
}

.star-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 700;
    color: #3730a3;
}

.star-icon {
    font-size: 1.35rem;
    line-height: 1;
}

.star-icon.gold {
    color: #f59e0b;
    text-shadow: 0 0 10px rgba(245, 158, 11, 0.65);
}

.star-icon.none {
    color: #d1d5db;
}

.leaderboard-panel {
    margin-top: 20px;
    border-top: 2px dashed #c7d2fe;
    padding-top: 14px;
}

.leaderboard-panel h3 {
    margin: 0 0 10px;
    color: #4338ca;
}

.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: left;
}

.leaderboard-item {
    border: 2px solid #e0e7ff;
    border-radius: 10px;
    padding: 8px;
    background: #f8fafc;
}

.leaderboard-head {
    display: flex;
    justify-content: space-between;
    font-weight: 700;
    color: #312e81;
    margin-bottom: 4px;
}

.leaderboard-stars {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    font-size: 0.85rem;
}

@keyframes starRewardPop {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 rgba(245, 158, 11, 0);
    }
    40% {
        transform: scale(1.16) rotate(-2deg);
        box-shadow: 0 0 24px rgba(245, 158, 11, 0.65);
    }
    70% {
        transform: scale(0.96) rotate(1deg);
        box-shadow: 0 0 12px rgba(245, 158, 11, 0.45);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 rgba(245, 158, 11, 0);
    }
}

@media (max-width: 560px) {
    .card {
        padding: 18px;
    }

    .top-bar {
        grid-template-columns: 1fr;
    }

    #answerInput,
    #playerNameInput,
    #tableSelect,
    #modeSelect,
    #orderSelect {
        width: 100%;
    }

    .table-stars {
        grid-template-columns: repeat(2, minmax(120px, 1fr));
    }
}
