:root {
  --fondo: #eef1f6;
  --marco: #ffffff;
  --texto: #12161f;
  --tenue: #7b8494;
  --tecla: #f3f5f9;
  --tecla-activa: #e3e7ef;
  --fn: #dfe4ec;
  --op: #2f6df6;
  --op-texto: #ffffff;
  --sombra: 0 20px 50px rgba(18, 22, 31, .12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #0c0f16;
    --marco: #171b24;
    --texto: #f2f4f8;
    --tenue: #8d95a5;
    --tecla: #232936;
    --tecla-activa: #2f3746;
    --fn: #2c3341;
    --op: #3b7bff;
    --sombra: 0 20px 50px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--fondo);
  color: var(--texto);
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.calc {
  width: min(100%, 360px);
  background: var(--marco);
  border-radius: 26px;
  padding: 22px;
  box-shadow: var(--sombra);
}

.pantalla {
  padding: 12px 8px 20px;
  text-align: right;
  overflow: hidden;
}

.historial {
  min-height: 1.4em;
  color: var(--tenue);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.resultado {
  display: block;
  font-size: clamp(34px, 12vw, 52px);
  font-weight: 600;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.tecla {
  appearance: none;
  border: 0;
  border-radius: 16px;
  aspect-ratio: 1 / 1;
  font-size: 22px;
  font-weight: 500;
  font-family: inherit;
  color: var(--texto);
  background: var(--tecla);
  cursor: pointer;
  transition: background .12s ease, transform .06s ease;
}

.tecla:hover { background: var(--tecla-activa); }
.tecla:active { transform: scale(.95); }
.tecla:focus-visible { outline: 2px solid var(--op); outline-offset: 2px; }

.tecla.fn { background: var(--fn); }
.tecla.op, .tecla.igual { background: var(--op); color: var(--op-texto); }
.tecla.op:hover, .tecla.igual:hover { filter: brightness(1.08); }
.tecla.op.seleccionada { box-shadow: inset 0 0 0 3px var(--marco); }

@media (max-width: 380px) {
  .calc { padding: 16px; }
  .teclado { gap: 8px; }
  .tecla { font-size: 20px; border-radius: 14px; }
}
