.kk-page {
  --kk-block: #3a2e5a;
  --kk-block-text: #f4efff;
  --kk-line: rgba(255, 255, 255, 0.5);
  --kk-grid-line: #2a2142;
  --kk-cell-bg: #fffdff;
  --kk-cell-text: #2a1d4a;
  --kk-peer: #f1eaff;
  --kk-selected: #ddd0ff;
  --kk-same: #7c3aed;
  --kk-given: #6d28d9;
  --kk-bad: #dc2626;
  --kk-bad-bg: #fde4e4;
  --kk-clue-active: #fde68a;
}
[data-theme="dark"] .kk-page {
  --kk-block: #0d0914;
  --kk-block-text: #ede6ff;
  --kk-line: rgba(237, 230, 255, 0.35);
  --kk-grid-line: #000;
  --kk-cell-bg: #2f2747;
  --kk-cell-text: #f7f2ff;
  --kk-peer: #3b3159;
  --kk-selected: #55468c;
  --kk-same: #c4b5fd;
  --kk-given: #c4b5fd;
  --kk-bad: #fca5a5;
  --kk-bad-bg: #4a1d2a;
  --kk-clue-active: #fcd34d;
}

.kk-shell {
  max-width: 960px;
  margin: 0 auto;
  border: 1px solid rgba(56, 28, 109, 0.2);
  border-radius: 16px;
  padding: 1rem;
  background: transparent;
}
/* Desktop: [title · coins] on the left, actions on the right. */
.kk-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.8rem;
}
.kk-head__bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1 1 auto;
  min-width: 0;
}
.kk-title {
  flex: 0 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 1.55rem;
}
/* The focus toggle only exists at tablet/phone widths (play-focus.css); keep it last in the bar. */
.kk-head__bar .word-search-game-shell__expand-btn {
  order: 0;
  flex: 0 0 auto;
  margin: 0;
}
.kk-controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}
.kk-label-short {
  display: none;
}
.kk-head__bar .pv-coin-chip {
  flex: 0 0 auto;
  box-sizing: border-box;
  border-radius: 12px;
  min-height: 40px;
  padding: 0 0.75rem;
  border: 1px solid color-mix(in srgb, var(--accent-strong) 35%, var(--border));
  background: transparent;
  font-size: 0.95rem;
  font-weight: 700;
}


.kk-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
  margin-bottom: 0.8rem;
}
.kk-chip {
  border: 1px solid rgba(56, 28, 109, 0.2);
  border-radius: 10px;
  padding: 0.45rem 0.6rem;
  background: var(--surface-strong);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  font-size: 0.92rem;
}

.kk-play {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 250px;
  gap: 1rem;
  align-items: start;
}

/* --- Board --- */
.kk-board-wrap {
  position: relative;
  width: min(100%, 620px, var(--kk-board-fit, 620px));
  max-width: 100%;
  margin: 0 auto;
}

/* Large portrait tablets (iPad Pro 13", Surface): the pad sits under the board, so the
   board may grow to the size kakuro.js fits it to. */
