:root {
  /* Friendly, soft palette */
  --primary-color: #6c63ff;   /* indigo */
  --accent-color: #ff7aa2;    /* soft pink */
  --bg1: #a18cd1;
  --bg2: #fbc2eb;
  --bg3: #8ec5fc;
  --bg4: #e0c3fc;
  --card-bg: #2a2d3a;
  --text-color: #f1f6f9;
  --success-color: #22c55e;
  --fail-color: #ef4444;
}

/* Prevent layout from exceeding viewport width */
*, *::before, *::after { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(120deg, var(--bg1), var(--bg2), var(--bg3), var(--bg4));
  background-size: 300% 300%;
  animation: gradientBG 20s ease infinite;
  color: var(--text-color);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh; /* better on mobile address bars */
  margin: 0;
  padding: 20px;
  flex-direction: column;
}

@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@keyframes blink {
    0%, 100% {
        color: #ff7aa2;
        text-shadow: 0 0 20px rgba(255, 122, 162, 0.8);
    }
    50% {
        color: #ffd700;
        text-shadow: 0 0 20px rgba(255, 215, 0, 0.8);
    }
}

header {
    display: none;
}

/* home button removed with header */

.game-container {
  position: relative;
  background-color: rgba(255, 255, 255, 0.10);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.22);
  padding: 24px 20px;
  border-radius: 20px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.35);
  text-align: center;
  width: 800px;           /* fixed desktop embed size */
  max-width: 800px;
  height: 500px;          /* fixed desktop embed size */
  transition: all 0.3s ease-in-out;
  margin-top: 32px;
  overflow: hidden;       /* no internal scrollbars or cut */
  display: flex;
  flex-direction: column;
}

/* Scaled inner content wrapper (fills and scales within the fixed card) */
#content-fit.content-fit {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Compact typography/layout for 500px-tall embeds */
.game-container.compact h1 { font-size: 1.5rem; margin: 0 0 2px 0; }
.game-container.compact #level-display { font-size: 1.2rem; }
.game-container.compact .game-panel { padding: 12px 0; }
.game-container.compact .score-display { font-size: 0.95em; margin-top: 6px; }
.game-container.compact .score-display.glass { padding: 4px 8px; }
.game-container.compact .progress-bar-bg { height: 6px; }
.game-container.compact #item-list { gap: 10px; margin: 14px 0; }
.game-container.compact #item-list li { font-size: 0.95rem; padding: 6px 10px; min-width: 56px; }
.game-container.compact #recall-area input { font-size: 0.9em; padding: 8px; margin: 6px auto; border-radius: 8px; }
.game-container.compact #input-container { gap: 8px; padding: 6px 0; }
.game-container.compact .message { font-size: 0.9em; padding: 6px; }
.game-container.compact #scorecard-level { font-size: 0.8em; }
.game-container.compact .correct-answers { font-size: 0.75em; }
.game-container.compact #message-area { height: 100px; }
.game-container.compact button { font-size: 0.8rem; padding: 5px 8px; }

h1 {
  font-size: 2.2rem;
  color: #ffffff;
  margin: 0 0 6px 0;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

.intro-title {
  font-size: 1.3rem;
  margin: 0 0 6px 0;
}

.intro-subtitle {
  font-size: 1rem;
  opacity: 0.95;
  margin: 0 0 8px 0;
}

.intro-list {
  list-style: none;
  padding: 0;
  margin: 6px 0 10px 0;
}
.intro-list li {
  margin: 4px 0;
  font-size: 0.95rem;
}

.intro-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
}

.game-panel {
    padding: 20px 0;
}

button {
  background: linear-gradient(45deg, var(--primary-color), var(--accent-color));
  color: white;
  border: none;
  padding: 12px 22px;
  font-size: 1rem;
  font-weight: 700;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
  margin-top: 10px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.4);
}

.secondary {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
}

/* reset-high-score removed */

/* quit button removed */

#play-again-btn {
    background: var(--success-color);
}

#play-again-btn:hover {
    background: #388e3c;
}

.header-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

/* Small bar for sound controls */
.top-controls {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-bottom: 8px;
}

