/* ============================================
   GRANDMA'S KNITTING CORNER — Main Stylesheet
   Warm, cozy, handmade aesthetic
   ============================================ */

:root {
  --cream: #FAF3E0;
  --warm-white: #FDF8F0;
  --tan: #E8D5B7;
  --brown: #8B6F47;
  --dark-brown: #4A3728;
  --dusty-rose: #D4A5A5;
  --sage: #8FAF8F;
  --dusty-blue: #7A9DB5;
  --gold: #C9A84C;
  --warm-shadow: rgba(74, 55, 40, 0.15);
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body: 'Lora', Georgia, serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-body);
  background: var(--dark-brown);
  color: var(--cream);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  user-select: none;
}

/* ============================================
   CANVAS
   ============================================ */
#game-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  display: none;
  cursor: crosshair;
}

/* ============================================
   SPLASH SCREEN
   ============================================ */
#splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.splash-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 80%, rgba(201, 168, 76, 0.3) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(212, 165, 165, 0.3) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, rgba(143, 175, 143, 0.15) 0%, transparent 70%),
    linear-gradient(160deg, #2C1810 0%, #4A3728 40%, #3D2B1F 100%);
  overflow: hidden;
}

.splash-bg::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23c9a84c' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  opacity: 0.5;
}

.splash-content {
  position: relative;
  text-align: center;
  animation: splashIn 1s ease-out;
}

@keyframes splashIn {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

.yarn-balls-deco {
  font-size: 3rem;
  margin-bottom: 1rem;
  animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.splash-content h1 {
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 6vw, 5rem);
  font-weight: 700;
  color: var(--cream);
  text-shadow: 0 4px 20px rgba(0,0,0,0.5);
  line-height: 1.1;
  margin-bottom: 0.5rem;
}

.tagline {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.3rem;
  color: var(--gold);
  margin-bottom: 2.5rem;
  opacity: 0.9;
}

.splash-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: center;
}

.btn-main {
  background: linear-gradient(135deg, var(--gold) 0%, #A8872D 100%);
  color: var(--dark-brown);
  border: none;
  padding: 1rem 2.5rem;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 6px 24px rgba(201, 168, 76, 0.4);
  min-width: 220px;
}

.btn-main:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 10px 32px rgba(201, 168, 76, 0.6);
}

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

.btn-secondary {
  background: rgba(255,255,255,0.08);
  color: var(--cream);
  border: 1px solid rgba(255,255,255,0.2);
  padding: 0.8rem 2rem;
  font-family: var(--font-body);
  font-size: 1rem;
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 220px;
  backdrop-filter: blur(8px);
}

.btn-secondary:hover {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.4);
  transform: translateY(-2px);
}

.version-note {
  margin-top: 1.5rem;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.3);
  font-style: italic;
}

/* ============================================
   GALLERY SCREEN
   ============================================ */
#gallery-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: linear-gradient(160deg, #2C1810 0%, #4A3728 100%);
  overflow-y: auto;
  padding: 2rem;
}

.gallery-header {
  text-align: center;
  margin-bottom: 2rem;
  position: relative;
}

.gallery-header h2 {
  font-family: var(--font-display);
  font-size: 2.5rem;
  color: var(--gold);
}

.gallery-header p {
  color: var(--tan);
  font-style: italic;
}

.btn-back {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.1);
  color: var(--cream);
  border: 1px solid rgba(255,255,255,0.2);
  padding: 0.6rem 1.2rem;
  font-family: var(--font-body);
  border-radius: 30px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-back:hover {
  background: rgba(255,255,255,0.2);
}

#gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
}

.gallery-card {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(8px);
}

.gallery-card:hover {
  transform: translateY(-6px);
  border-color: rgba(201, 168, 76, 0.4);
  box-shadow: 0 12px 40px rgba(0,0,0,0.4);
}

.gallery-card-preview {
  width: 100%;
  height: 200px;
  background: #1a0f08;
  position: relative;
  overflow: hidden;
}

.gallery-card-preview canvas {
  width: 100%;
  height: 100%;
}

.gallery-card-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-card-info {
  padding: 1rem;
}

