:root {
  --bg: #070a13;
  --surface: rgba(15, 23, 42, 0.72);
  --surface-strong: rgba(17, 27, 47, 0.9);
  --border: rgba(148, 163, 184, 0.14);
  --border-bright: rgba(148, 163, 184, 0.24);
  --text: #e8eefc;
  --muted: #8ea0bd;
  --cyan: #22d3ee;
  --violet: #a855f7;
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  padding: 22px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-x: hidden;
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  background:
    radial-gradient(circle at 12% -8%, rgba(34, 211, 238, 0.14), transparent 38%),
    radial-gradient(circle at 92% 108%, rgba(168, 85, 247, 0.13), transparent 42%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

button,
kbd {
  font-family: inherit;
}

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

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.orb {
  position: absolute;
  width: 340px;
  height: 340px;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.18;
}

.orb-cyan {
  top: -160px;
  left: -120px;
  background: var(--cyan);
  animation: drift 16s ease-in-out infinite alternate;
}

.orb-violet {
  right: -140px;
  bottom: -180px;
  background: var(--violet);
  animation: drift 19s ease-in-out infinite alternate-reverse;
}

.grid-glow {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(148, 163, 184, 0.038) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.038) 1px, transparent 1px);
  background-size: 64px 64px;
  -webkit-mask-image: radial-gradient(ellipse at center, #000 0%, transparent 74%);
  mask-image: radial-gradient(ellipse at center, #000 0%, transparent 74%);
}

.app {
  position: relative;
  z-index: 1;
  width: min(1000px, 100%);
  animation: appIn 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
}

.brand-mark {
  width: 46px;
  height: 46px;
  padding: 7px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  flex: 0 0 auto;
  border-radius: 14px;
  background: linear-gradient(150deg, rgba(30, 41, 59, 0.96), rgba(8, 13, 25, 0.96));
  border: 1px solid rgba(148, 163, 184, 0.16);
  box-shadow:
    0 12px 26px rgba(0, 0, 0, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.07);
  transform: rotate(-3deg);
}

.brand-mark span {
  border-radius: 4px;
}

.brand-mark span:nth-child(1) {
  background: linear-gradient(145deg, #67e8f9, #0891b2);
  box-shadow: 0 0 12px rgba(34, 211, 238, 0.45);
}

.brand-mark span:nth-child(2) {
  background: linear-gradient(145deg, #d8b4fe, #7e22ce);
  box-shadow: 0 0 12px rgba(168, 85, 247, 0.4);
}

.brand-mark span:nth-child(3) {
  background: linear-gradient(145deg, #fcd34d, #d97706);
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.35);
}

.brand-mark span:nth-child(4) {
  background: linear-gradient(145deg, #86efac, #15803d);
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.35);
}

.brand-copy {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 3px;
  color: rgba(148, 163, 184, 0.66);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.24em;
  white-space: nowrap;
}

.brand h1 {
  margin: 0;
  font-size: 23px;
  font-weight: 750;
  line-height: 1.1;
  letter-spacing: 0.035em;
  color: transparent;
  background: linear-gradient(100deg, #ffffff 10%, #a5f3fc 58%, #d8b4fe 100%);
  -webkit-background-clip: text;
  background-clip: text;
}

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

.chip-btn {
  min-height: 34px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: #cbd5e1;
  background: rgba(15, 23, 42, 0.62);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition:
    border-color 0.18s ease,
    color 0.18s ease,
    background 0.18s ease,
    transform 0.18s ease;
}

.chip-btn:hover:not(:disabled) {
  color: #f8fafc;
  border-color: rgba(34, 211, 238, 0.4);
  background: rgba(15, 32, 50, 0.86);
  transform: translateY(-1px);
}

.chip-btn:disabled {
  opacity: 0.36;
  cursor: default;
}

.game-shell {
  display: grid;
  grid-template-columns: 168px minmax(240px, 300px) 168px;
  gap: 18px;
  align-items: start;
  justify-content: center;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.panel {
  min-width: 0;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background:
    linear-gradient(160deg, rgba(22, 34, 58, 0.8), rgba(9, 16, 30, 0.76));
  box-shadow:
    0 18px 40px -18px rgba(0, 0, 0, 0.7),
    inset 0 1px 0 rgba(255, 255, 255, 0.045);
  backdrop-filter: blur(16px);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 5px;
  color: #cbd5e1;
  background: rgba(148, 163, 184, 0.07);
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.3);
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
}

.canvas-box {
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.08);
  border-radius: 10px;
  background:
    radial-gradient(circle at 50% 0%, rgba(34, 211, 238, 0.05), transparent 65%),
    rgba(3, 7, 15, 0.5);
  box-shadow: inset 0 1px 14px rgba(0, 0, 0, 0.35);
}

.canvas-box canvas {
  display: block;
  width: 100%;
  height: auto;
}

.stats-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stat {
  min-width: 0;
}

.stat-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.score-stat strong {
  display: block;
  overflow: hidden;
  color: #f8fafc;
  font-size: 30px;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
  line-height: 1;
  letter-spacing: -0.02em;
  text-overflow: ellipsis;
  text-shadow: 0 0 22px rgba(34, 211, 238, 0.22);
}

.best-stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid rgba(148, 163, 184, 0.1);
}

.best-stat .stat-label {
  margin: 0;
}

.best-stat strong {
  overflow: hidden;
  color: #cbd5e1;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  text-overflow: ellipsis;
}

.stat-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.mini-stat {
  padding: 8px 9px;
  border: 1px solid rgba(148, 163, 184, 0.09);
  border-radius: 10px;
  background: rgba(148, 163, 184, 0.045);
}

.mini-stat span {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.08em;
}

.mini-stat strong {
  color: #f1f5f9;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.level-progress {
  margin-top: 1px;
}

.progress-copy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  color: rgba(148, 163, 184, 0.72);
  font-size: 9px;
  letter-spacing: 0.04em;
}

.progress-track {
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.11);
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), #818cf8 60%, var(--violet));
  box-shadow: 0 0 12px rgba(34, 211, 238, 0.4);
  transition: width 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.board-column {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-width: 0;
}

.board-frame {
  position: relative;
  width: min(100%, calc((100vh - 210px) / 2));
  padding: 7px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 18px;
  background:
    linear-gradient(155deg, rgba(34, 211, 238, 0.22), rgba(168, 85, 247, 0.16) 42%, rgba(15, 23, 42, 0.92) 78%);
  box-shadow:
    0 0 0 1px rgba(34, 211, 238, 0.045),
    0 34px 70px -24px rgba(0, 0, 0, 0.9),
    0 0 58px -22px rgba(34, 211, 238, 0.28);
}

.board-frame canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
  background: #070b16;
}

