:root {
  color-scheme: light;
  --paper: #f6f3ea;
  --ink: #20211f;
  --muted: #74756f;
  --line: #d9d4c7;
  --coral: #ff5d52;
  --teal: #0faaa2;
  --yellow: #ffd166;
  --green: #6fcf7c;
  --blue: #4d83e6;
  --board: #20211f;
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--paper);
  color: var(--ink);
  min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) 16px max(10px, env(safe-area-inset-bottom));
}

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

button {
  font: inherit;
}

.game-shell {
  width: min(100%, 520px);
  margin: 0 auto;
}

.game-header {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: var(--coral);
  color: white;
  border: 2px solid var(--ink);
  border-radius: 8px;
  box-shadow: 3px 3px 0 var(--ink);
  font-size: 22px;
  font-weight: 900;
}

h1 {
  margin: 0;
  font-size: 23px;
  line-height: 1.05;
  letter-spacing: 0;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
  font-size: 22px;
  font-weight: 800;
}

.icon-button:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.icon-button.is-muted {
  color: var(--muted);
  background: #e8e4d9;
}

.scoreboard {
  display: grid;
  grid-template-columns: 1fr 112px 1fr;
  align-items: stretch;
  gap: 8px;
  margin-bottom: 10px;
}

.score-item,
.next-block {
  min-height: 62px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.score-item {
  background: white;
  flex-direction: column;
}

.score-item span,
.next-block span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.score-item strong {
  margin-top: 1px;
  font-variant-numeric: tabular-nums;
  font-size: 24px;
  line-height: 1;
}

.score-current {
  border-color: var(--coral);
}

.next-block {
  background: var(--yellow);
  color: var(--ink);
  gap: 8px;
}

.next-block strong {
  width: 42px;
  height: 42px;
  border: 2px solid var(--ink);
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: var(--coral);
  color: white;
  font-size: 20px;
}

.next-block strong[data-value="2"] { background: #ff5d52; }
.next-block strong[data-value="4"] { background: #ffd166; color: var(--ink); }
.next-block strong[data-value="8"] { background: #0faaa2; }

.board-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 7;
  max-height: calc(100dvh - 214px);
  margin: 0 auto;
  overflow: hidden;
  background: var(--board);
  border: 3px solid var(--ink);
  border-radius: 8px;
  box-shadow: 5px 5px 0 var(--teal);
  touch-action: manipulation;
  user-select: none;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.column-guides {
  position: absolute;
  inset: 0 0 auto;
  height: 31px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  pointer-events: none;
}

.column-guides span {
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.45);
  font-size: 11px;
  font-weight: 700;
}

.first-hint {
  position: absolute;
  left: 50%;
  top: 38%;
  width: min(78%, 320px);
  transform: translate(-50%, -50%);
  border: 2px solid white;
  border-radius: 8px;
  background: rgba(32, 33, 31, 0.94);
  color: white;
  padding: 17px 20px;
  text-align: center;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.first-hint strong,
.first-hint span {
  display: block;
}

.first-hint strong {
  font-size: 18px;
}

.first-hint span {
  margin-top: 5px;
  color: var(--yellow);
  font-size: 12px;
}

.first-hint.is-hidden {
  opacity: 0;
  transform: translate(-50%, -45%);
}

.game-over {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(32, 33, 31, 0.94);
  color: white;
  z-index: 4;
}

.game-over[hidden] {
  display: none;
}

.game-over-label {
  color: var(--yellow);
  font-size: 13px;
  font-weight: 800;
}

.game-over strong {
  margin: 8px 0 2px;
  font-size: 64px;
  line-height: 1;
}

.new-best {
  margin: 8px 0 18px;
  border-radius: 5px;
  background: var(--coral);
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 800;
}

.game-over button {
  min-width: 142px;
  min-height: 46px;
  border: 2px solid white;
  border-radius: 8px;
  background: var(--yellow);
  color: var(--ink);
  box-shadow: 4px 4px 0 white;
  cursor: pointer;
  font-size: 16px;
  font-weight: 900;
}

.game-over button:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 white;
}

.combo-toast {
  position: absolute;
  left: 50%;
  top: 17%;
  transform: translateX(-50%) scale(0.8);
  color: var(--yellow);
  opacity: 0;
  font-size: 26px;
  font-weight: 900;
  pointer-events: none;
  text-shadow: 2px 2px 0 var(--ink);
}

.combo-toast.is-visible {
  animation: combo-pop 720ms ease both;
}

@keyframes combo-pop {
  0% { opacity: 0; transform: translateX(-50%) scale(0.7); }
  22% { opacity: 1; transform: translateX(-50%) scale(1.2); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-28px) scale(1); }
}

.status-text {
  min-height: 18px;
  margin: 11px 0 6px;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  font-weight: 700;
}

footer {
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
}

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

footer a:hover {
  color: var(--coral);
}

.privacy-page article {
  margin-top: 20px;
  border-top: 2px solid var(--ink);
  padding: 18px 2px;
  color: #494a46;
  font-size: 14px;
  line-height: 1.9;
}

.privacy-page article p {
  margin: 0 0 14px;
}

.privacy-page article a {
  color: var(--coral);
  font-weight: 800;
}

@media (max-width: 480px) {
  body {
    padding-left: 10px;
    padding-right: 10px;
  }

  .game-header {
    min-height: 46px;
    margin-bottom: 7px;
  }

  .brand-mark,
  .icon-button {
    width: 38px;
    height: 38px;
  }

  h1 {
    font-size: 20px;
  }

  .scoreboard {
    grid-template-columns: 1fr 104px 1fr;
    margin-bottom: 7px;
  }

  .score-item,
  .next-block {
    min-height: 54px;
  }

  .score-item strong {
    font-size: 21px;
  }

  .next-block strong {
    width: 37px;
    height: 37px;
  }

  .board-wrap {
    max-height: calc(100dvh - 185px);
    box-shadow: 4px 4px 0 var(--teal);
  }

  .status-text {
    margin-top: 8px;
  }
}

@media (max-height: 700px) {
  .brand p,
  footer {
    display: none;
  }

  .status-text {
    margin-bottom: 0;
  }
}

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