:root {
  color-scheme: light;
  --ink: #263238;
  --muted: #64748b;
  --paper: #fffdf5;
  --sun: #ffe089;
  --mint: #bce8d6;
  --sky: #b9e5ff;
  --peach: #ffd1b8;
  --lavender: #d8cdf9;
  --line: rgba(38, 50, 56, 0.14);
  --shadow: 0 14px 34px rgba(71, 85, 105, 0.14);
  font-family: ui-rounded, "SF Pro Rounded", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

html {
  background:
    radial-gradient(circle at 16% 12%, rgba(255, 224, 137, 0.8), transparent 26rem),
    radial-gradient(circle at 88% 20%, rgba(185, 229, 255, 0.9), transparent 24rem),
    linear-gradient(135deg, #fff8dd 0%, #e8f8ef 54%, #f5efff 100%);
}

body {
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.26) 1px, transparent 1px) 0 0 / 42px 42px,
    linear-gradient(rgba(255, 255, 255, 0.22) 1px, transparent 1px) 0 0 / 42px 42px;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: grid;
  width: 100%;
  height: 100dvh;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(8px, 1.2vmin, 14px);
  overflow: hidden;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}

.topbar {
  display: grid;
  grid-template-columns: minmax(132px, 1fr) auto;
  gap: clamp(8px, 1.2vmin, 14px);
  width: min(100%, 1366px);
  margin: 0 auto;
  align-items: center;
}

.brand {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 2px;
  color: #587084;
  font-size: clamp(0.72rem, 1.45vmin, 0.9rem);
  font-weight: 850;
  white-space: nowrap;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  overflow: hidden;
  font-size: clamp(1.7rem, 4.2vmin, 3rem);
  line-height: 0.95;
  letter-spacing: 0;
  white-space: nowrap;
}

.toolbar-actions {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: clamp(6px, 1vmin, 10px);
}

.home-link,
.secondary-button {
  min-height: clamp(36px, 5.4vmin, 46px);
  padding: 0 clamp(12px, 1.8vmin, 18px);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink);
  cursor: pointer;
  font-size: clamp(0.9rem, 1.8vmin, 1.05rem);
  font-weight: 950;
  box-shadow: 0 8px 18px rgba(71, 85, 105, 0.11);
  text-decoration: none;
}

.rules {
  display: flex;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 8px 18px rgba(71, 85, 105, 0.1);
}

.rule-button {
  min-height: clamp(34px, 5vmin, 44px);
  padding: 0 clamp(12px, 1.7vmin, 18px);
  border-radius: 999px;
  background: transparent;
  color: #516579;
  cursor: pointer;
  font-size: clamp(0.9rem, 1.8vmin, 1.05rem);
  font-weight: 950;
  white-space: nowrap;
}

.rule-button.is-active {
  background: #263238;
  color: #fffdf5;
}

.game-shell {
  display: grid;
  width: min(100%, 1366px);
  height: 100%;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(8px, 1.2vmin, 14px);
  margin: 0 auto;
  overflow: hidden;
}

.hud-grid {
  display: grid;
  width: 100%;
  max-width: 100%;
  min-height: 0;
  min-width: 0;
  grid-template-columns: minmax(220px, 0.95fr) minmax(300px, 1.15fr) minmax(220px, 0.95fr);
  gap: clamp(8px, 1.2vmin, 14px);
}

