/* Pilnas CSS (atnaujinta pagal Tavo versiją + pataisymai dėl loading screen)
   - Kvadratinės kortelės (1:1)
   - Mobilioje versijoje visada 3 kortelės per eilutę
   - Desktop versijoje grid centravimas ir max-width, kad kortelės nebūtų išsibarstę
   - Pridėtas .app-content + body.loaded mechanizmas, kad pirminiai elementai nebūtų matomi kol vyksta loading
   - Sustiprintas #loading-screen z-index ir pointer-events, pridėta .hidden klasė sklandžiam paslėpimui
   - Ištaisytos klaidos (nereikalingi/nesutampantys media-query perrašymai ir uždarymo kabliataškiai)
*/

:root{
  --card-base-w: 140px;
  --card-gap: 12px;
  --card-radius: 10px;
  --pill-bg: #395338;
  /* maksimalus plotis, iki kurio grid nebebus ištemptas */
  --grid-max-width: 1100px;
}

/* --- baziniai nustatymai --- */
* { box-sizing: border-box; }
html, body {
  height: 100%;
}
body {
    margin: 0;
    /* prireikus atstatyk background ir font stilizacijas čia */
}

/* IMPORTANT: apgaubk visą savo pagrindinį turinį elementu .app-content.
   .app-content bus paslėpta iki pilno puslapio užsikrovimo (žiūr. body.loaded taisykles žemiau).
*/
.app-content {
  visibility: hidden;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.35s ease, transform 0.35s ease, visibility 0s linear 0.35s;
}

/* Kai JS pridės klasę body.loaded, parodome turinį */
body.loaded .app-content {
  visibility: visible;
  opacity: 1;
  transform: translateY(0);
  transition-delay: 0s;
}

/* Screens container */
.screen {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(8px);
    transition: opacity 0.35s ease, transform 0.35s ease;
    will-change: opacity, transform;
}

/* Loading screen styles
   - very high z-index so it covers everything
   - pointer-events to block interactions under the loader
*/
#loading-screen {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: url(assets/loadingscreenbackground.jpg) no-repeat bottom/cover;
    z-index: 99999;
    pointer-events: all;
}

/* Jei nori slėpti loader sklandžiai, panaudok .hidden */
#loading-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.35s ease, visibility 0s linear 0.35s;
}

.loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: #dfefff;
    margin-top: 20px;
}

.spinner {
    position: fixed;
    width: 160px;
    height: 160px;
    border-radius: 50%;
    border: 2px solid #048ED7;
    border-top-color: #0F5EA1;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Start screen and backgrounds */
div#start-screen {
    max-width: 100%;
    height: 100vh;
    background: url(./assets/Green\ and\ Blue\ Minimalist\ Forest\ Desktop\ Wallpaper\ \(6\).jpg) bottom/cover no-repeat;
    justify-content: flex-end;
}

.screen.active {
     visibility: visible;
     opacity: 1;
     pointer-events: auto;
     transform: translateY(0);
     transition: opacity 0.35s ease, transform 0.35s ease;
     z-index: 10;
     overflow-y: auto;
}

/* Headings */
h1 {
    font-weight: 700;
    font-size: clamp(20px, 4vw, 50px);
    margin-bottom: 10px;
    padding: 10px;
    border-radius: 10px;
    background-color: rgb(238 237 227 / 80%);
}
h2 {
    margin-top: 0;
    font-size: clamp(16px, 3.5vw, 34px);
    color: #222;
    text-transform: uppercase;
    line-height: 1.1;
    padding: 10px;
    border-radius: 10px;
    background-color: rgb(238 237 227 / 80%);
}

/* Start screen elements (fixed pagal Tavo pageidavimą) */
#start-screen {
  position: relative;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  text-align: center;
}

#sign {
  position: absolute;
  bottom: 0px; 
  left: 50%;
  transform: translateX(-50%);
  width: 1500px;
  z-index: 1;
}

#logo {
  position: absolute;
  bottom: 510px; 
  left: 50%;
  transform: translateX(-50%);
  width: 600px;
  z-index: 3;
}

#start-btn {
    position: absolute;
    bottom: clamp(80px, 22vh, 150px);
    left: 50%;
    transform: translateX(-50%);
    background-color: unset;
    cursor: pointer;
    z-index: 2;
}

/* Bounce animation for start button */
.bounce { animation: bounce 2s ease infinite; }
@keyframes bounce {
    70% { transform: translateY(0%); }
    80% { transform: translateY(-15%); }
    90% { transform: translateY(0%); }
    95% { transform: translateY(-7%); }
    97% { transform: translateY(0%); }
    99% { transform: translateY(-3%); }
    100% { transform: translateY(0); }
}

#start-btn img { width: min(350px, 70vw); }

