/* Focus Poetry CSS Experiment */

/* Canvas for focus trails */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: -1;
  background: transparent;
  opacity: 0.1;
}

/* Base focus styles that remain visible */
.focus-trail {
  position: relative;
  transition: all 0.3s ease;
}

.focus-trail:focus {
  outline: none;
  position: relative;
  z-index: 10;
}

/* Create persistent focus traces */
.focus-trail:focus::before {
  content: attr(data-focus-count);
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  background: linear-gradient(45deg, #007AFF, #5AC8FA);
  border-radius: 50%;
  font-size: 10px;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  z-index: 11;
  animation: focusPop 0.5s ease-out;
}

@keyframes focusPop {
  0% { transform: scale(0) rotate(0deg); opacity: 0; }
  50% { transform: scale(1.2) rotate(180deg); opacity: 1; }
  100% { transform: scale(1) rotate(360deg); opacity: 1; }
}

/* Focus ghost - semi-permanent trace */
.focus-trail.was-focused {
  box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.2);
  border-radius: 4px;
}

.focus-trail.was-focused::after {
  content: '◦';
  position: absolute;
  top: -10px;
  left: -10px;
  color: rgba(0, 122, 255, 0.4);
  font-size: 20px;
  pointer-events: none;
  animation: fadeTrace 2s ease-out forwards;
}

@keyframes fadeTrace {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0.3; transform: scale(0.8); }
}

/* Different shapes for different element types */
h1.focus-trail:focus::before,
h2.focus-trail:focus::before,
h3.focus-trail:focus::before {
  border-radius: 0;
  background: linear-gradient(45deg, #FF3B30, #FF9500);
  transform: rotate(45deg);
}

a.focus-trail:focus::before {
  background: linear-gradient(45deg, #34C759, #30D158);
  border-radius: 20% 80% 20% 80%;
}

button.focus-trail:focus::before {
  background: linear-gradient(45deg, #FF9500, #FFCC00);
  border-radius: 15%;
}

/* Focus constellation - connect focused elements */
.focus-constellation {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
  opacity: 0.6;
}

.constellation-line {
  position: absolute;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(0, 122, 255, 0.5), transparent);
  transform-origin: left center;
  animation: drawLine 1s ease-out forwards;
}

@keyframes drawLine {
  0% { width: 0; }
  100% { width: var(--line-length); }
}

/* Focus heat map */
.focus-heatmap {
  position: relative;
}

.focus-heatmap::before {
  content: '';
  position: absolute;
  top: -5px;
  left: -5px;
  right: -5px;
  bottom: -5px;
  background: radial-gradient(circle, rgba(255, 107, 107, 0.1) 0%, transparent 70%);
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: -1;
}

.focus-heatmap.frequent-focus::before {
  opacity: 1;
  animation: heatPulse 2s ease-in-out infinite;
}

@keyframes heatPulse {
  0%, 100% { transform: scale(1); opacity: 0.1; }
  50% { transform: scale(1.1); opacity: 0.3; }
}

/* Poetry mode - focus creates text */
.poetry-mode .focus-trail:focus::after {
  content: var(--focus-word);
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 12px;
  white-space: nowrap;
  z-index: 20;
  animation: fadeInUp 0.5s ease-out;
}

@keyframes fadeInUp {
  0% { opacity: 0; transform: translateX(-50%) translateY(10px); }
  100% { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Accessibility: Respect motion preferences */
@media (prefers-reduced-motion: reduce) {
  .focus-trail,
  .focus-trail::before,
  .focus-trail::after {
    animation: none !important;
    transition: none !important;
  }
}

/* High contrast mode compatibility */
@media (prefers-contrast: high) {
  .focus-trail:focus::before {
    background: black;
    border: 2px solid white;
  }
  
  .focus-trail.was-focused {
    box-shadow: 0 0 0 3px black;
  }
}

/* Demo styling for this page */
.demo-element {
  display: inline-block;
  padding: 12px 16px;
  margin: 8px;
  background: #f0f0f0;
  border: 1px solid #ddd;
  border-radius: 8px;
  text-decoration: none;
  color: #333;
  cursor: pointer;
}

.demo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin: 24px 0;
}

.demo-poem {
  font-family: 'Courier New', monospace;
  background: #1a1a1a;
  color: #0f0;
  padding: 20px;
  border-radius: 8px;
  margin: 20px 0;
  white-space: pre-line;
  line-height: 1.4;
}

/* Instructions panel */
.instructions {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 20px;
  border-radius: 12px;
  margin: 20px 0;
}

.instructions h3 {
  margin-top: 0;
  color: #fff;
}
