@import url('https://fonts.googleapis.com/css2?family=Sawarabi+Mincho&display=swap');

:root {
    --bg-color: #fcf4e8; /* Rice Paper */
    --ink-color: #2d2d2d; /* Sumi Ink */
    --red-stamp: #aa3a3a; /* Seal Red */
}

/* --- MAIN LAYOUT --- */
body {
    background-color: var(--bg-color);
    color: var(--ink-color);
    font-family: 'Sawarabi Mincho', serif;
    margin: 0;
    display: flex;
    justify-content: center;
    /* ALLOW SCROLLING (Crucial for small phones) */
    overflow-y: auto; 
    min-height: 100vh;
    background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0IiBoZWlnaHQ9IjQiPgo8cmVjdCB3aWR0aD0iNCIgaGVpZ2h0PSI0IiBmaWxsPSIjZmNmNGU4Ii8+CjxyZWN0IHdpZHRoPSIxIiBoZWlnaHQ9IjEiIGZpbGw9IiNkM2M4YjgiLz4KPC9zdmc+');
}

/* Container to distribute content vertically */
#app {
    width: 100%;
    /* DYNAMIC HEIGHT (Fixes Safari Address Bar cutting off bottom) */
    min-height: 100vh;
    min-height: 100dvh; 
    height: auto;
    
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-evenly; 
    padding: 20px 0; 
    box-sizing: border-box;
    position: relative;
}

/* --- MENU STYLES (NEW) --- */
#menu-container {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 200;
}

#menu-icon {
    font-size: 2.5rem;
    cursor: pointer;
    user-select: none;
    transition: transform 0.2s;
}

#menu-icon:active {
    transform: scale(0.9);
}

#dropdown-menu {
    position: absolute;
    top: 50px;
    right: 0;
    background: #fff;
    border: 3px solid var(--ink-color);
    width: 180px;
    box-shadow: 5px 5px 0 var(--red-stamp);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 201;
}

#dropdown-menu.menu-hidden {
    display: none;
}

.menu-item {
    padding: 15px;
    border-bottom: 1px solid var(--ink-color);
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s;
    font-size: 1.1rem;
    text-align: left;
}

.menu-item:last-child {
    border-bottom: none;
}

.menu-item:hover {
    background: #eee;
}

.menu-item.logout {
    color: var(--red-stamp);
}

/* --- GLOBAL HEADER --- */
#global-header {
    text-align: center;
    animation: fadeIn 1s;
    flex-shrink: 0;
}

.header-logo {
    width: 160px; /* Big Desktop Size */
    height: auto;
    filter: drop-shadow(2px 2px 0px rgba(0,0,0,0.1));
    transition: width 0.3s ease;
}

.header-text {
    width: 400px; /* Big Desktop Size */
    max-width: 90%;
    height: auto;
    margin-top: 15px;
    transition: width 0.3s ease;
}

.header-break {
    flex-basis: 100%;
    height: 0;
}

/* --- SCREEN MANAGEMENT --- */
.screen {
    display: none;
    text-align: center;
    width: 100%;
    max-width: 500px;
}

.screen.active {
    display: block;
    animation: fadeIn 0.5s;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- MODAL STYLES --- */
#modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8); z-index: 300; /* Must be higher than menu */
    display: flex; justify-content: center; align-items: center;
}
#modal-overlay.modal-hidden { display: none; }
.modal-content {
    background: #fff; border: 4px solid var(--ink-color); padding: 20px;
    text-align: center; width: 300px; max-width: 85%;
    box-shadow: 15px 15px 0 var(--red-stamp); position: relative;
}
#modal-title { font-size: 1.8rem; color: var(--red-stamp); margin: 0 0 15px 0; text-transform: uppercase; font-weight: bold; border-bottom: 2px solid var(--ink-color); padding-bottom: 10px; }
#modal-moves { display: flex; justify-content: center; align-items: center; gap: 15px; margin-bottom: 15px; }
.modal-move-box { display: flex; flex-direction: column; align-items: center; }
.ink-icon-small { width: 60px; height: 60px; object-fit: contain; }
.modal-vs { font-size: 1.5rem; font-weight: bold; color: var(--red-stamp); }
.small-label { font-size: 0.8rem; text-transform: uppercase; margin-bottom: 5px; font-weight: bold; }
#modal-timer-bar { height: 4px; background: var(--ink-color); width: 100%; margin-top: 20px; transform-origin: left; }
.animate-modal-bar { animation: shrinkBar 5s linear forwards; } /* CHANGED TO 5s */
@keyframes shrinkBar { from { width: 100%; } to { width: 0%; } }

