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

  --cg-cell-bg: rgba(255,255,255,.04);
  --cg-cell-br: rgba(255,255,255,.10);
  --cg-cell-br2: rgba(255,255,255,.16);

  --cg-gridline: rgba(255,255,255,.10);
  --cg-cage: rgba(255,255,255,.78);

  --cg-sel: rgba(120,180,255,.22);
  --cg-sel-br: rgba(120,180,255,.42);

  --cg-dup-bg: rgba(255,60,60,.10);
  --cg-dup-br: rgba(255,60,60,.30);

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

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

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

  /* driven by JS */
  --n: 4;
  --cell: 54px;
  --gap: 2px;
}

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

  --cg-cell-bg: rgba(255,255,255,.92);
  --cg-cell-br: rgba(11,15,20,.12);
  --cg-cell-br2: rgba(11,15,20,.16);

  --cg-gridline: rgba(11,15,20,.12);
  --cg-cage: rgba(11,15,20,.82);

  --cg-sel: rgba(0,120,255,.16);
  --cg-sel-br: rgba(0,120,255,.34);

  --cg-dup-bg: rgba(255,60,60,.16);
  --cg-dup-br: rgba(255,60,60,.34);

  --cg-sat-bg: rgba(0,160,90,.18);
  --cg-sat-br: rgba(0,160,90,.42);

  --cg-bad-bg: rgba(255,60,60,.18);
  --cg-bad-br: rgba(255,60,60,.40);

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

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

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

/* H1 tag */
.cgH1Tag{
  opacity: .72;
  font-weight: 800;
  letter-spacing: .01em;
  margin-left: .35rem;
  font-size: .92em;
}
@media (max-width:420px){
  .cgH1Tag{ display:none; }
}

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

  width:100%;
  max-width:none;
  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);
}
: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; }
}

.cgTopRow{
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  gap:10px;
  margin-bottom: 10px;
}

.cgMeta{ display:flex; flex-direction:column; gap:6px; }
.cgModeLine{ font-size: 13px; opacity: .92; }
.cgRule{ font-size: 12px; opacity: .78; max-width: 60ch; }

.cgStats{
  display:flex;
  gap:10px;
  align-items:flex-end;
}
.cgStat{
  text-align:right;
  display:flex;
  flex-direction:column;
  gap:3px;
  min-width: 86px;
}
.cgStatVal{ font-size: 18px; line-height: 1; }

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

.cgBoardShell{
  width: min(560px, 100%);
  max-width: 100%;
  padding: 10px;
  border-radius: 18px;
  background: var(--cg-bg);
  border: 1px solid var(--cg-br);
  box-shadow: var(--cg-shadow);
}

.cgGrid{
  display:grid;
  grid-template-columns: repeat(var(--n), var(--cell));
  grid-template-rows: repeat(var(--n), var(--cell));
  gap: var(--gap);
  border-radius: 14px;
  padding: var(--gap);
  background: rgba(255,255,255,.02);
  border: 1px solid var(--cg-br);
  overflow:hidden;
  user-select:none;
}
:root[data-theme="light"] .cgGrid{
  background: rgba(11,15,20,.02);
}

.cgCell{
  width: var(--cell);
  height: var(--cell);

  border-radius: 12px;
  background: var(--cg-cell-bg);
  border: 1px solid var(--cg-gridline);

  cursor:pointer;
  padding:0;
  position:relative;

  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;

  display:flex;
  align-items:center;
  justify-content:center;

  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease, box-shadow 140ms ease, opacity 140ms ease;
}
.cgCell:hover{ border-color: var(--cg-cell-br2); }
.cgCell:active{ transform: translateY(0.5px) scale(0.995); }

.cgCell .cgNum{
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-weight: 950;
  font-size: clamp(16px, calc(var(--cell) * 0.34), 26px);
  letter-spacing: .01em;
  opacity: .94;
}

.cgCell .cgLbl{
  position:absolute;
  left: 8px;
  top: 7px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-weight: 900;
  font-size: clamp(10px, calc(var(--cell) * 0.20), 13px);
  letter-spacing: .01em;
  opacity: .82;
  pointer-events:none;
  display:flex;
  gap: 4px;
  align-items:center;
}
.cgCell .cgLbl .op{
  opacity: .92;
}

.cgCell.sel{
  background: color-mix(in oklab, var(--cg-cell-bg), var(--cg-sel) 55%);
  border-color: var(--cg-sel-br);
  box-shadow:
    0 0 0 2px color-mix(in oklab, var(--cg-sel), transparent 55%) inset,
    0 10px 18px rgba(0,0,0,.10);
}

