/* Sudoku Solver (HoDoKu Dashboard)
   UI fixes requested:
   1) Board stays square immediately.
   2) User-entered vs solver-filled digits look different.
   3) SE marker is clearly visible (line + badge).
   4) Step Solver shows only the current step (with highlight).
   5) Solve Full steps render in grouped, collapsible sections.
*/

:root{
  --ss-bg: #f6f7fb;
  --ss-card: #ffffff;
  --ss-text: #0b1220;
  --ss-muted: rgba(11,18,32,0.62);
  --ss-border: rgba(11,18,32,0.12);
  --ss-shadow: 0 10px 30px rgba(11,18,32,0.10);
  --ss-blue: #2563eb;
  --ss-green: #16a34a;
  --ss-user: #0b3d91;
  --ss-solver: #0b1220;
  /* Step highlight (light green) */
  --ss-highlight: rgba(34,197,94,0.22);
  --ss-band-row: rgba(37,99,235,0.05);
  --ss-band-col: rgba(14,165,233,0.05);
}

/* Layout */
.ss-wrapper{
  display:grid;
  /* Keep the right panel close to the board (avoid huge dead space on wide screens) */
  grid-template-columns: clamp(280px, 60vw, 560px) minmax(320px, 420px);
  gap: 16px;
  align-items:start;
}

@media (max-width: 980px){
  .ss-wrapper{ grid-template-columns: 1fr; }
}

/* Board: keep perfect square */
.ss-board-wrapper{
  position: relative;
  width: 100%;
  max-width: none; /* column clamp above controls the size */
  background: var(--ss-card);
  border: 1px solid var(--ss-border);
  border-radius: 10px;
  box-shadow: var(--ss-shadow);
  padding: 14px; /* uniform outer padding */
  box-sizing: border-box;
  aspect-ratio: 1 / 1;
}

/* Inner wrapper so we can place an SVG overlay on top of the board */
.ss-board-inner{
  position: relative;
  width: 100%;
  height: 100%;
}

/* SVG overlay used for arrows/links (Layer 2) */
.ss-vis{
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#ss-board{
  width: 100%;
  height: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}

/*
  IMPORTANT: Tables don't reliably distribute row heights when empty.
  We force square cells using a pseudo-element + absolutely-centered value span.
  This keeps the grid perfectly even on initial page load.
*/

/* Cells */
#ss-board td.ss-cell{
  border: 1px solid rgba(11,18,32,0.14);
  text-align: center;
  vertical-align: middle;
  font-size: clamp(16px, 2.2vw, 26px);
  font-weight: 700;
  color: var(--ss-text);
  user-select: none;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  position: relative;
  overflow: hidden;
}

/* Square cell box */
#ss-board td.ss-cell::before{
  content: "";
  display: block;
  padding-top: 100%;
}

/* Centered value overlay */
#ss-board td.ss-cell .ss-val{
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10 !important; /* Always above pencil notes (force across themes/browsers) */
  pointer-events: none;
}

/* Auto Pencil Notes (candidates) */
#ss-board td.ss-cell .ss-notes{
  position: absolute;
  inset: 6px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  align-items: center;
  justify-items: center;
  font-size: clamp(7px, 0.95vw, 11px);
  /* Default notes should be light/neutral.
     Only the *matching* note (same as the active digit) becomes bold. */
  /* Cells are bold by default; force notes back to regular weight */
  font-weight: 400 !important;
  color: rgba(11,18,32,0.60);
  pointer-events: none;
  z-index: 1 !important; /* Always below confirmed value */
}
#ss-board td.ss-cell .ss-notes span{
  opacity: 0.10;
  transform: scale(0.98);
  font-weight: 400 !important;
}
#ss-board td.ss-cell .ss-notes span.on{
  /* Keep valid candidates visible but subtle. The *matching* candidate
     (same as the selected cell's value) will be bold/darker via .match.on. */
  opacity: 0.18;
  font-weight: 400 !important;
}

