/* ==========================================
   ULTIMATE TIC-TAC-TOE STYLES
   ========================================== */
:root {
    --bg-color: #121212;
    --text-color: #ffffff;
    --x-color: #00d2ff;
    --o-color: #ff0055;
    --grid-line: #333333;
    --active-bg: rgba(255, 215, 0, 0.08);
    --active-border: #ffd700;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-height: 100vh; margin: 0; overflow-x: hidden;
}

h1 { font-size: 2.5rem; text-align: center; margin: 0 0 30px 0; white-space: pre-line; }

.screen { display: none; flex-direction: column; align-items: center; width: 100%; max-width: 600px; }
.screen.active { display: flex; }

button {
    background-color: #2a2a2a; color: white; border: 2px solid #444;
    padding: 15px 30px; margin: 10px; font-size: 1.2rem; cursor: pointer;
    border-radius: 8px; width: 80%; transition: all 0.2s;
    font-family: inherit;
}
button:hover:not(:disabled) { background-color: #444; border-color: var(--x-color); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.input-field {
    padding: 15px; width: 80%; font-size: 1.4rem; text-align: center;
    background: #222; color: white; border: 2px solid #444; border-radius: 8px;
    text-transform: uppercase; margin-bottom: 10px; font-weight: bold;
}
.input-field:focus { outline: none; border-color: var(--x-color); }

select.input-field { font-size: 0.95rem; } /* Ensures long texts fit in dropdowns */

