/* ================================================================
   Théorie des Jeux v2 — ENS Antananarivo
   Design : iOS-inspired · Multi-thème · Palatino/Playfair
   ================================================================ */

/* ─── Themes ─────────────────────────────────────────────── */
:root, [data-theme="vert"] {
  --primary:    #2e7d5c;
  --primary-lt: #e6f4ee;
  --primary-md: #a8d5ba;
  --accent:     #c9a020;
  --accent-lt:  #fef5d8;
  --bg:         #f4f8f5;
  --bg2:        #ffffff;
  --surface:    #ffffff;
  --border:     #d0e8da;
  --text:       #1a2e25;
  --text2:      #4a6658;
  --text3:      #7a9c8a;
  --shadow:     rgba(46,125,92,.12);
  --shadow-md:  rgba(46,125,92,.18);
}
[data-theme="moutarde"] {
  --primary:    #b07d10;
  --primary-lt: #fef7e0;
  --primary-md: #f0d080;
  --accent:     #2e7d5c;
  --accent-lt:  #e6f4ee;
  --bg:         #fdf9ed;
  --bg2:        #ffffff;
  --surface:    #ffffff;
  --border:     #e8d898;
  --text:       #2a1e05;
  --text2:      #6a5010;
  --text3:      #a89040;
  --shadow:     rgba(176,125,16,.12);
  --shadow-md:  rgba(176,125,16,.2);
}
[data-theme="ocean"] {
  --primary:    #1a5fa8;
  --primary-lt: #e8f0fb;
  --primary-md: #a0c0e8;
  --accent:     #e06820;
  --accent-lt:  #fef0e0;
  --bg:         #eef4fc;
  --bg2:        #ffffff;
  --surface:    #ffffff;
  --border:     #b8d0f0;
  --text:       #0a1e38;
  --text2:      #2a4a78;
  --text3:      #6888b8;
  --shadow:     rgba(26,95,168,.12);
  --shadow-md:  rgba(26,95,168,.2);
}
[data-theme="rose"] {
  --primary:    #9a4060;
  --primary-lt: #fdedf3;
  --primary-md: #e8b0c8;
  --accent:     #6a7a20;
  --accent-lt:  #f0f4d8;
  --bg:         #fdf2f6;
  --bg2:        #ffffff;
  --surface:    #ffffff;
  --border:     #f0c8da;
  --text:       #2a0a18;
  --text2:      #6a2840;
  --text3:      #b07090;
  --shadow:     rgba(154,64,96,.12);
  --shadow-md:  rgba(154,64,96,.2);
}
[data-theme="sombre"] {
  --primary:    #3dbf8a;
  --primary-lt: rgba(61,191,138,.12);
  --primary-md: rgba(61,191,138,.3);
  --accent:     #f0c040;
  --accent-lt:  rgba(240,192,64,.12);
  --bg:         #0f1a14;
  --bg2:        #162010;
  --surface:    #1e2e22;
  --border:     rgba(61,191,138,.2);
  --text:       #e0f0e8;
  --text2:      #88c8a8;
  --text3:      #508868;
  --shadow:     rgba(0,0,0,.4);
  --shadow-md:  rgba(0,0,0,.6);
}

