:root {
    --primary-color: #FF9800;
    /* Orange */
    --primary-light: #FFCC80;
    --primary-dark: #F57C00;
    --accent-color: #FF5722;
    /* Deep Orange */
    --bg-color: #FFF3E0;
    /* Very light orange */
    --text-color: #3E2723;
    /* Dark Brown */
    --white: #FFFFFF;
    --gray-light: #ECEFF1;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    --radius: 16px;
    --font-main: 'Zen Maru Gothic', sans-serif;
    --font-display: 'Potta One', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html {
    background-color: var(--primary-color);
}

body {
    font-family: var(--font-main);
    background-color: var(--primary-color);
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
    /* Prevent body scroll */
    display: flex;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
}

#app {
    width: 100%;
    max-width: 500px;
    height: 100%;
    background-color: var(--bg-color);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.screen {
    width: 100%;
    height: 100%;
    padding: 20px;
    padding-top: calc(env(safe-area-inset-top) + 15px);
    padding-bottom: calc(env(safe-area-inset-bottom) + 20px);
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 0;
    left: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    background-color: var(--primary-color);
    overflow-y: auto;
}

.screen.hidden {
    pointer-events: none;
    opacity: 0;
    transform: scale(0.95);
    z-index: 0;
}

.screen.active {
    opacity: 1;
    transform: scale(1);
    z-index: 10;
}

/* Ensure button is above confetti (z-index 999) */
#back-to-title-btn {
    position: relative;
    z-index: 1000;
}

/* === Custom Modal === */
.modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 1;
    transition: opacity 0.2s;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
    z-index: -1;
}

.modal-content {
    background: var(--white);
    padding: 25px;
    border-radius: var(--radius);
    width: 80%;
    max-width: 350px;
    text-align: center;
    transform: scale(1);
    transition: transform 0.2s;
}

.modal.hidden .modal-content {
    transform: scale(0.9);
}

.modal-content h3 {
    margin-bottom: 10px;
    color: var(--primary-dark);
}

.modal-content p {
    margin-bottom: 20px;
    color: var(--text-color);
}

.modal-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.modal-actions button {
    min-width: 100px;
}

#modal-cancel-btn {
    background: var(--gray-light);
    color: var(--text-color);
}

/* Typography */
h1,
h2,
h3 {
    font-family: var(--font-display);
    color: black;
    text-align: center;
}

.logo {
    font-size: 2rem;
    margin: 20px 0;
}

/* Card Style */
.card {
    padding: 20px;
    margin-bottom: 20px;
}

.card h2 {
    font-size: 1.2rem;
    margin-bottom: 15px;
}

/* Inputs & Buttons */
.input-group {
    display: flex;
    gap: 10px;
}

input[type="text"] {
    flex: 1;
    padding: 12px;
    border-radius: 12px;
    font-family: var(--font-main);
    font-size: 1rem;
    outline: none;
    transition: 0.2s;
    user-select: text;
    -webkit-user-select: text;
}

input[type="text"]:focus {
    border-color: var(--accent-color);
}

.btn-primary {
    background: var(--accent-color);
    color: var(--white);
    border: none;
    padding: 10px 20px;
    border-radius: 12px;
    font-weight: bold;
    cursor: pointer;
}

.btn-primary:active {
    transform: translateY(4px);
    box-shadow: none;
}

.btn-large {
    width: 100%;
    padding: 18px;
    font-size: 1.5rem;
    font-family: var(--font-display);
    background: white;
    color: var(--accent-color);
    border: none;
    border-radius: 50px;
    margin-top: auto;
    /* Push to bottom */
    margin-bottom: 10%;
    cursor: pointer;
    transition: 0.1s;
}

.btn-large:active {
    transform: translateY(6px);
}

.btn-large:disabled {
    background: linear-gradient(to bottom, #FFA726, #FB8C00);
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
    color: var(--primary-dark);
}

.btn-small {
    background: var(--primary-dark);
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 8px;
    font-size: 0.8rem;
    cursor: pointer;
}

/* Player List Entry */
.player-list-entry {
    list-style: none;
    margin-top: 15px;
}

.player-list-entry li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--gray-light);
    border-radius: 8px;
    margin-bottom: 8px;
    font-weight: bold;
}

