/*
 * Algo Express — feuille de style
 *
 * Layout : un éditeur de code plein écran. Barre d'onglets en haut
 * (fichier = manche), gouttière numérotée, diapo au centre, barre d'état
 * fine en bas. Les scores vivent dans un panneau qu'on ouvre avec S.
 * Thème sombre unique, choisi pour l'effet « IDE » au projecteur.
 */

/* ===================== VARIABLES ===================== */
:root {
  color-scheme: dark;

  /* fonds et texte */
  --bg: #0c1122;
  --bg2: #10172d;
  --panel: #151d38;
  --card: #151d38;
  --line: #26305a;
  --fg: #e8ebff;
  --muted: #8a94bd;
  --comment: #6474a8;

  /* coloration syntaxique */
  --kw: #c39bff;
  --str: #ffb26b;
  --op: #4fe0e8;
  --num: #ff8a7a;
  --ok: #3ee59a;
  --caret: #4fe0e8;

  /* tuiles de réponse */
  --a: #3a78ff;
  --b: #ff4767;
  --c: #ffc13b;
  --d: #18c48a;
  --c-ink: #2a1d00;
  --vrai: #18c48a;
  --faux: #ff4767;

  /* équipes */
  --t1: #5b8cff;
  --t2: #ff5c79;
  --t3: #2fd99a;
  --t4: #ffc13b;

  /* polices */
  --display: "Martian Mono", "JetBrains Mono", ui-monospace, monospace;
  --body: "Atkinson Hyperlegible", Verdana, system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
}

/* Couleur d'équipe : chaque élément d'équipe reçoit une classe team-N
   et lit sa couleur dans --tc. */
.team-1 { --tc: var(--t1); }
.team-2 { --tc: var(--t2); }
.team-3 { --tc: var(--t3); }
.team-4 { --tc: var(--t4); }

/* ===================== BASE ===================== */
* {
  box-sizing: border-box;
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "calt" 0, "dlig" 0;
}

[hidden] { display: none !important; }

img { max-width: 100%; }

html,
body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--body);
  font-size: clamp(15px, 1.25vw, 22px);
  line-height: 1.45;
  background-image:
    radial-gradient(circle at 75% -10%, rgba(195, 155, 255, .14), transparent 45%),
    radial-gradient(circle at 0% 110%, rgba(79, 224, 232, .10), transparent 40%),
    radial-gradient(rgba(138, 148, 189, .16) 1px, transparent 1.2px);
  background-size: auto, auto, 24px 24px;
}

.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding-left: max(0px, env(safe-area-inset-left, 0px));
  padding-right: max(0px, env(safe-area-inset-right, 0px));
}

/* ===================== ONGLETS ===================== */
.tabs {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 0;
  min-height: 46px;
  background: var(--bg2);
  border-bottom: 1px solid var(--line);
}

.tabs .sp { flex: 1; }

.dots {
  display: flex;
  gap: 7px;
  align-items: center;
  padding: 0 16px;
}

.dots i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--b);
}

.dots i:nth-child(2) { background: var(--c); }
.dots i:nth-child(3) { background: var(--d); }

.tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 18px;
  font-family: var(--mono);
  font-size: 14px;
  color: var(--muted);
  border-right: 1px solid var(--line);
  white-space: nowrap;
}

.tab.on {
  background: var(--bg);
  color: var(--fg);
  box-shadow: inset 0 2px 0 var(--kw);
}

.tab .x { color: var(--comment); }
.tab .ext { color: var(--op); }

.progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
}

.progress i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--kw), var(--op));
  transition: width .3s;
}

.timer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
}

.timer .bar {
  width: clamp(90px, 16vw, 260px);
  height: 10px;
  border-radius: 99px;
  overflow: hidden;
  background: var(--line);
}

.timer .bar i {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--ok);
  transition: width 1s linear;
}

.timer .bar i.low { background: var(--b); }

.timer .num {
  min-width: 3ch;
  font-family: var(--mono);
  font-weight: 800;
  font-size: 22px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 700px) {
  .tab.file,
  .dots { display: none; }
}

/* ===================== CORPS ET GOUTTIÈRE ===================== */
.body {
  display: grid;
  grid-template-columns: 56px 1fr;
  min-height: 0;
}

.gutter {
  padding: 18px 10px 0 0;
  border-right: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 24px;
  color: var(--comment);
  text-align: right;
  white-space: pre;
  opacity: .7;
  overflow: hidden;
  user-select: none;
}

