/* Shared game chrome. Keep each game's simulation and canvas ratio independent. */
.game-shell {
  --shell-bg: oklch(from #000f3f l c h);
  --shell-white: oklch(100% 0 none);
  --shell-shadow: oklch(68% .055 270);
  --shell-gap: clamp(.625rem, .4rem + 1vw, 1.25rem);
  --shell-header: clamp(4.5rem, 3.7rem + 3vw, 6.25rem);
  --shell-control: clamp(.75rem, .65rem + .5vw, 1rem);
}
.game-shell.arcade {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  inline-size: 100%;
  block-size: 100dvh;
  min-block-size: 35.5rem;
  padding-block: env(safe-area-inset-top, 0px) env(safe-area-inset-bottom, 0px);
  padding-inline: 0;
  overflow: clip;
  background: var(--shell-bg);
  color: var(--shell-white);
}
.game-shell .game-nav {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr minmax(0, 1.45fr) 1fr;
  align-items: center;
  gap: var(--shell-gap);
  inline-size: min(100%, 48rem);
  block-size: var(--shell-header);
  flex: none;
  padding-block: .375rem;
  padding-inline: var(--shell-gap);
  background: var(--shell-bg);
  box-shadow: none;
}
.game-shell .game-nav h1 {
  order: initial;
  margin: 0;
  min-inline-size: 0;
  text-align: center;
}
.game-shell .title-logo {
  display: block;
  inline-size: 100%;
  block-size: calc(var(--shell-header) - .75rem);
  object-fit: contain;
}
.game-shell :is(.nav-button, .toolbar-button) {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .25em;
  min-inline-size: 44px;
  min-block-size: 44px;
  padding-block: .5rem;
  padding-inline: .25rem;
  border: 0;
  border-radius: .75rem;
  background: var(--shell-white);
  color: var(--shell-bg);
  font-family: inherit;
  font-size: var(--shell-control);
  font-weight: 900;
  line-height: 1.3;
  white-space: nowrap;
  text-decoration: none;
  box-shadow: 0 3px 0 var(--shell-shadow);
  touch-action: manipulation;
  cursor: pointer;
}
.game-shell :is(.nav-button, .toolbar-button):active {
  translate: 0 2px;
  box-shadow: 0 1px 0 var(--shell-shadow);
}
.game-shell :is(button, a):focus-visible {
  outline: 3px solid oklch(87% .16 95);
  outline-offset: 3px;
}
.game-shell button:disabled { opacity: .65; cursor: default; }
.game-shell #fullscreen > span:last-child { font-size: 1.1em; }
.game-shell .play-area {
  position: relative;
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  container-type: size;
  inline-size: 100%;
  block-size: auto;
  min-block-size: 0;
  padding: 0;
  margin-block: var(--shell-gap);
  background: transparent;
  overflow: clip;
}
.game-shell .game-frame {
  inline-size: min(calc(100cqw - 2 * var(--shell-gap)), calc(100cqh * 390 / 560));
  block-size: auto;
  max-inline-size: none;
  max-block-size: none;
  aspect-ratio: 390 / 560;
  border-radius: clamp(1rem, .75rem + 1vw, 1.75rem);
  outline: 0;
  box-shadow: none;
  overflow: clip;
}
.game-shell .game-toolbar {
  position: relative;
  z-index: 6;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--shell-gap);
  flex: none;
  inline-size: min(100%, 48rem);
  block-size: auto;
  padding-block: 0 .25rem;
  padding-inline: var(--shell-gap);
  background: transparent;
}
.game-shell #restart { font-family: inherit; font-size: var(--shell-control); font-weight: 900; line-height: 1.3; }
.game-shell .game-footer {
  container-type: inline-size;
  flex: none;
  inline-size: 100%;
  padding-block: .625rem .375rem;
  padding-inline: var(--shell-gap);
  text-align: center;
}
.game-shell .game-footer h2 {
  margin-block: 0 .25rem;
  font-size: clamp(1rem, .85rem + .6vw, 1.375rem);
  font-weight: 900;
}
.game-shell .footer-links {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: clamp(.5rem, 1.5cqi, 1.5rem);
}
.game-shell .footer-links :is(a, button) {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  min-block-size: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--shell-white);
  font: inherit;
  font-size: min(.75rem, 3cqi);
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
}
.game-shell .footer-links :is(a, button):active { opacity: .7; }
.game-shell.arcade.is-expanded {
  position: fixed;
  inset: 0;
  z-index: 1000;
  min-block-size: 0;
}
.game-shell.is-expanded .play-area { margin: 0; align-items: flex-start; }
.game-shell.is-expanded .game-nav { block-size: var(--shell-header); }
.game-shell.is-expanded .game-frame {
  inline-size: min(100cqw, calc(100cqh * 390 / 560));
  block-size: 100cqh;
  aspect-ratio: auto;
  border-radius: 0;
}
.game-shell.is-expanded .game-toolbar {
  position: absolute;
  inset-block-start: calc(env(safe-area-inset-top, 0px) + var(--shell-header) + .5rem);
  inset-block-end: auto;
  inset-inline: 0;
  margin-inline: auto;
  /* Match the portrait canvas even when desktop/landscape leaves side gutters. */
  inline-size: min(calc(100% - 2 * var(--shell-gap)), calc((100dvh - var(--shell-header) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) * 390 / 560 - 2 * var(--shell-gap)));
  max-inline-size: none;
  block-size: auto;
  padding: 0;
  gap: clamp(.25rem, .25rem + .2vw, .5rem);
  pointer-events: none;
}
.game-shell.is-expanded .toolbar-button {
  min-inline-size: 0;
  block-size: 44px;
  padding: 0;
  background: color-mix(in oklch, var(--shell-white) 82%, transparent);
  pointer-events: auto;
}
.game-shell .control-icon { display: none; }
.game-shell.is-expanded .control-label { display: none; }
.game-shell.is-expanded .control-icon {
  display: block;
  inline-size: 1.5rem;
  block-size: 1.5rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.game-shell #sound[aria-pressed="true"] .sound-off,
.game-shell #sound[aria-pressed="false"] .sound-on { display: none; }
.game-shell.is-expanded .game-footer { display: none; }
.game-shell.is-expanded #fullscreen-label { font-size: 1em; }
.game-shell .overlay-card {
  inline-size: 92%;
  max-inline-size: 300px;
  margin-block-start: 2rem;
  padding-block: .875rem .625rem;
  padding-inline: .75rem;
}
.game-shell .overlay h2 { font-size: clamp(1.15rem, 1rem + .6vw, 1.625rem); }
/* Place score inside the game's top safety band, below the floating controls. */
.game-shell.is-expanded .hud {
  inset-block-start: 3.25rem;
  inset-inline: 4.5%;
  translate: none;
  align-items: center;
  gap: .875rem;
  block-size: 20px;
  padding-inline: .375rem;
  border-radius: .375rem;
  background: color-mix(in oklch, var(--shell-bg) 80%, transparent);
}
.game-shell.is-expanded :is(.score-box, .best-box) {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  padding: 0;
}
.game-shell.is-expanded :is(.score-box, .best-box) span { font-size: 9px; }
.game-shell.is-expanded :is(.score-box, .best-box) strong { font-size: 18px; line-height: 1; }
.game-shell.is-expanded .canvas-caption { inset-block-end: 7%; }
.game-shell::backdrop { background: var(--shell-bg); }
@media (hover: hover) and (pointer: fine) {
  .game-shell :is(.nav-button, .toolbar-button):hover {
    background: color-mix(in oklch, var(--shell-white) 92%, var(--shell-shadow));
  }
  .game-shell .footer-links :is(a, button):hover { text-decoration: underline; }
}
@media (orientation: landscape) and (max-height: 600px) {
  /* Preserve the portrait game and let the normal page scroll on short screens. */
  .game-shell.arcade { min-block-size: 35.5rem; }
  .game-shell.arcade.is-expanded { min-block-size: 0; }
  .game-shell.is-expanded .hud { inset-block-start: 3.25rem; gap: .5rem; }
  .game-shell.is-expanded :is(.score-box, .best-box) strong { font-size: 14px; }
}
