:root {
  color-scheme: dark;
  --page: #111315;
  --shell: #050505;
  --screen: #090909;
  --number: #333335;
  --number-active: #4a4a4c;
  --utility: #a5a5a5;
  --utility-active: #c8c8c8;
  --operator: #ff9f0a;
  --operator-active: #ffffff;
  --operator-text-active: #ff9f0a;
  --text: #ffffff;
  --dark-text: #050505;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 159, 10, 0.16), transparent 30%),
    linear-gradient(145deg, #191b1f 0%, var(--page) 45%, #08090a 100%);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
}

.workspace {
  width: min(100vw, 980px);
  min-height: min(100vh, 932px);
  padding: clamp(16px, 4vw, 26px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
}

.calculator {
  position: relative;
  flex: 0 0 min(100%, 390px);
  width: min(100%, 390px);
  aspect-ratio: 390 / 760;
  min-height: 620px;
  padding: 26px 18px 20px;
  display: grid;
  grid-template-rows: minmax(190px, 1fr) auto;
  gap: 16px;
  background: var(--shell);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 48px;
  box-shadow:
    0 26px 70px rgba(0, 0, 0, 0.45),
    inset 0 0 0 8px rgba(255, 255, 255, 0.018);
  overflow: hidden;
}

.brand-mark {
  position: absolute;
  top: 32px;
  left: 28px;
  width: 58px;
  height: 58px;
  object-fit: contain;
}

.display {
  align-self: end;
  width: 100%;
  min-height: 124px;
  padding: 0 8px 6px;
  display: flex;
  align-items: end;
  justify-content: end;
  color: var(--text);
  font-size: clamp(48px, 17vw, 86px);
  font-weight: 300;
  line-height: 1;
  letter-spacing: 0;
  text-align: right;
  overflow: hidden;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.display.is-long {
  font-size: clamp(38px, 10vw, 62px);
}

.display.is-compact {
  font-size: clamp(24px, 6vw, 42px);
}

.display.is-tiny {
  font-size: clamp(18px, 4.5vw, 30px);
}

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

.key {
  width: 100%;
  aspect-ratio: 1;
  border: 0;
  border-radius: 50%;
  background: var(--number);
  color: var(--text);
  font: inherit;
  font-size: clamp(24px, 7vw, 34px);
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease, transform 80ms ease;
  -webkit-tap-highlight-color: transparent;
}

.key:active {
  transform: scale(0.96);
  background: var(--number-active);
}

.key:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.72);
  outline-offset: 3px;
}

.utility {
  background: var(--utility);
  color: var(--dark-text);
}

.utility:active {
  background: var(--utility-active);
}

.operator {
  background: var(--operator);
  color: var(--text);
  font-size: clamp(30px, 8vw, 42px);
}

.operator.is-selected,
.operator:active {
  background: var(--operator-active);
  color: var(--operator-text-active);
}

.zero {
  grid-column: span 2;
  aspect-ratio: auto;
  border-radius: 999px;
  padding-left: 30px;
  text-align: left;
}

.history-panel {
  flex: 0 1 320px;
  width: min(100%, 320px);
  height: min(760px, calc(100vh - 52px));
  min-height: 520px;
  padding: 24px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 18px;
  background: rgba(5, 5, 5, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 28px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(18px);
}

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

.history-header h1 {
  margin: 0;
  color: var(--text);
  font-size: 22px;
  font-weight: 650;
  letter-spacing: 0;
}

.history-clear {
  border: 0;
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.86);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.history-clear:active {
  background: rgba(255, 255, 255, 0.2);
}

.history-list {
  min-height: 0;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  list-style: none;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
}

.history-item {
  padding: 14px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.72);
}

.history-expression,
.history-result {
  display: block;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

.history-expression {
  font-size: 14px;
  line-height: 1.35;
}

.history-result {
  margin-top: 6px;
  color: var(--text);
  font-size: 20px;
  line-height: 1.2;
  text-align: right;
}

.history-empty {
  margin-top: 4px;
  color: rgba(255, 255, 255, 0.45);
  font-size: 14px;
  line-height: 1.45;
}

@media (max-width: 780px) {
  .workspace {
    min-height: 100vh;
    min-height: 100dvh;
    align-items: start;
    flex-direction: column;
  }

  .calculator,
  .history-panel {
    width: min(100%, 390px);
    margin-inline: auto;
  }

  .history-panel {
    height: auto;
    min-height: 220px;
    max-height: 360px;
  }
}

@media (max-width: 420px) {
  .workspace {
    padding: 0;
    gap: 0;
  }

  .calculator {
    flex-basis: auto;
    width: 100vw;
    min-height: 76vh;
    min-height: 76dvh;
    border-radius: 0;
    border: 0;
    padding: 18px 14px 18px;
  }

  .brand-mark {
    top: 20px;
    left: 18px;
    width: 52px;
    height: 52px;
  }

  .keys {
    gap: 10px;
  }

  .zero {
    padding-left: 28px;
  }

  .history-panel {
    width: 100vw;
    max-height: 34vh;
    border-radius: 0;
    border-inline: 0;
    padding: 18px 16px;
  }
}
