/* ==========================================================================
   STYLE: SIMULATION 02 - CRÉATURES AQUATIQUES (HYDRODYNAMIQUE 2D)
   Direction Artistique: Institutional Zero-Slop Workbench + Fidélité Vidéo Code BH
   ========================================================================== */

:root {
  --bg-primary: #030e1c;
  --bg-surface: #061629;
  --bg-panel: #0b2038;
  --bg-elevated: #122b48;

  --border-subtle: #173354;
  --border-focus: #00f0ff;

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-cyan: #00f0ff;
  --accent-cyan-glow: rgba(0, 240, 255, 0.25);
  --accent-teal: #2dd4bf;
  --accent-blue: #38bdf8;
  --accent-red: #f87171;
  --accent-green: #22c55e;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

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

html, body {
  width: 100%;
  max-width: 100%;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

/* HEADER BAR */
.workbench-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 14px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  min-height: 50px;
  width: 100%;
  max-width: 100vw;
  gap: 10px;
  flex-wrap: wrap;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-panel);
  transition: all 0.15s ease;
}

.back-link:hover {
  color: var(--text-primary);
  border-color: var(--accent-cyan);
}

.sim-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sim-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  background-color: rgba(0, 240, 255, 0.14);
  color: var(--accent-cyan);
  border: 1px solid rgba(0, 240, 255, 0.32);
}

/* SÉLECTEUR D'ESPÈCES (Header) */
.header-species {
  display: flex;
  align-items: center;
  gap: 6px;
}

.species-label {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 700;
  letter-spacing: 0.05em;
}

.species-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-panel);
  padding: 3px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  overflow-x: auto;
}

.species-tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.species-tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.species-tab.active {
  background: rgba(0, 240, 255, 0.16);
  color: var(--accent-cyan);
  font-weight: 600;
  border-color: rgba(0, 240, 255, 0.4);
}

.header-center {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-group {
  display: inline-flex;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg-panel);
}

.speed-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.speed-btn:hover {
  color: var(--text-primary);
}

.speed-btn.active {
  background: var(--accent-cyan);
  color: #030e1c;
  font-weight: 700;
}

.btn-action {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 9px;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s ease;
}

.btn-action:hover {
  background: var(--bg-elevated);
  border-color: var(--text-secondary);
}

.btn-primary {
  background: rgba(0, 240, 255, 0.15);
  border-color: rgba(0, 240, 255, 0.4);
  color: var(--accent-cyan);
}

.btn-primary:hover {
  background: rgba(0, 240, 255, 0.25);
  border-color: var(--accent-cyan);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.jump-group {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-panel);
  padding: 3px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
}

.jump-group label {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
}

.jump-input {
  width: 48px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 4px;
  border-radius: 3px;
  text-align: center;
}

/* WORKBENCH MAIN LAYOUT */
.workbench-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  height: calc(100vh - 52px);
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
}

.viewport-panel {
  display: flex;
  flex-direction: column;
  position: relative;
  background-color: var(--bg-primary);
  border-right: 1px solid var(--border-subtle);
  min-width: 0;
  width: 100%;
}

/* BARRE D'OBSERVATION CAMÉRA */
.camera-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  overflow-x: auto;
  max-width: 100%;
  min-width: 0;
  scrollbar-width: none;
}
.camera-toolbar::-webkit-scrollbar {
  display: none;
}

.toolbar-label {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 700;
  letter-spacing: 0.05em;
}

.cam-btn {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 9px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.cam-btn:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.cam-btn.active {
  background: rgba(0, 240, 255, 0.16);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
  font-weight: 600;
}

#cam-worst-btn.active {
  background: rgba(248, 113, 113, 0.16);
  border-color: var(--accent-red);
  color: var(--accent-red);
}

.step-creature-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 1px 4px;
}

.step-creature-group .cam-btn {
  border: none;
  padding: 3px 7px;
  background: transparent;
}

.showcase-label {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--accent-cyan);
  padding: 0 4px;
  white-space: nowrap;
}

.canvas-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: grab;
}

.canvas-container:active {
  cursor: grabbing;
}

#simCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* SIDEBAR TÉLÉMÉTRIE */
.sidebar-panel {
  background-color: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  width: 100%;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-secondary);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 4px;
}

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

.metric-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 7px 9px;
}

.metric-card.accent-cyan {
  border-color: rgba(0, 240, 255, 0.35);
  background: rgba(0, 240, 255, 0.05);
}

.metric-header {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}