/* ─── Reset & Base ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: 'Palatino Linotype', 'Palatino', 'Book Antiqua', 'Playfair Display', Georgia, serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  transition: background .3s, color .3s;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--primary-md); border-radius: 4px; }

/* ─── Top Bar ─────────────────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 12px var(--shadow);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1rem 0 .75rem;
  transition: background .3s, border-color .3s;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.topbar-left { display: flex; align-items: center; gap: .75rem; }
.topbar-right { display: flex; align-items: center; gap: .75rem; }

.menu-toggle {
  width: 36px; height: 36px; border-radius: 10px;
  border: none; background: var(--primary-lt); cursor: pointer;
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 4px; padding: 0;
  transition: background .2s, transform .15s;
}
.menu-toggle:active { transform: scale(.93); }
.menu-toggle span {
  display: block; width: 16px; height: 2px;
  background: var(--primary); border-radius: 2px;
  transition: all .25s;
}
.menu-toggle.open span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.menu-toggle.open span:nth-child(2) { opacity: 0; transform: scaleX(0); }
.menu-toggle.open span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.brand { display: flex; align-items: center; gap: .6rem; }
.brand-icon svg { display: block; border-radius: 8px; }
.brand-title {
  font-family: 'Playfair Display', 'Palatino Linotype', serif;
  font-size: 1rem; font-weight: 700; color: var(--text);
  line-height: 1.2;
}
.brand-sub { font-size: .68rem; color: var(--text3); margin-top: 1px; }

/* Theme switcher */
.theme-switcher { display: flex; align-items: center; gap: 5px; }
.theme-dot {
  width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid transparent;
  cursor: pointer; transition: transform .2s, border-color .2s;
}
.theme-dot:hover { transform: scale(1.2); }
.theme-dot.active { border-color: var(--primary); transform: scale(1.15); }
.theme-dot[data-theme="vert"]     { background: #2e7d5c; }
.theme-dot[data-theme="moutarde"] { background: #b07d10; }
.theme-dot[data-theme="ocean"]    { background: #1a5fa8; }
.theme-dot[data-theme="rose"]     { background: #9a4060; }
.theme-dot[data-theme="sombre"]   { background: #1e2e22; border: 2.5px solid #3dbf8a; }

/* ─── Sélecteur de thème en liste déroulante ─────────────── */
.theme-select-wrap {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .78rem;
  font-weight: 700;
  color: var(--text2);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .28rem .45rem .28rem .75rem;
  box-shadow: 0 4px 18px var(--shadow-sm);
}
.theme-select {
  min-width: 160px;
  border: 0;
  outline: none;
  background: var(--primary);
  color: white;
  border-radius: 999px;
  padding: .42rem .85rem;
  font-family: 'EB Garamond', Georgia, serif;
  font-weight: 700;
  cursor: pointer;
}
.theme-select option {
  color: #1a1a1a;
  background: #fff;
}
[data-theme="sombre"] .theme-select option {
  color: #f3f7f4;
  background: #122018;
}
@media (max-width: 640px) {
  .theme-select-wrap span { display: none; }
  .theme-select { min-width: 128px; padding: .38rem .65rem; }
}

/* ─── Layout ──────────────────────────────────────────────── */
.layout {
  display: flex;
  padding-top: 56px;
  min-height: 100vh;
}

/* ─── Sidebar overlay (mobile) ────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 56px 0 0 0;
  background: rgba(0,0,0,.4);
  z-index: 49;
  animation: fadeIn .2s;
}
.sidebar-overlay.show { display: block; }
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }

/* ─── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: 272px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: fixed; top: 56px; left: 0; bottom: 0;
  z-index: 50;
  overflow: hidden;
  transition: transform .28s cubic-bezier(.4,0,.2,1), box-shadow .28s;
}
.sidebar.closed { transform: translateX(-100%); }
.sidebar-scroll {
  height: 100%; overflow-y: auto; padding: .75rem .5rem 2rem;
}

/* Nav groups */
.nav-group { margin-bottom: .25rem; }

.nav-section-btn {
  width: 100%; display: flex; align-items: center; gap: .55rem;
  padding: .6rem .75rem; border-radius: 11px;
  border: none; background: none; cursor: pointer;
  font-family: inherit; font-size: .88rem; font-weight: 700;
  color: var(--text); text-align: left;
  transition: background .15s;
}
.nav-section-btn:hover, .nav-section-btn.active { background: var(--primary-lt); color: var(--primary); }
.nav-section-icon { font-size: 1rem; }
.nav-chevron {
  margin-left: auto; font-size: 1.1rem; color: var(--text3);
  transition: transform .22s;
}
.nav-section-btn.open .nav-chevron { transform: rotate(90deg); }

.nav-section-body { padding-left: .25rem; padding-top: .2rem; }

.nav-sub-group { margin-bottom: .2rem; }
.nav-sub-btn {
  width: 100%; display: flex; align-items: center; gap: .5rem;
  padding: .45rem .65rem; border-radius: 9px;
  border: none; background: none; cursor: pointer;
  font-family: inherit; font-size: .82rem; font-weight: 600;
  color: var(--text2); text-align: left;
  transition: background .15s;
}
.nav-sub-btn:hover { background: var(--primary-lt); }
.nav-sub-btn.open { color: var(--primary); }
.sub-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }

.nav-sub-body { padding-left: 1.15rem; padding-top: .15rem; }
.nav-item {
  display: block; width: 100%; text-align: left;
  padding: .38rem .6rem; border-radius: 8px;
  border: none; background: none; cursor: pointer;
  font-family: inherit; font-size: .8rem; color: var(--text2);
  transition: background .15s, color .15s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-item:hover { background: var(--primary-lt); color: var(--primary); }
.nav-item.active {
  background: var(--primary); color: white; font-weight: 600;
}

/* ─── Main ────────────────────────────────────────────────── */
.main {
  flex: 1; min-width: 0;
  margin-left: 272px;
  padding: 1.25rem 1.5rem 3rem;
  transition: margin-left .28s cubic-bezier(.4,0,.2,1);
}
.main.full { margin-left: 0; }

/* ─── Game header card ────────────────────────────────────── */
.game-header-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
  box-shadow: 0 2px 16px var(--shadow);
  transition: background .3s, border-color .3s;
}
.ghc-meta { display: flex; align-items: center; gap: .6rem; margin-bottom: .4rem; }
.ghc-badge {
  font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  padding: 3px 10px; border-radius: 20px;
  background: var(--primary-lt); color: var(--primary);
}
.ghc-cat { font-size: .75rem; color: var(--text3); }
.ghc-title {
  font-family: 'Playfair Display', 'Palatino Linotype', serif;
  font-size: 1.5rem; font-weight: 700; color: var(--text); line-height: 1.25;
  margin-bottom: .3rem;
}
.ghc-desc { font-size: .9rem; color: var(--text2); max-width: 820px; line-height: 1.65; }

/* ─── Parameters card ─────────────────────────────────────── */
.params-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 8px var(--shadow);
  transition: background .3s;
}
.params-header {
  display: flex; align-items: baseline; gap: .75rem; margin-bottom: .8rem;
  flex-wrap: wrap;
}
.params-title { font-size: .88rem; font-weight: 700; color: var(--primary); }
.params-hint { font-size: .75rem; color: var(--text3); font-style: italic; }
.params-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .9rem 1.4rem;
}
.param-item label {
  display: block; font-size: .8rem; color: var(--text2); margin-bottom: 4px;
}
.param-item label strong { color: var(--primary); font-weight: 700; }
input[type="range"] {
  width: 100%; height: 4px; cursor: pointer;
  accent-color: var(--primary);
  -webkit-appearance: none; appearance: none;
  background: var(--primary-lt); border-radius: 2px; outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px;
  border-radius: 50%; background: var(--primary);
  border: 2.5px solid white; box-shadow: 0 1px 4px var(--shadow-md);
}

/* ─── Tabs ────────────────────────────────────────────────── */
.tabs-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px 14px 0 0;
  border-bottom: none;
  overflow: hidden;
  transition: background .3s;
}
.tabs-scroll {
  display: flex; overflow-x: auto; gap: 2px; padding: .4rem .4rem 0;
  scrollbar-width: none;
}
.tabs-scroll::-webkit-scrollbar { display: none; }
.tab {
  padding: .55rem 1.1rem; border-radius: 10px 10px 0 0;
  border: none; background: none; cursor: pointer;
  font-family: inherit; font-size: .85rem; font-weight: 600;
  color: var(--text2); white-space: nowrap;
  transition: background .18s, color .18s;
  border-bottom: 2px solid transparent;
}
.tab:hover { background: var(--primary-lt); color: var(--primary); }
.tab.active {
  background: var(--primary); color: white;
  border-radius: 10px 10px 0 0;
}

/* ─── Tab body ────────────────────────────────────────────── */
.tab-body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 18px 18px;
  padding: 1.4rem;
  min-height: 280px;
  box-shadow: 0 4px 20px var(--shadow);
  transition: background .3s;
}
.tab-pane { display: none; }
.tab-pane.active { display: block; animation: slideUp .25s ease; }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Payoff matrix ───────────────────────────────────────── */
.matrix-wrap { overflow-x: auto; margin-bottom: 1rem; }
.payoff-table {
  border-collapse: collapse; margin: 0 auto;
  font-family: 'Palatino Linotype', Palatino, Georgia, serif;
}
.payoff-table th {
  background: var(--primary); color: white;
  padding: 8px 18px; font-weight: 600; font-size: .9rem;
  white-space: nowrap;
}
.payoff-table th.corner { background: var(--bg); border: 0; }
.payoff-table th.player-v {
  writing-mode: vertical-rl; transform: rotate(180deg);
  font-size: .82rem; min-width: 26px; padding: 10px 6px;
}
.payoff-table td {
  padding: 9px 18px; text-align: center;
  border: 1px solid var(--border); min-width: 88px; font-size: .95rem;
}
.payoff-table tr:hover td { background: var(--primary-lt); }
.ne-cell { background: var(--primary-lt) !important; border: 2.5px solid var(--primary) !important; }
.br1 { text-decoration: underline; font-weight: 700; color: var(--primary); }
.br2 { text-decoration: underline dotted 2px; font-weight: 700; color: var(--accent); }
.ne-badge {
  display: inline-flex; align-items: center; gap: .3rem;
  background: var(--primary); color: white;
  border-radius: 20px; padding: 2px 10px; font-size: .78rem; margin: 2px 3px;
}
.matrix-legend {
  display: flex; flex-wrap: wrap; gap: .75rem 1.25rem;
  font-size: .78rem; color: var(--text3); margin-top: .75rem;
}
.ne-summary { margin-top: .75rem; font-size: .9rem; }

