/* Bird Fan — Learn Mode Styles
   Mobile-first, accessible, high-contrast */

/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #faf9f6;
  --text: #1a1a1a;
  --primary: #2d6a4f;
  --primary-hover: #1b4332;
  --secondary: #52796f;
  --accent: #95d5b2;
  --card-bg: #ffffff;
  --border: #d8dad3;
  --focus: #2563eb;
  --error: #b91c1c;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

html {
  font-size: 18px;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Skip Link ────────────────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  background: var(--primary);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  z-index: 100;
  font-weight: 600;
}
.skip-link:focus {
  top: 1rem;
}

/* ── Screen Reader Only ───────────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ── Focus Indicator ──────────────────────────────────────── */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* ── Header ───────────────────────────────────────────────── */
header {
  text-align: center;
  padding: 1.5rem 1rem 0.5rem;
}
header h1 {
  font-size: 1.8rem;
  color: var(--primary);
  letter-spacing: -0.02em;
}
.subtitle {
  color: var(--secondary);
  font-size: 0.95rem;
}

/* ── Main / Screens ───────────────────────────────────────── */
main {
  flex: 1;
  padding: 1rem;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
  position: relative;
}

.screen {
  display: none;
}
.screen.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

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

/* ── Buttons ──────────────────────────────────────────────── */
button {
  cursor: pointer;
  border: none;
  font-family: inherit;
  font-size: 1rem;
  transition: background 0.15s, transform 0.1s;
}
button:active {
  transform: scale(0.97);
}

.primary-btn {
  display: block;
  width: 100%;
  padding: 1rem 1.5rem;
  background: var(--primary);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 600;
  border-radius: var(--radius);
  min-height: 52px;
}
.primary-btn:hover,
.primary-btn:focus-visible {
  background: var(--primary-hover);
}

.secondary-btn {
  display: block;
  width: 100%;
  padding: 0.85rem 1.5rem;
  background: var(--card-bg);
  color: var(--primary);
  font-weight: 600;
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  min-height: 52px;
}
.secondary-btn:hover,
.secondary-btn:focus-visible {
  background: var(--accent);
}

/* ── Mode Selection ───────────────────────────────────────── */
.mode-group {
  display: flex;
  gap: 0.75rem;
  margin: 1.5rem 0;
}
.mode-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 1rem 0.5rem;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  min-height: 100px;
  box-shadow: var(--shadow);
}
.mode-btn.selected {
  border-color: var(--primary);
  background: #e8f5e9;
}
.mode-btn:hover {
  border-color: var(--secondary);
}
.mode-icon {
  font-size: 1.6rem;
}
.mode-label {
  font-weight: 600;
  font-size: 1rem;
}
.mode-desc {
  font-size: 0.75rem;
  color: var(--secondary);
}

/* ── Region Selection ─────────────────────────────────────── */
#screen-region h2 {
  margin-bottom: 0.5rem;
}
#region-instructions {
  color: var(--secondary);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.quick-regions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
}
.region-btn {
  width: 100%;
  padding: 1rem 1.25rem;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  text-align: left;
  font-weight: 600;
  font-size: 1.05rem;
  min-height: 52px;
  box-shadow: var(--shadow);
}
.region-btn:hover,
.region-btn:focus-visible {
  border-color: var(--primary);
  background: #e8f5e9;
}

.search-group {
  position: relative;
}
#region-search {
  width: 100%;
  padding: 0.9rem 1rem;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--text);
  min-height: 52px;
}
#region-search:focus {
  border-color: var(--focus);
}
#region-search::placeholder {
  color: #888;
}

#search-results {
  list-style: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow);
  max-height: 240px;
  overflow-y: auto;
  z-index: 10;
}
#search-results li {
  padding: 0.8rem 1rem;
  cursor: pointer;
  font-size: 0.95rem;
  min-height: 48px;
  display: flex;
  align-items: center;
}
#search-results li:hover,
#search-results li:focus {
  background: #e8f5e9;
}
#search-results li[aria-selected="true"] {
  background: var(--accent);
}

