/* ==========================================================================
   CROSSWORD GAMEPLAY & INTERACTIVE BOARD STYLING
   ========================================================================== */

.game-stage {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  width: 100%;
}

/* Status Bar: Title, Date, Timer & Controls */
.game-status-bar {
  width: 100%;
  max-width: 860px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  backdrop-filter: blur(8px);
  padding: 10px 18px;
  border-radius: 14px;
  border: 1px solid var(--border-subtle);
}

.puzzle-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1 1 auto;
}

.puzzle-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  white-space: nowrap;
}

.puzzle-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.puzzle-difficulty-tag {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  text-transform: uppercase;
  flex-shrink: 0;
  white-space: nowrap;
}

.tag-easy { background: rgba(0, 255, 102, 0.1); color: var(--pickle-neon); border: 1px solid rgba(0, 255, 102, 0.3); }
.tag-medium { background: rgba(56, 189, 248, 0.1); color: var(--accent-blue); border: 1px solid rgba(56, 189, 248, 0.3); }
.tag-hard { background: rgba(255, 190, 11, 0.1); color: var(--toast-gold); border: 1px solid rgba(255, 190, 11, 0.3); }

.puzzle-date {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timer-section {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.timer-display {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--pickle-neon);
  background: rgba(0, 0, 0, 0.3);
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  min-width: 65px;
  text-align: center;
}

.timer-paused {
  color: var(--toast-gold);
  animation: pulseTimer 1.2s infinite;
}

@keyframes pulseTimer {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.puzzle-actions {
  display: flex;
  gap: 5px;
}

.action-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 5px;
}

.action-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

/* Active Clue Banner */
.current-clue-banner {
  width: 100%;
  max-width: 440px;
  position: relative;
  background: rgba(10, 24, 18, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(0, 255, 102, 0.28);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  padding: 10px 16px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.current-clue-banner:hover {
  border-color: rgba(0, 255, 102, 0.45);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.45), 0 0 14px rgba(0, 255, 102, 0.12);
}

.clue-badge {
  background: rgba(0, 255, 102, 0.12);
  border: 1px solid rgba(0, 255, 102, 0.35);
  color: var(--pickle-neon);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.clue-text {
  font-size: 0.98rem;
  font-weight: 600;
  color: #ffffff;
  flex: 1;
  line-height: 1.4;
  letter-spacing: -0.01em;
}

.banner-btn-group {
  display: flex;
  gap: 5px;
  align-items: center;
}

.clue-direction-toggle {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-dim);
  width: 30px;
  height: 30px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: all var(--transition-fast);
}

.clue-direction-toggle:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.22);
  color: #ffffff;
}

.banner-skip-btn {
  background: rgba(0, 255, 102, 0.1);
  border-color: rgba(0, 255, 102, 0.3);
  color: var(--pickle-neon);
}

.banner-skip-btn:hover {
  background: rgba(0, 255, 102, 0.22);
  color: #ffffff;
  border-color: var(--pickle-neon);
}

/* Main Puzzle Layout: Board & Clues Side-by-Side */
.puzzle-main-layout {
  width: 100%;
  max-width: 860px;
  display: grid;
  grid-template-columns: 440px 1fr;
  gap: 20px;
  align-items: start;
}

/* Board Wrapper */
.board-container {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  gap: 12px;
  position: relative;
}

@media (min-width: 769px) {
  .current-clue-banner {
    order: -1; /* Placed above the crossword on desktop */
  }
  .crossword-grid {
    order: 0;
  }
  #vault-rack-container {
    order: 1;
  }
}

/* -------------------------------------------------------------
   The Brine Vault Board Overlay (Bonus Game for 7x7 The Big Dill)
   Overlays the solved board directly so players can focus 100% on
   cracking the secret anagram word without grid interference!
   ------------------------------------------------------------- */
#vault-rack-container.vault-overlay-mode {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  margin: 0 auto;
  width: 100%;
  max-width: min(96vw, 440px);
  height: 100%;
  min-height: 380px;
  z-index: 80;
  background: rgba(5, 14, 10, 0.96);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 2px solid var(--pickle-neon);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.85), 0 0 25px rgba(0, 255, 102, 0.2);
  display: flex !important;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  animation: vaultOverlayFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  overflow-y: auto;
  transition: opacity 0.25s ease;
}

