:root {
  --bg-app: #0f172a;
  --bg-panel: #1e293b;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --border: #334155;
  --input-bg: #0f172a;
  --radius: 12px;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
}

[data-theme="light"] {
  --bg-app: #f1f5f9;
  --bg-panel: #ffffff;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --input-bg: #f8fafc;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
}

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

body {
  font-family: var(--font-main);
  background-color: var(--bg-app);
  color: var(--text);
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

h1 {
  text-align: center;
  font-size: 2rem;
  margin-bottom: 2rem;
  font-weight: 700;
  letter-spacing: -0.025em;
}

/* Category Section */
.category-section {
  margin-bottom: 2rem;
}

.category-section h2 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 0.75rem;
}

.category-btn {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 1rem 0.5rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 500;
}

.category-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.category-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* Converter Section */
.converter-section {
  background: var(--bg-panel);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.converter-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 1.5rem;
  align-items: center;
}

.unit-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-header h3 {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 600;
}

.clear-btn {
  background: transparent;
  border: none;
  color: var(--primary);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

.clear-btn:hover {
  background: rgba(59, 130, 246, 0.1);
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.value-input {
  font-size: 2rem;
  padding: 1rem;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  width: 100%;
  font-family: 'JetBrains Mono', monospace;
  transition: border-color 0.2s;
}

.value-input:focus {
  outline: none;
  border-color: var(--primary);
}

.unit-select {
  padding: 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}

.unit-description {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.conversion-arrow {
  display: flex;
  justify-content: center;
}

.swap-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}

.swap-btn:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  transform: rotate(180deg);
}

.quick-actions {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.action-btn {
  flex: 1;
  padding: 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-app);
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.action-btn:hover {
  background: var(--bg-panel);
  border-color: var(--primary);
  color: var(--primary);
}

.formula-section {
  margin-top: 1.5rem;
  background: rgba(59, 130, 246, 0.05);
  border-radius: var(--radius);
  padding: 1rem;
  border: 1px dashed var(--primary);
}

.formula-section h3 {
  font-size: 0.9rem;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.formula-display {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  color: var(--text);
}

/* Common Conversions */
.common-conversions-section {
  margin-top: 3rem;
}

.conversions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.conversion-card {
  background: var(--bg-panel);
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.conversion-card strong {
  color: var(--text);
}

/* Assist & Recent */
.assist-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-top: 2rem;
}

.assist-card, .recent-card {
  background: var(--bg-panel);
  padding: 1.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.assist-input {
  width: 100%;
  padding: 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  margin-top: 0.5rem;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.chip {
  background: var(--bg-app);
  padding: 0.25rem 0.75rem;
  border-radius: 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  cursor: pointer;
}

.chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.recent-list {
  list-style: none;
  margin-top: 1rem;
}

.recent-list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  color: var(--text-muted);
}

.recent-list li:last-child {
  border-bottom: none;
}

/* Reference Section */
.reference-section {
  margin-top: 3rem;
}

.reference-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}

.reference-tab {
  background: transparent;
  border: none;
  padding: 0.5rem 1rem;
  color: var(--text-muted);
  cursor: pointer;
  font-weight: 500;
  border-radius: 6px;
}

.reference-tab.active {
  background: var(--bg-panel);
  color: var(--primary);
}

.reference-content {
  display: none;
}

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

.reference-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
}

.reference-item h4 {
  color: var(--primary);
  margin-bottom: 0.75rem;
}

.reference-item ul {
  list-style: none;
}

.reference-item li {
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  padding-left: 1rem;
  border-left: 2px solid var(--border);
}

/* Theme Toggle */
.theme-toggle {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: transform 0.2s;
}

.theme-toggle:hover {
  transform: scale(1.1);
}

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

@media (max-width: 768px) {
  .converter-grid {
    grid-template-columns: 1fr;
  }
  
  .conversion-arrow {
    transform: rotate(90deg);
  }
  
  .swap-btn:hover {
    transform: rotate(270deg);
  }
  
  .assist-row {
    grid-template-columns: 1fr;
  }
}
