/* Help overlay styles */

/* Help overlay styled like postgame overlay */
.help-overlay {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.18);
  z-index: 20000;
  display: none;
  align-items: center;
  justify-content: center;
  animation: fadeInHelp 0.4s;
}
.help-overlay.visible {
  display: flex;
}
.help-content {
  background: #fff;
  color: #222;
  border-radius: 22px;
  box-shadow: 0 10px 40px 0 rgba(0,0,0,0.28), 0 2px 8px 0 rgba(0,0,0,0.10);
  padding: 36px 24px 36px 24px;
  min-width: 260px;
  max-width: 480px;
  width: 90vw;
  max-height: 80vh;
  text-align: center;
  overflow-y: auto;
  box-sizing: border-box;
  transform: translateY(60px);
  opacity: 0;
  transition: transform 0.45s cubic-bezier(.4,0,.2,1), opacity 0.45s cubic-bezier(.4,0,.2,1);
  animation: fadeInHelpContent 0.5s;
}
.help-overlay.visible .help-content {
  transform: translateY(0);
  opacity: 1;
}
@media (max-width: 700px), (max-height: 600px) {
  .help-content {
    max-width: 98vw;
    width: 98vw;
    max-height: 96vh;
    padding: 18px 4vw 32px 4vw;
    font-size: 0.98em;
    overflow-y: auto;
    box-sizing: border-box;
  }
}
.help-content h2 {
  font-size: 2.5rem;
  margin-bottom: 12px;
  color: #222;
}
.help-content p {
  font-size: 1.2rem;
  color: #444;
  margin-bottom: 0;
}
.help-btn-row {
  display: flex;
  gap: 32px;
  justify-content: center;
  align-items: center;
  margin-top: 32px;
}
.help-close-btn {
  background: none;
  border: none;
  /* border-radius: 50%; */
  /* box-shadow: 0 2px 8px rgba(0,0,0,0.10); */
  padding: 10px;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(.4, 0, .2, 1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.help-close-btn:hover {
  transform: scale(1.12);
  /* box-shadow: 0 4px 16px rgba(0,0,0,0.16); */
  /* border-radius: 50%; */
}
.help-close-btn:active {
  transform: scale(0.96);
}
.help-close-btn img {
  width: 32px;
  height: 32px;
}
@keyframes fadeInHelp {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes fadeInHelpContent {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}
/* Post-game overlay styles */
.postgame-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s cubic-bezier(.4,0,.2,1);
}
.postgame-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

/* Disable game screen content when postgame overlay is visible */
.game-screen:has(.postgame-overlay.visible) main,
.game-screen:has(.postgame-overlay.visible) .grid,
.game-screen:has(.postgame-overlay.visible) .keyboard,
header:has(~ .game-screen .postgame-overlay.visible) {
  pointer-events: none;
  user-select: none;
}

.postgame-content {
  background: #fff;
  border-radius: 22px;
  box-shadow: 0 10px 40px 0 rgba(0,0,0,0.28), 0 2px 8px 0 rgba(0,0,0,0.10);
  padding: 48px 36px 32px 36px;
  min-width: 320px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  text-align: center;
  transform: translateY(60px);
  opacity: 0;
  transition: transform 0.45s cubic-bezier(.4,0,.2,1), opacity 0.45s cubic-bezier(.4,0,.2,1);
  box-sizing: border-box;
}
.postgame-overlay.visible .postgame-content {
  transform: translateY(0);
  opacity: 1;
}
.postgame-content h2 {
  font-size: clamp(1.8rem, 5vw, 2.5rem);
  margin-bottom: 12px;
  color: #222;
}
.postgame-content p {
  font-size: clamp(1rem, 2.5vw, 1.2rem);
  color: #444;
  margin-bottom: 0;
}

/* Postgame gameplay visualization grid */
.postgame-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 24px auto 32px auto;
  padding: 12px;
  background: #f8f8f8;
  border-radius: 12px;
}

.postgame-row {
  display: flex;
  justify-content: center;
  gap: 3px;
}

.postgame-tile {
  width: 32px;
  height: 32px;
  border: 1.5px solid #ddd;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 700;
  font-family: 'Arial Rounded MT Bold', 'Quicksand', 'Nunito', Arial, sans-serif;
  background: #fff;
  color: #222;
  transition: none;
}

/* Color coding for postgame tiles */
.postgame-tile.green {
  background: #6aaa64;
  border-color: #5a9a54;
  color: #fff;
}

.postgame-tile.yellow {
  background: #c9b458;
  border-color: #b9a448;
  color: #fff;
}

.postgame-tile.orange {
  background: #e09052;
  border-color: #d08042;
  color: #fff;
}

.postgame-tile.red {
  background: #d84a4a;
  border-color: #c83a3a;
  color: #fff;
}

.postgame-tile.blue {
  background: #5d8fbb;
  border-color: #4d7fab;
  color: #fff;
}

.postgame-tile.black {
  background: #787c7e;
  border-color: #686c6e;
  color: #fff;
}

.postgame-tile.start-end {
  background: #f5f5f5;
  border-color: #ccc;
}

/* Postgame summary stats */
.postgame-summary {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 auto 24px auto;
  padding: 16px;
  background: #fff;
  border-radius: 12px;
  border: 1px solid #e8e8e8;
  max-width: 400px;
  width: 100%;
  box-sizing: border-box;
}

.postgame-summary-item {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.95rem;
  color: #333;
}

.postgame-summary-icon {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  flex-shrink: 0;
  border: 1.5px solid;
}

.postgame-summary-icon.green {
  background: #6aaa64;
  border-color: #5a9a54;
}

.postgame-summary-icon.red {
  background: #d84a4a;
  border-color: #c83a3a;
}

.postgame-summary-icon.blue {
  background: #5d8fbb;
  border-color: #4d7fab;
}

.postgame-summary-icon.yellow {
  background: #c9b458;
  border-color: #b9a448;
}

.postgame-summary-icon.orange {
  background: #e09052;
  border-color: #d08042;
}

.postgame-summary-count {
  font-weight: 700;
  min-width: 24px;
  text-align: center;
  color: #222;
}

.postgame-summary-label {
  flex: 1;
  color: #555;
}

@media (max-width: 600px) {
  .postgame-tile {
    width: 28px;
    height: 28px;
    font-size: 0.85rem;
  }
  .postgame-grid {
    padding: 8px;
    gap: 3px;
  }
  .postgame-row {
    gap: 2px;
  }
  .postgame-content {
    padding: 32px 20px 24px 20px;
    max-width: 95vw;
  }
  .postgame-content h2 {
    font-size: clamp(1.5rem, 6vw, 2rem);
    margin-bottom: 8px;
  }
  .postgame-content p {
    font-size: clamp(0.9rem, 3.5vw, 1.1rem);
  }
  .share-btn,
  .postgame-home-btn,
  .postgame-next-btn {
    width: 75%;
    max-width: 280px;
    padding: 14px 0;
    margin-bottom: 18px;
    font-size: clamp(1.1rem, 4vw, 1.3rem);
  }
  .share-btn img,
  .postgame-home-btn img,
  .postgame-next-btn img {
    width: 32px;
    height: 32px;
    margin-right: 8px;
  }
  .postgame-icon-btn {
    width: 56px;
    height: 56px;
  }
  .postgame-icon-btn img {
    width: 28px;
    height: 28px;
  }
  .postgame-nav-buttons {
    gap: 18px;
    margin-bottom: 18px;
  }
  .postgame-summary {
    padding: 12px;
    gap: 6px;
    max-width: 95%;
  }
  .postgame-summary-item {
    font-size: 0.88rem;
    gap: 10px;
  }
  .postgame-summary-icon {
    width: 20px;
    height: 20px;
  }
  .postgame-summary-count {
    min-width: 20px;
  }
}

/* Make game-screen un-interactable when postgame is visible */
.postgame-overlay.visible ~ * {
  pointer-events: none !important;
  user-select: none !important;
  filter: blur(0.5px) grayscale(0.08);
}
body {
  font-family: sans-serif;
  background-color: #ececec;
  margin: 0;
  padding: 0;
  overflow: hidden; /* Prevent scrollbar during page transitions */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

* {
  touch-action: manipulation;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: var(--app-height);
  overflow: hidden; /* Contain animated elements */
}

.menu-screen,
.difficulty-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: var(--app-height);
  overflow: hidden; /* Prevent scrollbar during exit animations */
}

.game-screen {
  top: 80px;
  left: 15vw;
  width: calc(100vw - 30vw);
  display: flex;
  flex-direction: column;
  align-items: center;       /* center horizontally */
  justify-content: flex-start; /* top-aligned vertically */
  position: absolute;
  flex: 1 1 auto;            /* fill remaining space */
  height: calc(var(--app-height) - 80px);              /* not full viewport in portrait */
  box-sizing: border-box;
  padding-top: 0; 
  padding-left: 0;
  padding-right: 0;
}


.game-screen main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  min-height: 0;
  box-sizing: border-box;
  padding: 10px;
  align-self: stretch;
  width: 100%;
  position: relative;
}
/*
.grid {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  flex: 1 1 auto;
  min-height: 0;
  width: 320px;
  margin: 0 auto;
  border-radius: 12px;
  padding: 16px 0;
  -ms-overflow-style: none;
  scrollbar-width: none;
  overflow-y: auto;
}*/

