:root {
    --bg-color: #fdfbe7;
    --green-row: #8bc75c;
    --yellow-row: #fec53b;
    --blue-row: #7fd1e3;
    --disabled-color: #ccc;
    --shape-bg: #ffffff;
    --puzzle-shadow: drop-shadow(-4px 4px 5px rgba(0, 0, 0, 0.15));
    
    /* Optimized parameters: kept rows thick ("jaadi") but adjusted to prevent cut-offs */
    --cell-size: 54px;
    --row-height: 80px;
    --formula-size: 44px;
}

html, body {
    height: 100vh;
    width: 100vw;
}

body {
    background-color: var(--bg-color);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
}

* {
    box-sizing: border-box;
}

img {
    max-width: 100%;
    height: auto;
}

.game-title {
    width: min(500px, 80%);
    display: block;
    margin: 0 auto 10px;
}

.setup-screen, .transition-screen { 
    text-align: center; 
    background: white;
    padding: 30px;
    border-radius: 20px;
    max-width: 500px;
    width: min(500px, 95%);
    box-shadow: 0 10px 30px rgba(0,0,0,0.08);
}

.btn {
    background-color: var(--green-row);
    color: white;
    border: none;
    padding: 12px 20px;
    font-size: 15px;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px rgba(0,0,0,0.1);
    transition: all 0.1s;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

.btn:active { 
    transform: translateY(4px); 
    box-shadow: none; 
}

.btn:disabled {
    background-color: #bbb;
    cursor: not-allowed;
    box-shadow: none;
}

.status-banner {
    max-width: 1100px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    background: rgba(255, 255, 255, 0.9);
    padding: 10px 25px;
    border-radius: 16px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.04);
    font-size: 16px;
    font-weight: bold;
    color: #222;
}

.banner-text {
    flex-grow: 1;
    text-align: left;
}

.banner-actions {
    display: flex;
    gap: 8px;
    align-shrink: 0;
}

/* Tiny variations to fit clean inside the top panel view line */
.btn.btn-sm {
    min-height: 36px;
    padding: 6px 14px;
    font-size: 13px;
    box-shadow: 0 2px rgba(0,0,0,0.1);
}

/* --- Individual Player Board Wrapper --- */
.player-board {
    background: #fffdf3;
    padding: 20px;
    border-radius: 20px;
    border: 2px solid #ffcc99;
    position: relative;
    box-shadow: 0 6px 12px rgba(0,0,0,0.03);
    width: 100%;
}

.player-name {
    font-size: 22px;
    font-weight: bold;
    margin-bottom: 15px;
    text-transform: uppercase;
    color: #444;
    letter-spacing: 1px;
}

/* --- Fixed 12-Column Grid Rows --- */
.row-container {
    width: 100%;
    margin-bottom: 12px;
}

.grid-row {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 0px; 
    padding: 4px 0;
    align-items: center;
    height: var(--row-height);
    width: 100%;
}

/* --- Interactive Shapes & Cells --- */
.cell {
    height: 100%;
    width: 100%; 
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: bold;
    color: #333;
    user-select: none;
}

.cell.has-bg {
    transition: all 0.2s;
    filter: var(--puzzle-shadow);
}

.cell.has-bg:not(.middle-gap-cell) {
    cursor: pointer;
}

.orange-cell { background-color: var(--green-row); }
.yellow-cell { background-color: var(--yellow-row); }
.purple-cell { background-color: var(--blue-row); }

.cell-inner {
    width: var(--cell-size);
    height: var(--cell-size);
    background-color: var(--shape-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.circle { border-radius: 50%; }
.pentagon { clip-path: polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%); }
.empty-slot { visibility: hidden; pointer-events: none; }

.cell.filled .cell-inner { 
    background-color: #333; 
    color: white; 
}

.cell.has-bg:hover:not(.filled):not(.middle-gap-cell) .cell-inner {
    transform: scale(1.08);
    background-color: #fff3db;
}

/* --- Rounded Corners for Rows --- */
.grid-row .cell.empty-slot + .cell.has-bg,
.grid-row .cell.has-bg:first-child {
    border-top-left-radius: 20px;
    border-bottom-left-radius: 20px;
}

.grid-row .cell.has-bg:has(+ .empty-slot),
.grid-row .cell.has-bg:last-child {
    border-top-right-radius: 20px;
    border-bottom-right-radius: 20px;
}

/* --- Controls Panel --- */
.dice-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fff;
    padding: 15px 30px;
    border-radius: 25px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.06);
    width: 100%;
    max-width: 1100px; 
    margin-bottom: 15px;
    gap: 20px;
    flex-shrink: 0; /* Prevents control box from smashing up when screen heights decrease */
}

