/* =========================
   General Page Styling
   ========================= */
body {
  font-family: Arial, sans-serif;
  background: #f7f7f7;
  margin: 0;
  padding: 0;
  text-align: center;
  font-size: 1rem;
  color: #222;
}

h1 {
  margin-top: 24px;
  color: #333;
}

:focus {
  outline: 3px solid #1976d2;
  outline-offset: 2px;
}

/* =========================
   Responsive Layout
   ========================= */
/* Main layout: single column on mobile, three columns on desktop */
.lb-main-layout {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 24px;
  margin-top: 16px;
  width: 100%;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
}

/* Three-column layout for desktop */
@media (min-width: 900px) {
  .lb-main-layout {
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 40px;
  }
  .lb-main-layout > * {
    flex: 1 1 0;
    min-width: 0;
    /* Optional: add max-width if you want to constrain column width */
    /* max-width: 360px; */
  }
}


/* Default: reasonable size for mobile/tablet */
.lb-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(36px, 1fr));
  grid-template-rows: repeat(5, minmax(36px, 1fr));
  gap: 10px;
  background: grey;
  border-radius: 8px;
  padding: 6px;
    width: max-content;
    justify-content: center;

}

/* Default for all .lb-cell (mobile/tablet) */
.lb-cell {
  width: 100%;
  aspect-ratio: 1/1;
  min-width: 36px;
  min-height: 36px;
  background: lightgrey;
border: 2px black;
position: relative;
  max-width: 60px;
  max-height: 60px;
    justify-content: center;
  display: flex;
  align-items: center;   
  font-size: 1.2em;
}

/* --- DESKTOP OVERRIDE --- */
@media (min-width: 900px) {
  .lb-grid {
    grid-template-columns: repeat(5, 44px);
    grid-template-rows: repeat(5, 44px);

      width: max-content;

  }
  .lb-cell {
    min-width: 36px;
    min-height: 36px;
    font-size: 1em;
  }
}


/* =========================
   Grid Container Styling
   ========================= */
#lb-grid-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  margin-top: 24px;
  width: 100%;
  max-width: 100vw;
  overflow-x: auto;
}



/* =========================
   Grid Cell Styling
   ========================= */

.lb-cell.empty {
  background: transparent;
  border: none;
  pointer-events: none;
}

.lb-cell.highlight-grid {
  background: #e3f2fd;
  cursor: pointer;
}

.lb-cell:focus-visible {
  outline: 3px solid #388e3c;
}

/* =========================
   Letter Row Area
   ========================= */
#lb-letter-rows {
  margin: 24px auto 0 auto;
  width: max-content;
}

.lb-letter-row {
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
}

.lb-letter-row.hidden {
  opacity: 0.3;
  pointer-events: none;
}

.lb-letter-row.frozen .lb-letter-btn {
  opacity: 0.6;
  background: #f8f8f8;
  color: #bbb;
  cursor: not-allowed;
}

/* =========================
   Letter Button Styling
   ========================= */
.lb-letter-btn {
  width: 44px;
  height: 44px;
  margin: 0 4px;
  font-size: 1.2em;
  background: #fafafa;
  border: 2px solid #bdbdbd;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, border 0.2s;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  user-select: none;
}

.lb-letter-btn.selected,
.lb-letter-btn.active {
  background: #b3e5fc;
  border-color: #0288d1;
  color: #01579b;
  box-shadow: 0 0 6px #81d4fa;
}

.lb-letter-btn:disabled,
.lb-letter-btn.disabled {
  background: #eee;
  color: #aaa;
  cursor: not-allowed;
}

.lb-letter-btn.faded-grey {
  opacity: 0.4;
  background: #e0e0e0;
  color: #aaa;
  border-color: #ccc;
}

.lb-letter-btn.not-chosen {
  opacity: 0.2;
  pointer-events: none;
  background: gold;
  color: brown;
  border-color: #f5e1a1;
}

.lb-letter-btn.tile-back {
  background: #d4d4d4;
  border: 2px solid #b0b0b0;
  color: transparent;
  cursor: default;
}

/* =========================
   Fifth Row Styling
   ========================= */
#lb-fifth-row {
  display: flex;
  gap: 12px;
  margin-top: 32px;
  justify-content: center;
  min-height: 48px;
  align-items: center;
  width: max-content;
  margin-left: auto;
  margin-right: auto;
}

