:root{
  --bg: #0f1216;
  --panel: #161a20;
  --border: #232a33;
  --text: #e9eef5;
  --muted: #9fb0c6;
  --accent: #3a7afe;
  --accent-2: #22b07d;
  --warning: #f0b429;
  --danger: #ef5555;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0,0,0,.35);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body{
  margin: 0;
  background: linear-gradient(180deg, #0b0e12, #121720);
  color: var(--text);
  font-family: var(--sans);
  display: grid;
  place-items: center;
  padding: 24px;
}

.app{
  width: min(960px, 100%);
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
}

@media (max-width: 860px){
  .app{ grid-template-columns: 1fr; }
}

.calculator{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.display-wrap{
  background: #0b0f14;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 12px;
}

.display{
  display: block;
  width: 100%;
  text-align: right;
  font-family: var(--mono);
  font-size: clamp(28px, 6vw, 44px);
  letter-spacing: 0.08em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  color: var(--text);
  min-height: 1.4em;
}

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

.key{
  appearance: none;
  border: 1px solid var(--border);
  background: #1b212a;
  color: var(--text);
  font-size: 18px;
  padding: 14px 0;
  border-radius: 10px;
  cursor: pointer;
  transition: transform .02s ease, background .2s ease, border-color .2s ease;
  user-select: none;
}

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

.key:active{
  transform: translateY(1px);
}

.key:hover{
  background: #222a35;
  border-color: #2b3644;
}

.key-op{
  background: #1a2432;
  border-color: #273244;
}

.key-func{
  background: #231d14;
  border-color: #3b2e1a;
  color: #ffd596;
}

.key-equal{
  background: var(--accent);
  border-color: #2b6df5;
  color: #fff;
  font-weight: 700;
}

.span-2{ grid-column: span 2; }

.history{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  min-height: 200px;
}

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

.history__header h2{
  margin: 0;
  font-size: 16px;
  color: var(--muted);
  font-weight: 600;
}

.history__clear{
  appearance: none;
  font: inherit;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #3a2b2b;
  background: #2a1b1b;
  color: #ffb3b3;
  cursor: pointer;
}

.history__clear:hover{
  background: #341f1f;
}

.history__list{
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}

.history__item{
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: baseline;
  padding: 8px 10px;
  background: #131922;
  border: 1px solid #202838;
  border-radius: 8px;
  cursor: pointer;
}

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

.history__item .expr{
  color: var(--muted);
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history__item .eq{ opacity: .6; }
.history__item .res{
  font-family: var(--mono);
  font-weight: 700;
}
