:root {
  --desk: #d9e7ec;
  --desk-deep: #c2d7df;
  --paper: #f7f8ef;
  --paper-bright: #fffdf4;
  --ink: #17243d;
  --ink-soft: #58657a;
  --blue: #2354d8;
  --blue-deep: #163aa1;
  --blue-wash: #e2eaff;
  --red: #dc503d;
  --red-deep: #a92f22;
  --yellow: #f2c14e;
  --grid: rgba(47, 79, 105, 0.14);
  --hairline: rgba(23, 36, 61, 0.28);
  --display: "KaiTi", "STKaiti", "Kaiti SC", "Noto Serif SC", serif;
  --body: "Microsoft YaHei UI", "PingFang SC", "Noto Sans SC", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--body);
  background-color: var(--desk);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    radial-gradient(circle at 12% 8%, rgba(255, 255, 255, 0.78), transparent 32%),
    radial-gradient(circle at 88% 92%, rgba(35, 84, 216, 0.11), transparent 30%);
  background-size: 28px 28px, 28px 28px, 100% 100%, 100% 100%;
  overflow-x: hidden;
}

button {
  font: inherit;
  color: inherit;
}

.page-grain {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.28;
  background-image: radial-gradient(rgba(23, 36, 61, 0.38) 0.55px, transparent 0.8px);
  background-size: 5px 5px;
  mix-blend-mode: multiply;
}

.game-shell {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100% - 80px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 56px 0;
  display: grid;
  grid-template-columns: minmax(350px, 0.9fr) minmax(430px, 1fr);
  align-items: center;
  gap: clamp(48px, 7vw, 104px);
}

.intro {
  align-self: center;
  min-width: 0;
}

.masthead {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--hairline);
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.masthead-mark {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--paper-bright);
  font-family: var(--display);
  font-size: 1rem;
  transform: rotate(-3deg);
}

.issue-tag {
  margin-left: auto;
  padding-left: 14px;
  border-left: 1px solid var(--hairline);
  color: var(--ink-soft);
  font-weight: 500;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

[hidden] {
  display: none !important;
}

.auth-slot {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
}

.auth-slot[data-auth-state="loading"] .google-login-button {
  visibility: hidden;
}

.google-login-button,
.account-button {
  min-height: 31px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 5px 9px;
  border: 1px solid var(--ink);
  font-family: var(--body);
  font-size: 0.73rem;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.google-login-button {
  color: var(--ink);
  background: var(--paper-bright);
  box-shadow: 2px 2px 0 rgba(23, 36, 61, 0.16);
  transition: background-color 150ms ease, transform 150ms ease;
}

.google-login-button:hover {
  background: #eef3ff;
  transform: translateY(-1px);
}

.google-mark {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
}

.account-button {
  max-width: 142px;
  color: var(--paper-bright);
  background: var(--ink);
}

.account-button:hover {
  background: var(--blue-deep);
}

.account-avatar {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border-radius: 50%;
  object-fit: cover;
  background: var(--blue-wash);
}

.account-initial {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--ink);
  background: var(--yellow);
  font-size: 0.7rem;
}

.account-name {
  overflow: hidden;
  text-overflow: ellipsis;
}

.google-login-button:focus-visible,
.account-button:focus-visible,
.logout-button:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 3px;
}

.account-menu,
.auth-notice {
  position: absolute;
  top: calc(100% + 9px);
  right: 0;
  z-index: 20;
  width: 230px;
  padding: 13px 14px;
  border: 1px solid var(--ink);
  background: var(--paper-bright);
  box-shadow: 4px 5px 0 rgba(23, 36, 61, 0.17);
}

.account-menu-kicker {
  margin: 0 0 8px;
  color: var(--ink-soft);
  font-size: 0.68rem;
  font-weight: 600;
}

.account-menu-name {
  display: block;
  font-size: 0.9rem;
}

