:root {
  color-scheme: light;
  --page: #e8eef1;
  --panel: #f9fbfb;
  --panel-strong: #ffffff;
  --ink: #152024;
  --muted: #667579;
  --line: #cbd7da;
  --accent: #0f7b6c;
  --accent-strong: #0a5f54;
  --accent-soft: #d9eee9;
  --function: #e4eaec;
  --operator: #18343b;
  --danger: #b14a3b;
  --shadow: 0 24px 70px rgba(20, 38, 43, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background:
    linear-gradient(135deg, rgba(15, 123, 108, 0.16), transparent 34%),
    linear-gradient(315deg, rgba(177, 74, 59, 0.12), transparent 28%),
    var(--page);
}

button {
  min-width: 0;
  border: 0;
  border-radius: 8px;
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition:
    transform 120ms ease,
    background 120ms ease,
    box-shadow 120ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(1px);
}

button:focus-visible {
  outline: 3px solid rgba(15, 123, 108, 0.35);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 430px) minmax(260px, 360px);
  gap: 24px;
  align-items: stretch;
  width: min(100% - 32px, 900px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 32px 0;
}

.calculator,
.history-panel {
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: rgba(249, 251, 251, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.calculator {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
}

.topbar,
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.45rem, 1.1rem + 1vw, 2rem);
}

h2 {
  font-size: 1rem;
}

.memory {
  display: grid;
  justify-items: end;
  gap: 2px;
  min-width: 84px;
  color: var(--muted);
  font-size: 0.76rem;
}

.memory strong {
  max-width: 110px;
  overflow: hidden;
  color: var(--ink);
  font-size: 1rem;
  text-overflow: ellipsis;
}

.display {
  display: grid;
  align-content: end;
  min-height: 128px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.expression {
  min-height: 25px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.94rem;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.value {
  display: block;
  overflow: hidden;
  font-size: clamp(2.25rem, 1.7rem + 2vw, 3.65rem);
  font-weight: 750;
  letter-spacing: 0;
  line-height: 1.05;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.memory-row,
.keys {
  display: grid;
  gap: 10px;
}

.memory-row {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.memory-row button,
.history-header button {
  min-height: 40px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 800;
}

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

.keys button {
  aspect-ratio: 1 / 0.78;
  min-height: 56px;
  background: var(--panel-strong);
  box-shadow: inset 0 0 0 1px rgba(21, 32, 36, 0.08);
  font-size: 1.24rem;
  font-weight: 760;
}

.keys .function {
  background: var(--function);
  color: #334247;
}

.keys .operator {
  background: var(--operator);
  color: #fff;
}

.keys .equals {
  grid-row: span 2;
  aspect-ratio: auto;
  background: var(--accent);
  color: #fff;
}

.history-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 20px;
}

.history-header button {
  padding: 0 14px;
  color: var(--danger);
  background: #f4e2de;
}

.history-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
  overflow: auto;
}

.history-list:empty::before {
  content: "Пока нет вычислений";
  display: grid;
  min-height: 180px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.95rem;
}

.history-item {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
  cursor: pointer;
}

.history-item span {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item strong {
  overflow: hidden;
  font-size: 1.12rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
    width: min(100% - 24px, 440px);
    padding: 16px 0;
  }

  .calculator,
  .history-panel {
    padding: 16px;
  }

  .history-panel {
    min-height: 260px;
  }

  .keys button {
    min-height: 52px;
  }
}
