/* =========================================================
   Lumen Calculator — styles
   Glassmorphism · dark/light · mobile-first
   ========================================================= */

:root {
  /* surfaces */
  --bg-1: #0b0d17;
  --bg-2: #1a0f2e;
  --bg-3: #06122a;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-strong: rgba(255, 255, 255, 0.09);
  --panel-border: rgba(255, 255, 255, 0.12);
  --panel-inner: rgba(255, 255, 255, 0.04);

  /* text */
  --text: #f4f6ff;
  --text-soft: rgba(244, 246, 255, 0.7);
  --text-mute: rgba(244, 246, 255, 0.45);

  /* keys */
  --key-digit: rgba(255, 255, 255, 0.07);
  --key-digit-h: rgba(255, 255, 255, 0.12);
  --key-fn: rgba(255, 255, 255, 0.1);
  --key-fn-h: rgba(255, 255, 255, 0.16);
  --key-op: linear-gradient(180deg, #ff8a3d 0%, #ff6a1a 100%);
  --key-op-h: linear-gradient(180deg, #ffa15a 0%, #ff7d2e 100%);
  --key-eq: linear-gradient(180deg, #6c8cff 0%, #4a64ff 100%);
  --key-eq-h: linear-gradient(180deg, #8aa1ff 0%, #5e76ff 100%);

  --key-text: var(--text);
  --op-text: #1a0f08;
  --eq-text: #ffffff;

  /* shadow / glow */
  --shadow-key: 0 6px 18px rgba(0, 0, 0, 0.35);
  --shadow-key-inset: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  --shadow-panel: 0 30px 80px rgba(0, 0, 0, 0.55), 0 2px 1px rgba(255, 255, 255, 0.04) inset;

  /* radii / spacing */
  --r-panel: 28px;
  --r-key: 18px;
  --gap: 10px;
  --pad: 18px;

  /* typography */
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

[data-theme="light"] {
  --bg-1: #d8e3ff;
  --bg-2: #ffe7f3;
  --bg-3: #e6f3ff;
  --panel: rgba(255, 255, 255, 0.55);
  --panel-strong: rgba(255, 255, 255, 0.7);
  --panel-border: rgba(255, 255, 255, 0.85);
  --panel-inner: rgba(255, 255, 255, 0.5);

  --text: #14172a;
  --text-soft: rgba(20, 23, 42, 0.7);
  --text-mute: rgba(20, 23, 42, 0.45);

  --key-digit: rgba(255, 255, 255, 0.7);
  --key-digit-h: rgba(255, 255, 255, 0.9);
  --key-fn: rgba(255, 255, 255, 0.55);
  --key-fn-h: rgba(255, 255, 255, 0.75);

  --shadow-key: 0 6px 18px rgba(60, 80, 140, 0.18);
  --shadow-key-inset: inset 0 1px 0 rgba(255, 255, 255, 0.9);
  --shadow-panel: 0 30px 80px rgba(60, 80, 140, 0.28),
    0 2px 1px rgba(255, 255, 255, 0.6) inset;
}

/* ---------- reset & base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}
body {
  font-family: var(--font-ui);
  color: var(--text);
  background: var(--bg-1);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: color 0.3s ease;
}

/* ---------- aurora background ---------- */
.aurora {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: radial-gradient(
      120% 100% at 0% 0%,
      var(--bg-1) 0%,
      transparent 60%
    ),
    radial-gradient(120% 100% at 100% 0%, var(--bg-2) 0%, transparent 60%),
    radial-gradient(120% 100% at 50% 100%, var(--bg-3) 0%, transparent 60%),
    var(--bg-1);
}
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.55;
  pointer-events: none;
  will-change: transform;
}
.blob-1 {
  width: 520px;
  height: 520px;
  background: #5b8cff;
  top: -160px;
  left: -120px;
  animation: drift 22s ease-in-out infinite;
}
.blob-2 {
  width: 460px;
  height: 460px;
  background: #ff6abf;
  top: 30%;
  right: -140px;
  animation: drift 28s ease-in-out -8s infinite reverse;
}
.blob-3 {
  width: 600px;
  height: 600px;
  background: #4be8c4;
  bottom: -200px;
  left: 30%;
  animation: drift 34s ease-in-out -14s infinite;
}
[data-theme="light"] .blob {
  opacity: 0.45;
}
[data-theme="light"] .blob-1 {
  background: #98b8ff;
}
[data-theme="light"] .blob-2 {
  background: #ffb1d8;
}
[data-theme="light"] .blob-3 {
  background: #9bf0d6;
}
@keyframes drift {
  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  33% {
    transform: translate3d(40px, -30px, 0) scale(1.06);
  }
  66% {
    transform: translate3d(-30px, 40px, 0) scale(0.96);
  }
}
@media (prefers-reduced-motion: reduce) {
  .blob {
    animation: none;
  }
}

/* ---------- top bar ---------- */
.topbar {
  width: 100%;
  max-width: 480px;
  padding: 18px var(--pad) 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: var(--text);
}
.brand-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: conic-gradient(from 180deg, #6c8cff, #ff6abf, #4be8c4, #6c8cff);
  box-shadow: 0 0 18px rgba(108, 140, 255, 0.7);
}
.brand-name {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 4px;
}
.topbar-actions {
  display: inline-flex;
  gap: 6px;
}
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text-soft);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease, color 0.2s ease,
    border-color 0.2s ease;
}
.icon-btn:hover {
  background: var(--panel-strong);
  color: var(--text);
  transform: translateY(-1px);
}
.icon-btn:active {
  transform: translateY(0);
}
.icon-btn svg {
  width: 20px;
  height: 20px;
}
.icon-btn .i-sun,
.icon-btn .i-moon {
  display: none;
}
[data-theme="dark"] .icon-btn .i-moon {
  display: block;
}
[data-theme="light"] .icon-btn .i-sun {
  display: block;
}
#modeBtn[aria-pressed="true"] {
  color: #14172a;
  background: linear-gradient(180deg, #ffd28a, #ffaf5a);
  border-color: transparent;
}

/* ---------- stage & calculator panel ---------- */
.stage {
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 6px var(--pad) 24px;
  flex: 1;
}
.calc {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-panel);
  backdrop-filter: blur(28px) saturate(150%);
  -webkit-backdrop-filter: blur(28px) saturate(150%);
  box-shadow: var(--shadow-panel);
  padding: 18px;
  display: grid;
  gap: 14px;
}

/* ---------- display ---------- */
.display {
  padding: 18px 16px 10px;
  border-radius: 20px;
  background: var(--panel-inner);
  border: 1px solid var(--panel-border);
  display: grid;
  gap: 6px;
  min-height: 110px;
  align-content: end;
  text-align: right;
  position: relative;
  overflow: hidden;
}
.display::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.05),
    transparent 30%
  );
  pointer-events: none;
}
.display-expr {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text-mute);
  min-height: 18px;
  word-break: break-all;
  white-space: pre-wrap;
  line-height: 1.3;
}
.display-value {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: clamp(34px, 9vw, 46px);
  line-height: 1.05;
  color: var(--text);
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}
.display-value.error {
  color: #ff7a7a;
}
[data-theme="light"] .display-value.error {
  color: #c52828;
}

