/* Shell for the single-page games (snake, 2048, blocks, ...). Loaded after site.css. */

.shell.game {
  width: min(560px, calc(100% - 32px));
  padding: 20px 0 36px;
}

.shell.game.wide {
  width: min(760px, calc(100% - 32px));
}

.game-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

h1 {
  margin: 0;
  font-size: clamp(1.6rem, 6vw, 2.1rem);
  line-height: 1;
  letter-spacing: 0;
}

.stats {
  display: flex;
  gap: 8px;
}

.stat {
  min-width: 66px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-align: center;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 800;
  text-transform: uppercase;
}

.stat b {
  display: block;
  margin-top: 2px;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

/* Action buttons stay together at the right, and wrap as one group on narrow screens. */
.toolbar .actions {
  display: flex;
  align-items: center;
  gap: inherit;
  margin-left: auto;
}

.btn,
.option select {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background-color: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 750;
  cursor: pointer;
}

.btn {
  padding: 9px 14px;
  touch-action: manipulation;
  user-select: none;
}

.btn:hover,
.option select:hover {
  border-color: rgba(23, 106, 81, 0.45);
}

.btn:focus-visible,
.option select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn:disabled:hover {
  border-color: var(--line);
}

.btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.btn[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

/* Square icon-only button (sound toggle). */
.btn.icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
}

.btn.icon svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
  pointer-events: none;
}

.btn.icon .wave,
.btn.icon .mute {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.btn.icon[aria-pressed="true"] .mute,
.btn.icon[aria-pressed="false"] .wave {
  display: none;
}

/* Labelled dropdown for a game setting (speed, difficulty, ...). */
.option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 750;
}

.option select {
  padding: 8px 28px 8px 10px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8l3.5-3.5' fill='none' stroke='%23626b66' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  background-size: 11px;
}

.banner {
  min-height: 1.4em;
  margin: 0 0 10px;
  font-size: 0.95rem;
  font-weight: 750;
}

.banner.win { color: var(--accent); }
.banner.lose { color: var(--danger); }

.stage {
  position: relative;
  border-radius: 10px;
  background: var(--board);
  overflow: hidden;
  box-shadow: var(--shadow);
  touch-action: pinch-zoom;
  user-select: none;
}

.stage canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 28, 22, 0.72);
  color: #ffffff;
  text-align: center;
}

.overlay[hidden] {
  display: none;
}

.overlay-box {
  display: grid;
  gap: 10px;
  justify-items: center;
  max-width: 300px;
}

.overlay-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 850;
  line-height: 1.1;
}

.overlay-text {
  margin: 0;
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.92rem;
  line-height: 1.45;
}

.overlay .btn {
  margin-top: 4px;
  padding: 11px 20px;
}

.pad {
  display: none;
  margin: 14px auto 0;
  gap: 8px;
  justify-content: center;
}

.pad .btn {
  width: 62px;
  height: 54px;
  padding: 0;
  display: grid;
  place-items: center;
}

.pad svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
  pointer-events: none;
}

.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.82rem;
}

.crumbs a {
  border-bottom: 1px solid transparent;
}

.crumbs a:hover,
.crumbs a:focus-visible {
  color: var(--accent);
  border-color: currentColor;
  outline: none;
}

.crumbs [aria-current] {
  color: var(--ink);
  font-weight: 700;
}

/* How to play, rules, controls, FAQ and related games under each game. */
.about {
  margin-top: 28px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.about h2 {
  margin: 22px 0 8px;
  font-size: 1.08rem;
  line-height: 1.25;
  letter-spacing: 0;
}

.about p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.93rem;
  line-height: 1.65;
}

.facts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.facts li {
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--soft);
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.facts b {
  margin-right: 4px;
  color: var(--ink);
}

.rules {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 0.93rem;
  line-height: 1.55;
}

.more {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.more a {
  display: block;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
  font-size: 0.86rem;
  font-weight: 750;
  transition: border-color 160ms ease, transform 160ms ease;
}

.more a:hover,
.more a:focus-visible {
  border-color: rgba(23, 106, 81, 0.5);
  transform: translateY(-2px);
  outline: none;
}

.more img {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 10;
  object-fit: cover;
}

.more span {
  display: block;
  padding: 8px 10px 9px;
}

@media (max-width: 520px) {
  .more {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.controls {
  display: grid;
  gap: 6px;
  margin: 0;
}

.controls div {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.4fr);
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 0.9rem;
  line-height: 1.4;
}

.controls dt {
  font-weight: 750;
}

.controls dd {
  margin: 0;
  color: var(--muted);
}

.faq details {
  border-bottom: 1px solid var(--line);
}

.faq summary {
  padding: 11px 0;
  font-size: 0.95rem;
  font-weight: 750;
  cursor: pointer;
}

.faq details p {
  margin: 0 0 12px;
}

/* Touch devices get the on-screen pad; keyboards don't need it. */
@media (hover: none), (pointer: coarse) {
  .pad {
    display: grid;
  }
}

@media (max-width: 640px) {
  .shell.game,
  .shell.game.wide {
    width: min(100% - 24px, 760px);
    padding-top: 16px;
  }
}

@media (max-width: 480px) {
  .toolbar {
    gap: 6px;
  }

  .toolbar .btn:not(.icon) {
    padding: 8px 9px;
    font-size: 0.85rem;
  }

  .option select {
    padding: 7px 24px 7px 8px;
    font-size: 0.85rem;
    background-position: right 7px center;
  }

  .stat {
    min-width: 58px;
    padding: 6px 8px;
  }
}

.btn, .option select { min-height: 44px; }
.stage:focus-visible { outline-color: #805a12 !important; }

.game-load-status {
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.game-load-status .btn { display: inline-flex; align-items: center; margin: 4px 8px 0 0; }
.game-load-status a:not(.btn) { text-decoration: underline; color: var(--accent); }
main.game [hidden] { display: none !important; }

.quick-controls, .related-games { margin-top: 24px; }
.quick-controls h2, .related-games h2 { font-size: 1.1rem; margin: 0 0 12px; }
.controls-more { display: inline-block; padding: 12px 0; color: var(--accent); font-size: .9rem; text-decoration: underline; }
.more small { display: block; margin-top: 4px; color: var(--muted); font-size: .75rem; line-height: 1.4; }
#full-controls { scroll-margin-top: 20px; }

@media (prefers-reduced-motion: reduce) {
  .more a, .btn, .option select { transition: none !important; }
}

/* Paint initialized game content together, rather than moving instructions as an
   empty DOM board fills in. The startup message remains usable if boot fails. */
main.game { position: relative; }
@media (scripting: enabled) {
  main.game[data-game-state="loading"] { min-height: 100svh; }
  main.game[data-game-state="loading"] > :not(.crumbs):not(.game-head):not(.game-load-status):not(noscript) { visibility: hidden; }
  main.game[data-game-state="loading"] #game-startup { position: absolute; top: 180px; left: 0; right: 0; }
}
@media (scripting: none) { #game-startup { display: none; } }

/* Keep grouped actions usable with larger text and narrow reflow. */
.toolbar .actions { flex-wrap: wrap; max-width: 100%; }
.toolbar .btn { max-width: 100%; }

.stats { flex-wrap: wrap; max-width: 100%; }
.stat { max-width: 100%; overflow-wrap: anywhere; }
.option { flex-wrap: wrap; max-width: 100%; }
.option select { min-width: 0; max-width: 100%; }
.more span { overflow-wrap: anywhere; }