/* ─── Content boxes ───────────────────────────────────────── */
.box {
  border-radius: 12px; padding: .9rem 1.1rem; margin: .5rem 0;
  font-size: .93rem; line-height: 1.75; overflow-x: auto;
}
.box-formula {
  background: var(--primary-lt);
  border-left: 4px solid var(--primary);
  border-radius: 0 12px 12px 0;
}
.box-result {
  background: var(--accent-lt);
  border: 1.5px solid var(--accent);
}
.box-def {
  background: var(--bg);
  border: 1px solid var(--border);
}
.box-warn {
  background: #fff7ed;
  border: 1.5px solid #fb923c;
  font-size: .85rem; color: #9a3412;
}
[data-theme="sombre"] .box-warn { background: rgba(251,146,60,.1); color: #fed7aa; border-color: #fb923c; }

.sym-h3 {
  font-size: .95rem; font-weight: 700; color: var(--primary);
  margin: 1.1rem 0 .45rem;
  padding-bottom: 3px; border-bottom: 1px solid var(--border);
  font-family: 'Playfair Display', serif;
}
.sym-h3:first-child { margin-top: 0; }

/* ─── Numeric cards ───────────────────────────────────────── */
.num-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .75rem; }
.num-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px; padding: .9rem 1rem;
}
.num-card h4 {
  font-size: .82rem; font-weight: 700; color: var(--primary);
  margin-bottom: .5rem; text-transform: uppercase; letter-spacing: .05em;
}
.num-card p { font-size: .9rem; line-height: 1.7; }
.num-val { font-weight: 700; color: var(--text); }

