:root {
  --bg: #05070f;
  --panel: rgba(15, 23, 42, 0.62);
  --panel-strong: rgba(15, 23, 42, 0.86);
  --line: rgba(148, 163, 184, 0.16);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --cyan: #22d3ee;
  --violet: #a855f7;
  --pink: #ec4899;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Consolas, monospace;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--text);
  font-family: var(--sans);
  background:
    radial-gradient(1200px 700px at 12% -10%, rgba(34, 211, 238, 0.14), transparent 60%),
    radial-gradient(1000px 700px at 100% 0%, rgba(168, 85, 247, 0.16), transparent 55%),
    radial-gradient(900px 600px at 50% 120%, rgba(236, 72, 153, 0.1), transparent 60%),
    var(--bg);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(148, 163, 184, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.045) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at 50% 20%, #000 0%, transparent 75%);
  -webkit-mask-image: radial-gradient(circle at 50% 20%, #000 0%, transparent 75%);
}

.app {
  position: relative;
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 22px clamp(12px, 3vw, 28px) 28px;
}

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

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

.logo {
  display: grid;
  grid-template-columns: repeat(2, 9px);
  grid-template-rows: repeat(2, 9px);
  gap: 2px;
  transform: rotate(45deg);
  margin-right: 4px;
}

.logo i {
  display: block;
  border-radius: 2px;
  background: var(--cyan);
  box-shadow: 0 0 10px rgba(34, 211, 238, 0.7);
}

.logo i:nth-child(2) {
  background: var(--violet);
  box-shadow: 0 0 10px rgba(168, 85, 247, 0.7);
}

.logo i:nth-child(3) {
  background: var(--pink);
  box-shadow: 0 0 10px rgba(236, 72, 153, 0.7);
}

.logo i:nth-child(4) {
  background: #facc15;
  box-shadow: 0 0 10px rgba(250, 204, 21, 0.6);
}

.brand-text {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 0.24em;
  background: linear-gradient(100deg, #67e8f9 0%, #c084fc 55%, #f472b6 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  white-space: nowrap;
}

.brand-badge {
  display: inline-block;
  padding: 4px 8px;
  border: 1px solid rgba(34, 211, 238, 0.28);
  border-radius: 999px;
  color: #67e8f9;
  background: rgba(34, 211, 238, 0.07);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.16em;
  white-space: nowrap;
}

.ghost-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.08em;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.ghost-btn:hover {
  color: var(--text);
  border-color: rgba(34, 211, 238, 0.4);
  background: rgba(34, 211, 238, 0.08);
}

.ghost-btn[aria-pressed="false"] {
  color: #64748b;
  border-color: rgba(100, 116, 139, 0.25);
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  width: min(640px, 100%);
  margin: 0 auto 16px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  min-width: 0;
}

.stat-label {
  font-size: 9px;
  letter-spacing: 0.24em;
  color: var(--muted);
}

.stat-value {
  font-family: var(--mono);
  font-size: clamp(16px, 2.4vw, 22px);
  font-weight: 700;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat:first-child .stat-value {
  color: #67e8f9;
  text-shadow: 0 0 18px rgba(34, 211, 238, 0.55);
}

.stage {
  display: grid;
  grid-template-columns: 150px minmax(0, 300px) 150px;
  justify-content: center;
  align-items: start;
  gap: clamp(12px, 2.4vw, 24px);
}

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

.card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.card-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  margin: 0 0 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--text);
}

.card-title span {
  font-family: var(--mono);
  font-size: 8px;
  font-weight: 500;
  letter-spacing: 0.2em;
  color: #64748b;
}

.card-hint {
  margin: 6px 0 0;
  text-align: center;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.1em;
  color: #64748b;
}

.hold-canvas,
.next-canvas {
  display: block;
  margin: 0 auto;
  width: 84px;
  height: 84px;
}

.next-stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.next-canvas {
  width: 76px;
  height: 76px;
}

.next-canvas + .next-canvas {
  border-top: 1px dashed rgba(148, 163, 184, 0.12);
  padding-top: 4px;
  height: 80px;
}

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

.keys li {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: var(--muted);
}

.keys li > span {
  flex: 1;
  white-space: nowrap;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: rgba(30, 41, 59, 0.65);
  color: #cbd5e1;
  font-family: var(--mono);
  font-size: 9px;
  line-height: 1;
}

.board-wrap {
  position: relative;
  width: 100%;
  padding: 6px;
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(34, 211, 238, 0.5), rgba(168, 85, 247, 0.4));
  box-shadow:
    0 0 60px -18px rgba(34, 211, 238, 0.45),
    0 0 100px -30px rgba(168, 85, 247, 0.55),
    0 30px 60px -30px rgba(0, 0, 0, 0.9);
}

.board-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 18px;
  pointer-events: none;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.12), transparent 35%);
  mix-blend-mode: overlay;
}

