/* Sudoku — Cozy Alpaca Studio · Slice 6.1 fuller stats menu */
:root {
  --cream: #f7f1e8;
  --ink: #3d3429;
  --soft: #8b7355;
  --accent: #c4785a;
  --panel: #fffaf3;
  --shadow: rgba(61, 52, 41, 0.15);
  --cell-a: #fffaf3;
  --cell-b: #f3ebe0;
  --given: #3d3429;
  --entry: #5a7a62;
  --select: rgba(196, 120, 90, 0.28);
  --conflict: #e8a0a0;
  --conflict-ink: #8b3a3a;
  --box-line: #3d3429;
  --grid-line: #c4b5a0;
  --win: #6b9b76;
  --note: #8b7355;
  --check-error: #d94a4a;
  --check-error-bg: #f5c4c4;
  --check-ok: #3f6b48;
  --check-ok-bg: #c8e0cc;
  --gem: #5b7fbf;
  --hint-o: rgba(63, 107, 72, 0.38);
  --dev-gem: #7a6a9a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  flex-direction: column;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(160deg, #f0e6d6 0%, #e4d5c0 50%, #d9cbb8 100%);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  justify-content: flex-start;
  align-items: stretch;
  padding: 0 0 2rem;
}

.app { width: 100%; max-width: 520px; align-self: center; margin-top: 1.25rem; padding: 0 1rem; }

.header { text-align: center; margin-bottom: 0.85rem; position: relative; }
.studio-mark {
  display: block;
  width: 3.15rem;
  height: auto;
  margin: 0 auto 0.15rem;
  filter: drop-shadow(0 2px 4px var(--shadow));
  pointer-events: none;
  user-select: none;
}
.header h1 {
  font-weight: 600;
  font-size: 1.75rem;
  letter-spacing: 0.02em;
}
.tagline { font-size: 0.85rem; color: var(--soft); margin-top: 0.15rem; }

.mute-btn {
  position: absolute;
  top: 0;
  right: 0;
  appearance: none;
  border: none;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 2px 6px var(--shadow);
  z-index: 2;
  min-width: 3.6rem;
}
.mute-btn:hover { filter: brightness(1.03); }
.mute-btn.is-muted {
  background: #e8dcc8;
  color: var(--soft);
  box-shadow: inset 0 0 0 1px rgba(61, 52, 41, 0.12);
}

.panel {
  background: var(--panel);
  border-radius: 12px;
  padding: 0.85rem 0.95rem;
  margin-bottom: 0.85rem;
  box-shadow: 0 2px 8px var(--shadow);
}

.diff-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.7rem;
}
.diff-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--soft);
}
.diff-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.65rem;
}

.timer {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-size: 1rem;
  font-weight: 600;
  color: var(--soft);
  min-width: 3.2rem;
  text-align: right;
  padding: 0.2rem 0.35rem;
}

.status {
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.35;
}
.meta {
  font-size: 0.78rem;
  color: var(--soft);
  margin-top: 0.25rem;
}

.btn {
  appearance: none;
  border: none;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 2px 4px var(--shadow);
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }
.btn-secondary {
  background: #e8dcc8;
  color: var(--ink);
}
.diff-btn {
  min-width: 4.6rem;
  background: #e8dcc8;
  color: var(--ink);
}
.diff-btn.is-selected {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 2px rgba(196, 120, 90, 0.35), 0 2px 4px var(--shadow);
}

.gem-hud {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--gem);
  background: #e8eef8;
  padding: 0.3rem 0.65rem;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(91, 127, 191, 0.25);
  font-variant-numeric: tabular-nums;
}
.gem-icon { font-size: 0.75rem; opacity: 0.9; }
.gem-balance { min-width: 1.4rem; text-align: right; }
.gem-label { font-weight: 600; font-size: 0.72rem; color: var(--soft); }

.btn-gem {
  background: var(--gem);
  color: #fff;
}
.btn-gem:disabled,
.btn-gem[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
  transform: none;
}

/* Playtest: visible +gems control (not a secret chord) */
.btn-dev-gems {
  background: var(--dev-gem);
  color: #fff;
  font-size: 0.78rem;
  padding: 0.3rem 0.65rem;
  white-space: nowrap;
}
.btn-dev-gems:hover { filter: brightness(1.06); }

/* Full 9×9 board — thick 3×3 box borders.
   Stage holds the studio alpaca; cells are a paper wash so she ghosts through. */
.board-stage {
  position: relative;
  margin-bottom: 0.85rem;
  border-radius: 10px;
  background: #efe6d8;
  box-shadow: 0 4px 14px var(--shadow);
  overflow: hidden;
}
.board-mark {
  position: absolute;
  left: 50%;
  top: 52%;
  transform: translate(-50%, -50%);
  width: 84%;
  height: 84%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  z-index: 0;
  opacity: 0.92;
  transition: opacity 0.45s ease;
}
.board-stage.is-won .board-mark {
  opacity: 1;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: 100%;
  aspect-ratio: 1 / 1;
  position: relative;
  z-index: 1;
  background: rgba(61, 52, 41, 0.72);
  border: 3px solid var(--box-line);
  border-radius: 10px;
  overflow: hidden;
  gap: 1px;
}

