@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@700&display=swap');

:root {
    --playfield-length: min(480px, 90vw);
    --cell-length: calc((var(--playfield-length) - 50px) / 4);
    --gap: 10px;
}

body {
    font-family: 'Orbitron', Arial, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    min-height: 100vh;
    overflow-x: hidden;
    touch-action: pan-y;
}

header {
    width: calc(var(--playfield-length) + 2 * var(--gap, 10px));
    height: auto;
    min-height: 20%;
    margin: clamp(10px, 3vh, 30px) auto;
    color: #3e3a36;
    display: grid;
    grid: repeat(6) / repeat(6);
}

footer {
    box-sizing: border-box;
    position: relative;
    text-align: center;
    padding: 12px;
    color: #8f7a66;
    font-size: 0.85rem;
}

header h1 {
    font-size: 4.5em;
    margin: 0;
    grid-row: 1 / 5;
    grid-column: 1 / 4;
}

header h2 {
    font-size: 1.5em;
    margin: auto 0;
    grid-row: 5;
    grid-column: 1 / 4;
}

#score-wrapper {
    display: flex;
    width: calc(1.8 * var(--cell-length));
    height: calc(0.55 * var(--cell-length));
    background-color: #bbada0;
    color: #eee4da;
    margin: auto;
    margin-right: 2%;
    grid-row: 1 / 5;
    grid-column: 4 / 7;
    text-align: center;
    border-radius: 5% / 15%;
    line-height: calc(0.55 * var(--cell-length));
}

#score-wrapper #score-text {
    margin: auto;
    height: calc(0.55 * var(--cell-length));
    font-size: 1.4em;
    font-weight: bold;
}

#score-wrapper #score-number {
    margin: auto;
    margin-left: 0;
    color: white;
    font-size: 2em;
    font-weight: bold;
}

#adding-score {
    opacity: 0;
    position: absolute;
    left: calc(50% + 0.5 * var(--playfield-length) - 20px);
    font-size: 1.8em;
    font-weight: bold;
    color: #8f7a66;
}

.fade-out {
    animation: fade-out 0.5s;
}

.new-game-button {
    width: calc(1.3 * var(--cell-length));
    height: calc(0.4 * var(--cell-length));
    margin: auto;
    margin-right: 2%;
    grid-row: 4 / 6;
    grid-column: 4 / 7;
    font-size: 1.1em;
    font-weight: bold;
    border: none;
    border-radius: 5% / 15%;
    color: white;
    background-color: #8f7a66;
}

.new-game-button:hover {
    background-color: #685f55;
    cursor: pointer;
}

#grid-container {
    position: relative;
    margin: 0 auto 16px;
    top: auto;
    left: auto;
    translate: none;

    width: var(--playfield-length, 480px);
    height: var(--playfield-length, 480px);
    padding: var(--gap, 10px);
    border-radius: 8px;
    background-color: #bbada0;

    display: grid;
    grid: repeat(4, 1fr) / repeat(4, 1fr);
    touch-action: none;
}

#tile-container {
    position: absolute;
    top: 0;
    left: 50%;
    translate: -50% 0;
    margin-top: 0;

    width: var(--playfield-length, 480px);
    height: var(--playfield-length, 480px);
    padding: var(--gap, 10px);
    border-radius: 8px;

    display: grid;
    grid: repeat(4, 1fr) / repeat(4, 1fr);
    pointer-events: none;
}

#gameover-mask {
    position: absolute;
    top: 0;
    left: 50%;
    translate: -50% 0;

    width: var(--playfield-length, 480px);
    height: var(--playfield-length, 480px);
    padding: var(--gap, 10px);
    border-radius: 8px;
    background-color: rgba(128, 128, 128, 0.7);
    font-size: clamp(2rem, 8vw, 4.5em);
    font-weight: bold;
    color: #3e3a36;
    text-align: center;
    line-height: var(--playfield-length, 480px);
    visibility: hidden;
    z-index: 10;
}

.grid-cell {
    width: var(--cell-length, 100px);
    height: var(--cell-length, 100px);
    margin: auto;
    border-radius: 5%;
    background-color: #cdc1b4;
}