.gallery-card-info h3 {
  font-family: var(--font-display);
  color: var(--cream);
  margin-bottom: 0.25rem;
}

.gallery-card-info .card-date {
  font-size: 0.8rem;
  color: var(--tan);
  font-style: italic;
}

.gallery-card-info .card-stats {
  font-size: 0.8rem;
  color: var(--sage);
  margin-top: 0.5rem;
}

.card-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.card-btn {
  flex: 1;
  padding: 0.4rem;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.05);
  color: var(--cream);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.2s;
}

.card-btn:hover { background: rgba(255,255,255,0.15); }
.card-btn.delete { border-color: rgba(212,100,100,0.4); }
.card-btn.delete:hover { background: rgba(212,100,100,0.2); }

#gallery-empty {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--tan);
  font-style: italic;
  font-size: 1.2rem;
}

/* ============================================
   MULTIPLAYER SCREEN
   ============================================ */
#multiplayer-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: linear-gradient(160deg, #2C1810 0%, #4A3728 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.mp-panel {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 24px;
  padding: 2.5rem;
  max-width: 480px;
  width: 90%;
  backdrop-filter: blur(16px);
  position: relative;
}

.mp-panel h2 {
  font-family: var(--font-display);
  font-size: 2rem;
  color: var(--gold);
  margin-bottom: 0.5rem;
}

.mp-panel > p {
  color: var(--tan);
  margin-bottom: 1.5rem;
  font-style: italic;
}

.mp-options {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.mp-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.mp-section label {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--cream);
}

.mp-divider {
  text-align: center;
  color: var(--tan);
  font-style: italic;
}

#join-code-input {
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.2);
  color: var(--cream);
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-size: 1.2rem;
  letter-spacing: 0.2em;
  text-align: center;
  font-family: var(--font-display);
  text-transform: uppercase;
  outline: none;
}

#join-code-input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(201, 168, 76, 0.2);
}

.room-code {
  font-family: var(--font-display);
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.3em;
  text-align: center;
  background: rgba(0,0,0,0.3);
  padding: 0.75rem;
  border-radius: 12px;
  border: 1px solid rgba(201, 168, 76, 0.3);
}

#btn-copy-code {
  background: rgba(255,255,255,0.08);
  color: var(--cream);
  border: 1px solid rgba(255,255,255,0.2);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font-body);
  align-self: center;
}

.mp-status {
  margin-top: 1rem;
  padding: 0.75rem;
  border-radius: 10px;
  text-align: center;
  font-style: italic;
}

.mp-status.success { background: rgba(143, 175, 143, 0.2); color: var(--sage); }
.mp-status.error { background: rgba(212, 100, 100, 0.2); color: #D48888; }
.mp-status.waiting { background: rgba(201, 168, 76, 0.1); color: var(--gold); }

/* ============================================
   GAME HUD
   ============================================ */
#game-hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

#game-hud > * {
  pointer-events: auto;
}

/* Top bar */
.hud-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: linear-gradient(to bottom, rgba(30,15,5,0.85) 0%, transparent 100%);
  gap: 1rem;
}

.hud-left, .hud-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
}

.hud-right {
  justify-content: flex-end;
}

.hud-center {
  flex: 2;
  display: flex;
  justify-content: center;
}

.hud-btn {
  background: rgba(255,255,255,0.1);
  color: var(--cream);
  border: 1px solid rgba(255,255,255,0.15);
  padding: 0.4rem 0.9rem;
  border-radius: 20px;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.85rem;
  transition: all 0.2s;
  white-space: nowrap;
  backdrop-filter: blur(8px);
}

.hud-btn:hover {
  background: rgba(255,255,255,0.2);
  border-color: rgba(255,255,255,0.3);
}

.save-btn {
  border-color: rgba(201, 168, 76, 0.4);
  color: var(--gold);
}

.save-btn:hover {
  background: rgba(201, 168, 76, 0.15);
}

.project-name-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--tan);
}

.project-name-input {
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--cream);
  padding: 0.25rem 0.6rem;
  border-radius: 8px;
  font-family: var(--font-display);
  font-size: 0.9rem;
  outline: none;
  width: 150px;
  transition: all 0.2s;
}

