/* DESIGN TOKENS - Zgodne z Brand Manual */
:root {
	--burgundy-900: #3A0510;
	--burgundy: #5A0A1A;
	--gold: #C9A46A;
	--ivory: #F5F1E9;
	--ivory-200: #FDFAF4;
	--blush: #E6C4C4;
	--graphite: #1A1A1A;
	--font-display: 'Playfair Display', serif;
	--font-body: 'Inter', sans-serif;
	--header-h: 60px;
	--footer-h: 70px;
	--radius: 12px;
	--trans: .25s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
	background-color: var(--ivory);
	color: var(--graphite);
	font-family: var(--font-body);
	min-height: 100vh;
	display: flex;
	flex-direction: column;
}

/* STICKY HEADER */
header {
	position: sticky;
	top: 0;
	height: var(--header-h);
	background: #FEF8F3;
	border-bottom: 1px solid var(--blush);
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 1rem;
	z-index: 100;
	box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.logo-small {
	height: 30px; /* Logo niskie zgodnie z wytycznymi */
	display: flex;
	align-items: center;
	font-family: var(--font-display);
	font-weight: 700;
	color: var(--burgundy);
	font-size: 1.2rem;
}

.logo-small span { color: var(--gold); margin: 0 2px; }

.game-progress {
	font-size: 0.8rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 1px;
	background: var(--ivory-200);
	padding: 4px 10px;
	border-radius: 20px;
	border: 1px solid var(--gold);
}

.user-actions {
	display: flex;
	align-items: center;
	gap: 15px;
}

.icon-btn {
	background: none;
	border: none;
	cursor: pointer;
	color: var(--burgundy);
	font-size: 1.4rem;
	display: flex;
	align-items: center;
}

/* SCROLLABLE CONTENT */
main {
	flex: 1;
	padding: 1.5rem 1rem;
	overflow-y: auto;
}

.models-grid {
	display: grid;
	grid-template-columns: repeat(2, 1fr); /* Mobile: 2 wiersze domyślnie */
	gap: 1rem;
	max-width: 1000px;
	margin: 0 auto;
}

@media (min-width: 600px) {
	.models-grid {
		grid-template-columns: repeat(3, 1fr); /* Maks 3 modelki na wiersz */
	}
}

.model-card {
	background: white;
	border-radius: var(--radius);
	overflow: hidden;
	border: 1px solid var(--blush);
	transition: var(--trans);
	position: relative;
	/* Zachowanie proporcji zdjęcia 1296x1616 (ok 4:5) */
	aspect-ratio: 1296 / 1616;
	cursor: pointer;
}

.model-card:hover {
	transform: translateY(-5px);
	box-shadow: 0 8px 20px rgba(90, 10, 26, 0.15);
	border-color: var(--gold);
}

.model-card img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	filter: grayscale(40%);
	transition: var(--trans);
}

.model-card.locked img {
	filter: grayscale(100%) blur(2px);
	opacity: 0.7;
}

.model-card:hover img {
	filter: grayscale(0%);
}

.model-info {
	position: absolute;
	bottom: 0;
	left: 0;
	right: 0;
	background: linear-gradient(transparent, rgba(58, 5, 16, 0.8));
	padding: 1.5rem 0.5rem 0.5rem;
	color: white;
	text-align: center;
}

.model-name {
	font-family: var(--font-display);
	font-size: 1.1rem;
	font-weight: 600;
}

.lock-overlay {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	color: white;
	font-size: 2rem;
	text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

/* STICKY FOOTER */
footer {
	position: sticky;
	bottom: 0;
	height: var(--footer-h);
	background: var(--burgundy);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 100;
	padding-bottom: env(safe-area-inset-bottom); /* Obsługa wycięć w iPhone */
}

.btn-play {
	background: var(--gold);
	color: #fff;
	border: none;
	padding: 10px 20px;
	border-radius: 50px;
	cursor: pointer;
	box-shadow: 0 4px 15px rgba(0,0,0,0.3);
	transition: var(--trans);
}

.btn-play:hover {
	background: var(--ivory);
	transform: scale(1.05);
}

/* IKONY SVG (Placeholder zamiast font-awesome) */
.icon-user {
	width: 24px;
	height: 24px;
	fill: currentColor;
}

.user-name-label{
	font-size: 0.8rem;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(58, 5, 16, 0.8);
    display: none; /* Ukryte domyślnie */
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-content {
    background: var(--ivory-200);
    padding: var(--space-xl, 2rem);
    border-radius: var(--radius);
    max-width: 400px;
    width: 100%;
    border: 2px solid var(--gold);
    position: relative;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.modal-content h2 {
    color: var(--burgundy);
    margin-bottom: 1.5rem;
    text-align: center;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
}

.form-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--blush);
    border-radius: var(--radius);
    background: white;
}

.modal-actions {
    margin-top: 1.5rem;
}

.modal-actions .btn-primary {
    width: 100%;
    border: none;
    cursor: pointer;
    margin-bottom: 1rem;
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--burgundy);
}

.switch-form {
	margin-top: 10px;
    text-align: center;
    font-size: 0.85rem;
}

.switch-form a {
    color: var(--burgundy);
    font-weight: 700;
    text-decoration: underline;
    cursor: pointer;
}

.error-msg {
    color: #f44336;
    font-size: 0.85rem;
    margin-bottom: 1rem;
    display: none;
}

.toast-container {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 999999;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
    width: 100%;
    max-width: 400px;
    padding: 0 20px;
}

.toast {
    background: rgba(15, 15, 15, 0.9);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    color: white;
    padding: 16px 20px;
    border-radius: 16px;
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    box-shadow: 0 15px 35px rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    pointer-events: auto;
    animation: toastIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    transition: all 0.3s ease;
}