@media (max-width: 700px) {
  .body { grid-template-columns: 16px 1fr; }
  .gutter { font-size: 0; padding: 0; border: none; }
}

/* ===================== SCÈNE ===================== */
.stage {
  position: relative;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding:
    clamp(14px, 2.6vh, 36px)
    max(16px, clamp(14px, 3.4vw, 56px))
    20px
    clamp(14px, 3.4vw, 56px);
}

.slide {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 2.2vh, 26px);
  animation: in .35s ease;
}

.center { justify-content: center; }

@keyframes in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ===================== TYPOGRAPHIE ===================== */
.comment {
  margin: 0;
  font-family: var(--mono);
  font-size: clamp(14px, 1.25vw, 21px);
  color: var(--comment);
}

.comment b { color: var(--fg); }

h1,
h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  line-height: 1.02;
  letter-spacing: -.03em;
  text-wrap: balance;
}

h1 {
  font-size: clamp(44px, 8.4vw, 150px);
  font-variation-settings: "wdth" 112.5;
}

h2 { font-size: clamp(30px, 4.6vw, 80px); }

/* curseur clignotant après les titres */
h1::after,
h2::after {
  content: "_";
  margin-left: .08em;
  color: var(--caret);
  animation: blink 1.1s steps(1) infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

h1 .grad {
  background: linear-gradient(90deg, var(--kw), var(--op));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

h3 {
  margin: 0 0 8px;
  font-family: var(--mono);
  font-size: clamp(17px, 1.5vw, 26px);
  font-weight: 800;
  color: var(--op);
}

.lead {
  max-width: 36ch;
  margin: 0;
  font-size: clamp(18px, 1.8vw, 32px);
  color: var(--fg);
}

.kbd {
  padding: 0 8px;
  border: 1px solid var(--line);
  border-bottom-width: 3px;
  border-radius: 7px;
  background: var(--panel);
  color: var(--fg);
  font-family: var(--mono);
  font-size: .85em;
}

.mono-big {
  margin: 0;
  font-family: var(--mono);
  font-weight: 800;
  font-size: clamp(24px, 3.2vw, 54px);
  color: var(--kw);
}

/* ===================== CARTES ET POST-IT ===================== */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: clamp(12px, 1.6vw, 24px);
}

.card {
  padding: clamp(14px, 1.6vw, 26px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.card p,
.card ul { margin: 0; }

.card p + p { margin-top: 8px; }

.card ul {
  display: grid;
  gap: 6px;
  padding-left: 1.1em;
}

.card b { color: var(--str); }

.postit {
  padding: clamp(14px, 1.6vw, 26px);
  background: linear-gradient(180deg, rgba(195, 155, 255, .10), rgba(195, 155, 255, .04));
  border: 1px solid rgba(195, 155, 255, .35);
  border-left: 4px solid var(--kw);
  border-radius: 12px;
  color: var(--fg);
}

.postit.narrow { max-width: 760px; }

.postit h3 { color: var(--kw); }
.postit h3::before { content: "/** "; color: var(--comment); }
.postit h3::after { content: " */"; color: var(--comment); }

.postit p { margin: 0 0 6px; }
.postit b { color: var(--str); }

.postit code,
.card code,
.steps code {
  padding: 0 6px;
  border-radius: 5px;
  background: rgba(79, 224, 232, .12);
  color: var(--op);
  font-family: var(--mono);
  font-size: .92em;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.chip {
  padding: 4px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--fg);
  font-family: var(--mono);
  font-size: clamp(14px, 1.2vw, 20px);
}

/* ordre des priorités : ( ) › NON › … */
.prio {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  font-family: var(--mono);
  font-weight: 700;
  color: var(--comment);
}

.prio span {
  padding: 2px 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--op);
}

.prio + p { margin-top: 8px; }

/* ===================== QUESTION ===================== */
.qhead {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.tag {
  padding: 3px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 99px;
  color: var(--muted);
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(13px, 1.05vw, 18px);
}

.howto {
  flex: 1 1 320px;
  padding: 4px 0;
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(14px, 1.15vw, 20px);
  color: var(--str);
}

.howto::before { content: "› "; color: var(--op); }

.prompt {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(22px, 2.6vw, 46px);
  line-height: 1.15;
  text-wrap: balance;
}

.qgrid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(12px, 2vw, 30px);
  align-content: start;
}

.qgrid.has-code { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }

@media (max-width: 900px) {
  .qgrid.has-code { grid-template-columns: 1fr; }
}

/* colonne des réponses (tuiles + correction) */
.answers {
  display: grid;
  gap: 14px;
  align-content: start;
  min-width: 0;
}

pre.code {
  min-width: 0;
  margin: 0;
  padding: clamp(14px, 1.6vw, 26px);
  overflow-x: auto;
  background: #080c19;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 20px 50px -30px rgba(0, 0, 0, .8);
  color: var(--fg);
  font-family: var(--mono);
  font-weight: 500;
  font-size: clamp(15px, 1.7vw, 30px);
  line-height: 1.5;
  white-space: pre;
}

pre.code.expr {
  padding-block: clamp(18px, 3vh, 40px);
  font-size: clamp(22px, 3.3vw, 58px);
  font-weight: 700;
  text-align: center;
  white-space: pre-wrap;
}

/* coloration du pseudocode */
.kw { color: var(--kw); font-weight: 700; }
.op { color: var(--op); font-weight: 700; }
.str { color: var(--str); }

/* tuiles de réponse */
.tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(8px, 1vw, 14px);
  align-content: start;
}

.has-code .tiles { grid-template-columns: 1fr; }

.tile {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: clamp(56px, 9vh, 110px);
  padding: clamp(12px, 1.6vh, 22px) clamp(12px, 1.2vw, 20px);
  border: none;
  border-radius: 12px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .35);
  color: #fff;
  font-family: var(--mono);
  font-weight: 800;
  font-size: clamp(17px, 1.9vw, 34px);
  line-height: 1.15;
  text-align: left;
  transition: opacity .3s, transform .3s;
}

