/* MATH & ÇA ! — Laboratoire Python */
:root {
  --bleu-fonce: #004aad;
  --bleu: #357df9;
  --bleu-clair: #bbdff4;
  --bleu-pale: #e8f0fa;
  --vert: #00b090;
  --violet: #673de6;
  --jaune: #ffcd35;
  --texte: #1d1e20;
  --texte-clair: #5c6370;
  --blanc: #fff;
  --bordure: #dce1e8;
  --nav-h: 120px;
  --topbar-h: 4vh;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  min-height: -webkit-fill-available;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: "DM Sans", system-ui, sans-serif;
  color: var(--texte);
  background: var(--blanc);
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  min-height: 100%;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

a { color: var(--bleu-fonce); text-decoration: none; }
a:hover { color: var(--bleu); }

/* ——— En-tête site (identique mathetca.fr) ——— */
.site-header {
  flex-shrink: 0;
  width: 100%;
  font-family: "Sen", system-ui, sans-serif;
  overflow: visible;
  z-index: 200;
}

.top-bar {
  position: relative;
  z-index: 20;
  width: 100%;
  height: var(--topbar-h);
  min-height: 36px;
  background-color: #bbdff4;
  overflow: hidden;
  display: flex;
  align-items: center;
}

.top-bar p {
  color: #004aad;
  display: inline-block;
  white-space: nowrap;
  animation: banner-animation 20s linear infinite;
  width: 100%;
  position: absolute;
  margin: 0;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.25;
}

#bannerTextOne {
  animation-delay: 0s !important;
}

#bannerTextTwo {
  animation-delay: 10s !important;
  visibility: hidden;
}

@keyframes banner-animation {
  0% {
    transform: translateX(100%);
    visibility: hidden;
  }
  100% {
    transform: translateX(-100%);
    visibility: visible;
  }
}

.site-nav {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--blanc);
  border-bottom: 1px solid #bbdff4;
  width: 100%;
  overflow: visible;
}

.site-nav-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  min-width: 0;
  max-width: 100%;
  width: auto;
}

.nav-logo {
  flex-shrink: 0;
  display: flex;
  width: 88px;
  height: 88px;
}
.nav-logo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.nav-scroll {
  flex: 0 1 auto;
  min-width: 0;
  overflow: visible;
}

.nav-menu {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-start;
  gap: 16px 20px;
  list-style: none;
  padding: 0;
  margin: 0;
  width: auto;
}

.nav-menu > li {
  position: relative;
}

.nav-menu a,
.nav-menu .nav-label,
.nav-menu .nav-trigger {
  display: inline-flex;
  align-items: center;
  color: #004AAD;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.25;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
}

.nav-caret {
  display: inline-flex;
  margin-left: 8px;
  color: #004AAD;
  transition: transform 0.3s;
}
.nav-caret svg {
  margin: 2px 6.5px;
}

.nav-menu a:hover,
.nav-has-dropdown:hover > .nav-trigger {
  color: #BBDFF4;
  text-decoration: underline;
  text-underline-offset: 7px;
}

.nav-has-dropdown:hover .nav-caret {
  transform: rotate(180deg);
}

.nav-dropdown-area {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 30;
  padding-top: 8px;
  padding-right: 16px;
  padding-bottom: 48px;
}

.nav-has-dropdown:hover .nav-dropdown-area {
  display: block;
}

/* iPad / iPhone : pas de menu au survol, ouverture au tap */
@media (hover: none), (pointer: coarse) {
  .nav-has-dropdown:hover .nav-dropdown-area {
    display: none;
  }
  .nav-has-dropdown.open .nav-dropdown-area {
    display: block;
  }
  .nav-has-dropdown.open .nav-caret {
    transform: rotate(180deg);
  }
}

.nav-dropdown {
  position: static;
  min-width: 220px;
  max-height: 400px;
  overflow: auto;
  margin: 0;
  padding: 16px 24px;
  list-style: none;
  background: var(--blanc);
  border-radius: 5px;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.1);
}

.nav-dropdown li + li {
  margin-top: 8px;
}

.nav-dropdown a {
  display: block;
  white-space: normal;
}

.nav-dropdown a:hover {
  color: #BBDFF4;
  text-decoration: underline;
  text-underline-offset: 7px;
}

.nav-menu a.active {
  color: #004AAD;
  text-decoration: underline;
  text-underline-offset: 7px;
}

.nav-toggle {
  display: none;
}

/* ——— Zone principale pleine page ——— */
.app-main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  width: 100%;
}

/* ——— Liste programmes ——— */
.program-nav {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #f6f8fb;
  border-right: 1px solid var(--bordure);
}

