/* ==========================================================================
   Test the jelly.
   Minimalist 3D Dessert Presentation
   ========================================================================== */

:root {
  --bg-table: #F4EBD9;
  --bg-card: rgba(250, 246, 238, 0.92);
  --text-ink: #1F1A17;
  --text-muted: #6E6259;
  --text-faint: #9C8F84;
  --border-hairline: rgba(70, 52, 38, 0.14);
  --border-strong: rgba(70, 52, 38, 0.28);
  --card-shadow: 0 16px 40px -12px rgba(45, 35, 25, 0.08), 0 2px 6px rgba(45, 35, 25, 0.04);
  
  --font-serif: 'Fraunces', 'Cormorant Garamond', Georgia, serif;
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-table);
  color: var(--text-ink);
  font-family: var(--font-sans);
  user-select: none;
  -webkit-user-select: none;
}

/* --------------------------------------------------------------------------
   3D Canvas Viewport
   -------------------------------------------------------------------------- */
#canvas-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  cursor: grab;
  touch-action: none;
}

#canvas-container:active {
  cursor: grabbing;
}

#webgl-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* --------------------------------------------------------------------------
   Header: Exactly one line
   -------------------------------------------------------------------------- */
.page-header {
  position: fixed;
  top: 0;
  left: 0;
  padding: 2.8rem 3.2rem;
  z-index: 10;
  pointer-events: none;
}

.header-title {
  font-family: var(--font-serif);
  font-size: clamp(2.4rem, 3.8vw, 3.4rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.0;
  color: var(--text-ink);
}

/* --------------------------------------------------------------------------
   Top Mode Toggle: Two words only (Plate / Play)
   -------------------------------------------------------------------------- */
.mode-nav {
  position: fixed;
  top: 2.8rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 500;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-hairline);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  box-shadow: var(--card-shadow);
}

.mode-btn {
  appearance: none;
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: inherit;
  color: var(--text-faint);
  cursor: pointer;
  transition: color 0.15s ease;
  padding: 0.15rem 0.4rem;
}

.mode-btn:hover {
  color: var(--text-ink);
}

.mode-btn.active {
  color: var(--text-ink);
  font-weight: 600;
}

.mode-slash {
  color: var(--text-faint);
  user-select: none;
}

/* --------------------------------------------------------------------------
   Play Start Line: You are dessert. They have spoons.
   -------------------------------------------------------------------------- */
.play-banner {
  position: fixed;
  top: 5.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.15rem;
  color: var(--text-ink);
  letter-spacing: 0.01em;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-hairline);
  border-radius: 999px;
  padding: 0.35rem 1.3rem;
  box-shadow: 0 4px 16px rgba(31, 26, 23, 0.06);
  pointer-events: none;
  animation: fadeInDown 0.35s ease-out;
  white-space: nowrap;
}

.play-banner.faded {
  opacity: 0;
  transform: translate(-50%, -8px);
  transition: opacity 0.8s ease, transform 0.8s ease;
  pointer-events: none;
}

