:root {
    --bg-color: #2c3e50;
    --table-color: #27ae60;
    --table-pattern: #2ecc71;
    --card-bg: #fdfdfd;
    --text-color: #2c3e50;
    --accent-p1: #e74c3c;
    --accent-p2: #3498db;
    --success-color: #f1c40f;
    --fail-color: #95a5a6;
    --font-main: 'Noto Sans JP', 'Hiragino Kaku Gothic Pro', 'Meiryo', 'Segoe UI', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    height: 100vh;
    height: 100dvh; 
    width: 100vw;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    color: white;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100dvh; /* Use Dynamic Viewport Height */
    background: rgba(44, 62, 80, 0.98);
    display: flex;
    flex-direction: column;
    align-items: center;
    
    /* CHANGE: This distributes space evenly so elements don't push each other off-screen */
    justify-content: space-evenly; 
    
    padding: 20px;
    z-index: 100;
    transition: opacity 0.3s;
    backdrop-filter: blur(5px);
    overflow: hidden; /* Prevent scrolling on mobile */
}

#ui-layer.hidden {
    opacity: 0;
    pointer-events: none;
}

h1 {
    /* Use clamp: Min 2rem, preferred 8vh, Max 3.5rem */
    font-size: clamp(2rem, 8vh, 3.5rem); 
    margin-bottom: 0; 
    text-transform: uppercase;
    letter-spacing: 4px;
    text-shadow: 4px 4px 0px rgba(0,0,0,0.3);
    background: linear-gradient(45deg, #f1c40f, #e67e22);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-align: center;
}

.instructions {
    background: rgba(255,255,255,0.1);
    padding: clamp(10px, 2vh, 20px); /* Padding shrinks on smaller screens */
    border-radius: 16px;
    margin: 10px 0; /* Reduced fixed margin */
    text-align: center;
    max-width: 700px;
    width: 100%;
    line-height: 1.4;
    border: 1px solid rgba(255,255,255,0.15);
    font-size: clamp(0.85rem, 1.8vh, 1rem); /* Font shrinks on smaller screens */
}

.instructions h3 { margin-bottom: 8px; color: var(--success-color); }

.key-badge {
    display: inline-block;
    background: #fff;
    color: #333;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 800;
    font-size: 0.8em;
    margin: 0 2px;
    box-shadow: 0 2px 0 #bbb;
}

button.btn-primary {
    background: linear-gradient(to bottom, #f1c40f, #f39c12);
    color: #2c3e50;
    border: none;
    padding: 15px 40px;
    font-size: 1.4rem;
    border-radius: 60px;
    cursor: pointer;
    font-weight: 900;
    text-transform: uppercase;
    box-shadow: 0 8px 0 #d35400, 0 15px 30px rgba(0,0,0,0.3);
    transition: all 0.1s;
}

button.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 0 #d35400, 0 20px 40px rgba(0,0,0,0.4);
}

button.btn-primary:active {
    transform: translateY(4px);
    box-shadow: 0 4px 0 #d35400, 0 5px 15px rgba(0,0,0,0.3);
}

.logo-link {
    display: block;
    margin: 10px auto; /* Reduced from 40px */
    width: 40%; 
    max-width: 200px; /* Slightly smaller to save vertical space */
    text-decoration: none;
    cursor: pointer;
}

.game-logo {
    display: block;
    width: 100%;
    height: auto;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.logo-link:hover .game-logo {
    transform: scale(1.05);
    opacity: 0.8;
}

.copyright-link {
    margin: 0;
    padding-bottom: 20px;
    text-align: center;
}

.copyright-link a {
    color: rgba(175, 238, 238, 0.6);
    text-decoration: none;
    font-size: 0.8em;
    font-family: sans-serif;
    letter-spacing: 0.5px;
    transition: color 0.3s ease;
}

.copyright-link a:hover {
    color: #AFEEEE;
    text-decoration: underline;
}

.mode-selector {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin: 15px 0;
}

.mode-option {
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.1);
    padding: 10px 15px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    flex: 1;
    max-width: 200px;
}

.mode-option.active {
    background: rgba(241, 196, 15, 0.15);
    border-color: var(--success-color);
    transform: scale(1.05);
}

.mode-title {
    font-weight: bold;
    color: white;
    font-size: 0.9em;
}

.mode-desc {
    font-size: 0.7em;
    opacity: 0.7;
    margin-top: 4px;
}

.mode-option.active .mode-title {
    color: var(--success-color);
}

#ui-layer:not(.hidden) #game-title {
    font-size: clamp(1.5rem, 7vh, 3rem);
    padding: 0 10px;
    line-height: 1.2;
}

/* Optional: Add a little celebration color for the win text */
#ui-layer #game-title {
    transition: color 0.5s ease;
}

@media (max-width: 480px), (max-height: 750px) {
    #ui-layer {
        padding: 10px;
    }

    /* Hide the extra line breaks on mobile to save space */
    .instructions br {
        display: none;
    }

    .instructions p {
        margin-bottom: 5px;
    }

    /* Adjust the P1/P2 flex gap */
    .instructions > div[style*="display:flex"] {
        gap: 10px !important;
    }

    button.btn-primary {
        padding: 12px 30px;
        font-size: 1.2rem;
    }

    .copyright-link {
        padding-bottom: 10px;
        margin-top: 5px;
    }
}