@media (min-width: 900px) and (max-width: 1199px) and (orientation: portrait) {
  .kk-board-wrap {
    width: min(100%, var(--kk-board-fit, 620px));
  }
}
.kk-board {
  --kk-cell: 48px;
  display: grid;
  width: 100%;
  aspect-ratio: 1 / 1;
  gap: 1px;
  background: var(--kk-grid-line);
  border: 2px solid var(--kk-grid-line);
  border-radius: 6px;
  overflow: hidden;
  user-select: none;
}
.kk-block {
  position: relative;
  background: var(--kk-block);
}
.kk-clue {
  background:
    linear-gradient(
      to top right,
      transparent calc(50% - 0.75px),
      var(--kk-line) calc(50% - 0.75px),
      var(--kk-line) calc(50% + 0.75px),
      transparent calc(50% + 0.75px)
    ),
    var(--kk-block);
  color: var(--kk-block-text);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  font-size: max(9px, calc(var(--kk-cell) * 0.3));
  line-height: 1;
}
.kk-clue__down,
.kk-clue__across {
  position: absolute;
  transition: color 0.15s ease, opacity 0.15s ease;
}
.kk-clue__down {
  top: 8%;
  right: 10%;
}
.kk-clue__across {
  bottom: 8%;
  left: 10%;
}
.kk-clue .is-active {
  color: var(--kk-clue-active);
}
.kk-clue .is-done {
  opacity: 0.45;
}
.kk-clue .is-bad {
  color: #fca5a5;
  opacity: 1;
}
.kk-cell {
  position: relative;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  appearance: none;
  -webkit-appearance: none;
  background: var(--kk-cell-bg);
  color: var(--kk-cell-text);
  font: inherit;
  font-weight: 800;
  font-size: max(12px, calc(var(--kk-cell) * 0.56));
  line-height: 1;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.12s ease;
}
.kk-cell:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}
.kk-cell.is-peer {
  background: var(--kk-peer);
}
.kk-cell.is-selected {
  background: var(--kk-selected);
  box-shadow: inset 0 0 0 2px var(--accent);
}
.kk-cell.is-same {
  color: var(--kk-same);
}
.kk-cell--given {
  color: var(--kk-given);
  font-style: italic;
}
.kk-cell.kk-invalid {
  color: var(--kk-bad);
  background: var(--kk-bad-bg);
}
.kk-cell.kk-wrong {
  animation: kk-wrong-flash 2s ease-out;
}
@keyframes kk-wrong-flash {
  0%, 70% { background: var(--kk-bad-bg); box-shadow: inset 0 0 0 3px var(--kk-bad); color: var(--kk-bad); }
  100% { box-shadow: inset 0 0 0 0 transparent; }
}
.kk-cell.kk-hint-flash {
  animation: kk-hint-pulse 1.6s ease-out;
}
@keyframes kk-hint-pulse {
  0%, 100% { box-shadow: inset 0 0 0 0 transparent; }
  18%, 42% { box-shadow: inset 0 0 0 3px var(--kk-given); }
}
.kk-notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 6%;
  box-sizing: border-box;
  font-size: max(7px, calc(var(--kk-cell) * 0.22));
  font-weight: 700;
  color: var(--text-muted);
  pointer-events: none;
}
.kk-notes span {
  display: grid;
  place-items: center;
}

/* --- Side panel --- */
.kk-side {
  display: grid;
  gap: 0.7rem;
}
.kk-pad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem;
}
/* Pad keys and tools take their look from tactile-buttons.css; only sizes live here. */
.kk-pad .kk-pad__key {
  min-height: 52px;
  padding: 0;
  font-size: 1.35rem;
  touch-action: manipulation;
}
.kk-pad.is-notes .kk-pad__key {
  font-size: 1rem;
  color: var(--text-muted);
  border-style: dashed;
}
.kk-tools {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.4rem;
}
.kk-combos {
  border: 1px solid rgba(56, 28, 109, 0.2);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  background: var(--surface-strong);
  font-size: 0.88rem;
}
.kk-combos__title {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
}
.kk-combos__empty {
  margin: 0;
  color: var(--text-muted);
}
.kk-combos__run + .kk-combos__run {
  margin-top: 0.5rem;
}
.kk-combos__head {
  margin: 0 0 0.25rem;
  font-weight: 700;
  color: var(--text-muted);
}
.kk-combos__list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  max-height: 7.5rem;
  overflow-y: auto;
}
.kk-combo {
  border-radius: 6px;
  padding: 0.1rem 0.4rem;
  background: var(--accent-soft);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
}
.kk-combo.is-out {
  opacity: 0.4;
  text-decoration: line-through;
  background: transparent;
}
.kk-combos__fits {
  margin: 0.55rem 0 0;
}
.kk-combos__fits strong {
  color: var(--accent-strong);
  letter-spacing: 0.1em;
}

.kk-status {
  margin-top: 0.75rem;
  border: 1px solid rgba(56, 28, 109, 0.2);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  min-height: 44px;
  background: var(--surface-strong);
}
.kk-how {
  margin-top: 0.7rem;
  color: var(--text-muted);
  font-size: 0.93rem;
  line-height: 1.55;
}

