:root {
    --bg-color: #f6d365;
    --bg-gradient: linear-gradient(135deg, #f6d365 0%, #fda085 100%);
    --text-color: #5d4037;
    /* Dark Brown/Gray */
    --accent-color: #ff6b6b;
    --accent-glow: none;
    --rock-color: #ff6b6b;
    --paper-color: #4ecdc4;
    --scissors-color: #ffe66d;
    --glass-bg: #ffffff;
    --glass-border: 4px solid #ffffff;
    --font-main: "Hiragino Maru Gothic ProN",
        "M PLUS Rounded 1c",
        "Varela Round",
        sans-serif;
    --shadow-pop: 0 6px 0 rgba(0, 0, 0, 0.15);
    --hand-bg-color: #000000;
    /* New black background */
}

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

body {
    margin: 0;
    padding: 0;
    background: var(--bg-gradient);
    color: var(--text-color);
    font-family: var(--font-main);
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Screens */
.screen {
    display: none;
    /* Default hidden */
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    /* Start from top to prevent centering issues with large content */
    width: 100%;
    height: 100%;
    padding: 20px;
    padding-bottom: 100px;
    /* Space for history */
    text-align: center;
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
    /* Star hidden for fade in */
    transition: opacity 0.5s ease, transform 0.5s ease;
    overflow-y: auto;
    /* Allow scrolling if content is too tall */
    -webkit-overflow-scrolling: touch;
}

/* Active state for display flex, but animation handles opacity */
.screen.active {
    display: flex;
    opacity: 1;
    z-index: 10;
}

.screen.fade-out {
    opacity: 0;
    transform: scale(0.95);
    pointer-events: none;
}

.screen.fade-in {
    opacity: 0;
    transform: scale(1.05);
}

/* Typography */
h1 {
    font-size: 3.5rem;
    margin-bottom: 2.5rem;
    text-shadow: 3px 3px 0 #fff;
    letter-spacing: 2px;
    color: #ff6b6b;
    background: none;
    -webkit-text-fill-color: initial;
    -webkit-background-clip: initial;
    font-weight: 900;
}

h2 {
    font-size: 2.5rem;
    margin-bottom: 0;
    /* Handled by absolute pos */
    text-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
}

#gameTitle {
    position: relative;
    /* Changed from absolute */
    margin: 10px 0 10px 0;
    flex-shrink: 0;
    width: 100%;
    z-index: 100;
}

/* Winner Animation */
@keyframes win-bounce {

    0%,
    100% {
        transform: scale(1.2);
    }

    50% {
        transform: scale(1.3);
    }
}

.winner-anim {
    animation: win-bounce 0.8s infinite ease-in-out;
    filter: drop-shadow(0 0 15px gold);
    z-index: 10;
}

p {
    font-size: 1.5rem;
}

/* Buttons (Glassmorphism) */
.menu-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 30px;
    width: 85%;
    max-width: 1100px;
}

.menu-btn {
    background: #ffffff;
    border: 4px solid #fff;
    border-radius: 30px;
    color: #5d4037;
    padding: 40px;
    font-size: 2rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 0 rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
}

.menu-btn:hover {
    transform: translateY(-2px);
    border-color: #fff;
    box-shadow: 0 10px 0 rgba(0, 0, 0, 0.1);
}

.menu-btn:active {
    transform: translateY(4px);
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.1);
}

.menu-btn span:first-child {
    font-size: 4rem;
    margin-bottom: 15px;
    filter: none;
    text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.1);
}

.back-btn {
    position: absolute;
    top: 30px;
    left: 30px;
    padding: 12px 25px;
    font-size: 1.2rem;
    background: #fff;
    backdrop-filter: none;
    border: none;
    color: #5d4037;
    border-radius: 30px;
    cursor: pointer;
    z-index: 1000;
    transition: 0.2s;
    font-weight: bold;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.15);
}

.back-btn:hover {
    background: #fff;
    transform: translateY(-2px);
    box-shadow: 0 6px 0 rgba(0, 0, 0, 0.15);
    color: #5d4037;
}

.back-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
}

/* History Panel */
.history-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 80px;
    /* Fixed height at bottom */
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 0;
    /* Full width */
    padding: 0 20px;

    display: flex;
    flex-direction: row;
    /* Horizontal */
    align-items: center;
    gap: 15px;
    overflow-x: auto;
    /* Horizontal scroll */
    overflow-y: hidden;
    white-space: nowrap;

    box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.3);
    z-index: 500;
    /* High z-index */
}

/* Scrollbar styling */
.history-panel::-webkit-scrollbar {
    height: 6px;
}

.history-panel::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.history-panel::-webkit-scrollbar-thumb {
    background: var(--accent-color);
    border-radius: 3px;
}

