/* Dadie's Majhong - Japanese Zen Theme */

/* Polices AUTO-HÉBERGÉES (sous-ensemble latin) — aucune connexion à Google.
   Remplace l'ancien @import fonts.googleapis.com (qui envoyait l'IP du joueur
   à Google et cassait le hors-ligne). Fichiers dans assets/fonts/. */
@font-face {
    font-family: 'Noto Serif JP';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url(assets/fonts/notoserifjp-latin.woff2) format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: 'Noto Serif JP';
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url(assets/fonts/notoserifjp-latin.woff2) format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: 'Noto Serif JP';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url(assets/fonts/notoserifjp-latin.woff2) format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: 'Zen Kaku Gothic New';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url(assets/fonts/zenkaku-400-latin.woff2) format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: 'Zen Kaku Gothic New';
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url(assets/fonts/zenkaku-500-latin.woff2) format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: 'Zen Kaku Gothic New';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url(assets/fonts/zenkaku-700-latin.woff2) format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
    /* Washi paper and natural tones */
    --bg-paper: #f5f1eb;
    --bg-paper-dark: #e8e0d5;
    --bg-tatami: #c9b896;
    --tatami-texture:
        repeating-linear-gradient(
            0deg,
            transparent 0px,
            transparent 2px,
            rgba(139, 119, 80, 0.3) 2px,
            rgba(139, 119, 80, 0.3) 3px
        ),
        repeating-linear-gradient(
            90deg,
            transparent 0px,
            transparent 8px,
            rgba(160, 140, 100, 0.15) 8px,
            rgba(160, 140, 100, 0.15) 16px
        ),
        linear-gradient(180deg, #d4c4a0 0%, #c9b896 50%, #bfae88 100%);
    --bg-wood: #8b7355;
    --bg-wood-dark: #5c4a3a;

    /* Accent colors - traditional Japanese */
    --aka: #c41e3a;        /* Red - 赤 */
    --aka-dark: #9a1830;
    --sumi: #2b2b2b;       /* Ink black - 墨 */
    --kin: #d4a84b;        /* Gold - 金 */
    --midori: #3a5a40;     /* Green - 緑 */
    --ai: #264653;         /* Indigo - 藍 */

    /* Text */
    --text-dark: #2b2b2b;
    --text-medium: #5a5a5a;
    --text-light: #8a8a8a;
    --text-cream: #f5f1eb;

    /* Borders */
    --border-light: rgba(139, 115, 85, 0.3);
    --border-dark: rgba(43, 43, 43, 0.2);

    /* Effects */
    --shadow-soft: 0 4px 20px rgba(43, 43, 43, 0.15);
    --shadow-paper: 0 2px 8px rgba(139, 115, 85, 0.2);

    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;

    --transition: all 0.3s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ===========================================
   LAYOUT STRUCTURE - RESPONSIVE
   =========================================== */

html {
    height: 100%;
}

body {
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Zen Kaku Gothic New', 'Noto Sans JP', sans-serif;
    color: var(--text-dark);
    background: #000;
    overflow: hidden;
    /* Respecter les encoches / barres système (iOS notch, Android cutout).
       Sur desktop ces valeurs valent 0 -> aucun effet. Requiert viewport-fit=cover. */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Static background image + animated petals (replaces the old video) */
#bg-image {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    object-fit: cover;
    z-index: -2;
}

#petals-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    pointer-events: none; /* clicks pass through to the game */
}

/* Main Container - responsive sizing */
#game-container {
    /* Size: fit viewport with margin (en % du body, qui retire déjà les
       safe-area-insets via son padding -> la carte reste dans la zone sûre).
       Sur desktop le padding du body vaut 0, donc 95% == ancien 95vw/95vh. */
    width: 95%;
    height: 95%;
    max-width: 1100px;
    max-height: 850px;

    /* Layout: flex column */
    display: flex;
    flex-direction: column;

    /* Style */
    background: var(--bg-paper);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    overflow: hidden;
}

/* Hide decorations for now */
.dragon-left,
.dragon-right {
    display: none;
}

/* Header - fixed height, green background (same as canvas START button) */
#header {
    flex-shrink: 0;
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
    padding: clamp(8px, 1.5vh, 14px) clamp(10px, 2vw, 20px);
    background: linear-gradient(180deg, #3a5a40 0%, #2d4a35 50%, #1a3325 100%);
    border-bottom: 2px solid #0f1f15;
    position: relative;
}

#header h1 {
    font-family: 'Noto Serif JP', serif;
    font-size: clamp(14px, 2.5vw, 26px);
    font-weight: 700;
    letter-spacing: clamp(2px, 0.5vw, 6px);
    white-space: nowrap;
    order: 0;
    width: auto;
    text-align: center;
    margin-bottom: 0;
}

/* Header buttons containers.
   Equal-width side columns (flex:1) so the centered <h1> sits on the TRUE header
   center, not on the midpoint of the gap between unequal-width button groups
   (LEADERBOARD is narrower than LOGIN, which used to pull the title left). */
#header .header-left,
#header .header-right {
    display: flex;
    flex: 1 1 0;
    gap: clamp(5px, 1vw, 10px);
    align-items: center;
}
#header .header-left { justify-content: flex-start; }
#header .header-right { justify-content: flex-end; }

/* Burger menu - hidden on desktop */
.burger-btn {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    width: 36px;
    height: 36px;
    background: linear-gradient(180deg, var(--aka) 0%, var(--aka-dark) 100%);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 8px;
    z-index: 101;
}

.burger-btn span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--text-cream);
    border-radius: 1px;
    transition: var(--transition);
}

.burger-btn.active span:nth-child(1) {
    transform: rotate(45deg) translate(4px, 4px);
}

.burger-btn.active span:nth-child(2) {
    opacity: 0;
}

.burger-btn.active span:nth-child(3) {
    transform: rotate(-45deg) translate(4px, -4px);
}

.burger-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 10px;
    background: linear-gradient(180deg, #3a5a40 0%, #1a3325 100%);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 100;
    min-width: 150px;
    overflow: hidden;
}

.burger-dropdown.open {
    display: block;
}

.burger-item {
    display: block;
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: none;
    color: var(--text-cream);
    font-size: 13px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    transition: var(--transition);
}

.burger-item:hover {
    background: rgba(255,255,255,0.1);
}

.burger-logout {
    background: var(--aka);
    border: none;
    color: white;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    margin-left: 10px;
}

/* Gold Effect - luxurious gold gradient for titles */
.gold-effect {
    color: #cfc09f;
    position: relative;
    text-shadow:
        -1px 0 1px #c6bb9f,
        0 1px 1px #c6bb9f,
        4px 4px 8px rgba(0, 0, 0, 0.5),
        -4px -4px 8px rgba(0, 0, 0, 0.3);
}

.gold-effect::before {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1;
    background: linear-gradient(
        to bottom,
        #cfc09f 22%,
        #634f2c 24%,
        #cfc09f 26%,
        #cfc09f 27%,
        #ffecb3 40%,
        #3a2c0f 78%
    );
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: none;
    letter-spacing: inherit;
}

/* Board Container - fills remaining space */
#board-container {
    position: relative;
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    background: var(--tatami-texture);
    overflow: hidden;
}

