/* style.css */

:root {
  --bg: #0f172a;           
  --bg-alt: #1e293b;       
  --primary: #3b82f6;      
  --primary-hover: #2563eb;
  --accent: #8b5cf6;       
  --text: #f8fafc;         
  --muted: #94a3b8;        
  --border: #334155;       
  --danger: #ef4444;       
  --success: #10b981;      
  --info: #0ea5e9;         
  --font-base: "Inter", system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--font-base);
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden; /* Global clamp */
}

h1, h2, h3 { 
    color: #ffffff; 
    font-weight: 700; 
    line-height: 1.2; 
    margin-bottom: 0.5em; 
    letter-spacing: -0.5px; 
}

a { 
    color: var(--primary); 
    text-decoration: none; 
    transition: color 0.2s; 
}

a:hover { 
    color: var(--primary-hover); 
}

.muted { 
    color: var(--muted); 
}

.hidden, .is-hidden { 
    display: none !important; 
}

.full-width { 
    width: 100%; 
}

/* === UNIVERSAL NAVIGATION (RIGHT-ALIGNED DROPDOWN) === */
.top-nav {
  display: flex;
  flex-direction: row; 
  align-items: center;
  padding: 15px 30px;
  background-color: var(--bg-alt);
  border-bottom: 2px solid var(--border);
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
  position: relative;
}

.nav-header { 
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%; 
}

.brand { 
    font-size: 1.3rem; 
    font-weight: 800; 
    color: var(--primary); 
    letter-spacing: 0.5px; 
}

.mobile-menu-btn {
  display: block; 
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.5em;
  cursor: pointer;
  padding: 5px 10px;
  border-radius: 5px;
  margin-left: 15px; 
  transition: background 0.2s, color 0.2s;
}

.mobile-menu-btn:hover { 
    background: var(--primary); 
    color: white; 
    border-color: var(--primary); 
}

.nav-links {
  display: none; 
  position: absolute;
  top: 100%; 
  right: 30px;
  width: 260px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 12px 12px;
  padding: 10px;
  z-index: 9999;
  box-shadow: 0 15px 35px rgba(0,0,0,0.5);
  flex-direction: column;
  gap: 5px;
}

.nav-links.active { 
    display: flex; 
    animation: fadeIn 0.2s ease-in-out; 
}

.nav-btn {
  width: 100%;
  text-align: left;
  padding: 12px 15px;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--text); 
  font-size: 0.95rem;
  font-weight: 500; 
  transition: all 0.2s ease;
}

.nav-btn:hover, .nav-btn.active { 
    background: var(--primary); 
    color: white; 
    border-color: var(--primary); 
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Layouts & Containers --- */
.page { 
    max-width: 1400px; 
    width: 100%; 
    margin: 0 auto; 
    padding: 30px 20px; 
    overflow-x: hidden; 
}

.builder-workspace {
  display: flex; 
  gap: 20px; 
  align-items: flex-start;
  height: calc(100vh - 120px); 
  padding: 20px; 
  margin: 0 auto; 
  max-width: 1600px;
  width: 100%;
}

.preset-sidebar { 
    flex: 0 0 300px; 
    display: flex; 
    flex-direction: column; 
    height: 100%; 
    overflow-y: auto; 
    padding-right: 5px; 
    max-width: 100%; 
}

.editor-pane, .preview-pane { 
    flex: 1; 
    height: 100%; 
    overflow-y: auto; 
    overflow-x: hidden; 
    display: flex; 
    flex-direction: column; 
    gap: 20px; 
    padding-right: 5px; 
    max-width: 100%;
}

.scrollable::-webkit-scrollbar { 
    width: 8px; 
}

.scrollable::-webkit-scrollbar-track { 
    background: transparent; 
}

.scrollable::-webkit-scrollbar-thumb { 
    background: var(--border); 
    border-radius: 50px; 
}

.scrollable::-webkit-scrollbar-thumb:hover { 
    background: var(--primary); 
}

/* --- Components --- */
.card {
  background-color: var(--bg-alt); 
  border: 1px solid var(--border);
  border-radius: 20px; 
  padding: 25px; 
  margin-bottom: 20px;
  box-shadow: 0 10px 25px -5px rgba(0,0,0,0.2);
  max-width: 100%; 
}

.card-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    margin-bottom: 15px; 
    flex-wrap: wrap; 
}