.history-item {
    background: #f9f9f9;
    border-radius: 12px;
    padding: 8px 15px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-width: 80px;
    flex-shrink: 0;
    border: 2px solid #eee;
}

.h-count {
    font-size: 0.8rem;
    opacity: 0.6;
    margin-bottom: 2px;
    color: #888;
}

.h-result {
    font-weight: bold;
    font-size: 1rem;
    color: #333;
}

.h-win {
    border-color: #ff6b6b;
    background: #fff0f0;
    color: #ff6b6b;
}

.h-lose {
    border-color: #54a0ff;
    background: #eaf4ff;
    color: #54a0ff;
}

.h-draw {
    border-color: #1dd1a1;
    background: #e3fdf5;
    color: #1dd1a1;
}

/* Decide Button */
.decide-btn {
    width: auto;
    min-width: 260px;
    max-width: 80%;
    height: 100px;
    background: #ff6b6b;
    border: 8px solid #fff;
    border-radius: 30px;
    color: white;
    font-size: 2.5rem;
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 10px 0 rgba(0, 0, 0, 0.15);
    /* Solid shadow */
    transition: all 0.2s;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    letter-spacing: 0;
    line-height: 1.2;
    margin-top: 20px;
    margin-bottom: 30px;
    /* Space for history */
    padding: 0 30px;
    text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.2);
}

.decide-btn:active {
    transform: translateY(10px);
    box-shadow: 0 0 0 rgba(0, 0, 0, 0.15);
}

/* Specific Screen Adjustments */
#screen-game {
    justify-content: flex-start;
    /* Align to top */
    padding-top: 10px;
    /* Minimal padding */
}

/* Game Area */
.game-area {
    display: flex;
    gap: 20px;
    align-items: center;
    /* Center items vertically */
    justify-content: center;
    width: 100%;
    flex-grow: 1;
    /* Allow growing */
    margin-bottom: 20px;
    position: relative;
    padding-bottom: 0;
}

.player-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    /* Align contents to top */
    width: 45%;
    max-width: 500px;
}

.player-name {
    font-size: 1.8rem;
    font-weight: bold;
    margin-bottom: 10px;
    opacity: 1;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    min-height: 2.2rem;
}

#vsBadge {
    font-size: 4rem;
    font-weight: 900;
    font-style: italic;
    color: #fff;
    text-shadow: 0 0 10px var(--accent-color), 0 0 20px var(--accent-color);
    margin-top: 0;
    /* Centered by flex */
    z-index: 10;
    animation: pulse-vs 1s infinite alternate;
}

@keyframes pulse-vs {
    from {
        transform: scale(1);
        opacity: 0.8;
    }

    to {
        transform: scale(1.1);
        opacity: 1;
    }
}

.hand-display {
    width: 35vw;
    height: 35vw;
    max-width: 350px;
    max-height: 350px;
    background: var(--hand-bg-color);
    /* Black background */
    border: 8px solid #fff;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 10px;
    position: relative;
    box-shadow: 0 10px 0 rgba(0, 0, 0, 0.1);
    outline: none;
    /* Removed dashed border for cleaner high contrast look, or keep if preferred. Let's keep it simple. */
}

.hand-text-local {
    font-size: 3rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 0 15px var(--accent-color);
    min-height: 4rem;
    text-align: center;
    margin-top: 5px;
}

.hand-img {
    width: 75%;
    height: 75%;
    object-fit: contain;
    filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.5));
    transition: transform 0.1s;
}

.hand-img.animate-roulette {
    animation: pop 0.2s infinite alternate;
}

.secret-text {
    font-size: 5rem;
    color: rgba(255, 255, 255, 0.2);
    font-weight: bold;
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

@keyframes pop {
    from {
        transform: scale(0.9);
    }

    to {
        transform: scale(1.1);
    }
}

.hand-name-display {
    font-size: 2.5rem;
    color: #fff;
    margin-top: 10px;
    font-weight: bold;
    text-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    min-height: 3.5rem;
    /* space reservation */
}

.result-text {
    font-size: 4rem;
    font-weight: 800;
    color: #fff;
    /* Flex positioning instead of absolute */
    position: relative;
    bottom: auto;
    left: auto;
    transform: none;
    width: 100%;
    text-align: center;
    margin-top: -20px;
    /* Pull up slightly */
    margin-bottom: 20px;
    height: 6rem;
    /* Reserve space */

    text-shadow: 4px 4px 0 var(--accent-color);
    text-stroke: 2px var(--accent-color);
    opacity: 0;
    transition: all 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
    z-index: 200;
}

.result-text.show {
    opacity: 1;
    transform: scale(1.1);
}

/* Timer Bar */
.timer-container {
    width: 70%;
    height: 10px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
    margin-top: 30px;
    overflow: hidden;
    display: none;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);
}

