:root {
  --accent: #7c7c9c;
  --bg: #14141c;
  --card-bg: #1e1e29;
  --text: #eaeaf2;
  --text-dim: #9a9aad;
  --success: #6fcf97;
  --failure: #eb5757;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  row-gap: 0.5rem;
  padding: 1rem 1.5rem;
  border-bottom: 2px solid var(--accent);
}

.header-title-block {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.app-header h1 {
  font-size: 1.4rem;
  margin: 0;
}

.copyright-line {
  margin: 0;
  font-size: 0.7rem;
  color: var(--text-dim);
}

.copyright-line a {
  color: var(--text-dim);
}

.kofi-line {
  margin: 0;
  font-size: 0.7rem;
}

.kofi-line a {
  color: var(--accent);
}

#mode-select,
#locale-select {
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
}

.header-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.control-selects {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  line-height: 1;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal-overlay.hidden {
  display: none;
}

.modal-card {
  background: var(--card-bg);
  border-radius: 10px;
  padding: 1.25rem;
  max-width: 420px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.settings-group h3 {
  margin-top: 0;
  font-size: 1rem;
}

.settings-hint {
  color: var(--text-dim);
  font-size: 0.85rem;
  line-height: 1.4;
  margin: 0 0 0.75rem;
}

#sync-code-input {
  width: 100%;
  padding: 0.5rem 0.7rem;
  margin-bottom: 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  text-align: center;
}

.settings-actions {
  display: flex;
  gap: 0.5rem;
}

.settings-actions button {
  flex: 1;
  padding: 0.5rem;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #0c0c12;
  font-weight: 600;
  cursor: pointer;
}

.settings-status {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: var(--text-dim);
  min-height: 1.2rem;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card {
  background: var(--card-bg);
  border-radius: 10px;
  padding: 1rem 1.25rem;
}

.card.hidden {
  display: none;
}

#puzzle-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

#puzzle-section.unavailable {
  opacity: 0.5;
}

.puzzle-endpoint {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
}

.puzzle-endpoint .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-dim);
  letter-spacing: 0.05em;
}

.puzzle-endpoint .name {
  font-weight: 600;
  font-size: 1.05rem;
  text-align: center;
  position: relative; /* anchors the channel-links popover, if shown */
}

.option-name {
  position: relative; /* anchors the channel-links popover, if shown */
}

.puzzle-arrow {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
}

.puzzle-arrow:disabled {
  cursor: default;
  opacity: 0.4;
}

#result-reveal,
#shortest-reveal {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  min-height: 2rem;
  margin-bottom: 0.75rem;
}

.reveal-card {
  background: var(--accent);
  color: #0c0c12;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  font-size: 0.9rem;
  position: relative; /* anchors the channel-links popover, if shown */
}

.reveal-card.video {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--accent);
  font-style: italic;
}

.chain-arrow {
  color: var(--text-dim);
}

#start-btn {
  width: 100%;
  padding: 0.6rem;
  margin-bottom: 0.75rem;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #0c0c12;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
}

#start-btn.hidden {
  display: none;
}

.unavailable-message {
  color: var(--text-dim);
  text-align: center;
  padding: 0.75rem 0;
}

.unavailable-message.hidden {
  display: none;
}

.path-history {
  margin-bottom: 0.6rem;
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.5;
  min-height: 1.3rem;
}

#option-filter {
  width: 100%;
  padding: 0.5rem 0.7rem;
  margin-bottom: 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

.main-body {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 0.4rem;
}

.body-row {
  padding: 0.5rem 0.7rem;
  border-radius: 6px;
}

.body-row.option {
  cursor: pointer;
}

.body-row.filtered-out {
  display: none;
}

.body-row.option:hover {
  background: var(--accent);
  color: #0c0c12;
}

.body-row.loading,
.body-row.empty {
  color: var(--text-dim);
  cursor: default;
}

.speaker-icon {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 0.85em;
  padding: 0 0.35rem;
  vertical-align: middle;
  opacity: 0.85;
}

.speaker-icon:hover {
  opacity: 1;
}

.language-icon {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 0.85em;
  padding: 0 0.35rem;
  vertical-align: middle;
  opacity: 0.85;
}

.language-icon:hover {
  opacity: 1;
}

.link-icon {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 0.85em;
  padding: 0 0.35rem;
  vertical-align: middle;
  opacity: 0.85;
  text-decoration: none;
}

.link-icon:hover {
  opacity: 1;
}

.channel-card {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  background: var(--card-bg);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  white-space: nowrap;
}

.channel-card a {
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: normal;
  text-decoration: none;
}

.channel-card a:hover {
  text-decoration: underline;
}

#result-heading.success {
  color: var(--success);
}

#result-heading.failure {
  color: var(--failure);
}

#stats-display {
  color: var(--text-dim);
}

/* the actual scrollable viewport — capped so it can't overflow the modal
   card, scrolls in both directions if the content (below) exceeds it.
   Deliberately separate from .archive-list itself: capping width here
   without also capping .archive-list would let this element clip/scroll
   correctly while .archive-list underneath stays its full natural width,
   so each .archive-row's own background/border still extends the full
   length of its (unwrapped) text instead of being cut off at the visible
   viewport edge when scrolled */