/* Game Board (Canvas) - scales to fit */
#game-board {
    max-width: 100%;
    max-height: 100%;
    display: block;
    background: transparent;
    object-fit: contain;
    position: relative;
    z-index: 5;
}

/* Shoji doors */
.shoji-door {
    position: absolute;
    top: 0;
    width: 50%;
    height: 100%;
    z-index: 10;
    background:
        linear-gradient(90deg,
            transparent 0%,
            transparent calc(100% - 2px),
            #8b6914 calc(100% - 2px),
            #8b6914 100%
        ),
        linear-gradient(180deg,
            transparent 0%,
            transparent calc(100% - 2px),
            #8b6914 calc(100% - 2px),
            #8b6914 100%
        ),
        repeating-linear-gradient(90deg,
            #a0522d 0px,
            #a0522d 5px,
            transparent 5px,
            transparent 150px
        ),
        repeating-linear-gradient(180deg,
            #a0522d 0px,
            #a0522d 5px,
            transparent 5px,
            transparent 205px
        ),
        linear-gradient(180deg, #f5f0e6 0%, #ede4d3 100%);
    transition: transform 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    box-shadow: inset 0 0 30px rgba(0,0,0,0.1);
}

#shoji-left {
    left: 0;
    border-right: 4px solid #6b4423;
    background:
        linear-gradient(90deg,
            transparent 0%,
            transparent calc(100% - 2px),
            #8b6914 calc(100% - 2px),
            #8b6914 100%
        ),
        linear-gradient(180deg,
            transparent 0%,
            transparent calc(100% - 2px),
            #8b6914 calc(100% - 2px),
            #8b6914 100%
        ),
        repeating-linear-gradient(270deg,
            #a0522d 0px,
            #a0522d 5px,
            transparent 5px,
            transparent 150px
        ),
        repeating-linear-gradient(180deg,
            #a0522d 0px,
            #a0522d 5px,
            transparent 5px,
            transparent 205px
        ),
        linear-gradient(180deg, #f5f0e6 0%, #ede4d3 100%);
}

#shoji-right {
    right: 0;
    border-left: 4px solid #6b4423;
    background-position: left center;
}

/* Doors open state */
#board-container.doors-open #shoji-left {
    transform: translateX(-90%);
}

#board-container.doors-open #shoji-right {
    transform: translateX(90%);
}

/* Start overlay - centered on board */
#start-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    z-index: 10;
    background: rgba(0, 0, 0, 0.7);
    padding: clamp(20px, 4vh, 40px) clamp(30px, 6vw, 60px);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

#start-overlay.hidden {
    display: none;
}

.layout-selector {
    display: flex;
    align-items: center;
    gap: clamp(10px, 2vw, 20px);
}

.chevron-btn {
    background: none;
    border: none;
    color: #cfc09f;
    font-size: clamp(20px, 4vw, 32px);
    cursor: pointer;
    padding: 5px 10px;
    transition: var(--transition);
    opacity: 0.7;
}

.chevron-btn:hover {
    color: #ffecb3;
    opacity: 1;
    transform: scale(1.2);
}

#layout-name-display {
    font-family: 'Noto Serif JP', serif;
    font-size: clamp(24px, 5vw, 42px);
    font-weight: 700;
    letter-spacing: 3px;
    min-width: clamp(150px, 30vw, 300px);
    text-align: center;
}

#start-preview {
    border: 2px solid #6b4423;
    border-radius: 6px;
    background: rgba(0,0,0,0.3);
    margin: 10px 0;
}

.start-btn {
    background: linear-gradient(180deg, #3a5a40 0%, #2d4a35 50%, #1a3325 100%) !important;
    padding: clamp(12px, 2.5vh, 20px) clamp(30px, 6vw, 60px) !important;
    font-size: clamp(14px, 2.5vw, 20px) !important;
    border: 2px solid #1a2a1f !important;
    font-weight: 700;
    letter-spacing: 1px;
    color: #cfc09f !important;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

.start-btn:hover {
    background: linear-gradient(180deg, #4a7a50 0%, #3a5a40 50%, #2d4a35 100%) !important;
    color: #ffecb3 !important;
}

.start-wr {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    font-family: 'Noto Serif JP', serif;
    color: #cfc09f;
    font-size: clamp(12px, 2vw, 16px);
}

.start-wr .wr-icon {
    font-size: clamp(14px, 2.5vw, 20px);
}

.start-wr #start-wr-time {
    font-weight: 700;
    color: #ffd700;
}

.start-wr .wr-player {
    font-size: clamp(10px, 1.5vw, 14px);
    opacity: 0.8;
}

/* Control Panel - fixed height */
#control-panel {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(6px, 1.5vh, 12px) clamp(8px, 2vw, 20px);
    gap: clamp(5px, 1vw, 12px);
    flex-wrap: wrap;
    background: var(--bg-paper);
    border-top: 2px solid var(--bg-wood-dark);
}

/* Game Mode Modal Styles */
.mode-selected {
    background: var(--midori) !important;
    color: white !important;
    cursor: default;
}

.mode-selected:hover {
    background: var(--midori) !important;
}

.mode-description {
    font-size: 13px;
    color: var(--text-medium);
    text-align: center;
    margin: 10px 0 20px;
    line-height: 1.5;
}

.mode-coming-soon {
    border-top: 1px solid var(--border-light);
    padding-top: 15px;
    margin-top: 10px;
}

.mode-coming-soon p {
    font-size: 12px;
    color: var(--text-light);
    font-style: italic;
    text-align: center;
}

/* Timer Display - precise chrono style */
#timer-display {
    background: var(--sumi);
    border-radius: var(--radius-sm);
    padding: clamp(4px, 1vh, 10px) clamp(8px, 1.5vw, 16px);
    font-family: 'Courier New', 'Consolas', monospace;
    font-size: clamp(12px, 2vw, 18px);
    font-weight: 700;
    color: #00ff88;
    min-width: clamp(70px, 10vw, 110px);
    text-align: center;
    letter-spacing: 1px;
    text-shadow: 0 0 8px rgba(0, 255, 136, 0.5);
}

/* Message Display */
#message-display {
    flex: 1;
    min-width: 200px;
    min-height: 40px;
    height: 40px;
    text-align: center;
    padding: 0 20px;
    background: var(--bg-paper-dark);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-medium);
    font-weight: 500;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

#message {
    display: block;
    line-height: 40px;
}

/* Buttons - traditional red accent */
.game-btn {
    background: linear-gradient(180deg, var(--aka) 0%, var(--aka-dark) 100%);
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-cream);
    padding: clamp(5px, 1vh, 12px) clamp(10px, 2vw, 24px);
    font-family: 'Zen Kaku Gothic New', sans-serif;
    font-size: clamp(10px, 1.4vw, 14px);
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.game-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(196, 30, 58, 0.3);
}

.game-btn:active {
    transform: translateY(0);
}

/* Modals - paper scroll feeling */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(43, 43, 43, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px;
}

.modal.hidden {
    display: none;
}

