/* ── Grundlayout ── */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Arial', sans-serif;
    background: url('bg.png') no-repeat center center;
    background-size: cover;
    background-attachment: fixed;
    color: white;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 10px 60px;
}

/* ── Container ── */
.container, footer {
  position: relative;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 15px;
  box-shadow: 0 0 30px rgb(218, 185, 157);
  padding: 30px;
  width: fit-content;
  max-width: 90vw;
  margin-bottom: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

footer { margin-top: 30px;}

/* ── Header ── */
.header-row {
    margin-bottom: 8px;
}

h1 {
    font-size: 4rem;
    font-weight: 900;
    line-height: 1;
}

.subtitle {
    margin-bottom: 12px;
    font-size: 0.95rem;
}

/* ── Score-Boxen ── */
.scores-row {
    display: flex;
    gap: 8px;
	justify-content: center;
}

.score-box {
    background: #bbada0;
    color: #eee4da;
    border-radius: 6px;
    padding: 8px 16px;
    text-align: center;
    min-width: 80px;
}
.score-box span {
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.score-box strong {
    display: block;
    font-size: 1.4rem;
    color: #fff;
}

/* ── Info-Zeile ── */
.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    flex-wrap: wrap;
    gap: 8px;
}
.info-row button, .logout-link {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.9rem;
    text-decoration: none;
}
#newGameBtn {
    background: #8f7a66;
    color: #fff;
    margin-right: 6px;
    transition: background 0.2s;
}
#newGameBtn:hover { background: #6d5c4e; }
.logout-link {
    background: #f2b179;
    color: #776e65;
    transition: background 0.2s;
}
.logout-link:hover { background: #e8925a; }

/* ── Spielfeld ── */
#grid-container {
    position: relative;
    background: #bbada0;
    border-radius: 10px;
    padding: 12px;
    width: 100%;
    aspect-ratio: 1;
    touch-action: none;
    user-select: none;
    /* CSS-Variablen für präzises Kachel-Positioning */
    --gap: 12px;
    --cols: 4;
}

#grid-background {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--gap);
    width: 100%;
    height: 100%;
}

.grid-cell {
    background: rgba(238, 228, 218, 0.35);
    border-radius: 6px;
}

#tile-container {
    position: absolute;
    inset: 12px; /* gleich wie padding des grid-container */
}

/* ── Kacheln ── */
/* Zellgröße = (100% - 3 Gaps) / 4
   Position  = Spalte * (Zellgröße + Gap)
   → calc((100% - 3 * var(--gap)) / 4 * col + var(--gap) * col) */
.tile {
    position: absolute;
    width:  calc((100% - 3 * var(--gap)) / 4);
    height: calc((100% - 3 * var(--gap)) / 4);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 2.2rem;
    top:  0;
    left: 0;
    /* transition wird per JS für Bewegungsanimation gesetzt */
    will-change: top, left;
    z-index: 2;
}

/* Neue Kachel: einblenden */
.tile-new {
    animation: tileAppear 0.18s ease forwards;
}
@keyframes tileAppear {
    0%   { transform: scale(0.5); opacity: 0; }
    60%  { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1);   opacity: 1; }
}

/* Verschmolzene Kachel: kurzer Pop + Leuchten */
.tile-merge {
    animation: tileMerge 0.25s ease forwards;
    z-index: 3;
}
@keyframes tileMerge {
    0%   { filter: brightness(1);   }
    30%  { filter: brightness(1.5); box-shadow: 0 0 18px rgba(255,220,50,0.8); }
    100% { filter: brightness(1);   box-shadow: none; }
}


/* ── Hinweis ── */
.controls-hint {
    text-align: center;
    font-size: 0.85rem;
    margin: 10px 0;
}

/* ── Game-Over / Win Overlay ── */
#game-message {
    position: absolute;
    inset: 0;
    background: rgba(238, 228, 218, 0.73);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}
#game-message.hidden { display: none; }
#game-message.game-over-msg { background: rgba(0, 0, 0, 0.5); }

.message-inner {
    text-align: center;
    background: #fff;
    border-radius: 12px;
    padding: 30px 40px;
    box-shadow: 0 6px 25px rgba(0,0,0,0.25);
}
.message-inner p {
    font-size: 1.6rem;
    font-weight: 900;
    color: #776e65;
    margin-bottom: 16px;
}
.message-inner button {
    background: #8f7a66;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 28px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s;
}
.message-inner button:hover { background: #6d5c4e; }

/* ── Login ── */
.login-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 16px 0;
    align-items: center;
}
.login-form input {
    font-size: 1rem;
    padding: 10px 16px;
    border-radius: 8px;
    border: 2px solid #bbada0;
    width: 280px;
    outline: none;
    transition: border-color 0.2s;
}
.login-form input:focus { border-color: #8f7a66; }
.login-form button {
    background: #8f7a66;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 30px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s;
}
.login-form button:hover { background: #6d5c4e; }
.hint  { font-size: 0.85rem; text-align: center; }
.error { color: #f65e3b; font-weight: bold; margin: 8px 0; text-align: center; }

/* ── Regeln ── */
.rules-box {
    border-radius: 10px;
    padding: 16px 20px;
    margin-top: 20px;
    text-align: left;
}
.rules-box h3 { margin-bottom: 10px; color: #e0c060; }
.rules-box ul { padding-left: 20px; }
.rules-box li { margin: 6px 0; color: #ccc; font-size: 0.9rem; }

/* ── Highscore ── */
.highscore-box {
    width: 100%;
    max-width: 500px;
    margin-top: 28px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 10px;
	box-shadow: 0 0 30px rgb(218, 185, 157);
    padding: 20px;
    color: #fff;
}
.highscore-box h2 { margin-bottom: 12px; }
.highscore-box table {
    width: 100%;
    border-collapse: collapse;
}
.highscore-box th, .highscore-box td {
    padding: 8px 10px;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.2);
    color: #fff;
}
.highscore-box th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 1px; }
tr.rank-1 { background: rgba(255,215,0,0.25); }
tr.rank-2 { background: rgba(192,192,192,0.2); }
tr.rank-3 { background: rgba(205,127,50,0.2); }
tr.own-score td { color: #edc22e; font-weight: bold; }

/* ── Responsive ── */
@media (max-width: 480px) {
    h1 { font-size: 3rem; }
    .tile { font-size: 1.5rem; }
}