/* ─── Figure legend ───────────────────────────────────────── */
.fig-legend {
  margin-top: .75rem; font-size: .85rem; color: var(--text2);
  padding: .6rem .9rem; background: var(--primary-lt); border-radius: 10px;
}

/* ─── Cooperative / Shapley ───────────────────────────────── */
.shapley-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .6rem;
  margin: .6rem 0;
}
.shapley-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
  padding: .7rem .9rem; text-align: center;
}
.shapley-card .player-name { font-size: .78rem; color: var(--text3); margin-bottom: .2rem; }
.shapley-card .shapley-val { font-size: 1.2rem; font-weight: 700; color: var(--primary); }

.coalition-table { width: 100%; border-collapse: collapse; font-size: .88rem; margin: .5rem 0; }
.coalition-table th { background: var(--primary-lt); color: var(--primary); padding: 6px 12px; text-align: left; font-weight: 700; }
.coalition-table td { padding: 6px 12px; border-bottom: 1px solid var(--border); }
.coalition-table tr:last-child td { border-bottom: none; }

/* ─── Responsive ──────────────────────────────────────────── */
@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px var(--shadow-md); }
  .main { margin-left: 0 !important; padding: 1rem; }
  .ghc-title { font-size: 1.2rem; }
  .params-grid { grid-template-columns: 1fr 1fr; }
  .num-cards { grid-template-columns: 1fr 1fr; }
  .brand-sub { display: none; }
}
@media (max-width: 480px) {
  .params-grid { grid-template-columns: 1fr; }
  .tab { font-size: .78rem; padding: .5rem .75rem; }
  .tab-body { padding: 1rem .75rem; }
  .num-cards { grid-template-columns: 1fr; }
}