/* ── Learn Screen ─────────────────────────────────────────── */
.learn-header {
  text-align: center;
  margin-bottom: 1rem;
}
.learn-header h2 {
  font-size: 1.2rem;
  color: var(--secondary);
}
#learn-progress {
  font-size: 0.9rem;
  color: var(--secondary);
  margin-top: 0.25rem;
}

.bird-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  text-align: center;
  margin-bottom: 1rem;
}

.bird-image-container {
  margin-bottom: 1rem;
}
.bird-image {
  max-width: 100%;
  max-height: 250px;
  border-radius: 8px;
  object-fit: cover;
}

.bird-info {
  margin-bottom: 1rem;
  min-height: 3rem;
}
.bird-name {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary);
}
.bird-sci-name {
  font-style: italic;
  color: var(--secondary);
  font-size: 0.9rem;
}

/* ── Vocalization Type Buttons ─────────────────────────────── */
.vocalization-types {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
  margin: 0.75rem 0;
}
.voc-type-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 500;
  min-height: 44px;
  white-space: nowrap;
}
.voc-type-btn:hover,
.voc-type-btn:focus-visible {
  border-color: var(--primary);
  background: #e8f5e9;
}
.voc-type-btn.playing {
  border-color: var(--primary);
  background: #d1fae5;
  font-weight: 600;
}
.voc-type-btn .voc-play-icon {
  font-size: 0.85rem;
}
.voc-type-label {
  text-transform: capitalize;
}
.voc-types-loading {
  font-size: 0.85rem;
  color: var(--secondary);
  text-align: center;
  padding: 0.5rem;
  font-style: italic;
}

.audio-controls {
  margin: 1rem 0 0.5rem;
}
.play-btn {
  max-width: 250px;
  margin: 0 auto;
}
.stop-btn {
  display: inline-block;
  margin: 0.5rem auto 0;
  padding: 0.6rem 1.5rem;
  background: var(--error);
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
  border-radius: var(--radius);
  min-height: 48px;
  min-width: 100px;
}
.stop-btn:hover,
.stop-btn:focus-visible {
  background: #991b1b;
}
.stop-btn[hidden] {
  display: none;
}

.credit {
  font-size: 0.7rem;
  color: #999;
  margin-top: 0.5rem;
}

.learn-actions {
  display: flex;
  gap: 0.75rem;
}
.learn-actions .secondary-btn,
.learn-actions .primary-btn {
  flex: 1;
}

.keyboard-hints {
  text-align: center;
  margin-top: 1rem;
  font-size: 0.75rem;
  color: #999;
}
kbd {
  background: #eee;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 0.1em 0.4em;
  font-size: 0.85em;
  font-family: inherit;
}

/* ── Activity Selection ───────────────────────────────────── */
.activity-instructions {
  color: var(--secondary);
  margin-bottom: 1rem;
  font-size: 0.95rem;
  text-align: center;
}
.activity-group {
  display: flex;
  gap: 0.75rem;
  margin: 1rem 0;
}
.activity-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 1.25rem 0.75rem;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  min-height: 110px;
  box-shadow: var(--shadow);
}
.activity-btn:hover,
.activity-btn:focus-visible {
  border-color: var(--primary);
  background: #e8f5e9;
}
.activity-icon {
  font-size: 1.8rem;
}
.activity-label {
  font-weight: 700;
  font-size: 1.15rem;
}
.activity-desc {
  font-size: 0.8rem;
  color: var(--secondary);
}
#screen-activity h2 {
  text-align: center;
  color: var(--primary);
  margin-bottom: 0.25rem;
}

/* ── Quiz Screen ─────────────────────────────────────────── */
.quiz-score {
  font-weight: 600;
  color: var(--primary);
  font-size: 1rem;
  margin-top: 0.25rem;
}

.quiz-prompt {
  font-weight: 600;
  font-size: 1.1rem;
  margin: 1rem 0 0.75rem;
}

