/* ══ FOCUS VISIBLE (second definition) ══ */
/* ── FOCUS VISIBLE ── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(var(--accent-rgb), 0.15);
}
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(var(--accent-rgb), 0.15);
}
:focus:not(:focus-visible) { outline: none; box-shadow: none; }

/* ══ HIGH CONTRAST ══ */
/* ── HIGH CONTRAST ── */
@media (forced-colors: active) {
  .node-border { stroke: CanvasText !important; fill: Canvas !important; }
  .panel-accent { background: Highlight !important; }
  .panel-nav-btn, .panel-tag, .panel-link { border: 1px solid ButtonText !important; }
  .badge-extinct { background: Mark !important; color: MarkText !important; }
  #panel { border-left: 2px solid CanvasText !important; }
}

/* ══ REDUCED MOTION (main block) ══ */
/* ── REDUCED MOTION ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ══ MOBILE ENGAGEMENT ══ */
/* ── MOBILE ENGAGEMENT ── */
@media(max-width:768px){
  #progress-badge{top:auto;bottom:11rem;left:0.5rem;right:auto;font-size:11px;padding:3px 8px;}
  #achievement-container{bottom:60px;right:10px;left:10px;}
  .achievement-toast{min-width:auto;width:100%;}
  #btn-quiz{padding:3px 8px;font-size:11px;}
}
@media(max-width:480px){
  #progress-badge{font-size:10px;padding:2px 6px;bottom:10.5rem;left:0.3rem;right:auto;}
}

