:root {
  color-scheme: dark;
  --ink: #f7f2e9;
  --muted: #b6bed0;
  --gold: #f5cf7a;
  --violet: #c3a3ff;
  --panel: rgba(8, 24, 39, .92);
  --line: rgba(235, 219, 180, .2);
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family: "Leelawadee UI", Tahoma, sans-serif;
  background: var(
    --game-background,
    radial-gradient(ellipse at 75% 48%, rgba(12, 88, 112, .42), transparent 35%),
    radial-gradient(ellipse at 17% 15%, rgba(90, 43, 111, .36), transparent 32%),
    linear-gradient(135deg, #091323 0%, #10172c 45%, #061e2a 100%)
  );
}

body::before {
  position: fixed;
  z-index: -1;
  inset: 0;
  content: "";
  opacity: .3;
  pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 12% 23%, #fff 99%, transparent),
    radial-gradient(2px 2px at 79% 17%, #b8e9ff 99%, transparent),
    radial-gradient(1px 1px at 68% 72%, #fff 99%, transparent),
    radial-gradient(2px 2px at 27% 82%, #f5cf7a 99%, transparent),
    radial-gradient(1px 1px at 91% 61%, #fff 99%, transparent);
  background-size: 290px 240px, 360px 330px, 250px 270px, 390px 320px, 300px 290px;
}

button { font: inherit; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

.ambient { position: fixed; z-index: -1; width: 340px; height: 340px; border-radius: 50%; filter: blur(80px); opacity: .16; pointer-events: none; }
.ambient-one { top: 4%; left: -150px; background: #d245ab; }
.ambient-two { right: -120px; bottom: -100px; background: #00b8c5; }

.home-screen {
  position: fixed;
  z-index: 30;
  inset: var(--pn-site-nav-height, 58px) 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 0;
  background: #07152a;
}
.home-screen[hidden] { display: none; }
.home-art {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.home-status {
  position: absolute;
  z-index: 1;
  bottom: 82px;
  left: 50%;
  display: grid;
  width: min(420px, calc(100% - 32px));
  gap: 7px;
  color: var(--ink);
  transform: translateX(-50%);
}
.home-load-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: #f7f2e9;
  font-size: 12px;
  font-weight: 700;
  text-shadow: 0 1px 5px #07141b;
}
.home-load-percent { color: var(--gold); font-variant-numeric: tabular-nums; }
.home-load-track {
  height: 8px;
  overflow: hidden;
  border: 1px solid rgba(245, 207, 122, .34);
  border-radius: 999px;
  background: rgba(3, 12, 22, .82);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, .45);
}
.home-load-fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #126b4d, #32b77d 58%, #f5cf7a);
  box-shadow: 0 0 12px rgba(76, 202, 143, .38);
  transition: width .2s ease;
}
.home-load-error {
  margin: 3px 0 0;
  color: #ffd2ca;
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
  overflow-wrap: anywhere;
}
.home-actions {
  position: absolute;
  z-index: 1;
  bottom: 24px;
  left: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translateX(-50%);
}
.home-play {
  min-height: 42px;
  padding: 10px 24px;
  border: 1px solid rgba(245, 207, 122, .62);
  border-radius: 999px;
  color: #09251b;
  background: linear-gradient(110deg, #16805a, #39bd83 58%, #f5cf7a);
  box-shadow: 0 5px 18px rgba(38, 169, 112, .28);
  font: inherit;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
  transition: .18s ease;
}
.home-play:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(38, 169, 112, .4); }
.home-play:disabled { cursor: wait; opacity: .58; }
.home-play:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

.game-shell { width: min(1240px, calc(100% - 64px)); min-height: calc(100dvh - var(--pn-site-nav-height, 58px)); margin: 0 auto; display: flex; flex-direction: column; }
.icon-button { width: 42px; height: 42px; border: 1px solid rgba(245, 207, 122, .58); border-radius: 50%; color: var(--gold); background: rgba(9, 24, 39, .68); font-size: 29px; line-height: 1; cursor: pointer; transition: .2s ease; }
.icon-button:hover { color: #fff3d4; background: rgba(153, 111, 54, .25); transform: rotate(-35deg); }

.game-layout { flex: 1; display: grid; grid-template-columns: minmax(220px, .75fr) minmax(0, 1.65fr); align-items: center; gap: clamp(38px, 6vw, 86px); padding: 38px 0; }
.intro { align-self: center; padding-bottom: 8px; }
.eyebrow { margin: 0 0 16px; color: var(--gold); font-size: 11px; letter-spacing: .17em; }
.eyebrow-line { display: inline-block; width: 22px; height: 1px; margin: 0 9px 3px 0; background: var(--gold); }
h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(48px, 5.2vw, 72px); font-weight: 500; line-height: .96; letter-spacing: -.055em; text-shadow: 0 4px 26px rgba(0, 0, 0, .48); }
h1 span { color: #d6c6ff; font-size: .75em; letter-spacing: -.02em; }
.intro-copy { margin: 22px 0 26px; color: #d4d7e1; font-size: 15px; font-weight: 300; line-height: 1.9; }
.score-card { position: relative; display: flex; align-items: center; gap: 14px; width: min(100%, 290px); padding: 14px 18px; border: 1px solid rgba(245, 207, 122, .35); border-radius: 7px; background: linear-gradient(115deg, rgba(20, 53, 65, .84), rgba(11, 28, 43, .78)); box-shadow: inset 0 0 23px rgba(87, 198, 208, .08), 0 8px 28px rgba(0, 0, 0, .2); }
.score-emblem { display: grid; width: 40px; height: 40px; place-items: center; border: 1px solid rgba(245, 207, 122, .43); border-radius: 50%; color: var(--gold); font-size: 22px; background: rgba(138, 104, 49, .15); }
.score-card > div:nth-child(2) { display: grid; gap: 2px; }
.card-label { color: #b5c3cc; font-size: 11px; }
.score-card strong { color: #fff0c8; font-family: Georgia, serif; font-size: 20px; font-weight: 500; letter-spacing: .06em; }
.card-sparkle { margin-left: auto; color: var(--gold); font-size: 21px; }
.how-to { display: flex; align-items: flex-start; gap: 12px; margin: 22px 0 18px; color: #c1c8d5; font-size: 12px; line-height: 1.8; }
.how-to p { margin: 0; }
.how-to b { color: #f2e8d1; font-size: 13px; font-weight: 500; }
.how-to-icon { margin-top: 1px; color: #c3a3ff; font-size: 21px; }
.hint-button { display: inline-flex; align-items: center; gap: 9px; padding: 10px 15px; border: 1px solid rgba(190, 159, 255, .36); border-radius: 5px; color: #e3d6ff; background: rgba(23, 18, 49, .6); font-size: 12px; cursor: pointer; transition: .2s ease; }
.hint-button > span { color: var(--gold); font-size: 17px; }
.hint-button:hover { border-color: var(--gold); box-shadow: 0 0 20px rgba(167, 124, 255, .19); }

.board-panel { position: relative; overflow: hidden; width: 100%; padding: clamp(20px, 2.4vw, 30px); border: 1px solid rgba(227, 204, 154, .36); border-radius: 9px; background: linear-gradient(140deg, rgba(15, 44, 54, .97), var(--panel) 70%); box-shadow: 0 22px 80px rgba(0, 0, 0, .43), inset 0 0 50px rgba(56, 184, 187, .08), 0 0 35px rgba(43, 173, 189, .08); backdrop-filter: blur(12px); }
.board-panel::before, .board-panel::after { position: absolute; z-index: 1; width: 30px; height: 30px; content: ""; pointer-events: none; }
.board-panel::before { top: 8px; left: 8px; border-top: 1px solid rgba(245, 207, 122, .7); border-left: 1px solid rgba(245, 207, 122, .7); }
.board-panel::after { right: 8px; bottom: 8px; border-right: 1px solid rgba(245, 207, 122, .7); border-bottom: 1px solid rgba(245, 207, 122, .7); }
.board-heading { display: flex; align-items: center; justify-content: space-between; gap: 15px; }
.board-kicker { margin: 0 0 4px; color: #a9c5d0; font-size: 11px; letter-spacing: .08em; }
.board-heading h2 { margin: 0; color: #fff6e3; font-size: 20px; font-weight: 500; letter-spacing: .02em; }
.level-seal { display: grid; width: 41px; height: 41px; place-items: center; border: 1px solid rgba(245, 207, 122, .52); border-radius: 50%; color: var(--gold); background: radial-gradient(circle, rgba(245, 207, 122, .16), transparent 70%); box-shadow: 0 0 18px rgba(245, 207, 122, .14); }
.level-seal span { font-size: 21px; text-shadow: 0 0 12px var(--gold); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); margin: 17px 0 15px; padding: 11px 0; border-top: 1px solid rgba(220, 229, 242, .13); border-bottom: 1px solid rgba(220, 229, 242, .13); }
.stat { display: grid; grid-template-columns: 19px auto; align-items: center; column-gap: 7px; padding-left: 14px; border-right: 1px solid rgba(220, 229, 242, .11); }
.stat:first-child { padding-left: 2px; }
.stat:last-child { border-right: 0; }
.stat-icon { grid-row: span 2; color: var(--gold); font-size: 17px; text-align: center; }
.stat-label { color: #aeb9ca; font-size: 10px; line-height: 1.3; }
.stat strong { color: #f9f0dd; font-family: Georgia, serif; font-size: 15px; font-weight: 500; letter-spacing: .05em; }

.board-frame { position: relative; padding: 10px; border: 1px solid rgba(125, 225, 214, .22); border-radius: 8px; background: linear-gradient(145deg, rgba(4, 17, 29, .96), rgba(10, 36, 44, .96)); box-shadow: inset 0 0 28px rgba(29, 197, 194, .09), 0 5px 20px rgba(0, 0, 0, .34); }
.board-glow { position: absolute; inset: 0; border-radius: inherit; background: radial-gradient(ellipse at 50% 45%, rgba(83, 201, 202, .1), transparent 72%); pointer-events: none; }
.tile-grid { position: relative; z-index: 1; display: grid; width: auto; height: 100%; max-width: 100%; aspect-ratio: 9 / 8; grid-template-columns: repeat(9, minmax(0, 1fr)); grid-template-rows: repeat(8, minmax(0, 1fr)); gap: 2px; container-type: inline-size; touch-action: none; user-select: none; }
.tile { position: relative; display: grid; width: 100%; height: 100%; min-width: 0; aspect-ratio: 1 / 1; place-items: center; padding: 0; overflow: hidden; border: 0; border-radius: clamp(5px, .7vw, 9px); color: var(--tile-color, #eaf5ee); background: transparent url("../assets/images/ui/pearl-tile.png") center / 122% auto no-repeat; box-shadow: none; cursor: pointer; transition: transform .16s ease, box-shadow .16s ease, opacity .18s ease; -webkit-tap-highlight-color: transparent; }
.tile::before { position: absolute; inset: 4px; border: 1px solid rgba(230, 231, 198, .1); border-radius: inherit; content: ""; pointer-events: none; }
.tile::after { position: absolute; inset: 0; content: ""; opacity: .62; background: radial-gradient(circle at 30% 22%, rgba(255, 255, 255, .17), transparent 38%); pointer-events: none; }
.tile::before, .tile::after { display: none; }
.tile-symbol { position: relative; z-index: 1; display: block; width: 82%; height: 82%; object-fit: contain; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .45)); pointer-events: none; transition: transform .15s ease, filter .15s ease; }
.tile:hover { z-index: 2; transform: translateY(-2px); box-shadow: 0 0 17px rgba(245, 207, 122, .5); }
.tile.is-selected { z-index: 3; box-shadow: 0 0 0 2px rgba(255, 220, 131, .7), 0 0 23px rgba(255, 204, 99, .55); }
.tile.is-swapping { z-index: 4; }
.tile.is-hint { z-index: 3; animation: hint-pulse .48s ease-in-out 3; }
.tile:focus-visible { outline-offset: 2px; }
.tile.type-0 { --tile-color: #ffd2e7; }
.tile.type-1 { --tile-color: #a9ebff; }
.tile.type-2 { --tile-color: #c9f49c; }
.tile.type-3 { --tile-color: #d3baff; }
.tile.type-4 { --tile-color: #ffe5a0; }
.tile.type-5 { --tile-color: #ffb79b; }
.tile.type-6 { --tile-color: #b6d6ff; }
.board-footer { display: flex; justify-content: space-between; gap: 10px; margin-top: 12px; color: #a6b5c2; font-size: 10px; }
.footer-sparkle { margin-right: 4px; color: var(--gold); font-style: normal; }


.page-footer { display: flex; justify-content: space-between; gap: 12px; padding: 13px 0 18px; border-top: 1px solid rgba(220, 229, 242, .13); color: #a8b2c2; font-family: Georgia, serif; font-size: 9px; letter-spacing: .11em; }
.footer-brand { color: var(--gold); }
.toast { position: fixed; z-index: 10; top: 92px; left: 50%; max-width: calc(100vw - 32px); padding: 10px 17px; border: 1px solid rgba(245, 207, 122, .4); border-radius: 5px; color: #f4e7ca; background: rgba(10, 24, 39, .96); font-size: 12px; opacity: 0; pointer-events: none; transform: translate(-50%, -8px); transition: .24s ease; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { border-color: rgba(255, 139, 128, .7); color: #ffe1dc; }

@keyframes hint-pulse { 50% { filter: brightness(1.6); transform: translateY(-3px) scale(1.05); box-shadow: 0 0 22px rgba(245, 207, 122, .7); } }



@media (min-width: 1500px) { .game-layout { gap: 100px; } }
@media (max-width: 900px) {
  .game-shell { width: min(720px, calc(100% - 36px)); }
  .game-layout { grid-template-columns: 1fr; gap: 24px; padding: 28px 0; }
  .intro { display: grid; grid-template-columns: 1fr auto; align-items: end; column-gap: 18px; }
  .intro .eyebrow, .intro h1, .intro-copy, .score-card, .how-to { grid-column: 1; }
  .intro .eyebrow { margin-bottom: 10px; }
  h1 { font-size: 46px; }
  .intro-copy { margin: 10px 0 15px; }
  .score-card { width: 245px; padding: 9px 12px; }
  .score-emblem { width: 34px; height: 34px; }
  .how-to { display: none; }
  .hint-button { grid-column: 2; grid-row: 2 / span 2; align-self: center; }
}
@media (max-width: 520px) {
  .game-shell { width: calc(100% - 24px); }
  .icon-button { width: 37px; height: 37px; font-size: 25px; }
  .game-layout { gap: 17px; padding: 20px 0; }
  .intro { grid-template-columns: 1fr auto; column-gap: 8px; }
  .eyebrow { font-size: 9px; }
  h1 { font-size: 37px; }
  .intro-copy { font-size: 12px; line-height: 1.6; }
  .score-card { width: 205px; gap: 9px; padding: 7px 9px; }
  .score-emblem { width: 30px; height: 30px; font-size: 17px; }
  .card-label { font-size: 9px; }
  .score-card strong { font-size: 16px; }
  .hint-button { gap: 5px; padding: 8px; font-size: 10px; }
  .board-panel { padding: 18px 12px; }
  .board-heading h2 { font-size: 17px; }
  .board-kicker { font-size: 9px; }
  .level-seal { width: 34px; height: 34px; }
  .board-frame { padding: 6px; }
  .tile { border-radius: 5px; }
  .tile::before { inset: 2px; }
  .stats { margin: 14px 0 12px; padding: 8px 0; }
  .stat { grid-template-columns: 15px auto; column-gap: 5px; padding-left: 7px; }
  .stat:first-child { padding-left: 0; }
  .stat-icon { font-size: 14px; }
  .stat-label { font-size: 9px; }
  .stat strong { font-size: 12px; }
  .board-footer { font-size: 9px; }
  .page-footer { flex-direction: column; align-items: center; padding-bottom: 14px; font-size: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

.game-layout {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  padding: 20px 0;
  transform: translateX(84px);
}
.board-panel {
  flex: 0 1 auto;
  width: min(720px, calc(100dvh - var(--pn-site-nav-height, 58px) - 334px), calc(100vw - 210px));
}
.heading-actions { display: flex; align-items: center; gap: 12px; }
.best-score-chip { display: grid; gap: 1px; min-width: 58px; text-align: right; }
.best-score-chip span { color: #b7c8cc; font-family: Georgia, serif; font-size: 8px; letter-spacing: .16em; }
.best-score-chip strong { color: #ffe4a0; font-family: Georgia, serif; font-size: 14px; font-weight: 500; }
.board-footer { align-items: center; }
.board-footer .hint-button { padding: 5px 9px; font-size: 10px; }
.board-footer .hint-button > span { font-size: 14px; }

.game-controls { display: flex; flex: 0 0 148px; flex-direction: column; align-items: center; align-self: stretch; justify-content: flex-start; gap: 14px; padding-top: 4px; }
.top-controls {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 214 / 74;
  background: url("../assets/images/ui/top-controls.png") center / 100% 100% no-repeat;
}
.round-control {
  position: absolute;
  top: 50%;
  width: 27%;
  height: auto;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: transparent;
  background: transparent;
  box-shadow: none;
  font-size: 0;
  cursor: pointer;
  transform: translate(-50%, -50%);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
#sound-button { left: 49.07%; }
#fullscreen-button { left: 81.78%; }
.round-control::after {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: transparent;
  content: "";
  pointer-events: none;
  transition: background .16s ease;
}
.round-control:hover::after { background: rgba(255, 232, 175, .13); }
.round-control:active::after { background: rgba(255, 232, 175, .25); }
.round-control:focus-visible { outline: 2px solid #fff0bd; outline-offset: 2px; }
.round-control span { display: none; }
.round-control.is-muted::after { background: rgba(10, 20, 30, .45); }
.power-dock {
  position: relative;
  flex: 0 0 auto;
  width: 116px;
  height: auto;
  aspect-ratio: 151 / 435;
  background: url("../assets/images/ui/power-dock.png") center / 100% 100% no-repeat;
}
.power-dock::before, .power-dock::after { display: none; }
.power-button {
  position: absolute;
  left: 50%;
  width: min(54%, 74.4px);
  height: auto;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: transparent;
  background: transparent;
  box-shadow: none;
  cursor: pointer;
  outline: none;
  transform: translate(-50%, -50%);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.power-button[data-power="shuffle"] { top: 19.8%; }
.power-button[data-power="bomb"] { top: 40.2%; }
.power-button[data-power="lightning"] { top: 61%; }
.power-button[data-power="hammer"] { top: 81.6%; }
.power-button::after {
  position: absolute;
  inset: -2px;
  border: 2px solid rgba(255, 231, 167, .9);
  border-radius: inherit;
  background: rgba(255, 225, 148, .08);
  box-shadow: 0 0 18px rgba(255, 214, 125, .8), inset 0 0 10px rgba(255, 245, 206, .28);
  content: "";
  opacity: 0;
  pointer-events: none;
  transform: scale(.88);
  transition: opacity .16s ease, transform .16s ease;
}
.power-button:hover:not(:disabled)::after,
.power-button.is-armed:not(:disabled)::after,
.power-button:focus-visible:not(:disabled)::after { opacity: 1; transform: scale(1); }
.power-button:active:not(:disabled)::after { background: rgba(255, 225, 148, .24); transform: scale(.9); }
.power-button:disabled { cursor: not-allowed; pointer-events: none; }
.power-button:disabled::after {
  border-color: rgba(190, 197, 200, .7);
  background: rgba(5, 13, 23, .62);
  box-shadow: inset 0 0 0 1px rgba(230, 235, 239, .25);
  opacity: 1;
  transform: none;
}
.power-button span { display: none; }

.settings-dialog {
  position: fixed;
  width: min(390px, calc(100% - 32px));
  max-height: min(80vh, 700px);
  overflow: auto;
  padding: 30px;
  border: 1px solid rgba(245, 207, 122, .52);
  border-radius: 10px;
  color: var(--ink);
  background: linear-gradient(145deg, #173342, #0b182a);
  box-shadow: 0 25px 80px rgba(0, 0, 0, .58), inset 0 0 30px rgba(62, 187, 195, .08);
}
.about-dialog {
  width: min(760px, calc(100% - 32px));
  max-height: min(86vh, 760px);
  padding: 32px;
}
.settings-dialog.about-dialog p.about-tagline {
  margin: 0 0 18px;
  color: #e7f2c4;
  font-size: 16px;
  font-weight: 600;
}
.about-dialog .about-section h3 {
  margin: 18px 0 6px;
  color: #f5cf7a;
  font-size: 15px;
}
.about-dialog .about-section h4 {
  margin: 12px 0 4px;
  color: #fff1cf;
  font-size: 13px;
}
.about-dialog .about-section p {
  margin: 0 0 12px;
  overflow-wrap: anywhere;
}
.about-dialog .about-section ul {
  margin: 0 0 14px;
  padding-left: 22px;
  color: #bdc9d3;
  font-size: 13px;
  line-height: 1.75;
}
.about-dialog .about-section li + li { margin-top: 4px; }
.about-dialog .about-section strong { color: #fff1cf; }
.about-dialog .about-section:first-of-type h3 { margin-top: 8px; }
@media (max-width: 520px) {
  .about-dialog { padding: 28px 20px; }
  .settings-dialog.about-dialog p.about-tagline { font-size: 14px; }
}
.settings-dialog::backdrop { background: rgba(3, 9, 20, .74); backdrop-filter: blur(5px); }
.settings-dialog h2 { margin: 0 0 8px; color: #fff1cf; font-size: 22px; font-weight: 500; }
.settings-dialog p:not(.board-kicker) { color: #bdc9d3; font-size: 13px; line-height: 1.8; }
.dialog-close { position: absolute; top: 8px; right: 12px; border: 0; color: #d7c6a0; background: none; font-size: 25px; cursor: pointer; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.summary-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 18px; }
.summary-stats > div { display: grid; gap: 4px; padding: 10px; border: 1px solid rgba(220, 229, 242, .13); border-radius: 6px; background: rgba(5, 17, 31, .3); }
.summary-stats span { color: #b7c8cc; font-size: 11px; }
.summary-stats strong { color: #fff0c8; font-family: Georgia, serif; font-size: 18px; font-weight: 500; }
.stage-dialog { width: min(560px, calc(100% - 32px)); max-height: min(86vh, 760px); padding: 28px; }
.mode-options { display: grid; gap: 10px; margin-top: 18px; }
.mode-option {
  display: grid;
  gap: 5px;
  padding: 14px 16px;
  border: 1px solid rgba(245, 207, 122, .38);
  border-radius: 7px;
  color: #f7f2e9;
  background: linear-gradient(115deg, rgba(22, 59, 57, .78), rgba(14, 28, 43, .9));
  text-align: left;
  cursor: pointer;
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
.mode-option:hover, .mode-option:focus-visible { border-color: var(--gold); background: rgba(70, 76, 43, .4); box-shadow: 0 0 18px rgba(245, 207, 122, .14); }
.mode-option strong { color: #ffe7ad; font-size: 15px; font-weight: 600; }
.mode-option span { color: #bfced1; font-size: 12px; line-height: 1.5; }
.stage-status-legend { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0; color: #c9d4d7; font-size: 10px; }
.stage-status-legend span::before { display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; content: ""; }
.stage-status-legend .is-unlocked::before { background: #81d8aa; }
.stage-status-legend .is-completed::before { background: var(--gold); }
.stage-status-legend .is-locked::before { background: #77828c; }
.stage-grid { display: grid; max-height: min(48vh, 390px); grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; overflow: auto; padding: 2px; }
.stage-choice {
  display: grid;
  min-width: 0;
  min-height: 72px;
  align-content: center;
  justify-items: center;
  gap: 3px;
  padding: 6px 3px;
  border: 1px solid rgba(129, 216, 170, .42);
  border-radius: 6px;
  color: #e9f4e9;
  background: linear-gradient(145deg, rgba(13, 51, 45, .8), rgba(8, 25, 38, .92));
  cursor: pointer;
}
.stage-choice:hover:not(:disabled), .stage-choice:focus-visible { border-color: #fff0bd; box-shadow: 0 0 14px rgba(245, 207, 122, .25); }
.stage-choice.is-current { outline: 1px solid rgba(245, 207, 122, .85); outline-offset: 1px; }
.stage-choice.is-completed { border-color: rgba(245, 207, 122, .7); color: #fff0c5; background: linear-gradient(145deg, rgba(86, 66, 30, .76), rgba(9, 29, 34, .94)); }
.stage-choice.is-locked { border-color: rgba(138, 150, 158, .25); color: #aab4bb; background: rgba(12, 21, 33, .85); }
.stage-choice:disabled { cursor: not-allowed; opacity: .6; }
.stage-choice-number { font-family: Georgia, serif; font-size: 18px; line-height: 1; }
.stage-choice-status { font-size: 9px; font-weight: 600; }
.stage-choice-best { min-height: 10px; color: #d7c58c; font-size: 8px; }
.dialog-secondary, .dialog-primary {
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid rgba(245, 207, 122, .42);
  border-radius: 5px;
  color: #e9dfc6;
  background: rgba(19, 34, 45, .92);
  cursor: pointer;
}
.dialog-primary { border-color: rgba(245, 207, 122, .78); color: #fff1c8; background: linear-gradient(135deg, rgba(25, 85, 59, .92), rgba(95, 69, 24, .92)); }
.dialog-secondary:hover, .dialog-primary:hover { border-color: #fff0bd; box-shadow: 0 0 14px rgba(245, 207, 122, .2); }
.stage-result { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; padding: 12px; border: 1px solid rgba(245, 207, 122, .28); border-radius: 6px; background: rgba(5, 17, 31, .36); }
.stage-result span { color: #bac9cf; font-size: 12px; }
.stage-result strong { color: #fff0c8; font-family: Georgia, serif; font-size: 23px; font-weight: 500; }
.stage-complete-actions { flex-wrap: wrap; }
.stage-complete-actions [hidden] { display: none; }

@media (max-width: 740px) {
  .game-shell { width: min(720px, calc(100% - 24px)); }
  .game-layout { flex-direction: column; gap: 14px; padding: 18px 0; transform: none; }
  .board-panel { width: 100%; max-width: min(720px, calc(100vw - 24px)); }
  .game-controls { order: -1; flex: 0 0 auto; flex-direction: row; justify-content: center; gap: 10px; width: 100%; }
  .top-controls { flex: 0 1 148px; width: min(148px, calc(100% - 89px)); }
  .power-dock { width: 82px; }
}
@media (max-width: 380px) {
  .game-controls { gap: 7px; }
  .top-controls { flex-basis: min(148px, calc(100% - 89px)); }
}

.game-shell { width: min(1240px, calc(100% - 48px)); }
.game-layout {
  display: grid;
  grid-template-columns: minmax(190px, 220px) minmax(0, 720px) 148px;
  justify-content: center;
  align-items: center;
  gap: 20px;
  width: 100%;
  padding: 20px 0;
  transform: none;
}
.game-info {
  position: relative;
  width: 220px;
  aspect-ratio: 768 / 1365;
  flex: 0 0 auto;
  padding: 0;
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  isolation: isolate;
}
.game-info-art { position: absolute; z-index: 0; inset: 0; display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; user-select: none; }
.game-info > :not(.game-info-art) { position: absolute; z-index: 1; }
.info-heading { inset: 0; pointer-events: none; }
.info-heading > div:first-child { position: absolute; inset: 0; }
.info-heading .board-kicker {
  position: absolute;
  top: 9.7%;
  left: 18%;
  width: 64%;
  margin: 0;
  color: #e7f2c4;
  font-size: calc(1.2 * clamp(8px, .7vw, 10px));
  text-align: center;
  text-shadow: 0 1px 4px #00150a;
}
.info-heading h2 {
  position: absolute;
  top: 23.8%;
  left: 19%;
  width: 42%;
  margin: 0;
  color: #fff6d5;
  font-size: calc(1.2 * clamp(10px, .95vw, 14px));
  font-weight: 600;
  text-align: center;
  text-shadow: 0 1px 4px #00150a;
  white-space: nowrap;
}
.heading-actions { position: absolute; inset: 0; pointer-events: none; }
.best-score-chip {
  position: absolute;
  top: 21%;
  left: 65%;
  display: grid;
  width: 18%;
  height: 8.5%;
  align-content: center;
  gap: 0;
  min-width: 0;
  text-align: center;
  text-shadow: 0 1px 4px #00150a;
}
.best-score-chip span { color: #fff1bd; font-size: calc(1.2 * clamp(6px, .58vw, 8px)); letter-spacing: .08em; }
.best-score-chip strong { color: #fff6cf; font-size: calc(1.2 * clamp(8px, .8vw, 11px)); font-weight: 700; }
.game-info .level-seal { display: none; }
.info-stats {
  inset: 0;
  display: contents;
  margin: 0;
  padding: 0;
}
.info-stats .stat {
  position: absolute;
  left: 28%;
  right: 14%;
  display: flex;
  height: 5.6%;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  margin: 0;
  padding: 0;
  border: 0;
  text-shadow: 0 1px 4px #00150a;
}
.info-stats .stat:nth-child(1) { top: 30.3%; }
.info-stats .stat:nth-child(2) { top: 36.8%; }
.info-stats .stat:nth-child(3) { top: 43.4%; }
.info-stats .stat:nth-child(4) { top: 50%; }
.info-stats .stat-icon { display: none; }
.info-stats .stat-label { color: #e3eedb; font-size: calc(1.2 * clamp(8px, .67vw, 10px)); line-height: 1.15; white-space: nowrap; }
.info-stats .stat strong { color: #fff4cf; font-family: Georgia, serif; font-size: calc(1.2 * clamp(9px, .78vw, 11px)); font-weight: 600; transform: translateX(-40px); }
.info-footer { inset: 0; pointer-events: none; }
.panel-about {
  position: absolute;
  top: 57.3%;
  left: 21.5%;
  display: grid;
  width: auto;
  height: auto;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 0;
  color: #ffe9a1;
  background: transparent;
  font-size: calc(1.2 * clamp(7px, .6vw, 9px));
  font-weight: 700;
  line-height: 1;
  text-align: center;
  text-shadow: 0 1px 3px #00150a;
  white-space: nowrap;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transform: translate(20px, 11px);
}
.panel-about::after {
  display: none;
}
.panel-about:hover, .panel-about:focus-visible { opacity: 1; }
.panel-about:focus-visible { outline: 0; }
.panel-hint {
  position: absolute;
  top: 82%;
  left: 16%;
  width: 15%;
  height: 7%;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: transparent;
  background: transparent;
  font-size: 0;
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.panel-hint > span { display: none; }
.panel-hint:hover { box-shadow: 0 0 15px rgba(255, 221, 130, .72); }
.panel-hint:active { background: rgba(255, 232, 175, .14); }
.panel-hint:focus-visible { outline: 2px solid rgba(255, 239, 182, .9); outline-offset: -3px; }
.session-controls {
  top: 65.3%;
  left: 13.4%;
  display: grid;
  width: 73.2%;
  height: 22%;
  grid-template-columns: 49.4% 47%;
  grid-template-rows: repeat(3, 28%);
  column-gap: 3.6%;
  row-gap: 8%;
  margin: 0;
  padding: 0;
}
.game-info .session-button {
  display: inline-flex;
  position: relative;
  min-width: 0;
  min-height: 0;
  align-items: center;
  justify-content: center;
  padding: 0 2% 0 22%;
  border: 0;
  border-radius: 20px;
  color: #fff3cd;
  background: transparent;
  font-size: calc(1.2 * clamp(7px, .65vw, 10px));
  font-weight: 600;
  line-height: 1.1;
  text-align: center;
  text-shadow: 0 1px 4px rgba(25, 0, 0, .85);
  white-space: nowrap;
  cursor: pointer;
  transition: transform .16s ease, filter .16s ease, opacity .16s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.game-info .session-button::after {
  position: absolute;
  inset: 7%;
  border-radius: inherit;
  background: rgba(255, 235, 175, .1);
  box-shadow: 0 0 15px rgba(255, 221, 140, .66), inset 0 0 10px rgba(255, 245, 206, .15);
  content: "";
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s ease, transform .16s ease;
}
.game-info .session-button:hover:not(:disabled)::after,
.game-info .session-button:focus-visible:not(:disabled)::after { opacity: 1; }
.game-info .session-button:active:not(:disabled) { filter: brightness(1.18); transform: scale(.96); }
.game-info .session-button:active:not(:disabled)::after { opacity: 1; transform: scale(.94); }
.game-info .session-button:focus-visible:not(:disabled) { outline: 2px solid rgba(255, 239, 182, .92); outline-offset: -3px; }
.game-info .session-button:disabled { opacity: .54; cursor: not-allowed; }
.game-info .mode-select-button {
  grid-column: 1 / -1;
  justify-self: center;
  align-self: center;
  top: 2px;
  width: 54%;
  height: calc(100% - 10px);
  padding: 0 8%;
  border: 1px solid rgba(245, 207, 122, .65);
  color: #fff1c8;
  background: linear-gradient(135deg, rgba(6, 28, 29, .94), rgba(92, 63, 23, .86));
  box-shadow: inset 0 0 9px rgba(245, 207, 122, .14), 0 0 10px rgba(0, 0, 0, .35);
}
.game-info .mode-select-button::after { inset: -5%; }
.tile-grid.is-paused { opacity: .48; filter: grayscale(.55); }
.board-panel { width: min(720px, calc(100dvh - var(--pn-site-nav-height, 58px) - 180px), calc(100vw - 456px)); padding: 10px; }
.board-frame { padding: 8px; }
.game-controls { align-self: center; justify-content: center; padding-top: 0; }
.power-button .power-count {
  position: absolute;
  display: grid;
  z-index: 1;
  bottom: 0;
  right: 0;
  width: 19px;
  height: 19px;
  place-items: center;
  border: 1px solid rgba(255, 229, 164, .95);
  border-radius: 50%;
  color: #fff5d5;
  background: rgba(8, 24, 31, .96);
  box-shadow: 0 0 8px rgba(255, 211, 112, .66);
  font-family: Georgia, serif;
  font-size: clamp(8px, .75vw, 11px);
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}
.power-button.is-depleted .power-count {
  color: #d9dce0;
  background: #343c47;
  border-color: #9198a3;
  box-shadow: none;
}
.top-controls { background: none; }
.top-controls::before {
  position: absolute;
  top: 0;
  left: 33.333%;
  width: 66.667%;
  height: 100%;
  background: url("../assets/images/ui/top-controls.png") right center / 150% 100% no-repeat;
  content: "";
  pointer-events: none;
}

@media (max-width: 900px) {
  .game-shell { width: min(720px, calc(100% - 24px)); }
  .game-layout { display: flex; flex-direction: column; gap: 12px; padding: 14px 0; transform: none; }
  .game-info-group { order: 0; margin: 0 auto; }
  .board-panel { order: 1; width: 100%; max-width: min(720px, calc(100vw - 24px)); padding: 7px; }
  .board-frame { padding: 6px; }
  .game-controls { order: 2; align-self: center; justify-content: center; flex-direction: row; width: 100%; padding-top: 0; }
  .top-controls { flex: 0 1 148px; width: min(148px, calc(100% - 89px)); }
  .power-dock { width: 82px; }
  .page-footer { flex-direction: column; align-items: center; }
}

.game-layout {
  --board-width: min(885px, calc(120.4vh - 197px), calc(100vw - 432px));
  --board-track-width: min(885px, calc(min(1320px, 100vw - 24px) - 408px));
  --status-panel-x: max(12px, calc((100vw - 1320px) / 2 + 13.5px));
  /* Account for the dock image's transparent edges when sizing and spacing it. */
  --tools-visible-left: calc(var(--status-panel-x) + 240px + (var(--board-track-width) + var(--board-width)) / 2 - var(--board-width) * .093 + 30px);
  --tools-width: min(
    139.2px,
    max(0px, calc((100dvh - var(--pn-site-nav-height, 58px) - 230px) * 151 / 435)),
    max(0px, calc((100vw - var(--tools-visible-left)) / .92715))
  );
  --tools-shift-x: calc(-64px + var(--tools-width) * .42715 - (var(--board-track-width) - var(--board-width)) / 2 - var(--board-width) * .093);
  width: min(1320px, calc(100vw - 24px));
  align-self: center;
  grid-template-columns: minmax(190px, 220px) minmax(0, 885px) 148px;
}
/* Account for transparent padding so the visible artwork keeps a 30px gap. */
.game-info-group {
  display: flex;
  width: 264px;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  transform: translateX(max(
    calc((var(--board-track-width) - var(--board-width)) / 2 + var(--board-width) * .093 - 32.35px),
    calc(-21.31px - var(--status-panel-x))
  ));
}
.game-info {
  width: 100%;
  transform: none;
}
.board-panel {
  width: var(--board-width);
  aspect-ratio: 925 / 768;
  container-type: inline-size;
  display: grid;
  place-items: center;
  justify-self: center;
  overflow: visible;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: url("../assets/images/ui/board-frame.png") center / 100% 100% no-repeat;
  box-shadow: none;
  backdrop-filter: none;
}
/* Align with the visible edge inside the frame image's transparent margin. */
.stage-target-score {
  position: absolute;
  z-index: 2;
  top: 10%;
  right: 2%;
  display: flex;
  align-items: baseline;
  gap: 5px;
  max-width: 98%;
  color: #ffe5a4;
  line-height: 1.05;
  text-align: right;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .8);
  pointer-events: none;
  white-space: nowrap;
  transform: translate(-50px, calc(-100% - 15px));
}
.stage-target-score[hidden] { display: none; }
.stage-target-score > strong {
  color: #fff8e9;
  font-family: Georgia, serif;
  font-size: clamp(24px, 4.1cqw, 28px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .8);
}
.stage-target-score > #stage-target-score-value { color: #ffe49a; }
.stage-target-score > .stage-score-separator { color: #e8d39e; font-size: clamp(24px, 4.1cqw, 28px); font-weight: 700; }
.board-panel::before, .board-panel::after { display: none; }
.board-frame {
  display: grid;
  place-items: center;
  width: 75.3%;
  height: 75.4%;
  margin: 0 auto;
  top: 1.82%;
  left: -.27%;
  padding: 8px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
.power-dock {
  width: var(--tools-width);
  transform: translate(
    var(--tools-shift-x),
    -37.7px
  );
}
.top-controls {
  width: 177.6px;
  transform: translate(calc(var(--tools-shift-x) - 27.4px), -20px);
}
.board-glow { display: none; }

@media (max-width: 900px) {
  .board-panel {
    width: 100%;
    max-width: min(720px, calc(100vw - 24px));
    margin: 42px 0 -42px;
  }
  .stage-target-score { top: 8.3%; }
  .stage-target-score > strong,
  .stage-target-score > .stage-score-separator { font-size: clamp(14px, 4.1cqw, 24px); }
  .game-layout { width: 100%; align-self: stretch; }
  .game-info-group { width: min(264px, 80vw, 100%); }
  .game-info { width: 100%; }
  .game-info-group, .game-info, .power-dock, .top-controls { transform: none; }
  .top-controls { width: min(148px, calc(100% - 89px)); }
  .power-dock { width: min(98.4px, calc(100vw - 24px)); }
}

@media (max-width: 740px) {
  .board-panel {
    width: 100%;
    max-width: min(720px, calc(100vw - 24px));
    aspect-ratio: 1;
  }
  .tile-grid { width: 100%; height: auto; max-height: 100%; }
}

@media (max-width: 320px) {
  body { min-width: 0; }
}

@media (max-width: 520px) {
  .stage-target-score { top: 0; }
  .stage-target-score > strong,
  .stage-target-score > .stage-score-separator { font-size: clamp(9px, 2.8cqw, 14px); }
  .stage-dialog { padding: 25px 16px 18px; }
  .stage-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .stage-choice { min-height: 66px; }
  .stage-complete-actions { justify-content: center; }
}
@media (max-width: 360px) {
  .stage-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stage-status-legend { gap: 7px; font-size: 9px; }
}

.power-dock > .stage-progress {
  position: absolute;
  /* The painted dock ends at pixel 141 of the 151px-wide image. */
  left: calc(14100% / 151 + 10px);
  inset-block: 8% 8%;
  display: grid;
  grid-template-columns: 8px 1fr;
  align-items: stretch;
  gap: 3px;
  width: 32px;
  color: #d7f4c9;
  text-shadow: 0 1px 3px #04160f;
  pointer-events: none;
}
.stage-progress[hidden] { display: none; }
.stage-progress-track {
  position: relative;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(3, 31, 21, .85);
  box-shadow: 0 0 0 1px rgba(245, 207, 122, .55);
}
.stage-progress-track > span {
  position: absolute;
  inset: auto 0 0;
  height: 0;
  border-radius: inherit;
  background: linear-gradient(0deg, #087442, #18a96a 58%, #79e89b);
  transition: height .42s ease;
}
.stage-progress-heading {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
  line-height: 1;
}
.stage-progress-heading span {
  writing-mode: vertical-rl;
  font-size: 10px;
}
.stage-progress-heading strong {
  font: 700 11px/1 Georgia, serif;
  font-variant-numeric: tabular-nums;
}
.game-layout[data-mode="stage"] .board-panel { margin-bottom: 0; }

@media (max-height: 520px) {
  .home-status { bottom: 68px; }
  .home-play, .home-retry { min-height: 36px; padding-block: 7px; }
}

.game-layout {
  flex: 0 0 auto;
  padding-top: 10px;
}

@media (max-width: 900px), (orientation: portrait) and (max-width: 1100px) {
  .game-shell { width: calc(100% - 24px); }
  .game-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(64px, 15vw, 130px);
    grid-template-areas: "board tools" "info info";
    align-items: start;
    align-self: stretch;
    width: 100%;
    gap: 20px 0;
  }
  .game-layout .board-panel,
  .game-layout[data-mode="stage"] .board-panel {
    grid-area: board;
    width: 100%;
    max-width: 885px;
    aspect-ratio: 925 / 768;
    margin: 0;
    padding: 0;
  }
  .game-info-group {
    grid-area: info;
    justify-self: center;
    margin: 0;
    transform: none;
  }
  .game-controls {
    grid-area: tools;
    align-self: center;
    flex-direction: column;
    width: 100%;
    gap: 6px;
  }
  .top-controls { flex: 0 0 auto; width: 100%; transform: translateX(-10%); }
  .power-dock { width: min(78%, 112px); transform: none; }
}
@media (max-width: 520px) {
  .game-layout { gap: 28px 0; }
  .board-frame { padding: 3px; }
  .stage-target-score { top: 10%; right: 12%; transform: none; }
  .tile-grid { gap: 1px; }
}

/* The wide layout places both sections in the same row. */
@media (min-width: 901px) and (orientation: landscape), (min-width: 1101px) {
  .game-info-group, .board-panel { align-self: end; }
  .game-info-group {
    /* The bottom 37 pixels of the 1365-pixel panel artwork are transparent. */
    margin-bottom: -12.72px;
  }
}

/* Crop the original scene from the top in the portal's 560px design viewport. */
.pn-embedded-game body {
  min-width: 0;
  isolation: isolate;
}
.pn-embedded-game body::after {
  position: fixed;
  z-index: -2;
  inset: 0 0 auto;
  height: max(840px, 100dvh);
  content: "";
  pointer-events: none;
  background: var(--game-background, linear-gradient(135deg, #091323, #061e2a));
  background-attachment: scroll;
  background-position: center top;
}

.pn-embedded-game .game-shell {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  width: 100%;
  height: 100dvh;
  min-height: 0;
  padding: 0 10px 8px;
}
.pn-embedded-game .game-layout {
  box-sizing: border-box;
  align-self: stretch;
  display: grid;
  grid-template-columns: minmax(132px, 20%) minmax(0, 1fr) minmax(132px, 20%);
  grid-template-areas: "info board tools";
  grid-template-rows: minmax(min-content, 1fr);
  align-items: center;
  width: 100%;
  min-height: 0;
  gap: 8px;
  padding: 8px 2px;
  overflow: auto;
  overscroll-behavior: contain;
}
.pn-embedded-game .game-info-group {
  grid-area: info;
  width: min(230px, 100%);
  justify-self: center;
  align-self: center;
  margin: 0;
  transform: none;
}
.pn-embedded-game .game-layout .board-panel {
  grid-area: board;
  width: min(100%, calc((100dvh - 52px) * 925 / 768));
  max-width: 100%;
  aspect-ratio: 925 / 768;
  align-self: center;
  margin: 0;
}
.pn-embedded-game .game-controls {
  grid-area: tools;
  width: 100%;
  align-self: center;
  flex-direction: column;
  gap: 8px;
}
.pn-embedded-game .top-controls { width: min(124px, 100%); transform: none; }
.pn-embedded-game .power-dock { width: min(102px, 95%); transform: none; }
.pn-embedded-game .stage-target-score { top: 7%; right: 12%; transform: none; }
.pn-embedded-game .tile-grid { width: auto; height: 100%; max-width: 100%; }
.pn-embedded-game .page-footer {
  flex-flow: row wrap;
  align-items: center;
  justify-content: space-between;
  gap: 3px 8px;
  padding: 5px 2px 0;
}

@media (max-width: 520px) {
  .pn-embedded-game .game-layout {
    grid-template-columns: minmax(0, 1fr) clamp(58px, 16vw, 100px);
    grid-template-areas: "board tools" "info info";
    grid-template-rows: auto auto;
    align-content: start;
  }
  .pn-embedded-game .game-info-group { margin-top: 8px; }
}

@media (min-width: 521px) {
  .pn-embedded-game .game-layout {
    container-type: size;
    grid-template-rows: minmax(0, 1fr);
    --panel-gap: 20px;
    transform: none;
  }
  .pn-embedded-game .game-layout > :is(.game-info-group, .board-panel, .game-controls) {
    --side-track: max(132px, 20cqw);
    --center-to-side: calc((100cqw - var(--side-track)) / 2);
    /* The 12px shell and grid padding already counts toward the 20px margin.
       381.604 is the combined reach of the gold frame and visible left panel
       at the reference sizes below; the right side is narrower. */
    --fit-unit: min(calc((50cqw - 8px - var(--panel-gap)) / 381.604),
                    calc((100cqh - 6px) / 456.65));
    --board-box: min(calc(550 * var(--fit-unit)), calc(100cqh * 925 / 768));
    --info-box: calc(190 * var(--fit-unit));
    --dock-box: calc(102 * var(--fit-unit));
    --top-controls-box: calc(124 * var(--fit-unit));
    --board-reach: calc(var(--board-box) * (0.5 - 87 / 925));
  }
  .pn-embedded-game .game-layout .board-panel {
    width: var(--board-box);
    max-width: none;
  }
  .pn-embedded-game .game-info-group {
    position: relative;
    width: var(--info-box);
    --info-right-reach: calc(var(--info-box) * (703 / 768 - 0.5));
    left: calc(var(--center-to-side) - var(--board-reach) - var(--info-right-reach) - var(--panel-gap));
  }
  .pn-embedded-game .game-controls {
    --dock-shift: calc(var(--board-reach) + var(--dock-box) * (0.5 - 12 / 151) + var(--panel-gap) - var(--center-to-side));
  }
  .pn-embedded-game .top-controls {
    width: var(--top-controls-box);
    /* Align the midpoint of both button centers with the bomb's center. */
    left: calc(var(--dock-shift) + var(--top-controls-box) * (0.5 - (0.4907 + 0.8178) / 2));
  }
  .pn-embedded-game .power-dock {
    width: var(--dock-box);
    left: var(--dock-shift);
  }
}

.game-controls > .stage-target-score {
  position: relative;
  top: auto;
  right: auto;
  left: var(--dock-shift, var(--tools-shift-x, 0px));
  width: var(--dock-box, var(--tools-width, 100%));
  align-self: center;
  justify-content: center;
  text-align: center;
  transform: none;
}
.game-controls > .stage-target-score > strong,
.game-controls > .stage-target-score > .stage-score-separator {
  font-size: clamp(12px, 2.5cqw, 18px);
}
@media (max-width: 520px) {
  .pn-embedded-game .game-controls > .stage-target-score {
    left: 0;
    width: min(102px, 95%);
  }
}


@media (max-width: 520px) {
  .pn-embedded-game .game-layout {
    grid-template-columns: minmax(0, 1fr) clamp(80px, 21vw, 110px);
  }
  .pn-embedded-game .game-controls .power-dock {
    width: min(72px, calc(100% - 35px));
    left: -12px;
  }
}
