/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #06080d;
  --surface: #0d1117;
  --surface-2: #151b27;
  --border: #1e293b;
  --border-light: #2a3a52;
  --primary: #818cf8;
  --primary-light: #a5b4fc;
  --primary-dark: #6366f1;
  --accent: #22d3ee;
  --accent-dark: #06b6d4;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --success: #34d399;
  --error: #f87171;
  --warning: #fbbf24;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

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

img { max-width: 100%; display: block; }

/* ===== NAVIGATION ===== */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(6,8,13,0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
}

.nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.nav-logo {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-logo .logo-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--bg);
}

.nav-links {
  display: flex;
  gap: 2px;
  list-style: none;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.nav-links a {
  color: var(--text-muted);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.2s;
  white-space: nowrap;
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--text);
  background: var(--surface-2);
}

.nav-mobile-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
}

/* ===== HERO ===== */
.hero {
  text-align: center;
  padding: 80px 24px 48px;
  position: relative;
}

.hero::before {
  content: '';
  position: absolute;
  top: -100px;
  left: 50%;
  transform: translateX(-50%);
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(99,102,241,0.08) 0%, transparent 70%);
  pointer-events: none;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--primary-light);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: 100px;
  margin-bottom: 24px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.hero h1 {
  font-size: clamp(2.2rem, 5vw, 3.5rem);
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: 16px;
  background: linear-gradient(135deg, var(--text), var(--primary-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero p {
  font-size: 1.15rem;
  color: var(--text-muted);
  max-width: 640px;
  margin: 0 auto 32px;
}

/* ===== CALCULATOR SECTION ===== */
.calculator-section {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px 64px;
}

.calc-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.calc-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 12px;
}

.calc-toolbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.calc-toolbar label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.size-btns {
  display: flex;
  gap: 4px;
}

.size-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}

.size-btn:hover { border-color: var(--border-light); color: var(--text); }
.size-btn.active {
  background: var(--primary-dark);
  border-color: var(--primary);
  color: white;
}

.type-select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: var(--font);
  cursor: pointer;
}

.type-select:focus { outline: none; border-color: var(--primary); }

.calc-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 400px;
}

.calc-input {
  padding: 32px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.calc-output {
  padding: 32px;
  overflow-y: auto;
  max-height: 600px;
}

.section-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 8px;
}

/* Matrix Input Grid */
.matrix-input-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
}

.matrix-bracket {
  font-size: 4rem;
  color: var(--primary);
  font-weight: 100;
  line-height: 1;
  user-select: none;
}

.matrix-grid {
  display: inline-grid;
  gap: 6px;
  padding: 8px;
}

.matrix-grid input {
  width: 60px;
  height: 42px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  text-align: center;
  font-size: 0.95rem;
  font-family: var(--mono);
  font-weight: 500;
  transition: all 0.2s;
}

.matrix-grid input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
  background: var(--bg);
}

.matrix-grid input::placeholder { color: var(--text-dim); }

.calc-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s;
  border: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: white;
  box-shadow: 0 2px 12px rgba(99,102,241,0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(99,102,241,0.4);
}

.btn-secondary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.btn-secondary:hover { border-color: var(--border-light); color: var(--text); }

.btn-sm { padding: 6px 14px; font-size: 0.8rem; }

/* Output / Results */
.result-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-dim);
  text-align: center;
  gap: 12px;
}

.result-empty-icon { font-size: 2.5rem; opacity: 0.4; }

.result-group {
  margin-bottom: 28px;
  animation: fadeInUp 0.3s ease;
}

.result-group h3 {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary-light);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.matrix-display {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-bottom: 8px;
}

.matrix-display .bracket {
  font-size: 3rem;
  color: var(--primary);
  font-weight: 100;
  line-height: 1;
  user-select: none;
}

.matrix-display-grid {
  display: inline-grid;
  gap: 2px;
  padding: 6px;
}

.matrix-display-cell {
  width: 64px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  background: var(--surface-2);
  border-radius: 4px;
}

