html:has(.mobile-game-shell) {
  scrollbar-gutter: auto;
}

.mobile-game-shell {
  --game-accent: var(--primary);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  padding-top: env(safe-area-inset-top);
  background: var(--bg);
  color: var(--text);
  font: 500 15px/1.4 var(--font-app);
  overscroll-behavior: none;
}

.shikaku-shell {
  --game-accent: var(--g-shikaku);
}
.chromedoku-shell {
  --game-accent: var(--g-chromedoku);
}
.codebreak-shell {
  --game-accent: var(--g-codebreak);
}
.pipes-shell {
  --game-accent: var(--g-pipes);
}
.color-sweeper-shell {
  --game-accent: var(--g-sweeper);
}
.atoms-shell {
  --game-accent: var(--g-atoms);
}
.mosaic-shell {
  --game-accent: var(--g-mosaic);
}
.lits-shell {
  --game-accent: var(--g-lits);
}
.sets-shell {
  --game-accent: var(--g-sets);
}

.mobile-game-shell * {
  box-sizing: border-box;
}
.shell-appbar {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--space-1);
  height: 52px;
  padding: 0 var(--space-2);
  border-bottom: 1px solid var(--line);
}
.shell-icon-button {
  display: grid;
  flex: none;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.shell-icon-button svg,
.shell-tool svg {
  width: 24px;
  height: 24px;
}
.shell-tool.primary svg {
  width: 20px;
  height: 20px;
}
.shell-icon-button:hover,
.shell-tool:hover:not(:disabled) {
  background: var(--surface-2);
}
.shell-title {
  display: flex;
  flex: 1;
  min-width: 0;
  flex-direction: column;
  line-height: 1.1;
}
.shell-title strong {
  overflow: hidden;
  font-size: 17px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.shell-title small {
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 12px;
}
.shell-timer {
  min-width: 49px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.shell-progress {
  flex: none;
  height: 3px;
  background: var(--surface-2);
}
.shell-progress span {
  display: block;
  height: 100%;
  background: var(--game-accent);
  transition: width 160ms ease-out;
}
.shell-stage {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  overflow: hidden;
  padding: var(--space-2) var(--space-4);
}
.shell-board-area {
  display: grid;
  flex: none;
  place-items: center;
  min-height: 0;
  max-width: 100%;
}
.shell-input {
  display: grid;
  flex: none;
  place-items: center;
  min-height: 48px;
  padding: 0 var(--space-4);
}
.shell-toolbar {
  display: grid;
  flex: none;
  grid-template-columns: repeat(var(--tool-count, 5), minmax(0, 112px));
  justify-content: center;
  height: calc(76px + env(safe-area-inset-bottom));
  padding: 0 var(--space-2) env(safe-area-inset-bottom);
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.shell-tool {
  display: flex;
  min-width: 0;
  min-height: 64px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 5px 0;
  border: 0;
  border-radius: var(--radius-m);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.shell-tool span {
  font-size: 11px;
  font-weight: 500;
}
.shell-tool:disabled {
  color: var(--text-muted);
  opacity: 0.6;
  cursor: default;
}
.shell-tool.active {
  color: var(--success);
}
.shell-tool-icon {
  display: grid;
  width: 36px;
  height: 30px;
  place-items: center;
  border-radius: var(--radius-pill);
}
/* The "new puzzle" tool is filled with the game colour so it is easy to find. */
.shell-tool.primary .shell-tool-icon {
  background: var(--game-accent);
  color: var(--game-on-accent, #ffffff);
}
.shell-tool.primary span:last-child {
  font-weight: 700;
}
/* The hint floats above the toolbar like a card; the board keeps its size and stays visible above it. */
.shell-hint {
  position: fixed;
  z-index: 50;
  right: var(--space-3);
  bottom: calc(84px + env(safe-area-inset-bottom));
  left: var(--space-3);
  width: auto;
  max-width: 560px;
  max-height: min(34dvh, 240px);
  margin: 0 auto;
  overflow: auto;
  padding: var(--space-3) var(--space-4) var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  background: var(--surface);
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.22);
  overscroll-behavior: contain;
  animation: shell-hint-enter 200ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.shell-hint h3,
.shell-hint p {
  margin: 0 0 var(--space-1);
}
.shell-hint h3 {
  padding-right: 40px;
  font-size: 16px;
}
.shell-hint .hint-tier {
  display: none;
}
.shell-hint-close {
  position: absolute;
  top: var(--space-1);
  right: var(--space-1);
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.shell-hint-close svg {
  width: 20px;
  height: 20px;
}
.shell-hint.top {
  top: calc(env(safe-area-inset-top) + 60px);
  bottom: auto;
}
.shell-hint-body h3 {
  overflow: hidden;
  margin: 0 0 var(--space-1);
  padding-right: 40px;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.shell-hint-step {
  min-height: 2.9em;
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
}
.shell-hint-nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
.shell-hint-nav .button {
  flex: 1;
  min-height: 40px;
}
.shell-hint-count {
  min-width: 40px;
  color: var(--text-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
@keyframes shell-hint-enter {
  from {
    transform: translateY(12px);
    opacity: 0;
  }
}
.shell-toast {
  position: fixed;
  z-index: 60;
  right: var(--space-4);
  bottom: calc(96px + env(safe-area-inset-bottom));
  left: var(--space-4);
  width: max-content;
  max-width: calc(100vw - 32px);
  margin: 0 auto;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  background: var(--primary);
  color: var(--on-primary);
  font-size: 13px;
  text-align: center;
  pointer-events: none;
}
.shell-toast.busy {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.shell-toast.busy::before {
  width: 14px;
  height: 14px;
  flex: none;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  content: '';
  animation: shell-spin 800ms linear infinite;
}
@keyframes shell-spin {
  to {
    transform: rotate(360deg);
  }
}
.shell-toast[hidden] {
  display: none;
}
.shell-toast.with-action {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-1) var(--space-1) var(--space-1) var(--space-4);
  text-align: left;
  pointer-events: auto;
}
:root .mobile-game-shell .shell-toast-action {
  flex: none;
  min-height: 36px;
  padding: 0 var(--space-4);
  border: 0;
  border-radius: var(--radius-pill);
  background: rgb(255 255 255 / 0.22);
  color: inherit;
  font: 700 13px var(--font-app);
  cursor: pointer;
}
.shell-toast.bad {
  background: var(--danger);
  color: var(--bg);
}
.shell-sheet-layer {
  position: fixed;
  z-index: 70;
  inset: 0;
}
.shell-sheet-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  border: 0;
  background: rgb(0 0 0 / 0.5);
}
.shell-sheet {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  margin: 0 auto;
  display: flex;
  width: min(100%, 560px);
  max-height: min(82dvh, 720px);
  flex-direction: column;
  border-radius: var(--radius-l) var(--radius-l) 0 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 -8px 30px rgb(0 0 0 / 0.25);
}
.shell-sheet-layer.entering .shell-sheet {
  animation: shell-sheet-enter 250ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.shell-sheet-grip {
  flex: none;
  width: 36px;
  height: 4px;
  margin: 8px auto 0;
  border-radius: var(--radius-pill);
  background: var(--line);
}
.shell-sheet-head {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
}
.shell-sheet-head h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}
.shell-sheet-content {
  overflow: auto;
  padding: 0 var(--space-4) calc(var(--space-6) + env(safe-area-inset-bottom));
}
.shell-sheet-content .tool-panel {
  margin: 0;
  padding: var(--space-4) 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}
.shell-sheet-content .panel-label .eyebrow {
  display: none;
}
.shell-sheet-content .panel-label h2 {
  margin: 0 0 var(--space-2);
  font-size: 17px;
}
.shell-sheet-content .button {
  min-height: 44px;
  border-radius: var(--radius-m);
}
.shell-sheet-content select,
.shell-sheet-content input {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}
.shell-sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  margin: var(--space-3) 0;
}
.shell-sheet-actions button {
  min-height: 48px;
}
/* Sheet buttons use the neutral shell style, not the legacy page buttons. */
:root .mobile-game-shell .shell-sheet .button {
  border: 0;
  border-radius: var(--radius-m);
  background: var(--surface-2);
  color: var(--text);
  font: 600 15px var(--font-app);
  box-shadow: none;
}
:root .mobile-game-shell .shell-sheet .button.primary {
  background: var(--primary);
  color: var(--on-primary);
}
:root .mobile-game-shell .shell-sheet .button:disabled {
  opacity: 0.4;
}
.shell-sheet-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) 0;
}
.shell-sheet-row button:not(.shell-switch) {
  min-height: 44px;
}
.shell-rules-card {
  padding: var(--space-4);
  border-radius: var(--radius-m);
  background: var(--surface-2);
}
.shell-rules-card h3 {
  margin: 0 0 var(--space-2);
  font-size: 18px;
}
.shell-rules-example {
  margin-bottom: var(--space-4);
  color: var(--text);
  font-size: 27px;
  font-weight: 700;
  letter-spacing: var(--space-1);
  text-align: center;
}
.shell-rules-card p {
  margin: 0;
}
.shell-rules-step {
  margin: var(--space-3) 0;
  color: var(--text-muted);
  font-size: 13px;
}
.shell-completion-title {
  font: 800 30px/1.2 var(--font-app);
}
.shell-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-2);
  margin: var(--space-4) 0;
}
.shell-stats div {
  padding: var(--space-3);
  border-radius: var(--radius-m);
  background: var(--surface-2);
}
.shell-stats strong {
  display: block;
  font-size: 20px;
}
.shell-stats small {
  color: var(--text-muted);
}
/* Controls used inside sheets: on/off switch, segmented choice, labels. */
.shell-switch {
  position: relative;
  box-sizing: border-box;
  width: 52px;
  height: 32px;
  min-height: 0;
  padding: 0;
  flex: none;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--line);
  cursor: pointer;
  transition: background 160ms ease-out;
}
.shell-switch::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.3);
  content: '';
  transition: transform 160ms ease-out;
}
.shell-switch[aria-checked='true'] {
  background: var(--success);
}
.shell-switch[aria-checked='true']::after {
  transform: translateX(20px);
}
.shell-sheet-label {
  margin: var(--space-4) 0 var(--space-2);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
}
.shell-segments {
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  gap: var(--space-1);
  padding: var(--space-1);
  border-radius: var(--radius-m);
  background: var(--surface-2);
}
.shell-segment {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text);
  font: 600 14px var(--font-app);
  cursor: pointer;
}
.shell-segment.on {
  background: var(--segment-on);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.2);
}
.shell-seed {
  margin-top: var(--space-4);
  color: var(--text-muted);
  font-size: 13px;
}
.shell-seed summary {
  min-height: 32px;
  cursor: pointer;
}
.shell-seed input {
  width: 100%;
  min-height: 44px;
  margin-top: var(--space-2);
  padding: 0 var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  font: 500 15px var(--font-app);
}
.shell-sheet-note {
  margin: var(--space-4) 0 0;
  color: var(--text-muted);
  font-size: 13px;
}
.shell-pill.wide {
  width: 100%;
  margin-top: var(--space-5);
}
.shell-pill:disabled {
  opacity: 0.6;
  cursor: default;
} /* The result card carries its own headline, so the sheet title is only kept for screen readers. */
.shell-sheet-layer.completion .shell-sheet-head h2 {
  visibility: hidden;
}
/* Result card after a solve (NYT-style: headline, this game, totals, week). */
.shell-result {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-align: center;
}
.shell-result-title {
  margin: var(--space-1) 0 var(--space-1);
  font: 800 30px/1.2 var(--font-app);
}
.shell-result-sub {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}
.shell-result dl {
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  margin: var(--space-5) 0 0;
}
.shell-result dl div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.shell-result dd {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.shell-result dt {
  color: var(--text-muted);
  font-size: 12px;
}
.shell-result-kpis {
  padding: var(--space-3) 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
}
.shell-result-kpis div + div {
  border-left: 1px solid var(--line);
}
.shell-result-totals dd {
  font-size: 22px;
}
.shell-result-week {
  display: flex;
  justify-content: space-between;
  margin: var(--space-5) var(--space-2) var(--space-6);
  padding: 0;
  list-style: none;
}
.shell-result-week li {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 11px;
}
.shell-result-week span {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--bg);
  font-size: 14px;
  font-weight: 800;
}
.shell-result-week li.done span {
  background: var(--game-accent);
}
.shell-result-week li.today span {
  box-shadow:
    0 0 0 2px var(--surface),
    0 0 0 4px var(--text);
}
.shell-pill {
  min-height: 52px;
  padding: 0 var(--space-6);
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--primary);
  color: var(--on-primary);
  font: 700 16px var(--font-app);
  cursor: pointer;
}
.shell-text-link {
  display: grid;
  min-height: 44px;
  place-items: center;
  margin-top: var(--space-1);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}
@keyframes shell-sheet-enter {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}
@media (pointer: coarse) {
  .shell-computer-guide {
    display: none;
  }
}
@media (max-width: 500px) {
  .shell-timer {
    font-size: 13px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .shell-sheet,
  .shell-hint {
    animation: none;
  }
  .shell-progress span {
    transition: background 120ms ease-out;
  }
}