/* duplicates */
.cgCell.dup{
  background: color-mix(in oklab, var(--cg-cell-bg), var(--cg-dup-bg) 70%);
  border-color: var(--cg-dup-br);
  box-shadow: 0 0 0 2px color-mix(in oklab, var(--cg-dup-bg), transparent 55%) inset;
}

/* Cage feedback (soft, premium) */
.cgCell.cgood{
  box-shadow: 0 0 0 2px color-mix(in oklab, var(--cg-sat-bg), transparent 55%) inset;
}
.cgCell.cbad{
  box-shadow: 0 0 0 2px color-mix(in oklab, var(--cg-bad-bg), transparent 55%) inset;
}

/* Cage borders: default thin, add thick on cage edges */
.cgCell.bt{ border-top-width: 3px; border-top-color: var(--cg-cage); }
.cgCell.bb{ border-bottom-width: 3px; border-bottom-color: var(--cg-cage); }
.cgCell.bl{ border-left-width: 3px; border-left-color: var(--cg-cage); }
.cgCell.br{ border-right-width: 3px; border-right-color: var(--cg-cage); }

/* Keypad */
.cgKeypad{
  margin-top: 12px;
  display:flex;
  flex-direction:column;
  gap:10px;
}
.cgKeypadGrid{
  display:grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}
.cgKey{
  padding: 12px 10px;
  border-radius: 14px;
  font-weight: 950;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 16px;
  letter-spacing: .02em;
}
@media (max-width:420px){
  .cgKeypadGrid{ gap: 7px; }
  .cgKey{ padding: 11px 8px; }
}

.cgKeypadActions{
  display:flex;
  gap:8px;
  justify-content:center;
  flex-wrap:wrap;
}

.cgMiniRow{
  margin-top:10px;
  display:flex;
  gap:10px;
  justify-content:space-between;
  align-items:center;
  flex-wrap:wrap;
}

.cgStatsPill{
  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"] .cgStatsPill{
  background: rgba(255,255,255,.92);
  border-color: rgba(11,15,20,.14);
}

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

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

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

.cgHelp{
  padding: 10px 10px 12px;
  max-width: 560px;
}
.cgHelpScroll{
  max-height: 70vh;
  overflow: auto;
  padding-right: 2px;
}
.cgHelpBox{
  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"] .cgHelpBox{
  border-color: rgba(11,15,20,.12);
  background: rgba(11,15,20,.02);
}
.cgHelpKicker{
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  opacity: .78;
  margin-bottom: 6px;
}
.cgHelpList{ margin:0; padding-left: 18px; }
.cgHelpList li{ margin:5px 0; }
.cgHelpActions{
  display:flex;
  gap:10px;
  justify-content:flex-end;
  flex-wrap:wrap;
  margin-top: 8px;
}

.cgWinActions{
  display:flex;
  gap:10px;
  justify-content:flex-end;
  flex-wrap:wrap;
  margin-top: 12px;
}

.cgPbLine{
  margin-top: 8px;
  font-weight: 900;
  letter-spacing: .01em;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--cg-sat-bg);
  border: 1px solid var(--cg-sat-br);
}

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

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

/* SEO card polish (similar to your Nonogram tweaks) */
.cgSeoCard .learnGrid{ gap: 14px; }
@media (min-width: 720px){
  .cgSeoCard .learnGrid{ gap: 16px; }
}
.cgSeoCard .agTipsGrid{ display:grid; gap: 12px; }
@media (min-width: 720px){
  .cgSeoCard .agTipsGrid{ gap: 14px; }
}
.cgSeoCard .agTipCard{
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.03);
}
:root[data-theme="light"] .cgSeoCard .agTipCard{
  border: 1px solid rgba(11,15,20,.10);
  background: rgba(11,15,20,.03);
}
.cgSeoCard .agTipTitle{ margin-bottom: 6px; }
.cgSeoCard .agTipCard p{ margin: 0; line-height: 1.55; }
.cgSeoCard .chips{ gap: 8px; }
.cgSeoCard .chip{ padding: 7px 10px; border-radius: 999px; }


/* ===========================
   MOBILE FIX: mode buttons overlap
   =========================== */
@media (max-width: 560px){
  .cgTopRow{
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .cgMeta{ width: 100%; }

  /* keep the 3 mode buttons usable */
  .cgCard .modeSeg{
    width: 100%;
  }
  .cgCard .modeSeg .seg{
    padding: 10px 8px;
    font-size: 13px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* stats becomes a full-width row under the mode pills */
  .cgStats{
    width: 100%;
    justify-content: space-between;
  }
  .cgStat{
    min-width: 0;
    text-align: center;
  }
  .cgStatVal{
    font-size: 16px;
  }
}

@media (max-width: 360px){
  .cgCard .modeSeg .seg{
    padding: 9px 6px;
    font-size: 12.5px;
  }
}
