:root {
  --bm-primary: #0b3fc6;
  --bm-primary-dark: #062b82;
  --bm-accent: #2458d4;
  --bm-ink: #082b79;
  --bm-ink-soft: #385081;
  --bm-paper: #fafbf7;
  --bm-surface: #fafbf7;
  --bm-background: #f0f2ee;
  --bm-border: #0b3fc6;
  --bm-success: #0b3fc6;
  --bm-danger: #b42318;
  --bm-shadow: 8px 8px 0 #062b82;
  --bm-ease: 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
  --bm-shell: 1120px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  overflow-x: hidden;
  color: var(--bm-ink);
  background-color: var(--bm-background);
  background-image: radial-gradient(rgba(6, 43, 130, 0.12) 0.55px, transparent 0.65px);
  background-size: 5px 5px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button {
  color: inherit;
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

svg {
  display: block;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 4px solid var(--bm-accent);
  outline-offset: 4px;
}

.game-shell {
  width: min(calc(100% - 40px), var(--bm-shell));
  margin-inline: auto;
}

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 12px;
  left: 12px;
  padding: 10px 14px;
  border: 2px solid var(--bm-border);
  color: #fff;
  background: var(--bm-primary-dark);
  transform: translateY(-160%);
  transition: transform var(--bm-ease);
}

.skip-link:focus {
  transform: translateY(0);
}

.game-header {
  position: sticky;
  z-index: 30;
  top: 0;
  border-bottom: 2px solid var(--bm-border);
  background: rgba(240, 242, 238, 0.96);
}

.header-inner {
  display: flex;
  min-height: 64px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.back-link,
.record-chip {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 9px;
  font-weight: 800;
}

.back-link {
  padding-right: 10px;
  color: var(--bm-primary-dark);
}

.back-link svg,
.record-chip svg {
  width: 22px;
}

.record-chip {
  padding: 0 15px;
  border: 2px solid var(--bm-border);
  border-radius: 0;
  background: var(--bm-paper);
  box-shadow: 4px 4px 0 var(--bm-primary-dark);
  font-size: 13px;
}

.record-chip strong {
  font-size: 15px;
}

.game-main {
  padding: clamp(28px, 4vw, 48px) 0 64px;
}

.game-intro {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.7fr);
  align-items: end;
  gap: 32px;
  margin-bottom: 24px;
}

.eyebrow,
.start-label,
.result-overline {
  margin: 0 0 6px;
  color: var(--bm-primary-dark);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.game-intro h1 {
  margin: 0;
  font-size: clamp(44px, 6vw, 72px);
  font-weight: 950;
  line-height: 0.95;
  letter-spacing: -0.065em;
  white-space: nowrap;
}

.game-intro h1 span {
  color: var(--bm-primary);
}

.intro-copy {
  max-width: 480px;
  margin: 0;
  color: var(--bm-ink-soft);
  font-size: clamp(17px, 2vw, 20px);
  font-weight: 650;
}

.game-panel {
  border: 2px solid var(--bm-border);
  border-radius: 0;
  background: var(--bm-surface);
  box-shadow: var(--bm-shadow);
}

.status-bar {
  display: grid;
  grid-template-columns: repeat(3, minmax(110px, 1fr)) auto;
  align-items: stretch;
  border-bottom: 2px solid var(--bm-border);
}

.status-item {
  display: flex;
  min-height: 82px;
  flex-direction: column;
  justify-content: center;
  padding: 12px 22px;
  border-right: 1px solid rgba(11, 63, 198, 0.3);
}

.status-item > span {
  color: var(--bm-ink-soft);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.status-item strong {
  margin-top: 2px;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.status-item--timer strong {
  color: var(--bm-primary-dark);
  font-size: 24px;
  line-height: 1.15;
}

.status-item--timer small {
  margin-left: 3px;
  font-size: 12px;
}

.restart-button {
  display: inline-flex;
  min-width: 132px;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin: 14px;
  padding: 0 14px;
  border: 2px solid var(--bm-border);
  border-radius: 0;
  background: var(--bm-paper);
  font-size: 13px;
  font-weight: 850;
  cursor: pointer;
  transition: background var(--bm-ease), transform var(--bm-ease);
}

.restart-button svg {
  width: 18px;
}

.restart-button:hover:not(:disabled) {
  background: #e8eefc;
}

.restart-button:active:not(:disabled) {
  transform: scale(0.97);
}

.restart-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.timer-track {
  height: 9px;
  overflow: hidden;
  background: #dbe5fb;
}

.timer-track span {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--bm-success);
  transform: scaleX(1);
  transform-origin: left;
  will-change: transform;
}

.timer-track span.is-low {
  background: var(--bm-danger);
}

.stage {
  min-height: 570px;
  padding: clamp(18px, 4vw, 42px);
}

.start-screen {
  display: flex;
  min-height: 480px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.sample-stack {
  position: relative;
  width: 176px;
  height: 146px;
  margin-bottom: 24px;
}

.sample-stack img {
  position: absolute;
  width: 104px;
  aspect-ratio: 1;
  border: 3px solid var(--bm-border);
  border-radius: 0;
  object-fit: cover;
  box-shadow: 4px 5px 0 var(--bm-border);
}

.sample-stack img:nth-child(1) {
  top: 22px;
  left: 0;
  transform: rotate(-10deg);
}

.sample-stack img:nth-child(2) {
  z-index: 2;
  top: 0;
  left: 36px;
}

.sample-stack img:nth-child(3) {
  top: 22px;
  right: 0;
  transform: rotate(10deg);
}

.start-screen h2 {
  margin: 0;
  font-size: clamp(34px, 5vw, 50px);
  line-height: 1.1;
  letter-spacing: -0.045em;
}

.start-screen > p:not(.start-label) {
  max-width: 560px;
  margin: 14px 0 26px;
  color: var(--bm-ink-soft);
}

.primary-button,
.secondary-button {
  display: inline-flex;
  min-height: 52px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 22px;
  border: 2px solid var(--bm-border);
  border-radius: 0;
  font-weight: 900;
  cursor: pointer;
  transition: transform var(--bm-ease), box-shadow var(--bm-ease), background var(--bm-ease);
}

.primary-button {
  color: #fff;
  background: var(--bm-primary);
  box-shadow: 4px 5px 0 var(--bm-primary-dark);
}

.primary-button svg {
  width: 20px;
  fill: currentColor;
}

.primary-button:hover {
  background: var(--bm-primary-dark);
  box-shadow: 6px 7px 0 var(--bm-primary-dark);
  transform: translate(-2px, -2px);
}

.primary-button:active {
  box-shadow: 2px 2px 0 var(--bm-primary-dark);
  transform: translate(2px, 2px);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.66;
}

.secondary-button {
  background: var(--bm-paper);
}

.secondary-button:hover {
  background: #e8eefc;
}

.match-grid {
  display: grid;
  width: min(100%, 880px);
  min-height: 486px;
  align-content: center;
  grid-template-columns: repeat(var(--grid-columns, 3), minmax(0, 1fr));
  gap: clamp(8px, 1.5vw, 14px);
  margin: 0 auto;
}

.match-card {
  position: relative;
  display: block;
  width: 100%;
  min-width: 44px;
  padding: 0;
  overflow: hidden;
  aspect-ratio: 1;
  border: 3px solid var(--bm-border);
  border-radius: 2px;
  background: #dbe5fb;
  box-shadow: 3px 4px 0 var(--bm-border);
  cursor: pointer;
  opacity: 0;
  transform: translateY(10px);
  animation: card-enter 260ms ease-out forwards;
  animation-delay: var(--card-delay, 0ms);
  transition: border-color var(--bm-ease), box-shadow var(--bm-ease), opacity 180ms ease, transform var(--bm-ease);
}

.match-card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.match-card::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 0 solid var(--bm-accent);
  border-radius: inherit;
  pointer-events: none;
  transition: border-width var(--bm-ease), background var(--bm-ease);
}

.match-card:hover:not(:disabled) {
  transform: translateY(-3px);
  box-shadow: 4px 7px 0 var(--bm-border);
}

.match-card.is-selected::after {
  border-width: 6px;
  background: rgba(36, 88, 212, 0.16);
}

.match-card.is-selected {
  box-shadow: 0 0 0 4px var(--bm-accent), 4px 7px 0 var(--bm-border);
  transform: translateY(-3px);
}

.match-card.is-wrong {
  animation: card-shake 280ms ease-in-out;
  box-shadow: 0 0 0 4px var(--bm-danger), 3px 4px 0 var(--bm-border);
}

.match-card.is-matched {
  visibility: hidden;
  opacity: 0;
  transform: scale(0.78);
}

.game-message {
  min-height: 48px;
  margin: 0;
  padding: 12px 20px;
  border-top: 2px solid var(--bm-border);
  color: var(--bm-ink-soft);
  background: #e8eefc;
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.result-dialog {
  width: min(calc(100% - 28px), 500px);
  padding: 0;
  overflow: visible;
  border: 0;
  color: var(--bm-ink);
  background: transparent;
}

.result-dialog::backdrop {
  background: rgba(6, 43, 130, 0.62);
}

.result-dialog[open] {
  animation: dialog-enter 260ms ease-out both;
}

.result-panel {
  padding: 38px;
  border: 3px solid var(--bm-border);
  border-radius: 0;
  background: var(--bm-paper);
  box-shadow: 8px 9px 0 var(--bm-primary-dark);
  text-align: center;
}

.result-icon {
  display: grid;
  width: 76px;
  height: 76px;
  margin: 0 auto 20px;
  place-items: center;
  border: 3px solid var(--bm-border);
  border-radius: 0;
  color: #fff;
  background: var(--bm-success);
  box-shadow: 4px 5px 0 var(--bm-border);
}

.result-icon.is-failure {
  background: var(--bm-danger);
}

.result-icon svg {
  width: 38px;
  stroke-width: 2.2;
}

.result-panel h2 {
  margin: 0;
  font-size: clamp(32px, 6vw, 44px);
  line-height: 1.12;
  letter-spacing: -0.05em;
}

.result-panel > p:not(.result-overline) {
  max-width: 380px;
  margin: 12px auto 0;
  color: var(--bm-ink-soft);
}

.result-stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 24px;
  padding: 14px 16px;
  border: 2px solid var(--bm-border);
  border-radius: 0;
  background: #e8eefc;
  font-size: 13px;
  font-weight: 800;
}

.result-stat strong {
  font-size: 17px;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 22px;
}

@keyframes card-enter {
  to { opacity: 1; transform: translateY(0); }
}

@keyframes card-shake {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-5px); }
  65% { transform: translateX(5px); }
}

@keyframes dialog-enter {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 760px) {
  .game-shell {
    width: min(calc(100% - 24px), var(--bm-shell));
  }

  .game-main {
    padding-top: 24px;
  }

  .game-intro {
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 18px;
  }

  .game-intro h1 {
    font-size: clamp(38px, 12vw, 52px);
  }

  .intro-copy {
    font-size: 16px;
  }

  .status-bar {
    grid-template-columns: repeat(3, 1fr);
  }

  .status-item {
    min-height: 72px;
    padding: 9px 10px;
  }

  .status-item--timer {
    border-right: 0;
  }

  .restart-button {
    grid-column: 1 / -1;
    margin: 10px;
  }

  .stage {
    min-height: 470px;
    padding: 14px;
  }

  .start-screen {
    min-height: 440px;
  }

  .match-grid {
    min-height: 440px;
    gap: 8px;
  }

  .match-card {
    border-width: 2px;
    box-shadow: 2px 3px 0 var(--bm-border);
  }

}

@media (max-width: 480px) {
  .header-inner {
    min-height: 60px;
  }

  .back-link {
    font-size: 14px;
  }

  .record-chip {
    gap: 5px;
    min-height: 44px;
    padding: 0 9px;
  }

  .record-chip > span,
  .record-chip svg {
    display: none;
  }

  .game-panel {
    border-radius: 0;
    box-shadow: 4px 5px 0 var(--bm-border);
  }

  .status-item--center {
    display: none;
  }

  .status-bar {
    grid-template-columns: 1fr 1fr;
  }

  .status-item strong {
    font-size: 16px;
  }

  .status-item--timer strong {
    font-size: 22px;
  }

  .stage {
    min-height: 400px;
    padding: 10px;
  }

  .start-screen {
    min-height: 390px;
    padding: 18px 8px;
  }

  .sample-stack {
    transform: scale(0.86);
    margin-bottom: 10px;
  }

  .match-grid {
    min-height: 380px;
    gap: 6px;
  }

  .match-card {
    border-radius: 2px;
  }

  .match-card.is-selected::after {
    border-width: 4px;
  }

  .result-panel {
    padding: 32px 20px 24px;
    box-shadow: 4px 5px 0 var(--bm-border);
  }

  .result-actions {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