.player-card,
.prompt-card,
.result-panel {
  border: 1px solid rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.player-card {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  gap: 4px 10px;
  align-items: center;
  padding: clamp(9px, 1.4vmin, 14px);
  border-radius: clamp(18px, 2.6vmin, 24px);
}

.player-one {
  background: linear-gradient(160deg, rgba(188, 232, 214, 0.94), rgba(255, 253, 245, 0.9));
}

.player-two {
  background: linear-gradient(160deg, rgba(185, 229, 255, 0.94), rgba(255, 253, 245, 0.9));
}

.player-label {
  grid-column: 1;
  color: #48606f;
  font-size: clamp(0.92rem, 1.8vmin, 1.1rem);
  font-weight: 950;
  white-space: nowrap;
}

.player-card strong {
  grid-column: 2;
  grid-row: 1 / 3;
  justify-self: center;
  font-size: clamp(1.75rem, 4.1vmin, 3rem);
  line-height: 1;
  white-space: nowrap;
}

.player-card span:last-of-type {
  grid-column: 1;
  grid-row: 2;
  color: #516579;
  font-size: clamp(0.86rem, 1.7vmin, 1.04rem);
  font-weight: 900;
  white-space: nowrap;
}

.board-stage {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-columns:
    minmax(120px, 1fr)
    minmax(0, min(100%, calc(100dvh - 176px), 980px))
    minmax(120px, 1fr);
  gap: clamp(10px, 1.4vmin, 18px);
  align-items: stretch;
  overflow: hidden;
}

.side-start {
  display: grid;
  min-width: 0;
  min-height: 0;
}

.start-button {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  padding: clamp(14px, 2vmin, 22px);
  border-radius: clamp(22px, 3vmin, 30px);
  background: #263238;
  color: #fffdf5;
  cursor: pointer;
  font-size: clamp(1.05rem, 2.3vmin, 1.55rem);
  font-weight: 950;
  white-space: normal;
  line-height: 1.2;
  box-shadow: 0 14px 28px rgba(71, 85, 105, 0.16);
}

.start-button:disabled {
  cursor: default;
  opacity: 0.36;
  box-shadow: none;
}

.prompt-card {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 4px clamp(10px, 1.5vmin, 16px);
  align-items: center;
  padding: clamp(9px, 1.4vmin, 14px);
  border-radius: clamp(18px, 2.6vmin, 24px);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(255, 247, 216, 0.9)),
    repeating-linear-gradient(45deg, transparent 0 18px, rgba(117, 199, 162, 0.12) 18px 34px);
  text-align: center;
}

#roundLabel {
  grid-column: 1;
  margin-bottom: 0;
  color: #587084;
  font-size: clamp(0.9rem, 1.8vmin, 1.08rem);
  font-weight: 950;
}

#targetNumber {
  grid-column: 2;
  grid-row: 1 / 3;
  position: relative;
  margin-bottom: 0;
  font-size: clamp(3rem, 8.5vmin, 6.1rem);
  line-height: 0.9;
  letter-spacing: 0;
  isolation: isolate;
}

#targetNumber::after {
  position: absolute;
  z-index: 2;
  inset: -0.08em -0.14em;
  border-radius: 0.18em;
  background:
    radial-gradient(circle at 28% 20%, rgba(255, 255, 255, 0.9), transparent 34%),
    linear-gradient(135deg, rgba(255, 253, 245, 0.98), rgba(226, 241, 235, 0.96));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.78), 0 8px 20px rgba(71, 85, 105, 0.08);
  content: "";
  opacity: 0;
  pointer-events: none;
  -webkit-backdrop-filter: blur(20px) saturate(0.7);
  backdrop-filter: blur(20px) saturate(0.7);
}

#targetNumber::before {
  position: absolute;
  z-index: 3;
  inset: 8% 18%;
  border-radius: 999px;
  background:
    linear-gradient(90deg, transparent 0 42%, rgba(88, 112, 132, 0.12) 42% 58%, transparent 58%),
    linear-gradient(0deg, transparent 0 42%, rgba(88, 112, 132, 0.12) 42% 58%, transparent 58%);
  content: "";
  opacity: 0;
  pointer-events: none;
}

#targetNumber.is-hidden {
  color: transparent;
  text-shadow: 0 0 0.22em rgba(38, 50, 56, 0.36);
}

#targetNumber.is-hidden::after,
#targetNumber.is-hidden::before {
  opacity: 1;
}

#targetNumber.is-revealing::after {
  opacity: 1;
  animation: targetErase 620ms ease-out forwards;
}

#targetNumber.is-revealing::before {
  opacity: 1;
  animation: targetMarkFade 420ms ease-out forwards;
}