.project-name-input:focus {
  border-color: var(--gold);
  background: rgba(0,0,0,0.5);
}

/* Granny speech bubble */
.granny-speech {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(250, 243, 224, 0.12);
  border: 1px solid rgba(250, 243, 224, 0.2);
  border-radius: 20px;
  padding: 0.4rem 1rem;
  backdrop-filter: blur(8px);
  max-width: 400px;
}

.granny-icon {
  font-size: 1.4rem;
  flex-shrink: 0;
}

#speech-text {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 0.85rem;
  color: var(--cream);
  opacity: 0.9;
}

.mp-pill {
  background: rgba(143, 175, 143, 0.2);
  border: 1px solid rgba(143, 175, 143, 0.4);
  color: var(--sage);
  padding: 0.3rem 0.75rem;
  border-radius: 20px;
  font-size: 0.8rem;
}

/* ============================================
   YARN PALETTE
   ============================================ */
.yarn-palette {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(30, 15, 5, 0.85);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  padding: 1rem;
  backdrop-filter: blur(16px);
  min-width: 140px;
  box-shadow: 4px 4px 24px rgba(0,0,0,0.5);
}

.palette-label {
  font-family: var(--font-display);
  font-size: 0.85rem;
  color: var(--gold);
  margin-bottom: 0.75rem;
  text-align: center;
}

.yarn-colors {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.yarn-swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s;
  position: relative;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.yarn-swatch:hover {
  transform: scale(1.15);
  box-shadow: 0 4px 12px rgba(0,0,0,0.6);
}

.yarn-swatch.active {
  border-color: white;
  transform: scale(1.2);
  box-shadow: 0 0 0 3px rgba(255,255,255,0.3), 0 4px 12px rgba(0,0,0,0.6);
}

/* Yarn texture on swatch */
.yarn-swatch::after {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, rgba(255,255,255,0.3) 0%, transparent 60%);
}

.yarn-thickness {
  margin-bottom: 0.75rem;
}

.yarn-thickness label,
.stitch-type label {
  display: block;
  font-size: 0.75rem;
  color: var(--tan);
  margin-bottom: 0.3rem;
}

.yarn-thickness input[type=range] {
  width: 100%;
  accent-color: var(--gold);
  cursor: pointer;
}

#thickness-label {
  font-size: 0.7rem;
  color: var(--gold);
  display: block;
  text-align: center;
  margin-top: 0.2rem;
}

.stitch-type select {
  width: 100%;
  background: rgba(0,0,0,0.4);
  color: var(--cream);
  border: 1px solid rgba(255,255,255,0.15);
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 0.8rem;
  cursor: pointer;
  outline: none;
}

.stitch-type select:focus {
  border-color: var(--gold);
}

/* ============================================
   UNDO/REDO
   ============================================ */
.undo-redo {
  position: absolute;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 1rem;
  align-items: center;
}

.undo-redo .hud-btn {
  font-size: 0.85rem;
  padding: 0.45rem 1rem;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
  min-width: 90px;
  justify-content: center;
}

/* ============================================
   INSTRUCTIONS
   ============================================ */
.instructions {
  position: absolute;
  bottom: 1.5rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  align-items: flex-end;
}

.inst-item {
  background: rgba(0,0,0,0.4);
  color: rgba(255,255,255,0.5);
  font-size: 0.72rem;
  padding: 0.25rem 0.6rem;
  border-radius: 10px;
  font-style: italic;
  backdrop-filter: blur(4px);
}

/* ============================================
   MENU OVERLAY
   ============================================ */
#menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.menu-panel {
  background: linear-gradient(160deg, #3D2B1F 0%, #2C1810 100%);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 20px;
  padding: 2rem;
  min-width: 260px;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  box-shadow: 0 24px 80px rgba(0,0,0,0.8);
}

.menu-panel h3 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  color: var(--gold);
  text-align: center;
  margin-bottom: 0.5rem;
}

.menu-panel button {
  background: rgba(255,255,255,0.06);
  color: var(--cream);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 0.75rem 1.2rem;
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.95rem;
  text-align: left;
  transition: all 0.2s;
}

