/* ===== CSS Variables ===== */
:root {
  --bg-primary: #f5f7fa;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --text-primary: #1a1a2e;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-light: #dbeafe;
  --success: #10b981;
  --danger: #ef4444;
  --orange: #f59e0b;
  --border: #e5e7eb;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.1);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-btn: 12px;
  --transition: 0.2s ease;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
}

[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #60a5fa;
  --accent-hover: #3b82f6;
  --accent-light: #1e3a5f;
  --border: #334155;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--accent-hover);
}

/* ===== Header ===== */
.header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

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

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 20px;
  color: var(--text-primary);
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
  font-weight: 700;
}

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

.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all var(--transition);
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

nav {
  display: flex;
  gap: 4px;
}

nav a {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition);
}

nav a:hover, nav a.active {
  color: var(--accent);
  background: var(--accent-light);
}

/* ===== Ad Slots ===== */
.ad-slot {
  max-width: 1200px;
  margin: 16px auto;
  padding: 0 24px;
}

.ad-placeholder {
  background: var(--bg-secondary);
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ===== Main Layout ===== */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px;
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 32px;
  align-items: start;
}

/* ===== Calculator Card ===== */
.calc-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1px solid var(--border);
}

.calc-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.calc-header h1 {
  font-size: 20px;
  font-weight: 700;
}

.calc-mode-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-primary);
  border-radius: 8px;
  padding: 3px;
}

.calc-mode-tab {
  padding: 6px 14px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
}

.calc-mode-tab.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* ===== Display ===== */
.calc-display {
  padding: 24px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
}

.calc-expression {
  font-size: 14px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  min-height: 20px;
  text-align: right;
  word-break: break-all;
}

.calc-result {
  font-size: 40px;
  font-weight: 700;
  font-family: var(--font-mono);
  text-align: right;
  color: var(--text-primary);
  margin-top: 8px;
  word-break: break-all;
  line-height: 1.2;
  min-height: 48px;
  transition: font-size var(--transition);
}

.calc-result.small {
  font-size: 28px;
}

/* ===== Button Grid ===== */
.calc-buttons {
  padding: 16px;
  display: grid;
  gap: 8px;
}

.calc-buttons.basic {
  grid-template-columns: repeat(4, 1fr);
}

.calc-buttons.scientific {
  grid-template-columns: repeat(5, 1fr);
}

.calc-btn {
  height: 56px;
  border-radius: var(--radius-btn);
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.calc-btn:hover {
  background: var(--accent-light);
  border-color: var(--accent);
}

.calc-btn:active {
  transform: scale(0.95);
}

.calc-btn.number {
  font-weight: 600;
  font-size: 20px;
}

.calc-btn.operator {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
  border-color: transparent;
}

.calc-btn.operator:hover {
  background: var(--accent);
  color: #fff;
}

.calc-btn.equals {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
  font-weight: 700;
}

.calc-btn.equals:hover {
  background: var(--accent-hover);
}

.calc-btn.danger {
  color: var(--danger);
}

.calc-btn.danger:hover {
  background: #fef2f2;
  border-color: var(--danger);
}

[data-theme="dark"] .calc-btn.danger:hover {
  background: #3b1a1a;
}

.calc-btn.func {
  font-size: 14px;
  color: var(--text-secondary);
}

.calc-btn.func:hover {
  color: var(--accent);
}

.calc-btn.wide {
  grid-column: span 2;
}

.calc-btn.scientific-fn {
  font-size: 13px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

/* ===== History ===== */
.history-panel {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  max-height: 200px;
  overflow-y: auto;
}

.history-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.history-clear {
  font-size: 12px;
  color: var(--danger);
  cursor: pointer;
  background: none;
  border: none;
  font-family: var(--font);
  text-transform: none;
  letter-spacing: 0;
}

.history-clear:hover {
  text-decoration: underline;
}

.history-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: opacity var(--transition);
}

.history-item:last-child {
  border-bottom: none;
}

.history-item:hover {
  opacity: 0.7;
}

.history-expr {
  font-size: 13px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.history-result {
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.history-empty {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  padding: 16px 0;
}

/* ===== Sidebar ===== */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.sidebar-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 20px;
}

.sidebar-card h3 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 12px;
}

.tool-list {
  list-style: none;
}

.tool-list li {
  margin-bottom: 4px;
}

.tool-list a {
  display: block;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 14px;
  transition: all var(--transition);
}

.tool-list a:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.keyboard-shortcut {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-primary);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  float: right;
}

