/* ===== Global box-sizing ===== */
.baseball-war-calculator-container,
.baseball-war-calculator-container *,
.baseball-war-calculator-container *::before,
.baseball-war-calculator-container *::after {
  box-sizing: border-box;
}

/* ===== Main container with CSS variables ===== */
.baseball-war-calculator-container {
  /* Background colors - Light mode */
  --bg-primary: #f5f5f0;
  --bg-secondary: #fff;
  --bg-section: #fff;
  
  /* Borders */
  --border-color: #333;
  
  /* Text colors */
  --text-primary: #222;
  --text-secondary: #555;
  --text-light: #666;
  
  /* Brand colors */
  --color-accent: #3498db;
  --color-success: #27ae60;
  --color-warning: #f39c12;
  --color-danger: #e74c3c;
  --color-purple: #9b59b6;
  --color-teal: #1abc9c;
  
  /* Component colors */
  --color-batting: #3182ce;
  --color-baserunning: #38a169;
  --color-fielding: #dd6b20;
  --color-pitching: #805ad5;
  
  /* Shadows (neobrutalism) */
  --shadow-sm: 2px 2px 0 rgba(0,0,0,0.1);
  --shadow-md: 4px 4px 0 rgba(0,0,0,0.15);
  --shadow-lg: 8px 8px 0 rgba(0,0,0,0.15);
  
  /* Border radius */
  --radius-container: 8px;
  --radius-section: 6px;
  --radius-button: 4px;
  --radius-input: 4px;
  
  /* Input focus */
  --input-focus-bg: #fffacd;
  
  /* Header title */
  --title-color: #2c3e50;
  --title-shadow: 2px 2px 0 rgba(255,255,255,0.5);
  
  /* Button hover background */
  --btn-hover-overlay: rgba(0,0,0,0.1);
  
  /* Main container styles */
  position: relative;
  max-width: 1000px;
  width: 100%;
  margin: 8px auto;
  padding: 8px;
  background: var(--bg-primary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-container);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Malgun Gothic', sans-serif;
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  line-height: 1.5;
}

/* ===== Manual dark mode ===== */
.baseball-war-calculator-container.dark {
  --bg-primary: #1a1a1a;
  --bg-secondary: #2d2d2d;
  --bg-section: #2d2d2d;
  --border-color: #e0e0e0;
  --text-primary: #e8e8e8;
  --text-secondary: #b0b0b0;
  --text-light: #909090;
  --color-accent: #5dade2;
  --color-success: #52c77a;
  --color-warning: #f5b041;
  --color-danger: #ec7063;
  --color-purple: #af7ac5;
  --color-teal: #48d1cc;
  --color-batting: #63b3ed;
  --color-baserunning: #68d391;
  --color-fielding: #f6ad55;
  --color-pitching: #b794f4;
  --shadow-sm: 2px 2px 0 rgba(255,255,255,0.08);
  --shadow-md: 4px 4px 0 rgba(255,255,255,0.12);
  --shadow-lg: 8px 8px 0 rgba(255,255,255,0.12);
  --input-focus-bg: #3a3a3a;
  --title-color: #7fb3d5;
  --title-shadow: 2px 2px 0 rgba(0,0,0,0.5);
  --btn-hover-overlay: rgba(255,255,255,0.1);
}

/* ===== System dark mode auto detection ===== */
@media (prefers-color-scheme: dark) {
  .baseball-war-calculator-container:not(.dark):not(.light) {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-section: #2d2d2d;
    --border-color: #e0e0e0;
    --text-primary: #e8e8e8;
    --text-secondary: #b0b0b0;
    --text-light: #909090;
    --color-accent: #5dade2;
    --color-success: #52c77a;
    --color-warning: #f5b041;
    --color-danger: #ec7063;
    --color-purple: #af7ac5;
    --color-teal: #48d1cc;
    --color-batting: #63b3ed;
    --color-baserunning: #68d391;
    --color-fielding: #f6ad55;
    --color-pitching: #b794f4;
    --shadow-sm: 2px 2px 0 rgba(255,255,255,0.08);
    --shadow-md: 4px 4px 0 rgba(255,255,255,0.12);
    --shadow-lg: 8px 8px 0 rgba(255,255,255,0.12);
    --input-focus-bg: #3a3a3a;
    --title-color: #7fb3d5;
    --title-shadow: 2px 2px 0 rgba(0,0,0,0.5);
    --btn-hover-overlay: rgba(255,255,255,0.1);
  }
}