.nav-head {
  padding: 0.65rem 0.75rem 0.4rem;
  border-bottom: 1px solid var(--bordure);
}
.nav-title {
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--bleu-fonce);
}

.level-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  padding: 0.5rem 0.75rem;
}
.level-btn {
  padding: 0.28rem 0.55rem;
  border: 1px solid var(--bordure);
  border-radius: 6px;
  background: var(--blanc);
  color: var(--bleu-fonce);
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.level-btn:hover { border-color: var(--bleu); }
.level-btn.active {
  background: var(--bleu-fonce);
  color: var(--blanc);
  border-color: var(--bleu-fonce);
}

.nav-toolbar {
  padding: 0 0.75rem 0.5rem;
}
.nav-toolbar input {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--bordure);
  border-radius: 6px;
  font-size: 0.82rem;
  font-family: inherit;
}
.nav-toolbar input:focus {
  outline: none;
  border-color: var(--bleu);
}
.nav-count {
  margin-top: 0.35rem;
  font-size: 0.7rem;
  color: var(--texte-clair);
}

.program-tree {
  flex: 1;
  overflow-y: auto;
  padding: 0.35rem 0.5rem 0.5rem;
}

.tree-level {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--texte-clair);
  padding: 0.5rem 0.35rem 0.2rem;
}

.tree-chapter {
  margin-bottom: 0.25rem;
  border-radius: 6px;
  background: var(--blanc);
  border: 1px solid transparent;
}
.tree-chapter[open] {
  border-color: var(--bordure);
}

.tree-chapter-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  padding: 0.4rem 0.5rem;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--bleu-fonce);
  list-style: none;
}
.tree-chapter-title::-webkit-details-marker { display: none; }
.tree-chapter-title::before {
  content: "▸ ";
  color: var(--texte-clair);
}
.tree-chapter[open] .tree-chapter-title::before {
  content: "▾ ";
}
.tree-chapter-count {
  font-size: 0.65rem;
  background: var(--bleu-pale);
  padding: 0 0.35rem;
  border-radius: 4px;
}

.tree-programs {
  padding: 0 0.35rem 0.35rem;
}
.tree-prog {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.4rem 0.5rem;
  margin-bottom: 0.2rem;
  border: none;
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--texte);
}
.tree-prog:hover { background: var(--bleu-pale); }
.tree-prog.active {
  background: var(--bleu-fonce);
  color: var(--blanc);
}
.tree-prog-summary,
.tree-prog-meta {
  display: none;
}

.empty-msg {
  padding: 1rem;
  font-size: 0.8rem;
  color: var(--texte-clair);
  text-align: center;
}

/* ——— Éditeur ——— */
.ide-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--blanc);
}

.py-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  background: #fff8e2;
  border-bottom: 1px solid #ffe08a;
  font-size: 0.82rem;
  font-weight: 600;
}
.py-loader-copy {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}
.py-loader-detail {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--texte-clair);
}
.py-banner.error {
  background: #ffe8ef;
  border-color: #fecdd3;
  color: #9f1239;
}

.spinner-sm {
  width: 16px;
  height: 16px;
  border: 2px solid var(--bleu-pale);
  border-top-color: var(--bleu-fonce);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn-retry {
  margin-left: auto;
  padding: 0.25rem 0.65rem;
  background: var(--bleu-fonce);
  color: var(--blanc);
  border: none;
  border-radius: 6px;
  font-size: 0.78rem;
  cursor: pointer;
  font-family: inherit;
}

.welcome-ide {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--texte-clair);
  font-size: 0.95rem;
  gap: 0.35rem;
}
.welcome-ide kbd {
  background: #eee;
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  font-size: 0.75rem;
}

.editor-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.ide-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--bordure);
  background: #fafbfc;
  flex-shrink: 0;
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.8rem;
  font-weight: 600;
  min-width: 0;
}
.crumb-level { font-weight: 800; }
.crumb-sep { color: var(--texte-clair); }
.crumb-prog { color: var(--bleu-fonce); }