/* ===== Content Section ===== */
.content-section {
  max-width: 1200px;
  margin: 0 auto;
  padding: 48px 24px;
}

.content-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 40px;
}

.content-card h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text-primary);
}

.content-card h3 {
  font-size: 18px;
  font-weight: 600;
  margin: 24px 0 12px;
  color: var(--text-primary);
}

.content-card p {
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.8;
}

.content-card ul, .content-card ol {
  color: var(--text-secondary);
  margin-bottom: 16px;
  padding-left: 24px;
  line-height: 1.8;
}

.content-card table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
}

.content-card th, .content-card td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.content-card th {
  font-weight: 600;
  color: var(--text-primary);
  background: var(--bg-primary);
}

.content-card td {
  color: var(--text-secondary);
}

/* ===== FAQ ===== */
.faq-item {
  border-bottom: 1px solid var(--border);
  padding: 16px 0;
}

.faq-item:last-child {
  border-bottom: none;
}

.faq-question {
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 0;
}

.faq-question::after {
  content: '+';
  font-size: 20px;
  color: var(--accent);
  flex-shrink: 0;
  transition: transform var(--transition);
}

.faq-item.open .faq-question::after {
  content: '−';
}

.faq-answer {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.faq-item.open .faq-answer {
  max-height: 500px;
}

.faq-answer p {
  padding-top: 12px;
  color: var(--text-secondary);
  line-height: 1.8;
}

/* ===== Footer ===== */
.footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 40px 24px;
  margin-top: 48px;
}

.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 40px;
}

.footer-brand p {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 12px;
  line-height: 1.6;
}

.footer h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-primary);
}

.footer ul {
  list-style: none;
}

.footer li {
  margin-bottom: 8px;
}

.footer li a {
  color: var(--text-muted);
  font-size: 14px;
  transition: color var(--transition);
}

.footer li a:hover {
  color: var(--accent);
}

.footer-bottom {
  max-width: 1200px;
  margin: 24px auto 0;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-muted);
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text-primary);
  color: var(--bg-primary);
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  z-index: 1000;
  opacity: 0;
  transform: translateY(16px);
  transition: all 0.3s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

  .sidebar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }
}

@media (max-width: 768px) {
  .header-inner {
    height: 56px;
    padding: 0 16px;
  }

  nav {
    display: none;
  }

  .main {
    padding: 16px;
    gap: 16px;
  }

  .calc-header {
    padding: 16px;
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }

  .calc-display {
    padding: 16px;
  }

  .calc-result {
    font-size: 32px;
  }

  .calc-result.small {
    font-size: 24px;
  }

  .calc-buttons {
    padding: 12px;
    gap: 6px;
  }

  .calc-btn {
    height: 50px;
    font-size: 16px;
    border-radius: 10px;
  }

  .calc-btn.number {
    font-size: 18px;
  }

  .calc-btn.scientific-fn {
    font-size: 11px;
  }

  .sidebar {
    grid-template-columns: 1fr;
  }

  .content-card {
    padding: 24px;
  }

  .content-card h2 {
    font-size: 20px;
  }

  .footer-inner {
    grid-template-columns: 1fr 1fr;
    gap: 24px;
  }

  .footer-bottom {
    flex-direction: column;
    gap: 8px;
    text-align: center;
  }
}

@media (max-width: 480px) {
  .logo {
    font-size: 17px;
  }

  .calc-result {
    font-size: 28px;
  }

  .calc-btn {
    height: 46px;
  }

  .calc-buttons.scientific {
    grid-template-columns: repeat(4, 1fr);
  }

  .footer-inner {
    grid-template-columns: 1fr;
  }
}