.menu-panel button:hover {
  background: rgba(255,255,255,0.12);
  border-color: rgba(201, 168, 76, 0.3);
}

/* ============================================
   VOICE CHAT
   ============================================ */
#voice-chat-panel {
  position: absolute;
  bottom: 1.5rem;
  left: 9rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: rgba(30,15,5,0.8);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 0.5rem 1rem;
  border-radius: 20px;
  backdrop-filter: blur(8px);
}

#partner-status {
  font-size: 0.8rem;
  color: var(--tan);
}

#partner-name {
  color: var(--sage);
}

/* ============================================
   TOAST
   ============================================ */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: rgba(143, 175, 143, 0.9);
  color: #1a3a1a;
  padding: 0.75rem 1.5rem;
  border-radius: 30px;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
  z-index: 200;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* ============================================
   UTILITY
   ============================================ */
.hidden {
  display: none !important;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); }
::-webkit-scrollbar-thumb { background: rgba(201, 168, 76, 0.3); border-radius: 3px; }

/* ============================================
   RESPONSIVE — handled in mobile section below
   ============================================ */

/* ============================================
   CAST-ON TUTORIAL OVERLAY
   ============================================ */
#cast-on-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 5, 2, 0.72);
  backdrop-filter: blur(6px);
  pointer-events: none; /* let clicks pass to canvas! */
}

/* The card itself IS pointer-events */
.co-panel {
  background: linear-gradient(155deg, #3D2B1F 0%, #2C1810 100%);
  border: 1px solid rgba(201, 168, 76, 0.3);
  border-radius: 22px;
  padding: 2rem 2.2rem 1.6rem;
  max-width: 440px;
  width: 90%;
  box-shadow: 0 24px 80px rgba(0,0,0,0.75);
  pointer-events: auto;
  text-align: center;
  animation: slideUp 0.5s cubic-bezier(0.34,1.56,0.64,1);
}

@keyframes slideUp {
  from { opacity:0; transform:translateY(40px); }
  to   { opacity:1; transform:translateY(0); }
}

.co-icon { font-size: 2.6rem; margin-bottom: 0.4rem; }

.co-panel h2 {
  font-family: var(--font-display);
  font-size: 1.9rem;
  color: var(--gold);
  margin-bottom: 0.3rem;
}

.co-sub {
  color: var(--tan);
  font-style: italic;
  margin-bottom: 1.2rem;
  font-size: 0.95rem;
}

.co-steps {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1.4rem;
  text-align: left;
}

.co-step {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  font-size: 0.88rem;
  color: var(--cream);
  line-height: 1.4;
}

.co-num {
  background: var(--gold);
  color: var(--dark-brown);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.8rem;
  border-radius: 50%;
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  margin-top: 0.1rem;
}

.co-action {
  background: rgba(255,255,255,0.05);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  margin-bottom: 1rem;
}

.co-action p {
  font-size: 0.9rem;
  color: var(--cream);
  margin-bottom: 0.7rem;
}

.co-progress-wrap {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.co-progress-bar {
  flex: 1;
  height: 8px;
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
  overflow: hidden;
}

#co-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold), #FFE066);
  border-radius: 4px;
  width: 0%;
  transition: width 0.3s ease;
}

#co-count {
  font-size: 0.8rem;
  color: var(--gold);
  white-space: nowrap;
  font-family: var(--font-display);
}

/* ============================================
   STEP INDICATOR (top-center during knitting)
   ============================================ */
.step-indicator {
  position: absolute;
  top: 4.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 10, 4, 0.82);
  border: 1px solid rgba(201, 168, 76, 0.35);
  border-radius: 30px;
  padding: 0.45rem 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  pointer-events: none;
  backdrop-filter: blur(8px);
  transition: opacity 0.4s;
}

.step-phase {
  font-family: var(--font-display);
  font-size: 0.88rem;
  color: var(--gold);
  font-style: italic;
  white-space: nowrap;
}

.step-progress {
  font-size: 0.78rem;
  color: var(--tan);
}

/* ============================================
   CAST-ON OVERLAY — backdrop passes clicks
   to canvas so manual cast-on works.
   Only the .co-panel card captures events.
   ============================================ */

