/* SPDX-FileCopyrightText: 2026 Célia Piquet */
/* SPDX-License-Identifier: GPL-3.0-or-later */

/* ═══════════════════════════════════════════
   SQLStory - Thème « Polar de nuit »
═══════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Fonds, du plus profond au plus clair */
  --bg:        #0e1320;
  --moon:      #1a2440;
  --inset:     #0b1019;
  --surface:   #151c2e;
  --surface2:  #1f2942;
  --surface3:  #26314d;

  /* Traits */
  --line:      #222c45;
  --line2:     #2d3b63;

  /* Texte */
  --text:      #e8ecf4;
  --text2:     #b9c3d9;
  --text3:     #8a96b3;

  /* Accents */
  --amber:     #ffb547;
  --amber2:    #ffd08a;
  --amber-bg:  #2b2414;
  --cyan:      #5ad1e6;
  --cyan2:     #8be4f3;
  --cyan-bg:   #12202b;
  --green:     #7ee2a8;
  --green-bg:  #16302a;
  --red:       #ff7a6b;
  --red-bg:    #33191a;

  --font: 'Space Grotesk', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', 'Cascadia Code', Consolas, monospace;
}

html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); }
#app       { height: 100vh; display: flex; flex-direction: column; }

.screen { display: none; flex-direction: column; flex: 1; overflow: hidden; }
.screen.active { display: flex; }
.hidden { display: none !important; }

button:focus-visible, a:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--cyan); outline-offset: 2px;
}

/* ── Boutons ──────────────────────────────── */

.btn-back {
  font-size: .85rem; font-weight: 500; color: var(--text2);
  background: none; border: 1px solid var(--line2);
  border-radius: 8px; padding: 7px 13px; cursor: pointer;
  font-family: var(--font); text-decoration: none;
  transition: background .15s, color .15s;
}
.btn-back:hover { background: var(--surface2); color: var(--text); }

.btn-primary, .btn-secondary {
  padding: 11px 20px; border-radius: 10px; font-size: .95rem; font-weight: 700;
  cursor: pointer; font-family: var(--font);
  text-decoration: none; display: inline-block; transition: background .15s, color .15s;
}
.btn-primary   { background: var(--amber); color: var(--bg); border: none; }
.btn-primary:hover { background: var(--amber2); }
.btn-secondary { background: none; color: var(--text); border: 1px solid var(--line2); }
.btn-secondary:hover { background: var(--surface2); }

/* ══════════════════════════════════════════
   POPUP LIVRE (début de chapitre)
══════════════════════════════════════════ */

.book-modal {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}

.book-overlay {
  position: absolute; inset: 0;
  background: rgba(5, 8, 15, .78);
  backdrop-filter: blur(4px);
}

.book {
  position: relative; z-index: 1;
  width: min(860px, 95vw);
  background: var(--surface);
  border: 1px solid var(--line2);
  border-radius: 18px;
  box-shadow: 0 24px 80px rgba(0,0,0,.6);
  display: flex; flex-direction: column;
  animation: book-open .3s cubic-bezier(.22,.68,0,1.2);
  overflow: hidden;
}
@keyframes book-open {
  from { opacity: 0; transform: translateY(12px) scale(.96); }
  to   { opacity: 1; transform: none; }
}