.quiz-choices {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.quiz-choice-btn {
  width: 100%;
  padding: 0.85rem 1rem;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  text-align: left;
  font-size: 1rem;
  font-weight: 500;
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.quiz-choice-btn:hover:not(:disabled),
.quiz-choice-btn:focus-visible:not(:disabled) {
  border-color: var(--primary);
  background: #e8f5e9;
}
.quiz-choice-btn:disabled {
  cursor: default;
  opacity: 0.85;
}
.quiz-choice-btn.correct {
  border-color: var(--primary);
  background: #d1fae5;
}
.quiz-choice-btn.wrong {
  border-color: var(--error);
  background: #fee2e2;
}
.choice-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: #eee;
  border: 1px solid #ccc;
  font-size: 0.85rem;
  font-weight: 600;
  flex-shrink: 0;
}

.quiz-feedback {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-weight: 600;
}
.quiz-feedback.correct {
  background: #d1fae5;
  color: #065f46;
}
.quiz-feedback.wrong {
  background: #fee2e2;
  color: #991b1b;
}

/* ── Summary Screen ──────────────────────────────────────── */
#screen-summary h2 {
  text-align: center;
  color: var(--primary);
  margin-bottom: 1rem;
}
.summary-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  box-shadow: var(--shadow);
  text-align: center;
  margin-bottom: 1.5rem;
}
.summary-score {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
}
.summary-percent {
  font-size: 1.2rem;
  color: var(--secondary);
  margin-top: 0.25rem;
}
.summary-message {
  font-size: 1rem;
  margin-top: 0.75rem;
  color: var(--text);
}
.summary-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* ── Explore Screen ──────────────────────────────────────── */
.explore-now-playing {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
  text-align: center;
  margin-bottom: 1rem;
  border: 2px solid var(--primary);
}
.explore-now-playing .bird-name {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}
.explore-now-playing .audio-controls {
  margin: 0.5rem 0 0;
}

.explore-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 50vh;
  overflow-y: auto;
  padding: 0.25rem 0;
}
.explore-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.explore-item-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 1rem;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  text-align: left;
  font-size: 0.95rem;
  min-height: 48px;
}
.explore-item-btn:hover,
.explore-item-btn:focus-visible {
  border-color: var(--primary);
  background: #e8f5e9;
}
.explore-item-btn.playing {
  border-color: var(--primary);
  background: #d1fae5;
  font-weight: 600;
}
.explore-item-name {
  flex: 1;
}
.explore-item-sci {
  font-style: italic;
  font-size: 0.8rem;
  color: var(--secondary);
}

/* ── Loading ──────────────────────────────────────────────── */
.loading {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(250, 249, 246, 0.92);
  z-index: 50;
}
.loading[hidden] {
  display: none;
}
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 1rem;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Footer ───────────────────────────────────────────────── */
footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.85rem;
}
footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}
footer a:hover {
  text-decoration: underline;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (min-width: 480px) {
  .quick-regions {
    flex-direction: row;
  }
  .region-btn {
    flex: 1;
    text-align: center;
  }
}

@media (min-width: 768px) {
  html { font-size: 20px; }
  main { padding: 2rem; }
}

/* ── Debug Log Panel ─────────────────────────────────────── */
.debug-panel {
  position: fixed;
  bottom: 0;
  right: 0;
  z-index: 999;
  font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
  font-size: 11px;
}
.debug-toggle {
  position: fixed;
  bottom: 8px;
  right: 8px;
  padding: 6px 12px;
  background: #1a1a2e;
  color: #7fdbca;
  border: 1px solid #333;
  border-radius: 6px;
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
  opacity: 0.7;
  z-index: 1000;
}
.debug-toggle:hover {
  opacity: 1;
}
.debug-log {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 45vh;
  background: #0a0a1a;
  color: #c8d6e5;
  border-top: 2px solid #7fdbca;
  display: flex;
  flex-direction: column;
}
.debug-log[hidden] {
  display: none;
}
.debug-log-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 10px;
  background: #1a1a2e;
  color: #7fdbca;
  font-weight: 600;
  font-size: 11px;
  flex-shrink: 0;
}
.debug-clear {
  padding: 2px 8px;
  background: transparent;
  color: #e55;
  border: 1px solid #e55;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 10px;
}
.debug-log-content {
  flex: 1;
  overflow-y: auto;
  padding: 6px 10px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.5;
}
