/* ═══════════════════════════════════════════════════════════════════
   THE PERFECT SHAPE — Immersive Drawing Game Styles
   Premium dark theme · Satisfying · Addictive · Tactile
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --bg: #0A0E14;
  --bg-2: #0F1520;
  --bg-3: #151D2B;
  --cream: #F7F2E8;
  --cream-2: #EFE8D6;
  --cream-3: #E5DCC4;
  --paper: #FBF7EE;
  --ink: #1A1814;

  --gold: #FFD166;
  --gold-dim: rgba(255, 209, 102, 0.15);
  --cyan: #4AEADC;
  --cyan-dim: rgba(74, 234, 220, 0.12);
  --rose: #FF6B8A;
  --rose-dim: rgba(255, 107, 138, 0.12);

  /* Game-specific accent palette */
  --perfect: #4AE68C;
  --great: #7BE68C;
  --good: #FFD166;
  --ok: #FF9B50;
  --miss: #FF4B4B;
  --purple: #A78BFA;
  --purple-dim: rgba(167, 139, 250, 0.15);

  --font-display: "Fraunces", "Times New Roman", serif;
  --font-body: "Plus Jakarta Sans", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
  --font-hand: "Caveat", "Comic Sans MS", cursive;

  --ease: cubic-bezier(.34, 1.56, .64, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-smooth: cubic-bezier(.25, .1, .25, 1);

  --topbar-h: 56px;
  --sidebar-w: 240px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--cream);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  position: fixed;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
::selection { background: var(--purple); color: #fff; }


/* ═══ Topbar ═══ */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  height: var(--topbar-h);
  background: rgba(10, 14, 20, 0.7);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.topbar__back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--cream-3);
  transition: all 0.2s;
  flex-shrink: 0;
}
.topbar__back:hover { border-color: var(--purple); color: var(--purple); }
.topbar__brand { display: flex; align-items: center; gap: 8px; }
.topbar__logo { width: 24px; height: 24px; }
.topbar__name {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 500;
  letter-spacing: -0.02em;
}
.topbar__name em { font-style: italic; color: var(--rose); }
.topbar__label {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.25);
}
.topbar__sound {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.45);
  transition: all 0.2s;
  flex-shrink: 0;
}
.topbar__sound:hover { border-color: var(--purple); color: var(--purple); }
.topbar__sound.is-muted { color: rgba(255, 255, 255, 0.15); }


/* ═══ Game layout ═══ */
.game {
  display: grid;
  grid-template-columns: 1fr var(--sidebar-w);
  grid-template-rows: 1fr;
  width: 100%;
  height: 100%;
  padding-top: var(--topbar-h);
}


/* ═══ Canvas area ═══ */
.game__canvas-wrap {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.game__paper-texture {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(167, 139, 250, 0.04) 0%, transparent 70%),
    radial-gradient(ellipse at 30% 70%, rgba(74, 230, 140, 0.02) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

.game__canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  cursor: crosshair;
  touch-action: none;
}

/* Live score display */
.game__live-score {
  position: absolute;
  top: 20px; left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}
.game__live-score.is-visible { opacity: 1; }

.game__live-pct {
  font-family: var(--font-display);
  font-size: 42px;
  font-weight: 400;
  font-variation-settings: "SOFT" 40;
  letter-spacing: -0.03em;
  color: var(--perfect);
  text-shadow: 0 0 30px rgba(74, 230, 140, 0.3);
  transition: color 0.6s ease, text-shadow 0.6s ease;
  font-variant-numeric: tabular-nums;
}
.game__live-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.25);
}

/* Draw hint */
.game__draw-hint {
  position: absolute;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(8px);
  opacity: 0.6;
  transition: opacity 0.4s ease;
  pointer-events: none;
}
.game__draw-hint.is-hidden { opacity: 0; }
.game__draw-hint-icon {
  font-size: 16px;
  color: var(--purple);
  animation: hintPulse 2.5s ease-in-out infinite;
}
.game__draw-hint-text {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.35);
}