.cell {
  appearance: none;
  border: none;
  margin: 0;
  padding: 0;
  background: rgba(255, 250, 243, 0.58);
  color: var(--entry);
  font: inherit;
  font-size: clamp(1.05rem, 4.2vw, 1.55rem);
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  position: relative;
  min-width: 0;
  min-height: 0;
  outline: none;
}

/* Soft checker within boxes */
.cell.tone-b { background: rgba(243, 235, 224, 0.58); }

.cell.given {
  color: var(--given);
  font-weight: 700;
  cursor: default;
}

/* Hint-verified (green O): same input lock affordance as givens */
.cell.hint-locked {
  cursor: default;
}

.cell.is-selected {
  box-shadow: inset 0 0 0 3px var(--accent);
  background: rgba(236, 210, 192, 0.7);
  z-index: 1;
}

.cell.is-related {
  background-image: linear-gradient(rgba(196, 120, 90, 0.12), rgba(196, 120, 90, 0.12));
}

.cell.is-conflict {
  background: var(--conflict) !important;
  color: var(--conflict-ink);
}

/* Slice 4 Check marks (intentional red/green) */
.cell.is-check-error {
  background: var(--check-error-bg) !important;
  color: var(--check-error) !important;
  box-shadow: inset 0 0 0 3px var(--check-error) !important;
  z-index: 2;
}
.cell.is-check-ok {
  background: var(--check-ok-bg) !important;
  color: var(--check-ok) !important;
  box-shadow: inset 0 0 0 3px rgba(63, 107, 72, 0.65) !important;
  z-index: 1;
}

/* Slice 4.1 — Check-picked error: red X (corner to corner); number stays visible */
.cell-check-x {
  position: absolute;
  inset: 6%;
  pointer-events: none;
  z-index: 3;
  opacity: 0;
}
.cell-check-x.is-visible {
  opacity: 1;
}
.cell-check-x.is-flash {
  animation: check-x-flash 0.85s ease-in-out 1 forwards;
}
@keyframes check-x-flash {
  0%   { opacity: 1; }
  18%  { opacity: 0.12; }
  36%  { opacity: 1; }
  54%  { opacity: 0.12; }
  72%  { opacity: 1; }
  100% { opacity: 1; }
}
.cell-check-x::before,
.cell-check-x::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 128%;
  height: 2.5px;
  background: var(--check-error);
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35);
}
.cell-check-x::before {
  transform: translate(-50%, -50%) rotate(45deg);
}
.cell-check-x::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

/* Slice 4.1 — Hint verified: faint green O, persists until New Puzzle */
.cell-hint-o {
  position: absolute;
  inset: 14%;
  border: 2px solid var(--hint-o);
  border-radius: 50%;
  pointer-events: none;
  z-index: 3;
  box-sizing: border-box;
  opacity: 0;
}
.cell-hint-o.is-visible {
  opacity: 1;
}

.cell.is-same-digit:not(.is-selected) {
  box-shadow: inset 0 0 0 2px rgba(90, 122, 98, 0.45);
}

/* Thick borders between 3×3 boxes (in addition to 1px gap grid) */
.cell.box-right {
  box-shadow: inset -2px 0 0 var(--box-line);
}
.cell.box-bottom {
  box-shadow: inset 0 -2px 0 var(--box-line);
}
.cell.box-right.box-bottom {
  box-shadow: inset -2px 0 0 var(--box-line), inset 0 -2px 0 var(--box-line);
}
.cell.box-right.is-selected,
.cell.box-bottom.is-selected,
.cell.box-right.box-bottom.is-selected {
  box-shadow: inset 0 0 0 3px var(--accent);
}

.cell-value {
  position: relative;
  z-index: 4;
  pointer-events: none;
  line-height: 1;
}

/* Notes — 3×3 hit grid (keypad map 1–9) */
.cell.has-notes .cell-value { display: none; }
.cell.has-entry .note-grid { opacity: 0; }
.cell.given .note-grid,
.cell.hint-locked .note-grid { display: none; }

.note-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  z-index: 2;
}

.note-section {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  font-size: clamp(0.45rem, 1.8vw, 0.7rem);
  font-weight: 500;
  color: var(--note);
  line-height: 1;
  opacity: 0.92;
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.08s ease;
}
/* Section wash: useful when notes present (left-commit exception / right-toggle).
   Left-click itself is whole-cell cycle — sections matter for right-click + note-hit. */
.cell:not(.given):not(.hint-locked).has-notes .note-section:hover {
  background: rgba(196, 120, 90, 0.18);
}
.cell:not(.given):not(.hint-locked).has-notes .note-section:active {
  background: rgba(196, 120, 90, 0.32);
}
.cell:not(.given):not(.hint-locked):not(.has-notes):not(.has-entry) .note-section:hover {
  background: rgba(196, 120, 90, 0.08);
}

.cell.has-entry .note-section {
  cursor: pointer;
}

