:root {
  --ink: #161616;
  --muted: #979797;
  --line: #ececec;
  --paper: #ffffff;
  --canvas: #f2f2f0;
  --soft: #f8f8f7;
  --blue: #347fbe;
  --blue-soft: #edf5fc;
  --red: #d93434;
  --red-soft: #fff0ef;
  --green: #2e8b65;
  --green-soft: #edf8f2;
  --warm: #fff8df;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--canvas);
}

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  color: inherit;
  font: inherit;
}

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

.app-shell {
  width: min(100%, 500px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(15px, env(safe-area-inset-top)) 22px max(34px, env(safe-area-inset-bottom));
  background: var(--paper);
  box-shadow: 0 0 0 1px rgb(0 0 0 / 4%);
}

.topbar {
  display: grid;
  grid-template-columns: 44px 1fr 64px;
  min-height: 46px;
  align-items: center;
}

.topbar h1 {
  margin: 0;
  font-size: 25px;
  font-weight: 520;
  letter-spacing: 0;
  text-align: center;
}

.icon-button,
.rules-button {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.icon-button {
  display: inline-grid;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  place-items: center;
}

.icon-button:active {
  background: var(--soft);
}

.icon-button svg {
  width: 27px;
  height: 27px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.rules-button {
  justify-self: end;
  min-height: 34px;
  padding: 5px 13px;
  border: 1px solid #dedede;
  border-radius: 999px;
  color: #666;
  font-size: 13px;
}

.screen {
  min-width: 0;
}

.landing-screen {
  padding-top: 47px;
}

.landing-kicker {
  display: flex;
  margin-bottom: 23px;
  align-items: center;
  gap: 10px;
  color: #555;
  font-size: 16px;
  font-weight: 650;
}

.brand-dots {
  position: relative;
  display: inline-block;
  width: 39px;
  height: 25px;
}

.brand-dots::before,
.brand-dots::after {
  position: absolute;
  top: 2px;
  width: 23px;
  height: 23px;
  border-radius: 50%;
  content: "";
}

.brand-dots::before {
  left: 0;
  background: var(--red);
}

.brand-dots::after {
  right: 0;
  background: var(--blue);
  mix-blend-mode: multiply;
}

.landing-title {
  max-width: 390px;
  margin: 0;
  font-size: clamp(38px, 10.5vw, 49px);
  font-weight: 680;
  letter-spacing: 0;
  line-height: 1.14;
}

.landing-title span {
  color: var(--blue);
}

.landing-copy {
  max-width: 350px;
  margin: 17px 0 0;
  color: #707070;
  font-size: 16px;
  line-height: 1.7;
}

.entry-panel {
  margin-top: 34px;
  padding: 21px;
  border: 1px solid #ececec;
  border-radius: 24px;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  color: #666;
  font-size: 13px;
  font-weight: 650;
}

.text-input {
  width: 100%;
  height: 52px;
  padding: 0 14px;
  border: 1.5px solid #dddddd;
  border-radius: 14px;
  outline: 0;
  background: #fff;
  font-size: 17px;
  transition:
    border-color 140ms ease,
    box-shadow 140ms ease;
}

.text-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgb(52 127 190 / 11%);
}

.primary-button,
.secondary-button {
  display: inline-flex;
  min-height: 54px;
  padding: 12px 18px;
  border-radius: 999px;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 650;
  line-height: 1.2;
  cursor: pointer;
  transition:
    transform 140ms ease,
    background-color 140ms ease;
}

.primary-button {
  border: 1.5px solid var(--ink);
  background: var(--ink);
  color: #fff;
}

.secondary-button {
  border: 1.5px solid var(--ink);
  background: #fff;
  color: var(--ink);
}

.primary-button:active,
.secondary-button:active {
  transform: scale(0.985);
}

.primary-button:disabled {
  border-color: #d8d8d8;
  background: #d8d8d8;
  cursor: not-allowed;
}

.entry-panel .primary-button {
  width: 100%;
  margin-top: 18px;
}

.entry-divider {
  display: flex;
  margin: 22px 0 16px;
  color: #aaa;
  font-size: 12px;
  align-items: center;
  gap: 10px;
}

.entry-divider::before,
.entry-divider::after {
  height: 1px;
  background: var(--line);
  content: "";
  flex: 1;
}

.join-row {
  display: grid;
  grid-template-columns: 1fr 104px;
  gap: 9px;
}

.join-row .secondary-button {
  min-height: 52px;
  padding-right: 10px;
  padding-left: 10px;
  font-size: 15px;
}

.resume-panel {
  display: flex;
  margin-top: 14px;
  padding: 15px 17px;
  border: 1px solid #e7e7e7;
  border-radius: 16px;
  background: var(--soft);
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.resume-panel strong {
  display: block;
  font-size: 14px;
}

.resume-panel span {
  display: block;
  margin-top: 3px;
  color: #8c8c8c;
  font-size: 12px;
}

.text-action {
  padding: 6px 0;
  border: 0;
  background: transparent;
  color: var(--blue);
  font-size: 14px;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
}

.landing-note {
  margin: 15px 0 0;
  color: #aaa;
  font-size: 12px;
  line-height: 1.55;
  text-align: center;
}

.waiting-screen {
  padding-top: 38px;
}

.room-label {
  margin: 0;
  color: #8c8c8c;
  font-size: 13px;
  text-align: center;
}

.room-code {
  margin: 8px 0 0;
  font-size: 42px;
  font-weight: 720;
  letter-spacing: 0.12em;
  text-align: center;
}

.waiting-copy {
  margin: 9px 0 0;
  color: #777;
  font-size: 14px;
  line-height: 1.6;
  text-align: center;
}

.waiting-players {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
  margin-top: 34px;
}

.waiting-player {
  min-height: 196px;
  padding: 24px 12px 20px;
  border: 1px solid #e9e9e9;
  border-radius: 22px;
  text-align: center;
}

.waiting-player--empty {
  border-style: dashed;
  background: #fcfcfc;
}

.avatar {
  display: grid;
  width: 74px;
  height: 74px;
  margin: 0 auto 14px;
  border: 2px solid transparent;
  border-radius: 50%;
  background: var(--soft);
  font-size: 29px;
  font-weight: 700;
  place-items: center;
}

.avatar--blue {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue);
}

.avatar--red {
  border-color: var(--red);
  background: var(--red-soft);
  color: var(--red);
}

.avatar--empty {
  border: 1.5px dashed #cfcfcf;
  background: #fff;
  color: #b9b9b9;
}

.waiting-name {
  font-size: 17px;
  font-weight: 650;
}

.waiting-status {
  display: inline-flex;
  margin-top: 7px;
  color: #999;
  font-size: 12px;
  align-items: center;
  gap: 6px;
}

.waiting-status::before {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  content: "";
}

.invite-panel {
  margin-top: 24px;
  padding: 17px;
  border-radius: 18px;
  background: var(--soft);
}

.invite-panel p {
  margin: 0 0 8px;
  color: #777;
  font-size: 12px;
  font-weight: 650;
}

.invite-link {
  overflow: hidden;
  color: #666;
  font-size: 13px;
  line-height: 1.5;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.invite-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-top: 16px;
}

.invite-actions .primary-button,
.invite-actions .secondary-button {
  min-height: 46px;
  padding-right: 10px;
  padding-left: 10px;
  font-size: 14px;
}

.cancel-room {
  display: block;
  margin: 24px auto 0;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  color: #909090;
  font-size: 13px;
  cursor: pointer;
}

.game-screen {
  padding-top: 20px;
}

.game-brandline {
  display: flex;
  min-height: 40px;
  align-items: center;
  justify-content: space-between;
}

.mini-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 16px;
  font-weight: 650;
}

.mini-brand .brand-dots {
  transform: scale(0.75);
  transform-origin: left center;
}

.end-room-button {
  padding: 6px 0;
  border: 0;
  background: transparent;
  color: #888;
  font-size: 13px;
  cursor: pointer;
}

.players-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 18px;
}