/* ══════════════════════════════════════════════════════
   MOBILE RESPONSIVE — 768px breakpoint
   ══════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── HEADER: compact, no overlap ── */
  #header {
    padding: 6px 12px 2rem;
    background: linear-gradient(to bottom, var(--surface-overlay) 40%, transparent);
    flex-wrap: wrap;
    gap: 6px;
  }
  .title-main { font-size: 1.1rem !important; }
  .title-sub  { font-size: 0.55rem !important; margin-top: 0.2rem; }
  /* ── BREADCRUMB: hide on mobile ── */
  #breadcrumb { display: none !important; }

  /* ── NAV CTRL: center bottom on mobile ── */
  #nav-ctrl{top:auto;bottom:5rem;left:50%;transform:translateX(-50%);right:auto;}
  #nav-ctrl.visible{transform:translateX(-50%) translateY(0);}
  [dir="rtl"] #nav-ctrl{left:50%;right:auto;transform:translateX(50%);}
  [dir="rtl"] #nav-ctrl.visible{transform:translateX(50%) translateY(0);}

  /* ── SEARCH BAR: full-width, below header ── */
  #search-wrap {
    top: 0.55rem !important;
    left: 12px !important;
    right: 12px !important;
    transform: none !important;
    width: auto !important;
    flex-wrap: wrap;
    gap: 6px;
  }
  #search-input {
    flex: 1;
    min-width: 0;
    width: auto !important;
    font-size: 0.82rem;
    padding: 0.5rem 1rem 0.5rem 2.2rem;
  }
  #search-input:focus { width: auto !important; }
  .search-pill {
    padding: 10px 14px;
    font-size: 0.75rem;
    min-height: 44px;
  }
  #search-results {
    max-height: 45vh;
    left: 0; right: 0;
  }

  /* ── LANG SWITCHER + THEME: move to top-right row ── */
  #lang-switcher {
    top: 0.55rem;
    right: auto;
    left: auto;
    position: fixed;
    right: 50px;
    z-index: 400;
  }
  .lang-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 0.25rem 0.4rem;
    font-size: 0.6rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  #theme-btn {
    top: 0.55rem;
    right: 6px;
    width: 44px !important;
    height: 44px !important;
    font-size: 0.8rem;
  }
  [dir="rtl"] #lang-switcher { right: auto; left: 50px; }
  [dir="rtl"] #theme-btn { right: auto; left: 6px; }

  /* ── DETAIL PANEL: bottom-sheet on mobile ── */
  #panel {
    position: fixed !important;
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-height: 75vh;
    border-radius: 16px 16px 0 0;
    border-top: 2px solid rgba(var(--accent-rgb),0.25);
    border-left: none !important;
    border-right: none !important;
    box-shadow: 0 -8px 40px rgba(0,0,0,0.5);
    transition: transform 0.35s cubic-bezier(0.16,1,0.3,1) !important;
    overflow-y: auto;
  }
  #panel:not(.open) {
    right: 0 !important;
    transform: translateY(100%);
  }
  #panel.open {
    right: 0 !important;
    transform: translateY(0);
  }
  [dir="rtl"] #panel {
    left: 0 !important;
    right: 0 !important;
  }
  [dir="rtl"] #panel.open {
    left: 0 !important;
    transform: translateY(0);
  }
  /* Swipe handle */
  #panel::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: rgba(var(--accent-rgb),0.35);
    border-radius: 2px;
    margin: 8px auto 4px;
    flex-shrink: 0;
  }
  .panel-scroll { padding: 0.8rem 1.2rem 1.5rem; }
  .panel-body { padding: 14px 16px; gap: 12px; }
  .panel-hero { aspect-ratio: 2/1; max-height: 150px; }
  .panel-hero .p-close { width: 40px !important; height: 40px !important; font-size: 1rem; }
  .panel-hero-meta { bottom: 10px; left: 14px; right: 14px; }
  .panel-title { font-size: 18px; }
  .mini-map svg { max-height: 100px; }
  .p-close {
    width: 44px !important;
    height: 44px !important;
    font-size: 1rem;
    top: 0.6rem;
    right: 0.6rem;
  }

  /* ── ZOOM CONTROLS: 44px touch targets ── */
  #zoom-ctrl {
    bottom: 5.5rem;
    right: 8px;
  }
  .zbtn {
    width: 44px !important;
    height: 44px !important;
    font-size: 1.2rem;
    border-radius: 10px;
  }

  /* ── FAB GROUP: compact on mobile ── */
  .fab-group { bottom: 16rem; left: 0.6rem; gap: 0.4rem; }
  [dir="rtl"] .fab-group { left: auto; right: 0.6rem; }
  .fab { padding: 0.4rem 0.7rem; font-size: 0.72rem; }
  .fab--tour { width: 34px; height: 34px; }

  /* ── LEGEND: collapsible, horizontal compact ── */
  #legend {
    bottom: 5rem;
    left: 8px;
    padding: 0.5rem 0.7rem;
    max-width: 150px;
    font-size: 0.6rem;
  }
  #legend.m-collapsed .leg-row,
  #legend.m-collapsed button {
    display: none;
  }
  .leg-title { cursor: pointer; }
  .leg-row {
    font-size: 0.6rem;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  /* ── TIMELINE: compact ── */
  #timeline {
    padding: 0.4rem 0.8rem 0.7rem;
  }
  #era-label { font-size: 0.55rem; }

  /* ── CANVAS ── */
  #canvas-wrap {
    width: 100vw !important;
    height: 100vh !important;
  }

  /* ── COMPARE PANEL: single column ── */
  #compare-panel {
    padding: 1rem !important;
  }
  #compare-grid {
    grid-template-columns: 1fr !important;
  }

  /* ── TOOLTIP: hidden on touch (use panel instead) ── */
  #tooltip { display: none !important; }

  /* ── FOOTER / HINTS ── */
  footer { display: none; }
  #shortcuts-hint { display: none !important; }
}

/* ══════════════════════════════════════════════════════
   SMALL MOBILE — 480px breakpoint
   ══════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .title-main { font-size: 0.95rem !important; }
  .title-sub  { display: none; }
  #search-wrap {
    top: 2.4rem !important;
    left: 8px !important;
    right: 8px !important;
  }
  .search-pill {
    padding: 5px 8px;
    font-size: 0.7rem;
  }
  #lang-switcher { display: none; }
  #theme-btn { top: 0.4rem; right: 4px; }
  #legend { display: none; }
  #panel { max-height: 80vh; }
  .p-facts { grid-template-columns: 1fr !important; }
  #zoom-ctrl { bottom: 5rem; right: 4px; }
  .zbtn { width: 44px !important; height: 44px !important; }
  /* FAB: icon-only circles on small screens */
  .fab-group { bottom: 14rem; left: 0.4rem; gap: 0.35rem; }
  .fab span:not(.fab-icon) { display: none; }
  .fab { padding: 0.5rem; border-radius: 50%; width: 42px; height: 42px; justify-content: center; }
  .fab-icon { font-size: 1.1rem; }
  .fab--tour { width: 42px; height: 42px; font-size: 1.1rem; }
}

/* ══════════════════════════════════════════════════════
   LANDSCAPE MOBILE — prevent controls stacking badly
   ══════════════════════════════════════════════════════ */
