:root {
  /* Dark Theme (Default) */
  --bg-primary: #0b0f19;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.75);
  --bg-card-hover: rgba(31, 41, 55, 0.85);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(99, 102, 241, 0.5);

  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;

  --accent-primary: #6366f1;
  --accent-primary-hover: #4f46e5;
  --accent-cyan: #06b6d4;
  --accent-emerald: #10b981;
  --accent-emerald-light: #34d399;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;

  --gradient-primary: linear-gradient(135deg, #6366f1 0%, #06b6d4 100%);
  --gradient-emerald: linear-gradient(135deg, #10b981 0%, #059669 100%);
  --gradient-accent: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 50%, #ec4899 100%);
  --glow-primary: 0 0 25px rgba(99, 102, 241, 0.35);
  --glow-emerald: 0 0 25px rgba(16, 185, 129, 0.35);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);

  --font-family: 'Plus Jakarta Sans', 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Outfit', 'Noto Sans JP', sans-serif;
}

[data-theme="light"] {
  --bg-primary: #f3f4f8;
  --bg-secondary: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-card-hover: rgba(255, 255, 255, 0.95);
  --border-color: rgba(0, 0, 0, 0.08);
  --border-focus: rgba(99, 102, 241, 0.4);

  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-muted: #9ca3af;

  --glow-primary: 0 0 20px rgba(99, 102, 241, 0.15);
  --glow-emerald: 0 0 20px rgba(16, 185, 129, 0.15);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.1);
}

/* Reset & Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: inherit;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-family);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  transition: background-color 0.3s ease, color 0.3s ease;
  line-height: 1.6;
}

/* Background Ambient Lighting */
.background-decorations {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.gradient-sphere {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.25;
  transition: all 0.5s ease;
}

.sphere-1 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, #6366f1, #3b82f6);
  top: -100px;
  right: -100px;
}

.sphere-2 {
  width: 450px;
  height: 450px;
  background: radial-gradient(circle, #10b981, #06b6d4);
  bottom: 50px;
  left: -150px;
}

.sphere-3 {
  width: 350px;
  height: 350px;
  background: radial-gradient(circle, #ec4899, #8b5cf6);
  top: 40%;
  left: 30%;
  opacity: 0.12;
}

/* App Container */
.app-container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  position: relative;
  z-index: 1;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-badge {
  width: 48px;
  height: 48px;
  background: var(--gradient-primary);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: var(--glow-primary);
}

.logo-badge svg {
  width: 26px;
  height: 26px;
}

.app-title {
  font-family: var(--font-display);
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #ffffff 30%, #94a3b8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

[data-theme="light"] .app-title {
  background: linear-gradient(135deg, #0f172a 30%, #475569 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.app-subtitle {
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.icon-button {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: all 0.2s ease;
}

.icon-button:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-primary);
  transform: translateY(-2px);
}

.icon-button svg {
  width: 20px;
  height: 20px;
}

/* Tabs */
.mode-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
  background: rgba(0, 0, 0, 0.15);
  padding: 6px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
}

[data-theme="light"] .mode-tabs {
  background: rgba(0, 0, 0, 0.04);
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
}

.tab-btn svg {
  width: 18px;
  height: 18px;
}

.tab-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
}

.tab-btn.active {
  background: var(--bg-secondary);
  color: var(--accent-primary);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
}

/* Main Grid Layout */
.main-grid {
  display: grid;
  grid-template-columns: 390px 1fr;
  gap: 24px;
  align-items: start;
}

@media (max-width: 1024px) {
  .main-grid {
    grid-template-columns: 1fr;
  }
}

/* Card Base */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 24px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-md);
  transition: border-color 0.25s ease;
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.14);
}

[data-theme="light"] .card:hover {
  border-color: rgba(0, 0, 0, 0.12);
}

.card-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.card-title svg {
  color: var(--accent-primary);
  width: 22px;
  height: 22px;
}

/* Tab Contents */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

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

/* Form Controls */
.form-group {
  margin-bottom: 22px;
}

.label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.label-row label {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.input-display {
  display: flex;
  align-items: center;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-weight: 700;
  transition: border-color 0.2s ease;
}

.input-display:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.input-display input {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  text-align: right;
  width: 110px;
  outline: none;
}

.currency, .unit {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-left: 2px;
  margin-right: 2px;
}

/* Range Slider */
.range-slider {
  width: 100%;
  height: 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  outline: none;
  -webkit-appearance: none;
  cursor: pointer;
  margin: 12px 0 14px;
}

[data-theme="light"] .range-slider {
  background: #e2e8f0;
}

.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-primary);
  box-shadow: var(--glow-primary);
  border: 2px solid #ffffff;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.range-slider::-webkit-slider-thumb:hover {
  transform: scale(1.18);
}

/* Chips */
.chip-container {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip-btn, .chip-btn-period, .chip-target {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chip-btn:hover, .chip-btn-period:hover, .chip-target:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.2);
}