.modal-content {
    position: relative;
    background: var(--bg-paper);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 32px;
    max-width: 90%;
    max-height: 90%;
    overflow-y: auto;
    box-shadow: var(--shadow-soft);
    animation: modalIn 0.3s ease-out;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-content h2 {
    text-align: center;
    font-family: 'Noto Serif JP', serif;
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 24px;
    color: var(--sumi);
    letter-spacing: 2px;
}

/* Confirm Modal */
#confirm-end-modal {
    background: rgba(43, 43, 43, 0.9);
}

.confirm-modal {
    text-align: center;
    padding: 40px;
}

.confirm-modal p {
    color: var(--text-medium);
    font-size: 16px;
    margin-bottom: 28px;
    line-height: 1.6;
}

.confirm-buttons {
    display: flex;
    justify-content: center;
    gap: 16px;
}

.confirm-buttons .game-btn {
    min-width: 90px;
}

/* Layout Modal with close button */
.layout-modal {
    position: relative;
    min-width: 650px;
    max-height: none;
    overflow: visible;
}

.modal-close-x {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    font-size: 32px;
    font-weight: bold;
    color: var(--text-medium);
    cursor: pointer;
    transition: var(--transition);
    line-height: 1;
    padding: 5px 10px;
}

.modal-close-x:hover {
    color: var(--aka);
    transform: scale(1.1);
}

/* Layout Grid */
#layout-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 24px;
}

.layout-item {
    background: var(--bg-paper-dark);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    padding: 10px;
    cursor: pointer;
    text-align: center;
    transition: var(--transition);
}

.layout-item:hover {
    border-color: var(--aka);
    background: var(--bg-paper);
    transform: translateY(-2px);
    box-shadow: var(--shadow-paper);
}

.layout-item.selected {
    border-color: var(--kin);
    box-shadow: 0 0 12px rgba(212, 168, 75, 0.3);
}

.layout-name {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-medium);
    margin-top: 8px;
}

.layout-preview {
    width: 140px;
    height: 115px;
    background: var(--bg-tatami);
    margin: 0 auto;
    border-radius: var(--radius-sm);
    overflow: hidden;
}

/* Layout Navigation Bar */
#layout-nav {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-top: 5px;
}

#layout-search-input {
    width: 140px;
    padding: 10px 12px;
    background: #fff;
    border: 2px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-dark);
    font-size: 13px;
    font-family: 'Zen Kaku Gothic New', sans-serif;
}

#layout-search-input:focus {
    outline: none;
    border-color: var(--aka);
}

#layout-search-input::placeholder {
    color: var(--text-light);
}

#layout-nav .nav-btn {
    min-width: 40px;
    padding: 10px 14px;
}

#layout-nav .nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

#page-indicator {
    color: var(--text-dark);
    font-size: 14px;
    min-width: 60px;
    text-align: center;
    font-weight: 600;
}

#layout-nav #btn-close-layout {
    margin-left: auto;
}

/* Menu Modal */
.menu-modal {
    min-width: 300px;
}

.menu-btn {
    display: block;
    width: 100%;
    margin-bottom: 10px;
    padding: 14px 20px;
    background: var(--bg-paper-dark);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-dark);
    font-family: 'Zen Kaku Gothic New', sans-serif;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-align: center;
    transition: var(--transition);
}

.menu-btn:hover {
    background: var(--aka);
    border-color: var(--aka);
    color: var(--text-cream);
}

.menu-btn:last-child {
    margin-bottom: 0;
}

/* Admin Menu Links */
.admin-menu-section {
    margin-top: 10px;
}

.admin-menu-btn {
    display: block;
    text-decoration: none;
    background: linear-gradient(135deg, #2d2d1a 0%, #1a1a0d 100%);
    border: 1px solid #ffd700;
    color: #ffd700;
}

.admin-menu-btn:hover {
    background: linear-gradient(135deg, #ffd700 0%, #b8942e 100%);
    color: #000;
}

/* Help Modal */
.help-modal {
    max-width: 580px;
}

.help-text {
    background: var(--bg-paper-dark);
    border-radius: var(--radius-md);
    color: var(--text-medium);
    padding: 24px;
    margin-bottom: 20px;
    font-size: 14px;
    line-height: 1.8;
}

.help-text h3 {
    color: var(--aka);
    font-size: 15px;
    font-weight: 600;
    margin: 18px 0 10px;
}

.help-text h3:first-child {
    margin-top: 0;
}

.help-text p {
    margin-bottom: 10px;
}

.help-text ul {
    margin-left: 18px;
    margin-bottom: 10px;
}

.help-text li {
    margin-bottom: 5px;
}

.help-text strong {
    color: var(--text-dark);
}

/* Top 10 Modal */
.top10-modal {
    min-width: 500px;
}

#top10-layout-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 18px;
    max-height: 90px;
    overflow-y: auto;
    padding: 4px;
}

#top10-layout-selector button {
    padding: 7px 12px;
    font-size: 11px;
    font-weight: 500;
    background: var(--bg-paper-dark);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-medium);
    cursor: pointer;
    transition: var(--transition);
}

#top10-layout-selector button:hover {
    border-color: var(--aka);
    color: var(--aka);
}

#top10-layout-selector button.active {
    background: var(--aka);
    border-color: var(--aka);
    color: var(--text-cream);
}

#top10-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 18px;
    border-radius: var(--radius-md);
    overflow: hidden;
}

#top10-table th,
#top10-table td {
    padding: 11px 14px;
    text-align: left;
}

#top10-table th {
    background: var(--bg-wood);
    color: var(--text-cream);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#top10-table td {
    background: var(--bg-paper-dark);
    color: var(--text-dark);
    border-top: 1px solid var(--border-light);
    font-size: 13px;
}

#top10-table tr:hover td {
    background: var(--bg-paper);
}

/* Win Modal */
#win-modal .modal-content {
    text-align: center;
}

#win-modal p {
    color: var(--text-medium);
    font-size: 15px;
    margin-bottom: 8px;
}

#win-modal span {
    color: var(--kin);
    font-weight: 600;
}

#player-name {
    display: block;
    width: 100%;
    padding: 12px 14px;
    margin: 18px 0;
    font-size: 15px;
    font-family: 'Zen Kaku Gothic New', sans-serif;
    border: 2px solid var(--border-light);
    border-radius: var(--radius-sm);
    background: var(--bg-paper-dark);
    color: var(--text-dark);
    transition: var(--transition);
}

#player-name:focus {
    outline: none;
    border-color: var(--aka);
    background: var(--bg-paper);
}

#player-name::placeholder {
    color: var(--text-light);
}

/* Scrollbar - subtle */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-paper-dark);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tatami);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--bg-wood);
}

/* ===========================================
   RESPONSIVE BREAKPOINTS
   =========================================== */

/* clamp() handles most responsive sizing automatically */
/* These are only for structural changes */

