:root {
  color-scheme: light;
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #666666;
  --accent: #2a5db0;
  --accent-fg: #ffffff;
  --border: #dddddd;
  --card-bg: #f7f7f8;
  --discord: #5865f2;
  --error: #c0392b;
  --success: #1f8a4c;
  --warning: #9a6400;
  --warning-bg: #fff6e0;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121212;
  --fg: #eaeaea;
  --muted: #a0a0a0;
  --accent: #6fa8ff;
  --accent-fg: #0b1220;
  --border: #333333;
  --card-bg: #1e1e1e;
  --error: #ff8a75;
  --success: #4fce8a;
  --warning: #ffcc66;
  --warning-bg: #3a2f10;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--fg);
  transition: background-color 0.15s ease, color 0.15s ease;
}

main {
  flex: 1 0 auto;
}

footer {
  flex-shrink: 0;
}

.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 10;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--fg);
  font-size: 1.15rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

header {
  padding: 2.5rem 1rem 1.25rem;
  text-align: center;
}

h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.5rem, 4vw, 2rem);
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.discord-banner {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  max-width: 960px;
  margin: 0 auto 1.75rem;
  padding: 0.9rem 1.2rem;
  border-radius: 12px;
  background: var(--discord);
  color: #ffffff;
  text-decoration: none;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.discord-banner:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(88, 101, 242, 0.35);
}

.discord-icon {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
}

.discord-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  flex: 1 1 auto;
  font-size: 0.9rem;
  line-height: 1.3;
}

.discord-text strong {
  font-size: 1rem;
}

.discord-compact-label {
  display: none;
}

.discord-cta {
  flex: 0 0 auto;
  font-weight: 600;
  white-space: nowrap;
  padding: 0.4rem 0.8rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.18);
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1rem 3rem;
}

#ask-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

#query {
  flex: 1 1 300px;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
  font-size: 1.05rem;
}

#query:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  padding: 0.85rem 1.6rem;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
}

button:disabled {
  opacity: 0.6;
  cursor: default;
}

.status {
  margin-top: 1.5rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.status-error {
  color: var(--error);
}

.answer-card {
  margin-top: 1.5rem;
  padding: 1.25rem 1.4rem;
  border-radius: 12px;
  background: var(--card-bg);
}

.origin-badge {
  display: inline-block;
  margin-bottom: 0.9rem;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
}

.origin-badge--rta {
  background: rgba(31, 138, 76, 0.15);
  color: var(--success);
}

.origin-badge--web {
  background: var(--warning-bg);
  color: var(--warning);
}

.answer-text {
  font-size: 1.05rem;
  line-height: 1.6;
}

.answer-text p {
  margin: 0 0 0.9rem;
}

.answer-text p:last-child {
  margin-bottom: 0;
}

.answer-text ol,
.answer-text ul {
  margin: 0 0 0.9rem;
  padding-left: 1.4rem;
}

.answer-text li {
  margin-bottom: 0.35rem;
}

.answer-text strong {
  color: var(--fg);
}

.web-sources {
  margin-top: 1.1rem;
}

.web-sources-label {
  margin: 0 0 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.web-sources ul {
  margin: 0;
  padding-left: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.web-sources a {
  color: var(--accent);
  word-break: break-word;
}

.sources {
  margin-top: 1.25rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.source-card {
  margin: 0;
  padding: 0.6rem;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.source-card--schematic {
  border-color: var(--accent);
}

.source-image {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 6px;
  cursor: zoom-in;
  display: block;
  background: var(--card-bg);
}

.source-card figcaption {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.full-page-link {
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}

.full-page-link:hover {
  text-decoration: underline;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  padding: 2rem;
}

.lightbox[hidden] {
  display: none;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
}

footer {
  max-width: 960px;
  margin: 2rem auto 2.5rem;
  padding: 0 1rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}

footer a {
  color: var(--accent);
}

.copyright {
  margin-top: 0.4rem;
  font-size: 0.8rem;
}

/* Grand écran : bouton Discord compact, ancré en haut à gauche (comme le
   bouton de thème en haut à droite) plutôt qu'une bannière pleine largeur */
@media (min-width: 701px) {
  .discord-banner {
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 10;
    max-width: none;
    width: auto;
    margin: 0;
    padding: 0.6rem 1.1rem 0.6rem 0.7rem;
    gap: 0.55rem;
  }

  .discord-icon {
    width: 24px;
    height: 24px;
  }

  .discord-text,
  .discord-cta {
    display: none;
  }

  .discord-compact-label {
    display: inline;
    font-size: 0.95rem;
  }
}

/* Tablette */
@media (max-width: 700px) {
  main,
  .discord-banner {
    max-width: 100%;
  }

  .sources {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }
}

/* Mobile */
@media (max-width: 480px) {
  header {
    padding: 1.75rem 1rem 1rem;
  }

  .discord-banner {
    margin: 0 0.75rem 1.25rem;
    padding: 0.8rem 0.9rem;
  }

  .discord-icon {
    width: 26px;
    height: 26px;
  }

  .discord-text {
    font-size: 0.82rem;
  }

  .discord-text strong {
    font-size: 0.92rem;
  }

  .discord-cta {
    display: none;
  }

  main {
    padding: 0 0.75rem 2rem;
  }

  #ask-form {
    flex-direction: column;
  }

  #query,
  #ask-form button {
    width: 100%;
  }

  .answer-card {
    padding: 1rem;
  }

  .sources {
    grid-template-columns: 1fr;
  }

  .lightbox {
    padding: 0.75rem;
  }
}