.sound-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 10px;
}

.sound-controls button {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 8px 12px;
  margin-top: 0;
}

.sound-controls input[type="range"] {
  width: 120px;
  accent-color: var(--accent-color);
}

/* Visually hidden for a11y-only labels */
.visually-hidden {
  position: absolute !important;
  height: 1px; width: 1px;
  overflow: hidden;
  clip: rect(1px, 1px, 1px, 1px);
  white-space: nowrap;
}

#level-display {
    font-size: 1.8rem;
    color: var(--text-color);
    margin: 0;
}

#level-display.blink-demo {
    animation: blink 0.8s ease-in-out infinite;
    font-weight: bold;
}

.timer-container {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

#timer-text {
    font-size: 1.2rem;
    margin-bottom: 5px;
}

.progress-bar-bg {
    width: 200px;
    height: 10px;
    background-color: #333;
    border-radius: 5px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background-color: var(--success-color);
    transition: width 1s linear;
}

.score-display {
    font-size: 1.2em;
    font-weight: bold;
    color: var(--accent-color);
    margin-top: 10px;
}

/* Glass treatment for score displays */
.score-display.glass {
  background: rgba(255, 255, 255, 0.12);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 10px;
  padding: 8px 12px;
  color: #a7114c;
  text-shadow: 0 1px 2px rgba(0,0,0,0.15);
  display: inline-block;
}
.score-display.glass span { color: #a7114c; }

#items-to-memorize {
    padding: 20px;
    border: 1px dashed var(--accent-color);
    border-radius: 10px;
}

#item-list {
    list-style-type: none;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    margin: 20px 0;
}

#item-list li {
  background: linear-gradient(135deg, var(--accent-color), #ff9abb);
  backdrop-filter: blur(6px);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 1.2rem;
  font-weight: 800;
  min-width: 80px;
  color: #ffffff;
  text-shadow: 0 2px 2px rgba(0,0,0,0.35);
  border: 1px solid rgba(255,255,255,0.25);
  transition: transform 0.3s;
}

#item-list li:hover {
    transform: scale(1.05);
}

#recall-area input {
    display: block;
    width: 80%;
    margin: 10px auto;
    padding: 12px;
    border: 1px solid rgba(255, 122, 162, 0.55);
    background-color: rgba(255, 122, 162, 0.18);
    color: #ffffff;
    border-radius: 10px;
    font-size: 1.05em;
    text-align: center;
    box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.25);
    transition: background-color 0.2s, border-color 0.2s;
}

/* Grid layout to keep inputs inside container without scroll/cutoff */
#input-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  padding: 10px 0;
}

/* Override input sizing when in grid */
#input-container input {
  width: 100%;
  margin: 0;
}

/* Strong, specific validity styles so feedback is immediate and obvious */
#recall-area input.valid {
  border-color: rgba(255, 122, 162, 0.95) !important;
  background-color: rgba(255, 122, 162, 0.22) !important;
  box-shadow: 0 0 0 2px rgba(255, 122, 162, 0.28);
}

#recall-area input.invalid {
  border-color: rgba(239, 68, 68, 0.95) !important;
  background-color: rgba(239, 68, 68, 0.24) !important;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.25);
}

/* Make the reacting glass shape more visible on wrong input */
.react-shape.bad { box-shadow: 0 0 44px rgba(239, 68, 68, 0.55) inset; }

#recall-area input::placeholder {
    color: #ffd1e6;
}

#recall-area input:focus {
    outline: none;
    background-color: rgba(255, 122, 162, 0.28);
    border-color: rgba(255, 122, 162, 0.85);
}

#recall-area input:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.hidden {
    display: none !important;
}

.message {
    padding: 10px;
    border-radius: 10px;
    font-weight: bold;
    font-size: 1.0em;
    line-height: 1.2;
    margin-top: 8px;
    max-width: 100%;
    box-sizing: border-box;
    overflow-wrap: anywhere; /* ensure no overflow beyond container */
    word-break: break-word;
    white-space: normal;
}

