:root {
  --canvas: #f4f6f3;
  --paper: #ffffff;
  --ink: #172524;
  --muted: #65716d;
  --rule: #d9dfda;
  --soft-rule: #e9ede9;
  --yellow: #f2b93b;
  --yellow-soft: #fff2c7;
  --coral: #e55747;
  --coral-soft: #fde9e5;
  --green: #267960;
  --green-soft: #dcefe7;
  --blue: #2d6174;
  --shadow: 0 18px 50px rgba(23, 37, 36, 0.09);
  font-family: "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--canvas);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background-color: var(--canvas);
  background-image: linear-gradient(rgba(23, 37, 36, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 37, 36, 0.035) 1px, transparent 1px);
  background-size: 32px 32px;
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid rgba(45, 97, 116, 0.35);
  outline-offset: 3px;
}

.app-shell {
  width: min(1480px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 28px 40px;
}

.topbar {
  min-height: 86px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid rgba(23, 37, 36, 0.16);
}

.brand,
.game-actions,
.turn-copy,
.player-identity,
.view-control,
.starter-control,
.result-actions {
  display: flex;
  align-items: center;
}

.brand {
  gap: 14px;
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(5, 22px);
  height: 34px;
  overflow: hidden;
  border: 2px solid var(--ink);
  background: var(--paper);
}

.brand-mark span {
  display: grid;
  place-items: center;
  border-right: 1px solid var(--ink);
  font-family: Arial, sans-serif;
  font-size: 15px;
  font-weight: 900;
}

.brand-mark span:last-child {
  border-right: 0;
}

.brand-title,
.brand-subtitle,
.eyebrow,
.turn-copy h1,
.turn-copy p,
.board-header h2,
.board-header p,
.result-dialog h2,
.result-dialog p {
  margin: 0;
}

.brand-title {
  font-size: 16px;
  font-weight: 800;
}

.brand-subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.game-actions {
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.room-bar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 3px;
  border-bottom: 1px solid rgba(23, 37, 36, 0.16);
}

.room-status-wrap,
.room-actions,
.room-join {
  display: flex;
  align-items: center;
}

.room-status-wrap {
  gap: 9px;
}

.connection-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 4px rgba(101, 113, 109, 0.12);
}

.connection-dot.is-live {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(38, 121, 96, 0.14);
}

.connection-dot.is-waiting {
  background: var(--yellow);
  box-shadow: 0 0 0 4px rgba(242, 185, 59, 0.16);
}

.room-label,
.room-status {
  margin: 0;
}

.room-label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.room-status {
  margin-top: 2px;
  font-size: 12px;
  font-weight: 700;
}

.room-actions {
  justify-content: flex-end;
  gap: 8px;
}

.room-join {
  gap: 6px;
}

.room-code-input {
  width: 92px;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--paper);
  color: var(--ink);
  font: 700 13px Arial, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.room-code-input:focus {
  border-color: var(--ink);
  outline: 3px solid rgba(45, 97, 116, 0.2);
  outline-offset: 1px;
}

.room-code-input::placeholder {
  color: var(--muted);
  letter-spacing: 0;
}

.room-copy-button {
  white-space: nowrap;
}

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

.button,
.segment {
  min-height: 40px;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--paper);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, background-color 150ms ease;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 15px;
}

.button:hover,
.segment:hover {
  border-color: var(--ink);
}

.button:active,
.segment:active {
  transform: translateY(1px);
}

.button-primary {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}

.view-control,
.starter-control {
  padding: 3px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.7);
}

