/* Cadre adaptatif : la navigation reste accessible sans écraser le profil ni le jeu. */
html { -webkit-text-size-adjust: 100%; }

.app-shell { min-width: 0; }

.topbar {
  position: relative;
  z-index: 20;
  height: 72px;
  gap: 14px;
  min-width: 0;
}

.topbar > * { min-width: 0; }

.clock-hud { max-width: min(300px, 100%); }

.brand {
  min-width: 178px;
  flex: 0 0 auto;
}

.brand-mark {
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #080d1d;
  box-shadow: 0 0 23px rgba(124, 92, 252, .42);
}

.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.avatar,
.profile-avatar {
  overflow: hidden;
  flex: 0 0 auto;
}

.avatar img,
.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.avatar-editor {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 0 3px;
}

.avatar-editor .eyebrow { margin-bottom: 5px; }

.avatar-status {
  max-width: 280px;
  margin: 0;
  color: #9ba8cd;
  font-size: 11px;
  line-height: 1.45;
}

.avatar-hint {
  margin: 3px 0 0;
  color: #6f7da8;
  font-size: 11px;
  line-height: 1.4;
}

.avatar-editor-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.avatar-upload {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  font-size: 11px;
  cursor: pointer;
}

.avatar-remove { min-height: 42px; padding: 8px 3px; }

.main-nav {
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scrollbar-width: none;
}

.main-nav::-webkit-scrollbar { display: none; }

.nav-link {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 11px 10px;
  font-size: 13px;
  white-space: nowrap;
}

.nav-link.active::after {
  right: 10px;
  bottom: 0;
  left: 10px;
}

.clock-hud {
  flex: 0 1 278px;
  min-width: 218px;
}

.player-chip {
  min-width: 132px;
  flex: 0 0 auto;
}

/* Une vraie couche modale : le profil ne peut plus passer sous le contenu du jeu. */
.modal-backdrop {
  z-index: 1000;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(12px, 3vw, 28px);
}

.modal-backdrop.open { align-items: start; }