.lb-fifth-letter,
.lb-fifth-letter.ghost {
  width: 48px;
  height: 48px;
  font-size: 1.2em;
  border-radius: 6px;
  border: 2px dashed #bbb;
  background: #f3f3f3;
  color: transparent;
  cursor: default;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border 0.2s, opacity 0.5s, transform 0.5s cubic-bezier(.4,2,.6,1);
}

.lb-fifth-letter {
  color: #222;
  background: #fafafa;
  border: 2px solid #bdbdbd;
  cursor: pointer;
  position: relative;
  z-index: 1;
}

.lb-fifth-letter.active,
.lb-fifth-letter.awake {
  background: #b3e5fc;
  border-color: #0288d1;
  color: #01579b;
  box-shadow: 0 0 10px #ffe082;
  animation: jumpIn 0.5s cubic-bezier(.6,-0.28,.74,.05);
}



.lb-fifth-letter.faded {
  background: #ffe0e0;
  border-color: #d32f2f;
  color: #b71c1c;
  opacity: 0.6;
  cursor: not-allowed;
  position: relative;
  /* Optional: add a cross-out line */
}
.lb-fifth-letter.faded::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  top: 50%;
  height: 2px;
  background: #d32f2f;
  transform: rotate(-20deg);
  pointer-events: none;
  opacity: 0.7;
}


.lb-fifth-letter.empty {
  border: 2px dashed #bbb;
  background: transparent;
  color: transparent;
  opacity: 0.5;
  cursor: not-allowed;
}

.lb-fifth-letter.ghost {
  opacity: 0.5;
  cursor: default;
}

.lb-fifth-letter.disabled {
  cursor: not-allowed !important;
  opacity: 0.4;
  background: #e0e0e0;
  color: #aaa;
  border-color: #ccc;
}

/* Animation for 5th row */
#lb-fifth-row.animated .lb-fifth-letter {
  opacity: 1;
  transform: translateY(0);
}
#lb-fifth-row.animated .lb-fifth-letter:not(.active) {
  opacity: 0;
  transform: translateY(-40px);
}

@keyframes jumpIn {
  0% { transform: scale(0.7); opacity: 0.2; }
  60% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); }
}

/* =========================
   Points and Letters
   ========================= */
.lb-points-wrapper {
  position: absolute;
  bottom: 2px;
  right: 2px;
  pointer-events: none;
  user-select: none;
}

.lb-points {
  position: absolute;
  bottom: 6px;
  right: 6px;
  font-size: 0.7em;
  color: #888;
  user-select: none;
  pointer-events: none;
  background: none;
}

/* =========================
   Scoring Animation Styles
   ========================= */
#lb-scoreboard {
  margin: 32px auto 0 auto;
  width: 95vw;
  max-width: 400px;
  min-width: 220px;
  min-height: 120px;
  text-align: left;
  position: relative;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  padding: 12px 10px 20px 10px;
}

#lb-scoring-sequence {
  margin-bottom: 16px;
}

.lb-score-row {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  min-height: 38px;
}

.lb-score-points {
  font-size: 1.1em;
  margin-left: 8px;
  color: #0288d1;
  min-width: 28px;
  font-weight: bold;
  opacity: 0;
  border: 1px black;
  transition: opacity 0.5s;
}

.lb-score-points.in {
  opacity: 1;
}

.lb-x2-badge {
  display: inline-block;
  background: #ffd600;
  color: #b28704;
  font-size: 0.95em;
  font-weight: bold;
  border-radius: 12px;
  padding: 2px 8px;
  margin-left: 8px;
  box-shadow: 0 0 10px #ffe082;
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.3s, transform 0.3s;
}

.lb-x2-badge.in {
  opacity: 1;
  transform: scale(1);
}

#lb-final-score {
  font-size: 1.5em;
  color: #388e3c;
  font-weight: bold;
  text-align: center;
  margin-top: 20px;
  min-height: 34px;
  opacity: 0;
  transition: opacity 0.7s;
}

#lb-final-score.in {
  opacity: 1;
  animation: final-score-celebrate 1.1s;
}

@keyframes final-score-celebrate {
  0% { transform: scale(1); }
  15% { transform: scale(1.28); }
  40% { transform: scale(1); }
  100% { transform: scale(1); }
}

/* =========================
   Testing Toggles and Reset
   ========================= */
#testing-toggles-btn,
#reset-btn {
  position: fixed;
  left: 20px;
  z-index: 1000;
  background: #fff;
  border: 2px solid #0288d1;
  color: #0288d1;
  border-radius: 6px;
  font-size: 1em;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  padding: 8px 16px;
}

#reset-btn {
  top: 10px;
}