.account-menu-email {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  color: var(--ink-soft);
  font-size: 0.72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-button {
  width: 100%;
  min-height: 34px;
  margin-top: 12px;
  border: 1px solid var(--ink);
  background: transparent;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
}

.logout-button:hover:not(:disabled) {
  color: var(--paper-bright);
  background: var(--ink);
}

.logout-button:disabled {
  cursor: default;
  opacity: 0.55;
}

.auth-notice {
  width: 236px;
  color: var(--red-deep);
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1.55;
}

.title-lockup {
  position: relative;
  width: max-content;
  max-width: 100%;
  margin-top: 38px;
  padding: 0 18px 10px 2px;
}

.game-title {
  display: flex;
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(5.3rem, 9vw, 8.2rem);
  line-height: 0.9;
  letter-spacing: 0.02em;
}

.game-title span {
  display: inline-block;
}

.game-title span:nth-child(1) {
  color: var(--ink);
  transform: rotate(-5deg) translateY(3px);
}

.game-title span:nth-child(2) {
  color: var(--blue);
  transform: rotate(1deg) translateY(-8px);
}

.game-title span:nth-child(3) {
  color: var(--ink);
  transform: rotate(-1deg) translateY(4px);
}

.pencil-stroke {
  position: absolute;
  right: 0;
  bottom: 0;
  width: calc(100% - 14px);
  height: 7px;
  background: var(--red);
  opacity: 0.86;
  transform: rotate(-1.8deg);
  clip-path: polygon(0 16%, 96% 0, 100% 57%, 8% 100%, 1% 84%, 0 64%);
}

.intro-copy {
  max-width: 33ch;
  margin: 30px 0 34px;
  color: var(--ink-soft);
  font-size: 1.05rem;
  line-height: 1.9;
  letter-spacing: 0.015em;
}

.mode-block {
  max-width: 450px;
}

.section-label {
  margin: 0 0 11px;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 700;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1.5px solid var(--ink);
  background: rgba(247, 248, 239, 0.58);
  padding: 3px;
  box-shadow: 4px 4px 0 rgba(23, 36, 61, 0.13);
}

.mode-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 43px;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: color 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.mode-button:hover {
  background: rgba(255, 255, 255, 0.5);
}

.mode-button.is-active {
  color: var(--paper-bright);
  background: var(--ink);
}

.mode-button:focus-visible,
.action-button:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 3px;
}

.mode-icon {
  font-size: 0.9rem;
}

.tip-strip {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  max-width: 430px;
  margin-top: 34px;
  padding-top: 17px;
  border-top: 1px dashed var(--hairline);
  color: var(--ink-soft);
  font-size: 0.86rem;
  line-height: 1.65;
}

.tip-strip p {
  margin: 0;
}

.tip-strip strong {
  color: var(--ink);
}

.tip-number {
  flex: 0 0 auto;
  padding: 2px 7px;
  border: 1px solid var(--red);
  color: var(--red-deep);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.5;
  transform: rotate(-2deg);
}

.play-area {
  width: 100%;
  max-width: 560px;
  justify-self: end;
}

.game-sheet {
  position: relative;
  padding: 22px 24px 20px;
  background: var(--paper);
  border: 1.5px solid var(--ink);
  box-shadow:
    9px 11px 0 rgba(23, 36, 61, 0.16),
    0 26px 60px rgba(37, 62, 82, 0.15);
}

.game-sheet::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid rgba(23, 36, 61, 0.09);
  pointer-events: none;
}

.sheet-head {
  position: relative;
  z-index: 1;
}

.scoreboard {
  display: grid;
  grid-template-columns: 1fr 1px 1fr 1px 1fr;
  align-items: center;
  gap: 13px;
  padding: 2px 2px 16px;
}

.score-item {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 7px;
}

.score-label {
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 600;
}

.score-value {
  color: var(--ink);
  font-family: var(--display);
  font-size: 1.45rem;
  line-height: 1;
}

.score-divider {
  width: 1px;
  height: 19px;
  background: var(--hairline);
}

.turn-card {
  display: flex;
  align-items: center;
  gap: 15px;
  min-height: 90px;
  padding: 14px 17px;
  border-top: 1.5px solid var(--ink);
  border-bottom: 1.5px solid var(--ink);
  background: var(--blue-wash);
}