/* ─── Corrections projet : footer fixe + alias couleur ───────── */
:root {
  --grenat: var(--primary);
  --shd: 0 8px 22px var(--shadow-md);
}
.plotly-frame { width: 100%; height: 500px; min-height: 420px; }
.main { padding-bottom: 5.5rem; }
.sidebar-scroll { padding-bottom: 5.5rem; }
.footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 12px;
  display: flex;
  justify-content: center;
  gap: .6em;
  z-index: 90;
  pointer-events: none;
}
.icn {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: var(--grenat, var(--primary));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shd);
  pointer-events: auto;
  text-decoration: none;
  transition: transform .18s ease, filter .18s ease, background .18s ease;
}
.icn:hover { transform: translateY(-2px); filter: brightness(1.08); }
.icn svg { color: #fff; width: 18px; height: 18px; }
.nav-section-btn.open,
.nav-sub-btn.open { background: var(--primary-lt); }
.nav-section-btn.has-active,
.nav-sub-btn.has-active { color: var(--primary); background: var(--primary-lt); }
@media print {
  .topbar, .sidebar, .sidebar-overlay, .footer, .tabs-container { display: none !important; }
  .layout { padding-top: 0 !important; }
  .main { margin-left: 0 !important; padding: 0 !important; }
  .tab-pane { display: block !important; }
}


/* ─── Arbres séquentiels SVG ───────────────────────────── */
.tree-card {
  width: 100%;
  overflow-x: auto;
  background: linear-gradient(180deg, rgba(255,255,255,.95), var(--bg2));
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem;
  box-shadow: 0 10px 30px var(--shadow);
}
.seq-tree {
  width: 100%;
  min-width: 720px;
  height: auto;
  font-family: 'EB Garamond', 'Palatino Linotype', Georgia, serif;
}
.tree-node circle {
  fill: var(--primary);
  stroke: var(--primary);
  stroke-width: 2;
}
.tree-node text {
  fill: #fff;
  font-weight: 700;
  font-size: 14px;
}
.tree-edge path, .repeated-chain path {
  stroke: var(--primary);
  stroke-width: 2;
  fill: none;
  marker-end: url(#arrow);
}
.tree-edge text, .repeated-chain text {
  fill: var(--text2);
  font-size: 13px;
  font-weight: 600;
}
.tree-terminal rect, .repeated-chain rect {
  fill: var(--primary-lt);
  stroke: var(--border);
  stroke-width: 1.5;
}
.tree-terminal text {
  fill: var(--text);
  font-size: 13px;
}
.tree-terminal text:first-of-type {
  font-weight: 700;
}
.tree-caption {
  fill: var(--text2);
  font-size: 13px;
  font-style: italic;
}