.board {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 2;
  border-radius: 13px;
  background: #070b14;
  cursor: default;
  touch-action: none;
}

.board-wrap.flash {
  animation: board-flash 0.2s ease;
}

.board-wrap.shake {
  animation: board-shake 0.36s ease;
}

@keyframes board-flash {
  0% { filter: brightness(1); }
  45% { filter: brightness(1.9) saturate(1.3); }
  100% { filter: brightness(1); }
}

@keyframes board-shake {
  0%, 100% { transform: translate3d(0, 0, 0); }
  20% { transform: translate3d(-5px, 2px, 0); }
  40% { transform: translate3d(4px, -2px, 0); }
  60% { transform: translate3d(-3px, 1px, 0); }
  80% { transform: translate3d(2px, -1px, 0); }
}

.overlay {
  position: absolute;
  inset: 6px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: rgba(5, 7, 15, 0.78);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 5;
  transition: opacity 0.2s ease;
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  width: 100%;
  padding: 20px 16px;
  text-align: center;
}

.eyebrow {
  margin: 0 0 8px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.34em;
  color: #67e8f9;
}

.overlay h1 {
  margin: 0 0 10px;
  font-family: var(--mono);
  font-size: clamp(28px, 8vw, 42px);
  font-weight: 800;
  letter-spacing: 0.1em;
  line-height: 1.05;
  background: linear-gradient(100deg, #67e8f9, #c084fc 55%, #f472b6);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 26px rgba(168, 85, 247, 0.35));
}

.overlay p {
  margin: 0 auto 16px;
  max-width: 220px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
}

.primary-btn {
  appearance: none;
  border: 0;
  padding: 12px 30px;
  border-radius: 999px;
  background: linear-gradient(100deg, #22d3ee, #a855f7);
  color: #05070f;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  cursor: pointer;
  box-shadow: 0 10px 30px -8px rgba(34, 211, 238, 0.7);
  transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease;
}

.primary-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
  box-shadow: 0 14px 36px -8px rgba(168, 85, 247, 0.7);
}

.primary-btn:active {
  transform: translateY(0) scale(0.98);
}

.overlay-tip {
  margin: 12px 0 0 !important;
  font-family: var(--mono);
  font-size: 9px !important;
  letter-spacing: 0.08em;
  color: #64748b !important;
}

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

.touch-btn {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 50px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.04em;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
  transition: background 0.1s ease, transform 0.1s ease, border-color 0.1s ease;
}

.touch-btn.touch-wide {
  font-size: 11px;
  letter-spacing: 0.12em;
}

.touch-btn.active,
.touch-btn:active {
  transform: scale(0.96);
  border-color: rgba(34, 211, 238, 0.5);
  background: rgba(34, 211, 238, 0.16);
}

.footnote {
  margin: 18px 0 0;
  text-align: center;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  color: #475569;
}

@media (max-width: 860px) {
  .stage {
    grid-template-columns: 124px minmax(0, 280px) 124px;
    gap: 12px;
  }

  .hold-canvas,
  .next-canvas {
    width: 70px;
    height: 70px;
  }

  .next-canvas + .next-canvas {
    height: 74px;
  }

  .keys li {
    font-size: 9px;
  }
}

@media (max-width: 720px) {
  .app {
    padding: 16px 12px 22px;
  }

  .brand-badge {
    display: none;
  }

  .hud {
    gap: 7px;
    margin-bottom: 12px;
  }

  .stat {
    padding: 7px 9px;
    border-radius: 10px;
  }

  .stat-value {
    font-size: 15px;
  }

  .stage {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 9px;
    width: min(360px, 100%);
    margin: 0 auto;
  }

  .side {
    display: block;
  }

  .side-left {
    grid-column: 1;
    grid-row: 1;
  }

  .side-right {
    grid-column: 2;
    grid-row: 1;
  }

  .board-wrap {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: center;
    width: min(320px, 100%);
    margin-top: 2px;
  }

  .keys-card {
    display: none;
  }

  .card {
    padding: 9px;
    height: 100%;
  }

  .card-hint {
    font-size: 8px;
  }

  .hold-canvas {
    width: 58px;
    height: 58px;
  }

  .next-stack {
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 0;
    height: 58px;
  }

  .next-canvas,
  .next-canvas + .next-canvas {
    width: 56px;
    height: 56px;
    padding: 0;
    border-top: 0;
  }

  .next-canvas + .next-canvas {
    border-left: 1px dashed rgba(148, 163, 184, 0.12);
  }
}

@media (pointer: coarse) {
  .touch-controls {
    display: grid;
  }

  .keys-card {
    display: none;
  }
}

@media (max-width: 380px) {
  .brand-text {
    font-size: 15px;
    letter-spacing: 0.18em;
  }

  .touch-btn {
    height: 46px;
  }
}

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