/* --- LEADERBOARD STYLES --- */
.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}
.leaderboard-table th, .leaderboard-table td {
    padding: 8px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}
.leaderboard-table th {
    background-color: var(--ink-color);
    color: white;
}
.leaderboard-table tr.gold { background-color: #fff8d6; font-weight: bold; }
.leaderboard-table tr.silver { background-color: #f4f4f4; }
.leaderboard-table tr.bronze { background-color: #fff0e6; }

/* --- GENERAL UI --- */
h1, h2, h3 { font-weight: bold; letter-spacing: 2px; margin: 10px 0; }
.scroll-container { border: 4px double var(--ink-color); padding: 2rem; background: #fff; box-shadow: 10px 10px 0px rgba(0,0,0,0.1); margin: 0 20px; }
input { display: block; width: 80%; margin: 15px auto; padding: 10px; border: none; border-bottom: 2px solid var(--ink-color); background: transparent; font-family: inherit; font-size: 1.2rem; text-align: center; outline: none; border-radius: 0; }
button { background-color: var(--red-stamp); color: white; border: none; padding: 12px 35px; font-size: 1.2rem; font-family: inherit; cursor: pointer; margin-top: 20px; border-radius: 2px; transition: background 0.2s; }
button:hover { background-color: #8a2a2a; }

/* --- LOBBY VISUALS --- */
.ink-circle {
    width: 140px; height: 140px; 
    border: 6px solid var(--ink-color); border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    margin: 20px auto;
    font-size: 3.5rem; font-weight: bold; background: #fff;
    transition: all 0.3s;
}
.ink-circle.red { border-color: var(--red-stamp); color: var(--red-stamp); animation: pulse 1s infinite; }
.timer-box { margin-top: 30px; font-size: 1.2rem; border-top: 1px solid var(--ink-color); padding-top: 10px; }
#lobby-timer { font-size: 2.5rem; margin: 5px 0; }

/* Visual Sync: The Urgent Lobby Timer (T-30s) */
.urgent {
    color: var(--red-stamp);
    animation: pulse 1s infinite;
    font-weight: 900;
}

/* --- GAME VISUALS --- */
.arena { display: flex; justify-content: center; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.move-btn { width: 30vw; max-width: 100px; padding: 5px; cursor: pointer; transition: transform 0.2s, background 0.2s; background: transparent; text-align: center; }
.move-btn:hover { transform: scale(1.05) translateY(-5px); background-color: rgba(45, 45, 45, 0.05); border-radius: 10px; }
.ink-icon { width: 100%; height: auto; object-fit: contain; display: block; margin: 0 auto; filter: drop-shadow(2px 2px 0px rgba(0,0,0,0.2)); }
.jap-char { font-size: 1.5rem; margin-top: 5px; font-weight: bold; }
.flash-text { color: var(--red-stamp); font-size: 2rem; animation: pulse 0.8s infinite; }
@keyframes pulse { 0% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.05); opacity: 0.7; } 100% { transform: scale(1); opacity: 1; } }
#move-timer-bar { height: 5px; background: var(--red-stamp); width: 0%; margin: 20px auto; }
.header { display: flex; justify-content: space-between; border-bottom: 2px solid var(--ink-color); margin-bottom: 20px; padding-bottom: 10px; font-weight: bold; margin: 0 20px; }

/* --- RESPONSIVE MOBILE LOGIC --- */
@media (max-height: 850px) {
    #app {
        /* Ensure content can grow beyond the screen height */
        padding-bottom: 50px; 
    }

    /* Shrink the Header slightly for small phones */
    .header-logo { width: 120px; } 
    .header-text { width: 300px; margin-top: 10px; }
    
    .ink-circle { width: 130px; height: 130px; font-size: 3rem; margin: 15px auto; }
    #lobby-timer { font-size: 2.5rem; }
    .timer-box { font-size: 1.1rem; }
    
    /* Ensure modal fits on small screens */
    .modal-content { width: 90%; padding: 15px; }
    
    /* Move menu icon a bit to not hit curved corners */
    #menu-container { top: 15px; right: 15px; }
}