:root {
  --ink: #17202a;
  --muted: #64707d;
  --line: #d7dee5;
  --paper: #ffffff;
  --surface: #f5f8fa;
  --accent: #0f6b78;
  --accent-dark: #0a4b55;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--surface);
  direction: rtl;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
}

.toolbar {
  padding: 24px;
  border-left: 1px solid var(--line);
  background: #fff;
}

.brand h1 {
  margin: 0 0 6px;
  font-size: 28px;
  letter-spacing: 0;
}

.brand p {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 14px;
}

.controls {
  display: grid;
  gap: 14px;
}

label span {
  display: block;
  margin-bottom: 6px;
  color: #33414e;
  font-size: 13px;
  font-weight: 700;
}

select,
input[type="number"] {
  width: 100%;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 0;
}

.toggle input {
  width: 18px;
  height: 18px;
}

.toggle span {
  margin: 0;
  font-weight: 600;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 6px;
}

button {
  height: 40px;
  border: 0;
  border-radius: 6px;
  color: #fff;
  background: var(--accent);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:hover { background: var(--accent-dark); }

#printBtn {
  background: #42505c;
}

#printBtn:hover {
  background: #2d3740;
}

.sheet {
  margin: 24px;
  padding: 28px 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 12px 32px rgba(23, 32, 42, .06);
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 16px;
  border-bottom: 2px solid #1b2b35;
}

.sheet-head h2 {
  margin: 0 0 6px;
  font-size: 24px;
  letter-spacing: 0;
}

.sheet-head p {
  margin: 0;
  color: var(--muted);
}

.student-fields {
  min-width: 260px;
  display: grid;
  align-content: start;
  gap: 8px;
  color: #2d3a45;
  font-weight: 600;
}

.exercise-list {
  margin: 22px 0 0;
  padding-right: 24px;
  padding-left: 0;
}

.exercise-item {
  padding: 12px 0 16px;
  border-bottom: 1px solid #edf1f4;
}

.exercise-item:last-child {
  border-bottom: 0;
}

.prompt {
  margin-bottom: 8px;
  font-size: 17px;
}

.math {
  direction: ltr;
  unicode-bidi: isolate;
  display: inline-block;
}

.answer {
  display: none;
  margin: 8px 0 0;
  padding: 8px 10px;
  border-right: 3px solid var(--accent);
  background: #f3fafb;
  color: #19343b;
}

.solution-steps {
  margin: 8px 0 0;
  padding-right: 24px;
  padding-left: 0;
}

.solution-steps li {
  margin: 5px 0;
}

body.show-corrections .answer {
  display: block;
}

@media (max-width: 880px) {
  .app-shell {
    display: block;
  }

  .toolbar {
    border-left: 0;
    border-bottom: 1px solid var(--line);
  }

  .sheet {
    margin: 14px;
    padding: 20px 16px;
  }

  .sheet-head {
    display: grid;
  }
}

/* Format de la feuille. Sans cette regle, le navigateur imprime au format par
   defaut de sa locale — souvent Letter — avec ses marges larges, et la mise en
   page prevue pour l'A4 deborde. */
@page {
  size: A4;
  margin: 10mm;
}

@media print {
  body {
    background: #fff;
  }

  .app-shell {
    display: block;
  }

  .toolbar {
    display: none;
  }

  .sheet {
    margin: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
  }

  .exercise-item {
    break-inside: avoid;
  }
}
