:root {
  --bg-1: #07111f;
  --bg-2: #13233d;
  --spot-a: rgba(45, 212, 191, 0.22);
  --spot-b: rgba(56, 189, 248, 0.22);
  --spot-c: rgba(249, 115, 22, 0.14);
  --surface: rgba(9, 18, 34, 0.82);
  --surface-border: rgba(148, 163, 184, 0.18);
  --surface-shadow: 0 28px 80px rgba(2, 6, 23, 0.45);
  --panel-border: rgba(125, 211, 252, 0.12);
  --panel-top: rgba(7, 15, 28, 0.98);
  --panel-bottom: rgba(5, 11, 21, 0.95);
  --text-main: #f8fafc;
  --text-soft: #a8b3c7;
  --text-muted: #6f7f97;
  --eyebrow-color: #67e8f9;
  --grid-line: rgba(255, 255, 255, 0.03);
  --status-chip-bg: rgba(15, 23, 42, 0.72);
  --status-chip-border: rgba(103, 232, 249, 0.18);
  --status-chip-color: #d5f8ff;
  --status-dot: #34d399;
  --status-dot-shadow: rgba(52, 211, 153, 0.72);
  --utility-bg: linear-gradient(180deg, rgba(23, 37, 62, 0.95), rgba(12, 22, 38, 0.95));
  --utility-border: rgba(148, 163, 184, 0.18);
  --utility-text: #e2e8f0;
  --number-bg: linear-gradient(180deg, rgba(16, 28, 48, 0.96), rgba(11, 21, 38, 0.96));
  --number-border: rgba(148, 163, 184, 0.14);
  --number-text: #f8fafc;
  --function-bg: linear-gradient(180deg, rgba(28, 42, 67, 0.96), rgba(17, 28, 48, 0.96));
  --function-border: rgba(148, 163, 184, 0.14);
  --function-text: #f8fafc;
  --operator-bg: linear-gradient(180deg, rgba(28, 204, 183, 0.95), rgba(22, 138, 221, 0.95));
  --operator-border: rgba(207, 250, 254, 0.16);
  --operator-text: #f0fdfa;
  --clear-bg: linear-gradient(180deg, rgba(251, 113, 133, 0.96), rgba(225, 29, 72, 0.96));
  --clear-border: rgba(255, 228, 230, 0.16);
  --clear-text: #fff1f2;
  --equals-bg: linear-gradient(180deg, rgba(250, 204, 21, 0.98), rgba(249, 115, 22, 0.96));
  --equals-border: rgba(255, 237, 213, 0.18);
  --equals-text: #1f1100;
  --footer-bg: rgba(15, 23, 42, 0.5);
  --footer-border: rgba(148, 163, 184, 0.14);
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #fb7185;
  --shadow-key: 0 14px 30px rgba(2, 6, 23, 0.28);
}

html {
  color-scheme: dark;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg-1: #f6f9ff;
  --bg-2: #dbeafe;
  --spot-a: rgba(14, 165, 233, 0.16);
  --spot-b: rgba(59, 130, 246, 0.18);
  --spot-c: rgba(249, 115, 22, 0.12);
  --surface: rgba(255, 255, 255, 0.82);
  --surface-border: rgba(148, 163, 184, 0.3);
  --surface-shadow: 0 28px 70px rgba(148, 163, 184, 0.28);
  --panel-border: rgba(59, 130, 246, 0.12);
  --panel-top: rgba(255, 255, 255, 0.96);
  --panel-bottom: rgba(241, 245, 249, 0.94);
  --text-main: #0f172a;
  --text-soft: #475569;
  --text-muted: #64748b;
  --eyebrow-color: #0284c7;
  --grid-line: rgba(15, 23, 42, 0.035);
  --status-chip-bg: rgba(255, 255, 255, 0.72);
  --status-chip-border: rgba(14, 165, 233, 0.18);
  --status-chip-color: #0f172a;
  --status-dot: #0ea5e9;
  --status-dot-shadow: rgba(14, 165, 233, 0.48);
  --utility-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(226, 232, 240, 0.95));
  --utility-border: rgba(148, 163, 184, 0.28);
  --utility-text: #0f172a;
  --number-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(226, 232, 240, 0.95));
  --number-border: rgba(148, 163, 184, 0.24);
  --number-text: #0f172a;
  --function-bg: linear-gradient(180deg, rgba(224, 231, 255, 0.96), rgba(219, 234, 254, 0.95));
  --function-border: rgba(59, 130, 246, 0.14);
  --function-text: #0f172a;
  --operator-bg: linear-gradient(180deg, rgba(59, 130, 246, 0.95), rgba(14, 165, 233, 0.92));
  --operator-border: rgba(239, 246, 255, 0.2);
  --operator-text: #eff6ff;
  --clear-bg: linear-gradient(180deg, rgba(251, 113, 133, 0.96), rgba(225, 29, 72, 0.96));
  --clear-border: rgba(255, 228, 230, 0.24);
  --clear-text: #fff1f2;
  --equals-bg: linear-gradient(180deg, rgba(245, 158, 11, 0.96), rgba(249, 115, 22, 0.96));
  --equals-border: rgba(255, 237, 213, 0.24);
  --equals-text: #1c1917;
  --footer-bg: rgba(255, 255, 255, 0.58);
  --footer-border: rgba(148, 163, 184, 0.22);
  --shadow-key: 0 12px 26px rgba(148, 163, 184, 0.22);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Sora", "Segoe UI", sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(circle at 15% 20%, var(--spot-a), transparent 26%),
    radial-gradient(circle at 82% 14%, var(--spot-b), transparent 30%),
    radial-gradient(circle at 50% 100%, var(--spot-c), transparent 32%),
    linear-gradient(145deg, var(--bg-1), var(--bg-2));
  transition: background 0.35s ease, color 0.25s ease;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: radial-gradient(circle at center, black 48%, transparent 100%);
  opacity: 0.45;
}

