* {
    box-sizing: border-box;
}

	
html, body {
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    position: fixed; 
    inset: 0;
    overscroll-behavior: none;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

button, input, .btn, a {
    touch-action: manipulation;
}

body {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
}

header {
    display: flex;
    justify-content: center;
	align-items: center;
    width: 100%;
	height: 15vh;
    background-color: orange;
    flex-shrink: 0;
	margin-top: 6vh;
}

header h1 {
    font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
    font-size: clamp(2rem, 6vw, 3rem);
    margin: 0.5rem;
}

main {
    width: 100%;
    display: flex;
    justify-content: center;
    flex: 1;
    min-height: 0; /* wichtig, damit flex-Kinder schrumpfen dürfen */
}

main div#snakepreview {
    display: flex;
    flex-direction: row;
    justify-content: space-evenly;
	align-items: center;
    width: 100%;
}
main div#snakepreview button.btn {
	width: 35vw;	
}
main div#snakepreview button[name="loginbtn"], main div#snakepreview button[name="registerbtn"] {
	width: 16vw;	
}
main div#snakepreview input {
	width: 35vw;
	font-size: 16px;
    font-family: Arial, sans-serif;
	padding: 0.5rem 1rem;
    max-width: 300px;
    height: auto;
    min-height: 3rem;
    font-size: clamp(1rem, 3vw, 1.5rem);
    background-color: transparent;
    border: 2px solid orange;
    border-radius: 4px;
    margin: 8px;
}

td {
	text-align: center;
	border: 1px solid #e5e7eb;
}

main div img {
    margin: clamp(10px, 3vh, 40px) 0;
    max-width: 40vw;
    max-height: 60vh;
    height: auto;
}

main div button {
    padding: 0.5rem 1rem;
    width: 60%;
    max-width: 300px;
    height: auto;
    min-height: 3rem;
    font-size: clamp(1rem, 3vw, 1.5rem);
    background-color: transparent;
    border: 2px solid orange;
    border-radius: 4px;
    margin: 8px;
}

main div button:hover {
    background-color: orange;
}

main div button[name="back"] {
    box-sizing: content-box;
    position: absolute;
    width: 3vw;
    height: 3vh;
    left: 8px;
    top: 14px;
    min-height: unset;
	border: none;
}

#user-avatar {
    width: auto;
	padding:2vh 2vw;
    height: 17vh;
    border-radius: 20%;
    background-color: black;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 18px;
    position: absolute;
    top: 5vh;
    right: 5vh;
}

/* --- Spielfeld: quadratisch, füllt verfügbaren Platz --- */
#grid {
    display: grid;
    gap: 5px;
    background-color: #222;
    padding: 8px;
    /* quadratisch, begrenzt durch die kleinere verfügbare Dimension */
    width: min(90vw, 85vh);
    height: min(90vw, 85vh);

    grid-template-columns: repeat(var(--grid-cols, 6), 1fr);
    grid-template-rows: repeat(var(--grid-rows, 6), 1fr);
}

.cell {
    width: 100%;
    height: 100%;
}

.cell.snake {
    background-color: #FFB74D;
    border-radius: 30%;
}

.cell.food {
    background-color: #FF8181;
    border-radius: 20%;
}

.cell.head {
    background-color: #FF8F00;
}

.info-row {
    margin: 3px;
    font-size: clamp(0.8rem, 2.5vw, 1rem);
}

/* --- Game Over Overlay --- */
#gameover-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

#gameover-box {
    font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
    background-color: black;
    color: #fff;
    padding: 20px 30px;
    border-radius: 12px;
    text-align: center;
    max-width: 80vw;
}

#btn-restart, #btn-menu {
    color: #fff;
}

.hidden {
    display: none !important;
}
#gameover-overlay.hidden {
	display: none;
}

/* --- Gedrehte Überschrift + seitliches Header-Layout (ergänzt, bitte gegenchecken!) --- */
.sideheader {
    flex-direction: row;
}

.sideheader header {
    width: auto;
	max-width: 12vw;
	margin: 0 0 0 10px;
    height: 100%;
    flex-shrink: 0;
}

header h1.turned {
    display: inline-block;
    width: fit-content;
    height: fit-content;
    align-self: center;
    transform: rotate(-90deg);
    transform-origin: center;
}

#game-wrapper {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

#game-areas {
    order: 1;
}

#game-info {
    order: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    transform: rotate(90deg);
    transform-origin: center;
}

/* --- Landscape-spezifische Anpassung (da Orientation gelockt ist) --- */
@media (orientation: landscape) and (max-height: 500px) {
    header h1 {
        font-size: clamp(2rem, 3vh, 1.5rem);
        margin: 0.25rem;
    }

    main div img {
        max-height: 50vh;
        margin: 5px 0;
    }

    #grid {
        width: min(80vw, 85vh);
        height: min(80vw, 85vh);
    }
}