.metric-value {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.metric-card.accent-cyan .metric-value {
  color: var(--accent-cyan);
}

.chart-box {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 8px;
  height: 128px;
  position: relative;
}

.story-chapters {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.story-chapter-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 7px 9px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.story-chapter-card:hover {
  background: var(--bg-elevated);
  border-color: var(--text-muted);
}

.story-chapter-card.active {
  border-color: var(--accent-cyan);
  background: rgba(0, 240, 255, 0.09);
}

.story-chapter-card .chapter-title {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.story-chapter-card .chapter-desc {
  font-size: 10.5px;
  color: var(--text-secondary);
  line-height: 1.32;
}

/* RESPONSIVE SUR MOBILE (LOCKED 100% WIDTH, CLEAN NAVBAR) */
@media (max-width: 1024px) {
  .workbench-header {
    padding: 6px 10px;
    gap: 5px;
    flex-wrap: wrap;
  }

  .header-left {
    order: 1;
    flex: 1 1 0%;
    min-width: 0;
    gap: 6px;
    overflow: hidden;
  }

  .sim-title {
    min-width: 0;
    overflow: hidden;
  }

  .sim-title span:first-child {
    font-size: 12.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .workbench-header .sim-tag {
    display: none;
  }

  .header-right {
    order: 2;
    flex: 0 0 auto;
    gap: 4px;
  }

  .jump-group {
    padding: 2px 5px;
    gap: 3px;
  }

  .jump-input {
    width: 36px;
    font-size: 10px;
    padding: 2px 3px;
  }

  .header-right .btn-action {
    font-size: 10px;
    padding: 3px 6px;
  }

  .header-species {
    order: 3;
    flex: 0 0 100%;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
    padding-top: 4px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
  }
  .header-species::-webkit-scrollbar,
  .species-tabs::-webkit-scrollbar {
    display: none;
  }

  .species-tabs {
    width: 100%;
    max-width: 100%;
    scrollbar-width: none;
  }

  .species-tab {
    font-size: 10px;
    padding: 3px 7px;
    flex-shrink: 0;
  }

  .species-label {
    display: none;
  }

  .header-center {
    order: 4;
    flex: 0 0 100%;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    display: flex;
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    scrollbar-width: none;
    gap: 5px;
  }
  .header-center::-webkit-scrollbar {
    display: none;
  }

  .header-center .btn-action,
  .header-center .speed-btn {
    font-size: 10px;
    padding: 3px 7px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .workbench-main {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
    height: auto;
    overflow: visible;
  }

  .viewport-panel {
    height: 40vh;
    min-height: 235px;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
  }

  .canvas-container,
  #simCanvas {
    touch-action: pan-y pinch-zoom !important;
  }

  .camera-toolbar {
    padding: 4px 8px;
    gap: 4px;
  }

  .toolbar-label {
    display: none;
  }

  .cam-btn {
    font-size: 9.5px;
    padding: 3px 6px;
    flex-shrink: 0;
  }

  /* Sidebar Mobile : Grille 2 colonnes (KPIs ultra-compacts + 2 Graphes par ligne) */
  .sidebar-panel {
    border-left: none;
    padding: 6px 8px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    overflow: visible;
  }

  .sidebar-section {
    min-width: 0;
    gap: 4px;
  }

  /* Section 1 (KPIs) et Section 4 (Chapitres) prennent toute la largeur ; Sections 2 et 3 (Graphes) sont côte à côte */
  .sidebar-section:first-child,
  .sidebar-section:nth-child(4) {
    grid-column: 1 / -1;
  }

  .section-title {
    font-size: 8.5px;
    padding-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #tracked-desc {
    display: none;
  }

  .sidebar-section:first-child > .metric-card {
    padding: 4px 7px;
    margin-bottom: 4px !important;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
  }

  #tracked-rank-header {
    margin-bottom: 0;
    font-size: 8px;
  }

  #tracked-name {
    font-size: 11px !important;
  }

  .metrics-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
  }

  .metric-card {
    padding: 4px 5px;
    min-width: 0;
  }

  .metric-header {
    font-size: 7px;
    margin-bottom: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .metric-value {
    font-size: 11px !important;
    white-space: nowrap;
  }

  .chart-box {
    height: 88px;
    padding: 4px;
  }

  .story-chapters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
  }

  .story-chapter-card {
    padding: 5px 6px;
  }

  .story-chapter-card .chapter-title {
    font-size: 9.5px;
    margin-bottom: 0;
    gap: 4px;
  }

  .story-chapter-card .sim-tag {
    font-size: 8px;
    padding: 1px 4px;
  }

  .story-chapter-card .chapter-desc {
    display: none;
  }
}