.hidden {
  display: none !important;
}

.ad-space {
  flex: 0 0 auto;
  position: absolute;
  flex-direction: column;
  top: 0;
  left: 0;
  width: 15vw;
  height: 100vh;
  display: flex;
  min-height: 600px;
  min-width: 160px;
  align-items: center;
  justify-content: center;
  background: #f5f5f5;
  color: #888;
  font-size: 1.2rem;
  z-index: 100;
  box-shadow: 2px 0 8px rgba(0,0,0,0.04);
}

.ad-space.right {
  left: auto;
  right: 0;
  box-shadow: -2px 0 8px rgba(0,0,0,0.04);
}

header {
  flex: 0 0 auto;
  position: relative;
  background: #ececec;
  padding: calc(20px + env(safe-area-inset-top)) 0 10px 0;
  z-index: 99;
  box-shadow: 0 2px 8px rgba(0,0,0,0.03);
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  top: 0;
  left: 15vw;
  width: calc(100vw - 30vw);
}

.title{
    font-size: 4rem;
    font-family: 'Times New Roman', Times, serif;
    margin-bottom: 20px;
}

.subtitle{
    font-size: 1.5rem;
    margin-bottom: 40px;
    font-style: italic;
}

.menu-button {
  margin: 5px;
  height: 60px;
  width: 200px;
  padding: 10px 20px;
  font-size: 1rem;
  cursor: pointer;
  border-radius: 100px;
  transition: transform 0.2s cubic-bezier(.4, 0, .2, 1), 
              box-shadow 0.2s cubic-bezier(.4, 0, .2, 1),
              background-color 0.2s ease;

  /* Override browser defaults  */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  text-decoration: none;
  color: inherit;
  border: 2px solid;
  border-color: black;
}

