:root {
  --bg: #e8ecf1;
  --card-bg: rgba(255, 255, 255, 0.75);
  --card-border: rgba(255, 255, 255, 0.4);
  --card-shadow: 0 25px 60px rgba(0, 0, 0, 0.12);
  --display-bg: rgba(255, 255, 255, 0.6);
  --text: #1e293b;
  --text-muted: #64748b;
  --key-bg: rgba(255, 255, 255, 0.85);
  --key-bg-hover: #ffffff;
  --key-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  --key-active: rgba(0, 0, 0, 0.05);
  --op-bg: rgba(59, 130, 246, 0.12);
  --op-color: #3b82f6;
  --op-hover: rgba(59, 130, 246, 0.2);
  --accent: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.25);
  --clear-color: #ef4444;
  --clear-bg: rgba(239, 68, 68, 0.1);
  --clear-hover: rgba(239, 68, 68, 0.18);
  --equals-bg: #3b82f6;
  --equals-color: #fff;
  --gcd-bg: rgba(34, 197, 94, 0.12);
  --gcd-color: #16a34a;
  --gcd-hover: rgba(34, 197, 94, 0.2);
  --lcm-bg: rgba(139, 92, 246, 0.12);
  --lcm-color: #7c3aed;
  --lcm-hover: rgba(139, 92, 246, 0.2);
  --header-border: rgba(0, 0, 0, 0.06);
}

body.dark {
  --bg: #0f172a;
  --card-bg: rgba(30, 41, 59, 0.85);
  --card-border: rgba(255, 255, 255, 0.06);
  --card-shadow: 0 25px 60px rgba(0, 0, 0, 0.4);
  --display-bg: rgba(15, 23, 42, 0.6);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --key-bg: rgba(51, 65, 85, 0.7);
  --key-bg-hover: rgba(71, 85, 105, 0.8);
  --key-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  --key-active: rgba(255, 255, 255, 0.05);
  --op-bg: rgba(59, 130, 246, 0.15);
  --op-color: #60a5fa;
  --op-hover: rgba(59, 130, 246, 0.25);
  --accent: #60a5fa;
  --accent-glow: rgba(96, 165, 250, 0.3);
  --clear-color: #f87171;
  --clear-bg: rgba(239, 68, 68, 0.15);
  --clear-hover: rgba(239, 68, 68, 0.25);
  --equals-bg: #3b82f6;
  --equals-color: #fff;
  --gcd-bg: rgba(34, 197, 94, 0.15);
  --gcd-color: #4ade80;
  --gcd-hover: rgba(34, 197, 94, 0.25);
  --lcm-bg: rgba(139, 92, 246, 0.15);
  --lcm-color: #a78bfa;
  --lcm-hover: rgba(139, 92, 246, 0.25);
  --header-border: rgba(255, 255, 255, 0.06);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.35s ease;
  -webkit-font-smoothing: antialiased;
  padding: 20px;
}

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

.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  border: none;
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s ease;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.theme-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
}

.theme-toggle .sun { display: block; }
.theme-toggle .moon { display: none; }
body.dark .theme-toggle .sun { display: none; }
body.dark .theme-toggle .moon { display: block; }

/* Card */
.calc-card {
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--card-border);
  border-radius: 28px;
  box-shadow: var(--card-shadow);
  padding: 24px;
  transition: all 0.35s ease;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: var(--op-bg);
  color: var(--op-color);
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-text {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text);
}

.badge-gcd {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 5px 12px;
  border-radius: 20px;
  background: var(--gcd-bg);
  color: var(--gcd-color);
  text-transform: uppercase;
}

/* Display */
.display-wrap {
  margin-bottom: 16px;
}

.display-scroll {
  background: var(--display-bg);
  border-radius: 18px;
  padding: 16px 20px;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  overflow-x: auto;
  transition: background 0.3s ease;
}

.display-scroll::-webkit-scrollbar { height: 3px; }
.display-scroll::-webkit-scrollbar-track { background: transparent; }
.display-scroll::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 4px; }

.display {
  width: 100%;
  border: none;
  background: transparent;
  font-size: 36px;
  font-weight: 700;
  text-align: right;
  color: var(--text);
  outline: none;
  font-family: 'Inter', monospace;
  letter-spacing: -1px;
  transition: color 0.3s ease;
}

.display::placeholder { color: var(--text-muted); font-weight: 500; }

/* GCD Section */
.gcd-section { margin-bottom: 16px; }

