:root {
    --grid-dimension: 8;
    --scoreboard-container-height: 80px;

    /* --grid-width: 800px; */
    --grid-width: calc(57vh);
    --grid-height: calc(57vh);
    /* --grid-height: 640px; */
    --grid-container-width: calc(var(--grid-width));
    --grid-container-height: var(--grid-height);

    --shape-container-height: calc(var(--grid-height) / 2);
    --shape-container-width: calc(var(--grid-width) / 2);

    --margin: 20px;
}

body {
    font-family: 'Courier New', Courier, monospace;
    background-color: rgb(17, 22, 33);
    overflow: auto;
    margin: 0;
}

.main-game {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-top: 15px;
}

h1 {
    color: #fff;
    font-size: 1rem;
    width: auto;
}

.game-over-overlay h1 {
    width: auto;
    text-align: center;
}

.game-over-overlay .new-game-btn {
    position: static;
}

/* ---- Navbar ---- */

.navbar {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    background: linear-gradient(135deg, rgba(12, 26, 49, 0.95), rgba(30, 15, 60, 0.95));
    border-bottom: 2px solid rgba(138, 43, 226, 0.4);
    box-shadow: 0 2px 20px rgba(138, 43, 226, 0.2);
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 2px;
    user-select: none;
    flex: 1;
    text-decoration: none;
}

.navbar-logo {
    font-size: 2rem;
    font-weight: 900;
    color: #c123de;
    text-shadow: 0 0 10px rgba(193, 35, 222, 0.6), 0 0 20px rgba(193, 35, 222, 0.3);
    font-family: 'Arial Black', Arial, sans-serif;
}

.navbar-title {
    font-size: 1.6rem;
    font-weight: 900;
    letter-spacing: 4px;
    color: #fff;
    font-family: 'Arial Black', Arial, sans-serif;
}

.navbar-score {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(138, 43, 226, 0.3);
    border-radius: 30px;
    padding: 6px 20px;
    position: relative;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.navbar-score-label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 3px;
    color: rgba(255, 255, 255, 0.5);
    font-family: Arial, sans-serif;
}

.grid-container {
    position: relative;
    width: var(--grid-container-width);
    height: var(--grid-container-height);
    border: 1px solid blueviolet;
    background: rgb(12, 26, 49);
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
}

.game-over-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    background: rgba(0, 0, 0, 0.7);
    z-index: 10;
    border-radius: 10px;
}

.grid-cell {
    border: 2px solid rgb(18, 31, 57);
    box-sizing: border-box;
    background: rgb(12, 26, 49);
    flex-basis: calc(var(--grid-width) / var(--grid-dimension));
    height: calc(var(--grid-height) / var(--grid-dimension));
    color: white;
    text-align: center;
    transition: all 0.3s ease;
    display: flex;
    align-content: center;
    flex-direction: column;
    justify-content: center;
    border-radius: 10px;
}

.shapes-container {
    width: calc(var(--grid-width) + 20px);
    margin-top: var(--margin);
    height: var(--shape-container-height);
    display: block;
    position: relative;
}

.shape-container {
    width: var(--shape-container-width);
    height: var(--shape-container-height);
    display: flex;
    color: white;
    text-align: center;
    position: absolute;
    z-index: 9;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
}

#shape-c1 {
    top: 0;
    left: 0;
}

#shape-c2 {
    top: 0;
    left: 50%;
}

.shape-cell {
    box-sizing: border-box;
    flex-basis: calc(var(--grid-width) / var(--grid-dimension));
    height: calc(var(--grid-height) / var(--grid-dimension));
    color: black;
    text-align: center;
    transition: all 0.3s ease;
    display: flex;
    align-content: center;
    flex-direction: column;
    justify-content: center;
    border-radius: 15px;
}

.shape-cell-active {
    background-position: center;
    background-repeat: no-repeat;
    background-size: initial;
    color: white;
    border: 2px solid rgb(17, 22, 33);
}

.shape-red, .tile-red {
    background-image: url("../imgs/red.png");
}

.shape-purple, .tile-purple {
    background-image: url("../imgs/purple.png");
}