/* Fixed message area at bottom of panel */
#message-area {
  height: 120px; /* reduced height since no buttons */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  overflow: hidden; /* never grow the inner panel height */
  padding-top: 2px;
}

#message-area .message { margin-top: 0; }
#message-area #scorecard-level { font-size: 0.9em; margin-top: 0; }
#message-area #correct-answers { font-size: 0.85em; margin-top: 0; }

/* Compact tightening for 500px embeds */
.game-container.compact #message-area { height: 90px; gap: 4px; }
.game-container.compact .message { font-size: 0.9em; padding: 6px; margin-top: 0; }
.game-container.compact #scorecard-level { display: none; }
.game-container.compact .correct-answers { font-size: 0.75em; margin-top: 0; }

.win {
    background-color: rgba(76, 175, 80, 0.2);
    color: var(--success-color);
}

.lose {
    background-color: rgba(211, 47, 47, 0.2);
    color: var(--fail-color);
}

#scorecard-level {
    margin-top: 15px;
    font-size: 1.1em;
    color: var(--text-color);
}

.correct-answers {
    margin-top: 4px;
    font-size: 0.9em;
    color: var(--text-color);
    opacity: 0.9;
}

/* Responsive Styles */
@media (max-width: 820px) {
    body {
        justify-content: flex-start;
        align-items: stretch;
        padding-top: 16px;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }
    .game-container {
        padding: 20px 15px;
        width: 100%;
        height: min(500px, 100dvh);
        overflow: hidden;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }

    h1 {
        font-size: 2rem;
    }
    
    .header-info {
        flex-direction: column;
        align-items: center;
    }

    .progress-bar-bg {
        width: 100%;
        margin-top: 10px;
    }

    #item-list li {
        font-size: 1em;
        min-width: 70px;
    }
    
    #recall-area input {
        width: 90%;
    }

  /* Keep the message area (feedback + restart buttons) visible
     as users scroll on small screens */
    #message-area {
        position: static !important;
        bottom: auto;
      padding-top: 8px;
      /* Ensure buttons aren’t clipped by iOS safe area */
      padding-bottom: max(8px, env(safe-area-inset-bottom));
      /* subtle fade to separate from content when stuck */
      background: linear-gradient(to bottom, rgba(0,0,0,0), rgba(0,0,0,0.12));
      backdrop-filter: blur(2px);
      -webkit-backdrop-filter: blur(2px);
      z-index: 2;
  }

    /* Ensure internal panels stack nicely on short viewports */
    #game-screen,
    #intro-screen,
    #final-screen {
        display: flex;
        flex-direction: column;
    }
}

/* Short-height viewports (iPhone landscape and similar) */
@media (max-height: 740px) {
  .game-container {
    height: auto;
    max-height: none;
    overflow: visible; /* allow inner sticky footer to fully show */
  }
  #message-area {
    position: sticky;
    bottom: 0;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 3;
  }
}

/* Extra-compact landscape devices */
@media (orientation: landscape) and (max-height: 520px) {
  .game-container {
    height: auto;
    max-height: none;
    overflow: visible;
  }
}

/* Broad safety net for most phones and short screens */
@media (max-width: 820px), (max-height: 740px) {
  .game-container {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }
  #message-area {
    position: static !important;
    bottom: auto;
  }
}
header {
    width: 100%;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    padding: 15px 20px;
    box-sizing: border-box;
    position: absolute;
    top: 0;
    left: 0;
    background-color: rgba(31, 31, 31, 0.8);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    z-index: 1000;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.logo {
    height: 40px;
    width: auto;
    border-radius: 50%;
    object-fit: cover;
    transition: height 0.3s ease;
}

#home-btn {
    background-color: #37474f;
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 1em;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    z-index: 1000;
    margin-top: 0;
}

#home-btn:hover {
    background-color: #546e7a;
}

footer {
    width: 100%;
    background-color: rgba(31, 31, 31, 0.8);
    color: rgba(255, 255, 255, 0.6);
    text-align: center;
    padding: 15px 20px;
    font-size: 0.9em;
    position: relative;
    bottom: 0;
    left: 0;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
    transition: font-size 0.3s ease;
}