/* Header: 2 rows only on very narrow screens (portrait phones) */
@media (max-width: 500px) {
    #header {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
        padding: 8px 10px;
    }

    #header h1 {
        order: -1;
        width: 100%;
        text-align: center;
        margin-bottom: 4px;
    }

    #header .header-left,
    #header .header-right {
        flex: 0 0 auto;
    }

    /* Hide premium badge on narrow screens */
    .premium-badge {
        display: none !important;
    }

    /* Smaller modals on narrow screens */
    .modal-content {
        padding: 16px;
        max-width: 98%;
        max-height: 90vh;
        margin: 5px;
    }

    .modal-content h2 {
        font-size: 18px;
        margin-bottom: 16px;
    }

    .layout-modal {
        min-width: auto;
        width: calc(100% - 20px);
        max-height: 85vh;
        overflow-y: auto;
        padding: 12px;
    }

    #layout-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .layout-preview {
        width: 70px;
        height: 55px;
    }

    .layout-item {
        padding: 6px;
    }

    .layout-item span {
        font-size: 10px;
    }

    .modal-close-x {
        top: 5px;
        right: 8px;
        font-size: 26px;
        padding: 3px 8px;
    }
}

@media (max-width: 700px) {
    /* Modal responsive - remove min-width constraints */
    .modal-content {
        padding: 20px;
        max-width: 95%;
        max-height: 85vh;
    }

    .layout-modal {
        min-width: auto;
        width: 100%;
        max-height: 80vh;
        overflow-y: auto;
    }

    #layout-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .top10-modal {
        min-width: auto;
    }

    #message-display {
        display: none;
    }

    .layout-preview {
        width: 80px;
        height: 65px;
    }

    .layout-item span {
        font-size: 11px;
    }
}

/* Limited height (landscape phones) - compress start overlay */
@media (max-height: 450px) {
    #start-overlay {
        gap: 8px;
        padding: 12px 25px;
    }

    #start-preview {
        width: 140px;
        height: 84px;
        margin: 5px 0;
    }

    #layout-name-display {
        font-size: 18px;
    }

    .chevron-btn {
        font-size: 18px;
        padding: 3px 8px;
    }

    .start-btn {
        padding: 8px 25px !important;
        font-size: 13px !important;
    }

    .start-wr {
        margin-top: 5px;
        font-size: 11px;
    }

    .start-wr .wr-icon {
        font-size: 13px;
    }
}

/* ========================================
   User Authentication & Premium Styles
   ======================================== */

/* user-section is now handled by .header-right in #header */

#user-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

#username-display {
    color: var(--kin);
    font-weight: 500;
    font-size: 14px;
}

.header-btn {
    background: linear-gradient(180deg, var(--aka) 0%, var(--aka-dark) 100%);
    color: var(--text-cream);
    border: none;
    padding: clamp(5px, 1vh, 10px) clamp(10px, 1.8vw, 20px);
    font-size: clamp(9px, 1.2vw, 13px);
    font-weight: 700;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.header-btn:hover {
    background: linear-gradient(180deg, #d63031 0%, #c41e3a 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(196, 30, 58, 0.3);
}

.header-btn.small {
    padding: 4px 10px;
    font-size: 11px;
}

.premium-badge {
    background: linear-gradient(135deg, var(--kin) 0%, #b8942f 100%);
    color: var(--sumi);
    padding: 3px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
}

/* Auth Modal Styles */
.auth-modal {
    min-width: 320px;
}

.auth-modal form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 20px 0;
}

.auth-modal input {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    background: var(--bg-paper);
    color: var(--text-dark);
    transition: var(--transition);
}

.auth-modal input:focus {
    outline: none;
    border-color: var(--kin);
    box-shadow: 0 0 0 2px rgba(212, 168, 75, 0.2);
}

.auth-modal input::placeholder {
    color: var(--text-light);
}

.error-msg {
    color: var(--aka);
    font-size: 12px;
    min-height: 18px;
    margin: 0;
}

.auth-switch {
    font-size: 13px;
    color: var(--text-medium);
    margin: 15px 0;
}

.auth-switch a {
    color: var(--kin);
    text-decoration: none;
    font-weight: 500;
}

.auth-switch a:hover {
    text-decoration: underline;
}

/* Premium Modal Styles */
.premium-modal {
    min-width: 350px;
    text-align: center;
}

.premium-features {
    background: var(--bg-paper);
    border-radius: var(--radius-md);
    padding: 20px;
    margin: 20px 0;
}

.premium-features p {
    margin-bottom: 15px;
    font-size: 15px;
}

.premium-features ul {
    text-align: left;
    list-style: none;
    padding: 0;
}

.premium-features li {
    padding: 8px 0;
    padding-left: 25px;
    position: relative;
    color: var(--text-medium);
}

.premium-features li::before {
    content: '✓';
    position: absolute;
    left: 0;
    color: var(--midori);
    font-weight: bold;
}

.premium-price {
    font-size: 28px;
    font-weight: 700;
    color: var(--kin);
    margin-top: 15px;
}

.premium-btn {
    background: linear-gradient(135deg, var(--kin) 0%, #b8942f 100%);
    color: var(--sumi);
    font-size: 16px;
    padding: 12px 30px;
    margin-bottom: 10px;
}

.premium-btn:hover {
    background: linear-gradient(135deg, #e4b85b 0%, #c8a43f 100%);
}

/* Layout item styling */
.layout-item {
    position: relative;
}

/* Locked layout overlay */
.layout-item.locked .layout-preview {
    opacity: 0.5;
    filter: grayscale(30%);
}

.layout-item.locked .layout-name {
    opacity: 0.6;
}

/* Lock icon */
.lock-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 28px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
    z-index: 2;
}

/* Header is now fully responsive via clamp() - no media query needed */

/* ========================================
   Win Guest Modal Styles
   ======================================== */

.win-guest-modal {
    min-width: 360px;
    text-align: center;
}

.win-guest-modal .big-score {
    font-size: 32px;
    font-weight: 700;
    color: var(--kin);
    margin: 15px 0 20px;
}

.win-guest-modal .guest-prompt,
.win-guest-modal .guest-login {
    background: var(--bg-paper);
    border-radius: var(--radius-md);
    padding: 20px;
    margin: 15px 0;
}

.win-guest-modal .guest-prompt p:first-child,
.win-guest-modal .guest-login p:first-child {
    margin-bottom: 15px;
    font-size: 14px;
    color: var(--text-medium);
}

.win-guest-modal form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.win-guest-modal input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    background: white;
    color: var(--text-dark);
}

.win-guest-modal input:focus {
    outline: none;
    border-color: var(--kin);
}

.win-guest-modal .game-btn {
    margin-top: 5px;
}

.win-guest-modal #btn-skip-save {
    margin-top: 15px;
    opacity: 0.7;
}

.win-guest-modal #btn-skip-save:hover {
    opacity: 1;
}

.hidden {
    display: none !important;
}

/* Win Modal Styles */
.win-modal-content {
    text-align: center;
    min-width: 380px;
}

.win-time-display {
    background: var(--sumi);
    border-radius: var(--radius-md);
    padding: 20px;
    margin: 20px 0;
    text-align: center;
}

.win-time-label {
    display: block;
    font-size: 12px;
    color: var(--text-light);
    letter-spacing: 2px;
    margin-bottom: 8px;
}

.win-time-value {
    display: block;
    font-size: 36px;
    font-weight: 700;
    color: #00ff88;
    font-family: 'Courier New', 'Consolas', monospace;
    text-shadow: 0 0 10px rgba(0, 255, 136, 0.4);
}

.win-records {
    background: var(--sumi);
    border-radius: var(--radius-md);
    padding: 15px;
    margin: 15px 0;
}