h2 { font-size: 1.2rem; margin: 10px 0 5px 0; color: #aaa; }

.status-text { color: var(--active-border); font-size: 1.1rem; text-align: center; margin: 15px 0; min-height: 25px; font-weight: bold; }

.toggle-container {
    display: flex; justify-content: space-between; align-items: center;
    width: 80%; background: #222; padding: 15px; border-radius: 8px; margin-bottom: 20px;
    gap: 15px;
}

.toggle-container > span {
    flex: 1;
    text-align: start;
}

.switch { 
    position: relative; display: inline-block; width: 60px; height: 34px; 
    flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #444; transition: .4s; border-radius: 34px; }
.slider:before { position: absolute; content: ""; height: 26px; width: 26px; left: 4px; bottom: 4px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--o-color); }
input:checked + .slider:before { transform: translateX(26px); }

#score-board { font-size: 1.2rem; margin-bottom: 10px; color: #aaa; background: #222; padding: 5px 20px; border-radius: 20px; border: 1px solid #333; }
#game-info { font-size: 1.5rem; margin-bottom: 5px; text-align: center; }
#network-role { font-size: 1rem; color: #aaa; margin-bottom: 20px; text-align: center; }
#game-info span { font-weight: bold; }
.turn-x { color: var(--x-color); }
.turn-o { color: var(--o-color); }

.super-board {
    display: grid; grid-template-columns: repeat(3, max-content); gap: 12px;
    background-color: #000; padding: 12px; border-radius: 12px;
}
.super-board.shake { animation: shake 0.4s ease-in-out; }

.macro-cell {
    display: grid; 
    grid-template-columns: 52px 52px 52px; 
    grid-template-rows: 52px 52px 52px; 
    gap: 3px;
    background-color: var(--grid-line); width: 162px; height: 162px;
    position: relative; border-radius: 6px; overflow: hidden; transition: background-color 0.2s ease;
}
.macro-cell.active-macro { background-color: #444; outline: 4px solid var(--active-border); outline-offset: -4px; z-index: 2; }
.macro-cell.detonated { background-color: #ff1100 !important; transition: none; }

.micro-cell {
    background-color: #1a1a1a; display: flex; justify-content: center; align-items: center;
    font-size: 2rem; font-weight: bold; cursor: pointer; user-select: none;
    transition: background-color 0.15s; line-height: 1; min-width: 0; min-height: 0;
}
.micro-cell:hover { background-color: #252525; }
.micro-cell.x { color: var(--x-color); }
.micro-cell.o { color: var(--o-color); }

.macro-won {
    display: flex !important; justify-content: center; align-items: center;
    font-size: 6rem; font-weight: bold; background-color: var(--bg-color) !important;
    width: 162px; height: 162px; line-height: 1;
}
.macro-won.x { color: var(--x-color); }
.macro-won.o { color: var(--o-color); }
.macro-won.draw { color: #555; font-size: 4rem; }

#emote-bar { display: none; gap: 10px; margin-top: 15px; justify-content: center; width: 80%; }
.emote-btn { background: #222; border: 1px solid #444; font-size: 1.5rem; padding: 8px; width: 50px; height: 50px; border-radius: 50%; display: flex; justify-content: center; align-items: center; cursor: pointer; transition: transform 0.1s; }
.emote-btn:hover { transform: scale(1.2); border-color: var(--active-border); }

.floating-emote {
    position: fixed; bottom: -50px; font-size: 3rem; z-index: 200;
    animation: flyUp 1.5s forwards; pointer-events: none;
}

#game-over-controls { display: none; flex-direction: column; align-items: center; width: 100%; margin-top: 15px; }
#game-over-controls button { background-color: #2e7d32; border-color: #1b5e20; width: auto; min-width: 200px; }
#game-over-controls button:hover { background-color: #388e3c; border-color: var(--x-color); }

.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.75); z-index: 100;
    justify-content: center; align-items: center; opacity: 0;
    transition: opacity 0.2s ease;
}
.modal-overlay.active { display: flex; opacity: 1; }
.modal-box {
    background-color: #1e1e1e; border: 2px solid #444; border-radius: 12px;
    padding: 30px; max-width: 400px; width: 85%; text-align: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5); transform: scale(0.8); transition: transform 0.2s ease;
}
.modal-overlay.active .modal-box { transform: scale(1); }
.modal-title { font-size: 1.8rem; font-weight: bold; margin-bottom: 15px; }
.modal-text { font-size: 1.2rem; color: #ccc; margin-bottom: 25px; line-height: 1.4; }
.modal-btn { background-color: #333; border-color: #555; width: auto; min-width: 120px; padding: 10px 20px; font-size: 1rem; margin: 0; }
.modal-btn:hover { background-color: #444; border-color: #ffd700; }

#toss-overlay { 
    display: none; position: fixed; top:0; left:0; width:100%; height:100%; 
    background: rgba(0,0,0,0.95); z-index: 300; 
    justify-content: center; align-items: center; flex-direction: column; 
}
#toss-overlay.active { display: flex; }
.toss-symbol { font-size: 12rem; font-weight: bold; transition: transform 0.1s; }
.toss-text { font-size: 1.5rem; color: #fff; margin-bottom: 20px; text-transform: uppercase; letter-spacing: 2px;}

.lang-selector {
    display: flex; gap: 12px; margin-top: 25px; background: #1e1e1e;
    padding: 10px 20px; border-radius: 30px; border: 1px solid #333;
    align-items: center; flex-wrap: wrap; justify-content: center;
}
.lang-flag {
    font-size: 2rem; cursor: pointer; transition: transform 0.2s, filter 0.2s;
    filter: grayscale(50%);
    display: flex; 
    align-items: center;
    justify-content: center;
    border-bottom: 2px solid transparent; 
    padding-bottom: 2px;
}
.lang-flag:hover { transform: scale(1.2); filter: grayscale(0%); }
.lang-flag.active-lang { filter: grayscale(0%); transform: scale(1.1); border-bottom: 2px solid var(--x-color); }

body.rtl-mode { direction: rtl; }
body.rtl-mode .toggle-container { flex-direction: row-reverse; }

@keyframes shake {
    0%, 100% { transform: translate(0, 0); }
    10%, 30%, 50%, 70%, 90% { transform: translate(-6px, -4px); }
    20%, 40%, 60%, 80% { transform: translate(6px, 4px); }
}
@keyframes flyUp {
    0% { bottom: -50px; opacity: 0; transform: translateX(0) scale(0.5); }
    10% { opacity: 1; transform: scale(1.2); }
    90% { opacity: 1; }
    100% { bottom: 105vh; opacity: 0; transform: translateX(var(--drift)) scale(1); }
}

@media (max-width: 600px) {
    .macro-cell { 
        grid-template-columns: 34px 34px 34px; 
        grid-template-rows: 34px 34px 34px; 
        width: 106px; height: 106px; gap: 2px; 
    }
    .macro-won { width: 106px; height: 106px; font-size: 4.5rem; }
    .micro-cell { font-size: 1.3rem; }
    .macro-won.draw { font-size: 2.5rem; }
}

/* Forces standard western font for game symbols */
.micro-cell, 
.macro-won, 
#current-player-display, 
.toss-symbol,
#score-board {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif !important;
}

/* --- THEME TOGGLE BUTTON --- */
.theme-selector {
    display: flex; align-items: center; justify-content: center;
    background: #1e1e1e; padding: 10px; border-radius: 50%;
    border: 1px solid #333; cursor: pointer; transition: transform 0.2s, background 0.2s;
}
.theme-selector:hover { transform: scale(1.1); }
#theme-icon {
    height: 24px; width: 24px; 
    filter: grayscale(100%) opacity(0.5); /* Off by default */
    transition: filter 0.3s, opacity 0.3s;
}

#timer-display {
    display: none; background: #222; padding: 10px 20px; border-radius: 20px; 
    border: 1px solid #444; margin-bottom: 15px; font-size: 1.2rem; font-weight: bold; color: #fff;
    align-items: center; justify-content: center; gap: 10px; width: 80%; max-width: 400px;
}

/* --- LIGHT MODE OVERRIDES --- */
body.light-mode {
    --bg-color: #f0f4f8;
    --text-color: #121212;
    --grid-line: #888888;
}
body.light-mode #theme-icon {
    filter: grayscale(0%) opacity(1);
}
body.light-mode .super-board { background-color: #cccccc; }
body.light-mode .macro-cell { background-color: var(--grid-line); }
body.light-mode .macro-cell.active-macro { background-color: #aaaaaa; }
body.light-mode .micro-cell { background-color: #ffffff; }
body.light-mode .micro-cell:hover { background-color: #e8e8e8; }

body.light-mode button,
body.light-mode .input-field,
body.light-mode .toggle-container,
body.light-mode #score-board,
body.light-mode #timer-display,
body.light-mode .emote-btn,
body.light-mode .lang-selector,
body.light-mode .theme-selector,
body.light-mode .modal-box {
    background-color: #ffffff;
    color: #121212;
    border-color: #cccccc;
}
body.light-mode button:hover:not(:disabled) {
    background-color: #e2e2e2;
    border-color: var(--x-color);
}
body.light-mode .switch .slider { background-color: #bbbbbb; }
body.light-mode #toss-overlay { background: rgba(255, 255, 255, 0.95); }
body.light-mode .toss-text { color: #121212; }
body.light-mode h2, 
body.light-mode small, 
body.light-mode #network-role { color: #555555 !important; }

body.light-mode .screen > div[style*="background: #1e1e1e"] {
    background: #ffffff !important;
    border-color: #cccccc !important;
    color: #333333 !important;
}

body.light-mode .scrollable-content {
    background: #ffffff;
    color: #333333;
    border-color: #cccccc;
}

body.light-mode .scrollable-content hr {
    border-color: #cccccc !important;
}

.scrollable-content {
    width: 85%; max-width: 600px; background: #1e1e1e; padding: 20px; 
    border-radius: 8px; border: 1px solid #333; margin-top: 10px; 
    text-align: start; overflow-y: auto; max-height: 60vh; color: #ccc; line-height: 1.6;
}

/* Line breaks inside the network hint */
#txt-net-hint { white-space: pre-line; }

/* ==========================================
   MATROSHKA / GOBBLET TIC-TAC-TOE STYLES
   ========================================== */

.gobblet-board {
    display: grid; gap: 10px; background-color: #000000; padding: 15px; border-radius: 12px; margin-bottom: 20px;
}
body.light-mode .gobblet-board { background-color: #cccccc; }

.gobblet-board.grid-3x3 { grid-template-columns: repeat(3, 110px); grid-template-rows: repeat(3, 110px); }
.gobblet-board.grid-4x4 { grid-template-columns: repeat(4, 95px); grid-template-rows: repeat(4, 95px); gap: 8px; padding: 12px; }

.g-cell {
    background-color: var(--grid-line); position: relative; border-radius: 8px; display: flex; justify-content: center; align-items: center;
    cursor: pointer; transition: background-color 0.2s, outline 0.1s;
}
body.light-mode .g-cell { background-color: #ffffff; }

.grid-3x3 .g-cell { width: 110px; height: 110px; }
.grid-4x4 .g-cell { width: 95px; height: 95px; }

.g-cell:hover { background-color: #444; }
body.light-mode .g-cell:hover { background-color: #e8e8e8; }
.g-cell.valid-target { outline: 4px dashed #2e7d32; outline-offset: -4px; z-index: 5;}
.g-cell.selected { outline: 4px solid var(--active-border); outline-offset: -4px; background-color: #555; z-index: 5;}

.piece {
    border-radius: 50%; position: absolute; box-shadow: 0 4px 10px rgba(0,0,0,0.7);
    display: flex; justify-content: center; align-items: center; font-weight: bold;
    transition: transform 0.2s; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
/* 3x3 Sizes */
.grid-3x3 .piece.L { width: 90px; height: 90px; z-index: 3; border-width: 6px; font-size: 2.5rem; }
.grid-3x3 .piece.M { width: 60px; height: 60px; z-index: 2; border-width: 4px; font-size: 1.5rem; }
.grid-3x3 .piece.S { width: 30px; height: 30px; z-index: 1; border-width: 3px; font-size: 0.8rem; }

/* 4x4 Sizes */
.grid-4x4 .piece.XL { width: 85px; height: 85px; z-index: 4; border-width: 6px; font-size: 2.2rem; }
.grid-4x4 .piece.L { width: 65px; height: 65px; z-index: 3; border-width: 5px; font-size: 1.6rem; }
.grid-4x4 .piece.M { width: 45px; height: 45px; z-index: 2; border-width: 4px; font-size: 1.1rem; }
.grid-4x4 .piece.S { width: 25px; height: 25px; z-index: 1; border-width: 3px; font-size: 0.6rem; }

.piece.X { background: rgba(0, 210, 255, 0.15); border-style: solid; border-color: var(--x-color); color: var(--x-color); }
.piece.O { background: rgba(255, 0, 85, 0.15); border-style: solid; border-color: var(--o-color); color: var(--o-color); }
body.light-mode .piece.X { background: rgba(0, 210, 255, 0.3); }
body.light-mode .piece.O { background: rgba(255, 0, 85, 0.3); }

/* INVENTORY SYSTEM */
.inventories { display: flex; justify-content: space-between; width: 100%; max-width: 480px; margin-bottom: 15px; background: #1a1a1a; padding: 15px; border-radius: 12px; border: 1px solid #333;}
body.light-mode .inventories { background: #ffffff; border-color: #cccccc; }
.inv-player { display: flex; flex-direction: column; align-items: center; width: 48%; }
.inv-title { font-weight: bold; margin-bottom: 10px; font-size: 1.2rem; }
.inv-title.X { color: var(--x-color); }
.inv-title.O { color: var(--o-color); }

.inv-slots { display: flex; gap: 15px; align-items: flex-end; justify-content: center; height: 90px;}
.inv-slot { display: flex; flex-direction: column; align-items: center; cursor: pointer; position: relative; }
.inv-slot.disabled { opacity: 0.3; cursor: not-allowed; }
.inv-slot.selected .inv-piece-preview { outline: 4px solid var(--active-border); outline-offset: 4px; transform: scale(1.1); }

.inv-piece-preview { border-radius: 50%; display: flex; justify-content: center; align-items: center; margin-bottom: 8px; transition: transform 0.1s; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;}

/* Inv Previews 3x3 */
.mode-3x3 .inv-piece-preview.L { width: 60px; height: 60px; border-width: 4px; font-size: 1.5rem;}
.mode-3x3 .inv-piece-preview.M { width: 40px; height: 40px; border-width: 3px; font-size: 1rem;}
.mode-3x3 .inv-piece-preview.S { width: 25px; height: 25px; border-width: 2px; font-size: 0.7rem;}

/* Inv Previews 4x4 */
.mode-4x4 .inv-piece-preview.XL { width: 60px; height: 60px; border-width: 5px; font-size: 1.5rem;}
.mode-4x4 .inv-piece-preview.L { width: 48px; height: 48px; border-width: 4px; font-size: 1.2rem;}
.mode-4x4 .inv-piece-preview.M { width: 36px; height: 36px; border-width: 3px; font-size: 0.9rem;}
.mode-4x4 .inv-piece-preview.S { width: 24px; height: 24px; border-width: 2px; font-size: 0.6rem;}
.mode-4x4 .stack-indicator { position: absolute; bottom: -10px; font-size: 0.8rem; color: #888; }

.inv-piece-preview.X { background: rgba(0, 210, 255, 0.15); border-style: solid; border-color: var(--x-color); color: var(--x-color); }
.inv-piece-preview.O { background: rgba(255, 0, 85, 0.15); border-style: solid; border-color: var(--o-color); color: var(--o-color); }
body.light-mode .inv-piece-preview.X { background: rgba(0, 210, 255, 0.3); }
body.light-mode .inv-piece-preview.O { background: rgba(255, 0, 85, 0.3); }

.inv-count { font-size: 1rem; color: #ccc; background: #333; padding: 2px 8px; border-radius: 10px; font-weight: bold;}
body.light-mode .inv-count { background: #eee; color: #333; border: 1px solid #ccc;}

@media (max-width: 600px) {
    .gobblet-board.grid-3x3 { grid-template-columns: repeat(3, 90px); grid-template-rows: repeat(3, 90px); padding: 10px;}
    .grid-3x3 .g-cell { width: 90px; height: 90px; }
    .grid-3x3 .piece.L { width: 75px; height: 75px; border-width: 5px; font-size: 2rem;}
    .grid-3x3 .piece.M { width: 50px; height: 50px; font-size: 1.2rem;}
    .grid-3x3 .piece.S { width: 25px; height: 25px; font-size: 0.7rem;}
    
    .gobblet-board.grid-4x4 { grid-template-columns: repeat(4, 75px); grid-template-rows: repeat(4, 75px); padding: 8px; gap: 5px;}
    .grid-4x4 .g-cell { width: 75px; height: 75px; }
    .grid-4x4 .piece.XL { width: 65px; height: 65px; border-width: 5px; font-size: 1.6rem;}
    .grid-4x4 .piece.L { width: 50px; height: 50px; border-width: 4px; font-size: 1.2rem;}
    .grid-4x4 .piece.M { width: 35px; height: 35px; font-size: 0.9rem;}
    .grid-4x4 .piece.S { width: 20px; height: 20px; font-size: 0.5rem;}

    .inventories { padding: 10px; max-width: 360px;}
    .inv-slots { gap: 10px; }
}