/* ===== Dark mode toggle button ===== */
.dark-mode-toggle {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 6px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-button);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
  font-size: 15.5px;
  font-weight: 600;
  color: var(--text-primary);
  z-index: 10;
}

.dark-mode-toggle:hover {
  transform: translate(0.5px, 0.5px);
  box-shadow: 1.5px 1.5px 0 rgba(0,0,0,0.15);
}

.dark-mode-toggle:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

.toggle-icon {
  display: inline-block;
  line-height: 1;
}

/* ===== Header ===== */
.calculator-header {
  text-align: center;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border-color);
}

.calculator-header h2 {
  margin: 0 0 4px 0;
  font-size: 28px;
  font-weight: 700;
  color: var(--title-color);
  text-shadow: var(--title-shadow);
  line-height: 1.2;
}

.subtitle {
  margin: 0;
  font-size: 13.5px;
  color: var(--text-light);
  line-height: 1.4;
}

/* ===== Main grid (2-column layout) ===== */
.calculator-main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* ===== Section common styles ===== */
.input-section,
.result-section {
  background: var(--bg-section);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-section);
  padding: 8px;
  box-shadow: var(--shadow-md);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 8px 0;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-color);
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.input-section .section-title {
  color: var(--color-accent);
}

.result-section .section-title {
  color: var(--color-success);
}

.section-title svg {
  flex-shrink: 0;
  stroke: currentColor;
}

/* ===== Input group ===== */
.input-group {
  margin-bottom: 8px;
}

.input-group label {
  display: block;
  margin-bottom: 4px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.input-group select,
.input-group input {
  width: 100%;
  padding: 7px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-input);
  color: var(--text-primary);
  font-size: 14px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Malgun Gothic', sans-serif;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
}

.input-group input[type="number"] {
  font-family: 'Courier New', monospace;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.input-group select:focus,
.input-group input:focus {
  outline: none;
  background: var(--input-focus-bg);
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.1);
}

.input-group input[readonly] {
  background: var(--bg-primary);
  color: var(--text-light);
  cursor: not-allowed;
}

.input-group input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== Tab container ===== */
.tab-container {
  margin-bottom: 8px;
}

.tab-buttons {
  display: flex;
  gap: 2px;
  border-bottom: 2px solid var(--border-color);
  margin-bottom: 8px;
}

.tab-btn {
  flex: 1;
  padding: 8px 4px;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Malgun Gothic', sans-serif;
}

.tab-btn:hover {
  color: var(--color-accent);
  background: var(--bg-primary);
}

.tab-btn.active {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
  background: var(--bg-primary);
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* ===== Stat grid ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

/* ===== Button group ===== */
.btn-group {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

/* ===== Calculate button (primary action) - 1.5px border ===== */
.btn-calculate {
  flex: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  background: var(--color-accent);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-button);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: 4px 4px 0 rgba(0,0,0,0.2);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Malgun Gothic', sans-serif;
}

.btn-calculate:hover {
  filter: brightness(1.05);
  transform: translate(1px, 1px);
  box-shadow: 3px 3px 0 rgba(0,0,0,0.2);
}

.btn-calculate:active {
  transform: translate(4px, 4px);
  box-shadow: none;
}

.btn-calculate svg {
  flex-shrink: 0;
}

/* ===== Reset button (secondary) - 1px border ===== */
.btn-reset {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 10px;
  background: var(--color-warning);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-button);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: 2px 2px 0 rgba(0,0,0,0.2);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Malgun Gothic', sans-serif;
}