.chip-btn.active, .chip-btn-period.active, .chip-target.active {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

/* Preset Returns */
.preset-returns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.preset-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
}

.preset-btn:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.2);
}

.preset-btn.active {
  background: rgba(99, 102, 241, 0.12);
  border-color: var(--accent-primary);
}

.rate-name {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.preset-btn.active .rate-name {
  color: var(--text-primary);
}

.rate-val {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-cyan);
}

.preset-btn.active .rate-val {
  color: var(--accent-primary);
}

/* Quota Meter */
.quota-container {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
}

.quota-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.quota-title {
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
}

.quota-title svg {
  width: 16px;
  height: 16px;
  color: var(--accent-emerald);
}

.quota-ratio {
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent-emerald);
}

.quota-bar-bg {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

[data-theme="light"] .quota-bar-bg {
  background: #e2e8f0;
}

.quota-bar-fill {
  height: 100%;
  background: var(--gradient-emerald);
  border-radius: 4px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.quota-footer {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Target Mode Specifics */
.target-result-card {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.12) 0%, rgba(6, 182, 212, 0.08) 100%);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: var(--radius-lg);
  padding: 16px;
  text-align: center;
  margin-top: 16px;
}

.target-result-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.target-result-value {
  font-family: var(--font-display);
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--accent-cyan);
}

.target-result-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.compare-desc {
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin-bottom: 18px;
  line-height: 1.5;
}

/* Results Area */
.results-area {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Metric Cards */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

@media (max-width: 860px) {
  .metrics-grid {
    grid-template-columns: 1fr;
  }
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 20px;
  display: flex;
  gap: 16px;
  align-items: flex-start;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.metric-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.16);
}

.metric-card.highlight {
  border-color: rgba(99, 102, 241, 0.4);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(17, 24, 39, 0.8) 100%);
}

.metric-card.tax-benefit {
  border-color: rgba(16, 185, 129, 0.4);
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.1) 0%, rgba(17, 24, 39, 0.8) 100%);
}

.metric-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.metric-icon.blue {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
}

.metric-icon.green {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
}

.metric-icon svg {
  width: 22px;
  height: 22px;
}

.metric-body {
  overflow: hidden;
}

.metric-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.metric-value {
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  white-space: nowrap;
}

.primary-glow {
  color: #a5b4fc;
}

.tax-glow {
  color: var(--accent-emerald-light);
}

.metric-sub {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Chart Card */
.chart-card {
  display: flex;
  flex-direction: column;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.chart-subtitle {
  font-size: 0.84rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.chart-legend-custom {
  display: flex;
  gap: 16px;
  align-items: center;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.principal-dot {
  background-color: #6366f1;
}

.profit-dot {
  background-color: #10b981;
}

.taxable-dot {
  background-color: #94a3b8;
}

.chart-wrapper {
  height: 340px;
  position: relative;
  width: 100%;
}

/* Table Card */
.table-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.secondary-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

.secondary-btn svg {
  width: 16px;
  height: 16px;
}

.table-responsive {
  max-height: 280px;
  overflow-y: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

/* Custom Scrollbar */
.table-responsive::-webkit-scrollbar {
  width: 6px;
}

.table-responsive::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

.table-responsive::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;
  font-size: 0.88rem;
}

.data-table th, .data-table td {
  padding: 12px 16px;
}

.data-table th {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 2;
  border-bottom: 1px solid var(--border-color);
}

.data-table th:first-child, .data-table td:first-child {
  text-align: left;
}

.data-table tbody tr {
  border-bottom: 1px solid var(--border-color);
  transition: background-color 0.15s ease;
}

.data-table tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.03);
}

[data-theme="light"] .data-table tbody tr:hover {
  background-color: rgba(0, 0, 0, 0.02);
}

.profit-text {
  color: var(--accent-emerald);
  font-weight: 600;
}

.tax-text {
  color: var(--accent-emerald-light);
  font-weight: 600;
}

/* Knowledge Card */
.knowledge-card {
  border: 1px solid rgba(99, 102, 241, 0.2);
  background: linear-gradient(135deg, rgba(17, 24, 39, 0.9) 0%, rgba(30, 27, 75, 0.4) 100%);
}

.knowledge-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.knowledge-header svg {
  color: var(--accent-amber);
  width: 20px;
  height: 20px;
}

.knowledge-header h4 {
  font-size: 0.98rem;
  font-weight: 700;
}

.knowledge-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

@media (max-width: 860px) {
  .knowledge-grid {
    grid-template-columns: 1fr;
  }
}

.knowledge-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.k-num {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--accent-primary);
  opacity: 0.7;
}

.k-content strong {
  display: block;
  font-size: 0.88rem;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.k-content p {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Footer */
.app-footer {
  margin-top: 36px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.copyright {
  margin-top: 8px;
  color: var(--text-secondary);
}
