/* GutQuest — bio-illustration douce, didactique chaud */
:root {
  --crème: #FBF5E9;
  --crème-fonce: #F5EAD1;
  --epi: #E9A3A0;
  --epi-fonce: #D17773;
  --mucus: #C9E4D0;
  --firm: #3F8A6E;
  --bact: #2A6F8C;
  --verru: #7B5EA7;
  --actin: #D4A24C;
  --proteo: #C0463B;
  --cdiff: #8B1A1A;
  --encre: #1F2937;
  --encre-doux: #475569;
  --teal: #0F766E;
  --teal-fonce: #0B5C56;
  --panel: #FFFDF7;
  --panel-edge: #E8E0CC;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--encre);
  background: var(--crème);
  font-feature-settings: 'tnum' 1;
}

#app {
  display: grid;
  grid-template-rows: 64px 1fr;
  height: 100vh;
  width: 100vw;
}

/* ===== TOPBAR ===== */
#topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-edge);
  box-shadow: 0 1px 3px rgba(31,41,55,0.04);
  z-index: 10;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand h1 {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 22px;
  margin: 0;
  letter-spacing: -0.01em;
  color: var(--encre);
}
#hud {
  flex: 1;
  display: flex;
  gap: 14px;
  align-items: center;
  overflow-x: auto;
  scrollbar-width: thin;
}
.hud-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 4px 12px;
  border-right: 1px solid var(--panel-edge);
  min-width: 70px;
}
.hud-item:last-child { border-right: none; }
.hud-label {
  font-size: 11px;
  color: var(--encre-doux);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.hud-value {
  font-family: 'Fraunces', serif;
  font-size: 18px;
  font-weight: 600;
  font-feature-settings: 'tnum' 1;
}
.topright { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 34px; height: 34px;
  border-radius: 999px;
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  cursor: pointer;
  font-size: 16px;
  color: var(--encre);
  transition: all 150ms;
}
.icon-btn:hover { background: var(--crème-fonce); transform: translateY(-1px); }
.mode-switch {
  display: flex;
  background: var(--crème-fonce);
  border-radius: 999px;
  padding: 3px;
  border: 1px solid var(--panel-edge);
}
.mode-btn {
  border: none;
  background: transparent;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 999px;
  color: var(--encre-doux);
  font-family: inherit;
}
.mode-btn.active {
  background: var(--teal);
  color: white;
  box-shadow: 0 1px 3px rgba(15,118,110,0.3);
}

/* ===== MAIN ===== */
#main {
  display: grid;
  grid-template-columns: 300px 1fr 280px;
  gap: 14px;
  padding: 14px;
  min-height: 0;
  background: linear-gradient(180deg, #F5EAD1 0%, #FBF5E9 60%);
}
.panel {
  background: var(--panel);
  border-radius: 12px;
  border: 1px solid var(--panel-edge);
  padding: 14px;
  box-shadow: 0 2px 10px rgba(31,41,55,0.04);
  overflow-y: auto;
}
.panel.left { padding: 12px; }
.panel.right h3 {
  font-family: 'Fraunces', serif;
  font-size: 14px;
  font-weight: 600;
  margin: 14px 0 8px;
  color: var(--encre);
}
.panel.right h3:first-child { margin-top: 0; }

/* ===== CANVAS ===== */
#canvas-wrap {
  position: relative;
  background: var(--crème);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--panel-edge);
  box-shadow: 0 2px 14px rgba(31,41,55,0.06);
  min-height: 0;
}
#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}
#time-controls {
  position: absolute;
  bottom: 14px;
  right: 14px;
  display: flex;
  gap: 6px;
  background: rgba(255,253,247,0.93);
  padding: 6px;
  border-radius: 10px;
  border: 1px solid var(--panel-edge);
  backdrop-filter: blur(4px);
  box-shadow: 0 4px 12px rgba(31,41,55,0.08);
}
.time-btn {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 11px;
  border-radius: 7px;
  cursor: pointer;
  color: var(--encre);
  transition: all 120ms;
}
.time-btn:hover { background: var(--crème-fonce); }
.time-btn.active { background: var(--teal); color: white; }

