:root{
  --lg-bg: rgba(255,255,255,.02);
  --lg-br: rgba(255,255,255,.08);
  --lg-br2: rgba(255,255,255,.14);

  --lg-cell-bg: rgba(255,255,255,.04);
  --lg-cell-br: rgba(255,255,255,.10);

  --lg-sat-bg: rgba(0,255,140,.10);
  --lg-sat-br: rgba(0,255,140,.24);

  --lg-bad-bg: rgba(255,60,60,.10);
  --lg-bad-br: rgba(255,60,60,.28);

  --lg-line: rgba(255,255,255,.92);
  --lg-x: rgba(255,255,255,.38);
  --lg-dot: rgba(255,255,255,.55);

  --lg-shadow: 0 10px 24px rgba(0,0,0,.22);

  /* Layout driven by JS */
  --u: 22px;                 /* unit tile size */
  --n: 5;
}

:root[data-theme="light"]{
  --lg-bg: rgba(11,15,20,.02);
  --lg-br: rgba(11,15,20,.10);
  --lg-br2: rgba(11,15,20,.16);

  --lg-cell-bg: rgba(255,255,255,.86);
  --lg-cell-br: rgba(11,15,20,.12);

  --lg-sat-bg: rgba(0,160,90,.10);
  --lg-sat-br: rgba(0,160,90,.22);

  --lg-bad-bg: rgba(255,60,60,.10);
  --lg-bad-br: rgba(255,60,60,.22);

  --lg-line: rgba(11,15,20,.92);
  --lg-x: rgba(11,15,20,.35);
  --lg-dot: rgba(11,15,20,.45);

  --lg-shadow: 0 10px 22px rgba(0,0,0,.10);
}

header.wrap { padding-bottom: 6px; }
main.wrap { padding-top: 6px; }

/* ---- no-wrap top bar safeguards ---- */
.top{
  flex-wrap: nowrap !important;
  gap: 10px;
}
.brandH1{ min-width: 0; }
.brandlink{
  min-width: 0;
  display:flex;
  align-items:center;
  gap: 10px;
  overflow:hidden;
}
.brandName{
  white-space: nowrap;
  overflow:hidden;
  text-overflow: ellipsis;
}
.nav{
  flex-wrap: nowrap !important;
  gap: 8px;
  flex-shrink: 0;
}
.pillbtn{ white-space: nowrap; }

/* H1 tag (hide on small to prevent wrap) */
.ngH1Tag{
  opacity: .72;
  font-weight: 800;
  letter-spacing: .01em;
  margin-left: .35rem;
  font-size: .92em;
  white-space: nowrap;
}
@media (max-width:420px){
  .ngH1Tag{ display:none; }
}

/* Premium tagline pill */
.sub{
  display:flex;
  flex-wrap:wrap;
  justify-content:center;
  align-items:center;
  gap: .45rem;

  width:100%;
  box-sizing:border-box;

  text-align:center;
  margin: 8px 0 0;
  padding: .5rem .75rem;

  font-size: .92rem;
  line-height: 1.15;
  border-radius: 999px;
  letter-spacing: .01em;

  background: rgba(0,0,0,.04);
  border: 1px solid rgba(0,0,0,.06);
  text-wrap: normal;
}
:root[data-theme="dark"] .sub{
  background: rgba(255,255,255,.06);
  border-color: rgba(255,255,255,.10);
}
@media (max-width:520px){
  .sub{ font-size: .86rem; }
}

.card.lgCard{ padding: 10px 10px 12px; }
@media (max-width:520px){
  .wrap { padding-left: 10px; padding-right: 10px; }
  .card.lgCard { padding: 8px 8px 10px; }
}

.lgTopRow{
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  gap:10px;
  margin-bottom: 10px;
}
.lgMeta{ display:flex; flex-direction:column; gap:6px; }
.lgModeLine{ font-size: 13px; opacity: .9; }
.lgRule{ font-size: 12px; opacity: .78; max-width: 60ch; }

.lgStats{
  display:flex;
  gap:10px;
  align-items:flex-end;
}
.lgStat{
  text-align:right;
  display:flex;
  flex-direction:column;
  gap:3px;
  min-width: 78px;
}
.lgStatVal{ font-size: 18px; line-height: 1; }

/* Mode pills always 1 row */
.lgCard .modeSeg{
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  width: 100%;
}
.lgCard .modeSeg .seg{
  width:100%;
  min-width:0;
  white-space:nowrap;
  padding: 10px 10px;
  font-size: 13px;
}
@media (max-width: 360px){
  .lgCard .modeSeg{ gap:5px; }
  .lgCard .modeSeg .seg{ padding: 9px 8px; font-size: 12.5px; }
}

