/* Apprendre Python — feuille de style du site statique.
   Aucun framework, typo système, clair/sombre automatique. */

:root {
  --bg: #ffffff;
  --bg-alt: #f5f6f8;
  --fg: #1c2330;
  --fg-muted: #5b6472;
  --border: #dde1e7;
  --accent: #1a6feb;
  --accent-soft: #e8f0fe;
  --code-bg: #f2f3f5;
  --code-block-bg: #f7f8fa;
  --sidebar-bg: #f5f6f8;
  --sidebar-width: 16.5rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181f;
    --bg-alt: #1b202a;
    --fg: #e4e8ee;
    --fg-muted: #98a1ad;
    --border: #2c333f;
    --accent: #6ea8ff;
    --accent-soft: #1e2a40;
    --code-bg: #232936;
    --code-block-bg: #1a1f29;
    --sidebar-bg: #171c24;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.65;
}

/* ------------------------------------------------------------------ */
/* Sidebar                                                             */
/* ------------------------------------------------------------------ */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  overflow-y: auto;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem 2rem;
}

.site-name {
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 0.75rem;
}

.site-name a {
  color: var(--fg);
  text-decoration: none;
}

.sidebar nav ul {
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0;
}

.sidebar nav li {
  margin: 0;
}

.sidebar nav a {
  display: block;
  padding: 0.28rem 0.5rem;
  border-radius: 6px;
  color: var(--fg-muted);
  text-decoration: none;
  font-size: 0.92rem;
}

.sidebar nav a:hover {
  color: var(--fg);
  background: var(--bg-alt);
}

.sidebar nav a.active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.nav-section {
  margin: 1rem 0 0.25rem;
  padding: 0 0.5rem;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-muted);
}

/* Toggle (mobile only) */
.nav-toggle,
.nav-toggle-label {
  display: none;
}

/* ------------------------------------------------------------------ */
/* Content                                                             */
/* ------------------------------------------------------------------ */

main {
  margin-left: var(--sidebar-width);
  padding: 2rem 1.5rem 4rem;
  max-width: calc(var(--sidebar-width) + 49rem);
}

main > * {
  max-width: 46rem;
}

h1, h2, h3, h4 {
  line-height: 1.3;
  margin: 1.8em 0 0.6em;
}

h1 { font-size: 1.75rem; margin-top: 0.4em; }
h2 { font-size: 1.35rem; border-bottom: 1px solid var(--border); padding-bottom: 0.25em; }
h3 { font-size: 1.12rem; }
h4 { font-size: 1rem; }

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

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* Code */

code {
  font-family: ui-monospace, SFMono-Regular, "Cascadia Code", Consolas,
    "Liberation Mono", Menlo, monospace;
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.12em 0.35em;
  border-radius: 4px;
}

pre {
  background: var(--code-block-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem 1.1rem;
  overflow-x: auto;
  line-height: 1.5;
}

pre code {
  background: none;
  padding: 0;
  font-size: 0.85rem;
  display: block;
}

/* Tables */

table {
  border-collapse: collapse;
  margin: 1rem 0;
  width: 100%;
  display: block;
  overflow-x: auto;
  font-size: 0.93rem;
}

th, td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.7rem;
  text-align: left;
  vertical-align: top;
}

th { background: var(--bg-alt); }

tbody tr:nth-child(even) { background: var(--bg-alt); }

/* Blockquotes */

blockquote {
  margin: 1rem 0;
  padding: 0.4rem 1rem;
  border-left: 3px solid var(--accent);
  background: var(--bg-alt);
  border-radius: 0 8px 8px 0;
  color: var(--fg-muted);
}

blockquote p { margin: 0.4rem 0; }

/* Lists and checklists */

ul, ol { padding-left: 1.6rem; }

li { margin: 0.25rem 0; }

li.task {
  list-style: none;
  margin-left: -1.35rem;
}

li.task input[type="checkbox"] {
  margin-right: 0.45rem;
  accent-color: var(--accent);
}

/* ------------------------------------------------------------------ */
/* Mobile: sidebar becomes a collapsible top menu                      */
/* ------------------------------------------------------------------ */

@media (max-width: 56rem) {
  .nav-toggle-label {
    display: block;
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 0.7rem 1rem;
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    cursor: pointer;
    user-select: none;
  }

  .sidebar {
    position: static;
    width: auto;
    display: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
  }

  .nav-toggle:checked ~ .sidebar {
    display: block;
  }

  main {
    margin-left: 0;
    padding: 1.25rem 1rem 3rem;
    max-width: none;
  }
}

/* --- Widget "Tuteur Python" (bouton + panneau de questions) ------------- */

.ask-open {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 60;
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: 2rem;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}
.ask-open:hover { filter: brightness(1.1); }

.ask-panel {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 61;
  width: min(26rem, calc(100vw - 2.5rem));
  height: min(30rem, calc(100vh - 5rem));
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  box-shadow: 0 6px 30px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.ask-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.9rem;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.ask-close {
  border: none;
  background: none;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  padding: 0 0.2rem;
}

.ask-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: var(--bg-alt);
}