.app {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.calculator {
  position: relative;
  width: min(100%, 460px);
  padding: 24px;
  border-radius: 30px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  box-shadow: var(--surface-shadow);
  backdrop-filter: blur(22px);
  overflow: hidden;
  animation: enter 0.6s ease;
  transition:
    background 0.3s ease,
    border-color 0.3s ease,
    box-shadow 0.3s ease,
    transform 0.3s ease;
}

.calculator::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at top left, rgba(125, 211, 252, 0.12), transparent 28%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.05), transparent 48%);
  pointer-events: none;
}

.calculator-header,
.display-shell,
.keys,
.calculator-footer {
  position: relative;
  z-index: 1;
}

.calculator-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.brand-block {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--eyebrow-color);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.calculator-header h1 {
  margin: 0;
  font-size: clamp(1.45rem, 4.5vw, 1.9rem);
  letter-spacing: -0.04em;
}

.subtitle {
  margin: 8px 0 0;
  color: var(--text-soft);
  font-size: 0.92rem;
  line-height: 1.5;
}

.header-actions {
  display: grid;
  gap: 10px;
  justify-items: end;
}

.status-chip,
.utility-button,
.mini-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  transition:
    background 0.25s ease,
    border-color 0.25s ease,
    color 0.25s ease,
    transform 0.15s ease,
    box-shadow 0.25s ease,
    filter 0.25s ease;
}

.status-chip {
  min-height: 40px;
  padding: 0 14px;
  background: var(--status-chip-bg);
  border-color: var(--status-chip-border);
  color: var(--status-chip-color);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-chip::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-dot);
  box-shadow: 0 0 14px var(--status-dot-shadow);
}

.utility-button,
.mini-button {
  font-family: inherit;
  cursor: pointer;
}

.utility-button {
  min-height: 42px;
  padding: 0 14px;
  background: var(--utility-bg);
  border-color: var(--utility-border);
  color: var(--utility-text);
  box-shadow: var(--shadow-key);
}