.archive-scroll {
  max-height: 55vh;
  overflow-y: auto;
  overflow-x: auto;
  max-width: 100%;
}

.archive-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  width: max-content; /* shrink/grow to whichever row is widest, no JS measurement needed */
}

.archive-row {
  padding: 0.55rem 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--accent);
  cursor: pointer;
  font-size: 0.9rem;
  white-space: nowrap; /* the whole point: date/names/status never wrap onto each other */
}

.archive-row:hover {
  background: var(--accent);
  color: #0c0c12;
}

/* the archive card sizes to its content (widest row) instead of the fixed
   420px every other modal uses, up to a cap so it can't overflow a small
   viewport or blow out to an unreasonable width from one long name pair */
#archive-overlay .modal-card {
  width: max-content;
  max-width: min(90vw, 640px);
}

#archive-load-more-btn {
  margin-top: 0.6rem;
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: none;
  color: var(--text);
  cursor: pointer;
}

#archive-load-more-btn.hidden {
  display: none;
}

#share-btn {
  margin-top: 0.75rem;
  width: 100%;
  padding: 0.6rem;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #0c0c12;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
}

/* touch-primary devices (regardless of screen width) get larger tap targets,
   since 44px is the commonly cited minimum and the mouse-tuned padding above
   falls well short of it */
@media (pointer: coarse) {
  .body-row.option {
    padding: 0.85rem 0.9rem;
  }

  .puzzle-arrow {
    padding: 0.6rem 0.9rem;
    font-size: 1.5rem;
  }

  #start-btn,
  #share-btn {
    padding: 0.85rem;
  }

  #option-filter {
    padding: 0.75rem 0.8rem;
  }

  #mode-select,
  #locale-select {
    padding: 0.6rem 0.7rem;
  }

  .speaker-icon,
  .link-icon,
  .language-icon {
    padding: 0.3rem 0.5rem;
    font-size: 1em;
  }

  .icon-btn {
    padding: 0.6rem 0.7rem;
    font-size: 1.4rem;
  }

  #sync-code-input,
  .settings-actions button {
    padding: 0.85rem;
  }
}

#report-overlay .modal-card {
  max-width: 480px;
}

.report-menu-btn,
.report-type-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.6rem 0.8rem;
  margin-bottom: 0.4rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: none;
  color: var(--text);
  cursor: pointer;
  font-size: 0.95rem;
}

.report-menu-btn:hover,
.report-type-btn:hover {
  background: var(--accent);
  color: #0c0c12;
}

.report-menu-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.report-menu-btn:disabled:hover {
  background: none;
  color: var(--text);
}

.report-back-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}

.report-search-select input {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 0.4rem;
}

.report-search-results {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-height: 8rem;
  overflow-y: auto;
  margin-bottom: 0.6rem;
}

.report-search-row {
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

.report-search-row:hover {
  background: var(--accent);
  color: #0c0c12;
}

.report-picked {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.6rem;
  min-height: 1.1rem;
}

.report-multiselect {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  max-height: 10rem;
  overflow-y: auto;
  margin-bottom: 0.75rem;
}

.report-checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.report-submit-btn {
  width: 100%;
  padding: 0.6rem;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #0c0c12;
  font-weight: 600;
  cursor: pointer;
  margin-top: 0.4rem;
}

.report-submit-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.report-status {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: var(--text-dim);
  min-height: 1.2rem;
}

.report-singleselect {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-height: 10rem;
  overflow-y: auto;
  margin-bottom: 0.75rem;
}

.report-singleselect-row {
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 0.9rem;
}

.report-singleselect-row:hover {
  background: var(--accent);
  color: #0c0c12;
}

.report-singleselect-row.selected {
  border-color: var(--accent);
  font-weight: 600;
}

.report-awaiting-badge {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-left: 0.4rem;
}

.report-code-display {
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 0.75rem;
  margin-bottom: 0.6rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--bg);
}

.report-code-hint {
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.4;
  margin-bottom: 0.75rem;
}

#video-link-input {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.help-card {
  max-width: 520px;
}

.help-section {
  margin-bottom: 1.25rem;
}

.help-section:last-child {
  margin-bottom: 0;
}

.help-section h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.help-section p {
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.45;
  margin: 0 0 0.6rem;
}

.faq-item {
  margin-bottom: 0.85rem;
}

.faq-item:last-child {
  margin-bottom: 0;
}

.faq-question {
  color: var(--text) !important;
  font-weight: 600;
  margin-bottom: 0.2rem !important;
}

.faq-answer {
  margin-bottom: 0 !important;
}

.icon-legend {
  list-style: none;
  padding: 0;
  margin: 0 !important;
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.6;
}

.about-card {
  padding-top: 1rem;
  border-top: 1px solid var(--accent);
}

.help-legal-link {
  font-size: 0.8rem !important;
}