/* Mini-classement sur l'écran de victoire */
.win-leaderboard {
    background: var(--sumi);
    border-radius: var(--radius-md);
    padding: 12px 15px;
    margin: 15px 0;
}
.win-leaderboard.hidden { display: none; }

.win-lb-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 8px;
}
.win-lb-title {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: #c7bca8;
}
.win-lb-rank {
    font-size: 13px;
    font-weight: 700;
    color: var(--kin, #cfc09f);
}

.win-lb-list {
    list-style: none;
    margin: 0;
    padding: 0;
}
.win-lb-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 14px;
}
.win-lb-row { color: var(--text-cream); }
.win-lb-row:nth-child(even) { background: rgba(255,255,255,0.05); }
.win-lb-row.me {
    background: rgba(212, 168, 75, 0.22);
    outline: 1px solid var(--kin);
    font-weight: 700;
}
.wlb-rank {
    min-width: 46px;
    text-align: left;
    white-space: nowrap;
    font-weight: 700;
    color: #c7bca8;
}
.win-lb-row:nth-child(1) .wlb-rank { color: #d4af37; }   /* or */
.win-lb-row:nth-child(2) .wlb-rank { color: #b8b8c0; }   /* argent */
.win-lb-row:nth-child(3) .wlb-rank { color: #cd7f32; }   /* bronze */
.wlb-name { flex: 1; text-align: left; color: var(--text-cream); }
.wlb-time {
    font-family: 'Courier New', 'Consolas', monospace;
    font-weight: 700;
    color: #3ddc84;
}
.win-lb-empty {
    list-style: none;
    text-align: center;
    padding: 10px;
    color: #c7bca8;
    font-style: italic;
}
.win-lb-btn {
    margin-top: 10px;
    width: 100%;
    font-size: 13px;
    padding: 8px;
}

.record-row {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.record-row:last-child {
    border-bottom: none;
}

.record-label {
    flex: 1;
    font-size: 12px;
    font-weight: 600;
    color: #c7bca8;
    text-align: left;
    letter-spacing: 1px;
}

.record-value {
    font-family: 'Courier New', 'Consolas', monospace;
    font-size: 16px;
    font-weight: 700;
    color: var(--kin);
    min-width: 90px;
    text-align: right;
}

.record-player {
    font-size: 11px;
    color: var(--text-light);
    min-width: 80px;
    text-align: right;
    margin-left: 10px;
}

.record-row.new-record .record-value {
    color: #00ff88;
    text-shadow: 0 0 5px rgba(0, 255, 136, 0.3);
}

.win-status {
    font-size: 14px;
    font-weight: 600;
    color: var(--midori);
    margin: 15px 0;
    min-height: 20px;
}

.win-status.error {
    color: var(--aka);
}

/* Game Over Modal */
.gameover-modal {
    text-align: center;
    min-width: 320px;
}

.gameover-modal h2 {
    color: var(--aka);
}

.gameover-message {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-medium);
    margin: 20px 0 10px;
}

.gameover-stats {
    font-size: 14px;
    color: var(--text-light);
    margin-bottom: 25px;
}

.gameover-stats span {
    font-weight: 700;
    color: var(--kin);
}

.gameover-modal .game-btn {
    display: block;
    width: 100%;
    margin-bottom: 10px;
}

.gameover-modal .game-btn.small {
    background: var(--bg-paper-dark);
    color: var(--text-medium);
    border: 1px solid var(--border-light);
}

.gameover-modal .game-btn.small:hover {
    background: var(--bg-wood);
    color: var(--text-cream);
}

/* ========================================
   Leaderboard Panel Styles
   ======================================== */

/* Leaderboard button in header */
.leaderboard-btn {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    background: linear-gradient(180deg, var(--kin) 0%, #b8942e 100%);
    color: var(--sumi);
    font-weight: 700;
    font-size: 11px;
    padding: 8px 14px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-shadow: 0 1px 0 rgba(255,255,255,0.3);
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    transition: var(--transition);
}

.leaderboard-btn:hover {
    background: linear-gradient(180deg, #e8c55a 0%, var(--kin) 100%);
    transform: translateY(-50%) scale(1.05);
}

/* Leaderboard Panel - same size as board-container */
#leaderboard-panel {
    background: linear-gradient(180deg, #2a2520 0%, #1a1815 100%);
    flex: 1;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    padding: 15px;
    position: relative;
    overflow-y: auto;
    /* Same borders as board-container */
    border-left: 8px solid var(--bg-wood-dark);
    border-right: 8px solid var(--bg-wood-dark);
    box-shadow:
        inset 0 0 0 12px #1a1a1a,
        inset 16px 0 8px rgba(0,0,0,0.15),
        inset -16px 0 8px rgba(0,0,0,0.15);
}

/* Door opening animation */
.door-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    z-index: 10;
    pointer-events: none;
}

.door {
    flex: 1;
    background: var(--bg-tatami);
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(139, 115, 85, 0.1) 2px,
            rgba(139, 115, 85, 0.1) 4px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 40px,
            rgba(139, 115, 85, 0.15) 40px,
            rgba(139, 115, 85, 0.15) 42px
        );
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

.door-left {
    transform-origin: left center;
    animation: doorOpenLeft 0.6s ease-in-out forwards;
    border-right: 3px solid var(--bg-wood-dark);
}

.door-right {
    transform-origin: right center;
    animation: doorOpenRight 0.6s ease-in-out forwards;
    border-left: 3px solid var(--bg-wood-dark);
}

@keyframes doorOpenLeft {
    0% {
        transform: translateX(0);
    }
    100% {
        transform: translateX(-100%);
    }
}

@keyframes doorOpenRight {
    0% {
        transform: translateX(0);
    }
    100% {
        transform: translateX(100%);
    }
}

/* Content appears after doors open */
#leaderboard-panel .leaderboard-filters,
#leaderboard-panel .leaderboard-content,
#leaderboard-panel .leaderboard-footer {
    opacity: 0;
    animation: fadeIn 0.3s ease-out 0.5s forwards;
}

@keyframes fadeIn {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

/* Filters */
.leaderboard-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    justify-content: center;
    margin-bottom: 20px;
    padding: 15px;
    background: rgba(0,0,0,0.3);
    border-radius: var(--radius-sm);
}

/* Aperçu visuel du stage sélectionné — montre la "tête" du stage, pas juste son nom */
.lb-stage-header {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0;
    margin-bottom: 14px;
    padding: 12px 16px;
    background: linear-gradient(180deg, rgba(0,0,0,0.35), rgba(0,0,0,0.15));
    border: 1px solid var(--kin);
    border-radius: var(--radius-sm);
}

.lb-stage-header.hidden { display: none; }

/* Groupe flèches + titre, centré dans tout le bandeau (l'espaceur à droite
   compense la largeur de l'aperçu à gauche). Les flèches entourent le titre. */
.lb-stage-nav {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

/* Espaceur droit = largeur de l'aperçu, pour un centrage parfait du titre */
.lb-stage-spacer {
    width: 170px;
    flex-shrink: 0;
}

/* Bouton titre cliquable -> ouvre la map des stages */
.lb-stage-pick {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-width: 200px;
    background: transparent;
    border: none;
    border-radius: 8px;
    padding: 6px 12px;
    cursor: pointer;
    transition: var(--transition);
}
.lb-stage-pick:hover {
    background: rgba(207, 192, 159, 0.12);
}

/* Flèches de navigation stage ‹ › */
.lb-nav-arrow {
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid var(--kin);
    background: rgba(0,0,0,0.35);
    color: var(--kin);
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    transition: var(--transition);
}
.lb-nav-arrow:hover {
    background: var(--kin);
    color: var(--sumi);
}

#lb-stage-preview {
    width: 170px;
    height: 104px;
    flex-shrink: 0;
    border-radius: 6px;
    border: 1px solid rgba(207, 192, 159, 0.35);
    background: #1a1a2e;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
    cursor: pointer;
}

.lb-stage-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.lb-stage-name {
    font-family: 'Noto Serif JP', serif;
    font-size: clamp(20px, 2.4vw, 30px);
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--kin, #cfc09f);
    text-transform: uppercase;
}

.lb-stage-sub {
    font-size: 12px;
    color: var(--text-cream);
    opacity: 0.65;
    text-align: left;
}

/* Sélecteur de période (All-time / Month / Week) */
.lb-periods {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 16px;
}

/* Ligne "ta place" si hors du top affiché */
.lb-myrank {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 12px;
    padding: 12px 18px;
    background: rgba(212, 168, 75, 0.16);
    border: 1px solid var(--kin);
    border-radius: var(--radius-sm);
}
.lb-myrank.hidden { display: none; }
.lb-myrank-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: var(--kin);
}
.lb-myrank-rank {
    font-size: 18px;
    font-weight: 700;
    color: var(--kin);
}
.lb-myrank-name {
    flex: 1;
    font-weight: 600;
    color: var(--text-cream);
}
.lb-myrank-time {
    font-family: 'Courier New', 'Consolas', monospace;
    font-weight: 700;
    color: #3ddc84;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.filter-group label {
    color: var(--text-cream);
    font-weight: 500;
    font-size: 13px;
    opacity: 0.8;
}

#lb-layout-select,
#lb-period-select,
#lb-view-select {
    background: var(--bg-wood-dark);
    color: var(--text-cream);
    border: 1px solid var(--kin);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    min-width: 100px;
}

#lb-layout-select:focus,
#lb-period-select:focus,
#lb-view-select:focus {
    outline: none;
    border-color: var(--kin);
    box-shadow: 0 0 0 2px rgba(212, 168, 75, 0.3);
}

