:root {
    /* Colors - Fifteen Original Theme */
    --bg-dark: #020b1c;
    --bg-light: #0d2d5e;
    --primary: #ff9d00;
    /* Orange */
    --secondary: #00e5ff;
    /* Blue */
    --card-bg: #051630;
    --text: #ffffff;
    --border: rgba(255, 255, 255, 0.1);

    /* Responsive Tokens (Default: Wide) */
    --root-padding: 3vmin;
    --app-gap: 2vmin;
    --main-radius: 2.5vmin;
    --home-size: 10vmin;
    --board-size: 75vmin;
    /* Clear gap from screen edges */
    --tile-gap: 0.8vmin;
    /* Elegant internal gap */
}

/* --- SAFETY OVERLAY --- */
#size-warning {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    background: rgba(2, 11, 28, 0.98);
    z-index: 10000;
    display: none;
    justify-content: center;
    align-items: center;
    color: white;
    padding: 10vw;
    text-align: center;
}

.warning-box {
    background: #051630;
    padding: 6vmin;
    border-radius: 4vmin;
    border: 2px solid var(--primary);
    box-shadow: 0 0 5vmin var(--primary);
}

.warning-icon {
    font-size: 12vmin;
    display: block;
    margin-bottom: 2vmin;
}

.warning-box h2 {
    font-size: 6vmin;
    margin: 0 0 2vmin 0;
    color: var(--primary);
}

.warning-box p {
    font-size: 3.5vmin;
    color: var(--secondary);
    margin: 0;
}

/* Base Resets */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: radial-gradient(circle at center, var(--bg-light) 0%, var(--bg-dark) 100%);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: var(--text);
}

#app-root {
    display: flex;
    width: 100%;
    height: 100dvh;
    padding: var(--root-padding);
    gap: var(--app-gap);
    position: relative;
    overflow: hidden;
}

/* Main Content Structure */
#main-content {
    flex: 1;
    display: flex;
    gap: var(--app-gap);
    height: 100%;
    max-width: 1200px;
    margin: 0 auto;
}

/* LEFT/TOP: The Board */
#scene-container {
    flex: 1.5;
    background: var(--card-bg);
    border-radius: var(--main-radius);
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8), 0 10px 30px rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    border: 1px solid var(--border);
    overflow: hidden;
}

.board {
    width: var(--board-size);
    height: var(--board-size);
    max-width: 500px;
    max-height: 500px;
    position: relative;
    padding: 0;
    /* Padding is handled precisely by JS positioning */
}

.tile {
    background: linear-gradient(145deg, #2a5fb1, #163e7a);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-bottom: 4px solid rgba(0, 0, 0, 0.5);
    border-right: 2px solid rgba(0, 0, 0, 0.3);
    border-radius: 12%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(1rem, 6vmin, 2.5rem);
    font-weight: 800;
    color: white;
    cursor: pointer;
    box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
    transition: transform 0.1s cubic-bezier(0.25, 0.46, 0.45, 0.94), background 0.3s, border 0.1s;
    position: absolute;
    /* Precise width: (100% - 5 gaps) / 4 = 25% - 1.25 gaps */
    width: calc(25% - var(--tile-gap) * 1.25);
    height: calc(25% - var(--tile-gap) * 1.25);
}

.tile:active {
    transform: scale(0.92) translate(2px, 2px);
    border-bottom-width: 1px;
}

.tile.correct {
    background: linear-gradient(145deg, #00e676, #00a052);
    box-shadow: 0 0 15px rgba(0, 230, 118, 0.4);
}

/* RIGHT/BOTTOM: UI */
#interaction-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 3vmin;
    padding: 2vmin;
}

.stats-card {
    display: flex;
    flex-direction: column;
    gap: 2vmin;
}

.stat-item {
    background: rgba(0, 0, 0, 0.3);
    padding: 2vmin 3vmin;
    border-radius: 1.5vmin;
    border: 1px solid var(--secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat-item .label {
    color: var(--secondary);
    font-weight: bold;
    font-size: 2.5vmin;
}

.stat-item .value {
    color: white;
    font-weight: 900;
    font-size: 4vmin;
}

.action-btn {
    background: var(--primary);
    color: black;
    border: none;
    padding: 2.5vmin 4vmin;
    font-size: 3.5vmin;
    font-weight: bold;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 0.5vmin 2vmin rgba(255, 157, 0, 0.4);
    transition: all 0.2s;
}

.action-btn:active {
    transform: scale(0.95);
}

/* UI Layer */
.ui-layer {
    position: absolute;
    z-index: 1000;
}

.home-btn {
    width: var(--home-size);
    height: var(--home-size);
    background: var(--primary);
    color: black;
    font-size: calc(var(--home-size) * 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    text-decoration: none;
    border: 0.6vmin solid white;
    box-shadow: 0 1vmin 2vmin rgba(0, 0, 0, 0.3);
}

/* Victory Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    display: none;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(8px);
}

.modal-content {
    background: var(--bg-light);
    padding: 5vmin;
    border-radius: 4vmin;
    text-align: center;
    border: 2px solid var(--primary);
    box-shadow: 0 0 30px var(--primary);
}

.modal-content h2 {
    font-size: 8vmin;
    color: var(--primary);
    margin-bottom: 2vmin;
}

.modal-content p {
    font-size: 4vmin;
    margin-bottom: 3vmin;
}

/* =========================================
   ASPECT RATIO SPECIFIC LAYOUTS
   ========================================= */

/* --- 1. WIDE/COMPACT --- */
.layout-wide #app-root,
.layout-compact #app-root {
    flex-direction: row;
}

.layout-wide .ui-layer,
.layout-compact .ui-layer {
    top: var(--root-padding);
    right: var(--root-padding);
}

/* --- 3. SQUARE --- */
.layout-square {
    --board-size: min(85vmin, 45vh);
}

.layout-square #app-root {
    flex-direction: column;
    padding: 2vmin;
}

.layout-square #main-content {
    flex-direction: column;
}

.layout-square .ui-layer {
    top: 3vmin;
    right: 3vmin;
}

/* --- 4. PORTRAIT --- */
.layout-portrait {
    --root-padding: 0vmin;
    --app-gap: 0vmin;
    --home-size: 13vmin;
    --main-radius: 0vmin;
    --board-size: min(90vmin, 44vh);
    /* Limit by height to prevent clipping */
}

.layout-portrait #app-root {
    flex-direction: column;
}

.layout-portrait #main-content {
    flex-direction: column;
    width: 100%;
}

.layout-portrait #scene-container {
    flex: 0 0 50vh;
    border-bottom: 2px solid var(--border);
}

.layout-portrait #interaction-container {
    flex: 1;
    padding: 6vmin;
    justify-content: flex-start;
}

.layout-portrait .stats-card {
    flex-direction: row;
    justify-content: center;
}

.layout-portrait .stat-item {
    flex: 1;
    flex-direction: column;
    align-items: center;
    padding: 3vmin;
}

.layout-portrait .stat-item .label {
    font-size: 3.5vmin;
}

.layout-portrait .stat-item .value {
    font-size: 6vmin;
}

.layout-portrait .ui-layer {
    top: 3vmin;
    right: 3vmin;
}