.btn {
  background-color: var(--primary); 
  color: #fff; 
  border: none;
  padding: 12px 24px; 
  border-radius: 50px; 
  cursor: pointer; 
  font-weight: 600;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); 
  display: inline-block; 
  text-align: center; 
  box-shadow: 0 4px 10px rgba(59, 130, 246, 0.3);
}

.btn:hover { 
    background-color: var(--primary-hover); 
    transform: translateY(-2px); 
    box-shadow: 0 6px 15px rgba(59, 130, 246, 0.4); 
}

.btn:disabled { 
    opacity: 0.5; 
    cursor: not-allowed; 
    transform: none; 
    box-shadow: none; 
}

.btn-ghost { 
    background-color: transparent; 
    color: var(--text); 
    border: 2px solid var(--border); 
    box-shadow: none; 
}

.btn-ghost:hover { 
    background-color: var(--border); 
    color: #fff; 
    box-shadow: none; 
}

.btn-sm { 
    padding: 8px 16px; 
    font-size: 0.85rem; 
}

/* Forms, Inputs & Thick Touch Targets */
.form-grid { 
    display: grid; 
    gap: 15px; 
    min-width: 0; 
    max-width: 100%; 
}

.field { 
    display: flex; 
    flex-direction: column; 
    gap: 6px; 
    min-width: 0; 
    max-width: 100%; 
}

.field span { 
    font-size: 0.85rem; 
    color: var(--muted); 
    font-weight: 600; 
    text-transform: uppercase; 
    letter-spacing: 0.5px; 
}

/* JARVIS FIX: Prevent zooming on mobile inputs by using 16px font-size minimum */
input[type="text"], input[type="number"], input[type="email"], input[type="password"], select, textarea {
  width: 100%; 
  padding: 12px 16px; 
  background-color: var(--bg); 
  border: 2px solid var(--border);
  color: var(--text); 
  border-radius: 12px; 
  font-family: inherit; 
  font-size: 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
  max-width: 100%;
}

input:focus, select:focus, textarea:focus { 
    outline: none; 
    border-color: var(--primary); 
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2); 
}

textarea { 
    resize: vertical; 
    min-height: 80px; 
}

select { 
    min-height: 48px; 
    white-space: normal; 
    cursor: pointer; 
}

.toggle { 
    display: flex; 
    align-items: center; 
    gap: 10px; 
    cursor: pointer; 
    user-select: none; 
    font-weight: 500; 
}

.toggle input[type="checkbox"] { 
    width: 20px; 
    height: 20px; 
    accent-color: var(--primary); 
    cursor: pointer; 
}

.chip-group { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 10px; 
    margin-top: 10px; 
    min-width: 0; 
}

.chip { 
    background: var(--bg-alt); 
    border: 2px solid var(--primary); 
    padding: 8px 16px; 
    border-radius: 50px; 
    cursor: pointer; 
    transition: all 0.2s; 
    color: var(--text); 
    font-weight: 600; 
    box-shadow: 0 4px 6px rgba(0,0,0,0.1); 
    white-space: nowrap; 
}

.chip:hover { 
    background: var(--primary); 
    color: #fff; 
    transform: translateY(-2px); 
    box-shadow: 0 6px 12px rgba(59, 130, 246, 0.3); 
}

/* JARVIS FIX: Forces Profile Builder buttons to stack instead of stretch */
.builder-tabs {
    display: flex;
    flex-wrap: wrap; 
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 10px;
}