.toast.error { border-bottom: 3px solid #ff4b2b; }
.toast.success { border-bottom: 3px solid #00d2ff; }
.toast.info { border-bottom: 3px solid #f9d423; }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(30px) scale(0.9); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateY(0) scale(1); }
    to { opacity: 0; transform: translateY(-20px) scale(0.8); }
}

/* Game page */

.game-page {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.game-stats {
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.7);
    display: flex;
    gap: 20px;
}

.game-stats strong {
    color: white;
}

.game-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: radial-gradient(circle at center, #1a1a1a 0%, #0a0a0a 100%);
}

.puzzle-board {
    position: relative;
    box-shadow: 0 20px 50px rgba(0,0,0,0.8);
    border-radius: 8px;
    background: #000;
	aspect-ratio: 1296 / 1616;
}

.game-preview-img {
    display: block;
    max-width: 100%;
    max-height: 70vh;
    height: auto;
    object-fit: contain;
}

.btn-home {
    background: var(--gold);
    border: none;
    color: #fff;
    padding: 12px 40px;
    border-radius: 30px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
	font-size: 1.1rem;
    transition: var(--trans);
	box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

.btn-home:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.btn-home svg {
    fill: white;
}

.puzzle-tile {
    position: absolute;
    /* Tworzymy 1px przerwy za pomocą ramki */
    border: 0px solid rgba(0, 0, 0, 0.5); /* Ciemna przerwa między kafelkami */
    box-sizing: border-box;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    background-repeat: no-repeat;
    
    /* KLUCZ: Tło nie wchodzi pod ramkę, co tworzy wizualną przerwę w obrazku */
    background-clip: content-box; 
    padding: 1px; /* To "odsuwa" obrazek od krawędzi o 1px z każdej strony */

    filter: grayscale(30%) saturate(0.7) brightness(0.9);
}

.puzzle-tile:hover {
    z-index: 10;
    transform: scale(1.02);
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
}

/* Styl dla zaznaczonego kafelka */
.puzzle-tile.selected {
    z-index: 20;
    outline: 3px solid #00d2ff;
    box-shadow: 0 0 20px rgba(0, 210, 255, 0.5);
    transform: scale(1.05);
}

/* Styl dla kafelka na właściwym miejscu */
.puzzle-tile.matched {
    border: none;
	padding: 0;
    cursor: default;
    z-index: 1;
    box-shadow: none;
    /* Delikatny błysk przy dopasowaniu */
    animation: matchSuccess 0.5s ease-out;
	filter: none;
}

.puzzle-tile.matched:hover {
    transform: none;
    box-shadow: none;
}

@keyframes matchSuccess {
    0% { filter: brightness(1); }
    50% { filter: brightness(1.5) contrast(1.2); }
    100% { filter: brightness(1); }
}

footer {
    padding: 0 1rem;
}

.footer-container {
    width: 100%;
    max-width: 1000px;
    display: flex;
    align-items: center;
    gap: 20px;
}

.footer-nav {
    display: flex;
    gap: 10px;
}

.icon-btn-game {
    background: rgba(255,255,255,0.1);
    border: 1px solid var(--gold);
    color: var(--ivory);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--trans);
}

.icon-btn-game:hover {
    background: var(--gold);
    color: var(--burgundy);
}

.game-timer-block {
    display: flex;
    flex-direction: column;
    justify-content: center;
    font-family: var(--font-body);
}

.timer-row {
    display: flex;
    align-items: center;
    line-height: 1.1;
    gap: 8px;
}

.timer-row.current .t-value {
    color: var(--gold);
    font-weight: 800;
}

.t-label {
    font-size: 0.6rem;
    color: var(--blush);
    width: 45px; /* Stała szerokość dla wyrównania czasów pod sobą */
    text-align: right;
    font-weight: 600;
}

.t-value {
    font-size: 0.85rem;
    color: var(--ivory);
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

.global-best-by {
    font-size: 0.7rem;
    color: var(--blush);
    font-style: italic;
    margin-left: 4px;
}

.game-view-wrapper {
    max-width: 100%;
    margin: 0 auto;
    padding: 0 60px; /* Miejsce na strzałki */
}

.nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    text-decoration: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 10;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.nav-arrow:hover {
    background: rgba(212, 175, 55, 0.8); /* Twój złoty kolor jeśli go używasz */
    transform: translateY(-50%) scale(1.1);
}

.left-arrow { left: 0; }
.right-arrow { right: 0; }

.arrow-icon {
    font-size: 2.5rem;
    line-height: 1;
    margin-top: -4px;
}

@media (max-width: 768px) {
    .game-view-wrapper { padding: 0 10px; }
    .nav-arrow {
        width: 40px;
        height: 40px;
        background: rgba(0, 0, 0, 0.3);
    }
}

.game-progress {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.6);
    padding: 5px 12px;
    border-radius: 20px;
    color: #fff;
    font-family: sans-serif;
}

.level-select {
    background: transparent;
    border: none;
    color: #ffd700; /* Złoty kolor dla numeru */
    font-weight: bold;
    cursor: pointer;
    font-size: 1rem;
    outline: none;
    appearance: none; /* Usuwa domyślną strzałkę w niektórych przeglądarkach */
    -webkit-appearance: none;
}

/* Dodajemy własną małą strzałeczkę w dół */
.game-progress::after {
    content: '▼';
    font-size: 0.7rem;
    margin-left: -5px;
    pointer-events: none;
    color: #aaa;
}

.level-select option {
    background: #222; /* Tło listy rozwijanej */
    color: #fff;
}

.level-select option:disabled {
    color: #666;
}