.period-buttons,
.view-buttons {
    display: flex;
    gap: 4px;
}

.period-btn,
.view-btn {
    background: var(--bg-wood-dark);
    color: var(--text-cream);
    border: 1px solid transparent;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    border-radius: var(--radius-sm);
}

.period-btn:hover,
.view-btn:hover {
    background: var(--bg-wood);
    border-color: var(--kin);
}

.period-btn.active,
.view-btn.active {
    background: linear-gradient(180deg, var(--kin) 0%, #b8942e 100%);
    color: var(--sumi);
    font-weight: 700;
    border-color: var(--kin);
}

/* Special World Records button */
.view-btn.wr-btn {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #1a1a2e 100%);
    border: 1px solid #d4af37;
    color: #ffd700;
    font-weight: 600;
    text-shadow: 0 0 8px rgba(255, 215, 0, 0.5);
    box-shadow:
        0 0 10px rgba(212, 175, 55, 0.3),
        inset 0 1px 0 rgba(255, 215, 0, 0.2);
    position: relative;
    overflow: hidden;
}

.view-btn.wr-btn::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(
        45deg,
        transparent 30%,
        rgba(255, 215, 0, 0.1) 50%,
        transparent 70%
    );
    animation: wr-shimmer 3s ease-in-out infinite;
}

@keyframes wr-shimmer {
    0% { transform: translateX(-100%) rotate(45deg); }
    100% { transform: translateX(100%) rotate(45deg); }
}

.view-btn.wr-btn:hover {
    background: linear-gradient(135deg, #1a1a2e 0%, #0f3460 50%, #1a1a2e 100%);
    border-color: #ffd700;
    box-shadow:
        0 0 20px rgba(255, 215, 0, 0.5),
        inset 0 1px 0 rgba(255, 215, 0, 0.3);
    color: #fff8dc;
}

.view-btn.wr-btn.active {
    background: linear-gradient(135deg, #d4af37 0%, #ffd700 50%, #d4af37 100%);
    color: #1a1a2e;
    text-shadow: none;
    font-weight: 700;
    box-shadow:
        0 0 25px rgba(255, 215, 0, 0.6),
        inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

/* Leaderboard Table */
.leaderboard-content {
    flex: 1;
    overflow-y: auto;
}

#leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

#leaderboard-table thead {
    position: sticky;
    top: 0;
    background: var(--bg-wood-dark);
}

#leaderboard-table th {
    padding: 12px 15px;
    text-align: left;
    color: var(--kin);
    font-weight: 700;
    font-size: 12px;
    letter-spacing: 1px;
    border-bottom: 2px solid var(--kin);
}

#leaderboard-table td {
    padding: 12px 15px;
    color: var(--text-cream);
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

#leaderboard-table tbody tr:hover {
    background: rgba(212, 168, 75, 0.1);
}

#leaderboard-table tbody tr.highlight {
    background: rgba(212, 168, 75, 0.2);
    font-weight: 600;
}

#leaderboard-table .rank-cell {
    font-weight: 700;
    color: var(--kin);
    font-size: 16px;
    white-space: nowrap;
    vertical-align: middle;
}

#leaderboard-table .rank-1 { color: #ffd700; }
#leaderboard-table .rank-2 { color: #c0c0c0; }
#leaderboard-table .rank-3 { color: #cd7f32; }
#leaderboard-table .rank-cell .medal {
    font-size: 18px;
    line-height: 1;
    margin-left: 4px;
    vertical-align: middle;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}

#leaderboard-table .time-cell {
    font-family: 'Courier New', 'Consolas', monospace;
    color: #00ff88;
    font-weight: 600;
}

#leaderboard-table .date-cell {
    color: var(--text-light);
    font-size: 12px;
}

/* Empty and Loading states */
#leaderboard-empty,
#leaderboard-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
    color: var(--text-light);
    font-style: italic;
}

/* World Record Footer */
.leaderboard-footer {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.world-record {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    padding: 10px;
    background: rgba(212, 168, 75, 0.1);
    border-radius: var(--radius-sm);
    border: 1px solid var(--kin);
}

.wr-label {
    color: var(--kin);
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 1px;
}

#wr-time {
    font-family: 'Courier New', 'Consolas', monospace;
    color: #ffd700;
    font-size: 18px;
    font-weight: 700;
}

#wr-player {
    color: var(--text-cream);
    font-weight: 500;
}

/* Responsive */
/* Sound Toggle Button in Menu */
.sound-menu-btn .sound-on,
.sound-menu-btn .sound-off {
    display: inline;
}

.sound-menu-btn .sound-off {
    color: #888;
}