.shape-yellow, .tile-yellow {
    background-image: url("../imgs/yellow.png");
}

.shape-blue, .tile-blue {
    background-image: url("../imgs/blue.png");
}

.shape-pink, .tile-pink {
    background-image: url("../imgs/pink.png");
}

.shape-hotpink, .tile-hotpink {
    background-image: url("../imgs/hotpink.png");
}

.shape-blueg, .tile-blueg {
    background-image: url("../imgs/blueg.png");
}

.shape-green, .tile-green {
    background-image: url("../imgs/green.png");
}

.shape-lime, .tile-lime {
    background-image: url("../imgs/lime.png");
}

.shape-cyan, .tile-cyan {
    background-image: url("../imgs/cyan.png");
}

.active-tile {
    background-position: center;
    background-repeat: no-repeat;
    background-size: initial;
}

/* ---- Drag hover highlight ---- */

.tile-drag-hover {
    background-position: center;
    background-repeat: no-repeat;
    background-size: initial;
    opacity: 0.4;
    box-shadow: 0 0 10px 2px rgba(255, 255, 255, 0.3);
    transition: opacity 0.1s ease, box-shadow 0.1s ease;
}

/* ---- Placement glow pulse ---- */

.tile-place-glow {
    animation: placeGlow 0.4s ease-out;
}

@keyframes placeGlow {
    0% {
        box-shadow: 0 0 0px rgba(255, 255, 255, 0);
        transform: scale(0.6);
    }
    40% {
        box-shadow: 0 0 14px 4px rgba(255, 255, 255, 0.5), 0 0 20px 6px rgba(138, 43, 226, 0.4);
        transform: scale(1.08);
    }
    100% {
        box-shadow: 0 0 0px rgba(255, 255, 255, 0);
        transform: scale(1);
    }
}

/* ---- Line clear explosion ---- */

.tile-clear-explode {
    animation: clearExplode 0.45s ease-out forwards;
}

@keyframes clearExplode {
    0% {
        transform: scale(1);
        opacity: 1;
        box-shadow: 0 0 0px rgba(255, 255, 255, 0);
    }
    30% {
        transform: scale(1.2);
        opacity: 1;
        box-shadow: 0 0 18px 6px rgba(255, 255, 255, 0.7), 0 0 30px 10px rgba(255, 0, 94, 0.5);
    }
    100% {
        transform: scale(0);
        opacity: 0;
        box-shadow: 0 0 0px rgba(255, 255, 255, 0);
    }
}

/* ---- Grid shake on line clear ---- */

.grid-shake {
    animation: gridShake 0.35s ease-out;
}

@keyframes gridShake {
    0%   { transform: translate(0, 0); }
    15%  { transform: translate(-3px, 2px); }
    30%  { transform: translate(3px, -2px); }
    45%  { transform: translate(-2px, 1px); }
    60%  { transform: translate(2px, -1px); }
    75%  { transform: translate(-1px, 1px); }
    100% { transform: translate(0, 0); }
}

.shape-wrapper1 {
    margin-right: 10px;
    /* padding: 10px; */
}

.score-text {
    font-size: 1.8rem;
    font-weight: 900;
    color: #fff;
    font-family: 'Arial Black', Arial, sans-serif;
    min-width: 40px;
    text-align: center;
    transition: color 0.2s ease;
}

/* ---- Score pop on placement ---- */

.score-pop {
    animation: scorePop 0.4s ease-out;
}

@keyframes scorePop {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.3); color: #c123de; }
    100% { transform: scale(1); }
}

/* ---- Score container glow on placement ---- */

.navbar-score-glow {
    animation: scoreContainerGlow 0.6s ease-out;
}

@keyframes scoreContainerGlow {
    0%   { border-color: rgba(138, 43, 226, 0.3); box-shadow: 0 0 0px rgba(193, 35, 222, 0); }
    40%  { border-color: rgba(193, 35, 222, 0.9); box-shadow: 0 0 15px 3px rgba(193, 35, 222, 0.5); }
    100% { border-color: rgba(138, 43, 226, 0.3); box-shadow: 0 0 0px rgba(193, 35, 222, 0); }
}

