/* =========================================
   1. VARIABLES & BASE SETUP
========================================= */
:root {
  --bg: #0f172a;
  --card-bg: #1e293b;
  --accent: #38bdf8;
  --accent-hover: #0284c7;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --success: #22c55e;
  --error: #ef4444;
  --border: #334155;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center; /* Forces the main container to the absolute center */
  padding: 2rem 1rem;
}

.container {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
}

/* =========================================
   2. NAVIGATION TABS
========================================= */
header {
  margin-bottom: 2rem;
  text-align: center;
  width: 100%;
}

header h1 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  color: var(--accent);
}

.nav-tabs {
  display: flex;
  justify-content: center; /* Centralizes the top navigation */
  gap: 0.5rem;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0.5rem;
  overflow-x: auto;
}

.nav-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  padding: 0.6rem 1.2rem;
  cursor: pointer;
  border-radius: 6px;
  font-weight: 600;
  white-space: nowrap;
  transition: all 0.2s;
}

.nav-btn:hover:not(.disabled) { color: var(--text); }
.nav-btn.active { background: var(--card-bg); color: var(--accent); }
.nav-btn.disabled { opacity: 0.4; cursor: not-allowed; }

/* Sub Navigation */
.sub-tabs {
  display: flex;
  justify-content: center;
  flex-wrap: wrap; /* Allows wrap on small screens */
  gap: 1rem;
  margin: 1.5rem 0;
}

.sub-btn {
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 1.2rem;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.9rem;
}

.sub-btn.active {
  background: var(--accent);
  color: #000;
  font-weight: 700;
  border-color: var(--accent);
}

/* =========================================
   3. PANELS & SETTINGS GRID
========================================= */
.tab-content, .panel { display: none; }
.tab-content.active, .panel.active { display: block; }

.panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
  justify-items: center; /* Centralizes dropdown boxes within grid */
}

.input-group { width: 100%; max-width: 200px; }
.input-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  text-align: center;
}

.input-group input, .input-group select {
  width: 100%;
  padding: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 1rem;
  text-align: center;
}

/* =========================================
   4. DRILL ARENA & INPUTS (CENTRALIZED)
========================================= */
.drill-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 100%;
  padding: 1rem 0;
}

form {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.target-number {
  font-size: 4.5rem;
  font-weight: 800;
  color: var(--accent);
  margin: 0.5rem 0;
}

/* Consolidated Input Rows (Shared across all tabs) */
.input-row, .power-arena-row, .triplet-input-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin: 1.5rem 0;
  width: 100%;
}

/* Consolidated Box Styling */
.factor-input, .power-box, .power-display-box, .triplet-slot {
  text-align: center;
  font-weight: 700;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}

.factor-input:focus, .power-box:focus, .triplet-slot:focus {
  outline: none;
  border-color: var(--accent);
}

.factor-input:disabled, .power-box:disabled, .triplet-slot:disabled {
  background: var(--card-bg);
  border-color: #475569;
  color: var(--accent);
  font-weight: 800;
  opacity: 1;
  cursor: default;
}

/* Specific Dimension Overrides */
.factor-input { width: 80px; height: 55px; font-size: 1.6rem; }
.power-box, .power-display-box { width: 120px; height: 65px; font-size: 1.8rem; }
.triplet-slot { width: 90px; height: 60px; font-size: 1.5rem; }

/* Display Box Specific (Non-editable) */
.power-display-box {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card-bg);
  border-color: #475569;
  color: var(--accent);
  font-weight: 800;
}

.operator, .triplet-comma {
  font-size: 2rem;
  color: var(--text-muted);
  font-weight: bold;
}

.power-input-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.power-input-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 700;
}

/* =========================================
   5. BUTTONS
========================================= */
.action-btn {
  background: var(--accent);
  color: #000;
  font-weight: 700;
  border: none;
  padding: 0.8rem 2rem;
  font-size: 1rem;
  border-radius: 8px;
  cursor: pointer;
  transition: 0.15s ease;
  margin-top: 1rem;
}
.action-btn:hover { background: var(--accent-hover); }