.gcd-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.gcd-input {
  flex: 1;
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--header-border);
  border-radius: 12px;
  background: var(--key-bg);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  font-family: 'Inter', monospace;
  outline: none;
  transition: all 0.2s ease;
}

.gcd-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.gcd-input::placeholder { color: var(--text-muted); font-weight: 500; }

.gcd-btn, .lcm-btn {
  height: 42px;
  border: none;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 700;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  font-family: 'Inter', sans-serif;
}

.gcd-btn { background: var(--gcd-bg); color: var(--gcd-color); }
.gcd-btn:hover { background: var(--gcd-hover); transform: translateY(-1px); }
.lcm-btn { background: var(--lcm-bg); color: var(--lcm-color); }
.lcm-btn:hover { background: var(--lcm-hover); transform: translateY(-1px); }

.gcd-btn:active, .lcm-btn:active { transform: scale(0.95); }

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

.key {
  height: 60px;
  border: none;
  border-radius: 16px;
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--key-bg);
  color: var(--text);
  box-shadow: var(--key-shadow);
  transition: all 0.15s ease;
  font-family: 'Inter', sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  position: relative;
  overflow: hidden;
}

.key::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--key-active);
  opacity: 0;
  transition: opacity 0.15s ease;
}

.key:active::after { opacity: 1; }

.key:hover {
  background: var(--key-bg-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
}

.key:active {
  transform: scale(0.94);
}

.key-num { font-size: 22px; }
.key-num:hover { background: var(--key-bg-hover); }

.key-op {
  background: var(--op-bg);
  color: var(--op-color);
  font-size: 22px;
}

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

.key-func {
  background: var(--op-bg);
  color: var(--op-color);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.key-func:hover {
  background: var(--op-hover);
}

.key-clear {
  background: var(--clear-bg);
  color: var(--clear-color);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.3px;
  grid-column: span 2;
}

.key-clear:hover {
  background: var(--clear-hover);
}

.key-equals {
  background: var(--equals-bg);
  color: var(--equals-color);
  font-size: 26px;
  font-weight: 700;
  grid-column: span 2;
  box-shadow: 0 4px 20px var(--accent-glow);
}

.key-equals:hover {
  background: #2563eb;
  transform: translateY(-2px);
  box-shadow: 0 8px 28px var(--accent-glow);
}

.key-equals:active {
  transform: scale(0.95);
}

/* Footer */
.calc-footer {
  text-align: center;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--header-border);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* Responsive */
@media (max-width: 420px) {
  .calc-card { padding: 18px; border-radius: 22px; }
  .key { height: 54px; border-radius: 14px; font-size: 18px; }
  .key-num { font-size: 20px; }
  .display { font-size: 30px; }
  .display-scroll { min-height: 68px; padding: 12px 16px; }
  .brand-text { font-size: 18px; }
  .gcd-btn, .lcm-btn { padding: 0 10px; font-size: 12px; }
  .home-title { font-size: 28px; }
  .home-subtitle { font-size: 15px; }
  .home-card { padding: 36px 24px; }
}

/* ===== Homepage ===== */

.home-container {
  max-width: 460px;
}

.home-card {
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--card-border);
  border-radius: 28px;
  box-shadow: var(--card-shadow);
  padding: 48px 36px;
  text-align: center;
  transition: all 0.35s ease;
}

.home-logo {
  margin-bottom: 24px;
  display: flex;
  justify-content: center;
}

.veritas-logo {
  width: 96px;
  height: auto;
  border-radius: 16px;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.1));
}

.home-title {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -1px;
  color: var(--text);
  margin-bottom: 8px;
}

.home-subtitle {
  font-size: 16px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 16px;
  line-height: 1.5;
}

.home-desc {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
  line-height: 1.6;
  margin-bottom: 32px;
}

.home-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 32px;
  border-radius: 16px;
  background: var(--equals-bg);
  color: var(--equals-color);
  font-size: 18px;
  font-weight: 700;
  font-family: 'Inter', sans-serif;
  text-decoration: none;
  box-shadow: 0 4px 20px var(--accent-glow);
  transition: all 0.2s ease;
  letter-spacing: -0.3px;
}

.home-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 30px var(--accent-glow);
  background: #2563eb;
}

.home-btn:active {
  transform: scale(0.96);
}

.home-footer {
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid var(--header-border);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* ===== Back Button ===== */

.back-btn {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 100;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  border: none;
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s ease;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  text-decoration: none;
}

.back-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
}