.player-column {
  min-width: 0;
  text-align: center;
}

.previous-word {
  min-height: 42px;
  overflow-wrap: anywhere;
  font-size: 27px;
  font-weight: 650;
  line-height: 1.25;
}

.previous-word.is-empty {
  color: transparent;
  user-select: none;
}

.player-column .avatar {
  width: 72px;
  height: 72px;
  margin-bottom: 10px;
}

.player-name {
  overflow: hidden;
  font-size: 16px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-status {
  display: inline-flex;
  margin-top: 5px;
  color: #999;
  font-size: 12px;
  align-items: center;
  gap: 6px;
}

.player-status::before {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #c4c4c4;
  content: "";
}

.player-status.is-ready {
  color: var(--green);
}

.player-status.is-ready::before {
  background: var(--green);
}

.round-heading {
  display: flex;
  margin-top: 34px;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.round-number {
  display: flex;
  align-items: baseline;
  gap: 13px;
}

.round-number strong {
  font-size: 64px;
  font-weight: 750;
  letter-spacing: 0;
  line-height: 0.9;
}

.round-number span {
  font-size: 22px;
  font-weight: 650;
}

.round-prompt {
  margin: 13px 0 0;
  font-size: 23px;
  font-weight: 650;
  line-height: 1.45;
}

.recent-history {
  margin-top: 22px;
}

.recent-history-heading {
  display: flex;
  margin-bottom: 9px;
  align-items: center;
  justify-content: space-between;
  color: #999;
  font-size: 12px;
}

.recent-history-track {
  display: flex;
  overflow-x: auto;
  padding: 0 0 4px;
  gap: 8px;
  scrollbar-width: none;
}

.recent-history-track::-webkit-scrollbar {
  display: none;
}

.recent-chip {
  min-width: max-content;
  padding: 9px 12px;
  border: 1px solid #ededed;
  border-radius: 12px;
  background: var(--soft);
  font-size: 13px;
  line-height: 1.4;
}

.recent-chip strong {
  margin-right: 7px;
  color: #999;
  font-weight: 500;
}

.recent-chip .blue {
  color: var(--blue);
}

.recent-chip .red {
  color: var(--red);
}

.recent-chip .separator {
  margin: 0 5px;
  color: #aaa;
}

.answer-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 103px;
  gap: 13px;
  margin-top: 32px;
}

.answer-input {
  height: 58px;
  padding: 0 16px;
  border: 0;
  border-bottom: 1px solid #cfcfcf;
  border-radius: 0;
  outline: 0;
  background: transparent;
  font-size: 22px;
  font-weight: 520;
}

.answer-input::placeholder {
  color: #bcbcbc;
}

.answer-input:disabled {
  color: #777;
  opacity: 1;
}

.answer-box .primary-button {
  min-height: 50px;
  padding-right: 12px;
  padding-left: 12px;
  font-size: 16px;
}

.answer-note {
  margin: 10px 0 0;
  color: #999;
  font-size: 12px;
  line-height: 1.5;
}

.reveal-card {
  margin-top: 27px;
  padding: 20px;
  border-radius: 20px;
  background: var(--soft);
}

.reveal-pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 45px minmax(0, 1fr);
  align-items: center;
}