.timer-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--paper-color), var(--accent-color));
    width: 100%;
    transform-origin: left;
    box-shadow: 0 0 10px var(--accent-color);
}



/* Message Overlay */
.overlay-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 6rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 0 30px rgba(0, 0, 0, 0.8), 0 0 10px var(--accent-color);
    pointer-events: none;
    z-index: 50;
    display: none;
    animation: fadeInOut 1s ease-in-out;
}

@keyframes fadeInOut {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }

    20% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.1);
    }

    80% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }

    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(1.5);
    }
}

/* Click Effect */
.click-effect {
    position: absolute;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, transparent 70%);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
}

.click-effect.active {
    opacity: 1;
}

/* Responsive Design */
@media (max-width: 768px) {
    h1 {
        font-size: 2.5rem;
    }

    #gameTitle {
        font-size: 1.8rem;
        margin: 10px 0;
    }

    /* Stack players vertically on mobile */
    .game-area {
        flex-direction: column;
        gap: 10px;
        min-height: 0; /* Allow shrinking */
    }

    .player-zone {
        width: 100%;
        max-width: none;
        flex-direction: column; /* Vertical stack like PC */
        align-items: center;
        justify-content: center;
        gap: 5px;
        padding: 10px;
        background: rgba(255, 255, 255, 0.1);
        border-radius: 15px;
    }

    .player-name {
        font-size: 1.5rem;
        margin: 0;
        width: auto;
        text-align: center;
        min-height: auto;
    }

    .hand-display {
        width: 140px; /* Reduced from PC but big enough for visibility */
        height: 140px;
        min-width: 140px;
        min-height: 140px;
        border-width: 5px;
        margin: 5px 0;
    }

    .hand-text-local {
        display: block; /* Show text again but smaller */
        font-size: 1.5rem;
        min-height: 1.5rem;
        margin-top: 0;
    }

    .decide-btn {
        width: 60%;
        max-width: 250px;
        height: 60px;
        font-size: 1.5rem;
        margin: 5px 0;
        border-width: 4px;
        border-radius: 15px;
        padding: 0;
        min-width: unset;
    }

    #vsBadge {
        margin: 2px 0;
        font-size: 1.5rem;
    }

    .result-text {
        font-size: 2.5rem;
        height: 3rem;
        margin-top: 0;
    }

    /* Hide history on mobile as requested */
    .history-panel {
        display: none;
    }

    /* Adjust main content padding since history is gone */
    .screen {
        padding-bottom: 20px;
    }

    .back-btn {
        top: 10px;
        left: 10px;
        padding: 8px 15px;
        font-size: 1rem;
    }

    #screen-game {
        padding-top: 40px;
        padding-bottom: 20px;
        justify-content: center; /* Center vertically if space allows */
    }

    #clearHistoryBtn {
        display: none; /* Hide clear button too */
    }

    /* Adjust main menu grid for mobile */
    .menu-grid {
        grid-template-columns: 1fr;
        width: 90%;
        gap: 15px;
        padding-bottom: 20px;
    }

    .menu-btn {
        padding: 20px;
        flex-direction: row;
        gap: 20px;
    }

    .menu-btn span:first-child {
        font-size: 2.5rem;
        margin-bottom: 0;
    }

    /* Smaller instruction on mobile */
    .instruction-box {
        font-size: 0.6rem;
        top: 5px;
        right: 10px;
        max-width: 150px;
    }
}

/* Instruction Box */
.instruction-box {
    position: absolute;
    top: 10px;
    right: 15px;
    text-align: right;
    font-size: 0.9rem;
    color: #fff;
    z-index: 1000;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    line-height: 1.5;
    pointer-events: none;
    opacity: 0.8;
}

/* Mobile adjustment for instructions */
@media (max-width: 768px) {
    .instruction-box {
        font-size: 0.7rem;
        top: 5px;
        right: 10px;
        max-width: 200px;
    }
}

#clearHistoryBtn {
    position: fixed;
    bottom: 25px;
    /* Centered in 80px panel */
    right: 20px;
    z-index: 600;
    /* Above history panel */
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 5px;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 5px 10px;
    transition: background 0.2s;
}

#clearHistoryBtn:hover {
    background: rgba(255, 255, 255, 0.4);
}

/* Focus Ring Accessibility */
*:focus-visible {
    outline: 4px solid #fff;
    outline-offset: 2px;
    box-shadow: 0 0 0 6px #000;
}

/* Specific adjustments for rounded buttons if needed */
.decide-btn:focus-visible {
    outline: 4px solid #fff;
    outline-offset: 4px;
    box-shadow: 0 0 0 8px #000;
}

.menu-btn:focus-visible {
    outline: 4px solid #fff;
    outline-offset: 4px;
    box-shadow: 0 0 0 8px #000;
}