.cell.given .note-section,
.cell.hint-locked .note-section {
  cursor: default;
}

.numpad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 0.3rem;
}
.num-btn {
  padding: 0.55rem 0.15rem;
  font-size: 0.95rem;
  background: #e8dcc8;
  color: var(--ink);
  position: relative;
  cursor: default;
  pointer-events: none;
  min-width: 0;
}
.num-btn:hover { filter: none; }
.num-btn:active { transform: none; }
.num-btn .num-label {
  display: block;
  line-height: 1.2;
}
.num-btn .num-remain {
  position: absolute;
  top: 0.12rem;
  right: 0.14rem;
  font-size: 0.58rem;
  font-weight: 700;
  color: var(--soft);
  line-height: 1;
  pointer-events: none;
}
.num-btn.is-exhausted {
  opacity: 0.72;
}

.hint {
  text-align: center;
  font-size: 0.78rem;
  color: var(--soft);
  margin-top: 0.75rem;
  line-height: 1.4;
}


/* —— Stats panel (Slice 6.1 fuller menu) —— */
.stats-panel {
  margin-top: 0.65rem;
  padding-top: 0.65rem;
  border-top: 1px solid rgba(61, 52, 41, 0.12);
}
.stats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.stats-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.02em;
}
.stats-close {
  padding: 0.28rem 0.7rem;
  font-size: 0.78rem;
}
.stats-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.55rem;
}
.stats-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  background: #f0e6d6;
  border-radius: 8px;
  padding: 0.28rem 0.55rem;
  font-size: 0.8rem;
  box-shadow: inset 0 0 0 1px rgba(61, 52, 41, 0.06);
}
.stats-k {
  color: var(--soft);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.stats-v {
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.stats-table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 0.35rem;
}
.stats-table {
  width: 100%;
  min-width: 18rem;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.stats-table th,
.stats-table td {
  text-align: right;
  padding: 0.32rem 0.4rem;
  border-bottom: 1px solid rgba(61, 52, 41, 0.08);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stats-table thead th {
  color: var(--soft);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.stats-table tbody th {
  text-align: left;
  color: var(--ink);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: none;
  letter-spacing: 0;
}
.stats-table thead th:first-child {
  text-align: left;
}
.stats-note {
  font-size: 0.72rem;
  color: var(--soft);
  line-height: 1.35;
  margin-top: 0.25rem;
}
#stats-btn.is-open {
  background: #e8dcc8;
  box-shadow: inset 0 0 0 1px rgba(61, 52, 41, 0.12);
}
.win-time {
  font-size: 1.05rem;
  font-weight: 700;
  color: #3f6b48;
  font-variant-numeric: tabular-nums;
  margin: 0.15rem 0;
}
.win-best {
  font-size: 0.85rem;
  color: var(--soft);
  margin-bottom: 0.35rem;
  min-height: 1.1em;
}
.win-best.is-new-best {
  color: #3f6b48;
  font-weight: 600;
}

.win-alpaca {
  display: block;
  width: 4.4rem;
  height: auto;
  margin: 0 auto 0.35rem;
  filter: drop-shadow(0 2px 6px rgba(63, 107, 72, 0.25));
  pointer-events: none;
  user-select: none;
}
.win-banner {
  background: linear-gradient(160deg, #e8f2ea, #dce9df);
  border: 2px solid var(--win);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  text-align: center;
  box-shadow: 0 2px 8px var(--shadow);
  margin-bottom: 0.5rem;
}
.win-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: #3f6b48;
  margin-bottom: 0.25rem;
}
.win-sub {
  font-size: 0.85rem;
  color: var(--soft);
}
.is-hidden { display: none !important; }

@media (prefers-reduced-transparency: reduce) {
  .board-mark { display: none; }
  .board-stage { background: var(--box-line); }
  .board { background: var(--box-line); }
  .cell { background: var(--cell-a); }
  .cell.tone-b { background: var(--cell-b); }
}

@media (max-width: 420px) {
  .header h1 { font-size: 1.45rem; }
  .studio-mark { width: 2.7rem; }
  .numpad { grid-template-columns: repeat(9, 1fr); gap: 0.22rem; }
  .num-btn { font-size: 0.85rem; padding: 0.45rem 0.08rem; }
  .action-row { width: 100%; }
  .action-row .btn { flex: 1; }
  .timer { margin-left: 0; width: 100%; text-align: center; }
  .gem-hud { margin-left: 0; }
  .btn-dev-gems { width: auto; }
  .diff-row { width: 100%; }
}

/* Studio bar — match First Fleece / Meadow Takeover */
#studio-bar {
  position: relative;
  z-index: 20;
  align-self: stretch;
  width: 100%;
  height: 40px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: #1c2619;
  color: #c9d4b8;
  font-family: Nunito, system-ui, sans-serif;
  font-size: 0.92rem;
  box-sizing: border-box;
  margin: 0;
}
#studio-bar a {
  color: #f7efe3;
  font-weight: 700;
  text-decoration: none;
  margin-right: 0.45rem;
}
#studio-bar a:hover { text-decoration: underline; }