.turn-mark {
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
}

.turn-mark svg,
.mark svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.turn-mark svg path,
.mark svg path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.turn-mark.mark-x svg path,
.mark-x svg path {
  stroke: var(--blue);
}

.turn-mark.mark-o svg path,
.mark-o svg path {
  stroke: var(--red);
}

.turn-mark.mark-draw svg path.draw-x {
  stroke: var(--blue);
}

.turn-mark.mark-draw svg path.draw-o {
  stroke: var(--red);
}

.turn-mark.mark-draw svg path {
  stroke-width: 8;
}

.turn-mark svg {
  width: 44px;
  height: 44px;
}

.turn-mark svg path {
  stroke-width: 9;
}

.turn-kicker {
  margin: 0 0 2px;
  color: var(--ink-soft);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.status-text {
  margin: 0;
  font-size: 1.14rem;
  font-weight: 800;
  line-height: 1.3;
}

.status-detail {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 0.78rem;
}

.board-stage {
  position: relative;
  width: min(100%, 466px);
  margin: 22px auto 20px;
}

.board-shadow {
  position: absolute;
  inset: 10px -8px -10px 8px;
  background: var(--desk-deep);
  transform: rotate(1.2deg);
}

.board-row {
  display: contents;
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 5px;
  width: 100%;
  aspect-ratio: 1;
  padding: 5px;
  background: var(--ink);
  transform: rotate(-0.65deg);
  box-shadow: 0 2px 0 rgba(255, 255, 255, 0.3) inset;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 0;
  border: 0;
  background: var(--paper-bright);
  cursor: pointer;
  transition: background-color 150ms ease, box-shadow 150ms ease;
}

.cell::after {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px solid transparent;
  pointer-events: none;
  transition: border-color 150ms ease;
}

.cell:hover:not(:disabled) {
  background: #eef3ff;
}

.cell:hover:not(:disabled)::after {
  border-color: rgba(35, 84, 216, 0.24);
}

.cell:focus-visible {
  z-index: 2;
  outline: 4px solid var(--yellow);
  outline-offset: -6px;
}

.cell:disabled {
  cursor: default;
}

.cell.winner {
  background: #fff2c9;
  animation: winnerGlow 900ms ease-out;
}

.mark {
  width: 77%;
  height: 77%;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.mark svg path {
  stroke-width: 10;
  vector-effect: non-scaling-stroke;
  stroke-dasharray: 1;
  stroke-dashoffset: 0;
  animation: drawMark 280ms cubic-bezier(0.25, 0.8, 0.35, 1) both;
}

.mark-x svg path {
  stroke-width: 11;
}

.mark-x svg path:nth-child(2) {
  animation-delay: 90ms;
}

.win-line {
  position: absolute;
  inset: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
  opacity: 0;
  transition: opacity 120ms ease;
}

.win-line.is-visible {
  opacity: 1;
}

.win-line line {
  stroke: var(--red);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.8));
}

.win-line.is-visible line {
  animation: drawWinLine 420ms cubic-bezier(0.2, 0.7, 0.35, 1) 120ms forwards;
}

.sheet-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 2px;
}

.corner-note {
  max-width: 17ch;
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.74rem;
  line-height: 1.5;
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 38px;
  padding: 8px 13px;
  border: 1.5px solid var(--ink);
  background: transparent;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
}

.action-button:hover:not(:disabled) {
  transform: translateY(-2px);
}

.action-button.quiet:disabled {
  cursor: default;
  opacity: 0.38;
}

.action-button.quiet:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.56);
}

.action-button.primary {
  color: var(--paper-bright);
  background: var(--ink);
  box-shadow: 3px 3px 0 rgba(23, 36, 61, 0.2);
}

.action-button.primary:hover {
  background: var(--blue-deep);
  box-shadow: 4px 5px 0 rgba(23, 36, 61, 0.2);
}

.button-icon {
  font-size: 1rem;
  line-height: 1;
}

