/* ClackDash Typing App Styles: Testbed, Word Display, Results, Heatmap, Chart */

/* Strict hidden contract: prevents author styles (display: flex) from overriding UA hidden */
[hidden],
.results-panel[hidden],
#results[hidden],
.history-panel[hidden],
#history[hidden],
.share-dialog:not([open]),
.share-dialog[hidden] {
  display: none !important;
}

.app-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  min-height: calc(100vh - 180px);
  position: relative;
  outline: none;
}

/* 1. Pill Config Bar */
.config-bar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  align-self: center;
  gap: 0.5rem;
  background-color: var(--sub-alt);
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-pill);
  margin-bottom: 2.5rem;
  font-size: 0.85rem;
  transition: opacity var(--transition-normal);
}
.config-group { display: inline-flex; align-items: center; gap: 0.25rem; }
.config-divider { width: 2px; height: 14px; background-color: var(--sub); opacity: 0.3; margin: 0 0.35rem; }
.btn-config {
  padding: 0.25rem 0.55rem;
  border-radius: var(--radius-sm);
  color: var(--sub);
  font-weight: 500;
  transition: color var(--transition-fast), background-color var(--transition-fast);
}
.btn-config:hover { color: var(--text); }
.btn-config.active,
.btn-config[aria-pressed="true"] { color: var(--main); font-weight: 700; }

.config-select {
  padding: 0.2rem 0.4rem;
  color: var(--sub);
  background-color: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--transition-fast);
}
.config-select:hover,
.config-select:focus { color: var(--text); }
.config-select option { background-color: var(--bg); color: var(--text); }

/* 2. Live Stats Bar */
.live-stats {
  display: flex;
  align-items: baseline;
  gap: 2rem;
  margin-bottom: 1.5rem;
  font-family: var(--font-mono);
  user-select: none;
  min-height: 2.5rem;
}
.live-stat-item { display: flex; flex-direction: column; }
.live-stat-val { font-size: 2.2rem; font-weight: 700; color: var(--main); line-height: 1; }
.live-stat-lbl { font-size: 0.75rem; text-transform: uppercase; color: var(--sub); letter-spacing: 0.05em; margin-top: 0.2rem; }

/* 3. Words Test Area */
.words-wrapper { position: relative; width: 100%; margin: 1.5rem 0 2rem; user-select: none; }
.words {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 0.6em 0.8em;
  font-family: var(--font-mono);
  font-size: 1.85rem;
  line-height: 1.45;
  height: 4.35em; /* Exactly 3 visible lines */
  overflow: hidden;
  position: relative;
  letter-spacing: 0.02em;
}
.word { display: inline-flex; position: relative; white-space: nowrap; }
.letter { position: relative; color: var(--sub); transition: color 0.08s ease; }

/* Word & Letter States (strictly §5) */
.letter.correct { color: var(--text); }
.letter.incorrect {
  color: var(--error);
  text-decoration: underline wavy var(--error);
  background-color: rgba(202, 71, 84, 0.15);
  border-radius: 2px;
}
.letter.extra { color: var(--error-extra); text-decoration: underline; opacity: 0.9; }
.letter.missed { opacity: 0.45; text-decoration: line-through; }

/* Caret: Smooth blinking vertical bar */
.caret {
  position: absolute;
  top: 10%;
  left: 0;
  width: 2.5px;
  height: 80%;
  background-color: var(--caret);
  border-radius: 1px;
  pointer-events: none;
  animation: caretBlink 1s infinite cubic-bezier(0.4, 0, 0.2, 1);
  transition: left 0.09s ease-out;
}
@keyframes caretBlink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* 4. Restart Action */
.test-actions { display: flex; justify-content: center; align-items: center; margin: 1.5rem 0; }
.btn-restart {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  color: var(--sub);
  border-radius: var(--radius-pill);
  transition: color var(--transition-fast), background-color var(--transition-fast);
}
.btn-restart:hover { color: var(--text); background-color: var(--sub-alt); }
.restart-tip { font-size: 0.85rem; font-weight: 500; }

/* 5. Results Section (#results) */
.results-panel {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  animation: fadeIn 0.3s ease-out;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.results-hero { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1.5rem; }
.stat-card {
  background-color: var(--sub-alt);
  padding: 1.25rem 1.5rem;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
}
.stat-card.stat-featured { border-left: 4px solid var(--main); }
.stat-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--sub);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}
.stat-val-hero { font-family: var(--font-mono); font-size: 3rem; font-weight: 800; color: var(--main); line-height: 1; }
.stat-val-sub { font-family: var(--font-mono); font-size: 1.8rem; font-weight: 700; color: var(--text); line-height: 1; }

/* 6. Chart Container & SVG */
.chart-container {
  width: 100%;
  background-color: var(--sub-alt);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-sizing: border-box;
}
.wpm-chart { width: 100%; height: 220px; overflow: visible; }
.chart-grid { stroke: var(--bg); stroke-width: 1; opacity: 0.5; }
.chart-line-wpm { fill: none; stroke: var(--main); stroke-width: 3; stroke-linecap: round; }
.chart-line-raw { fill: none; stroke: var(--sub); stroke-width: 2; stroke-dasharray: 4 4; }
.chart-dot-error { fill: var(--error); r: 4; }

