/* Brick Breaker — 像素街机皮肤。
 *
 * 几何来自 /assets/css/tokens.css 的 --pixel-* 令牌；Shell 的 pixel.css
 * 不进入 iframe。这里所有 UI 颜色、边框、阴影与动画均为游戏本地样式：
 * 硬边框、0 圆角、硬偏移阴影，无渐变、模糊、发光或玻璃半透明。
 * Canvas 渲染器继续读取下方 --bb-* 主题令牌。
 */

:root {
  color-scheme: light;

  --bb-border: var(--pixel-border-width);
  --bb-border-thin: var(--pixel-border-thin);
  --bb-shadow-offset: var(--pixel-shadow-offset);
  --bb-shadow-lg: var(--pixel-shadow-offset-lg);
  --bb-font: var(--pixel-ui-font);

  --bb-panel: #ffffff;
  --bb-panel-strong: #ffffff;
  --bb-line: #1b1b22;
  --bb-ink: #1b1b22;
  --bb-ink-muted: #5f6070;
  --bb-scrim: rgba(8, 8, 18, 0.78);
  --bb-dialog: #ffffff;
  --bb-dialog-ink: #1b1b22;
  --bb-dialog-muted: #5f6070;

  --bb-bg-top: #1c1c3c;
  --bb-bg-bottom: #080812;
  --bb-glow: rgba(108, 92, 231, 0.48);
  --bb-glow-warm: rgba(255, 122, 107, 0.2);
  --bb-grid: rgba(255, 255, 255, 0.1);

  --bb-brick-1: #ff7a6b;
  --bb-brick-2: #ffc861;
  --bb-brick-3: #3fd7b0;
  --bb-brick-4: #5fb8ff;
  --bb-brick-5: #b18cff;
  --bb-brick-edge: rgba(6, 6, 18, 0.38);
  --bb-brick-highlight: rgba(255, 255, 255, 0.45);

  --bb-special-multi: #7cf1ff;
  --bb-special-wide: #9bff8f;
  --bb-special-pierce: #ffa8f2;

  --bb-paddle: #f4f1ff;
  --bb-paddle-edge: #8f86ff;
  --bb-ball: #ffffff;
  --bb-ball-glow: rgba(124, 241, 255, 0.9);

  --bb-page-1: #f2efff;
  --bb-page-2: #e8e4ff;
  --bb-page-line: #ddd6ff;
  --bb-scene-opacity: 0.3;
  --bb-shadow: #1b1b22;

  --bb-sprite-size: 400% 200%;
  --bb-sprite-pos: 0% 0%;
}

[data-theme="dark"] {
  color-scheme: dark;

  --bb-panel: #1c1c25;
  --bb-panel-strong: #1c1c25;
  --bb-line: #f1f1f6;
  --bb-ink: #f1f1f6;
  --bb-ink-muted: #a0a0b0;
  --bb-scrim: rgba(3, 3, 10, 0.86);
  --bb-dialog: #1c1c25;
  --bb-dialog-ink: #f1f1f6;
  --bb-dialog-muted: #a0a0b0;

  --bb-bg-top: #12122a;
  --bb-bg-bottom: #05050c;
  --bb-glow: rgba(108, 92, 231, 0.34);
  --bb-glow-warm: rgba(255, 122, 107, 0.14);
  --bb-grid: rgba(255, 255, 255, 0.075);

  --bb-page-1: #14131d;
  --bb-page-2: #0c0c12;
  --bb-page-line: #2b2748;
  --bb-scene-opacity: 0.44;
  --bb-shadow: #07050f;
}

/* DOM 精灵回退位置；渲染器从 sprites.json 读取 Canvas 帧。 */
[data-sprite="hero"] { --bb-sprite-pos: 0% 0%; }
[data-sprite="coin"] { --bb-sprite-pos: 33.333% 0%; }
[data-sprite="hazard"] { --bb-sprite-pos: 66.667% 0%; }
[data-sprite="effect"] { --bb-sprite-pos: 100% 0%; }
[data-sprite="tile"] { --bb-sprite-pos: 0% 100%; }
[data-sprite="block"] { --bb-sprite-pos: 33.333% 100%; }
[data-sprite="orb"] { --bb-sprite-pos: 66.667% 100%; }
[data-sprite="spark"] { --bb-sprite-pos: 100% 100%; }

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bb-page-1);
}