.keyboard-hint {
  margin: 22px 5px 0 auto;
  max-width: 430px;
  color: rgba(23, 36, 61, 0.7);
  font-size: 0.76rem;
  text-align: right;
}

@keyframes drawMark {
  from {
    stroke-dashoffset: 1;
  }
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes drawWinLine {
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes winnerGlow {
  0% { background: var(--paper-bright); }
  45% { background: #ffe891; }
  100% { background: #fff2c9; }
}

@media (max-width: 1020px) {
  .game-shell {
    width: min(960px, calc(100% - 48px));
    grid-template-columns: minmax(300px, 0.8fr) minmax(380px, 1fr);
    gap: 38px;
  }

  .game-title {
    font-size: clamp(4.7rem, 9vw, 6.7rem);
  }

  .intro-copy {
    margin-top: 24px;
  }

  .game-sheet {
    padding: 19px 19px 17px;
  }

  .board-stage {
    margin-top: 18px;
    margin-bottom: 17px;
  }
}

@media (max-width: 760px) {
  body {
    background-size: 24px 24px, 24px 24px, 100% 100%, 100% 100%;
  }

  .game-shell {
    width: min(560px, calc(100% - 30px));
    padding: 26px 0 38px;
    display: block;
  }

  .intro {
    text-align: center;
  }

  .masthead {
    text-align: left;
  }

  .title-lockup {
    margin: 28px auto 0;
  }

  .game-title {
    justify-content: center;
    font-size: clamp(4.2rem, 20vw, 5.8rem);
  }

  .intro-copy {
    max-width: 32ch;
    margin: 24px auto 28px;
    font-size: 0.96rem;
    line-height: 1.75;
  }

  .mode-block {
    max-width: none;
  }

  .section-label {
    text-align: left;
  }

  .tip-strip {
    max-width: none;
    margin-top: 27px;
    text-align: left;
  }

  .play-area {
    max-width: 520px;
    margin: 34px auto 0;
  }

  .game-sheet {
    padding: 17px 16px 16px;
    box-shadow:
      6px 8px 0 rgba(23, 36, 61, 0.15),
      0 20px 44px rgba(37, 62, 82, 0.14);
  }

  .turn-card {
    min-height: 82px;
    padding: 12px 13px;
    gap: 11px;
  }

  .turn-mark {
    width: 48px;
    height: 48px;
  }

  .turn-mark svg {
    width: 39px;
    height: 39px;
  }

  .status-text {
    font-size: 1.02rem;
  }

  .board-stage {
    margin: 16px auto 15px;
  }

  .sheet-foot {
    align-items: flex-end;
  }

  .corner-note {
    max-width: 15ch;
  }

  .keyboard-hint {
    margin-top: 17px;
    text-align: center;
  }
}

@media (max-width: 430px) {
  .game-shell {
    width: calc(100% - 22px);
    padding-top: 19px;
  }

  .game-title {
    font-size: clamp(3.8rem, 19vw, 5rem);
  }

  .intro-copy {
    margin-top: 20px;
    margin-bottom: 24px;
  }

  .scoreboard {
    gap: 8px;
  }

  .game-sheet {
    padding: 13px 11px 14px;
  }

  .sheet-foot {
    display: block;
  }

  .corner-note {
    max-width: none;
    margin-bottom: 11px;
  }

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

  .action-button {
    min-height: 42px;
  }
}

@media (max-width: 760px) {
  .masthead {
    gap: 7px;
  }

  .google-login-button,
  .account-button {
    padding-right: 8px;
    padding-left: 8px;
  }
}

@media (max-width: 430px) {
  .issue-tag {
    padding-left: 9px;
  }

  .google-login-button,
  .account-button {
    gap: 5px;
    padding-right: 7px;
    padding-left: 7px;
    font-size: 0.69rem;
  }

  .account-button {
    max-width: 112px;
  }

  .account-menu,
  .auth-notice {
    width: 210px;
  }
}

@media (max-width: 360px) {
  .issue-tag {
    display: none;
  }

  .login-label {
    display: none;
  }

  .google-login-button {
    width: 31px;
    padding: 4px;
  }
}

@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;
  }
}