.builder-tabs .tab {
    flex: 1 1 auto; 
    white-space: nowrap;
}

.mode-toggle {
    display: flex;
    flex-wrap: wrap; 
    gap: 10px;
}

/* JARVIS FIX: Forces large Profile Images to shrink to fit the card */
.creature-card img {
    max-width: 100%;
    height: auto;
    object-fit: contain;
    border-radius: 12px;
}

.preview { 
    background: var(--bg); 
    padding: 20px; 
    border-radius: 12px; 
    border: 1px solid var(--border); 
    white-space: pre-wrap; 
    overflow-wrap: anywhere; 
    font-family: "Courier New", Courier, monospace; 
    min-height: 200px; 
    color: #e2e8f0; 
    font-size: 0.95em; 
    max-width: 100%; 
    overflow-x: auto; 
}

.stat-card { 
    background: var(--bg); 
    padding: 15px; 
    border-radius: 16px; 
    border: 1px solid var(--border); 
    text-align: center; 
}

input[type=range] { 
    -webkit-appearance: none; 
    width: 100%; 
    background: transparent; 
}

input[type=range]::-webkit-slider-thumb { 
    -webkit-appearance: none; 
    height: 20px; 
    width: 20px; 
    border-radius: 50%; 
    background: var(--primary); 
    cursor: pointer; 
    margin-top: -6px; 
    box-shadow: 0 2px 6px rgba(0,0,0,0.4); 
}

input[type=range]::-webkit-slider-runnable-track { 
    width: 100%; 
    height: 8px; 
    cursor: pointer; 
    background: var(--border); 
    border-radius: 50px; 
}

.drag-item { 
    position: relative; 
}

.drag-handle { 
    cursor: grab; 
    background: var(--bg); 
    border-bottom: 1px solid var(--border); 
    border-radius: 16px 16px 0 0; 
    padding: 12px 20px; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
}

.drag-handle:active { 
    cursor: grabbing; 
}

.toast { 
    visibility: hidden; 
    min-width: 250px; 
    background-color: var(--primary); 
    color: #fff; 
    text-align: center; 
    border-radius: 50px; 
    padding: 16px 24px; 
    position: fixed; 
    z-index: 1000; 
    left: 50%; 
    bottom: 30px; 
    transform: translateX(-50%); 
    font-weight: bold; 
    opacity: 0; 
    transition: opacity 0.3s, bottom 0.3s; 
    box-shadow: 0 10px 25px rgba(0,0,0,0.5); 
}

.toast.show { 
    visibility: visible; 
    opacity: 1; 
    bottom: 50px; 
}

/* === MOBILE OVERFLOW & RENDERING FIXES (PROFILES & STATS) === */
.creature-card, .creature-content, .stat-panel, .calculator-card { 
    max-width: 100%; 
    width: 100%; 
    box-sizing: border-box; 
    overflow-x: hidden; 
}

.creature-card p, .creature-card span { 
    word-break: break-word; 
}

.creature-header, .creature-tags { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 8px; 
    width: 100%; 
    min-width: 0; 
}

.creature-tags span { 
    white-space: normal; 
    text-align: center; 
    flex: 1 1 auto; 
}

.creature-stats { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); 
    gap: 10px; 
    width: 100%; 
    min-width: 0; 
}

table, .stat-matrix, .table-wrapper { 
    display: block; 
    width: 100%; 
    max-width: 100%; 
    overflow-x: auto; 
    white-space: nowrap; 
}

/* === TACTICAL MAP CLAMPS === */
#mapContainer, .map-window { 
    width: 100%; 
    max-width: 100%; 
    aspect-ratio: 1 / 1; 
    height: auto; 
    box-sizing: border-box; 
    margin: 0 auto; 
    padding: 0; 
    overflow: hidden; 
    background-color: var(--bg-alt); 
    position: relative; 
}

