/* ==========================================================================
   Per-game styling
   ========================================================================== */

/* --- crossword (mini + 15x15) -------------------------------------------- */

.xw { padding-bottom: var(--safe-bottom); }

.xw__gridwrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 10px 8px;
}

.xw__grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);
  width: min(94vw, 60vh, 560px);
  aspect-ratio: 1;
  background: var(--cell-border);
  gap: 1px;
  padding: 1px;
}
.xw[data-size="mini"] .xw__grid { width: min(88vw, 56vh, 420px); }

.xw__cell {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  background: var(--cell-bg);
  color: var(--label);
  overflow: hidden;
}
.xw__cell.is-blank { background: var(--cell-blank); cursor: default; }
.xw__cell.is-correct { background: var(--my-green); color: #fff; }
.xw__cell.is-highlighted { background: var(--my-yellow); color: #1a1206; }
.xw__cell.is-selected { background: var(--my-blue); color: #fff; }
.xw__cell.is-pencil .xw__letter { color: var(--my-gray); }

.xw__num {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: clamp(7px, calc(100vw / var(--cols) / 5.5), 12px);
  font-weight: 500;
  line-height: 1;
  opacity: 0.85;
  pointer-events: none;
}
.xw[data-size="big"] .xw__num { left: 50%; transform: translateX(-50%); }

.xw__letter {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding-top: 8%;
  font-size: clamp(11px, calc(min(94vw, 60vh, 560px) / var(--cols) * 0.58), 34px);
  font-weight: 700;
  line-height: 1;
}
.xw[data-size="mini"] .xw__letter {
  font-size: clamp(16px, calc(min(88vw, 56vh, 420px) / var(--cols) * 0.58), 44px);
}

.xw__cluebar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--my-blue);
  color: #fff;
}
@media (min-width: 700px) {
  .xw__cluebar { padding-inline: max(16px, calc((100% - 620px) / 2)); }
}
.xw__arrow {
  flex: none;
  padding: 2px 6px;
  font-size: 22px;
  font-weight: 500;
  color: #fff;
  line-height: 1;
}
.xw__clue {
  flex: 1;
  min-height: 20px;
  font-size: 16px;
  color: #fff;
  text-align: center;
  line-height: 1.3;
}

/* --- on-screen keyboard -------------------------------------------------- */

.keyboard {
  padding: 6px 3px calc(6px + var(--safe-bottom));
  background: var(--keyboard-bg, #D1D3D9);
  user-select: none;
}
.keyboard__rows { max-width: 620px; margin: 0 auto; }
@media (prefers-color-scheme: dark) { .keyboard { --keyboard-bg: #2C2C2E; } }

.keyboard__row {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin-bottom: 6px;
}
.keyboard__row:last-child { margin-bottom: 0; }
.keyboard__spacer { flex: 0.5; }

.key {
  flex: 1;
  max-width: 44px;
  min-width: 0;
  height: 42px;
  border-radius: 5px;
  font-size: 20px;
  font-weight: 400;
  color: var(--label);
  background: var(--key-bg, #FFFFFF);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.28);
}
@media (prefers-color-scheme: dark) { .key { --key-bg: #6B6B70; color: #fff; } }
.key:active { background: var(--key-active, #B8BCC4); }
.key--wide { flex: 1.4; max-width: 62px; font-size: 17px; }

@media (min-width: 700px) {
  .key { height: 46px; max-width: 52px; font-size: 21px; }
}

/* --- Gram Slam ----------------------------------------------------------- */

.gs {
  align-items: center;
  padding: 12px 16px calc(20px + var(--safe-bottom));
  gap: 16px;
}
.gs__inner { width: 100%; max-width: 460px; margin: 0 auto; }

.gs__score { font-size: 28px; font-weight: 700; text-align: center; }

.gs__bar {
  height: 8px;
  margin: 8px 16px 0;
  border-radius: 4px;
  background: color-mix(in srgb, var(--sys-gray) 30%, transparent);
  overflow: hidden;
}
.gs__bar i {
  display: block;
  height: 100%;
  border-radius: 4px;
  background: var(--rank-color, var(--my-blue));
  transition: width 0.3s ease;
}
.gs__rankrow {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 6px 16px 0;
}
.gs__rank { font-size: 17px; font-weight: 600; color: var(--rank-color, var(--my-blue)); }
.gs__next { font-size: 15px; color: var(--label-secondary); }

.gs__found {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 50px;
  margin-top: 14px;
  padding: 0 16px;
  border: 2px solid var(--cell-border);
  border-radius: 16px;
  background: var(--cell-bg);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  white-space: nowrap;
}
.gs__found::-webkit-scrollbar { display: none; }
.gs__found span { font-size: 17px; }
.gs__found span.is-revealed { font-style: italic; color: var(--label-secondary); }
.gs__found .gs__empty { color: var(--label-secondary); font-size: 15px; }

.gs__word {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  margin-top: 16px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.06em;
}
.gs__word.is-empty { color: var(--sys-gray); font-weight: 400; letter-spacing: normal; }

.gs__hive {
  position: relative;
  width: 264px;
  height: 200px;
  margin: 18px auto 0;
}
.hex {
  position: absolute;
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  color: var(--label);
  background: color-mix(in srgb, var(--sys-gray) 30%, transparent);
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  transition: transform 0.12s ease;
}
.hex.is-center { background: var(--my-yellow); color: #000; }
.hex:active { transform: scale(0.92); }

.gs__controls {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-top: 22px;
  padding: 0 16px;
}
.gs__btn {
  flex: 1;
  padding: 14px 16px;
  border-radius: 8px;
  font-size: 17px;
  font-weight: 600;
  color: #fff;
}
.gs__btn--delete { background: var(--my-red); }
.gs__btn--enter { background: var(--my-green); }
.gs__btn[disabled] { opacity: 0.5; cursor: default; }
.gs__btn--enter[disabled] { background: var(--sys-gray); opacity: 1; }
.gs__shuffle { flex: none; color: var(--my-blue); }
.gs__shuffle svg { width: 25px; height: 25px; display: block; }

.gs__banner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 20;
}
.gs__banner > div {
  padding: 16px 24px;
  border-radius: 15px;
  font-size: 34px;
  font-weight: 700;
  text-align: center;
  color: var(--rank-color, var(--my-blue));
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  animation: alert-in 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.gs__banner small { display: block; font-size: 17px; font-weight: 600; margin-top: 6px; }

.gs .result-card h2 { font-size: 34px; color: #fff; }

/* --- Word Lapse ---------------------------------------------------------- */

.wl {
  align-items: center;
  padding: 10px 0 calc(16px + var(--safe-bottom));
}
.wl__inner { width: 100%; max-width: 460px; margin: 0 auto; }

.wl__hint { font-size: 12px; text-align: center; color: var(--label); }

.wl__head {
  display: flex;
  align-items: flex-start;
  padding: 6px 16px 0;
}
.wl__time { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.wl__time.is-low { color: var(--sys-red); }
.wl__time.is-zen { color: var(--sys-purple); }
.wl__sub { font-size: 12px; color: var(--label-secondary); }
.wl__head-spacer { flex: 1; }
.wl__score { font-size: 17px; font-weight: 600; }

.wl__preview {
  display: flex;
  justify-content: center;
  min-height: 34px;
  margin: 8px 0 4px;
}
.wl__preview span {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.08em;
  background: color-mix(in srgb, var(--sys-blue) 12%, transparent);
  animation: alert-in 0.2s ease-out;
}

.wl__gridwrap {
  margin: 0 16px;
  padding: 16px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--sys-gray) 12%, transparent);
  touch-action: none;
}
.wl__grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  max-width: 340px;
  margin: 0 auto;
}
.wl__cell {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 25%;
  font-family: var(--font-mono);
  font-size: clamp(16px, 5.6vw, 24px);
  font-weight: 700;
  color: var(--label);
  background: var(--cell-bg);
  transition: transform 0.1s ease, background 0.15s ease;
}
.wl__cell.is-used { background: color-mix(in srgb, var(--sys-green) 30%, var(--cell-bg)); }
.wl__cell.is-selected {
  background: color-mix(in srgb, var(--sys-blue) 50%, var(--cell-bg));
  transform: scale(1.05);
  box-shadow: 0 1px 2px color-mix(in srgb, var(--sys-blue) 30%, transparent);
}
.wl__cell.is-hit {
  background: color-mix(in srgb, var(--sys-green) 70%, var(--cell-bg));
  animation: wl-pop 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}
@keyframes wl-pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.3); }
  100% { transform: scale(1); }
}
.wl__order {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 16px;
  height: 16px;
  border-radius: 8px;
  font-family: var(--font);
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  background: var(--sys-blue);
  display: flex;
  align-items: center;
  justify-content: center;
}

.wl__words {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding: 0 16px;
  overflow-x: auto;
  scrollbar-width: none;
}
.wl__words::-webkit-scrollbar { display: none; }
.wl__words span {
  flex: none;
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 12px;
  background: color-mix(in srgb, var(--sys-green) 20%, transparent);
}

.wl .result-card { background: rgba(0, 0, 0, 0.82); }
.wl .result-card h2 { font-size: 30px; font-weight: 700; }
.wl .result-card__found { margin-top: 10px; font-size: 20px; }
.wl .result-card__score { margin-top: 2px; font-size: 11px; }
.wl__zen {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  background: var(--sys-purple);
}
.wl__zen svg { width: 17px; height: 17px; }

/* --- Sudoku -------------------------------------------------------------- */

.sd { padding-bottom: calc(12px + var(--safe-bottom)); }

.sd__difficulties {
  display: grid;
  gap: 20px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px;
}
.sd__difficulty {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-radius: 12px;
  text-align: left;
  background: var(--bg-elevated);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  color: inherit;
  text-decoration: none;
}
.sd__difficulty:active { transform: scale(0.99); }
.sd__difficulty > svg { width: 30px; height: 30px; flex: none; color: var(--diff-color); }
.sd__difficulty h3 { margin: 0; font-size: 22px; font-weight: 600; }
.sd__difficulty p { margin: 2px 0 0; font-size: 12px; color: var(--label-secondary); }
.sd__difficulty-spacer { flex: 1; }
.sd__difficulty .sd__chevron { width: 12px; height: 12px; color: var(--label-secondary); flex: none; }
.sd__done { font-size: 12px; font-weight: 600; color: var(--sys-green); }

.sd__boardwrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 0;
  padding: 12px;
}

.sd__gridarea { position: relative; }

.sd__grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  gap: 2px;
  width: min(94vw, 44vh, 380px);
  aspect-ratio: 1;
}
.sd__cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  /* min-*: 0 and overflow keep a cell square no matter what it holds — without
     them a full set of pencil marks stretches its whole grid row. */
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--sys-gray) 50%, transparent);
  border-radius: 2px;
  font-size: clamp(15px, 5.2vw, 22px);
  font-weight: 500;
  color: var(--sys-blue);
  background: var(--cell-bg);
}
.sd__cell.is-given { font-weight: 700; color: var(--label); }
.sd__cell.is-revealed { color: var(--sys-orange); }
.sd__cell.is-error { color: var(--sys-red); border-color: var(--sys-red); }
.sd__cell.is-peer { background: color-mix(in srgb, var(--sys-blue) 10%, var(--cell-bg)); }
.sd__cell.is-match { background: color-mix(in srgb, var(--sys-green) 20%, var(--cell-bg)); }
.sd__cell.is-selected {
  background: color-mix(in srgb, var(--sys-blue) 30%, var(--cell-bg));
  border: 3px solid var(--sys-blue);
}
.sd__cell.is-done { color: var(--sys-green); background: color-mix(in srgb, var(--sys-green) 10%, var(--cell-bg)); border-color: var(--sys-green); }
.sd__cell[data-boxright] {
  border-right-width: 3px;
  border-right-color: color-mix(in srgb, var(--label) 45%, transparent);
}
.sd__cell[data-boxbottom] {
  border-bottom-width: 3px;
  border-bottom-color: color-mix(in srgb, var(--label) 45%, transparent);
}

.sd__notes {
  position: absolute;
  inset: 7%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  line-height: 1;
}
.sd__notes span {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(6px, 1.9vw, 9px);
  font-weight: 400;
  color: var(--sys-gray);
}

.sd__pad {
  width: min(94vw, 380px);
  padding: 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--sys-gray) 12%, transparent);
}
.sd__pad-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.sd__pad-head span { font-size: 17px; font-weight: 600; }
.sd__mode {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  background: color-mix(in srgb, var(--sys-gray) 18%, transparent);
}
.sd__mode svg { width: 14px; height: 14px; }
.sd__mode.is-pencil { color: var(--sys-orange); }

.sd__keys { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.sd__key {
  aspect-ratio: 1;
  max-height: 50px;
  border-radius: 8px;
  font-size: 22px;
  font-weight: 500;
  color: var(--label);
  background: color-mix(in srgb, var(--sys-gray) 55%, transparent);
}
.sd__pad.is-pencil .sd__key:not(.is-complete):not(.sd__key--clear) {
  background: color-mix(in srgb, var(--sys-orange) 55%, transparent);
}
.sd__key--clear { font-size: 17px; background: color-mix(in srgb, var(--sys-gray) 38%, transparent); }
.sd__key.is-complete {
  position: relative;
  background: color-mix(in srgb, var(--sys-green) 55%, transparent);
  color: var(--label-secondary);
  cursor: default;
}
.sd__key.is-complete::after {
  content: "✓";
  position: absolute;
  top: -6px;
  right: -6px;
  width: 16px;
  height: 16px;
  border-radius: 8px;
  font-size: 10px;
  line-height: 16px;
  color: #fff;
  background: var(--sys-green);
}
.sd__pad[disabled] { opacity: 0.6; pointer-events: none; }