.dice-container { 
    display: flex; 
    gap: 30px; 
    padding: 5px 0;
}

.dice-cube-scene {
    width: 54px;
    height: 54px;
    perspective: 300px;
    cursor: pointer;
    transition: transform 0.2s;
}

.dice-cube-scene:hover { transform: scale(1.05); }
.dice-cube-scene.deselected { opacity: 0.3; filter: grayscale(50%); }

.dice-cube {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transform: rotateX(-20deg) rotateY(30deg);
    transition: transform 0.15s ease-out;
}

.dice-cube.rolling {
    animation: spinDiceCube 1.2s cubic-bezier(0.2, 0.8, 0.25, 1) infinite;
}

.dice-pane {
    position: absolute;
    width: 54px;
    height: 54px;
    border: 2px solid rgba(0,0,0,0.15);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 20px;
    color: white;
    box-shadow: inset 0 0 12px rgba(255,255,255,0.2);
}

.dice-pane.front  { transform: rotateY(0deg) translateZ(27px); }
.dice-pane.back   { transform: rotateY(180deg) translateZ(27px); }
.dice-pane.left   { transform: rotateY(-90deg) translateZ(27px); }
.dice-pane.right  { transform: rotateY(90deg) translateZ(27px); }
.dice-pane.top    { transform: rotateX(90deg) translateZ(27px); }
.dice-pane.bottom { transform: rotateX(-90deg) translateZ(27px); }

.orange-die-cube .dice-pane { background-color: var(--green-row); }
.yellow-die-cube .dice-pane { background-color: var(--yellow-row); }
.purple-die-cube .dice-pane { background-color: var(--blue-row); }

@keyframes spinDiceCube {
    0% { transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg); }
    100% { transform: rotateX(720deg) rotateY(1080deg) rotateZ(360deg); }
}

.roll-result {
    font-size: 32px;
    font-weight: bold;
    color: #222;
    min-width: 65px;
    text-align: center;
    background: #fdfbe7;
    padding: 5px;
    border-radius: 12px;
    border: 2px solid #eed6b3;
}

.control-buttons-group {
    display: flex;
    flex-direction: row; 
    align-items: center;
    gap: 10px;
}

/* --- Missteps Panel --- */
.misstep-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 5px;
}

.misstep-box {
    width: 30px;
    height: 30px;
    border: 2px dashed #cc5a00;
    background: #f7d9c4;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #d66f1b;
    border-radius: 6px;
    cursor: pointer;
}

.misstep-box.checked { 
    background: #ff5500; 
    color: white; 
    border-style: solid; 
}

/* --- Proportional Formula Bar --- */
.formula-bar {
    background-color: #f58639;
    border-radius: 20px;
    padding: 12px 25px;
    display: flex;
    align-items: center;
    justify-content: center; 
    gap: 15px;
    margin-top: 15px;
    width: 100%;
    filter: var(--puzzle-shadow);
}

.formula-group {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.08);
    padding: 6px 12px;
    border-radius: 14px;
}

.formula-box {
    background-color: var(--shape-bg);
    border-radius: 10px;
    width: var(--formula-size);
    height: var(--formula-size);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 16px;
    color: #333;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}

.formula-operator {
    font-size: 24px;
    color: var(--shape-bg);
    font-weight: bold;
    user-select: none;
}

.formula-pentagon {
    width: var(--formula-size);
    height: var(--formula-size);
    background-color: var(--shape-bg);
    clip-path: polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 16px;
    color: #333;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}

.formula-result {
    background-color: var(--shape-bg);
    border-radius: 14px;
    height: 44px;
    width: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: bold;
    color: #222;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.1);
}

/* --- Rules Modal --- */
.rules-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}
.rules-content {
    background: white;
    padding: 30px;
    border-radius: 20px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    text-align: left;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

/* --- FIXED: Scalable viewport flexbox container to eliminate layout scrollbars --- */
.game-area {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    max-width: 1100px; 
    flex-grow: 1;         /* Automatically sizes into remaining space */
}

/* Responsive matrices updates */
@media (max-width: 992px) {
    :root { --cell-size: 42px; --row-height: 64px; --formula-size: 38px; }
    .dice-panel { padding: 12px 20px; }
}
@media (max-width: 768px) {
    :root { --cell-size: 32px; --row-height: 52px; --formula-size: 32px; }
    .dice-panel { flex-direction: column; height: auto; gap: 15px; }
    .control-buttons-group { flex-wrap: wrap; justify-content: center; }
    .formula-bar { flex-wrap: wrap; }
    
    /* Fallback overflow allowed only for small screen sizes */
    .game-area::-webkit-scrollbar { width: 5px; }
    .game-area::-webkit-scrollbar-thumb { background: #bbb; border-radius: 4px; }
}