/* Buttons */
button {
    padding: 12px 24px;
    font-size: clamp(14px, 3vw, 22px);
    border-radius: 10px;
    background-color: #27ae60;
    color: white;
    border: none;
    cursor: pointer;
    transition: 0.2s;
}
button:hover { background-color: #2ecc71; }
button.skip { background-color: #c0392b; }
button.skip:hover { background-color: #e74c3c; }

/* Grid container defaults
   - max-width + margin: 0 auto centrinimui
   - minmax(120px, 1fr) leidžia stulpeliams augti tvarkingai
*/
.grid-container {
    display: grid;
    gap: var(--card-gap);
    justify-items: center;
    align-items: start;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    padding: 16px;
    padding-bottom: 64px; /* daugiau vietos apačioje */
    width: 100%;
    max-width: var(--grid-max-width);
    margin: 0 auto; /* centruoja grid dideliuose ekranuose */
    box-sizing: border-box;
}

/* Level progress image */
.level-progress-img {
    display: block;
    width: 220px;
    max-width: 90%;
    height: auto;
    margin: 10px auto 18px;
    object-fit: contain;
    border-radius: 6px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.35);
    background-color: transparent;
    padding: 8px;
    -webkit-backface-visibility: hidden;
}

/* End screen / level buttons */
.end-actions {
    display: flex;
    gap: 24px;
    margin: 20px 0 30px;
    justify-content: center;
    align-items: center;
}

.end-btn, .level-btn {
    width: 60px;
    max-width: 40vw;
    cursor: pointer;
    transition: transform .25s ease, filter .25s ease;
    user-select: none;
}
.end-btn:hover, .level-btn:hover { transform: scale(1.05); filter: brightness(1.08); }
.end-btn:active, .level-btn:active { transform: scale(0.97); }

/* Card sizing: square using aspect-ratio 1:1 */
.card {
    width: 100%;
    max-width: var(--card-base-w);
    aspect-ratio: 1 / 1; /* square cards */
    border-radius: var(--card-radius);
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.5s ease-in-out;
    display: block;
    overflow: visible;
    box-sizing: border-box;
}

/* Ensure images fill the card */
.front-image {
    width: 100%;
    height: 100%;
    border-radius: inherit;
    object-fit: cover;
    display: block;
    backface-visibility: hidden;
}

/* Flip behaviour */
.card.flipped {
    transform: rotateY(180deg);
}
.front, .back {
    backface-visibility: hidden;
    position: absolute;
    border-radius: inherit;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
}
.card .front {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    background-image: url("./assets/animals_names-animation 1-000.png");
    background-position: center;
    background-size: cover;
    transform: rotateY(180deg);
}
.card .back {
    background: url(./assets/card-animation1-000.png) center/cover no-repeat;
    transform: rotateY(0deg);
}

/* Animal name pill (keeps inside card on all screens) */
.front-name {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 8px; /* inside card */
    display: inline-block;
    max-width: calc(100% - 12px);
    padding: 6px 10px;
    text-align: center;
    font-weight: 700;
    font-size: clamp(12px, 2.5vw, 14px);
    color: #fff;
    background: var(--pill-bg);
    border-radius: 12px;
    box-shadow: 0 6px 12px rgba(57, 83, 56, 0.18);
    pointer-events: none;
    line-height: 1.05;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Matched state */
.matched {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease;
}

/* Generic paragraph */
p {
    font-size: clamp(14px, 3vw, 24px);
    font-weight: bold;
}

/* End-screen background */
#end-screen {
    background: url(./assets/Green\ and\ Blue\ Minimalist\ Forest\ Desktop\ Wallpaper\ \(6\).png) no-repeat center/cover;
}

/* --- Responsive tweaks --- */
@media (max-width: 1200px) and (min-width: 770px) {
  :root { --card-base-w: 130px; --card-gap: 14px; --grid-max-width: 980px; }
  #start-btn img { width: min(600px, 80vw); }
  /* neprivalome perrašinėti #sign/#logo čia, paliekame globalias reikšmes */
  .grid-container { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
}

/* Mobile: force exactly 3 columns of square cards */
@media (max-width: 769px) {
  :root { --card-gap: 8px; --card-base-w: 9999px; /* ignore max-width on mobile so cards fill columns */ }

  .grid-container {
    grid-template-columns: repeat(3, 1fr); /* always 3 columns */
    gap: var(--card-gap);
    padding: 8px;            /* reduce outer padding so 3 cards fit */
    padding-bottom: 96px;
    box-sizing: border-box;
    width: 100%;
    max-width: none;
    margin: 0;
  }

  .card {
    width: 100%;            /* fill one grid column */
    max-width: none;
    aspect-ratio: 1 / 1;    /* remain square */
    border-radius: 8px;
  }

  .front-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .front-name {
    bottom: 6px; /* keep pill inside card */
    font-size: clamp(10px, 2.6vw, 12px);
    padding: 4px 6px;
    max-width: calc(100% - 12px);
  }

  /* ensure grid children box-sizing so widths are accurate */
  .grid-container > * { box-sizing: border-box; }

  #start-btn { bottom: 60px; }
  #logo { bottom: 78vh; width: 100vw; }
  h1, h2 { padding-left: 8px; padding-right: 8px; }
}

/* very narrow screens: optional fallback (kept commented) */
@media (max-width: 360px) {
  /* If 3 kortelės tampa per mažos, galima pereiti į 2 stulpelius:
  .grid-container { grid-template-columns: repeat(2, 1fr); }
  */
}

/* Accessibility / focus styles for keyboard users */
button:focus, .card:focus {
  outline: 3px solid rgba(39, 174, 96, 0.5);
  outline-offset: 2px;
}