:root {
  color-scheme: dark;
  --bg-top: #1c2335;
  --bg-bottom: #090c13;
  --panel: rgba(22, 27, 40, 0.92);
  --panel-border: rgba(255, 255, 255, 0.08);
  --display: #0b0f18;
  --text: #f6f7fb;
  --muted: #8f99ae;
  --key: #252c3d;
  --key-hover: #31394d;
  --function: #31394c;
  --operator: #173d3c;
  --operator-text: #76e6d2;
  --accent: #45d8bd;
  --accent-strong: #19b89c;
  --danger: #452938;
  --danger-text: #ff9dbf;
  --shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg-top: #eaf1f5;
  --bg-bottom: #c9d8df;
  --panel: rgba(247, 250, 252, 0.94);
  --panel-border: rgba(22, 52, 66, 0.1);
  --display: #e4ecf0;
  --text: #15232b;
  --muted: #687a84;
  --key: #edf2f4;
  --key-hover: #dfe8ec;
  --function: #dbe6e9;
  --operator: #d3eeea;
  --operator-text: #087d6b;
  --accent: #11a88f;
  --accent-strong: #0b8b77;
  --danger: #f4dfe7;
  --danger-text: #b22b60;
  --shadow: 0 30px 80px rgba(34, 67, 82, 0.2);
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 10%, rgba(69, 216, 189, 0.14), transparent 30%),
    radial-gradient(circle at 85% 85%, rgba(75, 112, 240, 0.12), transparent 30%),
    linear-gradient(145deg, var(--bg-top), var(--bg-bottom));
  transition: background 180ms ease;
}

button { font: inherit; }

.page-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 16px;
}

.calculator {
  width: min(100%, 520px);
  padding: 28px;
  border: 1px solid var(--panel-border);
  border-radius: 32px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.calculator__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.22em;
}

h1 { margin: 0; font-size: 24px; letter-spacing: -0.03em; }

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--panel-border);
  border-radius: 50%;
  color: var(--text);
  background: var(--key);
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}

.icon-button:hover { background: var(--key-hover); transform: rotate(12deg); }

.display {
  min-height: 130px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 20px;
  padding: 20px 22px;
  overflow: hidden;
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  background: var(--display);
  box-shadow: inset 0 2px 12px rgba(0, 0, 0, 0.14);
  text-align: right;
}

.display__expression {
  min-height: 24px;
  overflow: hidden;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.display__result {
  overflow: hidden;
  font-size: clamp(34px, 9vw, 52px);
  font-weight: 650;
  letter-spacing: -0.045em;
  line-height: 1.05;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.display__result.is-error { color: var(--danger-text); font-size: 28px; }

.keypad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 11px;
}

.keypad__spacer { grid-column: span 3; }

.key {
  min-width: 0;
  min-height: 58px;
  border: 1px solid var(--panel-border);
  border-radius: 17px;
  color: var(--text);
  background: var(--key);
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.12);
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: transform 90ms ease, background 90ms ease, box-shadow 90ms ease;
}

.key:hover { background: var(--key-hover); transform: translateY(-2px); }
.key:active, .key.is-pressed { transform: translateY(1px) scale(0.97); box-shadow: none; }
.key:focus-visible, .icon-button:focus-visible { outline: 3px solid rgba(69, 216, 189, 0.45); outline-offset: 2px; }
.key--function { color: var(--operator-text); background: var(--function); font-size: 17px; }
.key--operator { color: var(--operator-text); background: var(--operator); }
.key--danger { color: var(--danger-text); background: var(--danger); }
.key--equals { color: #062e27; background: linear-gradient(145deg, var(--accent), var(--accent-strong)); font-size: 27px; }
.key--equals:hover { background: linear-gradient(145deg, #65ead3, var(--accent)); }

.keyboard-tip {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

@media (max-width: 520px) {
  .page-shell { padding: 0; place-items: stretch; }
  .calculator { min-height: 100vh; width: 100%; padding: 22px 16px; border: 0; border-radius: 0; display: flex; flex-direction: column; justify-content: center; }
  .keypad { gap: 8px; }
  .key { min-height: 55px; border-radius: 15px; font-size: 18px; }
  .key--function { font-size: 15px; }
  .keyboard-tip { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