.ask-msg {
  max-width: 92%;
  padding: 0.5rem 0.75rem;
  border-radius: 0.6rem;
  font-size: 0.92rem;
  line-height: 1.5;
  overflow-wrap: break-word;
}
.ask-msg pre {
  background: var(--code-block-bg);
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  padding: 0.5rem;
  overflow-x: auto;
  font-size: 0.85em;
}
.ask-msg code { background: var(--code-bg); }
.ask-user {
  align-self: flex-end;
  background: var(--accent-soft);
  border: 1px solid var(--border);
}
.ask-bot {
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--border);
}

.ask-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.6rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.ask-form textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--bg-alt);
  color: var(--fg);
  font: inherit;
  font-size: 0.9rem;
  padding: 0.45rem 0.6rem;
}
.ask-form button {
  border: none;
  border-radius: 0.5rem;
  background: var(--accent);
  color: #fff;
  padding: 0 0.9rem;
  font-size: 0.9rem;
  cursor: pointer;
}
.ask-form button:disabled { opacity: 0.5; cursor: wait; }

@media (max-width: 44rem) {
  .ask-panel { right: 0.6rem; bottom: 0.6rem; }
}

/* Fix : l'attribut hidden doit toujours gagner (sinon display:flex l'écrase
   et le panneau couvre la page en permanence). */
.ask-panel[hidden],
.ask-open[hidden] { display: none !important; }

/* --- Atelier de code (Python interactif dans le navigateur) ------------- */

.atelier-open {
  position: fixed;
  left: calc(var(--sidebar-width) + 1.25rem);
  bottom: 1.25rem;
  z-index: 60;
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: 2rem;
  background: var(--bg);
  color: var(--fg);
  font-size: 0.95rem;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}
.atelier-open:hover { border-color: var(--accent); color: var(--accent); }
.atelier-open[hidden], .atelier-panel[hidden] { display: none !important; }

.atelier-panel {
  position: fixed;
  left: var(--sidebar-width);
  right: 0;
  bottom: 0;
  z-index: 62;
  height: min(34rem, 75vh);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-top: 2px solid var(--accent);
  box-shadow: 0 -6px 30px rgba(0, 0, 0, 0.25);
}
@media (max-width: 60rem) {
  .atelier-open { left: 1.25rem; }
  .atelier-panel { left: 0; }
}

.at-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.9rem;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.at-body {
  flex: 1;
  display: flex;
  gap: 0;
  min-height: 0;
}
@media (max-width: 52rem) { .at-body { flex-direction: column; } }

.at-editor-wrap {
  flex: 1.2;
  display: flex;
  min-height: 0;
  border-right: 1px solid var(--border);
}
.at-gutter {
  width: 2.6rem;
  overflow: hidden;
  padding: 0.6rem 0.3rem;
  text-align: right;
  color: var(--fg-muted);
  background: var(--bg-alt);
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.88rem;
  line-height: 1.5;
  user-select: none;
}
.at-ln-error {
  background: #c62828;
  color: #fff;
  border-radius: 0.25rem;
  font-weight: 700;
}
#at-code {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  padding: 0.6rem;
  background: var(--code-block-bg);
  color: var(--fg);
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.88rem;
  line-height: 1.5;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
}

.at-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.at-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.at-actions button {
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  background: var(--bg-alt);
  color: var(--fg);
  padding: 0.35rem 0.8rem;
  cursor: pointer;
  font-size: 0.9rem;
}
#at-run { background: var(--accent); color: #fff; border-color: var(--accent); }
#at-run:disabled { opacity: 0.5; cursor: wait; }
.at-kbd { opacity: 0.7; font-size: 0.75em; }

.at-output {
  flex: 1;
  margin: 0;
  padding: 0.6rem;
  overflow: auto;
  background: var(--code-block-bg);
  color: var(--fg);
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.86rem;
  white-space: pre-wrap;
}
.at-output-error { color: #e05252; }

.at-explain {
  border-top: 1px solid var(--border);
  padding: 0.6rem 0.8rem;
  max-height: 45%;
  overflow: auto;
  background: var(--bg-alt);
  font-size: 0.9rem;
}
.at-explain-title { font-weight: 700; color: #c62828; margin-bottom: 0.3rem; }
.at-explain pre { margin: 0.3rem 0; padding: 0.35rem 0.5rem; background: var(--code-block-bg); border-radius: 0.3rem; overflow-x: auto; }
.at-tutor-btn {
  margin-top: 0.4rem;
  border: 1px solid var(--accent);
  border-radius: 0.4rem;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0.35rem 0.8rem;
  cursor: pointer;
  font-size: 0.88rem;
}
.at-tutor-answer {
  margin-top: 0.5rem;
  padding: 0.5rem 0.7rem;
  border-left: 3px solid var(--accent);
  background: var(--bg);
  white-space: pre-wrap;
}

.at-try {
  position: absolute;
  top: 0.35rem;
  right: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 0.35rem;
  background: var(--bg);
  color: var(--fg-muted);
  font-size: 0.72rem;
  padding: 0.15rem 0.5rem;
  cursor: pointer;
  opacity: 0.75;
}
.at-try:hover { opacity: 1; color: var(--accent); border-color: var(--accent); }