/* Emphasize the currently "active" digit inside pencil notes so it stands out */
#ss-board td.ss-cell .ss-notes span.match{
  /* Bold the matching digit even if it's currently 'off' (faded). */
  font-weight: 800 !important;
}

#ss-board td.ss-cell .ss-notes span.match.on{
  opacity: 1 !important;
  font-weight: 800 !important;
  transform: scale(1.12);
  color: rgba(11,18,32,0.92) !important;
}
#ss-board td.ss-cell.ss-filled .ss-notes{
  display: none !important;
}

/* While the user is clicking/typing in a cell, hide notes entirely.
   Notes will reappear when the cell loses focus AND remains empty. */
#ss-board td.ss-cell.ss-editing .ss-notes{
  display: none !important;
}

/* Extra safety: if any theme/plugin adds a stacking context, keep the value above notes */
#ss-board td.ss-cell{ isolation: isolate; }

/* Thicker 3x3 borders */
#ss-board tr:nth-child(3) td,
#ss-board tr:nth-child(6) td{
  border-bottom-width: 2px;
  border-bottom-color: rgba(11,18,32,0.32);
}
#ss-board td:nth-child(3),
#ss-board td:nth-child(6){
  border-right-width: 2px;
  border-right-color: rgba(11,18,32,0.32);
}

#ss-board td.ss-selected{
  outline: 2px solid rgba(37,99,235,0.65);
  outline-offset: -2px;
  background: rgba(37,99,235,0.06);
}

/* User vs Solver */
#ss-board td.ss-user{
  color: var(--ss-user);
}
#ss-board td.ss-solver{
  color: var(--ss-solver);
  font-weight: 800;
}

/* Step highlight */
#ss-board td.ss-hl{
  background: var(--ss-highlight);
  box-shadow: inset 0 0 0 2px rgba(34,197,94,0.65);
}

/* ------------------------------------------------------------------
   Technique visualisation (Layers 1–2)
   - Focus cells: soft blue
   - Support cells: faint blue outline
   - Elimination cells: faint red
   - Result cell: soft green
-------------------------------------------------------------------*/

#ss-board td.ss-focus{
  background: rgba(37,99,235,0.10);
}

#ss-board td.ss-support{
  box-shadow: inset 0 0 0 2px rgba(37,99,235,0.25);
}

#ss-board td.ss-elim{
  background: rgba(220,38,38,0.08);
  box-shadow: inset 0 0 0 2px rgba(220,38,38,0.25);
}

/* Make eliminations obvious even without candidate digits */
#ss-board td.ss-elim::after{
  content: "✕";
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 14px;
  line-height: 1;
  color: rgba(220,38,38,0.75);
  font-weight: 900;
}

#ss-board td.ss-result{
  background: rgba(34,197,94,0.18);
  box-shadow: inset 0 0 0 2px rgba(34,197,94,0.55);
}

/* Arrow styling inside the SVG overlay */
.ss-vis path.ss-arrow{
  /* Semi-transparent so arrows don't obscure digits */
  stroke: rgba(37,99,235,0.45);
  opacity: 0.75;
  stroke-width: 6;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ss-vis path.ss-arrow.ss-arrow-dashed{
  stroke-dasharray: 10 10;
}
.ss-vis circle.ss-node{
  fill: rgba(37,99,235,0.18);
  stroke: rgba(37,99,235,0.55);
  stroke-width: 4;
}

/* Layer 1: focus/support/elimination shading */
#ss-board td.ss-focus{ background: rgba(37,99,235,0.10); }
#ss-board td.ss-support{ background: rgba(37,99,235,0.06); }
#ss-board td.ss-elim{ background: rgba(239,68,68,0.08); box-shadow: inset 0 0 0 2px rgba(239,68,68,0.35); }
#ss-board td.ss-result{ background: rgba(34,197,94,0.18); box-shadow: inset 0 0 0 2px rgba(34,197,94,0.75); }

/* Fish bands: faint row/column shading so patterns pop */
#ss-board td.ss-band-row{ background: var(--ss-band-row); }
#ss-board td.ss-band-col{ background: var(--ss-band-col); }
/* Box band used for locked candidates / box-based logic */
#ss-board td.ss-band-box{ background: rgba(245,158,11,0.06); }

/* Chain alternation (helps users “see” the flip-flop logic) */
#ss-board td.ss-chain-a{ box-shadow: inset 0 0 0 2px rgba(37,99,235,0.45); }
#ss-board td.ss-chain-b{ box-shadow: inset 0 0 0 2px rgba(147,51,234,0.40); }

/* Singles helper: show the already-placed same digit + their houses in a dull red
   so the user can visually connect “why this cell is forced”. */
#ss-board td.ss-constraint:not(.ss-result):not(.ss-focus){
  background: rgba(220,38,38,0.05);
}
#ss-board td.ss-same-digit{
  background: rgba(220,38,38,0.12);
  box-shadow: inset 0 0 0 2px rgba(220,38,38,0.35);
}