/* ---- Big score glow for line clears ---- */

.animate {
    animation: glowCycle 1.5s infinite alternate;
}

@keyframes glowCycle {
    0% {
        text-shadow: 0 0 5px #ff005e, 0 0 10px #ff005e, 0 0 20px #ff005e, 0 0 40px #ff005e, 0 0 80px #ff005e;
        color: #ff005e;
    }
    100% {
        text-shadow: 0 0 10px #00d4ff, 0 0 20px #00d4ff, 0 0 40px #00d4ff, 0 0 80px #00d4ff, 0 0 160px #00d4ff;
        color: #00d4ff;
    }
}

.navbar-score-blaze {
    animation: scoreContainerBlaze 2s ease-in-out infinite alternate;
}

@keyframes scoreContainerBlaze {
    0% {
        border-color: #ff005e;
        box-shadow: 0 0 10px 2px rgba(255, 0, 94, 0.4), 0 0 25px 5px rgba(255, 0, 94, 0.2);
    }
    100% {
        border-color: #00d4ff;
        box-shadow: 0 0 10px 2px rgba(0, 212, 255, 0.4), 0 0 25px 5px rgba(0, 212, 255, 0.2);
    }
}

/* ---- Floating score popup ---- */

.score-float {
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Arial Black', Arial, sans-serif;
    font-weight: 900;
    font-size: 1rem;
    color: #c123de;
    pointer-events: none;
    white-space: nowrap;
    animation: scoreFloatUp 1s ease-out forwards;
    z-index: 20;
}

.score-float-big {
    font-size: 1.3rem;
    color: #ff005e;
    text-shadow: 0 0 8px rgba(255, 0, 94, 0.6);
}

@keyframes scoreFloatUp {
    0%   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
    30%  { opacity: 1; transform: translateX(-50%) translateY(15px) scale(1.2); }
    100% { opacity: 0; transform: translateX(-50%) translateY(40px) scale(0.8); }
}

.navbar-right {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 15px;
}

.commentator-container {
}

.commentator-container h1 {
    margin: 0;
}

.commentator-text span {
    display: inline-block;
    font-size: 1.2rem;
    animation: wave 2s ease-in-out infinite;
}

.commentator-text span:nth-child(1) {
    animation-delay: 0s;
}
.commentator-text span:nth-child(2) {
    animation-delay: 0.2s;
}
.commentator-text span:nth-child(3) {
    animation-delay: 0.4s;
}
.commentator-text span:nth-child(4) {
    animation-delay: 0.6s;
}

@keyframes wave {
    0%,
    100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-20px);
    }
}

