:root {
  --primary: #3498db;
  --accent: #f1c40f;
  --error: #e74c3c;
  --success: #2ecc71;
  --bg: #f8f9fa;
}

/* 1. Reset & Global Layout */
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
overflow: hidden;
background-color: var(--bg);
font-family: "Segoe UI", sans-serif;
}

body {
  display: block;
}

/* 2. Main Container */
.game-wrapper {
  display: flex;
  flex-direction: column;
  height: 100svh;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  position: relative;
}

/* 3. Header & Stats */
header {
  flex-shrink: 0;
  padding: 10px;
  background: white;
  z-index: 10;
  border-bottom: 1px solid #ddd;
  text-align: center;
}

#timer-display {
    position: sticky;
    top: 0;
    width: 100%; /* Ensure it covers the width of the scrolling area */
    z-index: 10;
    background-color: white;
    padding: 10px;
    font-size: 2rem;
    font-weight: bold;
    /* border-bottom: 2px solid #eee; */
    color: var(--primary);
    margin: 0; /* Changed from 5px to 0 to prevent gaps while sticking */
    text-align: center;
    box-sizing: border-box; /* Keeps padding from making it too wide */
}

#best-time-display {
  font-size: 1rem;
  opacity: 0.7;
}

/* 4. The Word Board (The middle section) */
#game-board {
height: calc(100svh - 140px);
flex-grow: 1;
overflow-y: auto;
position: relative;
padding: 0 20px 20px 20px;
scroll-behavior: smooth;
display: flex;
flex-direction: column;
align-items: center;
-webkit-overflow-scrolling: touch;
padding-bottom: 50svh;
position: relative;
display: block;
}

.word-row {
  background: white;
  width: 90%;
  margin: 10px 0;
  padding: 12px;
  border-radius: 8px;
  font-size: 1.5rem;
  font-weight: bold;
  letter-spacing: 2px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  text-align: center;
  transition: all 0.3s ease;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 40px;
  scroll-margin: 20px;
  margin-left: auto;
  margin-right: auto;
  width: fit-content;
}

.hidden-word {
  color: var(--accent);
  border: 2px dashed var(--accent);
  background: transparent;
  letter-spacing: 4px;
}

/* 5. Input Area (Pinned to bottom) */
#guess-input {
  width: 100%;
  padding: 12px;
  font-size: 16px; /* 16px prevents iOS auto-zoom */
  border: 2px solid var(--accent);
  border-radius: 8px;
  box-sizing: border-box;
  text-transform: uppercase;
}

.input-area {
  flex-shrink: 0;
  padding: 15px;
  background: white;
  border-top: 1px solid #ddd;
  z-index: 20;
}

input:focus {
  outline: none;
  border-color: var(--accent);
}

#hint-text {
  font-size: 0.8rem;
  text-align: center;
  opacity: 0.6;
  margin-top: 8px;
}

/* 6. Modals & Overlays */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100svh;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

/* Specific visibility controls */
#overlay { display: flex; }
#end-screen { display: none; }

.modal {
  background: white;
  padding: 30px;
  border-radius: 12px;
  text-align: center;
  width: 85%;
  max-width: 380px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}

#record-message:empty { display: none; }
#record-message {
  font-weight: bold;
  color: var(--success);
  margin-bottom: 10px;
}

/* 7. Animations & States */
button {
  padding: 12px 24px;
  font-size: 1.1rem;
  cursor: pointer;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  font-weight: bold;
}

.shake {
  animation: shake 0.3s ease-in-out;
  border-color: var(--error) !important;
}

#timer {
  font-size: 1.2rem;
  margin-bottom: 5px;
}

#timer-container {
  flex-shrink: 0;
  background: white;
  padding: 10px;
  text-align: center;
  z-index: 10;
  border-bottom: 2px solid #eee;
}