#instruction {
  grid-column: 3;
  margin-bottom: 0;
  color: #405363;
  font-size: clamp(0.86rem, 1.75vmin, 1.08rem);
  font-weight: 850;
  line-height: 1.28;
}

.number-board {
  display: grid;
  width: 100%;
  max-width: 980px;
  height: auto;
  max-height: 100%;
  min-height: 0;
  aspect-ratio: 1;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-template-rows: repeat(6, minmax(0, 1fr));
  gap: clamp(7px, 1.1vmin, 12px);
  justify-self: center;
  align-self: center;
}

.number-tile {
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  border: clamp(2px, 0.42vmin, 3px) solid rgba(255, 255, 255, 0.78);
  border-radius: clamp(16px, 2.8vmin, 26px);
  background: var(--tile-bg, var(--sun));
  color: #263238;
  cursor: pointer;
  font-size: clamp(1.55rem, 5vmin, 3.3rem);
  font-weight: 950;
  line-height: 1;
  box-shadow: 0 9px 18px rgba(71, 85, 105, 0.13);
  transition: transform 160ms ease, filter 160ms ease, opacity 160ms ease, box-shadow 160ms ease;
}

.number-tile:disabled {
  cursor: default;
}

.number-tile.is-found {
  opacity: 0.28;
  filter: saturate(0.6);
  box-shadow: none;
  text-decoration: line-through;
}

.number-tile.is-target {
  outline: 5px solid rgba(255, 255, 255, 0.88);
  box-shadow: 0 0 0 7px rgba(117, 199, 162, 0.34), 0 14px 28px rgba(71, 85, 105, 0.18);
}

.number-tile.is-wrong {
  animation: wiggle 360ms ease;
  filter: brightness(1.06) saturate(0.8);
}

.home-link:active,
.start-button:not(:disabled):active,
.secondary-button:active,
.rule-button:active,
.number-tile:active {
  transform: scale(0.97);
}

.result-dialog {
  width: min(92vw, 560px);
  padding: 0;
  border: 0;
  border-radius: 30px;
  background: transparent;
}

.result-dialog::backdrop {
  background: rgba(38, 50, 56, 0.34);
  backdrop-filter: blur(4px);
}

.result-panel {
  padding: 24px;
  border-radius: 30px;
  background: linear-gradient(160deg, #fffdf5, #e8f8ef);
  text-align: center;
}

.result-panel h2 {
  margin-bottom: 18px;
  font-size: clamp(2rem, 6vw, 3.8rem);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.result-grid div {
  padding: 16px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.72);
}

.result-grid span,
.result-grid strong {
  display: block;
}

.result-grid span {
  margin-bottom: 6px;
  color: #587084;
  font-weight: 900;
}

.result-grid strong {
  font-size: 1.25rem;
}

@keyframes wiggle {
  0%,
  100% {
    transform: translateX(0);
  }
  30% {
    transform: translateX(-7px);
  }
  70% {
    transform: translateX(7px);
  }
}

@keyframes targetErase {
  0% {
    clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
  }
  72% {
    clip-path: polygon(116% 0, 116% 0, 34% 100%, 0 100%);
    opacity: 1;
  }
  100% {
    clip-path: polygon(116% 0, 116% 0, 116% 100%, 116% 100%);
    opacity: 0;
  }
}

@keyframes targetMarkFade {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@media (orientation: portrait) and (min-width: 700px) {
  .app {
    gap: 10px;
    padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }

  .topbar {
    grid-template-columns: auto 1fr;
  }

  .hud-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .player-card {
    grid-template-columns: auto auto minmax(0, 1fr);
    grid-template-rows: auto auto;
  }

  .player-card strong {
    grid-column: 2;
    grid-row: 1;
  }

  .player-card span:last-of-type {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
  }

  .prompt-card {
    grid-column: 1 / -1;
    grid-row: 2;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1.2fr);
  }

  .board-stage {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: auto minmax(0, 1fr);
  }

  .side-start-one,
  .side-start-two {
    min-height: clamp(62px, 8dvh, 92px);
  }

  .number-board {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .number-board {
    width: min(calc(100vw - 28px), calc(100dvh - 278px));
    max-width: 100%;
  }
}

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .toolbar-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }
}