.new-game-btn {
    box-shadow: inset 0px 1px 0px 0px #e184f3, 0 0 12px rgba(193, 35, 222, 0.3);
    background: linear-gradient(to bottom, #c123de 5%, #a20dbd 100%);
    background-color: #c123de;
    border-radius: 20px;
    border: 1px solid #a511c0;
    cursor: pointer;
    color: #ffffff;
    font-family: Arial, sans-serif;
    font-size: 14px;
    font-weight: bold;
    padding: 8px 22px;
    text-decoration: none;
    text-shadow: 0px 1px 0px #9b14b3;
    letter-spacing: 1px;
    text-transform: uppercase;
    transition: all 0.2s ease;
}
.new-game-btn:hover {
    background: linear-gradient(to bottom, #a20dbd 5%, #c123de 100%);
    background-color: #a20dbd;
    box-shadow: inset 0px 1px 0px 0px #e184f3, 0 0 20px rgba(193, 35, 222, 0.5);
    transform: scale(1.05);
}
.new-game-btn:active {
    transform: scale(0.97);
}
.new-game-btn:disabled {
    opacity: 0.4;
    cursor: default;
    transform: none;
}
.btn-secondary {
    background: linear-gradient(to bottom, #444 5%, #333 100%);
    background-color: #444;
    border: 1px solid #555;
    box-shadow: none;
    text-shadow: none;
}
.btn-secondary:hover {
    background: linear-gradient(to bottom, #555 5%, #444 100%);
    background-color: #555;
    box-shadow: none;
}

.sound-toggle-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(138, 43, 226, 0.3);
    border-radius: 50%;
    width: 38px;
    height: 38px;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
}
.sound-toggle-btn:hover {
    background: rgba(138, 43, 226, 0.2);
    border-color: rgba(138, 43, 226, 0.6);
    transform: scale(1.1);
}

/* ---- Replay viewer ---- */

.replay-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 15px;
}

.replay-btn {
    font-size: 12px;
    padding: 6px 16px;
}

.replay-info {
    text-align: center;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.8rem;
    margin-top: 15px;
    min-height: 1.2em;
}

/* ---- Replay shape panel ---- */

.replay-shape-panel {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-top: 15px;
}

.replay-shape-slot {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 100px;
    min-height: 80px;
}

.replay-shape-grid {
    display: grid;
    grid-template-columns: repeat(4, 28px);
    grid-template-rows: repeat(4, 28px);
}

.replay-shape-cell {
    width: 28px;
    height: 28px;
    box-sizing: border-box;
    border-radius: 6px;
}

.replay-shape-cell-active {
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    border: 1px solid rgb(17, 22, 33);
}

.replay-shape-label {
    margin-top: 5px;
    text-align: center;
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.7rem;
    font-family: Arial, sans-serif;
    letter-spacing: 1px;
}

.replay-shape-empty {
    color: rgba(255, 255, 255, 0.3);
    font-size: 0.8rem;
    font-family: Arial, sans-serif;
    font-style: italic;
    margin-top: 30px;
}

/* ---- Developer Tools Panel ---- */

.dev-toggle {
    position: fixed;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    background: rgba(255, 0, 94, 0.8);
    color: #fff;
    font-family: 'Arial Black', Arial, sans-serif;
    font-size: 0.65rem;
    font-weight: 900;
    letter-spacing: 2px;
    padding: 8px 6px;
    cursor: pointer;
    z-index: 1000;
    border-radius: 6px 0 0 6px;
    writing-mode: vertical-rl;
    user-select: none;
    transition: background 0.2s;
}
.dev-toggle:hover {
    background: rgba(255, 0, 94, 1);
}

.dev-panel {
    position: fixed;
    top: 0;
    right: -280px;
    width: 280px;
    height: 100vh;
    background: rgba(10, 14, 26, 0.97);
    border-left: 2px solid rgba(255, 0, 94, 0.4);
    z-index: 999;
    overflow-y: auto;
    transition: right 0.25s ease;
    padding: 15px;
    box-sizing: border-box;
    font-family: Arial, sans-serif;
}
.dev-panel-open {
    right: 0;
}

.dev-header {
    font-size: 0.85rem;
    font-weight: 900;
    color: #ff005e;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 15px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 0, 94, 0.3);
}

.dev-section {
    margin-bottom: 14px;
}

.dev-label {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 2px;
    color: rgba(255, 255, 255, 0.4);
    margin-bottom: 6px;
}

.dev-state {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.8);
    line-height: 1.6;
}
.dev-state b {
    color: #ff005e;
}

.dev-row {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
    align-items: center;
}

.dev-select {
    flex: 1;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    color: #fff;
    font-size: 0.7rem;
    padding: 5px 8px;
    font-family: monospace;
}

.dev-btn {
    display: block;
    width: 100%;
    background: rgba(255, 0, 94, 0.15);
    border: 1px solid rgba(255, 0, 94, 0.3);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 6px 10px;
    cursor: pointer;
    margin-bottom: 5px;
    transition: all 0.15s ease;
    font-family: Arial, sans-serif;
}
.dev-btn:hover {
    background: rgba(255, 0, 94, 0.3);
    border-color: rgba(255, 0, 94, 0.6);
    color: #fff;
}
.dev-btn-sm {
    width: auto;
    flex-shrink: 0;
}

.dev-hint {
    font-size: 0.65rem;
    color: rgba(255, 0, 94, 0.7);
    font-style: italic;
    margin-top: 4px;
}

.dev-toggle-mode .grid-cell {
    cursor: crosshair;
}