body {
  color: var(--bb-ink);
  font-family: var(--bb-font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: none;
  text-rendering: optimizeSpeed;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

button:focus-visible,
canvas:focus-visible {
  outline: var(--bb-border) solid var(--color-focus);
  outline-offset: 2px;
}

kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 3px;
  border: 1px solid var(--bb-line);
  background: var(--bb-panel-strong);
  color: var(--bb-ink-muted);
  font-family: var(--bb-font);
  font-size: 9px;
  line-height: 1.5;
  text-align: center;
}

[hidden] {
  display: none !important;
}

.bb-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* 背景 ------------------------------------------------------------------ */

.bb-backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background-color: var(--bb-page-1);
  background-image: url("./assets/brick-breaker-scene-light.png");
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  image-rendering: pixelated;
  opacity: var(--bb-scene-opacity);
  pointer-events: none;
}

[data-theme="dark"] .bb-backdrop {
  background-image: url("./assets/brick-breaker-scene-dark.png");
}

.bb-backdrop::before,
.bb-backdrop::after,
.bb-float {
  display: none;
}

/* 应用框架 -------------------------------------------------------------- */

.bb-app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "hud"
    "stage"
    "foot";
  gap: 4px;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  padding: max(4px, env(safe-area-inset-top, 0px))
    max(4px, min(env(safe-area-inset-right, 0px), 6px))
    max(6px, min(env(safe-area-inset-bottom, 0px), 10px))
    max(4px, min(env(safe-area-inset-left, 0px), 6px));
  overflow: hidden;
  color: var(--bb-ink);
}

/* HUD ------------------------------------------------------------------- */

.bb-hud {
  grid-area: hud;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "brand actions"
    "stats stats";
  align-items: center;
  gap: 4px 6px;
  min-width: 0;
  padding: 4px;
  border: var(--bb-border) solid var(--bb-line);
  background: var(--bb-panel);
  box-shadow: var(--bb-shadow-offset) var(--bb-shadow-offset) 0 var(--bb-shadow);
}

.bb-brand {
  grid-area: brand;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.bb-brand__mark {
  width: 32px;
  height: 32px;
  flex: none;
  border: var(--bb-border-thin) solid var(--bb-line);
  background-color: var(--bb-brick-5);
  background-image: url("./assets/pixel/brick-breaker-sprites.png");
  background-repeat: no-repeat;
  background-size: var(--bb-sprite-size);
  background-position: var(--bb-sprite-pos);
  image-rendering: pixelated;
}

.bb-brand__copy {
  min-width: 0;
}

.bb-brand__copy h1 {
  margin: 0;
  overflow: hidden;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: 0;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.bb-brand__copy p {
  display: none;
  margin: 2px 0 0;
  color: var(--bb-ink-muted);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.2;
  text-transform: uppercase;
}

.bb-stats {
  grid-area: stats;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 3px;
  margin: 0;
}

.bb-stat {
  min-width: 0;
  padding: 2px 4px;
  border: var(--bb-border-thin) solid var(--bb-line);
  background: var(--bb-panel-strong);
  line-height: 1;
}

.bb-stat dt {
  margin: 0;
  color: var(--bb-ink-muted);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.1;
  text-transform: uppercase;
}

.bb-stat dd {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 1px 0 0;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.bb-lives {
  display: inline-flex;
  gap: 2px;
}

.bb-lives i {
  width: 7px;
  height: 7px;
  background: var(--bb-brick-1);
}

.bb-lives i.is-empty {
  background: var(--bb-ink-muted);
  opacity: 0.35;
}

.bb-hud__actions {
  grid-area: actions;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  min-width: 0;
}

.bb-chip {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 4px;
  border: var(--bb-border-thin) solid var(--bb-line);
  background: var(--bb-brick-5);
  color: var(--bb-ink);
  font-size: 9px;
  font-weight: 700;
  line-height: 1.1;
  text-transform: uppercase;
  white-space: nowrap;
}

.bb-chip--power {
  background: var(--bb-special-wide);
}

.bb-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: var(--touch-target-min);
  min-height: var(--touch-target-min);
  padding: 0 6px;
  border: var(--bb-border-thin) solid var(--bb-line);
  background: var(--bb-panel-strong);
  box-shadow: 2px 2px 0 var(--bb-line);
  color: var(--bb-ink);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  transition:
    transform 80ms steps(2, end),
    box-shadow 80ms steps(2, end);
}

.bb-icon-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 0 0 0 var(--bb-line);
}

.bb-pause-icon {
  display: inline-flex;
  gap: 3px;
}

.bb-pause-icon i {
  width: 3px;
  height: 14px;
  background: currentColor;
}

.bb-icon-btn__label {
  display: none;
}

.bb-rail-note {
  display: none;
  margin: 0;
  color: var(--bb-ink-muted);
  font-size: 10px;
  line-height: 1.45;
}

.bb-rail-note kbd {
  font-size: 8px;
}

.bb-rail-seed {
  display: block;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* 舞台 ------------------------------------------------------------------ */

.bb-stage {
  grid-area: stage;
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: var(--bb-border) solid var(--bb-line);
  background: #080812;
  box-shadow: var(--bb-shadow-offset) var(--bb-shadow-offset) 0 var(--bb-line);
  isolation: isolate;
}

#board {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
  outline: none;
  image-rendering: pixelated;
}

#board:focus-visible {
  outline: var(--bb-border) solid var(--color-focus);
  outline-offset: -3px;
}