@keyframes fadeInDown {
  from { opacity: 0; transform: translate(-50%, -6px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.link-again-play {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.05rem;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 0.4rem;
  transition: color 0.15s ease;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.link-again-play:hover {
  color: var(--text-ink);
}

/* --------------------------------------------------------------------------
   Persistent Dialogue (Always visible on page)
   -------------------------------------------------------------------------- */
.dialogue-card {
  position: fixed;
  bottom: 2.8rem;
  left: 3.2rem;
  z-index: 10;
  pointer-events: auto;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-hairline);
  border-radius: 12px;
  padding: 1.1rem 1.4rem;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.dialogue-q {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.05rem;
  color: var(--text-ink);
  line-height: 1.25;
}

.dialogue-a {
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-ink);
  letter-spacing: -0.01em;
  line-height: 1.25;
}

/* --------------------------------------------------------------------------
   Right-Side Controls (Plate Mode)
   -------------------------------------------------------------------------- */
.controls-panel {
  position: fixed;
  top: 50%;
  right: 3.2rem;
  transform: translateY(-50%);
  z-index: 10;
  width: 220px;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-hairline);
  border-radius: 16px;
  padding: 1.5rem 1.4rem;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

.control-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Shape Chips: Heart / Star / Baby */
.chip-group {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.35rem;
  background: rgba(70, 52, 38, 0.06);
  padding: 0.25rem;
  border-radius: 10px;
}

.chip {
  appearance: none;
  background: transparent;
  border: none;
  padding: 0.55rem 0.6rem;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  text-align: center;
}

.chip:hover {
  color: var(--text-ink);
}

.chip.active {
  background: #FFFFFF;
  color: var(--text-ink);
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(35, 25, 15, 0.08);
}

/* Firm -> Melt Slider */
.slider-row {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.slider-labels {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-sans);
  font-size: 0.80rem;
  font-weight: 600;
  color: var(--text-ink);
  letter-spacing: -0.01em;
}

.slider-arrow {
  color: var(--text-faint);
  font-size: 0.85rem;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  border-radius: 999px;
  background: rgba(70, 52, 38, 0.16);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--text-ink);
  border: 2px solid #FFFFFF;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.22);
  cursor: pointer;
  transition: transform 0.12s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

input[type="range"]::-moz-range-thumb {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--text-ink);
  border: 2px solid #FFFFFF;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.22);
  cursor: pointer;
}

/* Small "again" link */
.again-row {
  display: flex;
  justify-content: center;
  margin-top: 0.1rem;
}

.link-again {
  appearance: none;
  background: transparent;
  border: none;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(70, 52, 38, 0.35);
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

.link-again:hover {
  color: var(--text-ink);
  text-decoration-color: var(--text-ink);
}

/* Pull Button */
.btn-pull {
  appearance: none;
  background: var(--text-ink);
  color: #FAF6EE;
  border: none;
  border-radius: 10px;
  padding: 0.75rem 1rem;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 12px rgba(31, 26, 23, 0.18);
  text-align: center;
  width: 100%;
}

.btn-pull:hover {
  background: #000000;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(31, 26, 23, 0.24);
}

.btn-pull:active {
  transform: translateY(0);
}

.hidden {
  display: none !important;
}

/* --------------------------------------------------------------------------
   Play Mode Controls: Tactile Keyboard HUD (WASD + Space Hop)
   -------------------------------------------------------------------------- */
.play-controls {
  position: fixed;
  bottom: 2.8rem;
  right: 3.2rem;
  z-index: 20;
  display: flex;
  align-items: center;
}

.keyboard-hud {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  background: var(--bg-card);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border-hairline);
  box-shadow: var(--card-shadow);
  padding: 0.85rem 1.3rem;
  border-radius: 18px;
}

.key-cluster {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.keys-row {
  display: flex;
  gap: 4px;
}

.key-cap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: #FFFFFF;
  border: 1px solid rgba(31, 26, 23, 0.15);
  border-bottom: 2.5px solid rgba(31, 26, 23, 0.32);
  border-radius: 7px;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-ink);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  transition: all 0.08s ease;
  user-select: none;
}

.key-cap.active,
.key-cap:active {
  transform: translateY(2px);
  border-bottom-width: 1px;
  background: var(--text-ink);
  color: #FFFFFF;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.key-instructions {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.key-action {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-ink);
}

.key-sub {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.key-divider {
  width: 1px;
  height: 38px;
  background: var(--border-hairline);
  margin: 0 0.2rem;
}

.key-action-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.key-cap-action {
  width: auto;
  min-width: 60px;
  height: 32px;
  padding: 0 10px;
  cursor: pointer;
}

.key-cap-action:hover {
  background: #FAF6EE;
  border-color: rgba(31, 26, 23, 0.3);
}

.key-cap-action.active,
.key-cap-action:active {
  transform: translateY(2px);
  border-bottom-width: 1px;
  background: var(--text-ink);
  color: #FFFFFF;
}

/* --------------------------------------------------------------------------
   Best Survive Time Indicator (Top Right in Play mode)
   -------------------------------------------------------------------------- */
.play-best-time {
  position: fixed;
  top: 2.8rem;
  right: 3.2rem;
  z-index: 20;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-hairline);
  border-radius: 999px;
  padding: 0.35rem 0.95rem;
  box-shadow: var(--card-shadow);
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Play Game Overlay (Munch. / Packed.)
   -------------------------------------------------------------------------- */
.play-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(244, 235, 217, 0.52);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: overlayFadeIn 0.22s ease-out;
  cursor: pointer;
}

.play-overlay-card {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 24px;
  padding: 2.4rem 3.6rem;
  text-align: center;
  box-shadow: 0 24px 60px -12px rgba(45, 35, 25, 0.22);
  pointer-events: auto;
}

.play-overlay-title {
  font-family: var(--font-serif);
  font-size: 3.2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-ink);
  margin-bottom: 0.45rem;
}

.play-overlay-sub {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.01em;
  margin-bottom: 1.25rem;
}

