:root {
  color-scheme: dark;
  --ink: #073a42;
  --cream: #fff8e8;
  --cream-soft: #f4ecd9;
  --teal: #0b676d;
  --teal-deep: #064955;
  --aqua: #63d8c7;
  --coral: #ff7a62;
  --gold: #ffc857;
  --line: rgba(255, 248, 232, 0.28);
  --shadow: 0 20px 60px rgba(2, 29, 35, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100svh;
  overflow: hidden;
  background-color: var(--teal);
  background-image:
    linear-gradient(180deg, #138184 0%, #0b676d 58%, #064955 100%),
    repeating-linear-gradient(118deg, transparent 0 78px, rgba(255, 255, 255, 0.035) 79px 81px, transparent 82px 156px);
  color: var(--cream);
  font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body::before,
body::after {
  position: fixed;
  z-index: 0;
  right: -12%;
  left: -12%;
  height: 88px;
  pointer-events: none;
  content: "";
  border-top: 1px solid rgba(255, 248, 232, 0.08);
  border-radius: 50%;
}

body::before {
  top: 14%;
  transform: rotate(-2deg);
}

body::after {
  bottom: 10%;
  transform: rotate(2deg);
}

button {
  font: inherit;
}

button,
canvas {
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

.game-shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(100%, 520px);
  height: 100svh;
  max-height: 980px;
  margin: 0 auto;
  padding:
    max(10px, env(safe-area-inset-top))
    12px
    max(10px, env(safe-area-inset-bottom));
  gap: 8px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: baseline;
  min-width: 0;
  gap: 9px;
}

.brand h1 {
  margin: 0;
  overflow: hidden;
  color: var(--cream);
  font-size: clamp(20px, 5.5vw, 25px);
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand span {
  flex: 0 0 auto;
  color: rgba(255, 248, 232, 0.72);
  font-size: 11px;
  font-weight: 700;
}

.toolbar {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
}

.icon-button {
  position: relative;
  display: grid;
  width: 36px;
  height: 36px;
  padding: 0;
  color: var(--cream);
  cursor: pointer;
  background: rgba(255, 248, 232, 0.1);
  border: 1px solid rgba(255, 248, 232, 0.22);
  border-radius: 8px;
  place-items: center;
  transition: background-color 160ms ease, transform 160ms ease;
}

.icon-button:hover {
  background: rgba(255, 248, 232, 0.2);
}

.icon-button:active {
  transform: translateY(1px);
}

.icon-button:focus-visible,
.primary-button:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.icon {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.sound-off {
  display: none;
}

.icon-button.is-muted .sound-on {
  display: none;
}

.icon-button.is-muted .sound-off {
  display: block;
}

.icon-button[data-tooltip]::after {
  position: absolute;
  top: calc(100% + 7px);
  left: 50%;
  z-index: 20;
  padding: 5px 8px;
  color: var(--ink);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
  pointer-events: none;
  content: attr(data-tooltip);
  background: var(--cream);
  border-radius: 6px;
  opacity: 0;
  transform: translate(-50%, -3px);
  transition: opacity 140ms ease, transform 140ms ease;
}

.icon-button[data-tooltip]:hover::after,
.icon-button[data-tooltip]:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.scorebar {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  min-height: 66px;
  overflow: hidden;
  background: rgba(255, 248, 232, 0.1);
  border: 1px solid rgba(255, 248, 232, 0.2);
  border-radius: 8px;
}

.metric {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  padding: 8px 14px;
}

.metric + .metric {
  border-left: 1px solid rgba(255, 248, 232, 0.16);
}

.metric span,
.next > span {
  color: rgba(255, 248, 232, 0.66);
  font-size: 11px;
  font-weight: 700;
}

.metric strong {
  overflow: hidden;
  margin-top: 2px;
  color: var(--cream);
  font-size: clamp(21px, 6vw, 27px);
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  line-height: 1;
  text-overflow: ellipsis;
}

.metric strong.bump {
  animation: score-bump 220ms ease-out;
}

.next {
  display: grid;
  grid-template-columns: auto 42px;
  align-items: center;
  padding: 6px 9px 6px 12px;
  gap: 8px;
  border-left: 1px solid rgba(255, 248, 232, 0.16);
}

.next-frame {
  display: grid;
  width: 42px;
  height: 48px;
  overflow: hidden;
  background: var(--cream-soft);
  border: 2px solid rgba(255, 248, 232, 0.92);
  border-radius: 8px;
  place-items: center;
}

.next-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
}

.stage {
  display: flex;
  flex: 1;
  min-height: 0;
  align-items: center;
  justify-content: center;
}

.board-frame {
  position: relative;
  flex: 0 0 auto;
  overflow: hidden;
  background: #bdeee3;
  border: 2px solid rgba(255, 248, 232, 0.78);
  border-radius: 8px;
  box-shadow: var(--shadow);
  isolation: isolate;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  outline: none;
  touch-action: none;
}

.win-toast {
  position: absolute;
  top: 14%;
  left: 50%;
  z-index: 5;
  display: flex;
  align-items: center;
  padding: 10px 15px;
  gap: 10px;
  color: var(--ink);
  pointer-events: none;
  background: var(--gold);
  border: 2px solid var(--cream);
  border-radius: 8px;
  box-shadow: 0 10px 26px rgba(7, 58, 66, 0.24);
  opacity: 0;
  transform: translate(-50%, 8px) scale(0.96);
  transition: opacity 180ms ease, transform 180ms ease;
}

.win-toast.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.win-toast span {
  font-size: 12px;
  font-weight: 900;
}

.win-toast strong {
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.modal {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  padding: 22px;
  background: rgba(4, 42, 49, 0.66);
  backdrop-filter: blur(7px);
  place-items: center;
}

.modal-panel {
  display: flex;
  flex-direction: column;
  width: min(100%, 280px);
  padding: 24px 22px 20px;
  color: var(--ink);
  text-align: center;
  background: var(--cream);
  border: 1px solid rgba(7, 58, 66, 0.12);
  border-radius: 8px;
  box-shadow: 0 18px 44px rgba(2, 28, 33, 0.28);
}

.modal-kicker {
  color: #43747a;
  font-size: 11px;
  font-weight: 800;
}

.modal-panel h2 {
  margin: 5px 0 18px;
  font-size: 25px;
  letter-spacing: 0;
  line-height: 1.15;
}

.final-score {
  display: flex;
  flex-direction: column;
  margin: -6px 0 19px;
}

.final-score span {
  color: #43747a;
  font-size: 11px;
  font-weight: 700;
}

.final-score strong {
  color: var(--coral);
  font-size: 42px;
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  line-height: 1.1;
}

.primary-button {
  min-height: 46px;
  padding: 0 20px;
  color: #fffaf0;
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
  background: var(--coral);
  border: 0;
  border-radius: 8px;
  box-shadow: 0 5px 0 #bf4e3d;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.primary-button:active {
  box-shadow: 0 2px 0 #bf4e3d;
  transform: translateY(3px);
}

@keyframes score-bump {
  0% {
    color: var(--cream);
    transform: scale(1);
  }
  45% {
    color: var(--gold);
    transform: scale(1.14);
  }
  100% {
    color: var(--cream);
    transform: scale(1);
  }
}

@media (max-width: 380px) {
  .game-shell {
    padding-right: 8px;
    padding-left: 8px;
  }

  .brand {
    gap: 6px;
  }

  .brand span {
    display: none;
  }

  .toolbar {
    gap: 4px;
  }

  .icon-button {
    width: 34px;
    height: 34px;
  }

  .metric {
    padding-right: 10px;
    padding-left: 10px;
  }

  .next {
    grid-template-columns: auto 38px;
    padding-right: 7px;
    padding-left: 9px;
  }

  .next-frame {
    width: 38px;
    height: 44px;
  }
}

@media (max-height: 720px) {
  .game-shell {
    gap: 6px;
  }

  .topbar {
    min-height: 40px;
  }

  .scorebar {
    min-height: 58px;
  }

  .metric {
    padding-top: 5px;
    padding-bottom: 5px;
  }

  .next-frame {
    height: 42px;
  }
}

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