footer {
    width: 100%;
    background-color: rgba(31, 31, 31, 0.8);
    color: rgba(255, 255, 255, 0.6);
    text-align: center;
    padding: 15px 20px;
    font-size: 0.9em;
    position: absolute;
    bottom: 0;
    left: 0;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
    transition: font-size 0.3s ease;
}


@media (max-width: 600px) {
    header {
        padding: 10px 15px;
    }

    .logo {
        height: 30px;
    }

    .header-left {
        gap: 10px;
    }

    footer {
        padding: 10px 15px;
    }
    
footer p {
        font-size: 0.8em;
    }
}

/* Glass helper class */
.glass {
    background: rgba(255, 255, 255, 0.10);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.22);
}

/* Decorative reacting glass shape */
.react-shape {
    position: absolute;
    width: 240px;
    height: 240px;
    left: -40px;
    bottom: -40px;
    border-radius: 40% 60% 70% 30% / 40% 30% 70% 60%;
    background: radial-gradient(120px 140px at 30% 30%, rgba(255,255,255,0.18), rgba(255,255,255,0.06));
    filter: blur(2px);
    opacity: 0.7;
    transition: transform 0.6s ease, background-color 0.3s ease, opacity 0.3s ease;
    pointer-events: none;
}
.react-shape.good { box-shadow: 0 0 40px rgba(255, 122, 162, 0.45) inset; }
.react-shape.bad { box-shadow: 0 0 40px rgba(239, 68, 68, 0.35) inset; }

/* Input validation cues */
.valid {
    border-color: rgba(255, 122, 162, 0.95) !important;
    box-shadow: 0 0 0 2px rgba(255, 122, 162, 0.25);
}
.invalid {
    border-color: rgba(239, 68, 68, 0.85) !important;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.18);
    background-color: rgba(239, 68, 68, 0.18);
}

/* Mobile readability tweaks */
@media (max-width: 375px) {
  h1 { font-size: 1.8rem; }
  #item-list li { font-size: 1.1em; min-width: 68px; }
  button { padding: 14px 22px; font-size: 1rem; }
  #recall-area input { width: 95%; font-size: 1.05em; }
}

.intro-title { color: #ffffff; text-shadow: 0 2px 8px rgba(0,0,0,0.35); }
.intro-subtitle { color: #a7114c; text-shadow: 0 1px 6px rgba(0,0,0,0.15); }
.intro-list li { color: #a7114c; text-shadow: 0 1px 6px rgba(0,0,0,0.10); }

/* SweetAlert2 Custom Styling */
.swal-custom-popup {
  backdrop-filter: blur(12px) !important;
  -webkit-backdrop-filter: blur(12px) !important;
  border: 1px solid rgba(255, 255, 255, 0.22) !important;
  border-radius: 20px !important;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.35) !important;
}

/* Restart Options Overlay */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.overlay.show {
  display: flex;
  animation: overlayFadeIn 0.3s ease;
}

@keyframes overlayFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.restart-message {
  background: rgba(42, 45, 58, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.22);
  padding: 40px;
  border-radius: 20px;
  text-align: center;
  max-width: 500px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.35);
  animation: slideIn 0.5s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.restart-message h2 {
  color: #ffffff;
  font-size: 1.8em;
  margin-bottom: 30px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

.btn-group {
  display: flex;
  gap: 15px;
  justify-content: center;
  flex-wrap: wrap;
}

.overlay-btn {
  padding: 14px 28px;
  font-size: 1.1em;
  background: linear-gradient(45deg, var(--primary-color), var(--accent-color));
  color: white;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  margin-top: 0;
}

.overlay-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.4);
}

.overlay-btn.hidden-btn {
  display: none;
}

@media (max-width: 600px) {
  .restart-message {
    padding: 30px 20px;
    max-width: 90%;
  }

  .restart-message h2 {
    font-size: 1.5em;
    margin-bottom: 20px;
  }

  .btn-group {
    flex-direction: column;
    gap: 10px;
  }

  .overlay-btn {
    width: 100%;
    padding: 12px 24px;
    font-size: 1em;
  }
}