/* Animations: subtle pulse on eliminations and a quick flash on result */
@keyframes ssPulse{
  0%{ box-shadow: inset 0 0 0 2px rgba(239,68,68,0.20); }
  50%{ box-shadow: inset 0 0 0 3px rgba(239,68,68,0.55); }
  100%{ box-shadow: inset 0 0 0 2px rgba(239,68,68,0.35); }
}
#ss-board td.ss-elim-pulse{ animation: ssPulse 800ms ease-in-out 1; }

@keyframes ssFlash{
  0%{ background: rgba(34,197,94,0.26); }
  100%{ background: rgba(34,197,94,0.18); }
}
#ss-board td.ss-step-flash{ animation: ssFlash 650ms ease-out 1; }

/* Layer 4: technical details (optional) */
.ss-tech-details{
  margin-top: 10px;
  border-top: 1px solid var(--ss-border);
  padding-top: 10px;
}

.ss-tech-details details{ background: rgba(11,18,32,0.03); border: 1px solid var(--ss-border); border-radius: 10px; padding: 8px 10px; }
.ss-tech-details summary{ cursor: pointer; font-weight: 800; color: var(--ss-text); }
.ss-tech-details .ss-tech-raw{ margin-top: 6px; color: var(--ss-muted); font-size: 12px; line-height: 1.35; word-break: break-word; }

/* Side panel */
.ss-side{
  background: transparent;
  width: 100%;
  display:flex;
  flex-direction:column;
  align-items:stretch;
  /* height is synced to the board via JS so the right column matches board height */
  min-height: 0;
}

.ss-toolbar{
  display:flex;
  gap: 14px;
  justify-content:center;
  margin-bottom: 10px;
  width: 100%;
}

.ss-tool{ text-align:center; font-size: 12px; color: var(--ss-muted); }

.ss-circle{
  width: 50px;
  height: 50px;
  border-radius: 999px;
  border: 1px solid rgba(11,18,32,0.14);
  background: #f2f4f8;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  font-size: 18px;
}

.ss-keypad{
  display:grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 10px 0 12px;
  width: 100%;
}

.ss-key{
  height: 54px;
  border-radius: 10px;
  border: 1px solid rgba(11,18,32,0.14);
  background: #eef2ff;
  font-weight: 800;
  font-size: 22px;
  cursor:pointer;
  color: #1f2937; /* dark grey digits */
}

.ss-solve-modes{
  display:grid;
  gap: 10px;
}

.ss-solve{
  height: 48px;
  border-radius: 10px;
  border: none;
  color: #fff;
  font-weight: 800;
  cursor:pointer;
}