.reveal-word {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 24px;
  font-weight: 650;
  text-align: center;
}

.reveal-word--blue {
  color: var(--blue);
}

.reveal-word--red {
  color: var(--red);
}

.reveal-line {
  position: relative;
  height: 1px;
  background: #84afd5;
}

.reveal-line::before,
.reveal-line::after {
  position: absolute;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  transform: translateY(-50%);
  content: "";
}

.reveal-line::before {
  left: 0;
  background: var(--blue);
}

.reveal-line::after {
  right: 0;
  background: var(--red);
}

.reveal-copy {
  margin: 12px 0 0;
  color: #777;
  font-size: 14px;
  line-height: 1.55;
  text-align: center;
}

.reveal-card .primary-button {
  width: 100%;
  min-height: 48px;
  margin-top: 16px;
  font-size: 15px;
}

.history-section {
  margin-top: 33px;
}

.history-heading {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 18px;
  font-weight: 500;
}

.history-list {
  border-top: 1px solid var(--line);
}

.game-history-list {
  max-height: 320px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.history-row {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  min-height: 60px;
  border-bottom: 1px solid var(--line);
  align-items: center;
}

.history-row.is-match {
  margin-right: -7px;
  margin-left: -7px;
  padding-right: 7px;
  padding-left: 7px;
  border-radius: 8px;
  background: var(--green-soft);
}

.history-row.is-match .history-round {
  color: var(--green);
  font-weight: 650;
}

.history-round {
  color: #a7a7a7;
  font-size: 16px;
}

.history-pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px minmax(0, 1fr);
  align-items: center;
}

.history-word {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 20px;
  font-weight: 520;
  text-align: center;
}

.history-word--blue {
  color: var(--blue);
}

.history-word--red {
  color: var(--red);
}

.history-line {
  position: relative;
  height: 1px;
  background: #83aed4;
}

.history-line::before,
.history-line::after {
  position: absolute;
  top: 50%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  transform: translateY(-50%);
  content: "";
}

.history-line::before {
  left: 0;
  background: var(--blue);
}

.history-line::after {
  right: 0;
  background: var(--red);
}

.result-screen {
  padding-top: 30px;
}

.certificate {
  position: relative;
  overflow: hidden;
  padding: 30px 22px 26px;
  border: 1.5px solid var(--ink);
  border-radius: 24px;
  background: var(--warm);
}

.certificate::before,
.certificate::after {
  position: absolute;
  width: 112px;
  height: 112px;
  border: 1px solid rgb(21 21 21 / 9%);
  border-radius: 50%;
  content: "";
}

.certificate::before {
  top: -65px;
  left: -56px;
}

.certificate::after {
  right: -56px;
  bottom: -65px;
}