@keyframes vaultOverlayFadeIn {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}

#vault-rack-container.vault-peek {
  opacity: 0.1 !important;
  pointer-events: none !important;
}

#btn-unpeek-vault {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 120;
  background: var(--pickle-neon);
  color: #040907;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.78rem;
  padding: 6px 12px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 255, 102, 0.4);
  display: none;
}

#vault-rack-container.vault-overlay-mode .brine-vault-container {
  margin-top: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  padding: 10px 14px;
  gap: 10px;
  width: 100%;
  box-sizing: border-box;
}

.crossword-grid {
  display: grid;
  width: 100%;
  max-width: 440px;
  aspect-ratio: 1 / 1;
  background: #050d0a;
  border: 1px solid rgba(0, 255, 102, 0.35);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 16px rgba(0, 255, 102, 0.1);
  overflow: hidden;
  gap: 1.5px;
  position: relative;
  user-select: none;
  margin: 0;
}

.grid-5 { 
  grid-template-columns: repeat(5, minmax(0, 1fr)); 
  grid-template-rows: repeat(5, minmax(0, 1fr)); 
}
.grid-6 { 
  grid-template-columns: repeat(6, minmax(0, 1fr)); 
  grid-template-rows: repeat(6, minmax(0, 1fr)); 
}
.grid-7 { 
  grid-template-columns: repeat(7, minmax(0, 1fr)); 
  grid-template-rows: repeat(7, minmax(0, 1fr)); 
}

/* Crossword Cell */
.crossword-cell {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1 / 1;
  background: #0c1914;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  box-sizing: border-box;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--transition-fast), box-shadow var(--transition-fast);
}

.crossword-cell.cell-blocked {
  background: #040907;
  cursor: default;
}

.cell-number {
  position: absolute;
  top: 2px;
  left: 3px;
  font-size: 0.62rem;
  font-weight: 700;
  color: #6ee7b7;
  line-height: 1;
  pointer-events: none;
  z-index: 2;
}

.cell-letter {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 3.8vw, 1.55rem);
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
  pointer-events: none;
  user-select: none;
  z-index: 1;
}

/* Highlighting States */
.crossword-cell.cell-active {
  background: var(--pickle-neon) !important;
  color: #041209 !important;
  box-shadow: inset 0 0 0 2px #ffffff, 0 0 14px rgba(0, 255, 102, 0.55) !important;
  z-index: 5;
}

.crossword-cell.cell-active .cell-number {
  color: #041209 !important;
}

.crossword-cell.cell-in-word {
  background: rgba(0, 255, 102, 0.16) !important;
  color: #ffffff !important;
}

.crossword-cell.cell-in-word .cell-number {
  color: #a7f3d0 !important;
}

/* Special 7x7 Mystery Cells */
.crossword-cell.cell-special {
  background: rgba(255, 190, 11, 0.08) !important;
  box-shadow: inset 0 0 0 1.5px rgba(255, 190, 11, 0.45) !important;
  position: relative;
}

.crossword-cell.cell-special::after {
  content: '';
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--toast-gold);
  box-shadow: 0 0 5px rgba(255, 190, 11, 0.8);
  pointer-events: none;
}

.crossword-cell.cell-special.cell-active {
  background: var(--pickle-neon) !important;
  color: #041209 !important;
  box-shadow: inset 0 0 0 2px #ffffff, 0 0 16px rgba(0, 255, 102, 0.55) !important;
  z-index: 6;
}

.crossword-cell.cell-special.cell-in-word {
  background: rgba(0, 255, 102, 0.2) !important;
  color: #ffffff !important;
}

.crossword-cell.cell-error {
  background: rgba(239, 68, 68, 0.22) !important;
  color: #fca5a5 !important;
  box-shadow: inset 0 0 0 1.5px #ef4444 !important;
  z-index: 7;
}

.crossword-cell.cell-shake {
  animation: cellShake 0.45s ease-in-out;
}

@keyframes cellShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px) rotate(-1deg); }
  40% { transform: translateX(4px) rotate(1deg); }
  60% { transform: translateX(-3px) rotate(-0.5deg); }
  80% { transform: translateX(3px) rotate(0.5deg); }
}

.crossword-cell.cell-correct-flash {
  animation: cellPop 0.4s ease;
}