.ide-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.btn {
  padding: 0.38rem 0.75rem;
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  touch-action: manipulation;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-run {
  background: var(--vert);
  color: var(--blanc);
}
.btn-ghost {
  background: var(--blanc);
  border: 1px solid var(--bordure);
  color: var(--texte);
  padding: 0.38rem 0.55rem;
}

.py-status {
  font-size: 0.72rem;
  color: var(--texte-clair);
  margin-left: 0.25rem;
}
.py-status.ready { color: var(--vert); font-weight: 700; }

.ide-split {
  flex: 1;
  display: flex;
  flex-direction: row;
  min-height: 0;
}

.ide-split--stacked {
  flex-direction: column;
}
.ide-split--stacked .split-handle {
  width: 100%;
  height: 6px;
  cursor: row-resize;
}

.editor-pane,
.console-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.editor-pane { flex: 1 1 55%; }
.console-pane { flex: 1 1 45%; }

.split-handle {
  flex: 0 0 5px;
  width: 5px;
  cursor: col-resize;
  background: var(--bordure);
}
.split-handle:hover,
body.is-resizing .split-handle {
  background: var(--bleu);
}
body.is-resizing {
  cursor: col-resize;
  user-select: none;
}

.pane-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--texte-clair);
  padding: 0.25rem 0.6rem;
  background: #f4f6f8;
  border-bottom: 1px solid var(--bordure);
  flex-shrink: 0;
}

.codemirror-box {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.codemirror-box .CodeMirror {
  height: 100% !important;
  font-size: 14px;
  font-family: "Cascadia Code", Consolas, monospace;
  -webkit-user-select: text;
  user-select: text;
}
.codemirror-box .CodeMirror-scroll {
  -webkit-overflow-scrolling: touch;
}

/* Terminal */
.terminal {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #0f172a;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 13px;
}

.terminal-out {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.65rem;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.terminal-empty .terminal-out::before {
  content: "Exécutez le programme (▶). Ensuite, testez des commandes ici.";
  color: #64748b;
  font-style: italic;
  font-size: 0.85rem;
}

.terminal-stream,
.terminal-line,
.terminal-block {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0 0 0.15rem;
  font-family: inherit;
  font-size: inherit;
}
.terminal-stream.term-stdout-stream { color: #e2e8f0; }
.terminal-stream.term-stderr-stream,
.terminal-block.term-stderr {
  color: #fecaca;
  background: rgba(127, 29, 29, 0.3);
  padding: 0.35rem;
  border-radius: 4px;
}
.term-system { color: #94a3b8; font-style: italic; }

.terminal-input-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.55rem;
  padding-bottom: max(0.4rem, env(safe-area-inset-bottom));
  background: #1e293b;
  border-top: 1px solid #334155;
  flex-shrink: 0;
}
.terminal-ps1 { color: #4ade80; font-weight: 700; }
.terminal-input {
  flex: 1;
  border: none;
  background: transparent;
  color: #f1f5f9;
  font: inherit;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  border-radius: 0;
}
.terminal-input:disabled { opacity: 0.5; }

.hidden { display: none !important; }

/* Mobile */
@media (max-width: 920px) {
  :root {
    --topbar-h: 10vh;
    --nav-h: 72px;
  }

  .top-bar p {
    animation: banner-animation 10s linear infinite;
    font-size: 14px;
  }

  #bannerTextTwo {
    animation-delay: 0s !important;
    visibility: hidden;
  }

  html, body { overflow: auto; }
  body {
    height: auto;
    min-height: 100%;
    min-height: -webkit-fill-available;
  }
  .app-main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: auto;
    min-height: calc(100vh - var(--topbar-h) - var(--nav-h));
    min-height: calc(100svh - var(--topbar-h) - var(--nav-h));
  }
  .program-nav {
    max-height: 220px;
    border-right: none;
    border-bottom: 1px solid var(--bordure);
  }
  .site-nav {
    padding: 12px 16px;
  }
  .site-nav-inner {
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
  }
  .nav-logo {
    width: 72px;
    height: 72px;
  }
  .nav-menu {
    gap: 10px 14px;
    flex-wrap: wrap;
    justify-content: center;
  }
  .nav-menu a,
  .nav-menu .nav-label,
  .nav-menu .nav-trigger {
    font-size: 14px;
  }
  .nav-dropdown-area {
    position: fixed;
    left: 8px;
    right: 8px;
    top: auto;
    max-width: calc(100vw - 16px);
    padding-top: 4px;
    padding-bottom: 16px;
  }
  .nav-has-dropdown:hover .nav-dropdown-area {
    display: none;
  }
  .nav-has-dropdown.open .nav-dropdown-area {
    display: block;
  }
  .ide-top { align-items: flex-start; flex-direction: column; }
  .ide-actions { flex-wrap: wrap; }
  .ide-split { flex-direction: column; min-height: 420px; }
  .split-handle { width: 100%; height: 6px; cursor: row-resize; }
  .nav-toolbar input,
  .terminal-input,
  .codemirror-box .CodeMirror {
    font-size: 16px;
  }
  .btn {
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
  }
  .level-btn {
    min-height: 40px;
    touch-action: manipulation;
  }
  .welcome-ide .hint-mobile {
    display: block;
    margin-top: 0.5rem;
    color: var(--texte-clair);
    font-size: 0.9rem;
  }
}