.board-frame::after {
  content: "";
  position: absolute;
  inset: 7px;
  z-index: 2;
  border-radius: 12px;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(125, 211, 252, 0.38));
  mix-blend-mode: screen;
}

.board-frame.flash::after {
  animation: boardFlash 0.22s ease-out;
}

.board-frame.shake-small {
  animation: shakeSmall 0.2s ease-in-out;
}

.board-frame.shake-big {
  animation: shakeBig 0.28s ease-in-out;
}

.toast {
  position: absolute;
  top: 17%;
  left: 50%;
  z-index: 3;
  max-width: calc(100% - 28px);
  padding: 8px 14px;
  border: 1px solid rgba(34, 211, 238, 0.32);
  border-radius: 999px;
  opacity: 0;
  color: #e0f2fe;
  background: rgba(4, 10, 22, 0.82);
  box-shadow: 0 0 28px rgba(34, 211, 238, 0.18);
  backdrop-filter: blur(10px);
  font-size: 13px;
  font-weight: 750;
  letter-spacing: 0.07em;
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
  transform: translate(-50%, 8px) scale(0.94);
}

.toast.show {
  animation: toastPop 1.2s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.toast.mega {
  border-color: rgba(168, 85, 247, 0.6);
  color: #ffffff;
  box-shadow: 0 0 34px rgba(168, 85, 247, 0.38);
  font-size: 18px;
}

.overlay {
  position: absolute;
  inset: 7px;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 18px;
  border-radius: 12px;
  opacity: 0;
  visibility: hidden;
  background: rgba(3, 7, 15, 0.68);
  backdrop-filter: blur(9px);
  transition:
    opacity 0.22s ease,
    visibility 0.22s ease;
}

.overlay.visible {
  opacity: 1;
  visibility: visible;
}

.overlay-card {
  width: 100%;
  max-width: 238px;
  text-align: center;
  transform: translateY(8px) scale(0.98);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.overlay.visible .overlay-card {
  transform: none;
}

.overlay-eyebrow {
  display: block;
  color: var(--cyan);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.32em;
  text-shadow: 0 0 16px rgba(34, 211, 238, 0.5);
}

.overlay h2 {
  margin: 8px 0 10px;
  color: transparent;
  background: linear-gradient(100deg, #ffffff, #a5f3fc 55%, #d8b4fe);
  -webkit-background-clip: text;
  background-clip: text;
  font-size: 26px;
  font-weight: 800;
  line-height: 1.18;
  letter-spacing: 0.02em;
}

.overlay p {
  max-width: 208px;
  margin: 0 auto;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.7;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 17px 0 3px;
}

.result-grid[hidden] {
  display: none;
}

.result-grid div {
  padding: 8px 3px;
  border: 1px solid rgba(148, 163, 184, 0.11);
  border-radius: 10px;
  background: rgba(148, 163, 184, 0.055);
}

.result-grid span {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 8px;
  letter-spacing: 0.08em;
}

.result-grid strong {
  color: #f8fafc;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 18px;
}

.primary-btn,
.ghost-btn {
  width: 100%;
  min-height: 43px;
  border-radius: 11px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition:
    transform 0.16s ease,
    filter 0.16s ease,
    border-color 0.16s ease;
}

.primary-btn {
  border: 0;
  color: #041018;
  background: linear-gradient(135deg, #67e8f9, #818cf8 55%, #c084fc);
  box-shadow:
    0 12px 26px -8px rgba(34, 211, 238, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.primary-btn:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.primary-btn:active,
.ghost-btn:active {
  transform: translateY(1px);
}

.ghost-btn {
  border: 1px solid rgba(148, 163, 184, 0.2);
  color: #cbd5e1;
  background: rgba(148, 163, 184, 0.06);
}

.ghost-btn:hover {
  border-color: rgba(148, 163, 184, 0.38);
  transform: translateY(-1px);
}

.ghost-btn[hidden] {
  display: none;
}

.overlay-hint {
  margin-top: 10px !important;
  color: rgba(148, 163, 184, 0.55) !important;
  font-size: 9px !important;
  letter-spacing: 0.1em;
}

.key-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.key-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 10px;
}

.keys {
  display: flex;
  align-items: center;
  gap: 3px;
}

.space-key {
  padding-inline: 4px;
  font-size: 7px;
  letter-spacing: 0.04em;
}

.touch-controls {
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: min(100%, 380px);
  margin: 14px auto 0;
  user-select: none;
  touch-action: none;
}

.touch-controls button {
  height: 52px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 13px;
  color: #dbeafe;
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.94), rgba(12, 20, 36, 0.94));
  box-shadow:
    0 5px 0 rgba(0, 0, 0, 0.26),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  font-size: 19px;
  font-weight: 650;
  cursor: pointer;
  touch-action: none;
  transition:
    transform 0.08s ease,
    box-shadow 0.08s ease,
    border-color 0.12s ease;
}

.touch-controls button:nth-child(4),
.touch-controls button:nth-child(5),
.touch-controls button:nth-child(6) {
  font-size: 12px;
  letter-spacing: 0.06em;
}

.touch-controls button:active,
.touch-controls button.pressed {
  border-color: rgba(34, 211, 238, 0.44);
  box-shadow:
    0 2px 0 rgba(0, 0, 0, 0.26),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transform: translateY(3px);
}

.touch-controls .drop-btn {
  border-color: rgba(34, 211, 238, 0.3);
  color: #cffafe;
  background: linear-gradient(180deg, rgba(34, 211, 238, 0.2), rgba(8, 74, 94, 0.34));
}

.footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 17px;
  color: rgba(148, 163, 184, 0.5);
  font-size: 9px;
  letter-spacing: 0.08em;
}

.footer i {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(148, 163, 184, 0.3);
}

@keyframes appIn {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes drift {
  from {
    transform: translate3d(0, 0, 0) scale(1);
  }
  to {
    transform: translate3d(28px, 22px, 0) scale(1.08);
  }
}

@keyframes toastPop {
  0% {
    opacity: 0;
    transform: translate(-50%, 9px) scale(0.9);
  }
  14% {
    opacity: 1;
    transform: translate(-50%, 0) scale(1.02);
  }
  22% {
    transform: translate(-50%, 0) scale(1);
  }
  76% {
    opacity: 1;
    transform: translate(-50%, -2px) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -10px) scale(0.98);
  }
}

@keyframes boardFlash {
  0% {
    opacity: 0;
  }
  28% {
    opacity: 0.34;
  }
  100% {
    opacity: 0;
  }
}

@keyframes shakeSmall {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }
  30% {
    transform: translate3d(-2px, 1px, 0);
  }
  60% {
    transform: translate3d(2px, -1px, 0);
  }
  82% {
    transform: translate3d(-1px, 0, 0);
  }
}

@keyframes shakeBig {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }
  20% {
    transform: translate3d(-4px, 2px, 0) rotate(-0.2deg);
  }
  42% {
    transform: translate3d(4px, -2px, 0) rotate(0.2deg);
  }
  64% {
    transform: translate3d(-3px, 1px, 0);
  }
  82% {
    transform: translate3d(2px, -1px, 0);
  }
}