.low-time {
  color: var(--error) !important;
  animation: pulse 0.8s infinite ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.active-guess-container {
  border: 2px solid var(--accent);
  background: #fff;
  padding: 0 !important;
  overflow: hidden;
}

.inline-guess-input {
  width: 100%;
  height: 100%;
  border: none;
  text-align: center;
  font-size: 1.5rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 4px;
  padding: 12px;
  color: var(--accent);
  outline: none;
  background: transparent;
}

.inline-guess-input::placeholder {
  color: #bdc3c7;
  letter-spacing: 4px;
}

.input-area {
  display: none;
}

/* Container for the slots */
.active-guess-row {
    position: relative;
    display: flex;
    gap: 8px;
    justify-content: center;
    background: transparent !important
}

.master-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: text;
    z-index: 10;
}

/* Individual Boxes */
.letter-slot {
    width: 45px;
    height: 50px;
    border: 2px solid #d3d6da;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: bold;
    background: white;
    transition: all 0.1s ease;
}

.letter-slot:focus {
    border-color: var(--accent);
}

.letter-slot.filled {
    border-color: #888;
}

/* Hint letter style (Grayed out/Locked) */
.hint-slot {
    background: #e2e8f0;
    border-color: #cbd5e1;
    color: #64748b;
}

.active-guess-row:focus-within .letter-slot:not(.hint-slot) {
    border-color: var(--accent);
}

/* Solved words appearance */
.solved-word {
    color: var(--success);
    letter-spacing: 2px;
}

.game-title {
    font-family: 'Arial Black', sans-serif;
    font-size: 3.5rem;
    text-align: center;
    margin: 20px 0;
    text-transform: uppercase;
    font-weight: 900;
    
    /* 1. Gradient Setup */
    background: linear-gradient(
        to right, 
        #3498db, #2ecc71, #f1c40f, #e67e22, #e74c3c, #3498db
    );
    background-size: 300% auto;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    
    /* 2. COMBINED ANIMATIONS: Shine (5s) and Float (3s) */
    animation: 
        shine 5s linear infinite, 
        float 3s ease-in-out infinite;
    
    /* 3. Visual Pop */
    filter: drop-shadow(2px 4px 4px rgba(0,0,0,0.15));
}

/* Color shifting logic */
@keyframes shine {
    to { background-position: 300% center; }
}

/* Floating logic */
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* Mobile responsive fix */
@media (max-width: 480px) {
    .game-title {
        font-size: 2.2rem;
        margin: 10px 0;
    }
}

/* Kid-friendly colorful touch */
.game-title span:first-child { color: #2ecc71; }
.game-title span:last-child { color: #9b59b6; }

#end-title {
    font-family: 'Arial Black', sans-serif;
    font-size: 2rem;
    display: flex;
    justify-content: center;
    gap: 2px;
    line-height: 1.5;
    padding: 10px;
    width: 100%;
    box-sizing: border-box;
}

#end-title span {
    display: inline-block;
    /* 1. Liquid Color Gradient */
    background: linear-gradient(
        to bottom, 
        #ff3e3e, #ffaa00, #33ffbd, #3388ff, #ff3e3e
    );
    background-size: 100% 300%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;

    /* 2. Wave & Color Flow Animations */
    animation: 
        winWave 1s ease-in-out infinite,
        colorFlow 3s linear infinite;
    
    /* Offset each letter's animation */
    animation-delay: calc(0.1s * var(--i));
}

@keyframes winWave {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-25px); }
}

@keyframes colorFlow {
    0% { background-position: 50% 0%; }
    100% { background-position: 50% 100%; }
}

@media (max-width: 480px) {
    #end-title {
        font-size: 2rem;
        gap: 1px;
    }
}

#end-message, #record-message {
    display: block; /* Ensures the whole block moves together */
    text-align: center;
    font-size: 1.2rem;
    font-weight: bold;
    color: #667085;
    margin-top: 15px;
    
    /* Animation applied to the WHOLE div, not the spans */
    animation: wholeFloat 3s ease-in-out infinite;
}

@keyframes wholeFloat {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-15px); /* The whole sentence drifts up 15px */
    }
}