.bb-launch {
  position: absolute;
  bottom: 16%;
  left: 50%;
  max-width: calc(100% - 20px);
  margin: 0;
  padding: 4px 8px;
  border: var(--bb-border-thin) solid #ffffff;
  background: #080812;
  color: #ffffff;
  box-shadow: 3px 3px 0 #000000;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
  transform: translateX(-50%);
  transition:
    opacity 120ms steps(2, end),
    transform 120ms steps(2, end);
  animation: bb-breathe 2.6s steps(2, end) infinite;
}

.bb-app:not([data-state="ready"]) .bb-launch {
  opacity: 0;
  visibility: hidden;
  transform: translateX(-50%) translateY(4px);
  animation: none;
}

@keyframes bb-breathe {
  0%, 100% { opacity: 0.78; }
  50% { opacity: 1; }
}

.bb-banner {
  position: absolute;
  top: 17%;
  left: 50%;
  margin: 0;
  padding: 4px 8px;
  border: var(--bb-border-thin) solid #ffffff;
  background: #080812;
  color: #ffffff;
  box-shadow: 3px 3px 0 #000000;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.2;
  text-transform: uppercase;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -4px);
  transition:
    opacity 120ms steps(2, end),
    transform 120ms steps(2, end);
}

.bb-banner.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* 页脚 ------------------------------------------------------------------ */

.bb-foot {
  grid-area: foot;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 2px 8px;
  min-width: 0;
  padding-inline: 2px;
  color: var(--bb-ink-muted);
  font-size: 10px;
  line-height: 1.35;
}

.bb-foot p {
  margin: 0;
  min-width: 0;
}

