/* ============================================================
   Fill the Box - game-specific styles
   ============================================================ */

.fill-the-box-wrap {
  max-width: 760px;
}

#level-select-view {
  width: 100%;
}

.ltf-intro {
  text-align: center;
  color: var(--ink-soft);
  font-weight: 600;
  margin: 0 0 22px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 10px;
  max-width: 620px;
  margin: 0 auto;
}

.level-btn {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  border: 2px solid var(--ink);
  background: var(--surface);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  box-shadow: 0 4px 0 rgba(34, 49, 74, 0.12);
  transition: transform 0.1s ease, background 0.15s ease;
}
.level-btn:hover:not(:disabled) { transform: translateY(-2px); }
.level-btn.completed {
  background: var(--simon-green);
  color: #fff;
}
.level-btn .diff-dot {
  position: absolute;
  top: 5px;
  right: 6px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
}
.diff-easy { background: var(--simon-green); }
.diff-medium { background: var(--yellow-deep); }
.diff-hard { background: var(--pink-deep); }
.diff-expert { background: var(--purple-deep); }

.ltf-legend {
  display: flex;
  gap: 18px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 20px 0 6px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-soft);
}
.ltf-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.ltf-legend .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

#game-play-view:not([hidden]) {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.ltf-play-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 2px;
}
.ltf-level-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.difficulty-chip {
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--ink-soft);
}

.ltf-progress {
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--teal-deep);
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 7px 16px;
  box-shadow: 0 3px 0 rgba(34, 49, 74, 0.12);
}

.ltf-board-shell {
  --grid-size: 5;
  position: relative;
  width: min(640px, 100%);
  aspect-ratio: 1;
  padding: clamp(8px, 2vw, 14px);
  background: #dbe6f5;
  border: 3px solid var(--ink);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
  overflow: hidden;
}
.ltf-board-shell::after {
  content: "";
  position: absolute;
  inset: clamp(8px, 2vw, 14px);
  z-index: 5;
  background: linear-gradient(105deg, transparent 18%, rgba(255, 255, 255, 0.8) 48%, transparent 78%);
  opacity: 0;
  transform: translateX(-120%);
  pointer-events: none;
}
.ltf-board-shell.is-victory {
  animation: ltf-victory-pop 0.52s ease both;
}
.ltf-board-shell.is-victory::after {
  animation: ltf-victory-sweep 0.95s ease-out 0.1s both;
}

.ltf-board {
  position: absolute;
  inset: clamp(8px, 2vw, 14px);
  display: grid;
  grid-template-columns: repeat(var(--grid-size), minmax(0, 1fr));
  grid-template-rows: repeat(var(--grid-size), minmax(0, 1fr));
  gap: 0;
  z-index: 1;
  border: 2px solid rgba(34, 49, 74, 0.26);
  background: rgba(34, 49, 74, 0.26);
}

.ltf-cell {
  position: relative;
  min-width: 0;
  border: 0;
  border-radius: 0;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: inset 0 0 0 1px rgba(34, 49, 74, 0.18);
  overflow: visible;
}
.ltf-cell.is-blocked {
  background: #6f7b8d;
  box-shadow: inset 0 0 0 1px rgba(34, 49, 74, 0.2);
}
.ltf-cell.is-filled {
  background: var(--cell-color);
  box-shadow: inset 0 0 0 1px rgba(34, 49, 74, 0.16);
}
.ltf-board-shell.is-victory .ltf-cell.is-filled {
  animation: ltf-cell-glow 0.9s ease both;
}
.ltf-cell.is-invalid {
  animation: ltf-bump 0.2s ease;
}
.ltf-cell.is-start {
  background: var(--cell-color);
  box-shadow: inset 0 0 0 3px var(--ink), inset 0 0 0 6px rgba(255, 255, 255, 0.5);
}
.ltf-cell.is-start::after {
  content: attr(data-limit-label);
  position: absolute;
  min-width: 40%;
  height: 40%;
  left: 50%;
  top: 50%;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(34, 49, 74, 0.55);
  transform: translate(-50%, -50%);
  z-index: 4;
  box-shadow: none;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: clamp(0.72rem, 2.2vw, 1.05rem);
  font-weight: 800;
  line-height: 1;
  padding: 0 3px;
}

.ltf-lines {
  position: absolute;
  inset: clamp(8px, 2vw, 14px);
  z-index: 2;
  overflow: visible;
  pointer-events: none;
  display: none;
}
.ltf-path {
  fill: none;
  stroke: var(--path-color);
  stroke-width: var(--line-size);
  stroke-linecap: butt;
  stroke-linejoin: miter;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 2px 0 rgba(34, 49, 74, 0.1));
}

.ltf-burst {
  position: absolute;
  left: calc(
    clamp(8px, 2vw, 14px)
    + ((100% - (clamp(8px, 2vw, 14px) * 2)) / var(--grid-size) * var(--burst-col))
  );
  top: calc(
    clamp(8px, 2vw, 14px)
    + ((100% - (clamp(8px, 2vw, 14px) * 2)) / var(--grid-size) * var(--burst-row))
  );
  width: clamp(8px, 2.2vw, 14px);
  height: clamp(8px, 2.2vw, 14px);
  border-radius: 3px;
  background: #fff;
  border: 1px solid rgba(34, 49, 74, 0.35);
  z-index: 6;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0);
  animation: ltf-burst-pop 0.82s ease-out var(--burst-delay) both;
}

.instructions.ltf {
  margin: 0;
}

.ltf-rules {
  width: 100%;
  max-width: none;
}

@keyframes ltf-bump {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(0.92); }
}

@keyframes ltf-victory-pop {
  0%, 100% { transform: scale(1); }
  42% { transform: scale(1.025); }
}

@keyframes ltf-victory-sweep {
  0% { opacity: 0; transform: translateX(-120%); }
  18%, 72% { opacity: 1; }
  100% { opacity: 0; transform: translateX(120%); }
}

@keyframes ltf-cell-glow {
  0%, 100% { filter: brightness(1); }
  45% { filter: brightness(1.18) saturate(1.18); }
}

@keyframes ltf-burst-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0) rotate(0deg);
  }
  28% {
    opacity: 1;
    transform: translate(-50%, -90%) scale(1) rotate(18deg);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -190%) scale(0.35) rotate(80deg);
  }
}

#game-stage:fullscreen,
#game-stage.is-ios-fullscreen {
  border-radius: 0;
  border: none;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  height: calc(var(--obg-vh, 1vh) * 100);
  justify-content: flex-start;
  background: var(--bg-soft);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
#game-stage:fullscreen .ltf-board-shell,
#game-stage.is-ios-fullscreen .ltf-board-shell {
  width: min(94vw, 78vh);
  width: min(94vw, 78dvh);
}

@media (max-width: 560px) {
  .ltf-board-shell {
    width: min(100%, calc(100vw - 28px));
    padding: 8px;
  }
  .ltf-board,
  .ltf-lines {
    inset: 8px;
  }
  .ltf-play-header {
    justify-content: center;
  }
  .level-grid {
    grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
    gap: 8px;
  }
  .level-btn {
    font-size: 0.9rem;
  }
}