@media (max-width: 620px) {
  html,
  body {
    overflow: auto;
  }

  .app {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
    padding: 12px;
  }

  .game-shell {
    overflow: visible;
  }

  .hud-grid {
    grid-template-columns: 1fr;
  }

  .board-stage {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    overflow: visible;
  }

  .player-card,
  .prompt-card {
    grid-template-columns: 1fr;
  }

  .player-card strong,
  .player-label,
  .player-card span:last-of-type,
  .start-button,
  #roundLabel,
  #targetNumber,
  #instruction {
    grid-column: auto;
    grid-row: auto;
  }

  .number-board {
    grid-column: 1;
    grid-row: 3;
    width: 100%;
    height: auto;
    max-height: none;
    aspect-ratio: auto;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: none;
    grid-auto-rows: auto;
    gap: clamp(7px, 2.1vw, 10px);
  }

  .number-tile {
    aspect-ratio: 1;
  }

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

@media (orientation: landscape) and (max-height: 520px) {
  html,
  body {
    overflow: auto;
  }

  .app {
    height: auto;
    min-height: 100dvh;
    gap: 8px;
    overflow: visible;
    padding: max(6px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 8px;
  }

  .eyebrow {
    font-size: clamp(0.68rem, 2.3dvh, 0.78rem);
  }

  h1 {
    font-size: clamp(1.55rem, 7dvh, 2.15rem);
  }

  .toolbar-actions {
    gap: 6px;
    flex-wrap: nowrap;
  }

  .home-link,
  .secondary-button {
    min-height: 36px;
    padding: 0 10px;
    font-size: clamp(0.78rem, 2.9dvh, 0.9rem);
  }

  .rules {
    gap: 3px;
    padding: 4px;
  }

  .rule-button {
    min-height: 32px;
    padding: 0 10px;
    font-size: clamp(0.78rem, 2.9dvh, 0.9rem);
  }

  .game-shell {
    gap: 8px;
    overflow: visible;
  }

  .hud-grid {
    grid-template-columns: minmax(160px, 0.9fr) minmax(240px, 1.15fr) minmax(160px, 0.9fr);
    gap: 8px;
  }

  .player-card,
  .prompt-card {
    padding: 8px;
    border-radius: 16px;
  }

  .player-label {
    font-size: clamp(0.76rem, 2.8dvh, 0.9rem);
  }

  .player-card strong {
    font-size: clamp(1.35rem, 6.6dvh, 2.15rem);
  }

  .player-card span:last-of-type {
    font-size: clamp(0.74rem, 2.7dvh, 0.86rem);
  }

  .prompt-card {
    grid-template-columns: minmax(0, 0.9fr) auto minmax(0, 1.1fr);
  }

  #roundLabel,
  #instruction {
    font-size: clamp(0.72rem, 2.6dvh, 0.86rem);
  }

  #targetNumber {
    font-size: clamp(2rem, 9dvh, 3rem);
  }

  .board-stage {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: auto auto;
    gap: 8px;
    align-content: start;
    overflow: visible;
  }

  .side-start {
    min-height: 44px;
  }

  .start-button {
    height: auto;
    min-height: 44px;
    padding: 8px 12px;
    border-radius: 20px;
    font-size: clamp(0.88rem, 3.2dvh, 1rem);
  }

  .number-board {
    grid-column: 1 / -1;
    grid-row: 2;
    width: min(100%, 560px);
    max-height: none;
    aspect-ratio: 1;
    gap: clamp(6px, 1.5dvh, 9px);
  }

  .number-tile {
    border-radius: clamp(12px, 4dvh, 18px);
    font-size: clamp(1.45rem, 8dvh, 2.25rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  #targetNumber.is-revealing::after,
  #targetNumber.is-revealing::before {
    animation: fadeCover 180ms ease-out forwards;
  }
}

@keyframes fadeCover {
  from {
    opacity: 1;
  }

  to {
    opacity: 0;
  }
}