.utility-button__label,
.utility-button__value {
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.utility-button__label {
  opacity: 0.62;
}

.utility-button:hover,
.mini-button:hover {
  transform: translateY(-2px);
  filter: brightness(1.03);
}

.utility-button.is-active {
  box-shadow:
    0 0 0 1px rgba(14, 165, 233, 0.18),
    var(--shadow-key);
}

.utility-button:active,
.mini-button:active,
.utility-button.is-active,
.mini-button.is-active {
  transform: translateY(1px);
}

.utility-button:focus-visible,
.mini-button:focus-visible,
.key:focus-visible {
  outline: 2px solid #67e8f9;
  outline-offset: 2px;
}

.display-shell {
  display: grid;
  gap: 10px;
  min-height: 170px;
  padding: 18px;
  margin-bottom: 18px;
  border-radius: 24px;
  background: linear-gradient(180deg, var(--panel-top), var(--panel-bottom));
  border: 1px solid var(--panel-border);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    inset 0 -12px 32px rgba(15, 23, 42, 0.12);
  transition:
    background 0.3s ease,
    border-color 0.3s ease,
    box-shadow 0.3s ease,
    transform 0.25s ease;
}

.display-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.display-history,
.display-status,
.display-value {
  min-width: 0;
}

.display-history {
  min-height: 1.2rem;
  color: var(--text-muted);
  font-size: 0.83rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mini-button {
  min-height: 34px;
  padding: 0 12px;
  background: var(--utility-bg);
  border-color: var(--utility-border);
  color: var(--utility-text);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.mini-button.is-copied {
  background: linear-gradient(180deg, rgba(34, 197, 94, 0.95), rgba(22, 163, 74, 0.94));
  border-color: rgba(220, 252, 231, 0.24);
  color: #f0fdf4;
}

.display-value {
  display: block;
  min-height: 3.6rem;
  font-family: "IBM Plex Mono", Consolas, monospace;
  font-weight: 600;
  letter-spacing: -0.05em;
  line-height: 1.05;
  text-align: right;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: font-size 0.2s ease, color 0.2s ease;
}

.display-value[data-size="xl"] {
  font-size: clamp(2.45rem, 7vw, 3.15rem);
}

.display-value[data-size="lg"] {
  font-size: clamp(2rem, 6vw, 2.65rem);
}

.display-value[data-size="md"] {
  font-size: clamp(1.65rem, 5vw, 2.15rem);
}

.display-value[data-size="sm"] {
  font-size: clamp(1.3rem, 4vw, 1.7rem);
}

.display-status {
  min-height: 1.15rem;
  color: var(--text-soft);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.calculator[data-tone="success"] .display-status {
  color: #86efac;
}

.calculator[data-tone="warning"] .display-status {
  color: #fbbf24;
}

.calculator[data-tone="error"] .display-shell {
  border-color: rgba(251, 113, 133, 0.55);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    inset 0 -12px 32px rgba(15, 23, 42, 0.12),
    0 0 0 1px rgba(251, 113, 133, 0.12),
    0 0 28px rgba(251, 113, 133, 0.16);
}

.calculator[data-tone="error"] .display-status,
.calculator[data-tone="error"] .display-value {
  color: #ffd5dd;
}

.calculator.is-error {
  animation: soft-shake 0.28s ease;
}

.keys {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.key {
  position: relative;
  isolation: isolate;
  min-height: 66px;
  border-radius: 18px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 1.06rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  cursor: pointer;
  box-shadow: var(--shadow-key);
  transition:
    transform 0.14s ease,
    box-shadow 0.18s ease,
    filter 0.18s ease,
    border-color 0.18s ease,
    background 0.25s ease,
    color 0.25s ease;
}

.key::before {
  content: "";
  position: absolute;
  inset: 1px;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.12), transparent 42%);
  pointer-events: none;
  opacity: 0.6;
}

.key:hover {
  transform: translateY(-2px);
  filter: brightness(1.05);
}

.key:active,
.key.is-pressed {
  transform: translateY(2px) scale(0.985);
  box-shadow: 0 8px 18px rgba(2, 6, 23, 0.22);
}

.key-number {
  background: var(--number-bg);
  border-color: var(--number-border);
  color: var(--number-text);
}

.key-function {
  background: var(--function-bg);
  border-color: var(--function-border);
  color: var(--function-text);
}

.key-clear {
  background: var(--clear-bg);
  border-color: var(--clear-border);
  color: var(--clear-text);
}

.key-operator {
  background: var(--operator-bg);
  border-color: var(--operator-border);
  color: var(--operator-text);
}

.key-equals {
  background: var(--equals-bg);
  border-color: var(--equals-border);
  color: var(--equals-text);
  font-size: 1.18rem;
}

.calculator-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.calculator-footer span {
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--footer-bg);
  border: 1px solid var(--footer-border);
  color: var(--text-soft);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

@keyframes enter {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.985);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes soft-shake {
  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-4px);
  }

  75% {
    transform: translateX(4px);
  }
}

@media (max-width: 560px) {
  .app {
    padding: 14px;
  }

  .calculator {
    padding: 18px;
    border-radius: 26px;
  }

  .calculator-header {
    flex-direction: column;
    align-items: stretch;
  }

  .header-actions {
    justify-items: stretch;
  }

  .utility-button,
  .status-chip {
    justify-content: center;
  }

  .display-shell {
    min-height: 160px;
    padding: 16px;
  }

  .display-toolbar {
    align-items: flex-start;
  }

  .mini-button {
    flex-shrink: 0;
  }

  .key {
    min-height: 60px;
    border-radius: 16px;
    font-size: 1rem;
  }
}

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

  .keys {
    gap: 10px;
  }

  .key {
    min-height: 56px;
  }

  .calculator-footer span {
    width: 100%;
    text-align: center;
  }
}