@keyframes cellPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.06); background: var(--cell-active); }
  100% { transform: scale(1); }
}

/* Clues Panel (Side List — NO internal scrolling!) */
.clues-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  background: rgba(10, 24, 19, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.clue-column {
  display: flex;
  flex-direction: column;
}

.clue-col-header {
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 8px;
}

.clue-column:first-child .clue-col-header {
  color: #38bdf8;
}

.clue-column:last-child .clue-col-header {
  color: var(--toast-gold);
}

.clue-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.clue-item {
  display: flex;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 0.84rem;
  line-height: 1.4;
  cursor: pointer;
  transition: all var(--transition-fast);
  color: var(--text-dim);
  border: 1px solid transparent;
}

.clue-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: #f1f5f9;
}

.clue-item.active {
  background: rgba(0, 255, 102, 0.08);
  border-left: 2.5px solid var(--pickle-neon);
  color: #ffffff;
  font-weight: 600;
}

.clue-num {
  font-weight: 800;
  color: var(--pickle-neon);
  min-width: 16px;
  font-size: 0.8rem;
}

/* Mobile Responsiveness & Layout Optimization */
@media (max-width: 768px) {
  .game-stage {
    gap: 6px;
    width: 100%;
  }

  .game-status-bar {
    width: 100%;
    max-width: min(94vw, 420px);
    margin: 0 auto;
    padding: 6px 12px;
  }

  .puzzle-main-layout {
    width: 100%;
    max-width: min(94vw, 420px);
    margin: 0 auto;
    grid-template-columns: 1fr;
    gap: 0;
  }

  .clues-panel {
    display: none; /* On mobile, clue banner provides primary focus */
  }

  .board-container {
    width: 100%;
    align-items: center;
    gap: 6px;
  }

  .crossword-grid {
    order: 1;
    width: 100%;
    max-width: min(94vw, calc(100svh - 220px), 420px);
    max-height: min(94vw, calc(100svh - 220px), 420px);
    aspect-ratio: 1 / 1;
    border-width: 1px;
    margin: 0 auto;
  }

  .current-clue-banner {
    order: 2; /* Positioned directly below the crossword on mobile! */
    width: 100%;
    max-width: min(94vw, calc(100svh - 220px), 420px);
    padding: 8px 12px;
    gap: 8px;
    margin: 0 auto;
  }

  #vault-rack-container {
    order: 3;
    width: 100%;
    max-width: min(94vw, 420px);
    margin: 0 auto;
  }

  .cell-letter {
    font-size: clamp(1.1rem, 5vw, 1.5rem);
  }

  .cell-number {
    font-size: 0.62rem;
    top: 2px;
    left: 2px;
  }

  .clue-badge {
    font-size: 0.72rem;
    padding: 2px 7px;
  }

  .clue-text {
    font-size: 0.88rem;
    line-height: 1.3;
  }

  .puzzle-title {
    font-size: 0.98rem;
  }

  .puzzle-difficulty-tag {
    font-size: 0.62rem;
    padding: 2px 6px;
  }

  .timer-display {
    font-size: 0.95rem;
    min-width: 52px;
    padding: 2px 7px;
  }

  .action-btn {
    padding: 4px 7px;
    font-size: 0.7rem;
    gap: 3px;
  }

  /* -------------------------------------------------------------
     Mobile Focus Mode (Active Virtual Keyboard)
     Ensures Header/Mode-Nav collapse so Puzzle + Clue + Keyboard
     are 100% visible on screen simultaneously without obstruction!
     ------------------------------------------------------------- */
  body.keyboard-active {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
    top: 0 !important;
    left: 0 !important;
  }

  body.keyboard-active .app-container {
    padding: 2px 8px 4px !important;
    height: var(--visual-vh, 100dvh) !important;
    max-height: var(--visual-vh, 100dvh) !important;
    min-height: 0 !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: flex-start !important;
  }

  body.keyboard-active .app-header,
  body.keyboard-active .mode-nav,
  body.keyboard-active .portal-section,
  body.keyboard-active .app-footer,
  body.keyboard-active #vault-rack-container:not(.vault-overlay-mode) {
    display: none !important;
  }

  body.keyboard-active #vault-rack-container.vault-overlay-mode {
    display: flex !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: var(--visual-vh, 100dvh) !important;
    max-height: var(--visual-vh, 100dvh) !important;
    z-index: 1000 !important;
    overflow-y: auto !important;
    background: rgba(5, 14, 10, 0.98) !important;
    box-sizing: border-box !important;
  }

  body.keyboard-active .vault-overlay-mode .brine-vault-container {
    padding: 4px 8px !important;
    gap: 4px !important;
  }

  body.keyboard-active .scrambled-jars-row {
    gap: 6px !important;
  }

  body.keyboard-active .scrambled-jar-badge {
    width: 44px !important;
    height: 50px !important;
    font-size: 1.3rem !important;
  }

  body.keyboard-active .typed-slots-row {
    gap: 6px !important;
  }

  body.keyboard-active .typed-slot {
    width: 42px !important;
    height: 48px !important;
    font-size: 1.35rem !important;
    border-radius: 8px !important;
  }

  body.keyboard-active .game-stage {
    gap: 4px !important;
    height: 100% !important;
    max-height: 100% !important;
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: flex-start !important;
    align-items: center !important;
    width: 100% !important;
  }

  body.keyboard-active .game-status-bar {
    width: 100% !important;
    max-width: min(92vw, 420px) !important;
    padding: 3px 8px !important;
    border-radius: 8px !important;
    margin-bottom: 0 !important;
    flex-shrink: 0 !important;
    box-sizing: border-box !important;
  }

  body.keyboard-active .puzzle-title {
    font-size: 0.82rem !important;
  }

  body.keyboard-active .timer-display {
    font-size: 0.85rem !important;
    padding: 2px 5px !important;
    min-width: 46px !important;
  }

  body.keyboard-active .puzzle-main-layout {
    width: 100% !important;
    flex: 1 !important;
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
  }

  body.keyboard-active .board-container {
    width: 100% !important;
    gap: 5px !important;
    flex: 1 !important;
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: flex-start !important;
    align-items: center !important;
  }

  body.keyboard-active .crossword-grid {
    /* Dynamically computed so Status Bar (~36px) + Clue Bar (~42px) + Gaps (~15px) all fit with 100% visibility above virtual keyboard on Android & iOS */
    order: 1 !important;
    width: min(88vw, calc(var(--visual-vh, 100dvh) - 110px), 340px) !important;
    height: min(88vw, calc(var(--visual-vh, 100dvh) - 110px), 340px) !important;
    max-width: min(88vw, calc(var(--visual-vh, 100dvh) - 110px), 340px) !important;
    max-height: min(88vw, calc(var(--visual-vh, 100dvh) - 110px), 340px) !important;
    aspect-ratio: 1 / 1 !important;
    margin: 0 auto !important;
    flex-shrink: 0 !important;
  }

  body.keyboard-active .current-clue-banner {
    order: 2 !important;
    width: 100% !important;
    max-width: min(92vw, 420px) !important;
    padding: 5px 10px !important;
    min-height: 40px !important;
    margin: 0 auto !important;
    flex-shrink: 0 !important;
    box-sizing: border-box !important;
  }

  body.keyboard-active .clue-text {
    font-size: 0.8rem !important;
    line-height: 1.25 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important;
    line-clamp: 2 !important;
    -webkit-box-orient: vertical !important;
  }

  body.keyboard-active .cell-number {
    font-size: clamp(0.5rem, 1.8vw, 0.62rem) !important;
    top: 1px !important;
    left: 2px !important;
  }

  body.keyboard-active .cell-letter {
    font-size: clamp(0.85rem, 4vw, 1.25rem) !important;
  }
}

@media (max-width: 480px) {
  .game-status-bar {
    padding: 6px 10px;
    gap: 6px;
  }

  .puzzle-title-row {
    gap: 5px;
  }

  .puzzle-title {
    font-size: 0.88rem;
  }

  .puzzle-difficulty-tag {
    font-size: 0.58rem;
    padding: 1px 5px;
  }

  .puzzle-date {
    font-size: 0.68rem;
  }

  .timer-section {
    gap: 4px;
  }

  .puzzle-actions {
    gap: 2px;
  }

  .action-btn {
    padding: 3px 5px;
    font-size: 0.65rem;
  }

  .action-btn svg {
    width: 9px;
    height: 9px;
  }

  .clue-direction-toggle {
    width: 26px;
    height: 26px;
  }
}