/* Tileset selection */
.tileset-preview-img {
    height: 28px;
    vertical-align: middle;
    margin-left: 8px;
    border-radius: 4px;
    border: 1px solid rgba(255,255,255,0.3);
}

.tileset-options {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-bottom: 20px;
}

.tileset-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 15px 20px;
    background: rgba(0,0,0,0.05);
    border: 2px solid rgba(90,60,25,0.25);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    /* Dark text: the modal background is cream, so cream text was invisible
       (and unreadable on the gold hover/selected state). */
    color: var(--text-dark);
    font-family: var(--font-main);
    font-size: 12px;
}

.tileset-option:hover {
    background: rgba(201,154,46,0.28);
    border-color: #b8860b;
    color: var(--text-dark);
}

.tileset-option.selected {
    background: rgba(201,154,46,0.42);
    border-color: #8a6508;
    color: var(--text-dark);
    font-weight: 700;
}

.tileset-option-img {
    width: 48px;
    height: 52px;
    border-radius: 4px;
}

/* Desktop/Mobile visibility classes */
.mobile-only {
    display: none;
}

@media (max-width: 700px) {
    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: block !important;
    }

    .leaderboard-filters {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px;
        margin-bottom: 10px;
    }

    .filter-group {
        flex: 1 1 auto;
        min-width: 120px;
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 8px;
    }

    .filter-group label {
        font-size: 10px;
        white-space: nowrap;
    }

    .filter-group select {
        flex: 1;
        font-size: 11px;
        padding: 6px 8px;
        min-width: 0;
    }

    #leaderboard-table {
        font-size: 11px;
    }

    #leaderboard-table th,
    #leaderboard-table td {
        padding: 6px 4px;
    }

    /* Hide world record footer on mobile */
    .leaderboard-footer {
        display: none;
    }
}

/* Very small screens */
@media (max-width: 400px) {
    .leaderboard-filters {
        flex-direction: column;
        gap: 10px;
    }

    .filter-group {
        width: 100%;
        justify-content: space-between;
    }

    .filter-group label {
        min-width: 45px;
    }

    .filter-group select {
        font-size: 12px;
        padding: 8px;
    }
}

/* ==================== STAGE WATERMARK ==================== */

#board-container::after {
    content: attr(data-stage);
    position: absolute;
    bottom: 5px;
    left: 100px;
    font-family: 'Noto Serif JP', serif;
    font-size: clamp(36px, 5vw, 64px);
    font-weight: 700;
    letter-spacing: 4px;
    color: rgba(45, 74, 53, 0.3);
    pointer-events: none;
    text-transform: uppercase;
    line-height: 1;
    z-index: 0;
}

/* Hide watermark on mobile */
@media (max-width: 768px) {
    #board-container::after {
        display: none;
    }
}

/* Hide watermark in fullscreen */
#game-container:fullscreen #board-container::after,
#game-container:-webkit-full-screen #board-container::after {
    display: none;
}

/* ==================== FULLSCREEN BUTTON ==================== */

/* Board controls container - bottom right of board-container */
#board-controls {
    position: absolute;
    bottom: 10px;
    right: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 50;
}

/* Fullscreen toggle button */
#btn-fullscreen-toggle {
    width: 36px;
    height: 36px;
    border: 1px solid rgba(207, 192, 159, 0.5);
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.5);
    color: #cfc09f;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

#btn-fullscreen-toggle:hover {
    background: rgba(0, 0, 0, 0.7);
    color: #ffecb3;
    border-color: #cfc09f;
    transform: scale(1.05);
}

/* When game-container is fullscreen */
#game-container:fullscreen,
#game-container:-webkit-full-screen,
#game-container:-moz-full-screen,
#game-container:-ms-fullscreen {
    width: 100vw;
    height: 100vh;
    max-width: none;
    max-height: none;
    background: var(--bg-primary);
    /* Bord-à-bord : protéger header (haut/côtés) et #board-controls (bas/droite,
       en absolute dans le conteneur) des encoches. border-box (reset global) garde
       le tout dans le viewport. Insets = 0 sur desktop -> sans effet. */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#game-container:fullscreen #board-container,
#game-container:-webkit-full-screen #board-container {
    flex: 1;
    max-width: none;
    width: 100%;
    height: calc(100vh - 120px);
}

#game-container:fullscreen #game-board,
#game-container:-webkit-full-screen #game-board {
    max-width: 95vw;
    max-height: calc(100vh - 140px);
    width: auto;
    height: auto;
}

/* Mobile landscape fullscreen - minimize header space and maximize board */
@media (max-height: 500px) {
    #game-container:fullscreen #header,
    #game-container:-webkit-full-screen #header {
        padding: 2px 8px;
        gap: 4px;
    }

    #game-container:fullscreen #header h1,
    #game-container:-webkit-full-screen #header h1 {
        font-size: 14px;
    }

    #game-container:fullscreen .header-btn,
    #game-container:-webkit-full-screen .header-btn {
        padding: 2px 6px;
        font-size: 10px;
    }

    #game-container:fullscreen #board-container,
    #game-container:-webkit-full-screen #board-container {
        height: calc(100vh - 30px);
        padding: 0;
    }

    #game-container:fullscreen #game-board,
    #game-container:-webkit-full-screen #game-board {
        max-width: 100%;
        max-height: 100%;
        width: auto;
        height: auto;
        object-fit: contain;
    }
}

/* Leaderboard panel in fullscreen */
#game-container:fullscreen #leaderboard-panel,
#game-container:-webkit-full-screen #leaderboard-panel {
    flex: 1;
    height: auto;
    min-height: auto;
    max-width: none;
    display: flex;
    flex-direction: column;
}

#game-container:fullscreen #leaderboard-panel .leaderboard-content,
#game-container:-webkit-full-screen #leaderboard-panel .leaderboard-content {
    flex: 1;
    overflow-y: auto;
}

/* ==================== MODALS IN FULLSCREEN ==================== */
#game-container:fullscreen .modal,
#game-container:-webkit-full-screen .modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
}

#game-container:fullscreen .modal-content,
#game-container:-webkit-full-screen .modal-content {
    max-width: 90vw;
    max-height: 85vh;
    overflow-y: auto;
}

#game-container:fullscreen .layout-modal,
#game-container:-webkit-full-screen .layout-modal {
    min-width: auto;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
}

/* Fullscreen modals on small screens */
@media (max-width: 700px) {
    #game-container:fullscreen .modal-content,
    #game-container:-webkit-full-screen .modal-content {
        max-width: 95vw;
        max-height: 90vh;
        padding: 16px;
    }

    #game-container:fullscreen .layout-modal,
    #game-container:-webkit-full-screen .layout-modal {
        width: calc(100vw - 20px);
        max-height: 85vh;
        padding: 12px;
    }

    #game-container:fullscreen #layout-grid,
    #game-container:-webkit-full-screen #layout-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
}

/* Lien discret vers la politique de confidentialité (menu) */
.menu-link-privacy {
    display: inline-block;
    margin-top: 10px;
    font-size: 12px;
    color: var(--text-medium);
    opacity: 0.8;
    text-decoration: underline;
}
.menu-link-privacy:hover { opacity: 1; color: var(--kin); }

