:root {
  --ink: #24242c;
  --muted: #77717f;
  --panel: rgba(255, 255, 255, 0.76);
  --panel-strong: rgba(255, 255, 255, 0.92);
  --line: rgba(80, 71, 92, 0.12);
  --tile: #faf3ea;
  --tile-border: #ded4c7;
  --accent: #48cbb9;
  --accent-dark: #219e90;
  --rose: #e84d74;
  --gold: #f0c35a;
  --shadow: 0 22px 60px rgba(85, 75, 112, 0.18);
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 27% 12%, rgba(247, 124, 137, 0.31) 0 42px, transparent 43px),
    radial-gradient(circle at 82% 11%, rgba(241, 148, 188, 0.32) 0 118px, transparent 119px),
    radial-gradient(circle at 51% 56%, rgba(96, 111, 225, 0.23) 0 88px, transparent 180px),
    linear-gradient(145deg, #eef8fb 0%, #fff7f0 42%, #f4efff 100%);
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(1120px, 100%);
  min-height: 100svh;
  margin: 0 auto;
  padding: clamp(18px, 3vw, 36px);
  display: grid;
  grid-template-columns: minmax(320px, 620px) minmax(280px, 360px);
  align-items: start;
  justify-content: center;
  gap: clamp(18px, 3vw, 30px);
}

.game-card,
.leaderboard-card {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.76);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.game-card {
  width: 100%;
  border-radius: 28px;
  padding: clamp(18px, 4vw, 30px);
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(24px, 5vw, 34px);
  line-height: 1.1;
  background: linear-gradient(90deg, #d94a70, #36bcae);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

h2 {
  font-size: 20px;
}

.mode-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 24px;
}

.mode-tab {
  min-width: 54px;
  min-height: 34px;
  border-radius: 999px;
  color: #3f3b44;
  background: rgba(255, 255, 255, 0.62);
  box-shadow: 0 8px 20px rgba(80, 72, 96, 0.08);
  transition: transform 160ms ease, color 160ms ease, background 160ms ease;
}

.mode-tab.active {
  color: var(--rose);
  background: rgba(255, 255, 255, 0.95);
  font-weight: 800;
}

.mode-tab:active,
.icon-button:active,
.tile:active {
  transform: scale(0.96);
}

.score-boxes {
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 12px;
  align-items: start;
}

.score-box {
  text-align: center;
  min-width: 50px;
}

.score-box span {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: #4b4650;
}

.score-box strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(28px, 5vw, 38px);
  line-height: 1;
  color: var(--rose);
}

.score-box:nth-child(2) strong {
  color: var(--accent-dark);
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: #4b4650;
  background: rgba(255, 250, 236, 0.92);
  box-shadow: 0 10px 20px rgba(80, 72, 96, 0.1);
  display: inline-grid;
  place-items: center;
  font-size: 26px;
}

.status-line {
  min-height: 34px;
  display: flex;
  align-items: center;
  color: var(--muted);
  font-weight: 700;
}

.board-wrap {
  width: 100%;
  display: grid;
  place-items: center;
  padding-top: 8px;
}

.board {
  --size: 5;
  width: min(100%, 540px);
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(var(--size), minmax(0, 1fr));
  grid-template-rows: repeat(var(--size), minmax(0, 1fr));
  gap: clamp(7px, 1.8vw, 12px);
}

.tile {
  min-width: 0;
  min-height: 0;
  border-radius: 10px;
  border: 1px solid var(--tile-border);
  color: #25252c;
  background: var(--tile);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    0 8px 16px rgba(74, 69, 80, 0.14);
  font-size: clamp(20px, calc(42vw / var(--size)), 48px);
  line-height: 1;
  display: grid;
  place-items: center;
  transition: transform 170ms ease, background 170ms ease, color 170ms ease, opacity 220ms ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.tile.selected {
  color: white;
  background: var(--accent);
  border-color: rgba(255, 255, 255, 0.5);
}

.tile.removing {
  opacity: 0;
  transform: scale(0.72);
  pointer-events: none;
}

.tile.empty {
  opacity: 0;
  pointer-events: none;
}

.tile.wrong {
  background: #ffdfda;
  color: #bd3348;
  animation: wrong 260ms ease;
}

.tile.hint {
  background: #fff0b8;
}

@keyframes wrong {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

.leaderboard-card {
  border-radius: 22px;
  padding: 22px;
}

.leaderboard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

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

.leaderboard-actions span {
  color: var(--rose);
  font-weight: 800;
}

.mini-button {
  min-width: 54px;
  min-height: 32px;
  border-radius: 999px;
  color: white;
  background: var(--rose);
  font-weight: 900;
}

.leaderboard-list {
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
  display: grid;
  gap: 10px;
}

.leaderboard-row,
.empty-rank {
  min-height: 44px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.52);
  display: grid;
  align-items: center;
}

.leaderboard-row {
  grid-template-columns: 38px 1fr auto;
  gap: 10px;
  padding: 8px 12px;
}

.leaderboard-rank {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(72, 203, 185, 0.17);
  color: var(--accent-dark);
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 13px;
}

.leaderboard-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.leaderboard-score {
  color: var(--rose);
  font-size: 20px;
  font-weight: 900;
}

.empty-rank {
  padding: 12px;
  color: var(--muted);
  text-align: center;
}

.score-dialog {
  width: min(360px, calc(100vw - 36px));
  border: 0;
  border-radius: 22px;
  padding: 0;
  color: var(--ink);
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}

.score-dialog::backdrop {
  background: rgba(34, 29, 42, 0.34);
  backdrop-filter: blur(6px);
}

.score-dialog form {
  padding: 24px;
  display: grid;
  gap: 16px;
}

.score-dialog p {
  margin: 0;
  color: var(--muted);
}

.score-dialog label {
  display: grid;
  gap: 8px;
  font-weight: 800;
}

.score-dialog input {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 12px;
  color: var(--ink);
  background: white;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primary-button,
.ghost-button {
  min-height: 44px;
  border-radius: 12px;
  font-weight: 900;
}

.primary-button {
  color: white;
  background: var(--rose);
}

.ghost-button {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
}

@media (max-width: 840px) {
  .app-shell {
    min-height: 100svh;
    grid-template-columns: minmax(0, 620px);
    padding: 14px;
  }

  .leaderboard-card {
    order: 2;
  }
}

@media (max-width: 520px) {
  .game-card {
    border-radius: 24px;
    padding: 18px;
  }

  .topbar {
    gap: 12px;
  }

  .score-boxes {
    gap: 6px;
  }

  .score-box {
    min-width: 42px;
  }

  .icon-button {
    width: 38px;
    height: 38px;
    font-size: 22px;
  }

  .mode-tabs {
    margin-top: 18px;
    gap: 6px;
  }

  .mode-tab {
    min-width: 46px;
    min-height: 31px;
  }
}
