/* Kakuro — own styles, theme variables only. Root class: .kk */

.kk {
  width: 100%;
  max-width: 640px;
}

.kk-bar {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.kk-stat {
  min-width: 84px;
  padding: 8px 14px 6px;
  text-align: center;
  border-radius: 10px;
  background: var(--gm-surface, #1b2740);
  border: 1px solid var(--gm-line, rgba(255, 255, 255, 0.09));
}

.kk-stat b {
  display: block;
  font: 500 1.35rem/1.15 var(--gm-display, "Fraunces", Georgia, serif);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.kk-lab {
  display: block;
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gm-muted, rgba(242, 238, 230, 0.66));
}

.kk-pencil {
  min-height: 44px;
  align-self: center;
  touch-action: manipulation;
}

.kk-pencil[aria-pressed="true"] {
  background: var(--gm-accent, #c0392b);
  border-color: var(--gm-accent, #c0392b);
  color: #fff;
}

/* The grid scales with the stage down to 34 px cells; below that it scrolls sideways. */
.kk-scroll {
  container-type: inline-size;
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--gm-radius, 12px);
}

.kk-grid {
  --n: 6;
  --gap: 2px;
  --pad: 6px;
  --cell: max(34px, min(60px, calc((100cqw - 2 * var(--pad) - (var(--n) - 1) * var(--gap)) / var(--n))));
  display: grid;
  grid-template-columns: repeat(var(--n), var(--cell));
  grid-auto-rows: var(--cell);
  gap: var(--gap);
  width: max-content;
  padding: var(--pad);
  margin: 0 auto;
  box-sizing: border-box;
  background: var(--gm-surface, #1b2740);
  border: 1px solid var(--gm-line, rgba(255, 255, 255, 0.09));
  border-radius: var(--gm-radius, 12px);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* clue / black cells, split by a diagonal from top-left to bottom-right */
.kk-clue {
  position: relative;
  border-radius: 4px;
  background: var(--gm-sq-dark, #6b3a44);
  color: var(--gm-sq-light, #e9e0cc);
  overflow: hidden;
}

.kk-clue.has-clue::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom right, transparent calc(50% - 0.7px), var(--gm-sq-light, #e9e0cc) calc(50% - 0.7px), var(--gm-sq-light, #e9e0cc) calc(50% + 0.7px), transparent calc(50% + 0.7px));
  opacity: 0.7;
}

.kk-across,
.kk-down {
  position: absolute;
  font: 600 calc(var(--cell) * 0.32)/1 var(--gm-body, "DM Sans", system-ui, sans-serif);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.kk-across {
  top: 10%;
  right: 10%;
}

.kk-down {
  bottom: 10%;
  left: 10%;
}

/* white cells */
.kk-cell {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  display: block;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  touch-action: manipulation;
  color: var(--gm-text, #f2eee6);
  background: var(--gm-bg-2, #131c2b);
  box-shadow: inset 0 0 0 1px var(--gm-line, rgba(255, 255, 255, 0.09));
  transition: background 0.12s ease;
}

.kk-cell:hover { background: var(--gm-surface-2, #22304a); }

.kk-cell:focus-visible {
  outline: 3px solid var(--gm-accent-bright, #e0584a);
  outline-offset: -2px;
  z-index: 2;
}

.kk-cell.is-peer { background: var(--gm-surface-2, #22304a); }

.kk-cell.is-selected {
  background: var(--gm-accent-soft, rgba(192, 57, 43, 0.3));
  box-shadow: inset 0 0 0 3px var(--gm-accent, #c0392b);
  color: var(--gm-text, #f2eee6);
}

.kk-cell.is-clash { box-shadow: inset 0 0 0 2px var(--gm-bad, #e0584a); }
.kk-cell.is-clash:not(.is-selected) { background: var(--gm-bad-soft, rgba(224, 88, 74, 0.22)); }
.kk-cell.is-wrong .kk-val { color: var(--gm-bad, #e0584a); text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.kk-cell.is-hinted:not(.is-selected) { background: var(--gm-accent-soft, rgba(192, 57, 43, 0.3)); }
.kk-cell.is-solved { background: var(--gm-good-soft, rgba(88, 190, 130, 0.22)); }

.kk-val {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font: 500 calc(var(--cell) * 0.52)/1 var(--gm-display, "Fraunces", Georgia, serif);
  pointer-events: none;
}

.kk-notes {
  position: absolute;
  inset: 8%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  pointer-events: none;
}

.kk-notes span {
  display: flex;
  align-items: center;
  justify-content: center;
  font: 600 calc(var(--cell) * 0.24)/1 var(--gm-body, "DM Sans", system-ui, sans-serif);
  color: var(--gm-muted, rgba(242, 238, 230, 0.66));
  visibility: hidden;
}

.kk-notes span.is-on { visibility: visible; }
.kk-cell.is-selected .kk-notes span { color: var(--gm-text, #f2eee6); }

/* keypad */
.kk-pad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.kk-pad button {
  appearance: none;
  -webkit-appearance: none;
  min-height: 48px;
  padding: 10px 0;
  font: 500 1.25rem/1 var(--gm-display, "Fraunces", Georgia, serif);
  color: var(--gm-text, #f2eee6);
  background: var(--gm-surface, #1b2740);
  border: 1px solid var(--gm-line, rgba(255, 255, 255, 0.09));
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.kk-pad button:hover { border-color: var(--gm-accent-bright, #e0584a); }

.kk-pad button:focus-visible {
  outline: 3px solid var(--gm-accent-bright, #e0584a);
  outline-offset: 2px;
}

.kk-pad button.is-done { opacity: 0.4; }

.kk-pad .kk-erase {
  font-family: var(--gm-body, "DM Sans", system-ui, sans-serif);
  font-size: 0.85rem;
  font-weight: 600;
}

.kk.is-pencil .kk-pad button:not(.kk-erase) {
  font-size: 0.95rem;
  font-family: var(--gm-body, "DM Sans", system-ui, sans-serif);
  font-weight: 600;
}

#gm-kakuro .gm-status { margin-top: 12px; }

#kk-size { border-radius: 16px; }
.gm-seg button, .gm-actions .gm-btn { min-height: 44px; }

@media (max-width: 480px) {
  .kk-bar { gap: 6px; }
  .kk-stat { min-width: 64px; padding: 8px 8px 6px; }
  .kk-stat b { font-size: 1.15rem; }
  .kk-grid { --gap: 1px; --pad: 4px; }
  .kk-pad { gap: 6px; }
  .kk-pencil { padding: 10px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .kk-cell, .kk-pad button { transition: none; }
}