.btn-reset:hover {
  filter: brightness(1.05);
  transform: translate(0.5px, 0.5px);
  box-shadow: 1.5px 1.5px 0 rgba(0,0,0,0.2);
}

.btn-reset:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

.btn-reset svg {
  flex-shrink: 0;
}

/* ===== Result area ===== */
.war-result {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ===== Total WAR display ===== */
.war-total {
  text-align: center;
  padding: 12px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-section);
  box-shadow: var(--shadow-sm);
}

.war-label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  font-weight: 600;
}

.war-value {
  display: block;
  font-size: 42px;
  font-weight: 700;
  color: var(--color-accent);
  line-height: 1;
  font-family: 'Courier New', monospace;
}

.war-rating {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  background: var(--text-light);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-button);
}

/* ===== Chart container ===== */
.war-chart-container {
  height: 180px;
  padding: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-section);
}

/* ===== WAR components ===== */
.war-components {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.component-item {
  padding: 10px 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-section);
  text-align: center;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.component-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  border-radius: var(--radius-section) 0 0 var(--radius-section);
}

.component-item.batting::before {
  background: var(--color-batting);
}

.component-item.baserunning::before {
  background: var(--color-baserunning);
}

.component-item.fielding::before {
  background: var(--color-fielding);
}

.component-item.pitching::before {
  background: var(--color-pitching);
}

.component-label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  font-weight: 600;
}

.component-value {
  display: block;
  font-size: 22px;
  font-weight: 700;
  color: var(--color-accent);
  font-family: 'Courier New', monospace;
}

/* ===== Additional stats ===== */
.additional-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.stat-item {
  padding: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-section);
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 11px;
  color: var(--text-light);
  margin-bottom: 2px;
  font-weight: 500;
}

.stat-value {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  font-family: 'Courier New', monospace;
}

/* ===== Toast notification - fixed bottom ===== */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-button);
  padding: 10px 15px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s;
  z-index: 1000;
  max-width: 300px;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.toast-content {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.toast-message {
  font-size: 13.5px;
  color: var(--text-primary);
  font-weight: 600;
}

/* ===== Responsive - Tablet (768px or less) ===== */
@media screen and (max-width: 768px) {
  .baseball-war-calculator-container {
    margin: 6px 5px;
    width: calc(100% - 10px);
    padding: 7px;
  }
  
  .calculator-main {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .war-components {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .calculator-header h2 {
    font-size: 24px;
  }
  
  .section-title {
    font-size: 15px;
  }
  
  .subtitle {
    font-size: 12.5px;
  }
  
  .dark-mode-toggle {
    top: 7px;
    right: 7px;
    padding: 5px 8px;
    font-size: 14px;
  }
  
  .war-value {
    font-size: 36px;
  }
}

/* ===== Responsive - Mobile (480px or less) ===== */
@media screen and (max-width: 480px) {
  .baseball-war-calculator-container {
    margin: 5px 3px;
    width: calc(100% - 6px);
    padding: 6px;
    border-width: 1px;
  }
  
  .input-section,
  .result-section {
    padding: 6px;
  }
  
  .calculator-header h2 {
    font-size: 22px;
  }
  
  .subtitle {
    font-size: 12px;
  }
  
  .tab-buttons {
    flex-wrap: wrap;
  }
  
  .tab-btn {
    font-size: 12px;
    padding: 6px 4px;
    flex: 1 1 45%;
  }
  
  .stat-grid {
    grid-template-columns: 1fr;
  }
  
  .btn-group {
    flex-direction: column;
  }
  
  .btn-calculate,
  .btn-reset {
    width: 100%;
    flex: none;
  }
  
  .btn-calculate {
    font-size: 14px;
  }
  
  .btn-reset {
    font-size: 12.5px;
  }
  
  .war-value {
    font-size: 32px;
  }
  
  .component-value {
    font-size: 18px;
  }
  
  .war-components {
    grid-template-columns: 1fr;
  }
  
  .additional-stats {
    grid-template-columns: 1fr;
  }
  
  .toast {
    bottom: 10px;
    right: 10px;
    left: 10px;
    max-width: none;
  }
}