:root {
  --bg-1: #0d1321;
  --bg-2: #18243c;
  --panel: rgba(9, 16, 29, 0.82);
  --panel-border: rgba(180, 208, 255, 0.16);
  --text-main: #eef5ff;
  --text-muted: #adc0db;
  --accent: #6ae3b9;
  --accent-soft: rgba(106, 227, 185, 0.14);
  --shadow: rgba(0, 0, 0, 0.35);
  --sticker-size: 48px;
  --sticker-ratio: 0.7895;
  --gap: 6px;
  color-scheme: dark;
  font-family: "Avenir Next", "PingFang SC", "Noto Sans SC", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top, rgba(69, 112, 204, 0.28), transparent 34%),
    radial-gradient(circle at bottom right, rgba(11, 196, 163, 0.22), transparent 30%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2));
  color: var(--text-main);
}

button,
input {
  font: inherit;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.site-nav {
  width: min(960px, calc(100vw - 32px));
  margin: 14px auto 0;
  padding: 10px 12px;
  display: flex;
  gap: 10px;
  justify-content: center;
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  background: rgba(9, 16, 29, 0.72);
  backdrop-filter: blur(16px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 12px 28px rgba(0, 0, 0, 0.22);
}

.site-nav-link {
  min-width: 92px;
  padding: 10px 14px;
  border-radius: 12px;
  color: var(--text-muted);
  text-decoration: none;
  text-align: center;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    color 140ms ease,
    background 140ms ease;
}

.site-nav-link:hover {
  transform: translateY(-1px);
  color: var(--text-main);
  border-color: rgba(106, 227, 185, 0.28);
}

.site-nav-link.is-active {
  color: #051019;
  background: linear-gradient(180deg, #7df4c8, #42b293);
  border-color: transparent;
}

.panel {
  width: min(960px, calc(100vw - 32px));
  margin: 0 auto 18px;
  padding: 18px 22px 22px;
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 20px 50px var(--shadow);
}

.panel-header {
  text-align: center;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 12px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 34px;
  line-height: 1.05;
}

h2 {
  font-size: 15px;
  color: var(--text-muted);
}

.controls {
  margin-top: 14px;
  padding: 18px;
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.controls-header,
.action-row {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
}

.controls-header {
  justify-content: space-between;
}

button {
  border: 0;
  border-radius: 14px;
  padding: 12px 14px;
  background: linear-gradient(180deg, #7df4c8, #42b293);
  color: #051019;
  font-weight: 700;
  cursor: pointer;
  transition:
    transform 140ms ease,
    filter 140ms ease,
    opacity 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.5;
  transform: none;
}

button.ghost {
  background: var(--accent-soft);
  color: var(--text-main);
  border: 1px solid rgba(106, 227, 185, 0.25);
}

.status-line {
  color: var(--text-muted);
}

.hidden {
  display: none !important;
}

.session-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 14px;
}

.stat-card {
  padding: 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  text-align: center;
}

.stat-label {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
}

.stat-value {
  display: block;
  margin-top: 6px;
  font-size: 18px;
  font-weight: 700;
}

.leaderboard-empty {
  margin-top: 12px;
  color: var(--text-muted);
  text-align: center;
}

.leaderboard-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.leaderboard-item {
  display: grid;
  grid-template-columns: 42px 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 13px;
}

.leaderboard-rank,
.leaderboard-name {
  font-weight: 700;
}

.leaderboard-meta,
.leaderboard-date {
  color: var(--text-muted);
}

.leaderboard-date {
  grid-column: 1 / -1;
}

.counter-card {
  text-align: center;
}

.counter-value {
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
}

.counter-label {
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 13px;
}

.stage-wrap {
  position: relative;
  display: grid;
  place-items: center;
  width: min(960px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 14px 0 4px;
  flex: 0 0 auto;
}

.stage {
  position: relative;
  width: 100%;
  height: min(64vh, 700px);
  overflow: hidden;
  border-radius: 28px;
  border: 1px solid rgba(196, 221, 255, 0.12);
  background:
    radial-gradient(circle at 50% 20%, rgba(180, 214, 255, 0.08), transparent 35%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.01));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 20px 60px var(--shadow);
  perspective: 2200px;
  cursor: grab;
  touch-action: none;
}

.stage:active {
  cursor: grabbing;
}

.stage-glow {
  position: absolute;
  inset: auto 24% 10% 24%;
  height: 18%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(58, 145, 255, 0.22), transparent 70%);
  filter: blur(22px);
}

.puzzle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform-style: preserve-3d;
  transform-origin: center center;
}

.cubie {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--sticker-size);
  height: var(--sticker-size);
  transform-style: preserve-3d;
  transition: transform 220ms ease;
}

.cubie.instant {
  transition: none;
}

.cubie.turning {
  transition: transform var(--turn-duration, 320ms) var(--turn-easing, ease);
  will-change: transform;
}

.cubie-core {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}

.cubie-fill {
  position: absolute;
  inset: 3px;
  border-radius: 7.5px;
  background: #14181f;
  transform: translateZ(0);
}

.face {
  position: absolute;
  inset: 0;
  border-radius: 7.5px;
  border: 0;
  background: transparent;
  transform-style: preserve-3d;
  backface-visibility: hidden;
}

.face::after {
  content: "";
  position: absolute;
  inset: calc(var(--sticker-size) * (1 - var(--sticker-ratio)) / 2);
  border-radius: 2.4px;
  background: var(--face-color, transparent);
  box-shadow: none;
}

.face.hidden::after {
  opacity: 0;
}

.face-logo {
  position: absolute;
  inset: calc(var(--sticker-size) * (1 - var(--sticker-ratio)) / 2 + 6px);
  border-radius: 2px;
  background: center / contain no-repeat url("./logo.png");
  opacity: 0;
  z-index: 1;
  pointer-events: none;
  transform: rotate(var(--logo-rotation, 0deg));
  transform-origin: center center;
}

.face.has-logo .face-logo {
  opacity: 1;
}

.face.right {
  transform: rotateY(90deg) translateZ(calc(var(--sticker-size) / 2));
}

.face.left {
  transform: rotateY(-90deg) translateZ(calc(var(--sticker-size) / 2));
}

.face.up {
  transform: rotateX(90deg) translateZ(calc(var(--sticker-size) / 2));
}

.face.down {
  transform: rotateX(-90deg) translateZ(calc(var(--sticker-size) / 2));
}

.face.front {
  transform: translateZ(calc(var(--sticker-size) / 2));
}

.face.back {
  transform: rotateY(180deg) translateZ(calc(var(--sticker-size) / 2));
}

.core-face {
  position: absolute;
  inset: 0;
  border-radius: 7.5px;
  border: 0;
  background: #14181f;
  backface-visibility: hidden;
}

@media (max-width: 720px) {
  .site-nav {
    width: calc(100vw - 20px);
    gap: 8px;
    padding: 8px;
  }

  .site-nav-link {
    min-width: 0;
    flex: 1 1 0;
    padding: 10px 8px;
  }

  .stage-wrap {
    width: calc(100vw - 20px);
  }

  .stage {
    width: 100%;
    height: min(56vh, 560px);
    border-radius: 22px;
  }

  .panel {
    width: calc(100vw - 20px);
    margin-bottom: 12px;
    padding: 16px;
  }

  h1 {
    font-size: 28px;
  }

  .controls {
    padding: 14px;
  }

  .action-row {
    flex-direction: column;
  }

  button {
    width: 100%;
  }

  .leaderboard-item {
    grid-template-columns: 36px 1fr;
  }
}

.core-face.right {
  transform: rotateY(90deg) translateZ(calc(var(--sticker-size) / 2));
}

.core-face.left {
  transform: rotateY(-90deg) translateZ(calc(var(--sticker-size) / 2));
}

.core-face.up {
  transform: rotateX(90deg) translateZ(calc(var(--sticker-size) / 2));
}

.core-face.down {
  transform: rotateX(-90deg) translateZ(calc(var(--sticker-size) / 2));
}

.core-face.front {
  transform: translateZ(calc(var(--sticker-size) / 2));
}

.core-face.back {
  transform: rotateY(180deg) translateZ(calc(var(--sticker-size) / 2));
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .stage-wrap {
    width: calc(100vw - 24px);
  }

  .panel {
    border-right: 0;
    border-bottom: 1px solid var(--panel-border);
  }

  .stage {
    width: 100%;
    height: min(58vh, 640px);
  }

  .controls-header,
  .action-row {
    flex-direction: column;
    align-items: stretch;
  }
}