.certificate-label {
  margin: 0;
  color: #80744b;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-align: center;
}

.result-title {
  margin: 16px 0 0;
  font-size: 31px;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
}

.result-badge {
  display: table;
  margin: 15px auto 0;
  padding: 7px 13px;
  border-radius: 999px;
  background: rgb(46 139 101 / 12%);
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
}

.final-pair {
  display: flex;
  margin-top: 18px;
  align-items: center;
  justify-content: center;
  gap: 13px;
}

.final-pair span {
  display: block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #aaa;
}

.final-pair strong {
  font-size: 29px;
  font-weight: 700;
}

.result-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 22px;
  border-top: 1px solid rgb(21 21 21 / 12%);
  border-bottom: 1px solid rgb(21 21 21 / 12%);
}

.result-metric {
  padding: 16px 7px;
  border-right: 1px solid rgb(21 21 21 / 10%);
  text-align: center;
}

.result-metric:last-child {
  border-right: 0;
}

.result-metric strong {
  display: block;
  font-size: 22px;
  font-weight: 720;
}

.result-metric span {
  display: block;
  margin-top: 4px;
  color: #7c735a;
  font-size: 11px;
}

.result-rounds {
  display: flex;
  margin-top: 12px;
  align-items: baseline;
  justify-content: center;
  gap: 5px;
}

.result-rounds strong {
  font-size: 70px;
  font-weight: 760;
  line-height: 1;
}

.result-rounds span {
  color: #7b735c;
  font-size: 20px;
}

.result-copy {
  margin: 12px 0 0;
  color: #756e58;
  font-size: 14px;
  line-height: 1.65;
  text-align: center;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px;
  margin-top: 20px;
}

.result-actions .primary-button,
.result-actions .secondary-button {
  min-height: 50px;
  padding-right: 8px;
  padding-left: 8px;
  font-size: 15px;
}

.result-actions .button-content {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.result-actions svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.replay-button {
  display: block;
  margin: 15px auto 0;
  padding: 7px 12px;
  border: 0;
  background: transparent;
  color: #777;
  font-size: 14px;
  cursor: pointer;
}

.rules-dialog {
  width: min(calc(100% - 34px), 440px);
  padding: 0;
  border: 0;
  border-radius: 25px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 24px 80px rgb(0 0 0 / 22%);
}

.rules-dialog::backdrop {
  background: rgb(0 0 0 / 42%);
}

.dialog-heading {
  display: flex;
  padding: 23px 23px 8px;
  align-items: center;
  justify-content: space-between;
}

.dialog-heading h2 {
  margin: 0;
  font-size: 25px;
}

.dialog-close {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #f4f4f4;
  color: #777;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.rule-list {
  margin: 9px 0 0;
  padding: 0 23px 19px 56px;
  color: #777;
}

.rule-list li {
  padding: 0 0 18px 4px;
  font-size: 14px;
  line-height: 1.55;
}

.rule-list strong {
  display: block;
  color: var(--ink);
  font-size: 18px;
}

.rule-list span {
  display: block;
  margin-top: 4px;
}

.rules-dialog > .primary-button {
  width: calc(100% - 46px);
  margin: 0 23px 23px;
}

.toast {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 50%;
  z-index: 20;
  width: max-content;
  max-width: calc(100vw - 40px);
  padding: 11px 18px;
  border-radius: 999px;
  background: rgb(21 21 21 / 93%);
  color: #fff;
  font-size: 14px;
  line-height: 1.35;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

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

@media (max-width: 420px) {
  .app-shell {
    padding-right: 16px;
    padding-left: 16px;
  }

  .topbar h1 {
    font-size: 23px;
  }

  .landing-screen {
    padding-top: 35px;
  }

  .landing-title {
    font-size: 39px;
  }

  .entry-panel {
    padding: 18px;
  }

  .previous-word {
    min-height: 36px;
    font-size: 22px;
  }

  .player-column .avatar {
    width: 64px;
    height: 64px;
  }

  .round-number strong {
    font-size: 57px;
  }

  .round-number span {
    font-size: 20px;
  }

  .round-prompt {
    font-size: 21px;
  }

  .answer-box {
    grid-template-columns: minmax(0, 1fr) 92px;
    gap: 8px;
  }

  .answer-input {
    padding-right: 8px;
    padding-left: 8px;
    font-size: 19px;
  }

  .history-row {
    grid-template-columns: 51px minmax(0, 1fr);
  }

  .history-round {
    font-size: 15px;
  }

  .history-pair {
    grid-template-columns: minmax(0, 1fr) 30px minmax(0, 1fr);
  }

  .history-word {
    font-size: 18px;
  }
}

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