.tile-base {
    width: var(--cell-length, 100px);
    height: var(--cell-length, 100px);
    line-height: var(--cell-length, 100px);
    text-align: center;
    font-weight: bold;
    margin: auto;
    border-radius: 5%;
}

.tile-spawning {
    animation: spawn 0.15s;
}

.tile-merging {
    animation: merge 0.15s;
}

.tile-base.tile2 {
    color: #776e65;
    font-size: calc(0.6 * var(--cell-length, 100px));
    background-color: #eee4da;
}

.tile-base.tile4 {
    color: #776e65;
    font-size: calc(0.6 * var(--cell-length, 100px));
    background-color: #ede0c8;
}

.tile-base.tile8 {
    color: white;
    font-size: calc(0.6 * var(--cell-length, 100px));
    background-color: #f2b179;
}

.tile-base.tile16 {
    color: white;
    font-size: calc(0.55 * var(--cell-length, 100px));
    background-color: #f59563;
}

.tile-base.tile32 {
    color: white;
    font-size: calc(0.55 * var(--cell-length, 100px));
    background-color: #f67c5f;
}

.tile-base.tile64 {
    color: white;
    font-size: calc(0.55 * var(--cell-length, 100px));
    background-color: #f65e3b;
}

.tile-base.tile128 {
    color: white;
    font-size: calc(0.45 * var(--cell-length, 100px));
    background-color: #e44d29;
}

.tile-base.tile256 {
    color: white;
    font-size: calc(0.45 * var(--cell-length, 100px));
    background-color: #edcf72;
}

.tile-base.tile512 {
    color: white;
    font-size: calc(0.45 * var(--cell-length, 100px));
    background-color: #c8a145;
}

.tile-base.tile1024 {
    color: white;
    font-size: calc(0.35 * var(--cell-length, 100px));
    background-color: #a8832b;
}

.tile-base.tile2048 {
    color: white;
    font-size: calc(0.35 * var(--cell-length, 100px));
    background-color: #86aa9c;
}

.tile-base.tile4096 {
    color: white;
    font-size: calc(0.35 * var(--cell-length, 100px));
    background-color: #a6c;
}

.tile-base.tile8192 {
    color: white;
    font-size: calc(0.35 * var(--cell-length, 100px));
    background-color: #791e6f;
}


@keyframes spawn {
    0% { width: 0px; height: 0px; line-height: 0px; }
    100% {
        width: var(--cell-length, 100px);
        height: var(--cell-length, 100px);
        line-height: var(--cell-length, 100px);
    }
}


@keyframes merge {
    0% { width: 100%; height: 100%; }
    50% { width: 110%; height: 110%; }
    100% { width: 100%; height: 100%; }
}


@keyframes fade-out {
    0% { opacity: 1; translate: 0 0; }
    100% { opacity: 0; translate: 0 -80px; }
}
/* ── BreakPlay 2048 Mobile Critical Fix ── */
/* Fix ghost tile floating over header on mobile */
#tile-container {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  translate: none !important;
  transform: none !important;
}

#adding-score {
  left: auto !important;
  right: 8px !important;
  top: -30px !important;
  bottom: auto !important;
  position: absolute !important;
  font-size: clamp(1rem, 3vw, 1.8em) !important;
}

/* Responsive header */
@media (max-width: 520px) {
  header {
    width: 100% !important;
    padding: 0 8px !important;
    margin: 8px auto !important;
  }
  header h1 {
    font-size: clamp(2rem, 12vw, 4rem) !important;
  }
  #score-wrapper {
    width: auto !important;
    min-width: 80px !important;
    height: auto !important;
    line-height: normal !important;
    padding: 6px 10px !important;
    border-radius: 8px !important;
  }
  #score-wrapper #score-text {
    height: auto !important;
    font-size: 0.7rem !important;
  }
  #score-wrapper #score-number {
    font-size: 1.4rem !important;
  }
  .new-game-button {
    width: auto !important;
    height: auto !important;
    padding: 6px 14px !important;
    font-size: 0.75rem !important;
    border-radius: 8px !important;
  }
  #grid-container {
    margin: 0 auto 12px !important;
  }
}