/* ── Width picker ─────────────────────────── */
.co-width-pick {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
}

.co-width-pick label {
  display: block;
  font-size: 0.88rem;
  color: var(--cream);
  margin-bottom: 0.5rem;
}

.co-width-note {
  font-size: 0.75rem;
  color: var(--sage);
  font-style: italic;
}

.co-width-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.co-width-tag {
  font-size: 0.72rem;
  color: var(--tan);
  white-space: nowrap;
}

.co-width-row input[type=range] {
  flex: 1;
  accent-color: var(--gold);
  cursor: pointer;
}

.co-width-display {
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--gold);
  margin-top: 0.4rem;
  font-weight: 700;
}

/* ── Manual place-stitch button ──────────── */
.co-place-btn {
  margin-top: 0.75rem;
  width: 100%;
  font-size: 0.95rem;
  padding: 0.55rem 1rem;
}

/* ── Freedom note in palette ─────────────── */
.freedom-note {
  font-size: 0.72rem;
  color: var(--sage);
  text-align: center;
  margin-top: 0.5rem;
  font-style: italic;
  opacity: 0.85;
}

/* ============================================
   SHAPING TOOLBAR
   ============================================ */
.shaping-bar {
  position: absolute;
  bottom: 4.5rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.6rem;
  align-items: center;
  background: rgba(10, 5, 2, 0.80);
  border: 1px solid rgba(201, 168, 76, 0.25);
  border-radius: 28px;
  padding: 0.45rem 0.9rem;
  backdrop-filter: blur(8px);
}