/* ===== TABS ===== */
.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  background: var(--crème-fonce);
  padding: 3px;
  border-radius: 8px;
  margin-bottom: 12px;
}
.tab {
  border: none;
  background: transparent;
  padding: 6px 4px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 5px;
  color: var(--encre-doux);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tab.active {
  background: white;
  color: var(--encre);
  box-shadow: 0 1px 3px rgba(31,41,55,0.08);
}

/* ===== SLIDERS / TOGGLES ===== */
.slider {
  margin-bottom: 12px;
}
.slider label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--encre);
}
.slider .val {
  color: var(--teal);
  font-weight: 600;
  font-feature-settings: 'tnum' 1;
}
input[type="range"] {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  background: linear-gradient(90deg, var(--teal), var(--actin));
  border-radius: 999px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  background: white;
  border: 2px solid var(--teal);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px;
  background: white;
  border: 2px solid var(--teal);
  border-radius: 50%;
  cursor: pointer;
}
.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}
.toggle input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--teal);
}

/* ===== INTERVENTIONS DIVERS ===== */
.atb-select {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--panel-edge);
  border-radius: 7px;
  font-family: inherit;
  font-size: 13px;
  background: white;
  margin-bottom: 8px;
}
.atb-desc {
  font-size: 11px;
  color: var(--encre-doux);
  margin: 4px 0 10px;
  line-height: 1.5;
}
.btn-primary {
  background: var(--teal);
  color: white;
  border: none;
  padding: 10px 14px;
  border-radius: 8px;
  font-family: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  width: 100%;
  transition: all 150ms;
}
.btn-primary:hover { background: var(--teal-fonce); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-secondary {
  background: transparent;
  color: var(--encre);
  border: 1px solid var(--panel-edge);
  padding: 9px 14px;
  border-radius: 8px;
  font-family: inherit;
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
}
.btn-secondary:hover { background: var(--crème-fonce); }
.btn-small {
  background: var(--teal);
  color: white;
  border: none;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
}
.btn-small:hover:not(.disabled):not(:disabled) { background: var(--teal-fonce); }
.btn-small.disabled,
.btn-small:disabled {
  background: #c8c2b3;
  cursor: not-allowed;
}
.pro-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--panel-edge);
}
.pro-row:last-child { border-bottom: none; }
.pro-row.fmt { background: #FAF3E0; padding: 10px 8px; border-radius: 7px; margin-top: 6px; border: none; }
.pro-info { flex: 1; min-width: 0; }
.pro-info strong { font-size: 12px; display: block; line-height: 1.35; }
.pro-info p { font-size: 10.5px; margin: 2px 0 0; color: var(--encre-doux); line-height: 1.45; }
.note { padding: 8px; border-radius: 6px; font-size: 12px; margin-bottom: 10px; }
.note.warn { background: #FFF4E6; border-left: 3px solid var(--actin); color: var(--encre); }

/* ===== LÉGENDE ===== */
.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  margin-bottom: 5px;
  line-height: 1.35;
}
.swatch {
  width: 14px; height: 14px;
  border-radius: 4px;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.05);
}
.sparkline {
  width: 100%;
  border-radius: 6px;
  border: 1px solid var(--panel-edge);
  margin-bottom: 6px;
  background: #FCF8EE;
}
.expert-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.expert-grid > div {
  background: var(--crème-fonce);
  padding: 6px 8px;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
}
.expert-grid .k { font-size: 10px; color: var(--encre-doux); text-transform: uppercase; letter-spacing: 0.04em; }
.expert-grid .v { font-family: 'Fraunces', serif; font-weight: 600; font-size: 16px; }

