:root {
  --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  --card-bg: rgba(30, 41, 59, 0.75);
  --card-border: rgba(255, 255, 255, 0.08);
  --card-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --btn-num-bg: rgba(255, 255, 255, 0.06);
  --btn-num-hover: rgba(255, 255, 255, 0.12);
  --btn-action-bg: rgba(255, 255, 255, 0.1);
  --btn-action-hover: rgba(255, 255, 255, 0.18);
  --btn-op-bg: #f97316;
  --btn-op-hover: #ea580c;
  --btn-op-active: #c2410c;
  --btn-equals-bg: #3b82f6;
  --btn-equals-hover: #2563eb;
  --btn-equals-active: #1d4ed8;
  --drawer-bg: rgba(15, 23, 42, 0.95);
  --badge-bg: #10b981;
  --card-subtle-bg: rgba(255, 255, 255, 0.03);
  --accent-color: #38bdf8;
}

[data-theme="light"] {
  --bg-gradient: linear-gradient(135deg, #e2e8f0 0%, #cbd5e1 100%);
  --card-bg: rgba(255, 255, 255, 0.85);
  --card-border: rgba(0, 0, 0, 0.06);
  --card-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0, 0, 0, 0.05);
  --text-main: #0f172a;
  --text-muted: #64748b;
  --btn-num-bg: #ffffff;
  --btn-num-hover: #f1f5f9;
  --btn-action-bg: #e2e8f0;
  --btn-action-hover: #cbd5e1;
  --btn-op-bg: #f97316;
  --btn-op-hover: #ea580c;
  --btn-op-active: #c2410c;
  --btn-equals-bg: #2563eb;
  --btn-equals-hover: #1d4ed8;
  --btn-equals-active: #1e40af;
  --drawer-bg: rgba(255, 255, 255, 0.96);
  --badge-bg: #059669;
  --card-subtle-bg: rgba(0, 0, 0, 0.02);
  --accent-color: #0284c7;
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-gradient);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 32px 16px;
  color: var(--text-main);
  transition: background 0.3s ease, color 0.3s ease;
  line-height: 1.6;
}

.page-wrapper {
  width: 100%;
  max-width: 680px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 40px;
}

.app-container {
  width: 100%;
  max-width: 360px;
}

.calculator-card {
  position: relative;
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 28px;
  border: 1px solid var(--card-border);
  box-shadow: var(--card-shadow);
  padding: 24px;
  overflow: hidden;
  transition: all 0.3s ease;
  user-select: none;
  -webkit-user-select: none;
}

/* Top Bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.app-title {
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.icon-btn {
  background: transparent;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 8px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  transform: scale(1.05);
}

[data-theme="light"] .icon-btn:hover {
  background: rgba(0, 0, 0, 0.06);
}

/* Display Area */
.display-area {
  position: relative;
  text-align: right;
  padding: 16px 8px;
  margin-bottom: 20px;
  border-radius: 16px;
  cursor: pointer;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.02);
  transition: background 0.2s ease;
}

