/* ── Color Lines ──
   The board is a 9×9 grid of square tiles; everything scales with the card
   width. Ball colours are shared by the board and the "next" preview. */

/* ── Palette (dark is the site default) ── */
.ln-game {
  --ln-board: #0a0e17;
  --ln-cell: #182033;
  --ln-cell-hover: #1f2a42;
  --ln-shadow: rgba(0, 0, 0, 0.45);
  --ln-c0: #e5484d; /* red */
  --ln-c1: #f2c94c; /* yellow */
  --ln-c2: #3fb950; /* green */
  --ln-c3: #2ec5d8; /* cyan */
  --ln-c4: #3b6fe0; /* blue */
  --ln-c5: #c04fd8; /* magenta */
  --ln-c6: #a8683c; /* brown */
}

[data-theme="light"] .ln-game {
  --ln-board: #b3b7bf;
  --ln-cell: #d3d6da;
  --ln-cell-hover: #dde0e4;
  --ln-shadow: rgba(0, 0, 0, 0.25);
}

/* ── Card and HUD ── */
.game-card.ln-card {
  max-width: 520px;
  margin: 0 auto;
  opacity: 1;
  transform: none;
}

.ln-controls {
  justify-content: center;
}

.ln-hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
}

.ln-box {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.3rem 0.8rem 0.35rem;
  border-radius: 8px;
  border: 1px solid var(--card-border);
  background: var(--btn-bg);
  line-height: 1.2;
}

[data-theme="light"] .ln-box {
  border-color: var(--btn-border);
}

.ln-box-score { justify-self: start; min-width: 5rem; }
.ln-box-best  { justify-self: end; min-width: 5rem; }

.ln-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.ln-box strong {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}

.ln-next-balls {
  display: inline-flex;
  gap: 0.35rem;
  padding-top: 0.15rem;
}

.ln-next .ln-ball {
  width: 1.15rem;
  height: 1.15rem;
}

/* "+N" drifts up out of the score box when a line clears */
.ln-gain {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.ln-gain-float {
  position: absolute;
  left: 0;
  right: 0;
  top: 40%;
  text-align: center;
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--accent);
  animation: ln-float 0.7s ease-out forwards;
}

@keyframes ln-float {
  from { transform: translateY(0); opacity: 1; }
  to   { transform: translateY(-2.2rem); opacity: 0; }
}

/* ── Board ── */
.ln-board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 3px;
  padding: 3px;
  width: 100%;
  aspect-ratio: 1;
  background: var(--ln-board);
  border-radius: 10px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.ln-cell {
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: var(--ln-cell);
  cursor: pointer;
}

@media (hover: hover) {
  .ln-board[data-status="playing"] .ln-cell:hover {
    background: var(--ln-cell-hover);
  }
}

.ln-cell:focus {
  outline: none;
}

.ln-cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.ln-board[data-status="over"] .ln-cell {
  cursor: default;
}

/* ── Balls ── */
.ln-ball {
  display: block;
  width: 74%;
  height: 74%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 30%, rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0) 42%),
    var(--ball);
  box-shadow:
    inset -2px -3px 5px rgba(0, 0, 0, 0.3),
    0 2px 3px var(--ln-shadow);
}

.ln-board .ln-ball:not([data-color]) {
  visibility: hidden;
}

.ln-ball[data-color="0"] { --ball: var(--ln-c0); }
.ln-ball[data-color="1"] { --ball: var(--ln-c1); }
.ln-ball[data-color="2"] { --ball: var(--ln-c2); }
.ln-ball[data-color="3"] { --ball: var(--ln-c3); }
.ln-ball[data-color="4"] { --ball: var(--ln-c4); }
.ln-ball[data-color="5"] { --ball: var(--ln-c5); }
.ln-ball[data-color="6"] { --ball: var(--ln-c6); }

/* Selected ball hops in place, as in the original, on a highlighted cell */
.ln-cell.is-selected {
  box-shadow: inset 0 0 0 2px var(--accent);
}

/* Cells the selected ball can't get to (open-path rule) */
.ln-cell.is-unreachable {
  opacity: 0.4;
}

/* Where the selected ball can go (straight-line rule) */
.ln-cell.is-reachable::after {
  content: "";
  width: 18%;
  height: 18%;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.45;
}

.ln-cell.is-reachable {
  position: relative;
}

.ln-cell.is-reachable .ln-ball {
  position: absolute;
}

.ln-cell.is-selected .ln-ball {
  animation: ln-hop 0.4s ease-in-out infinite alternate;
}

.ln-cell.is-new .ln-ball {
  animation: ln-pop 0.22s ease-out;
}

.ln-cell.is-clearing .ln-ball {
  animation: ln-clear 0.3s ease-in forwards;
}

.ln-cell.is-blocked {
  animation: ln-shake 0.3s ease-in-out;
}

@keyframes ln-hop {
  from { transform: translateY(6%); }
  to   { transform: translateY(-14%); }
}

@keyframes ln-pop {
  from { transform: scale(0); }
}

@keyframes ln-clear {
  to { transform: scale(0); opacity: 0; }
}

@keyframes ln-shake {
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.reduce-motion .ln-cell.is-selected .ln-ball,
.reduce-motion .ln-cell.is-new .ln-ball,
.reduce-motion .ln-cell.is-blocked {
  animation: none;
}

.reduce-motion .ln-cell.is-selected .ln-ball {
  box-shadow: 0 0 0 3px var(--accent);
}

/* The ball gliding from cell to cell during a move */
.ln-mover {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1;
  pointer-events: none;
}

.ln-mover[hidden] {
  display: none;
}

/* ── Game over overlay ── */
.ln-stage {
  position: relative;
}

.ln-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem;
  text-align: center;
  border-radius: 10px;
  background: rgba(10, 14, 23, 0.72);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  color: #e6e6eb;
  animation: ln-fade 0.4s ease;
}

[data-theme="light"] .ln-overlay {
  background: rgba(236, 238, 241, 0.8);
  color: var(--fg);
}

.ln-overlay[hidden] {
  display: none;
}

@keyframes ln-fade {
  from { opacity: 0; }
}

.ln-overlay-title {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 800;
}

.ln-overlay-msg {
  margin: 0;
  font-size: 0.9rem;
}

.ln-overlay-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.ln-overlay button {
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.5rem 1.2rem;
  border-radius: 8px;
  cursor: pointer;
}

.ln-btn-main {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--bg);
}

.ln-btn-alt {
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
}

.ln-overlay button:hover {
  filter: brightness(1.1);
}

.ln-overlay button:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* ── Status and help ── */
.ln-status {
  min-height: 1.6em;
  margin-top: 0.6rem;
  text-align: center;
}

.ln-help {
  margin-top: 0.25rem;
  line-height: 1.7;
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
}

@media (pointer: coarse) {
  .ln-help-keys { display: none; }
}

.ln-help kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 0 0.3em;
  font-family: inherit;
  font-size: 0.72rem;
  line-height: 1.5;
  text-align: center;
  border-radius: 4px;
  border: 1px solid var(--card-border);
  background: var(--btn-bg);
  color: var(--fg);
}

[data-theme="light"] .ln-help kbd {
  border-color: var(--btn-border);
}
