:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --panel: #141821;
  --panel-top: #181d28;
  --line: #262d3c;
  --line-soft: rgba(255, 255, 255, 0.045);
  --text: #eef1f7;
  --muted: #8b93a6;
  --accent: #ffb545;
  --accent-hot: #ffc66d;
  --key: #1c2230;
  --key-hover: #232b3c;
  --op: #cfd8ea;
  --danger: #ff7a7a;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  padding: 32px 20px;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(255, 181, 69, 0.12), transparent 60%),
    radial-gradient(800px 520px at 100% 100%, rgba(92, 132, 255, 0.1), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.shell {
  display: grid;
  grid-template-columns: minmax(320px, 400px) minmax(260px, 320px);
  gap: 18px;
  align-items: start;
}

.card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: linear-gradient(180deg, var(--panel-top), var(--panel));
  box-shadow:
    0 30px 60px -30px rgba(0, 0, 0, 0.85),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px 14px;
}

.brand {
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: #717a8e;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #58c98d;
  box-shadow: 0 0 0 3px rgba(88, 201, 141, 0.14);
}

.display {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
  min-height: 116px;
  padding: 18px 20px;
  border: 1px solid var(--line-soft);
  border-radius: 18px;
  background: linear-gradient(180deg, #090b0f, #0d1016);
  box-shadow: inset 0 2px 12px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.expression {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 34px;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  color: var(--text);
}

.expression::-webkit-scrollbar {
  display: none;
}

.expression.is-long {
  font-size: 27px;
}

.expression.is-longer {
  font-size: 21px;
}

.expression.is-error {
  font-size: 19px;
  color: var(--danger);
}

.preview {
  min-height: 20px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: #6f7789;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 16px;
}

.key {
  height: 60px;
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  background: var(--key);
  color: var(--text);
  font-family: inherit;
  font-size: 22px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background 120ms ease, transform 80ms ease, border-color 120ms ease;
  touch-action: manipulation;
}

.key:hover {
  background: var(--key-hover);
  border-color: rgba(255, 255, 255, 0.09);
}

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

.key:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.key.fn {
  background: #161b25;
  color: #9aa4b8;
  font-size: 19px;
}

.key.fn:hover {
  background: #1d232f;
}

.key.op {
  color: var(--op);
  background: #232a39;
  font-size: 25px;
}

.key.op:hover {
  background: #2a3346;
}

.key.equals {
  grid-column: span 4;
  height: 56px;
  border: none;
  border-radius: 16px;
  background: linear-gradient(180deg, var(--accent-hot), #f0a027);
  color: #201607;
  font-size: 24px;
  font-weight: 700;
  box-shadow: 0 14px 28px -14px rgba(255, 181, 69, 0.9);
}

.key.equals:hover {
  background: linear-gradient(180deg, #ffd38a, #f7ab34);
}

.card-foot {
  display: flex;
  gap: 16px;
  padding: 14px 4px 2px;
  font-size: 11px;
  letter-spacing: 0.02em;
  color: #6c748a;
}

kbd {
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: #11151d;
  font-family: inherit;
  font-size: 10px;
  color: #a6aec1;
}

.history {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: linear-gradient(180deg, #151a24, #121620);
  box-shadow: 0 30px 60px -34px rgba(0, 0, 0, 0.8);
  max-height: 558px;
  display: flex;
  flex-direction: column;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 2px 12px;
  border-bottom: 1px solid var(--line-soft);
}

.history-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.ghost {
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: #8c95a9;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease;
}

.ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: #3a4457;
}

.ghost:disabled {
  opacity: 0.35;
  cursor: default;
}

.history-empty {
  margin: 14px 2px 4px;
  padding: 16px;
  border: 1px dashed #29303f;
  border-radius: 14px;
  font-size: 12.5px;
  line-height: 1.55;
  color: #767f93;
}

.history-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.history-list:empty {
  display: none;
}

.history-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.history-item:hover {
  background: #1a2029;
  border-color: var(--line);
}

.history-item .expr {
  font-size: 11.5px;
  color: #788196;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item .res {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

@media (max-width: 760px) {
  body {
    place-content: start center;
    padding: 18px 14px 34px;
  }

  .shell {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
    width: 100%;
  }

  .card,
  .history {
    padding: 14px;
    border-radius: 22px;
  }

  .display {
    min-height: 100px;
    padding: 14px 16px;
  }

  .expression {
    font-size: 30px;
  }

  .expression.is-long {
    font-size: 24px;
  }

  .key {
    height: 54px;
    border-radius: 14px;
  }

  .history {
    max-height: 320px;
  }
}

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