/* Board wrap */
.lgBoardWrap{
  display:flex;
  justify-content:center;
  padding-top: 2px;
  overflow-x: hidden;
}

.lgBoardShell{
  width: min(560px, 100%);
  max-width: 100%;
  padding: 10px;
  border-radius: 18px;
  background: var(--lg-bg);
  border: 1px solid var(--lg-br);
  box-shadow: var(--lg-shadow);
  overflow:hidden;
}
@media (max-width: 420px){
  .lgBoardShell{ padding: 8px; }
}

/* Grid */
.lgBoard{
  display:grid;
  grid-template-columns: repeat(calc(var(--n) * 2 + 1), var(--u));
  grid-template-rows: repeat(calc(var(--n) * 2 + 1), var(--u));
  gap: 0;
  user-select:none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  border-radius: 14px;
  background: rgba(255,255,255,.02);
  border: 1px solid var(--lg-br);
  overflow:hidden;
}
:root[data-theme="light"] .lgBoard{
  background: rgba(11,15,20,.02);
}

/* Tiles */
.lgTile{
  width: var(--u);
  height: var(--u);
  box-sizing:border-box;
  display:flex;
  align-items:center;
  justify-content:center;
}

.lgVtx{
  position:relative;
}
.lgVtx::after{
  content:"";
  width: clamp(4px, calc(var(--u) * 0.18), 8px);
  height: clamp(4px, calc(var(--u) * 0.18), 8px);
  border-radius: 999px;
  background: var(--lg-dot);
  opacity: .9;
  box-shadow: 0 6px 14px rgba(0,0,0,.14);
}
.lgVtx.bad::after{
  background: rgba(255,60,60,.95);
  box-shadow: 0 0 0 4px rgba(255,60,60,.16);
}
:root[data-theme="light"] .lgVtx.bad::after{
  box-shadow: 0 0 0 4px rgba(255,60,60,.12);
}

/* Edges as premium touch targets */
.lgEdge{
  border: 0;
  background: transparent;
  cursor:pointer;
  padding:0;
  width: var(--u);
  height: var(--u);
  position:relative;
  border-radius: 10px;
  transition: transform 140ms ease, background 140ms ease, box-shadow 140ms ease, opacity 140ms ease;
  touch-action: none; /* enables drag reliably */
}
.lgEdge:hover{
  background: rgba(255,255,255,.03);
}
:root[data-theme="light"] .lgEdge:hover{
  background: rgba(11,15,20,.03);
}
.lgEdge:active{ transform: translateY(0.5px) scale(0.995); }

.lgEdge.h::before,
.lgEdge.v::before{
  content:"";
  position:absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%);
  border-radius: 999px;
  opacity: .0;
  background: var(--lg-line);
  box-shadow: 0 8px 18px rgba(0,0,0,.18);
}
.lgEdge.h::before{
  width: calc(var(--u) * 0.90);
  height: clamp(4px, calc(var(--u) * 0.22), 8px);
}
.lgEdge.v::before{
  height: calc(var(--u) * 0.90);
  width: clamp(4px, calc(var(--u) * 0.22), 8px);
}

.lgEdge.on::before{ opacity: 1; }

.lgEdge.x::after{
  content:"";
  position:absolute;
  inset: clamp(4px, calc(var(--u) * 0.22), 7px);
  background:
    linear-gradient(45deg, transparent 46%, var(--lg-x) 47%, var(--lg-x) 53%, transparent 54%),
    linear-gradient(-45deg, transparent 46%, var(--lg-x) 47%, var(--lg-x) 53%, transparent 54%);
  border-radius: 8px;
  opacity: .95;
}

/* Number cells */
.lgCell{
  border-radius: 12px;
  background: var(--lg-cell-bg);
  border: 1px solid var(--lg-cell-br);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.02);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-weight: 900;
  font-size: clamp(11px, calc(var(--u) * 0.46), 18px);
  line-height: 1;
  opacity: .95;
}

.lgCell.blank{
  opacity: .40;
  font-weight: 800;
}
.lgCell.sat{
  background: var(--lg-sat-bg);
  border-color: var(--lg-sat-br);
  box-shadow: 0 0 0 3px rgba(0,255,140,.10) inset;
}
:root[data-theme="light"] .lgCell.sat{
  box-shadow: 0 0 0 3px rgba(0,160,90,.10) inset;
}