.menu-button:hover {
  transform: scale(1.03);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.menu-button:active {
  transform: scale(0.98);
}

#play-btn {
  background-color: #000000;
  color: white;
  border: none;
}

#play-btn:hover {
  background-color: #222;
}

.icon-btn {
  background: none;
  border: none;
  padding: 10px;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(.4, 0, .2, 1);
}

.icon-btn:hover {
  transform: scale(1.1);
}

.icon-btn:active {
  transform: scale(0.95);
}

.icon-btn img {
  width: 25px;
  height: 25px;
}

.grid {
  width: 100%;
  flex: 1 1 0;
  min-height: 0;          /* critical for flex children to allow scrolling */
  overflow-y: auto;
  margin: 0 auto;
  border-radius: 12px;
  padding: 16px 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  overflow-anchor: auto;
  height: auto;
  max-height: 70%;
  
  --tile-size: min(calc((100vw - 20px)/5), calc(40vh / 3));
  --row-padding: 10px;
  --row-gap: 5px;
}

.grid > .row:first-child {
  margin-top: auto !important;
}

/* Chrome, Safari, and opera */
.grid::-webkit-scrollbar {
  display: none;
}

.row {
  justify-content: center;
  display: flex;
  padding: 10px;
  gap: 5px;
}

/* Responsive gap below the final row to keep rows centered */
.row.final {
  margin-bottom: max(0px, calc((70vh - 80px -(3 * (var(--tile-size) + 20px)))/2));
  /*margin-bottom: max(0px, calc(30vh - 150px));*/
  scale: 1;
}

.tile {
  width: min(calc((100vw - 20px)/5), calc(40vh / 3));
  aspect-ratio: 1/1;
  border: 2px solid #ccc;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;                /* Thicker text */
  font-family: 'Arial Rounded MT Bold', 'Quicksand', 'Nunito', Arial, sans-serif; 
  transition: transform 0.25s cubic-bezier(.22,1,.36,1), background 0.2s;
}