#testing-toggles-btn {
  top: 50px;
}

#reset-btn:hover,
#testing-toggles-btn:hover {
  background: #0288d1;
  color: #fff;
}

#testing-toggles-panel {
  position: fixed;
  top: 90px;
  left: 20px;
  background: #fff;
  border: 2px solid #0288d1;
  border-radius: 8px;
  padding: 16px;
  z-index: 1000;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  min-width: 220px;
}

#testing-toggles-panel label,
#testing-toggles-panel select,
#testing-toggles-panel button {
  display: block;
  margin-bottom: 10px;
}

/* =========================
   Floating Ghost Animations
   ========================= */
.lb-float-ghost,
.lb-ghost-float,
.lb-ghost-anim {
  position: absolute;
  z-index: 9999;
  pointer-events: none;
  width: 48px;
  height: 48px;
  font-size: 1.2em;
  border-radius: 6px;
  background: #fafafa;
  color: #222;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  transition:
    left 0.6s cubic-bezier(.6,-0.28,.74,.05),
    top 0.6s cubic-bezier(.6,-0.28,.74,.05),
    opacity 0.3s,
    transform 0.3s;
  opacity: 1;
  will-change: left, top, opacity, transform;
}

.lb-ghost-anim.galvanise {
  background: #b3e5fc;
  color: #0288d1;
  box-shadow: 0 0 18px #40c4ff;
  animation: galvanise-glow 0.66s;
}

@keyframes galvanise-glow {
  0% { box-shadow: 0 0 0 #40c4ff; }
  60% { box-shadow: 0 0 18px #40c4ff; }
  100% { box-shadow: 0 0 8px #40c4ff; }
}

.lb-ghost-anim.ashes {
  background: #eee;
  color: #bbb;
  opacity: 0.5;
  transform: translateY(-24px) scale(0.9) rotate(-12deg);
  transition: opacity 0.7s, transform 0.7s;
}

.lb-ghost-anim.hesitate {
  transition: none;
}

/* =========================
   Accessibility: Reduced Motion
   ========================= */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* =========================
   Accessibility: High Contrast Mode
   ========================= */
@media (forced-colors: active) {
  body, .lb-grid, .lb-cell, .lb-letter-btn, .lb-fifth-letter, #lb-scoring-results-container {
    forced-color-adjust: none;
    background: Canvas;
    color: CanvasText;
    border-color: Highlight;
  }
  .lb-letter-btn.selected,
  .lb-letter-btn.active,
  .lb-fifth-letter.active {
    background: Highlight;
    color: HighlightText;
  }
}

/* =========================
   Miscellaneous
   ========================= */
.lb-letter,
.lb-points {
  pointer-events: none;
  user-select: none;
}

.lb-fifth-letter.fadedafter::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  top: 50%;
  height: 2px;
  background: #222;
  transform: rotate(-20deg);
  pointer-events: none;
}

.lb-grid,
.lb-cell .lb-letter {
  transition: transform 0.5s cubic-bezier(.6,-0.28,.74,.05);
  will-change: transform;
 /* display: inline-block;*/
}

/* =========================
   Mobile-Specific Tweaks
   ========================= */
@media (max-width: 600px) {
  .lb-grid {
    grid-template-columns: repeat(5, minmax(32px, 1fr));
    grid-template-rows: repeat(5, minmax(32px, 1fr));
    padding: 2px;
  }
  .lb-letter-btn,
  .lb-fifth-letter,
  .lb-float-ghost,
  .lb-ghost-anim {
    width: 38px;
    height: 38px;
    font-size: 1em;
  }
  #lb-scoring-results-container {
    min-width: 0;
    width: 99vw;
    padding: 6px 2vw 16px 2vw;
    font-size: 0.98em;
  }
  #testing-toggles-panel {
    left: 2vw;
    min-width: 160px;
    padding: 8px;
  }
}

.score-slot {
    display: inline-flex;           /* Use flexbox for centering */
  align-items: center;            /* Vertically center content */
  justify-content: center; 
    font-size: 1.2em;  
  width: 2em;
  height: 2em;
  border: 2px solid #ccc;
  margin: 0 0.2em;
  background: #f9f9f9;
  border-radius: 0.5em;
  position: relative;
}