.matrix-display-cell.highlight {
  color: var(--accent);
  font-weight: 700;
}

.matrix-display-cell.pivot {
  background: rgba(99,102,241,0.15);
  color: var(--primary-light);
}

.matrix-label {
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  margin-right: 12px;
  min-width: 24px;
}

.matrix-equation {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.matrix-equation .eq-symbol {
  font-size: 1.3rem;
  color: var(--text-dim);
  font-weight: 300;
}

/* Steps */
.steps-container {
  margin-top: 24px;
}

.steps-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: 1px solid var(--border);
  color: var(--primary-light);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: var(--font);
  transition: all 0.2s;
  width: 100%;
  justify-content: center;
}

.steps-toggle:hover { background: var(--surface-2); }

.steps-list {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.step-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  animation: fadeInUp 0.3s ease;
}

.step-number {
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.step-text {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.step-text code {
  font-family: var(--mono);
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85rem;
  color: var(--accent);
}

/* ===== CARDS GRID ===== */
.cards-section {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px 80px;
}

.cards-section h2 {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.cards-section > p {
  color: var(--text-muted);
  margin-bottom: 40px;
  font-size: 1.05rem;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  transition: all 0.25s;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card:hover {
  border-color: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(99,102,241,0.1);
}

.card-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 800;
  font-family: var(--mono);
}

.card-icon.lu { background: rgba(99,102,241,0.12); color: var(--primary-light); }
.card-icon.qr { background: rgba(34,211,238,0.12); color: var(--accent); }
.card-icon.svd { background: rgba(52,211,153,0.12); color: var(--success); }
.card-icon.chol { background: rgba(251,191,36,0.12); color: var(--warning); }
.card-icon.eigen { background: rgba(248,113,113,0.12); color: var(--error); }

.card h3 {
  font-size: 1.1rem;
  font-weight: 700;
}

.card p {
  color: var(--text-muted);
  font-size: 0.9rem;
  flex: 1;
}

.card-link {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary-light);
  display: flex;
  align-items: center;
  gap: 4px;
}

.card-link:hover { gap: 8px; }

/* ===== FEATURES ===== */
.features-section {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px 80px;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 24px;
  margin-top: 40px;
}

.feature {
  display: flex;
  gap: 14px;
}

.feature-icon {
  width: 40px;
  height: 40px;
  background: var(--surface-2);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.feature h4 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 4px;
}

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

/* ===== EDUCATIONAL CONTENT ===== */
.edu-section {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 24px 80px;
}

.edu-section h2 {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 16px;
  margin-top: 48px;
}

.edu-section h2:first-child { margin-top: 0; }

.edu-section h3 {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 32px 0 12px;
  color: var(--primary-light);
}

.edu-section p {
  color: var(--text-muted);
  margin-bottom: 16px;
  font-size: 1rem;
  line-height: 1.8;
}

.edu-section ul, .edu-section ol {
  color: var(--text-muted);
  margin-bottom: 16px;
  padding-left: 24px;
}

.edu-section li {
  margin-bottom: 8px;
  line-height: 1.7;
}

.edu-section code {
  font-family: var(--mono);
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  color: var(--accent);
}

.edu-section .formula-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 20px 24px;
  margin: 20px 0;
  text-align: center;
  font-family: var(--mono);
  font-size: 1.1rem;
  color: var(--primary-light);
  letter-spacing: 0.02em;
}

/* ===== FOOTER ===== */
.footer {
  border-top: 1px solid var(--border);
  padding: 40px 24px;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.footer-links {
  display: flex;
  gap: 24px;
  list-style: none;
}

.footer-links a { color: var(--text-dim); font-size: 0.85rem; }
.footer-links a:hover { color: var(--text-muted); }

/* ===== ANIMATIONS ===== */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.fade-in { animation: fadeIn 0.4s ease; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .nav-links { display: none; }
  .nav-mobile-toggle { display: block; }

  .nav-links.open {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 64px;
    left: 0;
    right: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 16px;
    gap: 4px;
  }

  .hero { padding: 48px 20px 32px; }
  .hero h1 { font-size: 2rem; }

  .calc-body {
    grid-template-columns: 1fr;
  }

  .calc-input {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 24px 16px;
  }

  .calc-output { padding: 24px 16px; max-height: none; }

  .matrix-grid input { width: 48px; height: 36px; font-size: 0.85rem; }
  .matrix-display-cell { width: 50px; font-size: 0.78rem; }

  .calc-toolbar { padding: 12px 16px; }
  .cards-grid { grid-template-columns: 1fr; }
  .features-grid { grid-template-columns: 1fr; }

  .footer-inner { flex-direction: column; text-align: center; }
}

@media (max-width: 480px) {
  .matrix-grid input { width: 42px; height: 32px; font-size: 0.8rem; }
  .matrix-display-cell { width: 44px; font-size: 0.72rem; }
  .hero h1 { font-size: 1.7rem; }
}

/* ===== LOADING ===== */
.loading-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== ERROR STATE ===== */
.error-msg {
  background: rgba(248,113,113,0.1);
  border: 1px solid rgba(248,113,113,0.3);
  color: var(--error);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-bottom: 16px;
  animation: fadeInUp 0.3s ease;
}

/* ===== VERIFY BADGE ===== */
.verify-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(52,211,153,0.1);
  border: 1px solid rgba(52,211,153,0.25);
  color: var(--success);
  padding: 6px 14px;
  border-radius: 100px;
  font-size: 0.8rem;
  font-weight: 600;
  margin-top: 8px;
}

/* ===== EXAMPLE BUTTONS ===== */
.example-btns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.example-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 4px 12px;
  border-radius: 100px;
  font-size: 0.75rem;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.2s;
}