.tile:hover {
  filter: brightness(1.08);
  background-image: none;
}

.tile .l {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.7em;
  height: 1.7em;
  border-radius: 8px;
  background: rgba(0, 0, 0, .22);
  font-size: .85em;
}

.tile .t {
  min-width: 0;
  overflow-wrap: anywhere;
}

.tile.A { background: var(--a); }
.tile.B { background: var(--b); }
.tile.C { background: var(--c); color: var(--c-ink); }
.tile.D { background: var(--d); }

.tile.vrai,
.tile.faux {
  justify-content: center;
  min-height: clamp(90px, 18vh, 200px);
  font-family: var(--display);
  font-size: clamp(30px, 4.4vw, 80px);
}

.tile.vrai { background: var(--vrai); }
.tile.faux { background: var(--faux); }

.tile .icon { font-size: .6em; }

.tile.wrong {
  opacity: .14;
  filter: grayscale(.7);
}

.tile.right {
  transform: scale(1.02);
  box-shadow: 0 0 0 4px var(--bg), 0 0 0 7px var(--fg), 0 0 40px rgba(255, 255, 255, .25);
}

/* correction */
.correction {
  display: grid;
  gap: 10px;
  animation: in .3s ease;
}

.correction .postit {
  background: linear-gradient(180deg, rgba(62, 229, 154, .10), rgba(62, 229, 154, .03));
  border-color: rgba(62, 229, 154, .35);
}

.correction .postit h3 { color: var(--ok); }
.correction .postit h3::before { content: "$ "; color: var(--comment); }
.correction .postit h3::after { content: ""; }

.steps {
  display: grid;
  gap: 4px;
  margin: 0;
  padding-left: 0;
  list-style: none;
  font-size: clamp(16px, 1.4vw, 26px);
  counter-reset: s;
}

.steps li {
  position: relative;
  padding-left: 2.2em;
  counter-increment: s;
}

.steps li::before {
  content: counter(s) " ›";
  position: absolute;
  left: 0;
  font-family: var(--mono);
  color: var(--comment);
}

/* commandes sous la question */
.qctl {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

/* réglage de la durée du chrono : Chrono − 30 s + */
.chrono-set {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-family: var(--mono);
  font-weight: 700;
}

.chrono-set button { padding: 2px 12px; }

.chrono-set .tlen {
  min-width: 4.5ch;
  color: var(--fg);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ===================== BOUTONS ===================== */
button {
  padding: 8px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--fg);
  font: inherit;
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(13px, 1vw, 17px);
  cursor: pointer;
}

button:hover {
  border-color: var(--op);
  color: var(--op);
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--op);
  outline-offset: 2px;
}

button.primary {
  background: var(--kw);
  border-color: var(--kw);
  color: #160b2e;
}

button.primary:hover {
  filter: brightness(1.1);
  color: #160b2e;
}

button:disabled {
  opacity: .35;
  cursor: default;
}

