:root {
  font-family: "Segoe UI", Tahoma, sans-serif;
  color: #1f2a44;
  background-color: #f6f8fb;
  line-height: 1.5;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: linear-gradient(180deg, #f6f8fb 0%, #ffffff 100%);
}

.app-header,
.app-footer {
  text-align: center;
  padding: 1.5rem;
  background-color: #ffffff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

main {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 2rem 1rem;
}

.calculator {
  width: 100%;
  max-width: 360px;
  background-color: #ffffff;
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(31, 42, 68, 0.12);
  padding: 1.5rem;
  display: grid;
  gap: 1rem;
  touch-action: manipulation;
  /* Define a single-column grid so the display stacks above the keypad on every screen size. */
  grid-template-columns: 1fr;
  grid-template-areas:
    "screen"
    "grid"
    "toggle"
    "history";
}

.calculator__screen-row {
  grid-area: screen;
  display: flex;
  gap: 0.75rem;
  align-items: stretch;
}

.calculator__screen {
  background-color: #0a2540;
  color: #ffffff;
  font-size: 2rem;
  padding: 1rem;
  border-radius: 12px;
  min-height: 3.5rem;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  letter-spacing: 0.04em;
  flex: 1 1 auto;
}

.calculator__undo {
  flex: 0 0 auto;
  align-self: center;
  min-width: 3rem;
  padding: 0.5rem 0.75rem;
}

.calculator__undo[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}

.calculator__status {
  /* Keep the status text available to assistive tech while hiding it visually. */
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.calculator__grid {
  grid-area: grid;
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* Keep the auto-constant toggle anchored underneath the keypad for predictable scanning order. */
.calculator__auto-constant {
  grid-area: toggle;
}

.button {
  background: #1b8ef2;
  color: #ffffff;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  padding: 0.75rem;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.button:focus-visible {
  outline: 3px solid #f2a81b;
  outline-offset: 2px;
}

.button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(27, 142, 242, 0.35);
}

.button--secondary {
  background: #f2a81b;
  color: #0a2540;
}

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

.history {
  grid-area: history;
  background-color: #f9fbff;
  border-radius: 12px;
  padding: 1rem;
  font-size: 0.9rem;
  color: #44546a;
  max-height: 120px;
  overflow-y: auto;
}

.history__item {
  margin: 0.25rem 0;
}

.tagline {
  margin: 0.5rem 0 0;
  color: #44546a;
}

.app-header__kid-toggle {
  margin-top: 0.75rem;
  font-size: 0.95rem;
}

@media (max-width: 480px) {
  .calculator {
    padding: 1rem;
    gap: 0.75rem;
  }

  .calculator__screen {
    font-size: 1.75rem;
  }
}