@media (max-height: 500px) and (max-width: 900px) {
  #panel { max-height: 60vh; }
  #timeline { padding: 0.2rem 0.5rem 0.4rem; }
  #tl-density { display: none; }
  #era-track { height: 10px; }
  #tl-thumb { width: 14px; height: 18px; }
}

/* ══ MOBILE FOR NEW ELEMENTS ══ */
/* ── MOBILE FOR NEW ELEMENTS ── */
@media (max-width: 768px) {
  #view-toggle{top:auto;bottom:20rem;right:0.6rem;flex-direction:column;}
  .view-btn+.view-btn{border-left:none;border-top:1px solid var(--border);}
  #timeline{padding:0.3rem 0.6rem 0.5rem;}
  #era-label{font-size:0.6rem;}
  #era-time-range{display:none;}
  #era-species-count{display:none;}
  #tl-density{height:10px;}
  #era-track{height:12px;}
  #tl-thumb{width:14px;height:20px;}
  .era-seg-label{display:none;}
  .era-preset{font-size:0.65rem;padding:0.2rem 0.5rem;}
  .era-preset-icon{display:none;}
  #tl-speed-group{display:none;}
  #era-play{width:26px;height:26px;font-size:0.65rem;}
  [dir="rtl"] #view-toggle{left:0.6rem;right:auto;}
}

/* ══ DNA CALC MOBILE ══ */
@media(max-width:768px){
  .dna-panel-inner{padding:1rem;width:96vw;max-height:95vh;}
  .dna-percent-num{font-size:2.4rem;}
  .dna-selectors{flex-direction:column;gap:0.3rem;}
  .dna-vs{transform:rotate(90deg);}
  .dna-presets{justify-content:center;}
}

/* ══ PLAYBACK MOBILE ══ */
@media(max-width:768px){
  .discovery-card{max-width:90vw;left:5vw!important;right:5vw!important;bottom:140px!important;top:auto!important;}
  .playback-controls{gap:0.3rem;}
}

/* ══ EVO PATH MOBILE ══ */
@media(max-width:768px){
  .evo-panel-inner{padding:1rem;width:96vw;max-height:95vh;}
  .evo-selectors{flex-direction:column;gap:0.3rem;}
  .evo-arrow{transform:rotate(90deg);}
  .evo-presets{justify-content:center;}
  .evo-stat-value{font-size:1.4rem;}
  .evo-chain-node-name{max-width:45px;font-size:0.5rem;}
}

/* ══ TRIVIA MOBILE ══ */
@media(max-width:768px){
  .trivia-panel-inner{padding:1rem;width:96vw;max-height:95vh;}
  .trivia-question-text{font-size:0.88rem;}
}

/* ══ TOUR SELECTOR MOBILE ══ */
@media(max-width:768px){
  .tour-selector-cards{flex-direction:column;}
  .tour-selector{padding:1.5rem 1rem;}
  .tour-selector-card{flex-direction:row;gap:0.75rem;padding:1rem;text-align:left;}
  .tour-selector-card-icon{font-size:1.5rem;}
}

/* ══ TOUR CARD MOBILE ══ */
@media(max-width:768px){
  .tour-card{max-width:calc(100vw - 2rem);}
}

/* ══ KEYBOARD HELP MOBILE ══ */
@media(max-width:768px){.kbd-panel{padding:1.2rem 1.5rem;max-width:calc(100vw - 2rem);}}

/* ══ ACCESSIBILITY REDUCED MOTION (engagement block) ══ */
@media(prefers-reduced-motion:reduce){
  *,*::before,*::after{
    animation-duration:0.01ms !important;
    animation-iteration-count:1 !important;
    transition-duration:0.01ms !important;
    scroll-behavior:auto !important;
  }
  .particle { display: none !important; }
  .node-border { transition: none !important; }
  .branch-path { transition: none !important; stroke-dasharray: none !important; stroke-dashoffset: 0 !important; }
  .branch-entering,.branch-entered { transition: none !important; stroke-dasharray: none !important; stroke-dashoffset: 0 !important; }
  .node-entering,.node-entered { transition: none !important; opacity: 1 !important; transform: none !important; }
  #viewport { will-change: auto; }
  #panel { transition: none !important; }
  #panel.panel-enter { transform: none !important; opacity: 1 !important; }
}