.display-area:hover {
  background: rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .display-area {
  background: rgba(0, 0, 0, 0.03);
}

.history-expr {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  min-height: 1.4em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.main-display {
  font-size: 2.6rem;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-main);
  line-height: 1.2;
  word-break: break-all;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.02em;
}

.copy-badge {
  position: absolute;
  top: 8px;
  left: 12px;
  background: var(--badge-bg);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 9999px;
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: all 0.2s ease;
}

.copy-badge.show {
  opacity: 1;
  transform: translateY(0);
}

/* Keypad Grid */
.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.btn {
  aspect-ratio: 1;
  border: none;
  border-radius: 20px;
  font-size: 1.35rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.2s ease, box-shadow 0.2s ease;
  outline: none;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.btn:active, .btn.pressed {
  transform: scale(0.92);
}

/* Button Variants */
.btn-num {
  background: var(--btn-num-bg);
  color: var(--text-main);
}

.btn-num:hover {
  background: var(--btn-num-hover);
}

.btn-action {
  background: var(--btn-action-bg);
  color: var(--text-main);
  font-weight: 600;
}

.btn-action:hover {
  background: var(--btn-action-hover);
}

.btn-operator {
  background: var(--btn-op-bg);
  color: #ffffff;
  font-size: 1.5rem;
}

.btn-operator:hover {
  background: var(--btn-op-hover);
}

.btn-operator:active, .btn-operator.active-op {
  background: var(--btn-op-active);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.btn-equals {
  background: var(--btn-equals-bg);
  color: #ffffff;
  font-size: 1.5rem;
  font-weight: 600;
}

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

.btn-equals:active {
  background: var(--btn-equals-active);
}

/* History Panel Drawer */
.history-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--drawer-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-radius: 28px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  transform: translateX(105%);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 10;
}

.history-panel.open {
  transform: translateX(0);
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--card-border);
  margin-bottom: 16px;
}

.history-header span {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
}

.clear-history-btn {
  background: none;
  border: none;
  font-size: 0.8rem;
  color: #ef4444;
  cursor: pointer;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.2s ease;
}

.clear-history-btn:hover {
  background: rgba(239, 68, 68, 0.1);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 4px;
}

.history-list::-webkit-scrollbar {
  width: 4px;
}

.history-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

.history-item {
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  cursor: pointer;
  text-align: right;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.history-item:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
}

[data-theme="light"] .history-item {
  background: rgba(0, 0, 0, 0.03);
}

[data-theme="light"] .history-item:hover {
  background: rgba(0, 0, 0, 0.06);
}

.history-item-expr {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  margin-bottom: 4px;
}

.history-item-res {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-main);
  font-family: 'JetBrains Mono', monospace;
}

.empty-history-text {
  text-align: center;
  color: var(--text-muted);
  margin-top: 40px;
  font-size: 0.9rem;
}

/* ========================================================
   SEO & Content Sections Styling
   ======================================================== */
.seo-content-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.seo-header {
  text-align: center;
  padding: 0 12px;
}

.seo-main-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.seo-subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
  max-width: 580px;
  margin: 0 auto;
}

/* Feature Grid */
.seo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.seo-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(12px);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--card-shadow);
  transition: transform 0.2s ease, border-color 0.2s ease;
}

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

.seo-card-icon {
  font-size: 1.8rem;
  margin-bottom: 12px;
}

.seo-card h2 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 6px;
}

.seo-card p {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Shortcuts Table */
.seo-shortcuts-section {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(12px);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--card-shadow);
}

.seo-shortcuts-section h2,
.seo-faq-section h2 {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 16px;
}

.table-responsive {
  overflow-x: auto;
}

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

.shortcuts-table th {
  color: var(--text-muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--card-border);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}

.shortcuts-table td {
  padding: 12px;
  border-bottom: 1px solid var(--card-border);
  color: var(--text-main);
}

.shortcuts-table tr:last-child td {
  border-bottom: none;
}

kbd {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  padding: 3px 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}

[data-theme="light"] kbd {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #0f172a;
}

/* FAQ Accordion */
.seo-faq-section {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(12px);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--card-shadow);
}

.faq-accordion {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.faq-item {
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 14px 16px;
  background: var(--card-subtle-bg);
  transition: background 0.2s ease;
}

.faq-item[open] {
  background: rgba(255, 255, 255, 0.04);
}

.faq-question {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.faq-question::-webkit-details-marker {
  display: none;
}

.faq-question::after {
  content: '▼';
  font-size: 0.75rem;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.faq-item[open] .faq-question::after {
  transform: rotate(180deg);
}

.faq-answer {
  margin-top: 10px;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Footer */
.app-footer {
  text-align: center;
  padding: 20px 0 10px 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  border-top: 1px solid var(--card-border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s ease;
}

.footer-links a:hover {
  color: var(--text-main);
  text-decoration: underline;
}

@media (max-width: 480px) {
  .page-wrapper {
    gap: 28px;
  }
  .seo-main-title {
    font-size: 1.25rem;
  }
  .main-display {
    font-size: 2.2rem;
  }
}