/* ===================== CLASSEMENT ===================== */
.board {
  display: grid;
  gap: 12px;
  width: 100%;
  max-width: 960px;
}

.brow {
  display: grid;
  grid-template-columns: minmax(0, 11em) 1fr auto;
  gap: 14px;
  align-items: center;
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(16px, 1.6vw, 28px);
}

.brow .name {
  overflow: hidden;
  color: var(--tc);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brow .bar {
  height: clamp(22px, 3.4vh, 40px);
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.brow .bar i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 7px;
  background: var(--tc);
  transition: width .8s cubic-bezier(.2, .8, .2, 1);
}

.brow .pts {
  display: flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}

.brow .pts button {
  padding: 0 9px;
  font-size: 16px;
}

.brow .pts span {
  min-width: 2ch;
  text-align: center;
}

/* podium */
.podium {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: clamp(8px, 2vw, 28px);
  height: clamp(220px, 40vh, 420px);
}

.step {
  display: grid;
  justify-items: center;
  align-content: end;
  gap: 8px;
  min-width: 0;
  height: 100%;
}

.step .blk {
  display: grid;
  place-items: center;
  width: clamp(90px, 14vw, 220px);
  background: color-mix(in srgb, var(--tc) 22%, var(--card));
  border: 2px solid var(--tc);
  border-bottom: none;
  border-radius: 10px 10px 0 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(28px, 3.4vw, 56px);
}

.step.rank-1 .blk { height: 100%; }
.step.rank-2 .blk { height: 60%; }
.step.rank-3 .blk { height: 40%; }

.step .nm {
  color: var(--tc);
  font-family: var(--mono);
  font-weight: 800;
  font-size: clamp(15px, 1.6vw, 26px);
  text-align: center;
}

/* ===================== SOMMAIRE ET NOMS D'ÉQUIPES ===================== */
.menu {
  display: grid;
  gap: 10px;
  width: 100%;
  max-width: 960px;
}

.menu button {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 18px;
  padding: 14px 20px;
  font-family: var(--body);
  text-align: left;
}

.menu .n {
  color: var(--kw);
  font-family: var(--mono);
  font-size: clamp(17px, 1.5vw, 24px);
}

.menu b {
  font-family: var(--mono);
  font-size: clamp(18px, 1.8vw, 30px);
}

.menu span {
  color: var(--muted);
  font-weight: 400;
}

.names {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
  gap: 10px;
}

.names label {
  display: grid;
  gap: 4px;
  color: var(--tc);
  font-family: var(--mono);
  font-weight: 700;
  font-size: .85em;
}

.names input {
  width: 100%;
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--tc);
  border-radius: 10px;
  color: var(--fg);
  font: inherit;
  font-family: var(--body);
  font-size: 1.1em;
}

/* ===================== BARRE D'ÉTAT ===================== */
.status {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 32px;
  padding-right: max(8px, env(safe-area-inset-right, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--bg2);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 13px;
}

.status .seg {
  padding: 0 12px;
  white-space: nowrap;
}

.status .seg.mode {
  align-self: stretch;
  display: flex;
  align-items: center;
  background: var(--kw);
  color: #160b2e;
  font-weight: 800;
}

.status .sp { flex: 1; }

.status button {
  padding: 4px 10px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
}

.status button:hover {
  background: var(--panel);
  color: var(--fg);
}

@media (max-width: 700px) {
  .status .hide-s { display: none; }
}

/* ===================== PANNEAU DES SCORES ===================== */
.drawer {
  position: fixed;
  top: 56px;
  right: max(12px, env(safe-area-inset-right, 0px));
  z-index: 20;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 24px));
  padding: 14px;
  background: rgba(16, 23, 45, .96);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .8);
  animation: in .2s ease;
}

.drawer header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-family: var(--mono);
}

.drawer header b { color: var(--str); }

.team-list {
  display: grid;
  gap: 8px;
}

.trow {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 8px;
  align-items: center;
  font-family: var(--mono);
}

.trow .nm {
  overflow: hidden;
  color: var(--tc);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trow .sc {
  min-width: 2ch;
  font-size: 24px;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.trow button {
  padding: 2px 12px;
  border-color: var(--tc);
  font-size: 18px;
}

/* ===================== MOUVEMENT RÉDUIT ===================== */
@media (prefers-reduced-motion: reduce) {
  .slide,
  .correction,
  .drawer,
  h1::after,
  h2::after { animation: none; }

  .brow .bar i,
  .progress i,
  .timer .bar i { transition: none; }
}
