:root {
  color-scheme: light;
  --ink: #191d2b;
  --muted: #676b7e;
  --purple: #6d4aff;
  --purple-dark: #4d2ed4;
  --red: #e52332;
  --green: #20a66a;
  --surface: rgba(255, 255, 255, 0.84);
  --shadow: 0 18px 55px rgba(57, 42, 130, 0.14);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 12% 6%, rgba(255, 206, 95, 0.22), transparent 29rem),
    radial-gradient(circle at 92% 30%, rgba(125, 94, 255, 0.2), transparent 32rem),
    #f8f7ff;
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

html[lang="zh-CN"] body {
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", system-ui, sans-serif;
}

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

.background-orb {
  position: fixed;
  z-index: -1;
  border-radius: 50%;
  filter: blur(2px);
  opacity: 0.55;
}

.orb-one {
  width: 220px;
  height: 220px;
  top: 18%;
  left: -100px;
  background: #ffd46b;
}

.orb-two {
  width: 320px;
  height: 320px;
  right: -180px;
  bottom: 5%;
  background: #b7a8ff;
}

.game-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 42px 0 22px;
}

.hero {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 20px;
  margin-bottom: 24px;
}

.brand-mark {
  display: grid;
  width: 76px;
  height: 76px;
  place-items: center;
  border-radius: 23px;
  background: linear-gradient(145deg, #7658ff, #5d39ec);
  box-shadow: 0 14px 28px rgba(87, 57, 224, 0.28);
  color: #fff;
  font-size: 25px;
  font-weight: 900;
  letter-spacing: -2px;
  transform: rotate(-3deg);
}

.brand-mark span {
  color: #ffd862;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--purple);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 54px);
  line-height: 1;
  letter-spacing: -0.045em;
}

.subtitle {
  max-width: 660px;
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 16px;
}

.new-game-button,
.primary-button,
.secondary-button {
  border: 0;
  border-radius: 14px;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.header-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.language-switcher {
  display: flex;
  gap: 5px;
  padding: 5px;
  border: 1px solid rgba(109, 74, 255, 0.12);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.84);
  box-shadow: 0 9px 24px rgba(48, 41, 93, 0.1);
  backdrop-filter: blur(12px);
}

.language-button {
  display: grid;
  width: 38px;
  height: 34px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-size: 21px;
  line-height: 1;
  cursor: pointer;
  filter: grayscale(.55);
  opacity: .64;
  transition: transform 150ms ease, background 150ms ease, filter 150ms ease, opacity 150ms ease;
}

.language-button:hover {
  transform: translateY(-1px);
  background: #f1eeff;
  filter: grayscale(0);
  opacity: 1;
}

.language-button[aria-pressed="true"] {
  background: #ebe7ff;
  box-shadow: inset 0 0 0 2px rgba(109, 74, 255, .2);
  filter: grayscale(0);
  opacity: 1;
}

.language-button:focus-visible {
  outline: 3px solid #f3b725;
  outline-offset: 2px;
}

.flag-icon {
  position: relative;
  display: block;
  width: 26px;
  height: 18px;
  overflow: hidden;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(20, 20, 40, .14);
}

.flag-ru {
  background: linear-gradient(to bottom, #fff 0 33.333%, #2450a4 33.333% 66.666%, #d52b1e 66.666% 100%);
}

.flag-gb {
  background:
    linear-gradient(33deg, transparent 43%, #fff 43% 52%, transparent 52%),
    linear-gradient(-33deg, transparent 43%, #fff 43% 52%, transparent 52%),
    linear-gradient(33deg, transparent 47%, #c8102e 47% 50%, transparent 50%),
    linear-gradient(-33deg, transparent 47%, #c8102e 47% 50%, transparent 50%),
    linear-gradient(to right, transparent 39%, #fff 39% 61%, transparent 61%),
    linear-gradient(to bottom, transparent 34%, #fff 34% 66%, transparent 66%),
    linear-gradient(to right, transparent 45%, #c8102e 45% 55%, transparent 55%),
    linear-gradient(to bottom, transparent 42%, #c8102e 42% 58%, transparent 58%),
    #012169;
}

.flag-cn {
  background: #de2910;
}

.flag-cn::before {
  position: absolute;
  top: 1px;
  left: 3px;
  color: #ffde00;
  content: "★";
  font-size: 9px;
  line-height: 1;
}

.new-game-button {
  padding: 13px 18px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(48, 41, 93, 0.12);
  color: var(--purple-dark);
}

.new-game-button span {
  display: inline-block;
  margin-right: 5px;
  font-size: 20px;
  line-height: 0;
  vertical-align: -2px;
}

.new-game-button:hover,
.secondary-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 30px rgba(48, 41, 93, 0.18);
}

.new-game-button:active,
.primary-button:active,
.secondary-button:active {
  transform: translateY(1px);
}

.status-panel {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  overflow: hidden;
  margin-bottom: 22px;
  padding: 13px 20px 17px;
  border: 1px solid rgba(109, 74, 255, 0.1);
  border-radius: 19px;
  background: var(--surface);
  box-shadow: 0 12px 34px rgba(57, 42, 130, 0.08);
  backdrop-filter: blur(15px);
}

.status-item {
  display: flex;
  align-items: baseline;
  gap: 9px;
}

.status-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.status-item strong {
  min-width: 38px;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.status-item small {
  color: var(--muted);
  font-size: 13px;
}

.status-divider {
  width: 1px;
  height: 24px;
  background: #e2dff2;
}

.progress-track {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 5px;
  background: #ece9fb;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 0 4px 4px 0;
  background: linear-gradient(90deg, var(--purple), #a64fff);
  transition: width 450ms cubic-bezier(.2, .8, .2, 1);
}

.board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
}

.card {
  position: relative;
  width: 100%;
  min-width: 0;
  aspect-ratio: 4 / 3;
  padding: 0;
  border: 0;
  border-radius: 23px;
  outline: none;
  background: transparent;
  cursor: pointer;
  perspective: 1100px;
}

.card-inner {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  transform-style: preserve-3d;
  transition: transform 560ms cubic-bezier(.2, .75, .25, 1.15);
}

.card.is-flipped .card-inner,
.card.is-matched .card-inner {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: inherit;
  box-shadow: var(--shadow);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.card-back {
  border: 2px solid rgba(255, 255, 255, 0.46);
  background:
    linear-gradient(145deg, rgba(255,255,255,.12), transparent 48%),
    linear-gradient(145deg, #7355fa, #5532d6);
  color: #fff;
}

.card-back::before,
.card-back::after {
  position: absolute;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 50%;
  content: "";
}

.card-back::before {
  width: 150px;
  height: 150px;
  top: -90px;
  right: -55px;
}

.card-back::after {
  width: 110px;
  height: 110px;
  bottom: -72px;
  left: -35px;
}

.question-mark {
  display: grid;
  width: 66px;
  height: 66px;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-radius: 21px;
  background: rgba(255, 255, 255, 0.13);
  box-shadow: inset 0 0 20px rgba(255,255,255,.08);
  font-size: 39px;
  font-weight: 900;
  transform: rotate(-4deg);
}

.back-label {
  position: absolute;
  bottom: 15px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.18em;
  opacity: 0.75;
}

.card-front {
  border: 2px solid #fff;
  background: #fff;
  transform: rotateY(180deg);
}

.card-front img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.type-tag {
  position: absolute;
  z-index: 1;
  top: 10px;
  left: 10px;
  padding: 5px 8px;
  border: 1px solid #eceaf6;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: #737185;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.word-text {
  color: #1e2430;
  font-family: "Arial Rounded MT Bold", "Trebuchet MS", sans-serif;
  font-size: clamp(31px, 5.1vw, 68px);
  font-weight: 900;
  letter-spacing: -0.055em;
}

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

.card:hover:not(.is-flipped):not(.is-matched) .card-inner {
  transform: translateY(-5px) rotateX(2deg);
}

.card:focus-visible .card-inner {
  outline: 4px solid #f3b725;
  outline-offset: 4px;
}

.card.is-matched .card-front {
  border-color: #4ad693;
  box-shadow: 0 0 0 4px rgba(32, 166, 106, 0.15), var(--shadow);
  animation: matched 600ms ease both;
}

.card.is-matched {
  cursor: default;
}

@keyframes matched {
  0%, 100% { transform: rotateY(180deg) scale(1); }
  50% { transform: rotateY(180deg) scale(1.045); }
}

.tip {
  margin: 20px 0 0;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

footer {
  padding: 6px 20px 30px;
  text-align: center;
}

footer a {
  color: var(--purple-dark);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(19, 16, 40, 0.6);
  backdrop-filter: blur(8px);
}

.modal-card {
  position: relative;
  width: min(440px, 100%);
  padding: 34px;
  border-radius: 28px;
  background: #fff;
  box-shadow: 0 32px 80px rgba(14, 9, 45, 0.3);
  text-align: center;
  animation: modal-in 420ms cubic-bezier(.2, .9, .25, 1.15) both;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(20px) scale(.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.trophy {
  display: grid;
  width: 70px;
  height: 70px;
  margin: -4px auto 15px;
  place-items: center;
  border-radius: 22px;
  background: linear-gradient(145deg, #ffd568, #f6a91e);
  box-shadow: 0 12px 25px rgba(239, 164, 20, .28);
  color: #fff;
  font-size: 37px;
  transform: rotate(-5deg);
}

.modal-kicker {
  margin: 0 0 5px;
  color: var(--green);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .15em;
  text-transform: uppercase;
}

.modal h2 {
  margin: 0;
  font-size: 34px;
  letter-spacing: -.035em;
}

.modal-message {
  margin: 8px auto 20px;
  color: var(--muted);
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.result-grid div {
  padding: 14px;
  border-radius: 15px;
  background: #f5f3ff;
}

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

.result-grid strong {
  font-size: 24px;
}

.result-grid span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.record {
  min-height: 20px;
  margin: 13px 0;
  color: #b27b09;
  font-size: 13px;
  font-weight: 750;
}

.modal-actions {
  display: grid;
  gap: 9px;
}

.primary-button,
.secondary-button {
  padding: 13px 18px;
}

.primary-button {
  background: linear-gradient(135deg, var(--purple), var(--purple-dark));
  box-shadow: 0 12px 24px rgba(86, 54, 214, .24);
  color: #fff;
}

.primary-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 15px 29px rgba(86, 54, 214, .32);
}

.secondary-button {
  background: #f2f0fa;
  color: #4c4861;
}

.confetti-layer {
  position: fixed;
  z-index: 30;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 16px;
  border-radius: 3px;
  animation: confetti-fall var(--duration) linear var(--delay) forwards;
}

@keyframes confetti-fall {
  to {
    transform: translate3d(var(--drift), 110vh, 0) rotate(760deg);
    opacity: .9;
  }
}

@media (max-width: 760px) {
  .game-shell {
    position: relative;
    width: min(620px, calc(100% - 22px));
    padding-top: 70px;
  }

  .hero {
    grid-template-columns: auto 1fr;
    gap: 13px;
  }

  .brand-mark {
    width: 60px;
    height: 60px;
    border-radius: 18px;
    font-size: 20px;
  }

  .subtitle {
    font-size: 14px;
  }

  .header-actions {
    display: contents;
  }

  .language-switcher {
    position: absolute;
    top: 15px;
    right: 0;
  }

  .new-game-button {
    grid-column: 1 / -1;
    justify-self: stretch;
  }

  .board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .card {
    border-radius: 18px;
  }

  .status-panel {
    gap: 13px;
    padding-inline: 11px;
  }

  .status-item {
    display: grid;
    gap: 0;
    text-align: center;
  }

  .status-label {
    font-size: 10px;
  }

  .status-item strong {
    font-size: 18px;
  }

  .question-mark {
    width: 54px;
    height: 54px;
    border-radius: 17px;
    font-size: 32px;
  }

  .modal-card {
    padding: 28px 20px 22px;
  }
}

@media (max-width: 380px) {
  .word-text {
    font-size: 27px;
  }

  .type-tag {
    top: 7px;
    left: 7px;
    padding: 4px 6px;
    font-size: 7px;
  }
}

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