@keyframes hintPulse {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.1); }
}

/* Clear button */
.game__clear {
  position: absolute;
  top: 20px; right: 20px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(8px);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.3);
  transition: all 0.25s ease;
  opacity: 0;
  pointer-events: none;
}
.game__clear.is-visible {
  opacity: 1;
  pointer-events: auto;
}
.game__clear:hover {
  border-color: var(--rose);
  color: var(--rose);
  background: var(--rose-dim);
}


/* ═══ Sidebar ═══ */
.game__sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
  border-left: 1px solid rgba(255, 255, 255, 0.06);
  overflow: hidden;
}
.sidebar__header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.sidebar__title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 400;
  font-variation-settings: "SOFT" 60;
  letter-spacing: -0.02em;
  color: var(--cream);
}
.sidebar__count {
  display: block;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.2);
}

.sidebar__shapes {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.08) transparent;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Shape button */
.shape-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1.5px solid transparent;
  background: transparent;
  text-align: left;
  transition: all 0.2s ease;
  cursor: pointer;
  position: relative;
}
.shape-btn:hover {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.06);
}
.shape-btn.is-active {
  background: var(--purple-dim);
  border-color: rgba(167, 139, 250, 0.3);
}
.shape-btn__icon {
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  flex-shrink: 0;
  transition: all 0.2s ease;
}
.shape-btn.is-active .shape-btn__icon {
  background: rgba(167, 139, 250, 0.15);
}
.shape-btn__icon svg {
  width: 20px; height: 20px;
  stroke: rgba(255, 255, 255, 0.4);
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke 0.2s ease;
}
.shape-btn.is-active .shape-btn__icon svg {
  stroke: var(--purple);
}
.shape-btn__info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.shape-btn__name {
  font-size: 13px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.6);
  transition: color 0.2s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.shape-btn.is-active .shape-btn__name { color: var(--cream); }
.shape-btn__diff {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.2);
}
.shape-btn__best {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: rgba(255, 255, 255, 0.15);
  flex-shrink: 0;
}
.shape-btn__best.has-score {
  color: var(--perfect);
  text-shadow: 0 0 8px rgba(74, 230, 140, 0.2);
}


/* ═══ Mobile shape toggle ═══ */
.game__shape-toggle {
  display: none;
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 999px;
  background: rgba(15, 21, 32, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(167, 139, 250, 0.25);
  font-size: 13px;
  font-weight: 500;
  color: var(--cream-3);
  transition: all 0.25s var(--ease);
}
.game__shape-toggle:active {
  transform: translateX(-50%) scale(0.95);
}
.game__shape-toggle-icon {
  font-size: 18px;
  color: var(--purple);
}


/* ═══ Mobile bottom sheet ═══ */
.game__bottom-sheet {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
}
.game__bottom-sheet.is-open {
  display: block;
}
.bottom-sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.game__bottom-sheet.is-open .bottom-sheet__backdrop {
  opacity: 1;
}
.bottom-sheet__content {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  max-height: 65vh;
  background: var(--bg-2);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding: 12px 20px 32px;
  transform: translateY(100%);
  transition: transform 0.35s var(--ease-out);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.game__bottom-sheet.is-open .bottom-sheet__content {
  transform: translateY(0);
}
.bottom-sheet__handle {
  width: 36px; height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.12);
  margin: 0 auto 16px;
}
.bottom-sheet__title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 400;
  text-align: center;
  margin-bottom: 16px;
  color: var(--cream-3);
}
.bottom-sheet__shapes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.bottom-sheet__shapes .shape-btn {
  flex-direction: column;
  text-align: center;
  gap: 6px;
  padding: 12px 8px;
}
.bottom-sheet__shapes .shape-btn__best {
  margin-left: 0;
}


/* ═══ Results overlay ═══ */
.results {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 14, 20, 0.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}
.results.is-visible {
  opacity: 1;
  pointer-events: auto;
}
.results__inner {
  text-align: center;
  max-width: 520px;
  padding: 40px 28px;
  position: relative;
}
.results__particles {
  position: absolute;
  inset: -100px;
  pointer-events: none;
  z-index: 0;
}
.results__eyebrow {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.25);
  position: relative;
  z-index: 1;
  opacity: 0;
}

