/* ---------- Reset y base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  background: radial-gradient(1200px 800px at 80% -10%, #2a2a3d 0%, #16161f 60%, #0d0d14 100%);
  color: #f4f4f5;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- Layout principal ---------- */
.app {
  width: 100%;
  max-width: 420px;
  height: 100dvh;
  max-height: 900px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: #e4e4e7;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f472b6, #818cf8);
  box-shadow: 0 0 12px rgba(129, 140, 248, 0.6);
}

/* ---------- Display ---------- */
.display {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 18px;
  padding: 18px 18px 22px;
  text-align: right;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02),
    0 10px 30px rgba(0, 0, 0, 0.25);
  min-height: 110px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow: hidden;
}

.history {
  min-height: 22px;
  font-size: 16px;
  color: #a1a1aa;
  word-wrap: break-word;
  word-break: break-all;
  line-height: 1.2;
  letter-spacing: 0.2px;
}

.result {
  font-size: 44px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 4px;
}

/* ---------- Teclado ---------- */
.keys {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding-bottom: env(safe-area-inset-bottom);
}

.key {
  appearance: none;
  border: none;
  outline: none;
  background: rgba(255, 255, 255, 0.06);
  color: #f4f4f5;
  border-radius: 16px;
  font-size: 22px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.06s ease, background 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.35),
    inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  min-height: 56px;
}

.key:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35),
    inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.key-func {
  background: rgba(244, 114, 182, 0.12);
  color: #f9a8d4;
}

.key-op {
  background: rgba(129, 140, 248, 0.16);
  color: #c4b5fd;
}

.key-eq {
  background: linear-gradient(135deg, #818cf8, #f472b6);
  color: #0b0b12;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.4),
    inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.key-zero {
  grid-column: span 1;
}

/* ---------- Footer ---------- */
.foot {
  text-align: center;
  color: #71717a;
  font-size: 12px;
  padding-bottom: 4px;
}

/* ---------- Móvil: ocupar toda la pantalla y botones grandes ---------- */
@media (max-width: 480px) {
  .app {
    max-width: 100%;
    max-height: 100dvh;
    padding: 14px;
    gap: 12px;
  }
  .key {
    font-size: 24px;
    min-height: 64px;
    border-radius: 18px;
  }
  .result {
    font-size: 48px;
  }
}

/* ---------- Móvil muy pequeño (iPhone SE, etc.) ---------- */
@media (max-width: 360px) {
  .key {
    font-size: 20px;
    min-height: 56px;
  }
  .result {
    font-size: 40px;
  }
}

/* ---------- Modo horizontal en móvil ---------- */
@media (max-height: 520px) and (orientation: landscape) {
  body {
    overflow: auto;
  }
  .app {
    max-height: none;
    height: auto;
  }
  .display {
    min-height: 80px;
    padding: 12px 14px;
  }
  .result {
    font-size: 34px;
  }
  .key {
    min-height: 44px;
    font-size: 18px;
  }
}