@media (hover: none), (max-width: 840px) {
  .touch-controls {
    display: grid;
  }
}

@media (max-width: 840px) {
  body {
    align-items: flex-start;
    padding: 14px 14px 22px;
  }

  .app {
    width: min(500px, 100%);
    margin: 0 auto;
  }

  .topbar {
    margin-bottom: 14px;
  }

  .brand {
    gap: 10px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
    padding: 6px;
    border-radius: 12px;
  }

  .brand h1 {
    font-size: 19px;
  }

  .eyebrow {
    font-size: 8px;
    letter-spacing: 0.18em;
  }

  .chip-btn {
    min-height: 32px;
    padding-inline: 10px;
    font-size: 10px;
  }

  .game-shell {
    grid-template-columns: minmax(0, 1fr) 106px;
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "board left"
      "board right";
    gap: 10px;
  }

  .board-column {
    grid-area: board;
    align-self: start;
    justify-content: center;
  }

  .board-frame {
    width: min(100%, 300px);
  }

  .side {
    gap: 9px;
  }

  .side-left {
    grid-area: left;
  }

  .side-right {
    grid-area: right;
    align-self: start;
  }

  .panel {
    padding: 9px;
    border-radius: 13px;
  }

  .panel-head {
    margin-bottom: 7px;
    font-size: 9px;
    letter-spacing: 0.1em;
  }

  .hold-panel kbd {
    display: none;
  }

  .stats-panel {
    gap: 8px;
  }

  .score-stat strong {
    font-size: 21px;
  }

  .best-stat,
  .level-progress {
    display: none;
  }

  .stat-pair {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .mini-stat {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 7px;
  }

  .mini-stat span {
    margin: 0;
    font-size: 8px;
  }

  .mini-stat strong {
    font-size: 13px;
  }

  .stat-label {
    font-size: 8px;
  }

  .controls-panel,
  .footer {
    display: none;
  }

  .touch-controls {
    margin-top: 12px;
  }

  .overlay {
    padding: 14px;
  }

  .overlay-card {
    max-width: 210px;
  }

  .overlay h2 {
    font-size: 22px;
  }

  .overlay p {
    font-size: 10px;
  }

  .primary-btn,
  .ghost-btn {
    min-height: 40px;
  }
}

@media (max-width: 400px) {
  body {
    padding-inline: 11px;
  }

  .game-shell {
    grid-template-columns: minmax(0, 1fr) 96px;
    gap: 8px;
  }

  .brand h1 {
    font-size: 17px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .eyebrow {
    display: none;
  }

  .chip-btn {
    padding-inline: 8px;
  }

  .touch-controls button {
    height: 48px;
  }
}

@media (max-height: 760px) and (min-width: 841px) {
  .board-frame {
    width: min(100%, calc((100vh - 190px) / 2));
  }

  .game-shell {
    grid-template-columns: 150px minmax(220px, 280px) 150px;
    gap: 15px;
  }

  .panel {
    padding: 11px;
  }

  .score-stat strong {
    font-size: 25px;
  }

  .footer {
    margin-top: 12px;
  }
}

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

  .toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
    animation: none !important;
  }
}