.results__score-wrap {
  position: relative;
  display: inline-block;
  margin: 12px 0 8px;
  z-index: 1;
}
.results__score {
  font-family: var(--font-display);
  font-size: clamp(80px, 20vw, 160px);
  font-weight: 400;
  font-variation-settings: "SOFT" 30;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--perfect);
  text-shadow: 0 0 60px rgba(74, 230, 140, 0.3);
  font-variant-numeric: tabular-nums;
  opacity: 0;
}
.results__glow {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 200px; height: 200px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(74, 230, 140, 0.15) 0%, transparent 70%);
  pointer-events: none;
  opacity: 0;
  transition: all 1s ease;
}

.results__label {
  font-family: var(--font-display);
  font-style: italic;
  font-size: clamp(22px, 4vw, 32px);
  font-weight: 400;
  font-variation-settings: "SOFT" 100, "WONK" 1;
  color: var(--cream);
  position: relative;
  z-index: 1;
  opacity: 0;
}
.results__shape-name {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.2);
  margin-top: 4px;
  position: relative;
  z-index: 1;
  opacity: 0;
}

.results__breakdown {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-top: 36px;
  position: relative;
  z-index: 1;
  opacity: 0;
}
.results__stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.results__stat-value {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 400;
  color: var(--cream);
  font-variant-numeric: tabular-nums;
}
.results__stat-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.2);
}

.results__actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 40px;
  position: relative;
  z-index: 1;
  opacity: 0;
}
.results__btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 28px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  transition: all 0.25s var(--ease);
}
.results__btn--primary {
  background: var(--purple);
  color: #fff;
  border: 2px solid var(--purple);
}
.results__btn--primary:hover {
  transform: translate(-2px, -2px);
  box-shadow: 5px 5px 0 rgba(167, 139, 250, 0.25);
}
.results__btn--primary:active {
  transform: translate(1px, 1px);
  box-shadow: none;
}
.results__btn--ghost {
  color: var(--cream-3);
  border: 1.5px solid rgba(255, 255, 255, 0.12);
}
.results__btn--ghost:hover {
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.04);
}
.results__btn .arrow {
  transition: transform 0.25s var(--ease);
}
.results__btn:hover .arrow {
  transform: translateX(4px);
}

.results__best {
  margin-top: 20px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.15);
  position: relative;
  z-index: 1;
  opacity: 0;
}


/* ═══ Animations ═══ */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes glowPulse {
  0%, 100% { opacity: 0.3; transform: translate(-50%, -50%) scale(1); }
  50% { opacity: 0.6; transform: translate(-50%, -50%) scale(1.2); }
}
@keyframes celebrateShake {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-2deg); }
  75% { transform: rotate(2deg); }
}


/* ═══ Responsive — Mobile ═══ */
@media (max-width: 680px) {
  :root {
    --topbar-h: 48px;
    --sidebar-w: 0px;
  }

  .topbar__label { display: none; }
  .topbar { padding: 8px 16px; }

  .game {
    grid-template-columns: 1fr;
  }

  .game__sidebar {
    display: none;
  }

  .game__shape-toggle {
    display: flex;
  }

  .game__live-score {
    top: 12px;
  }
  .game__live-pct {
    font-size: 32px;
  }

  .game__clear {
    top: 12px;
    right: 12px;
  }

  .game__draw-hint {
    bottom: 72px;
  }

  .results__breakdown {
    gap: 20px;
  }
  .results__stat-value {
    font-size: 22px;
  }
  .results__actions {
    flex-direction: column;
    align-items: center;
  }

  .results__inner {
    padding: 32px 20px;
  }
}

@media (max-width: 400px) {
  .bottom-sheet__shapes {
    grid-template-columns: repeat(2, 1fr);
  }
  .results__breakdown {
    gap: 14px;
  }
}

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