:root {
  color-scheme: light;
  font-family: "Microsoft YaHei", system-ui, sans-serif;
  color: #25213c;
  background: #eae5f8;
  font-synthesis: none;
  --ink: #221d37;
  --paper: #faf7ff;
  --lime: #d5fb8c;
}
* { box-sizing: border-box; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
body {
  margin: 0; min-height: 100svh;
  background: radial-gradient(ellipse at 45% 40%, #303049, transparent 70%), #191925;
}
button { font: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 3px solid #6c47ca; outline-offset: 3px; }
button:disabled { cursor: default; opacity: .45; }
.mobile-heading { display: none; }
.layout {
  --cabinet-max: clamp(265px, calc((100svh - 204px) * .8), 460px);
  display: grid;
  grid-template-columns: minmax(0, var(--cabinet-max)) minmax(240px, 285px);
  justify-content: center;
  gap: clamp(24px, 5vw, 72px);
  align-items: center;
  width: min(100% - 32px, 850px);
  min-height: 100svh;
  margin: auto;
  padding-block: 24px;
}
.cabinet {
  border: 2px solid #78748e;
  border-radius: 5px;
  background: #262638;
  color: #fcf6e8;
  box-shadow: 0 5px 0 #0f0e18, 0 0 0 2px #171621;
  overflow: hidden;
}
.scoreboard {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) 1.1fr .7fr .8fr;
  align-items: center;
  padding: 12px 16px;
}
.scoreboard div { display: grid; gap: 3px; min-width: 0; align-content: center; }
.scoreboard div:not(.current-level) { border-left: 1px solid #49475c; padding-left: clamp(5px, 1.4vw, 12px); }
.scoreboard span { font-size: .8rem; color: #c2bfd1; }
.scoreboard #score, .scoreboard #lives, .scoreboard #remaining {
  font: bold 1rem/1.15 ui-monospace, monospace;
}
#score { color: #ffd373; }
#lives { color: #ffbaa6; }
#remaining { color: #bde6ee; }
#mode-label { color: var(--lime); }
.scoreboard strong { font-size: .96rem; font-variant-numeric: tabular-nums; }
.current-level { padding-right: 6px; }
.cabinet:has(.court[data-result]) .scoreboard div:not(.current-level) { display: none; }
.cabinet:has(.court[data-result]) .current-level { grid-column: 1 / -1; }
.progress { height: 4px; background: #494458; }
#progress-fill { height: 100%; background: var(--lime); transform: scaleX(0); transform-origin: left; }
.court {
  position: relative;
  background-color: var(--ink);
  background-image: radial-gradient(circle, #382f50 .55px, transparent .8px);
  background-size: 4% 3.2%;
}
#brick-layer { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#board { position: relative; display: block; width: 100%; height: auto; aspect-ratio: 4 / 5; touch-action: none; }
#board:focus-visible { outline: 2px solid var(--lime); outline-offset: -4px; }
.active-powers {
  position: absolute;
  inset: 3px 6px auto;
  display: flex;
  justify-content: center;
  gap: 3px;
  margin: 0;
  padding: 0;
  list-style: none;
  pointer-events: none;
}
.active-powers[hidden], .active-powers li[hidden] { display: none; }
.active-powers li {
  border-radius: 4px;
  padding: 1px 4px;
  color: var(--ink);
  font-size: .72rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.overlay {
  position: absolute;
  left: 50%;
  top: 68%;
  transform: translate(-50%, -50%);
  display: grid;
  gap: 12px;
  justify-items: center;
  width: min(86%, 260px);
  padding: 16px;
  border: 1px solid #66587e;
  border-radius: 14px;
  background: #2b2441;
  color: #faf7ff;
  text-align: center;
}
.overlay[hidden] { display: none; }
.overlay[data-aiming] { pointer-events: none; }
.overlay[data-aiming] button { pointer-events: auto; }
.overlay h2 { margin: 0; font-size: 1rem; }
.court:not([data-result]) .overlay {
  border: 2px solid #767286;
  border-top-color: var(--lime);
  border-radius: 2px;
  background: #232333;
  box-shadow: 3px 3px #15131e;
}
.court:not([data-result]) .round-actions button {
  border-radius: 2px;
  box-shadow: inset 0 -3px #0002;
}
.result-emblem, .result-emblem g { display: none; }
.court[data-result="won"] .cup, .court[data-result="lost"] .broken-ball { display: inline; }
.court[data-result] { --prize: #ffd373; --rim: #a87948; }
.court[data-result="lost"] { --prize: #ffaf99; --rim: #a36376; }
.court[data-result] .overlay {
  top: auto;
  bottom: 4%;
  transform: translateX(-50%);
  width: min(94%, 320px);
  gap: 8px;
  padding: 11px;
  text-align: left;
  border: 2px solid var(--rim);
  border-radius: 0;
  background: #211d35;
  box-shadow: 0 3px #141020, 3px 0 #141020, -3px 0 #141020, 0 -3px #141020;
}
.court[data-result] .overlay-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 4px 0 7px;
  border-bottom: 2px dotted var(--rim);
}
.court[data-result] .result-emblem { display: block; width: 32px; height: 32px; flex: none; }
.court[data-result] .overlay-heading h2 {
  color: var(--prize);
  font-size: 1.35rem;
  font-weight: 900;
  line-height: 1.15;
  text-shadow: 1px 2px #56364c;
}
.court[data-result] .result-rating { margin-left: auto; font-size: 1.12rem; letter-spacing: 1px; }
@media (prefers-reduced-motion: no-preference) {
  .court[data-result] .overlay { animation: settle-score 240ms ease-out both; }
  .court[data-result="won"] .result-emblem { animation: award-cup 380ms ease-out both; }
}
@keyframes settle-score {
  from { opacity: 0; transform: translate(-50%, 7px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes award-cup {
  from { transform: scale(.7); }
  65% { transform: scale(1.12); }
  to { transform: scale(1); }
}
.court[data-result="won"] #brick-layer { animation: reveal-pattern 460ms ease-out both; }
@media (prefers-reduced-motion: no-preference) {
  .court[data-finale]::after {
    content: "";
    position: absolute;
    pointer-events: none;
    left: var(--hit-x);
    top: var(--hit-y);
    width: 4px;
    height: 4px;
    background: #fff5cf;
    box-shadow: -6px 0 #ffd373, 6px 0 #ffd373, 0 -6px #ffd373, 0 6px #ffd373;
    animation: final-spark 230ms ease-out both;
  }
  .court[data-finale] #brick-layer { animation: reveal-pattern 320ms 140ms ease-out both; }
  .court[data-finale] .overlay { animation: present-award 200ms 650ms ease-out both; }
  .court[data-finale] .result-emblem { animation-delay: 650ms; }
  @keyframes final-spark {
    from { transform: translate(-50%, -50%) scale(.75); }
    60% { opacity: 1; }
    to { transform: translate(-50%, -50%) scale(2); opacity: 0; }
  }
  @keyframes present-award {
    from { visibility: hidden; opacity: 0; transform: translate(-50%, 6px); }
    to { visibility: visible; opacity: 1; transform: translate(-50%, 0); }
  }
}
@keyframes reveal-pattern {
  from { clip-path: inset(0 0 100%); }
  to { clip-path: inset(0); }
}
@media (prefers-reduced-motion: reduce) {
  .court[data-result="won"] #brick-layer { animation: none; }
}
.resume-count {
  position: absolute;
  top: 62%;
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 10px;
  border-radius: 8px;
  pointer-events: none;
  background: #2b2441;
  color: var(--lime);
  font-weight: 750;
  white-space: nowrap;
}
.round-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.overlay[data-confirm-restart] #action { order: 1; }
.overlay[data-confirm-restart] .round-actions button { min-width: 0; padding-inline: 10px; }
.court[data-result] .round-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: 100%;
}
.court[data-result] .round-actions button {
  min-width: 0;
  min-height: 44px;
  padding-inline: 6px;
}
.court[data-result] #action, .court[data-result] #result-levels { grid-column: 1 / -1; }
.court[data-result] #action {
  min-width: 0; padding-inline: 6px; border-radius: 2px;
  background: var(--prize); box-shadow: inset 0 -3px #0003, inset 0 2px #fff6;
}
.court[data-result] .round-actions button:not(#action) {
  font-size: .8rem; border-radius: 2px;
}
#restart, #view-pattern, #result-levels {
  padding: 7px 9px;
  border: 1px solid #887ba2;
  border-radius: 8px;
  color: #faf7ff;
  background: transparent;
  font-size: .88rem;
}
.result-summary { width: 100%; }
.result-stats {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  margin: 0;
  background: #181627;
}
.result-metric { min-width: 0; padding: 6px 9px; }
.result-metric + .result-metric { border-inline-start: 1px solid #66587e; }
.result-metric dt, .result-comparison, #result-detail { color: #dfd5f3; font-size: .75rem; }
.result-metric dt, .result-comparison { line-height: 1.25; }
.result-metric dd { margin: 0; font-variant-numeric: tabular-nums; }
#result-score, #result-duration { font-size: 1.2rem; line-height: 1.2; font-weight: 750; overflow-wrap: anywhere; }
#result-score { font: 800 1.55rem/1.15 ui-monospace, monospace; color: var(--prize); }
#result-detail { margin: 6px 0 0; line-height: 1.35; }
.level-time { color: #5d5177; font-size: .78rem; font-variant-numeric: tabular-nums; }
.result-rating { flex: none; margin: 0; color: #ffdb87; font-size: .875rem; font-weight: 750; white-space: nowrap; }
@media (max-width: 650px) and (max-height: 500px), (orientation: landscape) and (max-height: 580px) {
  .court[data-result] .overlay { gap: 6px; padding: 8px; }
  .court[data-result] .overlay-heading h2 { font-size: 1rem; }
  .court[data-result] .result-emblem { width: 24px; height: 24px; }
  .court[data-result] .overlay-heading { padding: 0 0 4px; }
  .result-metric { padding: 4px 6px; }
  #result-score, #result-duration { font-size: 1.05rem; }
  .court[data-result="won"] .round-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .court[data-result] .round-actions :is(#action, #result-levels) { grid-column: auto; }
  .court[data-result] #action { padding-inline: 2px; font-size: .82rem; }
  .court[data-result] .round-actions button:not(#action) { padding-inline: 2px; font-size: .75rem; }
}
.combo {
  grid-column: 1 / -1;
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: #eee8fa;
  font-size: .78rem;
  font-variant-numeric: tabular-nums;
}
#next-preview:not([hidden]) {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff2d6;
  font-size: .8rem;
}
.scoreboard:has(#next-preview:not([hidden])) { grid-template-columns: 1fr 1.4fr; }
.cabinet:has(#next-preview:not([hidden])) .current-level { grid-column: auto; }
#next-preview canvas { width: 32px; height: 32px; image-rendering: pixelated; background: #191724; }
.court[data-result] .round-actions:has(#next-giant:not([hidden])) {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.court[data-result] .round-actions:has(#next-giant:not([hidden])) #action { grid-column: auto; }
.court[data-result] #next-giant {
  background: #91e5cc; color: #172d28; font-weight: 750; border: 0;
  box-shadow: inset 0 -3px #0003, inset 0 2px #fff6;
}
.cabinet:has(#next-preview:not([hidden])) #effect { display: none; }
.combo[hidden] { display: none; }
.toolbar:has(.combo:not([hidden])) #effect { visibility: hidden; grid-row: 1; }
#combo-tier { color: #ffd373; }
.combo-meter { display: flex; gap: 2px; }
.combo-meter i { width: 8px; height: 5px; background: #565265; }
.combo[data-charge="1"] i:first-child, .combo[data-charge="2"] i:nth-child(-n+2),
.combo[data-charge="3"] i { background: #ffd373; }
#action {
  border: 0;
  border-radius: 8px;
  background: var(--lime);
  color: var(--ink);
  font-weight: 750;
  min-width: 108px;
  padding: 8px 18px;
}
.toolbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px 6px;
  padding: 4px 12px 8px;
}
.toolbar button, .menu-heading button, .switch-actions button, .play-modes button, .save-actions button,
.more-actions button, .settings-row button, #pattern-save, #pattern-zoom, #pattern-web-export {
  border: 1px solid #d3c9e4;
  border-radius: 8px;
  background: #f2ecfb;
  color: var(--ink);
  padding: 6px 11px;
}
#effect { grid-column: 1 / -1; min-height: 1.4em; font-size: .8rem; font-weight: 650; text-align: center; }
.cabinet:has(.court[data-result="lost"]) #effect { display: none; }
.toolbar button { min-height: 44px; white-space: nowrap; }
.toolbar:has(#pause[hidden]) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.toolbar button {
  border-radius: 3px; border-color: #555368; background: #363546; color: #faf6ed;
  box-shadow: inset 0 -2px #222130;
}
.toolbar button::before {
  content: ""; display: inline-block; vertical-align: .04em;
  width: 10px; height: 10px; margin-inline-end: 6px;
}
#levels-open::before { background: conic-gradient(currentColor 25%, transparent 0 50%, currentColor 0 75%, transparent 0) 0 0 / 7px 7px; }
#pause { border-color: #b2c991; background: #d5edaf; color: #27321e; font-weight: 750; box-shadow: inset 0 -2px #aac58c; }
#pause::before { border-inline: 3px solid currentColor; width: 3px; }
#more-open::before { height: 3px; background: repeating-linear-gradient(to right, currentColor 0 2px, transparent 2px 4px); }
.toolbar button:active, .round-actions button:active { transform: translateY(1px); }
#effect { color: #d3d1df; }
.cabinet button:focus-visible { outline-color: #a9deff; }
.more-actions { display: grid; gap: 8px; margin-top: 12px; }
.more-actions button { display: flex; align-items: center; justify-content: space-between; min-height: 48px; font-weight: 700; }
.more-actions button::after {
  content: '';
  width: 7px;
  height: 7px;
  margin-right: 3px;
  border: solid #5d5177;
  border-width: 1.5px 1.5px 0 0;
  transform: rotate(45deg);
}
.side, .mobile-heading { color: #fcf6e8; }
.brand { color: var(--lime); font-weight: 750; margin: 0 0 9px; letter-spacing: .18em; }
.side h1 { text-shadow: 3px 3px #584768; }
.key-guide { margin: 24px 0 0; padding-top: 14px; border-top: 2px dotted #605769; }
.key-guide div { display: flex; align-items: center; gap: 10px; margin-block: 8px; }
.key-guide dt { min-width: 50px; }
.key-guide dd { margin: 0; color: #d0cad9; font-size: .87rem; }
.key-guide kbd { display: inline-block; padding: 2px 5px; border: 1px solid #81778c; border-bottom-width: 3px; border-radius: 3px; font: inherit; font-size: .8rem; }
h1 { margin: 0; font-size: clamp(2rem, 4vw, 3rem); letter-spacing: -.06em; line-height: 1.1; }
.instructions { line-height: 1.65; margin: 14px 0 20px; color: #534769; }
.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}
.settings-row[hidden] { display: none; }
.settings-row button { min-width: 64px; min-height: 44px; }
.range-setting { margin-top: 10px; }
.range-setting > div { display: flex; justify-content: space-between; gap: 8px; }
.range-setting output { color: #5d5177; font-size: .875rem; font-variant-numeric: tabular-nums; }
.range-setting input { display: block; width: 100%; height: 44px; margin: 0; accent-color: #6744b4; }
.level-summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 10px;
  margin: 8px 0 12px;
  color: #5d5177;
  font-size: .85rem;
}
.play-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.play-modes button { min-height: 44px; }
.play-modes button[aria-pressed="true"] { border-color: #6744b4; background: #e6d9ff; font-weight: 750; }
.mode-description { margin: 8px 0 0; color: #5d5177; font-size: .85rem; }
.continue-round {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 3px 8px;
  width: 100%;
  min-height: 48px;
  margin-top: 8px;
  padding: 7px 12px;
  border: 1px solid #52733e;
  border-radius: 8px;
  background: var(--lime);
  color: var(--ink);
  text-align: left;
}
.continue-round[hidden] { display: none; }
.continue-round span { color: #365421; font-size: .78rem; }
@media (max-width: 360px) {
  .continue-round { grid-template-columns: 1fr; }
}
.level-groups { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-bottom: 10px; }
.level-groups button {
  display: grid;
  justify-items: center;
  min-height: 44px;
  padding: 4px;
  color: var(--ink);
  background: #f2ecfb;
  border: 1px solid #d3c9e4;
  border-radius: 8px;
}
.level-groups button[aria-pressed="true"] { background: var(--lime); border-color: #52733e; font-weight: 750; }
.level-groups small { font-variant-numeric: tabular-nums; font-size: .75rem; }
.levels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.level-card { min-width: 0; }
.level-card:has(.level-chart:not([hidden])) {
  padding: 3px;
  background: var(--paper);
  border: 1px solid #d3c9e4;
  border-radius: 10px;
}
.level-play {
  display: grid;
  grid-template-columns: minmax(0, 50px) minmax(0, 1fr);
  width: 100%;
  min-height: 77px;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 8px;
  text-align: left;
  background: var(--paper);
  border: 2px solid #d3c9e4;
  border-radius: 10px;
  color: var(--ink);
}
.level-play[aria-current="step"] { background: #eefbd7; border-color: #52733e; }
.level-details { display: grid; gap: 3px; justify-items: start; }
.level-details strong { font-size: .88rem; overflow-wrap: anywhere; }
.level-chart {
  width: 100%;
  min-height: 44px;
  margin-top: 3px;
  border: 0;
  border-radius: 6px;
  color: #513498;
  background: #f2ecfb;
  font-size: .85rem;
  font-weight: 700;
}
.levels canvas {
  display: block;
  width: 100%;
  height: auto;
  padding: 4px;
  border-radius: 6px;
  background: #31284d;
  image-rendering: pixelated;
}
.level-best { color: #5d5177; font-size: .8rem; }
.level-status { color: #365421; font-size: .78rem; font-weight: 750; }
#switch-title { margin: 0; font-size: 1.2rem; }
#switch-note { margin: 8px 0 16px; font-size: .9rem; line-height: 1.55; }
.switch-actions { display: flex; justify-content: flex-end; gap: 8px; }
.switch-actions button { min-height: 44px; }
#switch-confirm { background: var(--lime); border-color: #52733e; }
.power-guide { margin-top: 12px; }
.save-tools { border-top: 1px solid #cfc4e2; margin-top: 12px; padding-top: 12px; }
.save-tools summary { min-height: 36px; cursor: pointer; font-weight: 700; }
.save-tools p { margin: 0 0 8px; color: #5d5177; font-size: .85rem; }
.save-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.save-actions button { min-height: 44px; }
#save-status { margin-top: 8px; }
.power-guide .instructions { margin: 0 0 12px; }
.power-guide ul { display: grid; grid-template-columns: 1fr 1fr; gap: 9px 6px; list-style: none; padding: 0; margin: 0; }
.power-guide li { display: flex; align-items: center; gap: 6px; font-size: .86rem; }
.power-guide b { display: grid; place-items: center; width: 28px; height: 23px; border-radius: 5px; color: var(--ink); }
.power-guide b { flex-shrink: 0; }
.power-guide b svg { width: 18px; height: 16px; }
.power-guide small { display: block; color: #584e68; }
.active-powers li svg { width: 14px; height: 13px; vertical-align: -.13em; }
.active-powers li span:not(:empty) { margin-inline-start: 2px; }
.split { background: #ffd287; }
.wide { background: #d5fb8c; }
.pierce { background: #fdb1e7; }
.burst { background: #ffa994; }
.laser { background: #addcff; }
.giant { background: #7ff0cf; }
.shield { background: #bfb2ff; }
body:has(.game-dialog[open]) { overflow: hidden; }
.game-dialog {
  width: min(100% - 24px, 440px);
  max-width: 100%;
  max-height: calc(100dvh - env(safe-area-inset-top) - 20px);
  padding: 16px;
  border: 1px solid #d3c9e4;
  border-radius: 18px;
  background: #eae5f8;
  color: var(--ink);
  overscroll-behavior: contain;
}
.game-dialog::backdrop { background: #221d37ad; }
.game-dialog .menu-heading { padding-bottom: 8px; border-bottom: 2px dotted #a89eb8; }
.game-dialog .menu-heading h2 { border-left: 5px solid #795a9f; padding-left: 8px; }
.menu-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.menu-heading h2 { margin: 0; font-size: 1.2rem; }
.menu-heading button, #sound { min-height: 44px; }
@media (min-height: 400px) {
  #level-menu[open] {
    display: grid;
    grid-template-rows: auto auto minmax(64px, 1fr);
    overflow-y: auto;
  }
  #levels {
    overflow-y: auto;
    overscroll-behavior: contain;
    align-content: start;
    padding: 4px;
  }
}
#levels:focus-visible { outline: 2px solid #6744b4; outline-offset: -2px; }
.pattern-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 8px; margin: 8px 0; }
.pattern-exports { display: flex; flex-wrap: wrap; gap: 6px; }
#pattern-web-export { display: inline-flex; align-items: center; min-height: 44px; text-decoration: none; background: var(--lime); border-color: #52733e; font-weight: 750; }
#pattern-web-export:focus-visible { outline: 3px solid #6c47ca; outline-offset: 3px; }
.pattern-actions p, .pattern-hint, #pattern-status { margin: 0; color: #5d5177; font-size: .85rem; }
.pattern-inspect { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#pattern-save, #pattern-zoom { min-height: 44px; flex-shrink: 0; }
#pattern-viewport {
  --pattern-view-height: min(54dvh, max(96px, calc(100dvh - 300px - env(safe-area-inset-top) - env(safe-area-inset-bottom))));
  min-width: 0;
  max-height: var(--pattern-view-height);
  overflow: auto;
  overscroll-behavior: contain;
}
#pattern-viewport:focus-visible { outline: 2px solid #6744b4; outline-offset: 2px; }
#pattern-grid {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: var(--pattern-view-height);
  object-fit: contain;
  margin: 0 auto;
}
#pattern-viewport[data-zoomed] #pattern-grid {
  width: max(180%, var(--pattern-readable-width));
  max-width: none;
  max-height: none;
  height: auto;
  margin: 0;
}
.pattern-colors {
  display: flex;
  gap: 6px;
  margin: 6px 0 8px;
  padding: 3px;
  list-style: none;
  overflow-x: auto;
  scrollbar-width: thin;
  scroll-snap-type: x proximity;
}
.pattern-colors li { flex: 0 0 auto; scroll-snap-align: start; }
.pattern-colors button {
  display: flex;
  width: 100%;
  min-height: 44px;
  align-items: center;
  gap: 5px;
  padding: 5px;
  border: 1px solid #d3c9e4;
  border-radius: 6px;
  color: var(--ink);
  background: var(--paper);
  font-size: .82rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.pattern-colors button[aria-pressed="true"] { border-color: #6744b4; background: #e6d9ff; }
.pattern-colors i { flex: 0 0 12px; height: 12px; border: 1px solid #221d3755; border-radius: 2px; }
@media (max-width: 650px) {
  .layout {
    width: min(100% - 16px, 440px, max(256px, calc((100svh - 178px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * .8)));
    grid-template-columns: minmax(0, 1fr);
    align-content: center;
    gap: 8px;
    padding-top: calc(8px + env(safe-area-inset-top));
    padding-bottom: calc(15px + env(safe-area-inset-bottom));
  }
  .mobile-heading { display: block; }
  .mobile-heading h1 { font-weight: 750; font-size: 1rem; letter-spacing: normal; }
  .side { display: none; }
  .cabinet { border-radius: 4px; }
  .scoreboard { padding: 8px; }
  .scoreboard span { font-size: .75rem; }
  .scoreboard strong { font-size: .82rem; }
  #level-name { overflow-wrap: anywhere; }
  .toolbar { padding: 5px 7px; }
  #action, #restart, #view-pattern, #result-levels { min-height: 44px; }
  #effect { font-size: .75rem; }
  .overlay { gap: 7px; padding: 10px; }
  .game-dialog {
    width: min(100%, 480px);
    margin: auto auto 0;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    border-radius: 18px 18px 0 0;
  }
  #switch-menu { width: min(100% - 24px, 380px); margin: auto; padding: 16px; border-radius: 14px; }
}
@media (max-width: 650px) and (max-height: 500px) {
  .layout {
    width: min(100% - 16px, max(190px, calc((100svh - 154px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * .8)));
  }
  .mobile-heading {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .scoreboard { grid-template-columns: 1.5fr 1fr 1fr 1fr; }
  #level-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
@media (orientation: landscape) and (max-height: 580px) {
  .layout {
    --court-size: min(440px, calc((100svh - 23px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * .8));
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
    gap: 0;
    padding: calc(7px + env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
      calc(12px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }
  .mobile-heading {
    position: absolute;
    display: block;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .side { display: none; }
  .cabinet {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 176px;
    grid-template-rows: auto 4px minmax(0, 1fr);
    justify-self: center;
    width: min(100%, calc(var(--court-size) + 180px));
    border-radius: 4px;
  }
  .court { grid-area: 1 / 1 / 4 / 2; }
  .scoreboard {
    grid-area: 1 / 2;
    grid-template-columns: 1fr 1fr;
    gap: 8px 6px;
    padding: 8px;
  }
  .current-level { grid-column: 1 / -1; }
  .scoreboard div:not(.current-level) { border: 0; padding-left: 2px; }
  .scoreboard span { font-size: .75rem; }
  .progress { grid-area: 2 / 2; }
  .toolbar {
    grid-area: 3 / 2;
    align-self: end;
    padding: 8px;
  }
  .toolbar button { padding-inline: 0; }
  .toolbar button::before { display: none; }
  #action, #restart, #view-pattern, #result-levels { min-height: 44px; }
  #effect { grid-column: 1 / -1; grid-row: 1; min-height: 1.2em; font-size: .75rem; }
  .overlay { gap: 5px; padding: 8px; }
  .overlay[data-aiming]:has(#restart:not([hidden])) #action { min-width: 64px; padding-inline: 8px; }
  .active-powers { inset: 2px 2px auto; gap: 2px; }
  .active-powers li { padding-inline: 2px; font-size: .65rem; }
  .game-dialog {
    width: min(calc(100% - 24px - env(safe-area-inset-left) - env(safe-area-inset-right)), 560px);
    max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px);
    margin: auto;
    padding: 12px;
    border-radius: 12px;
  }
  #level-menu[open] {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
    grid-template-rows: auto minmax(64px, 1fr);
    gap: 8px 12px;
    overflow-y: auto;
  }
  #level-menu .menu-heading { grid-column: 1 / -1; }
  #level-menu .level-options, #levels { overflow-y: auto; overscroll-behavior: contain; }
  #levels { align-content: start; padding: 4px; }
  .level-options .play-modes { margin-top: 0; }
  .level-options .level-groups { margin-bottom: 0; }
  .continue-round { grid-template-columns: minmax(0, 1fr); }
  .level-play { grid-template-columns: minmax(0, 42px) minmax(0, 1fr); gap: 6px; }
  #pattern-menu[open] {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
    column-gap: 12px;
  }
  #pattern-menu .menu-heading { grid-area: 1 / 1 / 2 / -1; }
  #pattern-menu .pattern-actions { grid-area: 2 / 2; }
  #pattern-menu .pattern-inspect { grid-area: 3 / 2; }
  #pattern-menu .pattern-colors { grid-area: 4 / 2; align-self: start; }
  #pattern-viewport { grid-area: 2 / 1 / 5; --pattern-view-height: min(65dvh, calc(100dvh - 90px)); }
  #pattern-status { grid-area: 5 / 1 / 6 / -1; }
}