/* ---------- memory strip ---------- */
.memory-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--gap);
}
.m-key {
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: var(--panel-inner);
  color: var(--text-soft);
  font: 600 12px/1 var(--font-ui);
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.1s ease;
}
.m-key:hover {
  background: var(--panel-strong);
  color: var(--text);
}
.m-key:active {
  transform: scale(0.97);
}

/* ---------- scientific panel ---------- */
.scientific {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--gap);
}
.scientific[hidden] {
  display: none;
}

/* ---------- keypad ---------- */
.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
}
.k {
  appearance: none;
  border: 1px solid var(--panel-border);
  background: var(--key-digit);
  color: var(--key-text);
  font: 600 20px/1 var(--font-ui);
  height: 60px;
  border-radius: var(--r-key);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  display: inline-grid;
  place-items: center;
  box-shadow: var(--shadow-key), var(--shadow-key-inset);
  transition: transform 0.08s ease, background 0.2s ease, box-shadow 0.2s ease,
    filter 0.2s ease;
  position: relative;
  overflow: hidden;
}
.k::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.08),
    transparent 40%
  );
  pointer-events: none;
}
.k:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}
.k:active,
.k.is-pressed {
  transform: translateY(1px) scale(0.98);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35) inset,
    0 1px 0 rgba(255, 255, 255, 0.05) inset;
}
.k-fn {
  background: var(--key-fn);
  color: var(--text-soft);
  font-size: 17px;
}
.k-fn:hover {
  background: var(--key-fn-h);
  color: var(--text);
}
.k-op {
  background: var(--key-op);
  color: var(--op-text);
  font-size: 22px;
}
.k-op:hover {
  background: var(--key-op-h);
}
.k-equals {
  background: var(--key-eq);
  color: var(--eq-text);
  font-size: 22px;
}
.k-equals:hover {
  background: var(--key-eq-h);
}
.k-zero {
  grid-column: span 2;
}
.k[data-active="true"] {
  outline: 2px solid rgba(108, 140, 255, 0.55);
  outline-offset: 2px;
}
#sciPanel .k[data-second="true"] {
  color: #14172a;
  background: linear-gradient(180deg, #ffd28a, #ffaf5a);
}
#sciPanel .k[data-second="true"]::before {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.25),
    transparent 50%
  );
}