.segment {
  min-height: 32px;
  padding: 0 12px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.segment-active {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}

.turn-band {
  min-height: 122px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 3px;
  border-bottom: 1px solid rgba(23, 37, 36, 0.16);
}

.turn-copy {
  gap: 16px;
}

.turn-avatar,
.player-token,
.result-stamp {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  font-family: Arial, sans-serif;
  font-weight: 900;
}

.turn-avatar {
  width: 54px;
  height: 54px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 4px 4px 0 var(--ink);
  font-size: 22px;
}

.eyebrow {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0;
}

.turn-copy h1 {
  margin-top: 3px;
  font-size: clamp(22px, 2.4vw, 32px);
  line-height: 1.2;
  letter-spacing: 0;
}

.turn-copy p:last-child {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.last-call {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.last-call strong {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border: 2px solid var(--coral);
  border-radius: 50%;
  background: var(--paper);
  color: var(--coral);
  font-family: Arial, sans-serif;
  font-size: 24px;
  font-weight: 900;
  transform: rotate(-3deg);
}

.arena {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  max-width: 1160px;
  margin: 0 auto;
  padding-top: 34px;
}

.board-sheet {
  position: relative;
  overflow: hidden;
  width: min(100%, 780px);
  padding: 20px 24px;
  border: 1px solid var(--rule);
  border-top: 5px solid transparent;
  border-radius: 6px;
  background: var(--paper);
  box-shadow: var(--shadow);
  transition: border-color 180ms ease, transform 180ms ease, box-shadow 180ms ease;
}

.board-sheet[hidden] {
  display: none;
}

.board-sheet.is-active {
  border-top-color: var(--yellow);
  box-shadow: 0 18px 55px rgba(23, 37, 36, 0.14);
  transform: translateY(-3px);
}

.board-sheet.is-primary {
  order: -2;
  width: min(100%, 1080px);
  padding: clamp(22px, 3vw, 34px);
}

.board-sheet.is-winner {
  border-top-color: var(--green);
}

.board-header {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.player-identity {
  gap: 10px;
}

.player-token {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  color: var(--paper);
  font-size: 14px;
}

.player-token-a {
  background: var(--blue);
}

.player-token-b {
  background: var(--coral);
}

.board-header h2 {
  font-size: 17px;
  line-height: 1.2;
}

.board-header p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.line-score {
  text-align: right;
}

.line-score span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.line-score strong {
  font-family: Arial, sans-serif;
  font-size: 18px;
}

.number-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  border-top: 2px solid var(--ink);
  border-left: 2px solid var(--ink);
}

.number-cell {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  border-right: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Arial, sans-serif;
  font-size: clamp(24px, 4.2vw, 44px);
  font-weight: 900;
  line-height: 1;
  cursor: default;
  transition: background-color 150ms ease, color 150ms ease;
}

.number-cell.can-pick {
  cursor: pointer;
}

.number-cell.can-pick:hover {
  z-index: 1;
  background: var(--yellow-soft);
  box-shadow: inset 0 0 0 3px var(--yellow);
}

.number-cell.is-called {
  background: var(--coral-soft);
  color: var(--coral);
}

.number-cell.is-called::after {
  content: "";
  position: absolute;
  width: 64%;
  height: 64%;
  border: 3px solid currentColor;
  border-radius: 50%;
  transform: rotate(-7deg);
}

.number-cell.in-line {
  background: var(--green-soft);
  color: var(--green);
}

.number-cell.fresh-line {
  animation: line-pop 620ms ease both;
}

.bingo-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-top: 12px;
}

.bingo-letter {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  height: 48px;
  color: var(--muted);
  font-family: Arial, sans-serif;
  font-size: clamp(23px, 3vw, 31px);
  font-weight: 900;
}

.bingo-letter.is-earned {
  color: var(--green);
}

.bingo-letter.is-earned::after {
  content: "";
  position: absolute;
  width: 39px;
  height: 39px;
  border: 3px solid var(--green);
  border-radius: 50%;
  transform: rotate(-8deg);
  animation: stamp-in 320ms ease both;
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 28px;
  max-width: calc(100vw - 32px);
  padding: 11px 16px;
  border-radius: 4px;
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 180ms ease, transform 180ms ease;
}

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

.result-dialog {
  width: min(430px, calc(100vw - 32px));
  padding: 34px;
  border: 1px solid var(--ink);
  border-radius: 7px;
  background: var(--paper);
  color: var(--ink);
  text-align: center;
  box-shadow: 8px 8px 0 var(--ink);
}

.result-dialog::backdrop {
  background: rgba(23, 37, 36, 0.48);
  backdrop-filter: blur(3px);
}

.result-stamp {
  width: 68px;
  height: 68px;
  margin: 0 auto 18px;
  border: 3px solid var(--green);
  border-radius: 50%;
  color: var(--green);
  font-size: 28px;
  transform: rotate(-6deg);
}

.result-dialog h2 {
  margin-top: 8px;
  font-size: 27px;
}

.result-dialog p:not(.eyebrow) {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.result-actions {
  justify-content: center;
  gap: 9px;
  margin-top: 24px;
}

@keyframes stamp-in {
  from {
    opacity: 0;
    transform: scale(1.45) rotate(-15deg);
  }
  to {
    opacity: 1;
    transform: scale(1) rotate(-8deg);
  }
}

@keyframes line-pop {
  0%, 100% {
    transform: scale(1);
  }
  45% {
    transform: scale(0.9);
    background: #bfe4d5;
  }
}

@media (max-width: 980px) {
  .app-shell {
    padding-inline: 20px;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding-inline: 14px;
    padding-bottom: 28px;
  }

  .topbar {
    align-items: flex-start;
    padding: 15px 0;
  }

  .brand-subtitle {
    display: none;
  }

  .game-actions {
    gap: 7px;
  }

  .room-bar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .room-actions {
    width: 100%;
    justify-content: stretch;
  }

  .room-actions > .button,
  .room-join {
    flex: 1;
  }

  .room-code-input {
    width: 100%;
  }

  .button,
  .segment {
    min-height: 36px;
    font-size: 12px;
  }

  .starter-control {
    order: 2;
    width: 100%;
  }

  .view-control .segment,
  .starter-control .segment {
    flex: 1;
  }

  .turn-band {
    min-height: 104px;
  }

  .last-call span {
    display: none;
  }

  .last-call strong {
    width: 50px;
    height: 50px;
    font-size: 21px;
  }

  .arena {
    gap: 18px;
    padding-top: 12px;
  }

  .board-sheet.is-primary {
    padding: 18px 16px;
  }

  .board-sheet.is-primary .number-cell {
    font-size: clamp(23px, 9vw, 38px);
  }
}

@media (max-width: 480px) {
  .topbar {
    display: block;
  }

  .game-actions {
    margin-top: 13px;
  }

  .game-actions > .button {
    flex: 1;
  }

  .room-actions {
    flex-wrap: wrap;
  }

  .room-join {
    min-width: 100%;
  }

  .room-copy-button {
    width: 100%;
  }

  .turn-copy {
    gap: 12px;
  }

  .turn-avatar {
    width: 46px;
    height: 46px;
    box-shadow: 3px 3px 0 var(--ink);
    font-size: 18px;
  }

  .turn-copy h1 {
    font-size: 21px;
  }

  .turn-copy p:last-child {
    max-width: 190px;
    font-size: 11px;
  }

  .bingo-letter {
    height: 42px;
  }

}

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