.delete-btn {
    background: none;
    border: none;
    color: #ef5350;
    font-size: 1.2rem;
    cursor: pointer;
}

/* Score Setter */
.score-setter {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
}

.adjust-btn {
    width: 40px;
    height: 40px;
    background: var(--primary-light);
    border: none;
    border-radius: 50%;
    font-size: 1.5rem;
    color: var(--primary-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.star-display {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 2rem;
    font-family: var(--font-display);
    color: white
}

/* === Game Screen === */
#game-screen {
    padding: 0;
    display: flex;
    flex-direction: column;
}

.topic-area {
    height: 35%;
    background: var(--white);
    border-bottom: 4px solid var(--primary-color);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    z-index: 5;
}

.topic-area:active {
    background-color: #FAFAFA;
}

.topic-content {
    text-align: center;
}

.topic-text {
    font-family: var(--font-display);
    font-size: 2.5rem;
    color: #D32F2F;
    /* Red */
    margin-bottom: 5px;
    line-height: 1.2;
}

.topic-text.placeholder {
    color: #BDBDBD;
    font-size: 2rem;
}


.topic-stars {
    margin-top: 10px;
    font-size: 1.5rem;
    color: #FBC02D;
    min-height: 1.5em;
}

.instruction {
    position: absolute;
    bottom: 10px;
    font-size: 0.8rem;
    color: #90A4AE;
    opacity: 0.8;
}

.score-area {
    flex: 1;
    /* Occupy remaining 2/3 */
    background: var(--primary-color);
    padding: 10px 20px;
    overflow-y: auto;
}

.score-header {
    display: flex;
    justify-content: right;
    align-items: center;
    margin-bottom: 15px;
}

.game-player-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.game-player-card {
    background: var(--white);
    border-radius: 12px;
    padding: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: transform 0.15s, border 0.15s;
    border: 3px solid transparent;
    cursor: pointer;
    user-select: none;
}

/* Toggle Selection Style */
.game-player-card.selected {
    border-color: var(--accent-color);
    background-color: #FFECB3;
    transform: scale(1.02);
}

.player-info {
    font-weight: bold;
    font-size: 1.1rem;
}

.player-score {
    color: #FBC02D;
    font-size: 1.2rem;
    letter-spacing: 2px;
}

/* Stars */
.star-filled {
    color: #FBC02D;
    font-size: 0.9rem
}

.star-empty {
    color: #E0E0E0;
}

/* === Result Screen === */
#result-screen {
    justify-content: center;
    align-items: center;
    text-align: center;
}

.result-title {
    font-size: 3rem;
    margin-bottom: 30px;
    color: #000000;
}

.result-list {
    width: 100%;
    margin-bottom: 40px;
}

.result-item {
    background: var(--white);
    padding: 20px;
    margin: 10px 0;
    border-radius: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.2rem;
    font-weight: bold;
    transform: scale(0.9);
    opacity: 0.8;
}

.result-item.winner {
    transform: scale(1.1);
    opacity: 1;
    border: 4px solid #FFD700;
    background: linear-gradient(to bottom right, #FFF8E1, #FFECB3);
    margin: 20px 0;
    padding: 30px 20px;
}

.result-item.winner .r-name {
    font-size: 2rem;
    color: #D84315;
}

.result-item.winner .r-score {
    font-size: 2rem;
}

/* Animation utilities */
@keyframes shake {
    0% {
        transform: rotate(0deg);
    }

    25% {
        transform: rotate(5deg);
    }

    50% {
        transform: rotate(0deg);
    }

    75% {
        transform: rotate(-5deg);
    }

    100% {
        transform: rotate(0deg);
    }
}

.shake {
    animation: shake 0.5s infinite;
}

.pop {
    animation: pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes pop {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}