/* ---------- history drawer ---------- */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 20;
  backdrop-filter: blur(2px);
}
.scrim.is-open {
  opacity: 1;
  pointer-events: auto;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100dvh;
  width: min(360px, 92vw);
  background: var(--panel-strong);
  border-left: 1px solid var(--panel-border);
  backdrop-filter: blur(28px) saturate(160%);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
  box-shadow: -20px 0 50px rgba(0, 0, 0, 0.35);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  z-index: 30;
  display: flex;
  flex-direction: column;
}
.drawer.is-open {
  transform: translateX(0);
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
  border-bottom: 1px solid var(--panel-border);
}
.drawer-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--text-soft);
}
.history-list {
  list-style: none;
  margin: 0;
  padding: 8px 12px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.history-list:empty::after {
  content: "No history yet";
  display: block;
  text-align: center;
  color: var(--text-mute);
  padding: 40px 0;
  font-size: 14px;
}
.history-item {
  background: var(--panel-inner);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 10px 12px;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
  text-align: right;
  display: grid;
  gap: 2px;
}
.history-item:hover {
  background: var(--panel-strong);
}
.history-item:active {
  transform: scale(0.99);
}
.history-item .h-expr {
  font: 500 12px/1.3 var(--font-mono);
  color: var(--text-mute);
  word-break: break-all;
}
.history-item .h-result {
  font: 600 18px/1.2 var(--font-mono);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.drawer-foot {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--panel-border);
}
.ghost-btn {
  width: 100%;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: transparent;
  color: var(--text-soft);
  font: 600 13px/1 var(--font-ui);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}
.ghost-btn:hover {
  background: var(--panel-inner);
  color: var(--text);
}

/* ---------- responsive ---------- */
@media (min-width: 1100px) {
  .stage {
    padding-top: 30px;
  }
  .drawer {
    position: relative;
    transform: none;
    height: auto;
    max-height: calc(100dvh - 40px);
    border-radius: var(--r-panel);
    border: 1px solid var(--panel-border);
    box-shadow: var(--shadow-panel);
    margin: 36px 36px 36px 0;
  }
  .drawer:not(.is-open) {
    display: flex;
  }
  .scrim {
    display: none;
  }
  body {
    align-items: flex-start;
  }
  .calc {
    max-width: 420px;
  }
}
@media (max-width: 380px) {
  .k {
    height: 54px;
    font-size: 18px;
  }
  .k-op,
  .k-equals {
    font-size: 20px;
  }
  .display-value {
    font-size: 36px;
  }
}

/* ---------- a11y focus ---------- */
button:focus-visible {
  outline: 2px solid rgba(108, 140, 255, 0.65);
  outline-offset: 2px;
}