.tile:focus {
  outline: none;
  border-color: #ccc;
  box-shadow: none;
}


/* ANIMATIONS */
.tile.animated {
  animation: tilePop 0.35s cubic-bezier(.22,1,.36,1);
}

/* Shake feedback for invalid words */
.tile.shake {
  animation: shake 0.4s cubic-bezier(.22,1,.36,1);
}

.row.user-entry.new-row {
  opacity: 0;
  animation: fadeInRow .8s cubic-bezier(.22,1,.36,1) forwards;
  animation-delay: 0.3s;
}

@keyframes fadeInRow {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Slide down for final row */

/* Fade-out used when undoing a finalized word */
.row.fade-out {
  animation: fadeOutRow 300ms ease-out forwards;
}

@keyframes fadeOutRow {
  from { opacity: 1; }
  to   { opacity: 0; }
}

@keyframes tilePop {
  0% {
    transform: scale(1);
  }
  20% {
    transform: scale(1.09);
  }
  40% {
    transform: scale(1.18);
  }
  60% {
    transform: scale(1.09);
  }
  80% {
    transform: scale(0.96);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes shake {
  0% { transform: translateX(0); }
  15% { transform: translateX(-6px); }
  30% { transform: translateX(6px); }
  45% { transform: translateX(-5px); }
  60% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
  90% { transform: translateX(3px); }
  100% { transform: translateX(0); }
}

/* Menu/difficulty exit: slide elements downward off-screen with staggered delays */
.menu-screen.animate-exit .title,
.menu-screen.animate-exit .subtitle,
.menu-screen.animate-exit .menu-button,
.menu-screen.animate-exit footer,
.difficulty-screen.animate-exit .title,
.difficulty-screen.animate-exit .subtitle,
.difficulty-screen.animate-exit .menu-button,
.difficulty-screen.animate-exit footer {
  animation: slideDownExit 450ms cubic-bezier(.4, 0, .2, 1) forwards;
}
/* Reverse the exit order: footer -> buttons (last to first) -> subtitle -> title */
.menu-screen.animate-exit footer,
.difficulty-screen.animate-exit footer { animation-delay: 0ms; }
.menu-screen.animate-exit .menu-button:nth-of-type(3),
.difficulty-screen.animate-exit .menu-button:nth-of-type(3) { animation-delay: 100ms; }
.menu-screen.animate-exit .menu-button:nth-of-type(2),
.difficulty-screen.animate-exit .menu-button:nth-of-type(2) { animation-delay: 200ms; }
.menu-screen.animate-exit .menu-button:nth-of-type(1),
.difficulty-screen.animate-exit .menu-button:nth-of-type(1) { animation-delay: 300ms; }
.menu-screen.animate-exit .subtitle,
.difficulty-screen.animate-exit .subtitle { animation-delay: 400ms; }
.menu-screen.animate-exit .title,
.difficulty-screen.animate-exit .title { animation-delay: 500ms; }

@keyframes slideDownExit {
  from { transform: translateY(0); opacity: 1; }
  to   { transform: translateY(60px); opacity: 0; }
}

/* Game/header enter: slide elements from above into place with staggered delays */
header.animate-enter {
  animation: slideInDown 700ms cubic-bezier(.4, 0, .2, 1) forwards;
}
.game-screen.animate-enter .grid {
  /* Animate child rows individually */
  animation: none;
}
.game-screen.animate-enter .keyboard {
  /* Animate keyboard rows individually */
  animation: none;
}

@keyframes slideInDown {
  from { transform: translateY(-50px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* Pre-enter state to avoid flash before animations start */
header.enter-ready {
  opacity: 0;
  transform: translateY(-50px);
}
.game-screen.enter-ready .grid .row,
.game-screen.enter-ready .keyboard .keyboard-row {
  opacity: 0;
  transform: translateY(-50px);
}

/* Bottom-first enter: animate rows from the bottom up with small stagger */
.game-screen.animate-enter .grid .row,
.game-screen.animate-enter .keyboard .keyboard-row {
  animation: slideInDown 800ms cubic-bezier(.4, 0, .2, 1) forwards;
}

/* Keyboard rows: bottom -> middle -> top */
.game-screen.animate-enter .keyboard .keyboard-row:nth-child(3) { animation-delay: 0ms; }
.game-screen.animate-enter .keyboard .keyboard-row:nth-child(2) { animation-delay: 180ms; }
.game-screen.animate-enter .keyboard .keyboard-row:nth-child(1) { animation-delay: 360ms; }

/* Grid rows: bottom (final) -> middle (user-entry) -> top (start) */
.game-screen.animate-enter .grid .row:nth-child(3) { animation-delay: 150ms; }
.game-screen.animate-enter .grid .row:nth-child(2) { animation-delay: 330ms; }
.game-screen.animate-enter .grid .row:nth-child(1) { animation-delay: 510ms; }

/* Game exit (Home): staged fall down animations */
/* Stage 1: Keyboard rows fall bottom -> top */
.game-screen.animate-exit-kb .keyboard .keyboard-row {
  animation: slideDownExit 550ms cubic-bezier(.4, 0, .2, 1) forwards;
}
.game-screen.animate-exit-kb .keyboard .keyboard-row:nth-child(3) { animation-delay: 0ms; }
.game-screen.animate-exit-kb .keyboard .keyboard-row:nth-child(2) { animation-delay: 80ms; }
.game-screen.animate-exit-kb .keyboard .keyboard-row:nth-child(1) { animation-delay: 160ms; }

/* Stage 2: Grid rows fall bottom -> top (JS sets per-row delays) */
.game-screen.animate-exit-grid .grid .row {
  animation: slideDownExit 550ms cubic-bezier(.4, 0, .2, 1) forwards;
}

/* Header exit for Home: slide down slightly */
header.animate-exit {
  animation: slideDownExit 550ms cubic-bezier(.4, 0, .2, 1) forwards;
}

/* Stage 0: Game footer exits first */
.game-screen.animate-exit-footer footer {
  animation: slideDownExit 550ms cubic-bezier(.4, 0, .2, 1) forwards;
}

/* Menu/difficulty re-enter: fall down bottom-first */
.menu-screen.enter-ready .title,
.menu-screen.enter-ready .subtitle,
.menu-screen.enter-ready .menu-button,
.menu-screen.enter-ready footer,
.difficulty-screen.enter-ready .title,
.difficulty-screen.enter-ready .subtitle,
.difficulty-screen.enter-ready .menu-button,
.difficulty-screen.enter-ready footer {
  opacity: 0;
  transform: translateY(-50px);
}

.menu-screen.animate-enter .title,
.menu-screen.animate-enter .subtitle,
.menu-screen.animate-enter .menu-button,
.menu-screen.animate-enter footer,
.difficulty-screen.animate-enter .title,
.difficulty-screen.animate-enter .subtitle,
.difficulty-screen.animate-enter .menu-button,
.difficulty-screen.animate-enter footer {
  animation: slideInDown 450ms cubic-bezier(.4, 0, .2, 1) forwards;
}
/* Bottom-first menu/difficulty enter: footer -> buttons (last to first) -> subtitle -> title */
.menu-screen.animate-enter footer,
.difficulty-screen.animate-enter footer { animation-delay: 0ms; }
.menu-screen.animate-enter .menu-button:nth-of-type(3),
.difficulty-screen.animate-enter .menu-button:nth-of-type(3) { animation-delay: 150ms; }
.menu-screen.animate-enter .menu-button:nth-of-type(2),
.difficulty-screen.animate-enter .menu-button:nth-of-type(2) { animation-delay: 300ms; }
.menu-screen.animate-enter .menu-button:nth-of-type(1),
.difficulty-screen.animate-enter .menu-button:nth-of-type(1) { animation-delay: 450ms; }
.menu-screen.animate-enter .subtitle,
.difficulty-screen.animate-enter .subtitle { animation-delay: 600ms; }
.menu-screen.animate-enter .title,
.difficulty-screen.animate-enter .title { animation-delay: 750ms; }

/* Inline notice box (top of main) */
.notice {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, -14px);
  opacity: 0;
  background: #ffffff;
  color: #111;
  border-radius: 12px;
  padding: 8px 12px;
  box-shadow: 0 6px 14px rgba(0,0,0,0.08);
  font-size: 0.95rem;
  font-weight: 600;
  pointer-events: none;
  z-index: 2;
  border: 1px solid #e8e8e8;
}

.notice.show {
  animation: slideFadeDown 450ms cubic-bezier(.22,1,.36,1) forwards;
}

.notice.hide {
  animation: fadeOutUp 250ms ease forwards;
}

@keyframes slideFadeDown {
  from { transform: translate(-50%, -24px); opacity: 0; }
  to   { transform: translate(-50%, 8px); opacity: 1; }
}

@keyframes fadeOutUp {
  from { transform: translate(-50%, 8px); opacity: 1; }
  to   { transform: translate(-50%, -14px); opacity: 0; }
}


/* KEYBOARD STYLES */
.keyboard {
  height: 30%;
  flex: 0 0 auto;
  margin: 24px auto 0 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;            /* fill game-screen width */
  gap: 6px;
  user-select: none;
  width: 100%;                     /* match game-screen width (already minus ad-space) */
  max-width: 100%;
  /*padding: 0 12px calc(12px + env(safe-area-inset-bottom)) 12px; */                /* side padding so keys don’t touch edges */
  box-sizing: border-box;
}

.keyboard-row {
  height: 33%;
  display: grid;
  grid-gap: 5px;
  width: 100%;
}

/* Row column counts (Wordle-style layout) */
.keyboard-row:nth-child(1) { grid-template-columns: repeat(10, 1fr); } /* Q W E R T Y U I O P */
.keyboard-row:nth-child(2) { grid-template-columns: repeat(9, 1fr); }  /* A S D F G H J K L */
/* Third row: 7 letters + 2 special keys spanning 2 columns each => 11 columns total */
.keyboard-row:nth-child(3) { grid-template-columns: repeat(11, 1fr); }

.key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;                     /* fill grid cell */
  height: 100%;  /* responsive height */
  margin: 0;                       /* use grid gap instead */
  background: #d1d5db;
  color: #222;
  font-size: clamp(1rem, 2.5vw, 1.3rem);
  font-weight: 700;
  font-family: 'Arial Rounded MT Bold', 'Quicksand', 'Nunito', Arial, sans-serif;
  border-radius: 14px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
  border: none;
  box-sizing: border-box;
  min-width: 0;                    /* allow shrinking */
}

.key:active {
  background: #b0b6be;
  transform: scale(0.96);
}

.special-key {
  grid-column: span 2;             /* make ENTER and ⌫ wider within the grid */
  font-size: clamp(0.95rem, 2.2vw, 1.1rem);
  background: #e5e7eb;
  min-width: 2.5em;
  min-height: 2.5em;
  width: 100%;
  height: 100%;
}

.backspace-icon {
    width: 70%;
    height: 70%;
    object-fit: contain;
    display: block;
}

footer {
    position: absolute;
    bottom: 10px;
    font-size: 0.9rem;
    color: #888;
}

.game-screen footer {
  position: static;
  margin-top: 12px;
}

/* This section only applies to mobile phones */
/* Add skipable ad for mobile phones */
@media (max-width: 1070px), (max-height: 600px) {
  .ad-space {
    display: none;
  }
  .game-screen {
    width: 100vw;
    left: 0;
  }
  header {
    top: 0;
    width: 100vw;
    left: 0;
  }
}

/* Scaling and fading effect for previous rows */
/* .row {
  scale: .95;
  z-index: 1;
}
.row.scaled-1:not(.start) {
  transform: scale(0.85);
  opacity: 0.85;
  z-index: 1;
  transition: transform 0.3s, opacity 0.3s;
}
.row.scaled-2:not(.start) {
  transform: scale(0.75);
  opacity: 0.65;
  z-index: 0;
  transition: transform 0.3s, opacity 0.3s;
} 
.row[class^="scaled-"]:not(.scaled-1):not(.scaled-2),
.row[class*=" scaled-"]:not(.scaled-1):not(.scaled-2) {
  /* Applies to .scaled-3, .scaled-4, ... */
  transform: scale(0.6);
  opacity: 0;
  z-index: 0;
  transition: transform 0.3s, opacity 0.3s;
}
.row.start{
  scale: .85;
  opacity: 0.85;
}
.row.scaled-2.start {
  transform: scale(0.82);
  opacity: 0.65;
  z-index: 0;
  transition: transform 0.3s, opacity 0.3s;
} */

/* Hide desktop icons and show mobile menu on small screens */
@media (max-width: 600px) {
  .desktop-icons {
    display: none !important;
  }
  .mobile-menu {
    display: flex !important;
  }
  header {
    padding-top: 8px;
    padding-bottom: 8px;
  }
  header h1 {
    font-size: 1.3em !important;
  }
}

/* Dropdown styles */
.mobile-menu-dropdown {
  display: none;
  position: absolute;
  top: 44px;
  left: 0;
  background: #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,0.13);
  border-radius: 12px;
  z-index: 100;
  flex-direction: column;
  min-width: 48px;
  padding: 6px 0;
}
.mobile-menu-dropdown.show {
  display: flex;
}
.mobile-menu-dropdown .icon-btn {
  width: 48px;
  height: 48px;
  justify-content: flex-start;
}

.share-btn {
  display: block;
  width: 60%;
  max-width: 340px;
  margin: 0 auto 28px auto;
  padding: 18px 0;
  font-size: clamp(1.2rem, 3vw, 1.5rem);
  font-weight: bold;
  background: #000;
  color: #fff;
  border: none;
  border-radius: 100px;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
  letter-spacing: 0.08em;
  box-shadow: 0 4px 16px rgba(0,0,0,0.10);
}
.share-btn:hover {
  background: #222;
  transform: scale(1.03);
}
.share-btn:active {
  background: #111;
  transform: scale(0.98);
}
.share-btn img {
  filter: brightness(0) invert(1); /* Makes icon white */
}

/* Postgame navigation buttons row */
.postgame-nav-buttons {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
  margin: 0 auto 24px auto;
}

.postgame-icon-btn {
  background: #f5f5f5;
  border: none;
  border-radius: 50%;
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  padding: 0;
}

.postgame-icon-btn:hover {
  background: #e8e8e8;
  transform: scale(1.08);
  box-shadow: 0 6px 16px rgba(0,0,0,0.12);
}

.postgame-icon-btn:active {
  transform: scale(0.96);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.postgame-icon-btn img {
  width: 32px;
  height: 32px;
  pointer-events: none;
}

.login-btn, .postgame-home-btn,
.postgame-next-btn {
  display: block;
  width: 60%;
  max-width: 340px;
  margin: 0 auto 28px auto;
  padding: 18px 0;
  font-size: clamp(1.2rem, 3vw, 1.5rem);
  font-weight: bold;
  border-radius: 100px;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
  letter-spacing: 0.08em;
  box-shadow: 0 4px 16px rgba(0,0,0,0.10);
}

.login-btn:hover {
  transform: scale(1.03);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.login-btn:active {
  transform: scale(0.98);
}

/* Share dropdown styles */
.share-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  padding: 12px;
  gap: 10px;
  z-index: 10;
  flex-wrap: wrap;
  justify-content: center;
  width: max-content;
  max-width: 280px;
}

.share-dropdown.show {
  display: flex;
  animation: dropdownSlideIn 0.3s cubic-bezier(.4,0,.2,1);
}

@keyframes dropdownSlideIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.share-icon-btn {
  background: #f5f5f5;
  border: none;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s;
  padding: 0;
}

.share-icon-btn:hover {
  background: #e8e8e8;
  transform: scale(1.1);
}

.share-icon-btn:active {
  transform: scale(0.95);
}

.share-icon-btn img {
  width: 28px;
  height: 28px;
  pointer-events: none;
}

.share-message {
  position: absolute;
  top: calc(100% + 80px);
  left: 50%;
  transform: translateX(-50%);
  background: #222;
  color: #fff;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  white-space: nowrap;
}

.share-message.show {
  opacity: 1;
}

/* ==================== Profile Screen Styles ==================== */
/* Profile screen matches game-screen width/position relative to ad space */
.profile-screen {
  display: flex;
  -ms-overflow-style: none;
  scrollbar-width: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: var(--app-height);
  padding: 0;
  box-sizing: border-box;
  overflow-y: auto;
  background: #ececec;
  position: absolute;
  top: 0;
  left: 15vw;
  width: calc(100vw - 30vw);
  height: var(--app-height);
}

.profile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 20px 16px 10px 16px;
  box-sizing: border-box;
}

.profile-title {
  font-size: 3rem;
  font-family: 'Times New Roman', Times, serif;
  color: #222;
  margin: 0;
  text-align: center;
  flex: 1;
}

.profile-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding: 0 16px 32px 16px;
  box-sizing: border-box;
  gap: 24px;
}

.profile-section {
  width: 100%;
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  box-sizing: border-box;
}

.profile-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: #666;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}


/* Streak Section */
.streak-section {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  box-shadow: none;
  gap: 16px;
  padding: 24px 20px;
}

.streak-icon {
  font-size: 3rem;
  line-height: 1;
}

.streak-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.streak-count {
  font-size: 2.5rem;
  font-weight: 700;
  color: #222;
  line-height: 1;
}

.streak-label {
  font-size: 1rem;
  color: #666;
  font-weight: 500;
}

/* Stats by Difficulty */
.profile-stats {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
}

.difficulty-stats {
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  border-left: 4px solid #ccc;
}

.difficulty-stats.easy {
  border-left-color: #6aaa64;
}

.difficulty-stats.normal {
  border-left-color: #c9b458;
}

.difficulty-stats.hard {
  border-left-color: #d84a4a;
}

.difficulty-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: #222;
  margin: 0 0 16px 0;
  padding-bottom: 8px;
  border-bottom: 1px solid #eee;
  text-align: center;
}

.difficulty-stats.easy .difficulty-title {
  color: #5a9a54;
}

.difficulty-stats.normal .difficulty-title {
  color: #b9a448;
}

.difficulty-stats.hard .difficulty-title {
  color: #c83a3a;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  width: 100%;
  /* max-width: 280px; */
  margin: 0 auto;
  align-items: center;
  padding: 8px 0;
}

.stat-label {
  font-size: 0.95rem;
  color: #555;
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: #222;
}

/* Profile screen animations */
.profile-screen.animate-exit .profile-header,
.profile-screen.animate-exit .profile-section,
.profile-screen.animate-exit .streak-section,
.profile-screen.animate-exit .difficulty-stats,
.profile-screen.animate-exit footer {
  animation: slideDownExit 450ms cubic-bezier(.4, 0, .2, 1) forwards;
}

.profile-screen.animate-exit footer { animation-delay: 0ms; }
.profile-screen.animate-exit .difficulty-stats.hard { animation-delay: 100ms; }
.profile-screen.animate-exit .difficulty-stats.normal { animation-delay: 200ms; }
.profile-screen.animate-exit .difficulty-stats.easy { animation-delay: 300ms; }
.profile-screen.animate-exit .streak-section { animation-delay: 400ms; }
.profile-screen.animate-exit .profile-section:first-of-type { animation-delay: 500ms; }
.profile-screen.animate-exit .profile-header { animation-delay: 600ms; }

.profile-screen.enter-ready .profile-header,
.profile-screen.enter-ready .profile-section,
.profile-screen.enter-ready .difficulty-stats,
.profile-screen.enter-ready footer {
  opacity: 0;
  transform: translateY(-30px);
}

.profile-screen.animate-enter .profile-header,
.profile-screen.animate-enter .profile-section,
.profile-screen.animate-enter .difficulty-stats,
.profile-screen.animate-enter footer {
  animation: slideInDown 700ms cubic-bezier(.4, 0, .2, 1) forwards;
}

.profile-screen.animate-enter footer { animation-delay: 0ms; }
.profile-screen.animate-enter .difficulty-stats.hard { animation-delay: 150ms; }
.profile-screen.animate-enter .difficulty-stats.normal { animation-delay: 300ms; }
.profile-screen.animate-enter .difficulty-stats.easy { animation-delay: 450ms; }
.profile-screen.animate-enter .profile-section.streak-section { animation-delay: 600ms; }
.profile-screen.animate-enter .profile-section:first-of-type { animation-delay: 750ms; }
.profile-screen.animate-enter .profile-header { animation-delay: 900ms; }

/* Responsive adjustments for profile */
@media (max-width: 1070px), (max-height: 600px) {
  .profile-screen {
    width: 100%;
    left: 0;
    position: absolute;
  }
}

@media (max-width: 600px) {
  .profile-header {
    padding: 16px 12px 8px 12px;
  }
  .profile-title {
    font-size: 1.6rem;
  }
  .profile-content {
    padding: 0 12px 24px 12px;
    gap: 16px;
  }
  .profile-section {
    padding: 16px;
  }
  .streak-icon {
    font-size: 2.5rem;
  }
  .streak-count {
    font-size: 2rem;
  }
  .difficulty-stats {
    padding: 16px;
  }
  .difficulty-title {
    font-size: 1.1rem;
  }
  .stat-label {
    font-size: 0.85rem;
  }
  .stat-value {
    font-size: 1rem;
  }
}

:root {
 --app-height: 100vh;
}

@supports (height: 100dvh) {
  :root {
   --app-height: 100dvh;
  }
}

