.bb-seed {
  color: var(--bb-ink-muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* 对话框 ---------------------------------------------------------------- */

.bb-dialog {
  width: min(calc(100% - 16px), 420px);
  max-width: none;
  max-height: 80dvh;
  margin: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--bb-dialog-ink);
}

.bb-dialog::backdrop {
  background: var(--bb-scrim);
}

.bb-dialog__body {
  max-height: 80dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  border: var(--bb-border) solid var(--bb-line);
  background: var(--bb-dialog);
  color: var(--bb-dialog-ink);
  box-shadow: var(--bb-shadow-lg) var(--bb-shadow-lg) 0 var(--bb-line);
  text-align: center;
}

.bb-eyebrow {
  margin: 0 0 4px;
  color: var(--bb-dialog-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.bb-dialog__title {
  margin: 0 0 8px;
  font-size: 20px;
  line-height: 1.2;
  letter-spacing: 0;
  text-transform: uppercase;
}

.bb-dialog__text {
  margin: 0 0 12px;
  color: var(--bb-dialog-muted);
  font-size: 16px;
  line-height: 1.45;
}

.bb-dialog__fine {
  margin: 10px 0 0;
  color: var(--bb-dialog-muted);
  font-size: 11px;
  line-height: 1.4;
}

.bb-result {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  margin: 10px 0 12px;
}

.bb-result div {
  padding: 6px 4px;
  border: var(--bb-border-thin) solid var(--bb-line);
  background: var(--bb-panel-strong);
}

.bb-result dt {
  color: var(--bb-dialog-muted);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.bb-result dd {
  margin: 2px 0 0;
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.bb-dialog__actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  width: 100%;
  padding: 6px 12px;
  border: var(--bb-border) solid var(--bb-line);
  background: var(--bb-panel-strong);
  color: var(--bb-dialog-ink);
  box-shadow: 3px 3px 0 var(--bb-line);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  text-transform: uppercase;
  touch-action: manipulation;
  transition:
    transform 80ms steps(2, end),
    box-shadow 80ms steps(2, end);
}

.bb-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--bb-line);
}

.bb-btn--primary {
  background: var(--bb-brick-5);
  color: #ffffff;
}

.bb-btn--ghost {
  background: var(--bb-panel-strong);
}

/* 宽屏：舞台在左，数值信息栏在右 ---------------------------------------- */

@media (orientation: landscape) and (min-width: 640px) {
  .bb-app {
    grid-template-columns: minmax(0, 1fr) clamp(158px, 20vw, 236px);
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: "stage hud";
    gap: 6px;
    padding: max(4px, env(safe-area-inset-top, 0px))
      max(6px, min(env(safe-area-inset-right, 0px), 10px))
      max(4px, env(safe-area-inset-bottom, 0px))
      max(4px, min(env(safe-area-inset-left, 0px), 6px));
  }

  .bb-hud {
    grid-area: hud;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    align-self: stretch;
    gap: 6px;
    min-height: 0;
    overflow: hidden;
    padding: 6px;
  }

  .bb-brand {
    flex: 0 0 auto;
    align-items: flex-start;
  }

  .bb-brand__mark {
    width: 30px;
    height: 30px;
  }

  .bb-brand__copy p {
    display: block;
  }

  .bb-brand__copy h1 {
    font-size: 16px;
    white-space: normal;
  }

  .bb-stats {
    flex: 0 0 auto;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    text-align: right;
  }

  .bb-stat {
    min-height: 50px;
    padding: 4px;
  }

  .bb-stat dd {
    justify-content: flex-end;
    font-size: 16px;
  }

  .bb-hud__actions {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .bb-hud__actions .bb-icon-btn {
    width: 100%;
  }

  .bb-icon-btn__label {
    display: inline;
  }

  .bb-rail-note {
    display: block;
    margin-top: auto;
  }

  .bb-chip {
    white-space: normal;
  }

  .bb-stage {
    grid-area: stage;
  }

  .bb-foot {
    display: none;
  }
}

@media (orientation: landscape) and (max-height: 430px) {
  .bb-brand__copy p,
  .bb-rail-note {
    display: none;
  }

  .bb-hud {
    gap: 4px;
    padding: 4px;
  }

  .bb-brand__mark {
    display: none;
  }

  .bb-stat {
    min-height: 38px;
    padding: 2px 4px;
  }

  .bb-stat dt {
    font-size: 8px;
  }

  .bb-stat dd {
    font-size: 14px;
  }
}

@media (max-width: 359px) {
  .bb-brand__mark {
    display: none;
  }

  .bb-brand__copy p,
  .bb-seed {
    display: none;
  }

  .bb-stat dd {
    font-size: 13px;
  }

  .bb-foot {
    font-size: 9px;
  }
}

/* 减少动态 -------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .bb-float,
  .bb-launch {
    animation: none !important;
  }

  .bb-launch,
  .bb-banner,
  .bb-icon-btn,
  .bb-btn {
    transition: none !important;
  }
}

.bb-app[data-motion="reduce"] .bb-float,
.bb-app[data-motion="reduce"] .bb-launch {
  animation: none !important;
}

.bb-app[data-motion="reduce"] .bb-launch,
.bb-app[data-motion="reduce"] .bb-banner,
.bb-app[data-motion="reduce"] .bb-icon-btn,
.bb-app[data-motion="reduce"] .bb-btn {
  transition: none !important;
}

.bb-app[data-paused="true"] .bb-float,
.bb-app[data-paused="true"] .bb-launch {
  animation-play-state: paused;
}

@media (max-height: 420px) {
  .bb-dialog__body {
    padding: 12px;
  }

  .bb-result {
    margin-block: 6px;
  }

  .bb-dialog__text {
    margin-bottom: 8px;
  }
}