/* Flip Direction Button */
.direction-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #1e293b;
  border: 2px solid var(--accent);
  color: var(--accent);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-top: 1rem;
}
.direction-btn:hover {
  background: var(--accent);
  color: #000;
  transform: scale(1.08);
}
.direction-btn #direction-arrow { font-size: 1.4rem; line-height: 1; font-weight: 900; }
.direction-btn .direction-sub { font-size: 0.55rem; font-weight: 800; letter-spacing: 0.05em; }

/* =========================================
   6. FEEDBACK & STATS
========================================= */
.feedback {
  min-height: 48px;
  margin-top: 1.5rem;
  font-size: 1.05rem;
  font-weight: 600;
  text-align: center;
  width: 100%;
}
.feedback.success { color: var(--success); }
.feedback.error { color: var(--error); }

.all-factors {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

.stats-bar {
  display: flex;
  justify-content: center;
  gap: 2rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  margin-top: 1.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  width: 100%;
}
.stats-bar span { color: var(--text); font-weight: bold; }

/* =========================================
   7. REFERENCE TABLES & LISTS
========================================= */
.table-container {
  max-height: 480px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 100%;
}

.powers-table {
  width: 100%;
  border-collapse: collapse;
  text-align: center;
  font-size: 0.95rem;
}
.powers-table th {
  position: sticky;
  top: 0;
  background: #1e293b;
  color: var(--accent);
  padding: 0.75rem;
  border-bottom: 2px solid var(--border);
}
.powers-table td { padding: 0.6rem; border-bottom: 1px solid var(--border); }
.powers-table tr:nth-child(even) { background: rgba(255, 255, 255, 0.02); }

/* Box Grid layout (Table tab) */
.table-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.5rem;
  padding: 1rem;
}
.table-item {
  background: var(--bg);
  padding: 0.5rem;
  text-align: center;
  border-radius: 6px;
  font-size: 0.95rem;
  border: 1px solid var(--border);
}

/* 3-Column Triplet Layout */
.triplets-columns-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.2rem;
  align-items: start;
}
.triplet-column { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.column-header { padding: 0.75rem 1rem; font-weight: 700; text-align: center; font-size: 0.95rem; text-transform: uppercase; border-bottom: 1px solid var(--border); }
.column-header.most { background: rgba(34, 197, 94, 0.15); color: #4ade80; }
.column-header.somewhat { background: rgba(56, 189, 248, 0.15); color: #38bdf8; }
.column-header.rare { background: rgba(249, 115, 22, 0.15); color: #fb923c; }
.triplet-list { display: flex; flex-direction: column; padding: 0.5rem; gap: 0.4rem; }
.triplet-chip { padding: 0.6rem; background: var(--card-bg); border-radius: 6px; text-align: center; font-size: 1.05rem; font-weight: 600; border: 1px solid var(--border); }

/* =========================================
   8. MOBILE RESPONSIVENESS
========================================= */
@media (max-width: 600px) {
  header h1 { font-size: 1.6rem; }
  .nav-btn { font-size: 0.85rem; padding: 0.5rem 0.8rem; }
  .sub-btn { font-size: 0.8rem; padding: 0.4rem 0.8rem; }
  
  .target-number { font-size: 2.8rem !important; }
  #multiply-q-display { font-size: 2.5rem !important; }
  .operator, .triplet-comma { font-size: 2rem !important; margin: 0 5px !important; }
  
  .factor-input, .power-box, .power-display-box {
    width: 80px !important;
    height: 55px !important;
    font-size: 1.3rem !important;
  }
  
  #multiply-answer {
    width: 100px !important;
    height: 60px !important;
    font-size: 1.8rem !important;
  }
  
  .triplet-slot {
    width: 65px !important;
    height: 50px !important;
    font-size: 1.2rem !important;
  }

  .input-row, .power-arena-row, .triplet-input-row {
    gap: 0.5rem;
    flex-wrap: nowrap;
  }

  .direction-btn { width: 40px; height: 40px; margin-top: 1.5rem; }
  .direction-btn #direction-arrow { font-size: 1.2rem; }
  .direction-btn .direction-sub { display: none; }

  .powers-table th, .powers-table td { padding: 0.4rem; font-size: 0.85rem; }
  
  .stats-bar { gap: 1rem; flex-wrap: wrap; }

  /* Fix for navigation tabs getting cut off on mobile */
  .nav-tabs {
    justify-content: flex-start;
    padding: 0.5rem; 
  }
}