.book-close {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  background: none; border: 1px solid var(--line2);
  color: var(--text2); border-radius: 50%; width: 34px; height: 34px;
  cursor: pointer; font-size: .9rem; display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.book-close:hover { background: var(--surface2); color: var(--text); }

.book-spread { display: flex; flex: 1; min-height: 360px; }

.book-page { padding: 32px 30px; flex: 1; position: relative; overflow: hidden; }

/* Page gauche : fiche du chapitre */
.book-page-left {
  flex: 0 0 34%;
  background: var(--inset);
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 14px; text-align: center;
}
.book-page-left::before {
  content: ''; position: absolute; width: 260px; height: 260px; border-radius: 50%;
  background: var(--moon); top: -90px; right: -110px; pointer-events: none;
}

.book-ornament { display: none; }

.book-case-label {
  position: relative; z-index: 1;
  font-family: var(--mono); font-size: .72rem; font-weight: 700; letter-spacing: .08em;
  color: var(--amber); border: 1px solid var(--amber);
  padding: 4px 12px; border-radius: 999px; width: fit-content;
}

.book-chapter-num {
  position: relative; z-index: 1;
  font-size: 4rem; font-weight: 700; color: var(--line2);
  line-height: 1; letter-spacing: -2px; user-select: none;
}

.book-chapter-icon  { font-size: 2.6rem; position: relative; z-index: 1; }

.book-chapter-title {
  font-size: 1.2rem; font-weight: 700; color: var(--text);
  position: relative; z-index: 1; line-height: 1.25;
}

.book-concept-badge {
  background: var(--surface2); border-radius: 10px; padding: 9px 16px;
  text-align: center; width: 100%; max-width: 200px; position: relative; z-index: 1;
}
.book-concept-label { display: block; font-size: .7rem; font-weight: 500; color: var(--text3); margin-bottom: 3px; }
.book-concept-badge strong { font-family: var(--mono); font-size: .95rem; color: var(--cyan2); }

.book-page-num-left, .book-page-num-right {
  position: absolute; bottom: 14px;
  font-family: var(--mono); font-size: .72rem; color: var(--text3);
}
.book-page-num-left  { right: 18px; }
.book-page-num-right { left: 30px; }

/* Séparation */
.book-spine { width: 1px; flex-shrink: 0; background: var(--line2); }

/* Page droite : récit */
.book-page-right { display: flex; flex-direction: column; gap: 14px; padding-bottom: 44px; }

.book-chapter-label {
  font-family: var(--mono); font-size: .75rem; font-weight: 500; letter-spacing: .08em;
  color: var(--cyan); text-transform: uppercase;
}
.book-story-title { font-size: 1.6rem; font-weight: 700; color: var(--text); line-height: 1.15; letter-spacing: -.5px; }
.book-story-text  { font-size: 1rem; color: var(--text2); line-height: 1.7; flex: 1; }

.book-mission-box {
  background: var(--amber-bg); border: 1px solid rgba(255,181,71,.35);
  border-radius: 12px; padding: 12px 16px;
}
.book-mission-label { font-family: var(--mono); font-size: .75rem; font-weight: 700; color: var(--amber); margin-bottom: 5px; }
.book-mission-text  { font-size: 1rem; color: var(--text); line-height: 1.5; font-weight: 500; }

.book-footer {
  padding: 14px 30px;
  background: var(--inset);
  border-top: 1px solid var(--line);
  display: flex; justify-content: flex-end; align-items: center;
}

.book-btn-start {
  background: var(--amber); color: var(--bg);
  border: none; border-radius: 10px;
  padding: 12px 24px; font-size: 1rem; font-weight: 700;
  cursor: pointer; font-family: var(--font);
  transition: background .15s;
}
.book-btn-start:hover { background: var(--amber2); }

/* ══════════════════════════════════════════
   CHARGEMENT
══════════════════════════════════════════ */

#screen-loading { background: var(--bg); align-items: center; justify-content: center; position: relative; }
#screen-loading::before {
  content: ''; position: absolute; width: 520px; height: 520px; border-radius: 50%;
  background: var(--moon); top: -180px; right: -140px; pointer-events: none;
}
.load-box { position: relative; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 16px; max-width: 320px; padding: 0 20px; }
.load-logo  { font-size: 2.8rem; font-weight: 700; letter-spacing: -1px; color: var(--text); }
.load-logo span { color: var(--amber); }
.load-sub   { color: var(--text2); font-size: .95rem; }
.load-tip   { color: var(--cyan); font-size: .85rem; font-family: var(--mono); }
.load-bar   { width: 180px; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.load-fill  { height: 100%; width: 0; background: var(--amber); animation: loadpulse 1.6s ease-in-out infinite; }
@keyframes loadpulse { 0%{width:0} 60%{width:75%} 100%{width:100%} }

/* ══════════════════════════════════════════
   ACCUEIL
══════════════════════════════════════════ */

/* Couleurs propres à l'accueil, un peu plus claires que le jeu */
#screen-map {
  --map-bg:      #141c2e;
  --map-panel:   #1b2539;
  --map-module:  #222e48;
  --map-line:    #36496c;
  --map-edge:    #40537a;
  --map-dim:     #94a3c0;
  --map-text2:   #c3cee2;
  --map-led-off: #5a6c90;
  background-color: var(--map-bg);
  background-image: linear-gradient(#5ad1e614 1px, transparent 1px), linear-gradient(90deg, #5ad1e614 1px, transparent 1px);
  background-size: 32px 32px;
  /* Hauteur des livres : les 3 étagères tiennent dans la hauteur de l'écran */
  --bh: clamp(110px, calc((100vh - 150px) / 3 - 74px), 170px);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.map-header {
  padding: 16px 40px; border-bottom: 1px solid #2c3b58; background: #141c2ecc;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-shrink: 0; flex-wrap: wrap;
}
.map-header-l { display: flex; align-items: center; gap: 18px; }
.map-header-r { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.map-header .btn-back { font-family: var(--mono); border-color: var(--map-line); color: var(--map-text2); }
.map-logo { font-family: var(--mono); font-size: 1.4rem; font-weight: 700; color: var(--text); }
.map-logo span, .map-logo i { color: var(--cyan); }
.map-logo i { font-style: normal; animation: map-blink 1.1s steps(1) infinite; }
.map-resume {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  font-family: var(--mono); font-size: .82rem; color: var(--amber2);
  background: none; border: 1px solid var(--amber); border-radius: 6px; padding: 8px 14px;
}
.map-resume:hover { background: var(--amber-bg); }
.btn-reset {
  font-family: var(--mono); font-size: .82rem; color: var(--map-text2, var(--text2));
  background: none; border: 1px solid var(--map-line, var(--line2)); border-radius: 6px;
  padding: 8px 12px; cursor: pointer; transition: background .15s, color .15s;
}
.btn-reset:hover { background: var(--surface2); color: var(--text); }

.map-body { flex: 1; overflow-y: auto; padding: 16px 40px 0; display: flex; flex-direction: column; }
.library { display: flex; flex-wrap: wrap; justify-content: center; gap: 32px; width: 100%; max-width: 1080px; margin: 0 auto 16px; }

/* Baie de stockage : une étagère par niveau */
.rack {
  /* Largeur prévue pour SHELF_SIZE livres (js/game.js) */
  flex: 1 1 520px; max-width: 580px; min-width: 0; align-self: flex-start;
  background: var(--map-panel); border: 1px solid var(--map-line); border-radius: 10px; padding: 6px 20px 14px;
}
.rack-head { display: flex; justify-content: space-between; gap: 12px; font-family: var(--mono); font-size: .7rem; color: var(--map-dim); padding: 6px 0 2px; }
.shelf { padding-top: 10px; }
.shelf-label {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  padding: 0 4px 18px; font-family: var(--mono); font-size: .82rem;
}
.shelf-label b { color: var(--lc); }
.shelf-label > span { color: var(--map-text2); }
.kw { display: flex; flex-wrap: wrap; gap: 6px; }
.kw code {
  font-family: var(--mono); font-size: .7rem; color: var(--map-text2);
  background: var(--map-module); border: 1px solid var(--map-line); padding: 2px 6px; border-radius: 4px;
}
.shelf-books { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 8px; padding: 0 8px; min-height: calc(var(--bh) + 18px); }
.shelf-rail { height: 4px; border-radius: 2px; background: var(--map-line); box-shadow: 0 6px 14px #00000080; }
.shelf-rail { background: color-mix(in srgb, var(--lc) 35%, var(--map-line)); }
.shelf.has-sel .shelf-rail { background: var(--lc); box-shadow: 0 0 12px color-mix(in srgb, var(--lc) 50%, transparent); }

/* Un livre = un module de données */
.spine {
  position: relative; padding: 0; cursor: pointer; color: var(--text);
  background: color-mix(in srgb, var(--c) 30%, var(--map-module));
  border: 1px solid color-mix(in srgb, var(--c) 45%, var(--map-edge)); border-top: 3px solid var(--c);
  border-radius: 6px 6px 2px 2px; height: calc(var(--bh) + var(--dh, 0px));
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  transition: transform .15s, box-shadow .15s;
}
.spine:hover { transform: translateY(-6px); box-shadow: 0 0 14px color-mix(in srgb, var(--c) 45%, transparent); }
.spine.sel { transform: translateY(-14px); border-color: var(--c); box-shadow: 0 0 22px color-mix(in srgb, var(--c) 60%, transparent); }
.spine-ghost {
  cursor: default; background: transparent; color: var(--map-dim);
  border: 1px dashed color-mix(in srgb, var(--lc) 40%, var(--map-line)); border-top-width: 1px;
  opacity: .55;
}
.spine-ghost:hover { transform: none; box-shadow: none; }
.spine-ghost .spine-title { font-style: italic; }
.spine-ghost .spine-foot { background: none; border-top-style: dashed; }
.spine-id { font-family: var(--mono); font-size: .56rem; color: var(--map-text2); padding: 4px 0 2px; }
.spine-title {
  writing-mode: vertical-rl; transform: rotate(180deg); overflow: hidden; flex: 1; min-height: 0;
  font-family: var(--mono); font-size: .72rem; font-weight: 500; line-height: 1.15;
}
.spine-foot { width: 100%; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 5px 0 6px; border-top: 1px solid #00000040; background: #00000030; }
.spine-lv { font-family: var(--mono); font-size: .56rem; color: var(--text); }
.led { width: 8px; height: 8px; border-radius: 50%; background: var(--map-led-off); }
.led.done { background: var(--green); box-shadow: 0 0 8px var(--green); }
.led.run  { background: var(--amber); box-shadow: 0 0 8px var(--amber); animation: map-pulse 1.4s ease-in-out infinite; }

/* Fiche du livre choisi, en fenêtre de terminal */
.story-detail {
  flex: 1 1 320px; max-width: 460px; align-self: center;
  background: var(--map-panel); border: 1px solid var(--map-line); border-radius: 10px; overflow: hidden;
}
.detail-bar {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--map-line);
  font-family: var(--mono); font-size: .75rem; color: var(--map-text2);
}
.detail-bar i { width: 10px; height: 10px; border-radius: 50%; background: var(--map-line); }
.detail-bar span { margin-left: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-body { padding: 22px 24px 26px; display: flex; flex-direction: column; gap: 16px; }
.detail-cmd { font-family: var(--mono); font-size: .75rem; color: var(--map-dim); }
.detail-cmd b { color: var(--cyan); font-weight: 500; }
.detail-tag {
  align-self: flex-start; font-family: var(--mono); font-size: .7rem; font-weight: 700;
  color: var(--bg); background: var(--c); padding: 3px 8px; border-radius: 4px;
}
.detail-body h2 { font-size: 1.85rem; line-height: 1.1; font-weight: 700; }
.detail-place { font-family: var(--mono); font-size: .75rem; color: var(--map-text2); }
.detail-pitch { font-size: .95rem; line-height: 1.55; color: #d6deec; }
.detail-body .kw code { font-size: .75rem; color: var(--text); border-color: color-mix(in srgb, var(--c) 50%, var(--map-line)); }
.detail-prog { display: flex; justify-content: space-between; gap: 12px; font-family: var(--mono); font-size: .82rem; color: var(--map-text2); }
.detail-prog b { color: var(--cyan); font-weight: 500; letter-spacing: -1px; }
.detail-actions { display: flex; align-items: center; gap: 10px; }
.btn-launch {
  font-family: var(--mono); font-weight: 700; font-size: .88rem; cursor: pointer;
  color: var(--bg); background: var(--cyan); border: none; border-radius: 6px; padding: 13px 20px;
}
.btn-launch:hover { background: var(--cyan2); box-shadow: 0 0 16px #5ad1e680; }
.detail-actions .btn-icon { border-radius: 6px; border-color: var(--map-line); color: var(--map-text2); }

@keyframes map-pulse { 50% { opacity: .35; } }
@keyframes map-blink { 50% { opacity: 0; } }

.btn-icon {
  width: 42px; height: 42px; flex-shrink: 0; border-radius: 10px;
  background: none; border: 1px solid var(--line2); color: var(--text2);
  font-size: 1.25rem; line-height: 1; cursor: pointer; font-family: var(--font);
  transition: background .15s, color .15s;
}
.btn-icon:hover { background: var(--surface2); color: var(--text); }

.map-footer {
  text-align: center; padding: 12px 22px; font-family: var(--mono); font-size: .75rem;
  color: var(--map-dim); border-top: 1px solid #2c3b58; flex-shrink: 0; margin: auto -40px 0;
}

/* ══════════════════════════════════════════
   JEU
══════════════════════════════════════════ */

.game-topbar {
  background: var(--bg); border-bottom: 1px solid var(--line);
  padding: 10px 20px; display: flex; align-items: center; gap: 14px; flex-shrink: 0;
}
.game-topbar-center { display: flex; align-items: center; gap: 12px; flex: 1; justify-content: center; min-width: 0; }
.game-logo { font-size: 1.1rem; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.game-level-badge {
  font-family: var(--mono); font-size: .78rem; font-weight: 700; color: var(--bg);
  background: var(--amber); padding: 3px 10px; border-radius: 999px; white-space: nowrap;
}

.zoom-ctrl  { display: flex; align-items: center; border: 1px solid var(--line2); border-radius: 8px; }
.zoom-btn   {
  width: 34px; height: 32px; border: none; border-radius: 7px; background: none;
  color: var(--text2); font-size: 1.1rem; font-weight: 700; line-height: 1; cursor: pointer; font-family: var(--font);
}
.zoom-btn:hover    { background: var(--surface2); color: var(--text); }
.zoom-btn:disabled { opacity: .3; cursor: default; background: none; }
.zoom-label { min-width: 46px; text-align: center; font-size: .78rem; color: var(--text2); font-family: var(--mono); }

.game-topbar-prog   { width: 110px; }
.game-prog-track    { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.game-prog-fill     { height: 100%; background: var(--cyan); transition: width .4s ease; }

.game-layout { flex: 1; display: flex; overflow: hidden; }

.right-panel {
  flex: 1; background: var(--bg);
  background-image: radial-gradient(var(--line) 1px, transparent 1px);
  background-size: 28px 28px;
  display: flex; flex-direction: column; overflow: hidden;
}

.game-field { flex: 1; position: relative; overflow: hidden; }

.draggable-panel { position: absolute; user-select: none; transform-origin: top left; }

#handle-tablet, #handle-result { cursor: grab; }
#handle-tablet:active, #handle-result:active { cursor: grabbing; }

#panel-tablet { width: fit-content; }
#panel-result { width: fit-content; }

/* ── Accordéon des tables ────────────────── */

.accordion { flex: 1; overflow-y: auto; }
.acc-item { border-bottom: 1px solid var(--line); }

.acc-header {
  width: 100%; background: none; border: none; cursor: pointer;
  padding: 9px 18px; display: flex; align-items: center; gap: 9px;
  font-family: var(--font); text-align: left; transition: background .12s;
}
.acc-header:hover { background: var(--surface2); }

.acc-arrow { font-size: .7rem; color: var(--text3); flex-shrink: 0; transition: transform .2s ease; display: inline-block; }
.acc-item.open .acc-arrow { transform: rotate(90deg); color: var(--cyan); }

.acc-name  { font-family: var(--mono); font-size: .9rem; font-weight: 700; color: var(--cyan2); flex: 1; }
.acc-count { font-family: var(--mono); font-size: .75rem; color: var(--text3); flex-shrink: 0; }

/* Marge latérale : les doigts des mains recouvrent les bords de la tablette */
.acc-body { display: none; overflow-x: auto; background: var(--inset); margin: 0 18px 10px; border-radius: 8px; border: 1px solid var(--line); }
.acc-item.open .acc-body { display: block; }

.acc-table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: .78rem; }
.acc-table th {
  background: var(--cyan-bg); padding: 6px 10px; text-align: left;
  font-weight: 700; color: var(--cyan); border-bottom: 1px solid var(--line);
  white-space: nowrap; position: sticky; top: 0;
}
.acc-table td {
  padding: 5px 10px; border-bottom: 1px solid var(--line);
  color: var(--text); white-space: nowrap; cursor: pointer;
  max-width: 130px; overflow: hidden; text-overflow: ellipsis;
}
.acc-table tr:hover td       { background: var(--surface); }
.acc-table tr:hover td:hover,
.acc-table td:hover          { background: var(--amber-bg); color: var(--amber); }
.acc-null { color: var(--text3); font-style: italic; }

/* ── Touches (chips) ─────────────────────── */

.chip-palette {
  padding: 10px 18px; display: flex; flex-direction: column; gap: 6px; flex-shrink: 0;
}
.chip-row { display: flex; align-items: flex-start; gap: 6px; }
.chip-row-label { display: none; }
.chip-group { display: flex; flex-wrap: wrap; gap: 5px; }

.chip {
  font-family: var(--mono); font-size: .85rem; font-weight: 700;
  color: var(--text); background: var(--surface3);
  border: 1px solid transparent; border-radius: 8px; padding: 6px 11px;
  cursor: pointer; user-select: none;
  transition: background .12s, transform .08s;
}
.chip:hover  { background: #33406a; }
.chip:active { transform: translateY(1px); }

.chip.is-new {
  background: none; color: var(--amber); border: 1.5px dashed var(--amber);
  animation: chip-glow 1.5s ease-in-out 3;
}
.chip.is-new:hover { background: var(--amber-bg); }
@keyframes chip-glow {
  0%,100% { box-shadow: 0 0 0 0 rgba(255,181,71,0); }
  50%      { box-shadow: 0 0 0 4px rgba(255,181,71,.18); }
}

.chip-table       { background: #173a4a; color: var(--cyan2); }
.chip-table:hover { background: #1d4a5e; }
.chip-col         { background: #1d3b2c; color: #8fe9b5; }
.chip-col:hover   { background: #254c38; }
.chip-combo       { background: #2b2650; color: #c9bcff; font-size: .78rem; }
.chip-combo:hover { background: #363063; }
.chip-extra       { background: #3d2a17; color: var(--amber2); }
.chip-extra:hover { background: #4d361d; }

/* ══════════════════════════════════════════
   TABLETTE - Conteneur + Mains
══════════════════════════════════════════ */

.tablet-section { flex-shrink: 0; display: flex; justify-content: center; }

.tablet-wrap {
  display: flex; align-items: center;
}

.tablet-hand {
  width: 48px; min-width: 48px; height: 260px; align-self: center;
  flex-shrink: 0; position: relative; z-index: 2;
}
.tablet-hand-left  { margin-right: -14px; }
.tablet-hand-right { margin-left: -14px; transform: scaleX(-1); }

/* Redimensionnable par le coin bas droit, comme le panneau des résultats */
.tablet-frame {
  flex: 0 0 auto; width: 712px; height: 580px;
  min-width: 520px; min-height: 420px; resize: both;
  background: var(--surface);
  border: 1px solid var(--line2);
  border-radius: 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  overflow: hidden; position: relative; z-index: 1;
  display: flex; flex-direction: column;
}

/* Défilement sans barre visible dans toute la tablette */
.tablet-frame, .tablet-frame * { scrollbar-width: none; }
.tablet-frame ::-webkit-scrollbar { display: none; }

/* ── Barre de statut ─────────────────────── */

.tablet-statusbar {
  padding: 7px 24px;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.ts-app { font-family: var(--mono); font-size: .72rem; font-weight: 500; letter-spacing: .06em; color: var(--text3); text-transform: uppercase; }
.ts-app #ts-level { color: var(--text3); }
.ts-right { display: flex; align-items: center; gap: 4px; }
.ts-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--line2); }
.ts-dot.active { background: var(--cyan); }
.ts-sep { width: 1px; height: 9px; background: var(--line2); margin: 0 3px; }
.ts-battery { font-family: var(--mono); font-size: .72rem; color: var(--text3); letter-spacing: -1px; }

/* ── Zone de contenu à onglets ───────────── */

.tablet-content { flex: 1; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.tab-pane { display: none; flex-direction: column; flex: 1; overflow-y: auto; min-height: 0; }
.tab-pane.active { display: flex; }

/* ── En-tête mission ─────────────────────── */

.mission-terminal {
  flex-shrink: 0; margin: 0 18px;
  background: var(--inset); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 16px 11px;
}
.term-topline { display: flex; align-items: center; gap: 9px; margin-bottom: 4px; flex-wrap: wrap; }
.term-prompt { font-family: var(--mono); font-size: .9rem; color: var(--cyan); }
.term-badge {
  font-family: var(--mono); font-size: .72rem; font-weight: 700;
  color: var(--text3); border: 1px solid var(--line2); padding: 1px 7px; border-radius: 6px;
}
.term-mission-title { font-size: 1.05rem; font-weight: 700; color: var(--text); flex: 1; }
.term-concept {
  font-family: var(--mono); font-size: .75rem; font-weight: 500;
  color: var(--amber); border: 1px solid var(--amber); padding: 2px 8px; border-radius: 6px;
}
.term-objective { font-size: .95rem; color: var(--text2); line-height: 1.45; }

/* ── Éditeur SQL ─────────────────────────── */

#sql-editor-view { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.sql-editor {
  width: auto; flex: 1; min-height: 90px; max-height: 180px; margin: 8px 18px 0;
  padding: 11px 14px; font-family: var(--mono); font-size: 1rem;
  border: 1px solid var(--line2); border-radius: 12px; outline: none; resize: none;
  background: var(--inset); color: var(--text); line-height: 1.55;
  caret-color: var(--amber); flex-shrink: 0;
}
.sql-editor:focus { border-color: var(--cyan); }
.sql-editor::placeholder { color: var(--text3); }

.sql-actions {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  padding: 8px 18px; flex-shrink: 0;
}
.btn-clear {
  width: 38px; height: 38px; font-size: .9rem; font-weight: 700; color: var(--text2);
  background: none; border: 1px solid var(--line2); border-radius: 10px; cursor: pointer;
  font-family: var(--font); transition: color .15s, border-color .15s;
}
.btn-clear:hover { color: var(--red); border-color: var(--red); }

.btn-run {
  height: 38px; background: var(--amber); color: var(--bg); border: none; border-radius: 10px;
  padding: 0 18px; font-size: .95rem; font-weight: 700; cursor: pointer;
  font-family: var(--font); transition: background .15s; white-space: nowrap;
}
.btn-run kbd { font-family: var(--mono); font-size: .7rem; margin-left: 6px; background: rgba(14,19,32,.15); padding: 1px 5px; border-radius: 4px; }
.btn-run:hover { background: var(--amber2); }

.tablet-msg {
  margin: 0 18px 8px; padding: 8px 12px; border-radius: 10px;
  font-family: var(--mono); font-size: .82rem; line-height: 1.4; flex-shrink: 0;
}
.tablet-msg-error { background: var(--red-bg); border: 1px solid rgba(255,122,107,.4); color: #ffb3a9; }

/* ── Onglet Base ─────────────────────────── */

.tab-base-header {
  padding: 4px 18px 10px;
  display: flex; align-items: baseline; gap: 10px; flex-shrink: 0;
}
.tab-base-title { font-size: 1rem; font-weight: 700; color: var(--text); }
.tab-base-hint  { font-size: .8rem; color: var(--text3); }

/* ── Onglets Aide et Histoire ────────────── */

.aide-pane { padding: 6px 18px 16px; display: flex; flex-direction: column; gap: 12px; }
.aide-header { display: flex; align-items: center; gap: 12px; }
.aide-icon-big { font-size: 1.7rem; }
.aide-title    { font-size: 1.05rem; font-weight: 700; color: var(--text); }
.aide-subtitle { font-family: var(--mono); font-size: .78rem; color: var(--text3); margin-top: 2px; }
.aide-text {
  font-size: .95rem; color: var(--text); line-height: 1.6;
  background: var(--amber-bg); border: 1px solid rgba(255,181,71,.3);
  padding: 12px 14px; border-radius: 12px;
}
.aide-shortcuts { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.aide-shortcut-row { font-size: .82rem; color: var(--text2); display: flex; align-items: center; gap: 6px; }
.aide-shortcut-row kbd {
  background: var(--surface2); border: 1px solid var(--line2);
  border-radius: 5px; padding: 1px 6px; font-family: var(--mono); font-size: .75rem; color: var(--text);
}

.histoire-text { font-size: .98rem; line-height: 1.7; color: var(--text2); }
.histoire-mission-label { display: block; margin-bottom: 4px; font-family: var(--mono); font-size: .8rem; color: var(--amber); }

/* ── Barre de navigation ─────────────────── */

.tablet-navbar {
  display: flex; gap: 6px; padding: 8px; background: var(--inset); flex-shrink: 0;
}
.nav-tab {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 7px;
  height: 42px; background: none; border: none; border-radius: 10px;
  cursor: pointer; font-family: var(--font); transition: background .12s;
}
.nav-tab:hover  { background: var(--surface); }
.nav-tab.active { background: var(--surface3); }
.nav-icon  { font-size: 1rem; line-height: 1; }
.nav-label { font-size: .88rem; font-weight: 700; color: var(--text3); }
.nav-tab:hover .nav-label, .nav-tab.active .nav-label { color: var(--text); }

/* ── Panneau résultat ────────────────────── */

.result-matrix {
  width: 650px; height: 580px; min-width: 220px; min-height: 140px;
  background: var(--inset);
  border: 1px solid var(--cyan); border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
  display: flex; flex-direction: column; overflow: hidden;
  resize: both;
}
.tablet-frame::-webkit-resizer { background: linear-gradient(135deg, transparent 60%, var(--amber) 60%); }
.result-matrix::-webkit-resizer { background: linear-gradient(135deg, transparent 60%, var(--cyan) 60%); }

.matrix-topbar {
  background: var(--cyan-bg); padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
}
.matrix-prompt { font-family: var(--mono); font-size: .85rem; font-weight: 700; color: var(--cyan); }
.matrix-count  { font-family: var(--mono); font-size: .8rem; color: var(--text3); }

.matrix-scroll { overflow-y: auto; flex: 1; scrollbar-width: thin; scrollbar-color: var(--line2) transparent; }

.matrix-table { width: 100%; border-collapse: collapse; font-family: var(--mono); }
.matrix-table th {
  font-size: .8rem; font-weight: 700; color: var(--cyan);
  background: var(--inset); padding: 9px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left; white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
}
.matrix-table td {
  font-size: .88rem; color: var(--text);
  padding: 7px 16px; border-bottom: 1px solid #172033;
  white-space: normal; word-break: break-word;
}
.matrix-table tr:hover td { background: var(--surface); }
.matrix-null { color: var(--text3) !important; font-style: italic; }

/* ══════════════════════════════════════════
   QUIZ (onglet SQL après succès)
══════════════════════════════════════════ */

#quiz-view { display: flex; flex-direction: column; flex: 1; overflow-y: auto; min-height: 0; }

.quiz-header {
  display: flex; align-items: center; gap: 12px;
  margin: 0 18px; padding: 10px 16px;
  background: var(--green-bg); border: 1px solid rgba(126,226,168,.3); border-radius: 12px;
  flex-shrink: 0;
}
.quiz-header-icon  { font-size: 1.4rem; flex-shrink: 0; }
.quiz-header-title { font-size: 1rem; font-weight: 700; color: var(--green); }
.quiz-header-sub   { font-size: .82rem; color: var(--text2); margin-top: 1px; }

.quiz-query-box {
  margin: 8px 18px 0; padding: 6px 12px; flex-shrink: 0;
  background: var(--inset); border: 1px solid var(--line2); border-radius: 10px;
}
.quiz-query-label { display: block; font-size: .72rem; color: var(--text3); margin-bottom: 3px; }
.quiz-query {
  font-family: var(--mono); font-size: .8rem; line-height: 1.45; color: var(--text);
  white-space: pre-wrap; word-break: break-word; max-height: 4.4em; overflow-y: auto;
}

/* Les questions gardent leur hauteur : c'est tout le quiz qui défile */
.quiz-questions-container {
  flex: 1 0 auto; padding: 12px 18px; display: flex; flex-direction: column; gap: 14px;
}

.quiz-question { display: flex; flex-direction: column; gap: 6px; }
.quiz-q-num  { font-family: var(--mono); font-size: .75rem; color: var(--text3); }
.quiz-q-text { font-size: .95rem; font-weight: 500; color: var(--text); line-height: 1.45; padding-left: 18px; position: relative; }
.quiz-q-text::before { content: '?'; position: absolute; left: 0; color: var(--cyan); font-weight: 700; }

.quiz-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

.quiz-choice {
  background: var(--surface2); border: 1px solid transparent; border-radius: 10px;
  padding: 9px 12px; font-family: var(--font); font-size: .9rem; color: var(--text);
  cursor: pointer; text-align: left; transition: background .1s, border-color .1s, color .1s;
}
.quiz-choice:hover { background: var(--surface3); }
.quiz-choice.selected       { background: var(--amber-bg); border-color: var(--amber); color: var(--amber2); }
.quiz-choice.correct-answer { background: var(--green-bg); border-color: var(--green); color: var(--green); }
.quiz-choice.wrong-answer   { background: var(--red-bg);   border-color: var(--red);   color: #ffb3a9; }

.quiz-question.q-correct .quiz-q-text { color: var(--green); }
.quiz-question.q-correct .quiz-q-text::before { content: '✓'; color: var(--green); }
.quiz-question.q-wrong   .quiz-q-text { color: #ffb3a9; }
.quiz-question.q-wrong   .quiz-q-text::before { content: '✗'; color: var(--red); }

.quiz-footer {
  position: sticky; bottom: 0; background: var(--surface);
  padding: 8px 18px 10px;
  display: flex; flex-direction: column; gap: 7px; flex-shrink: 0;
}

#quiz-feedback-bar { font-family: var(--mono); font-size: .82rem; padding: 8px 12px; border-radius: 10px; border: 1px solid transparent; }
#quiz-feedback-bar.quiz-ok   { background: var(--green-bg); border-color: rgba(126,226,168,.4); color: var(--green); }
#quiz-feedback-bar.quiz-err  { background: var(--red-bg);   border-color: rgba(255,122,107,.4); color: #ffb3a9; }
#quiz-feedback-bar.quiz-warn { background: var(--amber-bg); border-color: rgba(255,181,71,.4); color: var(--amber2); }

.btn-quiz-validate {
  height: 40px; background: var(--amber); color: var(--bg); border: none; border-radius: 10px;
  padding: 0 18px; font-size: .95rem; font-weight: 700; cursor: pointer;
  font-family: var(--font); transition: background .15s, opacity .15s;
}
.btn-quiz-validate:disabled { opacity: .35; cursor: not-allowed; }
.btn-quiz-validate:not(:disabled):hover { background: var(--amber2); }

/* ══════════════════════════════════════════
   VICTOIRE
══════════════════════════════════════════ */

#screen-victory { background: var(--bg); align-items: center; justify-content: center; position: relative; }
#screen-victory::before {
  content: ''; position: absolute; width: 520px; height: 520px; border-radius: 50%;
  background: var(--moon); top: -180px; right: -140px; pointer-events: none;
}
.victory-wrap { position: relative; display: flex; align-items: center; gap: 36px; max-width: 700px; padding: 32px 24px; flex-wrap: wrap; justify-content: center; }
.victory-content { text-align: center; flex: 1; min-width: 260px; }
.victory-stamp {
  display: inline-block; font-family: var(--mono); font-size: .8rem; font-weight: 700;
  color: var(--green); border: 1px solid var(--green); padding: 4px 12px; border-radius: 999px; margin-bottom: 16px;
}
.victory-content h1 { font-size: 2.6rem; font-weight: 700; letter-spacing: -1px; color: var(--text); margin-bottom: 12px; }
.victory-content p  { color: var(--text2); font-size: 1.05rem; line-height: 1.6; margin-bottom: 20px; }
.victory-content strong { color: var(--amber); }
.victory-content code { background: var(--surface2); color: var(--cyan2); padding: 1px 6px; border-radius: 4px; font-family: var(--mono); font-size: .9rem; }
.victory-skills { display: flex; gap: 7px; justify-content: center; flex-wrap: wrap; margin-bottom: 24px; }
.victory-skills span { font-family: var(--mono); font-size: .82rem; font-weight: 700; color: var(--green); background: var(--green-bg); padding: 5px 10px; border-radius: 6px; }
.victory-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ══════════════════════════════════════════
   TUTORIEL (js/tutorial.js)
══════════════════════════════════════════ */

#tuto-spot {
  position: fixed; z-index: 2000; pointer-events: none;
  border: 2px solid var(--cyan); border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(5, 8, 15, .62), 0 0 18px #5ad1e680;
  transition: left .2s, top .2s, width .2s, height .2s;
}
#tuto-bubble {
  position: fixed; z-index: 2001; width: min(340px, calc(100vw - 16px));
  background: var(--surface); border: 1px solid var(--cyan); border-radius: 12px;
  padding: 14px 16px; display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 10px 30px #00000080;
}
.tuto-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.tuto-head span { font-family: var(--mono); font-size: .72rem; font-weight: 700; color: var(--cyan); }
.tuto-skip {
  font-family: var(--mono); font-size: .72rem; color: var(--text3);
  background: none; border: none; cursor: pointer; text-decoration: underline;
}
.tuto-skip:hover { color: var(--text); }
.tuto-text { font-size: .95rem; line-height: 1.5; color: var(--text); }
.tuto-text code, .tuto-text kbd {
  font-family: var(--mono); font-size: .85em; color: var(--amber);
  background: var(--inset); padding: 1px 5px; border-radius: 4px;
}
.tuto-next {
  align-self: flex-end; font-family: var(--font); font-weight: 700; font-size: .9rem;
  color: var(--bg); background: var(--cyan); border: none; border-radius: 8px;
  padding: 8px 16px; cursor: pointer;
}
.tuto-next:hover { background: var(--cyan2); }
.tuto-shake { animation: tuto-shake .35s; }
@keyframes tuto-shake {
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* ══════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════ */

@media (max-width: 860px) {
  .tablet-frame { max-width: 86vw; }
  .book-spread { flex-direction: column; }
  .book-page-left { flex-basis: auto; }
  .book-spine { width: auto; height: 1px; }
}
@media (max-width: 540px) {
  .tablet-hand { display: none; }
  .tablet-hand-left  { margin-right: 0; }
  .tablet-hand-right { margin-left: 0; }
  .tablet-wrap  { width: 100%; }
  .tablet-frame { width: 100%; height: auto; min-width: 0; resize: none; border-radius: 14px; }
  .tablet-section { padding: 8px 8px 0; }
  .map-header, .map-body { padding-left: 16px; padding-right: 16px; }
  .map-footer { margin: auto -16px 0; }
}