/* 7. Key Heatmap */
.key-heatmap {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  background-color: var(--sub-alt);
  padding: 1.25rem;
  border-radius: var(--radius-md);
  align-items: center;
}
.heatmap-row { display: flex; gap: 0.35rem; }
.heatmap-key {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  background-color: var(--bg);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  border: 1px solid transparent;
}
.heatmap-key.key-err-low { border-color: rgba(202, 71, 84, 0.4); }
.heatmap-key.key-err-mid { background-color: rgba(202, 71, 84, 0.25); border-color: var(--error); }
.heatmap-key.key-err-high { background-color: var(--error); color: var(--bg); }

/* 8. Results Action Buttons */
.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: center;
  margin-top: 1rem;
}
.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  background-color: var(--sub-alt);
  color: var(--text);
  border-radius: var(--radius-pill);
  font-weight: 600;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}
.btn-action:hover { background-color: var(--main); color: var(--bg); }
[data-t="share"].is-copied { background-color: var(--main) !important; color: var(--bg) !important; }

/* 9. History Panel */
.history-panel {
  background-color: var(--sub-alt);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  margin-top: 1rem;
}
.history-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.history-title { font-size: 1.1rem; margin: 0; }
.history-tools { display: flex; gap: 0.5rem; }
.btn-sm {
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  background-color: var(--bg);
  color: var(--text);
  font-size: 0.8rem;
}
.btn-sm:hover { color: var(--main); }
.btn-sm.btn-danger:hover { color: var(--error); }
.history-table-wrapper { overflow-x: auto; }
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  text-align: left;
}
.history-table th,
.history-table td { padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--bg); }
.history-table th { color: var(--sub); font-size: 0.75rem; text-transform: uppercase; }

/* 10. Fallback Share Dialog */
.share-dialog {
  background-color: var(--bg);
  color: var(--text);
  border: 1px solid var(--sub);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  max-width: 480px;
  width: calc(100% - 2rem);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  margin: auto;
}
.share-dialog::backdrop { background: rgba(0, 0, 0, 0.65); backdrop-filter: blur(2px); }
.share-dialog-title { font-size: 1.25rem; margin-bottom: 1rem; color: var(--text); }
.share-url {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background-color: var(--sub-alt);
  color: var(--text);
  border: 1px solid var(--sub);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  margin-bottom: 1.25rem;
}
.share-close {
  display: inline-block;
  padding: 0.5rem 1.25rem;
  background-color: var(--main);
  color: var(--bg);
  border-radius: var(--radius-pill);
  font-weight: 600;
  cursor: pointer;
}

/* 11. Error Card in Result Page */
.result-error {
  background-color: var(--sub-alt);
  border: 1px solid var(--error);
  border-radius: var(--radius-md);
  padding: 2rem 1.5rem;
  text-align: center;
  margin: 2rem auto;
  max-width: 600px;
}
.result-error-title { color: var(--error); margin-bottom: 0.5rem; }
.result-error-text { color: var(--sub); margin-bottom: 1.5rem; }
.result-error-home {
  display: inline-flex;
  align-items: center;
  padding: 0.5rem 1.25rem;
  background-color: var(--main);
  color: var(--bg);
  border-radius: var(--radius-pill);
  font-weight: 600;
  text-decoration: none;
}

/* Hero Section */
.hero-intro {
  text-align: center;
  padding: 1.25rem 0 1.5rem;
}
.hero-h1 {
  font-size: 2.25rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
  color: var(--text);
  letter-spacing: -0.01em;
}
.hero-lead {
  font-size: 1.1rem;
  color: var(--sub);
  max-width: 680px;
  margin: 0 auto;
  line-height: 1.5;
}

/* 12. Responsive & Touch Adaptations */
@media (max-width: 768px) {
  .hero-h1 { font-size: 1.85rem; }
  .hero-lead { font-size: 1rem; }
  .app-container { padding: 1.25rem 1rem; }
  .words { font-size: 1.5rem; }
  .stat-val-hero { font-size: 2.4rem; }
  .heatmap-key { width: 32px; height: 34px; font-size: 0.75rem; }
}

@media (max-width: 480px) {
  .hero-intro {
    padding: 0.2rem 0 0.35rem;
    margin-bottom: 0.2rem;
  }
  .hero-h1 {
    font-size: 1.25rem;
    line-height: 1.2;
    margin: 0 0 0.2rem;
  }
  .hero-lead {
    font-size: 0.8rem;
    line-height: 1.35;
    margin: 0 auto;
    max-width: 290px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .app-container {
    padding: 0.35rem 0.5rem;
  }
  .config-bar {
    display: flex;
    flex-wrap: nowrap;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    justify-content: flex-start;
    padding: 0.25rem 0.4rem;
    margin-bottom: 0.85rem;
    gap: 0.3rem;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .config-bar::-webkit-scrollbar {
    display: none;
  }
  .config-group {
    flex-shrink: 0;
    gap: 0.15rem;
  }
  .btn-config {
    padding: 0.2rem 0.4rem;
    font-size: 0.78rem;
    white-space: nowrap;
  }
  .config-divider {
    margin: 0 0.15rem;
    flex-shrink: 0;
  }
  .words { font-size: 1.25rem; height: 4.2em; }
  .live-stats { gap: 1.2rem; }
  .live-stat-val { font-size: 1.7rem; }
  .btn-action { width: 100%; justify-content: center; }
}