.example-btn:hover {
  border-color: var(--primary-dark);
  color: var(--primary-light);
}

/* ===== AI CHAT PANEL ===== */
.ai-panel {
  border-top: 1px solid var(--border);
  margin-top: 24px;
  padding-top: 20px;
  animation: fadeInUp 0.3s ease;
}

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

.ai-badge {
  background: linear-gradient(135deg, #6366f1, #06b6d4);
  color: white;
  font-size: 0.7rem;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 100px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.ai-panel-header h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

.ai-quick-btns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.ai-quick-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 100px;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.2s;
}

.ai-quick-btn:hover {
  border-color: var(--primary-dark);
  color: var(--primary-light);
  background: rgba(99,102,241,0.08);
}

.ai-chat-input {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.ai-chat-input input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 14px;
  font-size: 0.88rem;
  font-family: var(--font);
  transition: border-color 0.2s;
}

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

.ai-chat-input input::placeholder {
  color: var(--text-dim);
}

.ai-chat-input button {
  background: linear-gradient(135deg, var(--primary-dark), var(--accent-dark));
  border: none;
  color: white;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.2s;
  white-space: nowrap;
}

.ai-chat-input button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(99,102,241,0.3);
}

.ai-chat-input button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.ai-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ai-message {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text-muted);
  animation: fadeInUp 0.3s ease;
  overflow-wrap: break-word;
}

.ai-message.user {
  background: rgba(99,102,241,0.08);
  border-color: rgba(99,102,241,0.2);
  color: var(--text);
  font-weight: 500;
}

.ai-message p { margin-bottom: 10px; }
.ai-message p:last-child { margin-bottom: 0; }
.ai-message strong { color: var(--text); font-weight: 600; }
.ai-message code {
  font-family: var(--mono);
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  color: var(--accent);
}

.ai-message .typing-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--primary);
  animation: blink 0.8s infinite;
  vertical-align: text-bottom;
  margin-left: 2px;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

.btn-ai {
  background: linear-gradient(135deg, #6366f1, #06b6d4);
  color: white;
  box-shadow: 0 2px 12px rgba(99,102,241,0.25);
}

.btn-ai:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(99,102,241,0.35);
}