.btn-play-again {
  display: inline-block;
  padding: 0.75rem 2.2rem;
  background: var(--text-ink, #1c1815);
  color: #faf6f0;
  border: none;
  border-radius: 9999px;
  font-family: var(--font-sans);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(28, 24, 21, 0.28);
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.btn-play-again:hover {
  background: #383028;
  transform: translateY(-2px);
  box-shadow: 0 8px 22px rgba(28, 24, 21, 0.36);
}

.btn-play-again:active {
  transform: translateY(1px);
  box-shadow: 0 2px 8px rgba(28, 24, 21, 0.2);
}

.confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 105;
}

.play-overlay-card.celebrate {
  border-color: rgba(245, 158, 11, 0.45);
  box-shadow: 0 28px 70px -10px rgba(245, 158, 11, 0.32), 0 12px 30px rgba(45, 35, 25, 0.15);
  background: linear-gradient(145deg, #fffdfa 0%, #fff6e8 100%);
  animation: celebratePop 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes celebratePop {
  0% { transform: scale(0.85); opacity: 0; }
  70% { transform: scale(1.05); }
  100% { transform: scale(1.0); opacity: 1; }
}

.celebrate-badge {
  font-size: 3.2rem;
  line-height: 1;
  margin-bottom: 0.6rem;
  animation: badgeBounce 1.2s infinite ease-in-out;
}

@keyframes badgeBounce {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-8px) rotate(6deg); }
}

.stat-time {
  display: inline-block;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  color: #b45309;
  background: #fef3c7;
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 9999px;
  padding: 0.35rem 1.2rem;
  margin-bottom: 1.25rem;
}

.btn-play-again.celebrate-btn {
  background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
  color: #ffffff;
  box-shadow: 0 4px 18px rgba(180, 83, 9, 0.35);
}

.btn-play-again.celebrate-btn:hover {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  box-shadow: 0 8px 24px rgba(180, 83, 9, 0.45);
}

@keyframes overlayFadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1.0); }
}

/* --------------------------------------------------------------------------
   Mobile Touch Controls
   -------------------------------------------------------------------------- */
.touch-controls {
  display: none;
}

@media (max-width: 860px), (hover: none) and (pointer: coarse) {
  .touch-controls {
    position: fixed;
    inset: 0;
    pointer-events: none;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 2.0rem 2.0rem 4.0rem 2.0rem;
    z-index: 50;
  }
  .touch-stick-zone {
    width: 110px;
    height: 110px;
    border-radius: 50%;
    background: rgba(250, 246, 238, 0.5);
    border: 2px dashed var(--border-strong);
    position: relative;
    pointer-events: auto;
    touch-action: none;
  }
  .touch-stick-thumb {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    box-shadow: 0 4px 12px rgba(45, 35, 25, 0.15);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
  }
  .touch-btn-cluster {
    display: flex;
    gap: 1.0rem;
    align-items: center;
    pointer-events: auto;
  }
  .touch-btn {
    border-radius: 999px;
    font-family: var(--font-sans);
    font-weight: 600;
    border: 1px solid var(--border-strong);
    background: var(--bg-card);
    box-shadow: 0 4px 14px rgba(45, 35, 25, 0.12);
    touch-action: none;
    user-select: none;
  }
  .touch-btn-hop {
    width: 62px;
    height: 62px;
    font-size: 0.92rem;
    color: var(--text-ink);
  }
  .touch-btn-flatten {
    width: 52px;
    height: 52px;
    font-size: 0.78rem;
    color: var(--text-muted);
  }
  .touch-btn:active, .touch-btn.active {
    background: var(--text-ink);
    color: #fff;
    transform: scale(0.94);
  }
  .keyboard-hud {
    display: none;
  }
  .play-best-time {
    top: 1.8rem;
    right: 1.6rem;
    font-size: 0.78rem;
    padding: 0.25rem 0.75rem;
  }
}

/* --------------------------------------------------------------------------
   Footer: Exactly one line
   -------------------------------------------------------------------------- */
.page-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 1.5rem 3.2rem;
  z-index: 10;
  pointer-events: none;
  display: flex;
  justify-content: flex-end;
}

.page-footer span {
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-faint);
  letter-spacing: 0.02em;
}

/* --------------------------------------------------------------------------
   Responsive Adaptations
   -------------------------------------------------------------------------- */
@media (max-width: 860px) {
  .page-header {
    padding: 1.8rem 1.6rem;
  }

  .header-title {
    font-size: 2.2rem;
  }

  .dialogue-card {
    left: 1.6rem;
    bottom: 4.5rem;
    padding: 0.9rem 1.1rem;
  }

  .controls-panel {
    top: auto;
    bottom: 4.5rem;
    right: 1.6rem;
    transform: none;
    width: 180px;
    padding: 1.1rem 1.0rem;
    gap: 1.0rem;
  }

  .page-footer {
    padding: 1.2rem 1.6rem;
    justify-content: center;
  }
}