.score-slot.pop-in {
  animation: popIn 0.2s cubic-bezier(.68,-0.55,.27,1.55);
}
@keyframes popIn {
  0% { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.bonus-double-letter {
  background: #fffbe6 !important;
  border: 2px solid #ffd600 !important;
  position: relative;
}
.bonus-double-letter::after {
  content: "2× Letter";
  color: #ffd600;
  opacity: 0.3;
  font-weight: bold;
  font-size: 0.85em;
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%) rotate(-20deg);
  pointer-events: none;
  white-space: nowrap;
}
.bonus-triple-letter {
  background: #ffeaea !important;
  border: 2px solid #e53935 !important;
  position: relative;
}
.bonus-triple-letter::after {
  content: "TL";
  color: #e53935;
  opacity: 0.3;
  font-weight: bold;
  font-size: 0.85em;
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%) rotate(-20deg);
  pointer-events: none;
  white-space: nowrap;
}
.bonus-double-word {
  background: #e3f2fd !important;
  border: 2px solid #1976d2 !important;
  position: relative;
}
.bonus-double-word::after {
  content: "DW";
  color: #1976d2;
  opacity: 0.3;
  font-weight: bold;
  font-size: 0.85em;
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%) rotate(-20deg);
  pointer-events: none;
  white-space: nowrap;
}

/* --- Scoreboard Result Animations --- */

/* Valid word (galvanise) */
.lb-score-row.galvanise {
  background: #e3f7fd;
  animation: rowGalvaniseGlow 0.7s;
}
@keyframes rowGalvaniseGlow {
  0%   { box-shadow: 0 0 0 #40c4ff; }
  60%  { box-shadow: 0 0 18px #40c4ff; }
  100% { box-shadow: 0 0 8px #40c4ff; }
}

/* Theme word (galvanise + theme) */
.lb-score-row.theme {
  background: linear-gradient(90deg, #fffbe6 0%, #ffe082 100%);
  box-shadow: 0 0 18px #ffd600;
  animation: rowThemeGlow 0.9s;
}
@keyframes rowThemeGlow {
  0%   { box-shadow: 0 0 0 #ffd600; }
  60%  { box-shadow: 0 0 24px #ffd600; }
  100% { box-shadow: 0 0 12px #ffd600; }
}

/* Invalid word (ashes) */
.lb-score-row.ashes {
  background: #f5f5f5;
  color: #bbb;
  opacity: 0.7;
  animation: rowAshesShake 0.5s;
}
@keyframes rowAshesShake {
  0% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
  100% { transform: translateX(0); }
}

/* Optional: Animate individual score slots for extra effect */
.lb-score-row.galvanise .score-slot,
.lb-score-row.theme .score-slot {
  background: #b3e5fc;
  color: #0288d1;
  transition: background 0.3s, color 0.3s;
}
.lb-score-row.theme .score-slot {
  background: #fffde7;
  color: #b28704;
}
.lb-score-row.ashes .score-slot {
  background: #eee;
  color: #bbb;
  transition: background 0.3s, color 0.3s;
}

/* Example for 0°, 90°, 180°, 270° grid rotations */
.lb-points-pos-0 {
  transform: rotate(0deg) translate(6px, 6px);
  transition: transform 0.5s cubic-bezier(.6,-0.28,.74,.05);
}
.lb-points-pos-90 {
  transform: rotate(-90deg) translate(6px, 6px);
  transition: transform 0.5s cubic-bezier(.6,-0.28,.74,.05);
}
.lb-points-pos-180 {
  transform: rotate(-180deg) translate(6px, 6px);
  transition: transform 0.5s cubic-bezier(.6,-0.28,.74,.05);
}
.lb-points-pos-270 {
  transform: rotate(-270deg) translate(0px, 48px);
  transition: transform 0.5s cubic-bezier(.6,-0.28,.74,.05);
}

.scoreboard-letter {
  display: inline-flex;
  flex-direction: column;
  
  margin: 0 2px;
  font-size: 1em;
  position: relative;
}
.scoreboard-letter-char {
  font-weight: bold;
  align-items: center;
  justify-content: center;

  font-size: 1em;
  letter-spacing: 0.03em;
}
.scoreboard-letter-points {
  font-size: 0.7em;
  color: #888;
  line-height: 1;
  margin-top: 0px;
    position: absolute;
  bottom: -0.5vw;
  right: -0.5vw;
  pointer-events: none;
  user-select: none;
}

#lb-grid-area {
  position: relative;  /* Contains positioning context */
}

#lb-endgame-popup {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;

  background-color: rgba(0, 0, 0, 0.7); /* Semi-transparent overlay */
  display: flex;
  justify-content: center;
  align-items: center;

  color: white;
  font-size: 2rem;
  z-index: 1000;
  display: none; /* Hidden by default */
}