.ss-solve-full{ background: #22c55e; }
.ss-solve-step{ background: #2563eb; }

.ss-solve:disabled{
  opacity: 0.55;
  cursor: not-allowed;
}

.ss-outcome{
  margin-top: 12px;
  background: var(--ss-card);
  border: 1px solid var(--ss-border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--ss-muted);
  box-shadow: var(--ss-shadow);
  width: 100%;
}

/* Human explanation card (fills remaining right-column height in Step mode) */
.ss-human{
  margin-top: 12px;
  background: var(--ss-card);
  border: 1px solid var(--ss-border);
  border-radius: 10px;
  box-shadow: var(--ss-shadow);
  padding: 12px;
  width: 100%;
  flex: 1 1 auto;
  min-height: 120px;
  overflow: auto;
  box-sizing: border-box;
}

.ss-human-head{
  font-weight: 900;
  color: var(--ss-text);
  margin-bottom: 6px;
}

.ss-human-text{
  color: var(--ss-muted);
  font-size: 13px;
  line-height: 1.35;
}

.ss-human .ss-human-what{
  font-weight: 900;
  color: var(--ss-text);
  margin: 8px 0 4px;
}

.ss-human details{
  margin-top: 10px;
  border: 1px solid rgba(11,18,32,0.10);
  border-radius: 10px;
  background: rgba(11,18,32,0.02);
  padding: 8px 10px;
}

.ss-human details summary{
  cursor: pointer;
  font-weight: 800;
  color: var(--ss-text);
}

.ss-human .ss-tech-raw{
  margin-top: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  line-height: 1.35;
  color: rgba(11,18,32,0.75);
  white-space: pre-wrap;
  word-break: break-word;
}

.ss-human.is-empty .ss-human-text{
  opacity: 0.75;
}

/* Dashboard */
.ss-dashboard{
  margin-top: 18px;
  background: var(--ss-bg);
  border-radius: 12px;
  padding: 14px;
}

.ss-dash-header{
  background: var(--ss-card);
  border: 1px solid var(--ss-border);
  border-radius: 12px;
  box-shadow: var(--ss-shadow);
  padding: 12px;
  display:flex;
  gap: 14px;
  align-items:center;
  justify-content:space-between;
  flex-wrap:wrap;
}

.ss-dash-status{
  font-size: 16px;
  font-weight: 900;
  color: var(--ss-text);
}

.ss-dash-meta{ display:flex; gap: 8px; flex-wrap:wrap; margin-top: 6px; }

.ss-pill{
  display:inline-flex;
  align-items:center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(37,99,235,0.18);
  background: rgba(37,99,235,0.06);
  color: var(--ss-text);
  font-size: 12px;
  font-weight: 800;
}

/* SE bar */
.ss-sebar{
  min-width: 320px;
  max-width: 520px;
  width: 100%;
}

.ss-sebar-track{
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(37,99,235,0.25), rgba(34,197,94,0.22), rgba(239,68,68,0.18));
  border: 1px solid rgba(11,18,32,0.12);
}

.ss-sebar-fill{
  height: 100%;
  border-radius: 999px;
  background: rgba(37,99,235,0.25);
}

.ss-sebar-marker{
  position:absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 3px;
  height: 18px;
  background: rgba(11,18,32,0.75);
  border-radius: 3px;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.9), 0 2px 8px rgba(0,0,0,0.12);
}

.ss-sebar-badge{
  position:absolute;
  top: -28px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(11,18,32,0.92);
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  padding: 4px 6px;
  border-radius: 8px;
  white-space: nowrap;
}

.ss-sebar-labels{
  display:flex;
  justify-content:space-between;
  margin-top: 6px;
  font-size: 11px;
  color: var(--ss-muted);
}

/* Cards */
.ss-dash-grid{
  display:grid;
  grid-template-columns: 1fr 360px;
  gap: 14px;
  margin-top: 14px;
}

@media (max-width: 980px){
  .ss-dash-grid{ grid-template-columns: 1fr; }
}

.ss-card{
  background: var(--ss-card);
  border: 1px solid var(--ss-border);
  border-radius: 12px;
  box-shadow: var(--ss-shadow);
  padding: 12px;
}

.ss-card-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.ss-card-title{
  font-size: 14px;
  font-weight: 900;
  color: var(--ss-text);
}