.shaping-btn {
  font-family: var(--font-body, 'Lora', serif);
  font-size: 0.82rem;
  padding: 0.38rem 0.85rem;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,0.12);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.2s;
  white-space: nowrap;
  color: var(--cream, #F5E6C8);
  background: rgba(60, 35, 20, 0.85);
}
.shaping-btn:hover:not(:disabled) { background: rgba(90, 55, 30, 0.9); transform: translateY(-1px); }
.shaping-btn:active:not(:disabled) { transform: translateY(0); }
.shaping-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.increase-btn { border-color: rgba(100, 220, 100, 0.4); color: #a0e8a0; }
.increase-btn:hover:not(:disabled) { background: rgba(30, 80, 30, 0.9); }

.decrease-btn { border-color: rgba(220, 120, 80, 0.4); color: #f0b090; }
.decrease-btn:hover:not(:disabled) { background: rgba(80, 35, 20, 0.9); }

.end-row-btn  { border-color: rgba(180, 160, 80, 0.5); color: #e8d080; }
.end-row-btn:hover:not(:disabled) { background: rgba(70, 60, 20, 0.9); }

.bind-btn     { border-color: rgba(180, 80, 80, 0.45); color: #e8a0a0; }
.bind-btn:hover:not(:disabled) { background: rgba(80, 25, 25, 0.9); }

/* ============================================
   BIND-OFF COMPLETION PANEL
   ============================================ */
.bind-off-panel {
  position: absolute;
  bottom: 4.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 10, 4, 0.92);
  border: 1px solid rgba(201, 168, 76, 0.5);
  border-radius: 24px;
  padding: 0.7rem 1.4rem;
  backdrop-filter: blur(10px);
  animation: slideUp 0.4s cubic-bezier(0.34,1.56,0.64,1);
}

.bo-content {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  white-space: nowrap;
}

.bo-icon { font-size: 1.4rem; }

.bo-text {
  font-family: var(--font-display, 'Playfair Display', serif);
  color: var(--gold, #C9A84C);
  font-size: 1rem;
}

.bo-new-btn {
  font-size: 0.85rem;
  padding: 0.4rem 1rem;
  white-space: nowrap;
}

/* Keyboard shortcut hint in step indicator */
.step-shortcuts {
  font-size: 0.7rem;
  color: rgba(201,168,76,0.55);
  margin-left: 0.5rem;
}

/* ── Palette close button (mobile only) ─── */
.palette-close-btn {
  display: none;
}

/* ============================================
   MOBILE LAYOUT — ≤ 600px
   Philosophy: keep the canvas visible at all times.
   HUD elements shrink, collapse, or move to the
   edges. No element should block more than ~15%
   of screen height or ~40% of screen width.
   ============================================ */

/* ── Palette toggle button (mobile only, hidden on desktop) ─── */
#palette-toggle {
  display: none; /* only shown via @media rule below */
}

@media (max-width: 600px) {

  /* ── Touch canvas ─────────────────────── */
  #game-canvas {
    touch-action: none; /* prevent browser scroll interfering with knitting */
  }

  /* ── HUD top bar ──────────────────────── */
  .hud-top {
    padding: 0.4rem 0.5rem;
    gap: 0.3rem;
    flex-wrap: nowrap; /* single row, items shrink */
    background: linear-gradient(to bottom, rgba(20,8,2,0.92) 0%, transparent 100%);
  }

  /* Hide the project name label text, keep input but shrink */
  .project-name-wrap .project-name-label {
    display: none;
  }
  .project-name-input {
    width: 90px;
    font-size: 0.75rem;
    padding: 0.2rem 0.4rem;
  }

  /* Shrink HUD buttons */
  .hud-btn {
    font-size: 0.72rem;
    padding: 0.3rem 0.55rem;
  }

  /* Granny speech — compact, don't let it push other items */
  .granny-speech {
    max-width: 160px;
    padding: 0.3rem 0.55rem;
    gap: 0.25rem;
  }
  .granny-icon { font-size: 1rem; }
  #speech-text {
    font-size: 0.68rem;
    /* Clamp to 2 lines */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .mp-pill {
    font-size: 0.65rem;
    padding: 0.2rem 0.45rem;
  }

  /* ── Step indicator ───────────────────── */
  .step-indicator {
    top: 3.2rem;
    padding: 0.3rem 0.8rem;
    max-width: 88vw;
    white-space: normal;
    text-align: center;
    flex-direction: column;
    gap: 0.15rem;
  }
  .step-phase {
    font-size: 0.72rem;
    white-space: normal;
  }
  .step-progress {
    font-size: 0.65rem;
  }

  /* ── Yarn palette — slide-in drawer ───── */
  #palette-toggle {
    display: flex;
    position: fixed;
    left: 0.6rem;
    top: 50%;
    transform: translateY(-50%);
    z-index: 20;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid rgba(201,168,76,0.5);
    background: rgba(20,10,4,0.88);
    cursor: pointer;
    font-size: 1.3rem;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    box-shadow: 2px 2px 12px rgba(0,0,0,0.5);
    transition: border-color 0.2s, opacity 0.2s;
  }
  #palette-toggle:hover { border-color: var(--gold); }

  .yarn-palette {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 148px;
    border-radius: 0 16px 16px 0;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
    overflow-y: auto;
    z-index: 25;
    padding: 0.75rem;
    /* Keep vertical centring on desktop, override for mobile */
    top: 0 !important;
    bottom: 0 !important;
  }

  .yarn-palette.mobile-open {
    transform: translateX(0);
  }

  /* Palette toggle hides when palette is open */
  .yarn-palette.mobile-open ~ #palette-toggle,
  #palette-toggle.palette-open {
    opacity: 0;
    pointer-events: none;
  }

  /* Close button inside palette on mobile */
  .palette-close-btn {
    display: flex !important;
  }

  .yarn-colors {
    gap: 0.3rem;
  }
  .yarn-swatch {
    width: 26px;
    height: 26px;
  }

  /* ── Shaping bar — 2×2 grid on mobile ── */
  .shaping-bar {
    bottom: 3.5rem;
    padding: 0.3rem 0.5rem;
    gap: 0.3rem;
    flex-wrap: wrap;
    max-width: 92vw;
    justify-content: center;
  }

  .shaping-btn {
    font-size: 0.70rem;
    padding: 0.32rem 0.55rem;
    /* Abbreviate button text via attr override — done in HTML */
  }

  /* ── Undo / Redo ──────────────────────── */
  .undo-redo {
    bottom: 0.6rem;
    gap: 0.5rem;
  }
  .undo-redo .hud-btn {
    font-size: 0.72rem;
    padding: 0.3rem 0.65rem;
    min-width: 72px;
  }

  /* ── Voice chat ───────────────────────── */
  #voice-chat-panel {
    bottom: 0.6rem;
    left: 0.5rem;
    padding: 0.35rem 0.65rem;
    gap: 0.4rem;
    font-size: 0.72rem;
  }

  /* ── Cast-on overlay ──────────────────── */
  .co-panel {
    padding: 1.2rem 1.1rem 1rem;
    max-width: 95vw;
    border-radius: 16px;
  }

  .co-icon { font-size: 1.8rem; margin-bottom: 0.2rem; }

  .co-panel h2 {
    font-size: 1.35rem;
    margin-bottom: 0.2rem;
  }

  .co-sub {
    font-size: 0.78rem;
    margin-bottom: 0.75rem;
  }

  /* Hide the detailed step list — too much text on mobile */
  .co-steps {
    display: none;
  }

  .co-action {
    padding: 0.6rem 0.75rem;
    margin-bottom: 0.6rem;
  }
  .co-action p { font-size: 0.78rem; margin-bottom: 0.5rem; }

  .co-width-pick {
    padding: 0.6rem 0.75rem;
    margin-bottom: 0.6rem;
  }
  .co-width-pick label { font-size: 0.78rem; }

  .co-place-btn {
    font-size: 0.82rem;
    padding: 0.45rem 0.8rem;
    margin-top: 0.5rem;
  }

  .btn-secondary {
    font-size: 0.8rem;
    padding: 0.55rem 1rem;
  }

  /* ── Bind-off panel ───────────────────── */
  .bind-off-panel {
    bottom: 3.5rem;
    padding: 0.5rem 1rem;
    max-width: 92vw;
  }
  .bo-content { gap: 0.5rem; flex-wrap: wrap; justify-content: center; }
  .bo-icon { font-size: 1.1rem; }
  .bo-text { font-size: 0.82rem; }
  .bo-new-btn { font-size: 0.75rem; padding: 0.35rem 0.75rem; }

  /* ── Menu overlay ─────────────────────── */
  .menu-panel {
    padding: 1.4rem;
    min-width: 0;
    width: 88vw;
    max-width: 320px;
    gap: 0.4rem;
  }
  .menu-panel h3 { font-size: 1.2rem; }
  .menu-panel button {
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
  }

  /* ── Splash ───────────────────────────── */
  .splash-content h1 {
    font-size: clamp(1.8rem, 8vw, 2.8rem);
  }
  .tagline {
    font-size: 1rem;
    margin-bottom: 1.5rem;
  }
  .btn-main {
    min-width: 180px;
    font-size: 1rem;
    padding: 0.85rem 1.8rem;
  }
  .btn-secondary {
    min-width: 180px;
  }

  /* ── Gallery ──────────────────────────── */
  #gallery-screen {
    padding: 1rem;
  }
  .gallery-header h2 { font-size: 1.6rem; }
  #gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
  }
  .gallery-card-preview { height: 120px; }
  .gallery-card-info { padding: 0.6rem; }
  .gallery-card-info h3 { font-size: 0.85rem; }
}

/* ── Landscape mobile (short screens) ─────── */
@media (max-width: 900px) and (max-height: 500px) {
  .hud-top { padding: 0.25rem 0.5rem; }
  .granny-speech { display: none; } /* reclaim vertical space */
  .step-indicator { top: 2.4rem; }
  .co-panel {
    max-height: 85vh;
    overflow-y: auto;
    padding: 0.8rem 1rem;
  }
  .co-steps { display: none; }
  .shaping-bar { bottom: 2.8rem; }
  .undo-redo { bottom: 0.4rem; }
}

/* ── Shaping button short labels on mobile ─ */
@media (max-width: 600px) {
  .shaping-btn {
    font-size: 0px; /* hide text */
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .shaping-btn::before {
    content: attr(data-short);
    font-size: 1.1rem;
  }
  .shaping-bar {
    bottom: 3.2rem;
    gap: 0.5rem;
    padding: 0.4rem 0.7rem;
    border-radius: 30px;
  }
}
