:root {
  --bg: #0b1220;
  --bg-2: #162033;
  --card: rgba(15, 23, 42, 0.82);
  --card-border: rgba(255, 255, 255, 0.1);
  --text: #edf3ff;
  --muted: #9caecb;
  --btn: rgba(255, 255, 255, 0.08);
  --btn-border: rgba(255, 255, 255, 0.1);
  --operator: linear-gradient(145deg, #4f7cff, #315fe8);
  --equal: linear-gradient(145deg, #23b26d, #199455);
  --utility: linear-gradient(145deg, #f59e0b, #ea580c);
  --display-bg: rgba(8, 14, 26, 0.9);
  --card-shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
  --button-shadow: 0 5px 12px rgba(0, 0, 0, 0.14);
  --accent-soft: rgba(79, 124, 255, 0.15);
}

body.light {
  --bg: #e8eefb;
  --bg-2: #f8fbff;
  --card: rgba(255, 255, 255, 0.94);
  --card-border: rgba(38, 56, 88, 0.08);
  --text: #17233a;
  --muted: #6a7c98;
  --btn: rgba(245, 248, 255, 0.96);
  --btn-border: rgba(38, 56, 88, 0.08);
  --display-bg: #f3f7ff;
  --card-shadow: 0 14px 30px rgba(65, 88, 128, 0.12);
  --button-shadow: 0 4px 10px rgba(65, 88, 128, 0.1);
  --accent-soft: rgba(79, 124, 255, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

html, body {
  min-height: 100%;
}

body {
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.06), transparent 28%),
    radial-gradient(circle at bottom right, var(--accent-soft), transparent 30%),
    linear-gradient(160deg, var(--bg), var(--bg-2));
  transition: background 0.3s ease, color 0.3s ease;
  overflow-x: hidden;
}

.bg-orb {
  position: fixed;
  width: 170px;
  height: 170px;
  border-radius: 50%;
  filter: blur(42px);
  opacity: 0.35;
  pointer-events: none;
}

.orb-1 {
  top: -70px;
  left: -35px;
  background: rgba(79, 124, 255, 0.2);
}

.orb-2 {
  right: -70px;
  bottom: 5%;
  background: rgba(35, 178, 109, 0.12);
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 26px 26px;
  mask-image: radial-gradient(circle at center, black 35%, transparent 88%);
  pointer-events: none;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.calculator {
  position: relative;
  width: 100%;
  max-width: 380px;
  padding: 14px;
  border-radius: 24px;
  border: 1px solid var(--card-border);
  background: var(--card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--card-shadow);
}

.calculator::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 1px solid rgba(255, 255, 255, 0.05);
  pointer-events: none;
}

.topbar,
.toolbar-row,
.display-panel,
.scientific-panel,
.buttons {
  position: relative;
  z-index: 1;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.brand-area h1 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.top-actions {
  display: flex;
  gap: 6px;
}

.icon-btn,
.mode-btn,
.btn {
  border: 1px solid var(--btn-border);
  outline: none;
}

.icon-btn,
.mode-btn {
  min-height: 38px;
  border-radius: 12px;
  background: var(--btn);
  color: var(--text);
  box-shadow: var(--button-shadow);
}

.icon-btn {
  min-width: 38px;
  padding: 0 10px;
  cursor: pointer;
  font-size: 0.95rem;
}

.toolbar-row {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.single-action-row {
  grid-template-columns: 1fr;
}

.mode-btn {
  width: 100%;
  padding: 0 12px;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
}

.display-panel {
  border-radius: 18px;
  padding: 11px 12px;
  background: var(--display-bg);
  border: 1px solid rgba(255, 255, 255, 0.06);
  margin-bottom: 10px;
}

.display-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 8px;
}

#display {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: right;
  font-size: clamp(1.55rem, 4vw, 2rem);
  font-weight: 800;
  letter-spacing: 0.02em;
}

#display::placeholder {
  color: color-mix(in srgb, var(--muted) 75%, transparent);
}

.scientific-panel,
.buttons {
  display: grid;
  gap: 8px;
}

.scientific-panel {
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 10px;
}

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

.btn {
  min-height: 48px;
  border-radius: 15px;
  background: var(--btn);
  color: var(--text);
  box-shadow: var(--button-shadow);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}

.btn:hover,
.icon-btn:hover,
.mode-btn:hover {
  transform: translateY(-1px);
}

.btn:active,
.icon-btn:active,
.mode-btn:active {
  transform: translateY(1px) scale(0.985);
}

.utility { background: var(--utility); color: #fff; }
.operator { background: var(--operator); color: #fff; }
.equals { background: var(--equal); color: #fff; }
.sci { background: rgba(255, 255, 255, 0.1); }
.zero { grid-column: span 2; }
.hidden { display: none; }

@media (max-width: 600px) {
  .app-shell {
    min-height: 100dvh;
    padding: 10px;
  }

  .calculator {
    max-width: 100%;
    border-radius: 22px;
    padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)) 12px;
  }

  .brand-area h1 {
    font-size: 1.08rem;
  }

  .icon-btn,
  .mode-btn {
    min-height: 36px;
  }

  .btn {
    min-height: 46px;
    font-size: 0.96rem;
  }

  #display {
    font-size: clamp(1.45rem, 6vw, 1.9rem);
  }
}

@media (max-width: 380px) {
  .calculator {
    padding: 10px;
  }

  .topbar {
    margin-bottom: 8px;
  }

  .toolbar-row,
  .display-panel,
  .scientific-panel {
    margin-bottom: 8px;
  }

  .btn {
    min-height: 42px;
    border-radius: 13px;
    font-size: 0.92rem;
  }

  .icon-btn {
    min-width: 34px;
    min-height: 34px;
    padding: 0 8px;
  }

  #display {
    font-size: 1.35rem;
  }
}