/* ===== TOOLTIP ===== */
.tooltip {
  position: fixed;
  background: white;
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 8px 22px rgba(31,41,55,0.18);
  max-width: 260px;
  pointer-events: none;
  z-index: 100;
  font-size: 12px;
  line-height: 1.5;
}
.tip-head {
  border-left: 3px solid #ccc;
  padding-left: 8px;
  margin-bottom: 6px;
}
.tip-head strong {
  display: block;
  font-family: 'Fraunces', serif;
  font-size: 13px;
}
.tip-phylum {
  font-size: 10px;
  color: var(--encre-doux);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.tip-role, .tip-sub { margin: 0 0 4px; color: var(--encre); }
.tip-sub em { color: var(--encre-doux); font-style: normal; font-weight: 600; }
.tip-ref { margin: 6px 0 0; font-size: 11px; color: var(--teal); font-style: italic; }

/* ===== MODALE ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(31,41,55,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(3px);
  animation: fadeIn 200ms;
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
.modal-card {
  background: var(--panel);
  border-radius: 16px;
  padding: 28px;
  max-width: 560px;
  width: calc(100% - 32px);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(31,41,55,0.25);
}
.modal-card h2 {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 26px;
  margin: 0 0 14px;
  line-height: 1.15;
  letter-spacing: -0.01em;
}
.modal-body, .modal-card .lead {
  font-size: 15px;
  line-height: 1.6;
  margin: 0 0 12px;
  color: var(--encre);
}
.modal-card .lead { color: var(--encre); }
.modal-card .hint {
  background: var(--crème-fonce);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--encre-doux);
  margin: 16px 0 0;
}
.modal-card .learn {
  background: #EFF6F4;
  border-left: 3px solid var(--teal);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.55;
}
.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.home-modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 18px 0;
}
.big-btn {
  background: var(--crème-fonce);
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  padding: 16px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: all 200ms;
}
.big-btn:hover {
  background: white;
  border-color: var(--teal);
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(15,118,110,0.12);
}
.big-btn strong {
  font-family: 'Fraunces', serif;
  font-size: 18px;
  display: block;
  margin-bottom: 4px;
}
.big-btn span {
  font-size: 12.5px;
  color: var(--encre-doux);
  line-height: 1.45;
}

.mission-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 8px 0;
}
.mission-card {
  background: var(--crème-fonce);
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  padding: 12px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  position: relative;
  transition: all 180ms;
}
.mission-card:hover {
  background: white;
  border-color: var(--teal);
  transform: translateY(-2px);
}
.mission-card strong {
  font-family: 'Fraunces', serif;
  font-size: 16px;
  display: block;
  margin: 4px 0;
}
.mission-card p {
  font-size: 11.5px;
  color: var(--encre-doux);
  margin: 0;
  line-height: 1.5;
}
.m-niveau {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.m-niveau.dec { background: #D5E9DD; color: var(--firm); }
.m-niveau.exp { background: #EADDF4; color: var(--verru); }

.glossaire { max-height: 60vh; overflow-y: auto; }
.gloss-row {
  padding: 8px 0;
  border-bottom: 1px solid var(--panel-edge);
}
.gloss-row strong {
  font-family: 'Fraunces', serif;
  font-size: 15px;
  display: block;
  color: var(--teal);
  margin-bottom: 3px;
}
.gloss-row p {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
}

/* ===== MOBILE ===== */
@media (max-width: 900px) {
  #app { grid-template-rows: auto 1fr; height: auto; min-height: 100vh; overflow: visible; }
  html, body { overflow: auto; height: auto; }
  #topbar {
    flex-wrap: wrap;
    padding: 8px 10px;
    height: auto;
    gap: 8px;
  }
  .brand h1 { font-size: 18px; }
  #hud {
    order: 3;
    width: 100%;
    gap: 4px;
    padding-top: 8px;
    border-top: 1px solid var(--panel-edge);
    flex-wrap: wrap;
    overflow-x: visible;
  }
  .hud-item {
    min-width: 0;
    padding: 2px 6px;
    flex: 1 1 25%;
    border-right: 1px solid var(--panel-edge);
  }
  .hud-label { font-size: 9px; }
  .hud-value { font-size: 13px; }
  .topright { gap: 4px; }
  .icon-btn { width: 30px; height: 30px; font-size: 13px; }
  .mode-btn { padding: 4px 10px; font-size: 11px; }
  #main {
    grid-template-columns: 1fr;
    grid-template-rows: 300px auto auto;
    padding: 8px;
    gap: 8px;
    height: auto;
  }
  .panel { max-height: none; }
  .panel.left, .panel.right { max-height: 60vh; }
  #canvas-wrap { order: -1; min-height: 300px; }
  .home-modes, .mission-list { grid-template-columns: 1fr; }
  .modal-card { padding: 20px; }
  .modal-card h2 { font-size: 22px; }
  .time-btn { font-size: 10.5px; padding: 6px 7px; }
  #time-controls { gap: 4px; padding: 5px; right: 8px; bottom: 8px; }
}