/* === GLOBAL RESPONSIVE ADJUSTMENTS === */
@media (max-width: 768px) {
  body, html { 
      width: 100vw; 
      max-width: 100vw; 
      overflow-x: hidden !important; 
      padding: 0; 
      margin: 0; 
  }
  
  .top-nav { 
      padding: 15px 10px; 
  }
  
  .nav-links { 
      right: 10px; 
      left: 10px; 
      width: auto; 
  } 

  .page { 
      padding: 10px !important; 
  }
  
  .builder-workspace { 
      flex-direction: column; 
      height: auto !important; 
      padding: 0 !important; 
      overflow: hidden !important; 
      max-width: 100%; 
  }
  
  .editor-pane { 
      padding: 0 !important; 
      margin: 0 !important; 
      max-width: 100%; 
      overflow-x: hidden !important; 
      height: auto !important; 
      overflow-y: visible !important; 
      width: 100%; 
  }
  
  .dashboard-grid, .form-grid, .preset-sidebar { 
      grid-template-columns: 1fr !important; 
      width: 100%; 
      flex: 0 0 auto; 
      max-width: 100%; 
  }

  /* JARVIS FIX: Dashboard Quick Widgets Mobile Clamp */
  #dashboardWidgetGrid {
      grid-template-columns: 1fr !important; 
  }

  /* JARVIS FIX: Threat Simulator Mobile Override */
  .threat-sim-grid {
      grid-template-columns: 1fr 1fr !important; 
  }

  .widget-menu {
      right: 0;
      left: auto;
      width: calc(100vw - 40px);
      max-width: 300px;
  }

  /* JARVIS FIX: Ensure lineage & tabs scroll horizontally */
  .lineage-tabs {
      overflow-x: auto;
      white-space: nowrap;
      -webkit-overflow-scrolling: touch;
      padding-bottom: 5px;
      margin-bottom: 15px;
  }
  
  .lineage-tab {
      flex: 0 0 auto;
  }

  .tree-workspace {
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
      padding: 20px 10px;
  }

  .modal-overlay .card {
      margin: 15px;
      max-height: 85vh;
      overflow-y: auto;
  }
  
  .hero { 
      flex-direction: column; 
      text-align: center; 
  }
  
  .hero > div { 
      width: 100%; 
      text-align: center !important; 
      align-items: center !important; 
  }
  
  .card { 
      padding: 15px; 
      max-width: 100%; 
      box-sizing: border-box; 
  }
  
  h1 { 
      font-size: 1.8em !important; 
  }
  
  .kd-display { 
      font-size: 2.5em; 
  }
  
  .btn, .toolbar-btn { 
      padding: 12px 16px; 
  }

  .vitals-container { 
      flex-wrap: wrap; 
      justify-content: center; 
      min-width: 0; 
      max-width: 100%; 
  }
  
  .vitals-container > span { 
      margin-left: 0 !important; 
      width: 100%; 
      text-align: center; 
      margin-top: 15px; 
      font-size: 1.8em !important; 
  }
  
  .preset-list { 
      max-height: 250px; 
      overflow-y: auto; 
      border: 1px solid var(--border); 
      border-radius: 8px; 
      padding: 5px; 
  }
  
  #system-manual, .floating-manual, .guide-sidebar { 
      position: relative !important; 
      width: 100% !important; 
      max-width: 100% !important; 
      height: auto !important; 
      float: none !important; 
      display: block; 
      margin-bottom: 20px; 
      z-index: 1; 
  }

  /* JARVIS FIX: Mobile Button Spacing & Wrapping for Stats page */
  .mode-toggle { 
      display: flex;
      flex-direction: row;
      flex-wrap: wrap;
      justify-content: center; 
      gap: 12px;
      margin-top: 20px;
      margin-bottom: 25px;
      width: 100%;
  }
  
  .mode-toggle button {
      flex: 1 1 calc(50% - 12px); 
      min-width: 140px;
      padding: 12px 10px;
      white-space: normal;
      height: auto;
  }
}