/* Bouton Retour du menu — un peu d'espace au-dessus pour le détacher des items */
.menu-back-btn { display: block; width: fit-content; margin: 16px auto 0; }

/* ===== Drapeaux pays (classement) ===== */
.flag {
    display: inline-block;
    width: 22px;
    height: 16px;
    object-fit: cover;
    vertical-align: middle;
    margin-right: 8px;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.25);
}
#leaderboard-table .player-cell .flag { margin-right: 8px; }
.wlb-name .flag { margin-right: 6px; width: 18px; height: 13px; }
.lb-myrank-name .flag { margin-right: 6px; }

/* Sélecteur de pays dans les formulaires/modale */
.auth-select {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    margin: 6px 0;
    background: var(--bg-wood-dark, #5c4a3a);
    color: var(--text-cream, #f5f1eb);
    border: 1px solid var(--kin, #d4a84b);
    border-radius: var(--radius-sm, 6px);
    font-size: 14px;
}
#country-modal .modal-content { text-align: center; max-width: 420px; }
#country-modal .auth-select { margin: 14px 0; }

/* ===== Panneau "Mon compte" ===== */
.account-modal { text-align: left; max-width: 460px; max-height: 86vh; overflow-y: auto; }
.account-modal h2 { text-align: center; }
.account-line { text-align: center; margin: 4px 0 14px; }
.account-section { margin: 14px 0; padding: 12px 14px; background: rgba(0,0,0,0.05); border-radius: 8px; }
.account-section > label { display: block; font-weight: 700; font-size: 13px; margin-bottom: 6px; }
.account-section input,
.account-section .auth-select {
    width: 100%; box-sizing: border-box; margin: 5px 0;
    padding: 9px 11px; border: 1px solid var(--kin, #d4a84b); border-radius: 6px;
    background: var(--bg-wood-dark, #5c4a3a); color: var(--text-cream, #f5f1eb); font-size: 14px;
}
.account-btn { width: 100%; margin-top: 8px; font-size: 13px; padding: 9px; }
.account-msg { text-align: center; min-height: 18px; font-size: 13px; margin: 8px 0; }
.account-msg.ok { color: #2e7d32; font-weight: 600; }
.account-msg.err { color: #c62828; font-weight: 600; }
.account-danger { margin-top: 14px; border-top: 1px solid rgba(0,0,0,0.15); padding-top: 14px; text-align: center; }
.danger-btn { background: #b3261e; color: #fff; }
.danger-btn:hover { background: #8f1d17; color: #fff; }
.danger-text { color: #b3261e; font-size: 13px; margin: 10px 0; }
#delete-confirm input {
    width: 100%; box-sizing: border-box; margin: 6px 0; padding: 9px 11px;
    border: 1px solid #b3261e; border-radius: 6px;
    background: var(--bg-wood-dark, #5c4a3a); color: var(--text-cream, #f5f1eb);
}

/* Bouton de suppression rendu discret (secondaire), pas comme un CTA principal */
.danger-label {
    display: block; font-size: 11px; letter-spacing: 1px; text-transform: uppercase;
    color: #9a9a9a; margin-bottom: 8px;
}
.delete-trigger {
    background: transparent; color: #b3261e; border: 1px solid #d9a8a4;
    border-radius: 6px; padding: 7px 14px; font-size: 12px; cursor: pointer;
    transition: var(--transition);
}
.delete-trigger:hover { background: #b3261e; color: #fff; border-color: #b3261e; }

/* ===== Titre avec dragons dorés ===== */
.title-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(6px, 1.4vw, 16px);
    min-width: 0;
}
.title-stack { display: flex; flex-direction: column; align-items: center; line-height: 1.02; }
.title-stack h1 { margin: 0; }
.title-sub {
    font-family: 'Noto Serif JP', serif;
    font-weight: 700;
    color: var(--kin, #d4a84b);
    letter-spacing: clamp(2px, 1vw, 9px);
    font-size: clamp(8px, 1.4vw, 14px);
    margin-top: 2px;
    text-transform: uppercase;
}
.title-dragon {
    height: clamp(30px, 5.4vw, 54px);
    width: auto;
    flex-shrink: 0;
    filter: drop-shadow(0 1px 3px rgba(0,0,0,0.45));
}
.title-dragon.flip { transform: scaleX(-1); }

/* Le select Pays des formulaires d'inscription doit matcher les champs texte (fond clair) */
.auth-modal .auth-select {
    padding: 12px 15px;
    background: var(--bg-paper);
    color: var(--text-dark);
    border: 1px solid var(--border-light);
}

/* ===== Modale Suggestions / boîte à idées ===== */
.feedback-modal { max-width: 460px; text-align: center; }
#feedback-modal textarea,
#feedback-modal input {
    width: 100%;
    box-sizing: border-box;
    margin: 8px 0;
    padding: 10px 12px;
    border: 1px solid var(--kin, #d4a84b);
    border-radius: var(--radius-sm, 6px);
    background: var(--bg-paper, #f5f1eb);
    color: var(--text-dark, #2b2b2b);
    font-family: inherit;
    font-size: 14px;
}
#feedback-modal textarea { resize: vertical; min-height: 90px; }
#feedback-modal #btn-send-feedback { width: 100%; margin-top: 8px; }

/* ===== Nudge d'avis (écran de victoire, une seule fois) ===== */
.rate-nudge {
    margin: 10px 0 4px;
    padding: 10px 12px;
    background: rgba(212, 168, 75, 0.12);
    border: 1px solid var(--kin, #d4a84b);
    border-radius: 8px;
}
.rate-nudge p { margin: 0 0 8px; font-size: 13px; }
.rate-nudge-btn { font-size: 13px; padding: 8px 14px; }

/* ===== Mode portail (CrazyGames, Yandex, Poki…) ===== */
/* Règles portail : jeu en invité par défaut, pas de gestion de compte email,
   pas de lien vers d'autres stores. CrazyGames/Yandex : le bouton LOGIN reste
   mais déclenche la connexion du portail (géré en JS). */
html.portal-crazygames #btn-account,
html.portal-crazygames #btn-rate,
html.portal-crazygames #rate-nudge,
html.portal-yandex #btn-account,
html.portal-yandex #btn-rate,
html.portal-yandex #rate-nudge,
html.portal-facebook #btn-account,
html.portal-facebook #btn-rate,
html.portal-facebook #rate-nudge {
    display: none !important;
}

/* Poki : aucun compte possible (collecte d'email interdite, pas de login SDK
   adapté à nos classements) — tout le circuit de connexion disparaît, et la
   modale de victoire invité se réduit au temps + CONTINUE. */
html.portal-poki #btn-login,
html.portal-poki #burger-login,
html.portal-poki #btn-account,
html.portal-poki #btn-rate,
html.portal-poki #rate-nudge,
html.portal-poki #email-guest-prompt,
html.portal-poki #guest-login-form-container {
    display: none !important;
}

/* Boîte à idées : le champ email (optionnel) reste une collecte de donnée
   personnelle — interdite chez Poki, à éviter chez Yandex (loi 152-FZ) et
   chez Facebook (règles données du mode Zero Permissions). */
html.portal-poki #feedback-email,
html.portal-yandex #feedback-email,
html.portal-facebook #feedback-email {
    display: none !important;
}