.ss-card-actions{ display:flex; gap: 8px; }

.ss-mini{
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  border: none;
  background: var(--ss-blue);
  color: #fff;
  font-weight: 900;
  cursor:pointer;
  font-size: 12px;
}

.ss-mini:disabled{ opacity: 0.45; cursor:not-allowed; }

.ss-mini-ghost{
  background: rgba(11,18,32,0.06);
  color: var(--ss-text);
  border: 1px solid rgba(11,18,32,0.12);
}

/* Step panel */
.ss-step{
  border: 1px solid rgba(11,18,32,0.10);
  border-radius: 10px;
  padding: 12px;
  background: #f8fafc;
}

.ss-step-tech{
  font-weight: 950;
  font-size: 16px;
  color: var(--ss-text);
  margin-bottom: 6px;
}

.ss-step-desc,
.ss-step-conc{
  font-size: 12px;
  color: var(--ss-muted);
}

/* Full move list (grouped) */
.ss-moves{
  margin-top: 10px;
}

.ss-moves details{
  border: 1px solid rgba(11,18,32,0.10);
  border-radius: 10px;
  background: #fff;
  margin-bottom: 10px;
  overflow:hidden;
}

.ss-moves summary{
  cursor:pointer;
  list-style: none;
  padding: 10px 12px;
  font-weight: 900;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 8px;
}

.ss-moves summary::-webkit-details-marker{ display:none; }

.ss-moves .ss-count{
  font-size: 12px;
  font-weight: 900;
  background: rgba(37,99,235,0.10);
  border: 1px solid rgba(37,99,235,0.18);
  color: var(--ss-text);
  padding: 3px 8px;
  border-radius: 999px;
}

.ss-moves ol{
  margin: 0;
  padding: 0 12px 12px 34px;
  /* Show ~5 rows, then scroll */
  max-height: 170px;
  overflow:auto;
}

.ss-moves li{
  padding: 6px 0;
  font-size: 12px;
  color: var(--ss-text);
}

/* Techniques cards */
.ss-tech-cards{
  display:flex;
  flex-direction:column;
  gap: 8px;
}

.ss-tech-card{
  border: 1px solid rgba(11,18,32,0.10);
  border-radius: 12px;
  padding: 10px 12px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  background: #fff;
}

.ss-tech-name{ font-weight: 900; font-size: 12px; color: var(--ss-text); }

.ss-tech-num{
  min-width: 30px;
  text-align:center;
  font-weight: 950;
  border-radius: 10px;
  padding: 4px 8px;
  background: rgba(37,99,235,0.10);
  border: 1px solid rgba(37,99,235,0.18);
  color: var(--ss-text);
}

/* -------------------------------------------------------------------------
   Solver overlay (covers ONLY the puzzle board while solving / retrying)
   ------------------------------------------------------------------------- */
.ss-board-wrapper{ position: relative; }

.ss-solver-overlay{
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 10, 14, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 999;
}

.ss-solver-overlay-card{
  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 16px;
  padding: 18px 22px;
  min-width: 240px;
  max-width: 92%;
  box-shadow: 0 16px 50px rgba(0,0,0,0.35);
  text-align: center;
}

.ss-solver-overlay-title{
  font-weight: 700;
  font-size: 16px;
  line-height: 1.3;
  margin-bottom: 14px;
  color: rgba(20,20,28,0.95);
}

.ss-solver-spinner{
  width: 34px;
  height: 34px;
  margin: 0 auto;
  border-radius: 999px;
  border: 3px solid rgba(0,0,0,0.18);
  border-top-color: rgba(0,0,0,0.72);
  animation: ssSpin 0.9s linear infinite;
}

@keyframes ssSpin{
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce){
  .ss-solver-spinner{ animation: none; }
}




/* ✅ Make sure the overlay actually disappears when JS sets hidden=true */
.ss-solver-overlay[hidden]{
  display: none !important;
}
