:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --muted: #666666;
  --accent: #2c2c2c;
  --accent-2: #1a1a1a;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; 
  background: #f5f5f5; 
  color: #2c2c2c; 
  display: flex; 
  align-items: center; 
  justify-content: center;
}

.app {
  width: min(420px, 94vw);
  background: var(--bg);
  border-radius: 4px; 
  padding: 24px; 
  min-height: 560px; 
  display: flex; 
  flex-direction: column; 
  gap: 12px; 
  position: relative; 
  overflow: hidden;
  /* Prevent all default touch behaviors during drag operations */
  touch-action: none;
}

header {
  display: flex; 
  justify-content: space-between; 
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.nav-links {
  margin-left: auto;
}

.generator-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  padding: 6px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.generator-link:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: #f9f9f9;
}

.brand {
  font-family: Georgia, "Times New Roman", Times, serif;
  font-weight: 700; 
  font-size: 24px; 
  letter-spacing: 0.5px;
}

.brand .grape {
  font-weight: 900;
}

/* Start overlay */
.overlay {
  position: absolute; 
  inset: 0; 
  background: rgba(255, 255, 255, 0.95); 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  z-index: 40;
}

.startCard {
  background: var(--bg); 
  padding: 32px; 
  border-radius: 3px; 
  text-align: center; 
  width: 86%; 
  border: 1px solid #e0e0e0;
}

.startCard h1 {
  margin: 0 0 8px 0; 
  font-size: 32px;
  font-family: Georgia, "Times New Roman", Times, serif;
  color: var(--accent);
}

.startCard p {
  margin: 0 0 18px 0; 
  color: var(--muted);
}

#puzzleSelector {
  margin: 0 0 18px 0;
  text-align: left;
}

#puzzleSelector label {
  display: block;
  margin-bottom: 5px;
  font-weight: 600;
  color: var(--accent);
}

#puzzleSelector select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  margin-bottom: 10px;
}

#favoritesSelector.hidden {
  display: none;
}

.btn {
  background: var(--accent); 
  color: #ffffff; 
  border: 0; 
  padding: 12px 18px; 
  border-radius: 2px; 
  font-weight: 600; 
  cursor: pointer;
  font-size: 14px;
}

/* Timer - small corner */
.timer {
  position: absolute; 
  top: 12px; 
  right: 16px; 
  font-size: 12px; 
  color: var(--muted);
}

/* Main board */
.board {
  display: flex; 
  flex-direction: column; 
  gap: 8px; 
  align-items: center; 
  padding-top: 4px;
}

.list {
  width: 100%; 
  display: flex; 
  flex-direction: column; 
  gap: 8px;
  /* Prevent any touch gestures that could interfere with dragging */
  touch-action: none;
}

.word {
  background: #f0f0f0; 
  border-radius: 3px; 
  padding: 12px 14px; 
  font-size: 18px; 
  cursor: grab; 
  user-select: none; 
  transition: transform .18s ease;
  touch-action: none; /* Prevent browser scroll during drag on mobile */
}

.word.admiring {
  cursor: default;
}

.word .text {
  display: block;
}

.word.dragging {
  transform: translateY(-4px) scale(1.01); 
  cursor: grabbing; 
  z-index: 1000;
  background: #e8e8e8;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
  /* Remove transition for immediate feedback on mobile */
  transition: none;
  /* Improve mobile touch responsiveness */
  pointer-events: none;
  /* Prevent mobile scrolling interference */
  touch-action: none;
  /* Better mobile visibility */
  opacity: 0.95;
}

.placeholder {
  height: 54px; 
  border-radius: 3px; 
  border: 1px dashed #cccccc;
}

/* Attempts indicator */
.footer {
  display: flex; 
  align-items: center; 
  justify-content: space-between; 
  gap: 12px;
}

.attempts {
  display: flex; 
  gap: 8px; 
  align-items: center;
}

.dot {
  width: 12px; 
  height: 12px; 
  border-radius: 999px; 
  background: var(--accent);
}

.dot.gone {
  opacity: .18; 
  transform: scale(.7);
}

/* Controls */
.controls {
  display: flex; 
  gap: 10px;
}

button.secondary {
  background: transparent; 
  color: var(--muted); 
  border: 1px solid #cccccc; 
  padding: 10px 14px; 
  border-radius: 2px; 
  cursor: pointer;
  font-size: 14px;
}

button.primary {
  background: var(--accent-2); 
  color: #ffffff; 
  padding: 10px 14px; 
  border-radius: 2px; 
  border: 0; 
  font-weight: 600; 
  cursor: pointer;
  font-size: 14px;
}

/* End screen */
.end {
  position: absolute; 
  inset: 0; 
  background: rgba(255, 255, 255, 0.95); 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  z-index: 50;
}

.endCard {
  background: var(--bg); 
  padding: 24px; 
  border-radius: 3px; 
  width: 86%; 
  text-align: center;
  border: 1px solid #e0e0e0;
}

.endCard h2 {
  margin: 0 0 8px 0;
  font-family: Georgia, "Times New Roman", Times, serif;
  color: var(--accent);
}

.muted {
  color: var(--muted);
}

/* Helper classes */
.hidden {
  display: none;
}

.meta {
  font-size: 13px;
  color: var(--muted);
}

@media (max-width: 380px) { 
  .app {
    min-height: 640px;
  } 
  
  .word {
    font-size: 16px;
    padding: 12px;
  } 
}

/* Word list connector - subtle bracket connecting top and bottom */
.list-container {
  position: relative;
  width: 100%;
}

.word-connector {
  position: absolute;
  right: -16px;
  top: 0;
  bottom: 0;
  width: 12px;
  pointer-events: none;
  z-index: 1;
}

.word-connector::before,
.word-connector::after {
  content: '';
  position: absolute;
  left: 0;
  width: 8px;
  height: 1px;
  background: #ccc;
}

.word-connector::before {
  top: 25px; /* Align with center of first word */
}

.word-connector::after {
  bottom: 25px; /* Align with center of last word */
}

.word-connector .connector-line {
  position: absolute;
  left: 8px;
  top: 25px;
  bottom: 25px;
  width: 1px;
  background: #ccc;
}

/* Mobile-specific improvements */
@media (pointer: coarse) {
  /* Fix scrollability on mobile */
  body {
    align-items: flex-start; /* Allow content to start at top instead of center */
    padding: 8px 0; /* Add some padding for mobile */
  }
  
  .app {
    overflow: visible; /* Allow content to overflow for scrolling */
    min-height: auto; /* Remove fixed min-height */
    margin: 0 auto; /* Center horizontally only */
  }
  
  .word {
    /* Larger touch targets on mobile */
    min-height: 48px;
    /* Better spacing for finger touch */
    margin: 2px 0;
  }
  
  .word.dragging {
    /* More prominent shadow on mobile for better visibility */
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
    /* Slightly larger scale for better visibility during drag */
    transform: translateY(-6px) scale(1.02);
  }
  
  .word-connector {
    right: -12px; /* Closer on mobile for better fit */
    width: 10px;
  }
  
  .word-connector::before,
  .word-connector::after {
    width: 6px;
    left:2px;
  }
}