.lgCell.bad{
  background: var(--lg-bad-bg);
  border-color: var(--lg-bad-br);
}
.lgCell.bad.flash{
  animation: lgFlash 240ms ease-out 1;
}
@keyframes lgFlash{
  0%{ transform: scale(1); }
  35%{ transform: scale(1.02); }
  100%{ transform: scale(1); }
}

/* Bars */
.lgBar{
  margin-top: 12px;
  display:flex;
  gap:8px;
  justify-content:center;
  flex-wrap:wrap;
}
.lgMiniRow{
  margin-top:10px;
  display:flex;
  gap:10px;
  justify-content:space-between;
  align-items:center;
  flex-wrap:wrap;
}
.lgStatsPill{
  display:inline-flex;
  align-items:center;
  gap:.35rem;
  padding: 10px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.10);
  font-size: 13px;
  box-shadow: 0 10px 22px rgba(0,0,0,.10);
}
:root[data-theme="light"] .lgStatsPill{
  background: rgba(255,255,255,.86);
  border-color: rgba(11,15,20,.14);
}

/* More */
.lgMoreWrap{
  margin-top: 12px;
  display:flex;
  justify-content:center;
}
.lgMoreBtn{
  text-decoration:none;
  padding: 12px 16px;
  border-radius: 16px;
  box-shadow: 0 10px 22px rgba(0,0,0,.10);
  animation: lgMorePulse 2.8s ease-in-out infinite;
}
@keyframes lgMorePulse{
  0%,100%{ transform: translateY(0); }
  50%{ transform: translateY(-1px); }
}

/* Msg */
.msg{
  display:none;
  margin: 8px auto 0;
  text-align:center;
  font-weight: 900;
  letter-spacing:.01em;
}

/* Dialogs */
.lgHelpDlg,
.lgWinDlg,
.lgShareDlg{
  padding: 0;
  border: 0;
  background: transparent;
  width: fit-content;
  max-width: calc(100vw - 24px);
  margin: auto;
}
.lgHelpDlg::backdrop,
.lgWinDlg::backdrop,
.lgShareDlg::backdrop{ background: rgba(0,0,0,.55); }
:root[data-theme="light"] .lgHelpDlg::backdrop,
:root[data-theme="light"] .lgWinDlg::backdrop,
:root[data-theme="light"] .lgShareDlg::backdrop{ background: rgba(0,0,0,.35); }

.lgHelp{
  padding: 10px 10px 12px;
  max-width: 560px;
}
.lgHelpScroll{
  max-height: 70vh;
  overflow: auto;
  padding-right: 2px;
}
.lgHelpBox{
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.02);
  border-radius: 12px;
  padding: 9px 10px;
  margin: 8px 0;
}
:root[data-theme="light"] .lgHelpBox{
  border-color: rgba(11,15,20,.12);
  background: rgba(11,15,20,.02);
}
.lgHelpKicker{
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  opacity: .78;
  margin-bottom: 6px;
}
.lgHelpList{ margin:0; padding-left: 18px; }
.lgHelpList li{ margin:5px 0; }
.lgHelpActions{
  display:flex;
  gap:10px;
  justify-content:flex-end;
  flex-wrap:wrap;
  margin-top: 8px;
}

.lgWinActions{
  display:flex;
  gap:10px;
  justify-content:flex-end;
  flex-wrap:wrap;
  margin-top: 12px;
}
.lgPbLine{
  margin-top: 8px;
  font-weight: 900;
  letter-spacing: .01em;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--lg-sat-bg);
  border: 1px solid var(--lg-sat-br);
}

/* Light mode: selected seg pop */
:root[data-theme="light"] .seg.on{
  box-shadow: 0 0 0 3px rgba(0,120,255,.18) inset;
}

@media (prefers-reduced-motion: reduce){
  .lgEdge{ transition:none !important; }
  .lgMoreBtn{ animation:none !important; }
}

.lgBoardWrap{
  display:flex;
  justify-content:stretch;   /* was center */
  padding-top: 2px;
  overflow-x: hidden;
}

.lgBoardShell{
  width: 100%;               /* was min(560px, 100%) */
  max-width: none;           /* remove the 560 cap */
  padding: 10px;
  border-radius: 18px;
  background: var(--lg-bg);
  border: 1px solid var(--lg-br);
  box-shadow: var(--lg-shadow);
  overflow:hidden;
}