/* --- Win overlay --- */
.kk-win {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: min(86%, 450px);
  padding: 0.9rem 1rem;
  border-radius: 14px;
  border: 1px solid rgba(115, 76, 226, 0.36);
  background:
    radial-gradient(circle at 12% 20%, rgba(255, 224, 143, 0.32) 0 24px, transparent 25px),
    radial-gradient(circle at 88% 18%, rgba(255, 170, 226, 0.24) 0 20px, transparent 21px),
    radial-gradient(circle at 84% 82%, rgba(132, 214, 255, 0.22) 0 22px, transparent 23px),
    rgba(255, 255, 255, 0.94);
  box-shadow: 0 12px 34px rgba(36, 24, 85, 0.18);
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.45;
  color: #22133f;
  display: none;
  pointer-events: none;
  z-index: 6;
}
.kk-win.is-visible {
  display: block;
  pointer-events: auto;
  animation: kk-pop 0.55s ease-out;
}
/* Never taller than the board it sits on; anything extra scrolls inside the box. */
.kk-win {
  max-height: calc(100% - 12px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
@media (max-width: 560px) {
  /* Phones: tighten the solved card so the streak line and app prompt fit on the board. */
  .kk-win {
    padding: 0.6rem 0.75rem;
    font-size: 0.9rem;
    line-height: 1.32;
  }
  .kk-win .kk-win__title {
    font-size: 1rem;
  }
  .kk-win .kk-win__btn {
    margin-top: 0.45rem;
    min-height: 36px;
    padding: 0.25rem 0.75rem;
  }
  .kk-win .pv-win-streak {
    margin-top: 0.4rem;
  }
  .kk-win .pv-win-streak__line {
    font-size: 0.88rem;
  }
  .kk-win .pv-win-streak__next {
    margin-top: 0.1rem;
    font-size: 0.78rem;
  }
  .kk-win .pv-win-streak__share {
    margin-top: 0.3rem;
    padding: 0.18rem 0.75rem;
    font-size: 0.78rem;
  }
  .kk-win .pv-app-win-promo {
    margin-top: 0.45rem;
    padding-top: 0.4rem;
  }
  .kk-win .pv-app-win-promo__title {
    font-size: 0.9rem;
  }
  .kk-win .pv-app-win-promo__text {
    margin: 0.05rem 0 0.3rem;
    font-size: 0.78rem;
  }
  .kk-win .pv-app-win-promo__badge img {
    height: 36px;
  }
  .kk-win .pv-app-win-promo__dismiss {
    margin-top: 0.15rem;
    padding: 0.1rem 0.4rem;
    font-size: 0.78rem;
  }
  /* When the app prompt is up, skip the next-game hint (the home strip and other wins show it). */
  .kk-win:has(.pv-app-win-promo:not([hidden])) .pv-win-streak__next {
    display: none;
  }
  .kk-win:has(.pv-app-win-promo:not([hidden])) .pv-win-streak__share {
    margin-top: 0.2rem;
    padding: 0.12rem 0.75rem;
  }
  /* Badge and "Not now" share one row instead of stacking. */
  .kk-win .pv-app-win-promo {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    column-gap: 0.7rem;
    margin-top: 0.35rem;
    padding-top: 0.3rem;
  }
  .kk-win .pv-app-win-promo__title,
  .kk-win .pv-app-win-promo__text {
    flex-basis: 100%;
  }
  .kk-win .pv-app-win-promo__dismiss {
    margin-top: 0;
  }
}
.kk-win__title,
.kk-win__detail {
  margin: 0;
}
.kk-win__title {
  font-weight: 800;
  font-size: 1.1rem;
}
.kk-win__detail + .kk-win__detail {
  margin-top: 0.2rem;
}
.kk-win__btn {
  margin-top: 0.65rem;
  width: 100%;
  border: 1px solid rgba(115, 76, 226, 0.36);
  background: var(--surface-strong, #fff);
  border-radius: 10px;
  min-height: 40px;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  color: #22133f;
}
@keyframes kk-pop {
  0% { opacity: 0; transform: translate(-50%, -42%) scale(0.94); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
[data-theme="dark"] .kk-win {
  border-color: rgba(185, 160, 255, 0.62);
  color: #f2f5ff;
  background:
    radial-gradient(circle at 12% 20%, rgba(255, 224, 143, 0.24) 0 24px, transparent 25px),
    radial-gradient(circle at 88% 18%, rgba(255, 170, 226, 0.18) 0 20px, transparent 21px),
    rgba(20, 24, 48, 0.94);
  box-shadow: 0 14px 36px rgba(4, 6, 18, 0.5);
}
[data-theme="dark"] .kk-win__btn {
  color: #f2f5ff;
  border-color: rgba(185, 160, 255, 0.45);
  background: rgba(31, 38, 72, 0.85);
}

/* --- Stats dialog --- */
.kk-stats-dialog {
  width: min(560px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 1rem 1.1rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-strong);
  color: var(--text);
  box-shadow: var(--shadow-md);
}
.kk-stats-dialog::backdrop {
  background: rgba(18, 12, 26, 0.45);
}
.kk-stats-dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.kk-stats-dialog__title {
  margin: 0;
  font-size: 1.2rem;
}
.kk-stats-dialog__close {
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  min-width: var(--tap-target);
  min-height: var(--tap-target);
}
.kk-stats-dialog__table-wrap {
  overflow-x: auto;
}
.kk-stats-dialog__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}
.kk-stats-dialog__table th,
.kk-stats-dialog__table td {
  padding: 0.45rem 0.35rem;
  border-bottom: 1px solid var(--border);
  text-align: center;
}
.kk-stats-dialog__table tbody th {
  text-align: left;
}
.kk-stats-dialog__note {
  margin: 0.7rem 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

[data-theme="dark"] .kk-shell { border-color: rgba(189, 166, 240, 0.35); }
[data-theme="dark"] .kk-chip,
[data-theme="dark"] .kk-status,
[data-theme="dark"] .kk-combos,
[data-theme="dark"] .kk-head__bar .pv-coin-chip {
  border-color: rgba(189, 166, 240, 0.35);
  background: rgba(22, 16, 40, 0.62);
  color: #f3e8ff;
}

@media (max-width: 1024px), (max-width: 1199px) and (orientation: portrait) {
  .kk-head {
    flex-direction: column;
    flex-wrap: nowrap; /* a wrapping column sizes each row to its content, not the card */
    align-items: stretch;
  }
  .kk-head__bar {
    flex: 0 0 auto;
  }
  .kk-controls {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.4rem;
  }
  .kk-controls button {
    min-width: 0;
    padding-inline: 0.35rem;
  }
}
@media (max-width: 820px), (min-width: 900px) and (max-width: 1199px) and (orientation: portrait) {
  .kk-play {
    grid-template-columns: 1fr;
  }
  .kk-pad {
    grid-template-columns: repeat(9, minmax(0, 1fr));
    gap: 0.3rem;
  }
  .kk-pad .kk-pad__key {
    min-height: 46px;
    font-size: 1.15rem;
  }
  .kk-tools {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .kk-tools .kk-tool {
    padding-inline: 0.3rem;
    font-size: 0.9rem;
  }
}
@media (max-width: 560px) {
  /* Title, level badge, coins and the focus button share one row. */
  .kk-head__bar {
    gap: 0.25rem;
  }
  .kk-title {
    flex-shrink: 0;
    font-size: 1.2rem;
  }
  .kk-head__bar .pv-coin-chip {
    min-height: 36px;
    padding: 0 0.4rem;
  }
  .kk-shell {
    padding: 0.7rem;
  }
  .kk-label-long {
    display: none;
  }
  .kk-label-short {
    display: inline;
  }
  .kk-tools {
    gap: 0.3rem;
  }
  .kk-stats {
    gap: 0.35rem;
  }
  .kk-chip {
    font-size: 0.8rem;
    padding: 0.4rem 0.3rem;
  }
}

/* The app in landscape (tablets): kakuro.js fits the board to the screen height. */
@media (min-width: 1025px) and (orientation: landscape), (min-width: 1200px) {
  .site-shell--native-app .kk-board-wrap {
    width: min(100%, var(--kk-board-fit, 620px));
  }
}