.trade-modal,
.profile-modal,
.analysis-modal,
.world-feed-modal,
.scenario-modal {
  max-height: calc(100dvh - 24px);
  margin: auto;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.life-profile-modal {
  width: min(570px, 100%);
  max-height: calc(100dvh - 24px);
}

.market-intro-actions,
.leaderboard-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.company-ceo {
  display: block;
  margin-top: 3px;
  color: #8391bc;
  font-size: 10px;
}

.leaderboard-panel { margin-top: 28px; }
.leaderboard-heading { align-items: flex-start; }
.leaderboard-heading .section-copy { max-width: 540px; margin: 5px 0 0; }
.leaderboard-actions { justify-content: flex-end; }
.leaderboard-list { display: grid; gap: 8px; margin-top: 16px; }
.leaderboard-row { display: grid; grid-template-columns: 38px minmax(0,1fr) auto; gap: 12px; align-items: center; padding: 11px 12px; border: 1px solid rgba(160,179,236,.12); border-radius: 13px; background: rgba(10,16,37,.45); }
.leaderboard-row.is-player { border-color: rgba(104,229,180,.48); box-shadow: inset 0 0 0 1px rgba(104,229,180,.08); }
.leaderboard-rank { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; color: #dfe6ff; background: rgba(131,104,255,.2); font-weight: 800; }
.leaderboard-row b { overflow-wrap: anywhere; }
.leaderboard-row small { display: block; margin-top: 3px; color: #8e9bc1; }
.leaderboard-empty { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 16px; padding: 16px; border: 1px dashed rgba(160,179,236,.22); border-radius: 13px; color: #aab5d5; }
.leaderboard-empty p { margin: 4px 0 0; font-size: 13px; }
.leaderboard-own { margin: 14px 2px 0; color: #aab5d5; font-size: 13px; }

.toast-area { z-index: 1200; }

.profile-header {
  padding-right: 48px;
}

.profile-header > div { min-width: 0; }

.profile-header h2,
.profile-header > div > span { overflow-wrap: anywhere; }

.profile-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.close-modal {
  z-index: 3;
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 50%;
}

body:has(.modal-backdrop.open) { overflow: hidden; }

@media (max-width: 1320px) {
  .app-shell { padding-right: 28px; padding-left: 28px; }

  .topbar {
    height: auto;
    min-height: 72px;
    flex-wrap: wrap;
    padding: 9px 0 0;
  }

  .main-nav {
    order: 4;
    flex: 0 0 100%;
    width: 100%;
    height: 42px;
    border-top: 1px solid rgba(176, 191, 231, .1);
  }

  .nav-link { min-height: 41px; }

  .clock-hud { margin-left: auto; }

  main { padding-top: 20px; }
}

@media (max-width: 960px) {
  .clock-hud { display: none; }

  .topbar { gap: 10px; }

  .main-nav { order: 3; }

  .dashboard-layout,
  .two-column,
  .portfolio-layout { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .stats-grid,
  .portfolio-summary,
  .market-context,
  .macro-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .app-shell { padding: 0 15px 30px; }

  .topbar {
    min-height: 90px;
    padding-top: 8px;
  }

  .main-nav {
    display: flex;
    gap: 2px;
    height: 42px;
    margin: 0 -15px;
    padding: 0 15px;
    scroll-padding-inline: 15px;
  }

  .nav-link {
    min-height: 42px;
    padding: 10px 12px;
    font-size: 13px;
  }

  .brand { min-width: 0; }

  .player-chip { min-width: 120px; }
  .player-chip { position: relative; z-index: 30; min-height: 44px; touch-action: manipulation; }

  .market-toolbar { display: grid; grid-template-columns: minmax(0,1fr); gap: 10px; }
  .market-toolbar .search-box { width: 100%; min-width: 0; }
  .sector-filters { width: 100%; max-width: none; overflow: visible; flex-wrap: wrap; gap: 7px; }
  .filter-button { flex: 1 0 auto; min-height: 40px; padding: 9px 10px; }
  .market-toolbar .sort-button { justify-self: start; min-height: 44px; margin-left: 0; }
  .market-intro-actions { width: 100%; }
  .market-intro-actions > button { flex: 1 1 145px; min-height: 44px; }
  .leaderboard-heading { display: block; }
  .leaderboard-actions { margin-top: 13px; justify-content: flex-start; }
  .leaderboard-actions > button { min-height: 42px; }
  .leaderboard-empty { align-items: flex-start; flex-direction: column; }
  .leaderboard-empty > button { width: 100%; min-height: 44px; }

  main { padding-top: 18px; }

  .modal-backdrop { padding: 10px; }

  .trade-modal,
  .profile-modal,
  .analysis-modal,
  .world-feed-modal,
  .scenario-modal,
  .life-profile-modal {
    width: 100%;
    max-height: calc(100dvh - 20px);
    border-radius: 13px;
  }

  .life-profile-modal { padding: 20px 15px; }

  .avatar-editor {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .avatar-status,
  .avatar-hint { max-width: none; font-size: 12px; }

  .avatar-editor-actions { width: 100%; }

  .avatar-upload { flex: 1; min-height: 44px; font-size: 14px; }

  .avatar-remove { min-height: 44px; font-size: 13px; }

  .life-form-grid input,
  .life-form-grid select,
  .name-label input {
    min-height: 44px;
    font-size: 16px;
  }

  .income-estimate { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .toast-area {
    right: 12px;
    bottom: 12px;
    left: 12px;
    z-index: 900;
  }

  .toast { max-width: none; }
}

@media (max-width: 420px) {
  .app-shell { padding-right: 12px; padding-left: 12px; }

  .main-nav {
    margin-right: -12px;
    margin-left: -12px;
    padding-right: 12px;
    padding-left: 12px;
    scroll-padding-inline: 12px;
  }

  .brand strong { font-size: 15px; }

  .brand em { font-size: 8px; }

  .player-chip {
    min-width: 0;
    padding: 5px;
  }

  .player-copy,
  .player-chip .chevron { display: none; }

  .avatar { width: 34px; height: 34px; }

  .profile-avatar { width: 52px; height: 52px; }

  .income-estimate { grid-template-columns: 1fr; }

  .profile-header { align-items: flex-start; }
}

/* Garde-fous mobiles : aucune fenêtre ne peut élargir la page ni recouvrir une autre.
   Les contenus longs se lisent à l'intérieur de leur fenêtre. */
@media (max-width: 760px) {
  html,
  body {
    max-width: 100%;
    overflow-x: clip;
  }

  .modal-backdrop {
    box-sizing: border-box;
    align-items: flex-start;
    padding:
      max(10px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
  }

  .modal-backdrop > .trade-modal,
  .modal-backdrop > .profile-modal,
  .modal-backdrop > .analysis-modal,
  .modal-backdrop > .world-feed-modal,
  .modal-backdrop > .scenario-modal,
  .modal-backdrop > .life-profile-modal,
  .modal-backdrop > .academy-news-modal,
  .modal-backdrop > .tutorial-video-shell {
    box-sizing: border-box;
    width: min(100%, 46rem);
    max-width: 100%;
    max-height: calc(100dvh - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    margin: 0 auto;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .toast-area {
    bottom: max(12px, env(safe-area-inset-bottom));
  }

  .entry-tutorial-layer,
  .career-tutorial-layer,
  .section-guide-layer {
    max-width: 100%;
    overflow-x: hidden;
  }

  .entry-tutorial-scene,
  .entry-tutorial-stage,
  .career-tutorial-scene,
  .career-tutorial-stage,
  .section-guide-card {
    box-sizing: border-box;
    max-width: 100%;
  }

  /* Une seule couche interactive à la fois : les aides reviennent dès la fermeture. */
  html.modal-is-open .section-guide-layer,
  html.modal-is-open .section-guide-prompt,
  html.modal-is-open .career-tutorial-resume,
  html.modal-is-open .beginner-path-coach {
    display: none !important;
  }
}

/* Marchés alternatifs : cartes compactes sur ordinateur, une colonne lisible sur mobile. */
.alternative-market-section { margin-top: 30px; }
.alternative-asset-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.alternative-asset-card { background: linear-gradient(145deg, rgba(22, 33, 59, .92), rgba(10, 16, 32, .94)); border: 1px solid var(--line); border-radius: 12px; padding: 14px; min-width: 0; position: relative; overflow: hidden; }
.alternative-asset-card::before { content: ""; position: absolute; width: 88px; height: 88px; border-radius: 50%; right: -34px; top: -38px; background: var(--asset-color); opacity: .1; filter: blur(4px); }
.alternative-asset-top { display: flex; gap: 9px; align-items: center; }
.alternative-asset-top .company-logo { width: 35px; height: 35px; font-size: 15px; }
.alternative-asset-top strong { font-size: 12px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.alternative-asset-top small { font-size: 9px; color: #99a6ce; display: block; margin-top: 3px; }
.asset-class-tag { font-size: 8px; color: #c7d0ef; border: 1px solid rgba(173, 188, 238, .16); border-radius: 5px; padding: 4px 5px; margin-left: auto; text-align: right; max-width: 74px; }
.asset-metrics { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid rgba(176,191,231,.1); margin-top: 12px; padding-top: 10px; gap: 8px; }
.asset-metrics small { display: block; font-size: 8px; letter-spacing: .06em; color: #7e8db7; font-weight: 800; }
.asset-metrics b { display: block; font-size: 10px; color: #d5def8; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.asset-driver { font-size: 9px; line-height: 1.35; color: #91a0c9; margin: 11px 0 0; min-height: 25px; }
.asset-driver b { color: #c9d3f0; }
@media (max-width: 1080px) { .alternative-asset-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 760px) { .alternative-asset-grid { grid-template-columns: 1fr; } .alternative-asset-card { padding: 15px; } }
