/* iPhone-style Calculator Clone
       - Responsive (5+ breakpoints)
       - Light/Dark toggle
       - Memory buttons (MC/MR/M+/M-)
       - iPhone-like alignment: display top, grid of buttons, right column operators
    */

:root {
  --bg: #f2f2f4;
  --panel: #ffffff;
  --display-bg: #000000;
  --display-color: #ffffff;
  --btn-fn-bg: #d4d4d2; /* AC, +/- , % */
  --btn-num-bg: #333333; /* number buttons */
  --btn-op-bg: #ff9500; /* operator buttons */
  --btn-text-fn: #000000;
  --btn-text-num: #ffffff;
  --shadow: 0 8px 30px rgba(15, 15, 15, 0.12);
  --gap: 10px;
  --radius: 20px;
  --container-width: clamp(280px, 42vw, 420px);
  --display-height: clamp(84px, 14vw, 120px);
  --btn-size: clamp(56px, 10vw, 84px);
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial;
}

/* Dark theme overrides */
[data-theme="dark"] {
  --bg: #0b0b0b;
  --panel: #1c1c1e;
  --display-bg: #000000;
  --display-color: #ffffff;
  --btn-fn-bg: #2c2c2e;
  --btn-num-bg: #2c2c2e;
  --btn-op-bg: #ff9f0a;
  --btn-text-fn: #ffffff;
  --btn-text-num: #ffffff;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-family);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding: 20px;
}

.calc-wrap {
  width: var(--container-width);
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.15),
    rgba(255, 255, 255, 0)
  );
  border-radius: 28px;
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  backdrop-filter: blur(6px);
  user-select: none;
}

/* Top controls: theme toggle + optional memory indicator */
.top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.theme-toggle {
  background: transparent;
  border: 1px solid rgba(0, 0, 0, 0.06);
  padding: 6px 10px;
  font-size: 18px;
  border-radius: 12px;
  cursor: pointer;
}

.memory-indicator {
  font-size: 12px;
  color: var(--btn-text-fn);
  opacity: 0.9;
}

.display {
  height: var(--display-height);
  border-radius: 16px;
  background: var(--display-bg);
  color: var(--display-color);
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 18px 18px;
  font-weight: 600;
  font-size: clamp(28px, 8vw, 54px);
  line-height: 1;
  overflow: hidden;
  white-space: nowrap;
}

/* Buttons grid */
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
  align-items: center;
}

.btn {
  height: var(--btn-size);
  min-height: var(--btn-size);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: clamp(18px, 4.6vw, 28px);
  border: 0;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.08) inset;
  transition: transform 0.06s ease, box-shadow 0.06s ease;
}
.btn:active {
  transform: translateY(1px);
}

.btn.fn {
  background: var(--btn-fn-bg);
  color: var(--btn-text-fn);
}
.btn.num {
  background: var(--btn-num-bg);
  color: var(--btn-text-num);
}
.btn.op {
  background: var(--btn-op-bg);
  color: #fff;
}

/* 0 button spans two columns and is pill shaped like iPhone */
.btn.zero {
  grid-column: span 2;
  border-radius: 40px;
  display: flex;
  justify-content: flex-start;
  padding-left: 28px;
}

/* Memory row styles - smaller buttons */
.mem-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.mem-row .btn {
  height: 42px;
  min-height: 42px;
  border-radius: 10px;
  font-size: 14px;
}

/* responsive tweaks at various breakpoints (minimum 5 breakpoints requested) */
/* breakpoints: 320, 375, 414, 768, 1024 */

@media (min-width: 320px) {
  :root {
    --gap: 8px;
  }
}
@media (min-width: 375px) {
  :root {
    --gap: 10px;
  }
}
@media (min-width: 414px) {
  :root {
    --btn-size: clamp(60px, 9vw, 88px);
  }
}
@media (min-width: 768px) {
  :root {
    --container-width: 420px;
    --display-height: 120px;
  }
  .calc-wrap {
    padding: 22px;
  }
}
@media (min-width: 1024px) {
  :root {
    --container-width: 480px;
    --btn-size: 88px;
  }
}

/* accessibility focus */
.btn:focus {
  outline: 3px solid rgba(255, 159, 10, 0.12);
}

/* small helper for hidden labels (screen readers) */
.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
