/* ═══════════════════════════════════════════════════════════
   SCIENTIFIC CALCULATOR PWA - PREMIUM DARK THEME
   Inspired by Casio fx-991 with modern aesthetics
   ═══════════════════════════════════════════════════════════ */

/* ═══ CSS VARIABLES ═══ */
:root {
  /* Colors */
  --bg-body: #05050a;
  --bg-calc: #121222;
  --bg-calc-light: #1b1b33;
  --bg-display: #0b0b14;
  --bg-display-dark: #07070d;
  --text-display: #f0f0f8;
  --text-display-dim: #606085;

  /* Button colors */
  --btn-func: #2d2d48;
  --btn-func-hover: #383860;
  --btn-func-active: #252540;
  --btn-func-text: #c8c8e0;

  --btn-num: #d4d4e0;
  --btn-num-hover: #e0e0ec;
  --btn-num-active: #c0c0cc;
  --btn-num-text: #1a1a2e;

  --btn-op: #8888a8;
  --btn-op-hover: #9898b8;
  --btn-op-active: #7878a0;
  --btn-op-text: #1a1a2e;

  --btn-shift: #e8a020;
  --btn-shift-active: #d09018;
  --btn-alpha: #e04848;
  --btn-alpha-active: #c83838;

  --btn-equals: #4a6fa5;
  --btn-equals-hover: #5a7fb5;
  --btn-equals-active: #3a5f95;

  --btn-clear: #5878a8;
  --btn-clear-hover: #6888b8;
  --btn-clear-active: #4868a0;

  --btn-ans: #6b7b8d;
  --btn-ans-hover: #7b8b9d;

  --btn-del: #5a5a78;

  /* Labels */
  --label-shift: #4ecdc4;
  --label-alpha: #ff6b6b;

  /* Accents */
  --accent-teal: #4ecdc4;
  --accent-green: #7fdb8a;
  --accent-free: #4ecdc4;

  /* Shadows */
  --shadow-btn: 0 3px 0 rgba(0,0,0,0.35), 0 4px 8px rgba(0,0,0,0.2);
  --shadow-btn-active: 0 1px 0 rgba(0,0,0,0.35), 0 1px 3px rgba(0,0,0,0.2);
  --shadow-display: inset 0 2px 8px rgba(0,0,0,0.3), inset 0 0 2px rgba(0,0,0,0.1);

  /* Sizing */
  --key-gap: 5px;
  --key-radius: 7px;
  --display-radius: 10px;
  --calc-padding: 10px;

  /* Safe areas */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);

  /* Typography */
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;
}

/* ═══ RESET & BASE ═══ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: var(--font-ui);
  background: var(--bg-body);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* ═══ CALCULATOR BODY ═══ */
.calculator {
  position: relative;
  width: 100%;
  max-width: 420px;
  height: 100%;
  max-height: 100dvh;
  background: var(--bg-calc);
  background-image:
    linear-gradient(135deg, rgba(255,255,255,0.03) 0%, transparent 50%),
    linear-gradient(to bottom, #1e1e34 0%, #1a1a2e 20%, #181830 100%);
  display: flex;
  flex-direction: column;
  padding: var(--calc-padding);
  padding-top: calc(var(--sat) + var(--calc-padding));
  padding-bottom: calc(var(--sab) + 4px);
  padding-left: calc(var(--sal) + var(--calc-padding));
  padding-right: calc(var(--sar) + var(--calc-padding));
  overflow: hidden;
}

/* ═══ DISPLAY ═══ */
.display-container {
  flex-shrink: 0;
  margin-bottom: 6px;
}

.display {
  background: linear-gradient(160deg, #10101d 0%, #07070e 100%);
  border: 1px solid #28283f;
  border-radius: var(--display-radius);
  box-shadow: inset 0 2px 10px rgba(0,0,0,0.85), 0 0 15px rgba(78, 205, 196, 0.08);
  padding: 12px 16px;
  min-height: 125px;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.display::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 35%;
  background: linear-gradient(to bottom, rgba(255,255,255,0.03), transparent);
  pointer-events: none;
  border-radius: var(--display-radius) var(--display-radius) 0 0;
}

.display__status-bar {
  display: flex;
  gap: 8px;
  font-size: 9px;
  font-family: var(--font-mono);
  font-weight: 600;
  color: #4a4a70;
  margin-bottom: 6px;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
  letter-spacing: 0.5px;
}

.status-item {
  transition: color 0.15s, opacity 0.15s, text-shadow 0.15s;
}

.status-item.active {
  color: var(--accent-teal);
  text-shadow: 0 0 4px rgba(78, 205, 196, 0.6);
}

.display__history {
  font-family: var(--font-mono);
  font-size: 13px;
  color: #7b7b9b;
  min-height: 0;
  flex-shrink: 1;
  overflow: hidden;
  text-align: right;
  line-height: 1.5;
  position: relative;
  z-index: 1;
}

.display__expression {
  font-family: var(--font-mono);
  font-size: 21px;
  font-weight: 500;
  color: #e2e2f0;
  text-align: right;
  min-height: 30px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  position: relative;
  z-index: 1;
  scrollbar-width: none;
}

.display__expression::-webkit-scrollbar {
  display: none;
}

.expression-text {
  min-width: 0;
}

.cursor {
  display: inline-block;
  animation: blink 1s step-end infinite;
  color: var(--accent-teal);
  font-weight: 300;
  margin-left: 1px;
  text-shadow: 0 0 6px rgba(78, 205, 196, 0.8);
}

@keyframes blink {
  50% { opacity: 0; }
}

.display__result {
  font-family: var(--font-mono);
  font-size: 29px;
  font-weight: 600;
  color: var(--accent-teal);
  text-shadow: 0 0 8px rgba(78, 205, 196, 0.25);
  text-align: right;
  min-height: 38px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  position: relative;
  z-index: 1;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
}

.display__result::-webkit-scrollbar {
  display: none;
}

/* ═══ TOOLBAR ═══ */
.toolbar {
  display: flex;
  gap: 4px;
  margin-bottom: 6px;
  flex-shrink: 0;
  align-items: center;
}

.toolbar__btn {
  flex: 1;
  height: 30px;
  border: none;
  border-radius: 5px;
  background: var(--btn-func);
  color: var(--btn-func-text);
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  letter-spacing: 0.5px;
}

.toolbar__btn:active {
  background: var(--btn-func-active);
}

.toolbar__btn--free {
  background: linear-gradient(135deg, var(--accent-teal), #38b2ac);
  color: #fff;
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 1px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
  flex: 0.8;
  cursor: default;
  box-shadow: 0 2px 8px rgba(78, 205, 196, 0.3);
}

/* ═══ KEYPAD LAYOUT ═══ */
.keypad {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 0;
}

.keypad__func-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: var(--key-gap);
  flex-shrink: 0;
}

.keypad__numpad {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--key-gap);
  margin-top: 4px;
}

.keypad__row--num {
  display: grid;
  gap: var(--key-gap);
  grid-template-columns: repeat(5, 1fr);
  flex: 1;
}

/* ═══ D-PAD STYLING ═══ */
.dpad-container {
  grid-column: 3 / span 2;
  grid-row: 1 / span 2;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  width: 100%;
  aspect-ratio: 1;
}

.dpad {
  position: relative;
  width: 96px;
  height: 96px;
  background: radial-gradient(circle, #2d2d48 0%, #151526 100%);
  border: 2px solid #383858;
  border-radius: 50%;
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.06), 
              inset 0 -2px 4px rgba(0,0,0,0.65),
              0 4px 8px rgba(0,0,0,0.5);
  display: flex;
  justify-content: center;
  align-items: center;
}

.dpad__btn {
  position: absolute;
  background: transparent;
  border: none;
  color: #8888a5;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, text-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  padding: 0;
  margin: 0;
  z-index: 2;
}

.dpad__btn:active {
  color: var(--accent-teal);
  text-shadow: 0 0 5px rgba(78, 205, 196, 0.6);
}

.dpad__btn--up {
  top: 5px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 25px;
}

.dpad__btn--down {
  bottom: 5px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 25px;
}

.dpad__btn--left {
  left: 5px;
  top: 50%;
  transform: translateY(-50%);
  width: 25px;
  height: 40px;
}

.dpad__btn--right {
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  width: 25px;
  height: 40px;
}

.dpad__center {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #161626 0%, #25253e 100%);
  border: 1px solid #383858;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0,0,0,0.45), inset 0 1px 2px rgba(255,255,255,0.08);
  z-index: 1;
}

/* ═══ KEY BASE STYLES ═══ */
.key {
  position: relative;
  border: none;
  border-radius: var(--key-radius);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2px 2px 4px;
  min-height: 38px;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.1s;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
}

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

/* ═══ KEY VARIANTS ═══ */

/* Function keys (dark) */
.key--func {
  background: linear-gradient(to bottom, #35355a, #2a2a4a);
  box-shadow: var(--shadow-btn);
  color: var(--btn-func-text);
}
.key--func:active {
  background: var(--btn-func-active);
  box-shadow: var(--shadow-btn-active);
}

/* Navigation keys */
.key--nav {
  background: linear-gradient(to bottom, #35355a, #2a2a4a);
  box-shadow: var(--shadow-btn);
  color: var(--btn-func-text);
}
.key--nav:active {
  background: var(--btn-func-active);
  box-shadow: var(--shadow-btn-active);
}

/* SHIFT key */
.key--shift {
  background: linear-gradient(to bottom, #f0b030, #d89820);
  box-shadow: 0 3px 0 rgba(180,120,0,0.5), 0 4px 8px rgba(0,0,0,0.2);
  color: #fff;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.key--shift:active {
  background: var(--btn-shift-active);
  box-shadow: var(--shadow-btn-active);
}
.key--shift.active {
  background: linear-gradient(to bottom, #ffd050, #f0b830);
  box-shadow: 0 0 12px rgba(240,176,48,0.5), var(--shadow-btn);
}

/* ALPHA key */
.key--alpha {
  background: linear-gradient(to bottom, #e85050, #d03838);
  box-shadow: 0 3px 0 rgba(160,40,40,0.5), 0 4px 8px rgba(0,0,0,0.2);
  color: #fff;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.key--alpha:active {
  background: var(--btn-alpha-active);
  box-shadow: var(--shadow-btn-active);
}
.key--alpha.active {
  background: linear-gradient(to bottom, #ff6868, #e85050);
  box-shadow: 0 0 12px rgba(232,80,80,0.5), var(--shadow-btn);
}

/* Number keys (light) */
.key--num {
  background: linear-gradient(to bottom, #e0e0ec, #d0d0dc);
  box-shadow: 0 3px 0 rgba(160,160,180,0.6), 0 4px 8px rgba(0,0,0,0.15);
  color: var(--btn-num-text);
  font-weight: 600;
}
.key--num:active {
  background: var(--btn-num-active);
  box-shadow: var(--shadow-btn-active);
}

/* Operator keys */
.key--op {
  background: linear-gradient(to bottom, #9898b8, #8888a8);
  box-shadow: 0 3px 0 rgba(100,100,130,0.6), 0 4px 8px rgba(0,0,0,0.15);
  color: #1a1a2e;
  font-weight: 700;
}
.key--op:active {
  background: var(--btn-op-active);
  box-shadow: var(--shadow-btn-active);
}

/* Delete key */
.key--del {
  background: linear-gradient(to bottom, #606088, #505078);
  box-shadow: var(--shadow-btn);
  color: #e0e0f0;
}
.key--del:active {
  background: #454568;
  box-shadow: var(--shadow-btn-active);
}

/* Clear key */
.key--clear {
  background: linear-gradient(to bottom, #6888b0, #5878a0);
  box-shadow: 0 3px 0 rgba(60,80,120,0.6), 0 4px 8px rgba(0,0,0,0.15);
  color: #fff;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.key--clear:active {
  background: var(--btn-clear-active);
  box-shadow: var(--shadow-btn-active);
}

/* Ans key */
.key--ans {
  background: linear-gradient(to bottom, #7b8b9d, #6b7b8d);
  box-shadow: 0 3px 0 rgba(80,90,110,0.6), 0 4px 8px rgba(0,0,0,0.15);
  color: #fff;
  font-weight: 600;
}
.key--ans:active {
  background: #5b6b7d;
  box-shadow: var(--shadow-btn-active);
}

/* Equals key */
.key--equals {
  background: linear-gradient(to bottom, #5a7fc0, #4a6fb0);
  box-shadow: 0 3px 0 rgba(50,80,140,0.6), 0 4px 8px rgba(0,0,0,0.2);
  color: #fff;
  font-weight: 700;
  font-size: 20px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.key--equals:active {
  background: var(--btn-equals-active);
  box-shadow: var(--shadow-btn-active);
}

/* Exp key */
.key--exp {
  background: linear-gradient(to bottom, #3a3a5a, #2d2d48);
}

/* ═══ KEY LABELS ═══ */
.key__label {
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  pointer-events: none;
  z-index: 1;
}

.key__label sub {
  font-size: 0.7em;
}

.key--num .key__label {
  font-size: 18px;
  font-weight: 700;
}

.key--op .key__label {
  font-size: 18px;
  font-weight: 800;
}

.key--equals .key__label {
  font-size: 22px;
}

.key--clear .key__label {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 1px;
}

.key--ans .key__label {
  font-size: 15px;
  font-weight: 700;
}

.key--del .key__label {
  font-size: 18px;
}

.key--shift .key__label,
.key--alpha .key__label {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.8px;
}

/* Shift & Alpha secondary labels */
.key__shift-label,
.key__alpha-label {
  position: absolute;
  font-size: 8px;
  font-weight: 600;
  pointer-events: none;
  line-height: 1;
  letter-spacing: 0.3px;
  white-space: nowrap;
  opacity: 0.85;
}

.key__shift-label {
  top: 2px;
  left: 3px;
  color: var(--label-shift);
  font-family: var(--font-ui);
}

.key__alpha-label {
  top: 2px;
  right: 3px;
  color: var(--label-alpha);
  font-family: var(--font-ui);
}

/* When SHIFT is active, highlight shift labels */
.calculator.shift-active .key__shift-label {
  opacity: 1;
  text-shadow: 0 0 6px rgba(78, 205, 196, 0.5);
  animation: labelPulse 1.2s ease-in-out infinite;
}

/* When ALPHA is active, highlight alpha labels */
.calculator.alpha-active .key__alpha-label {
  opacity: 1;
  text-shadow: 0 0 6px rgba(255, 107, 107, 0.5);
  animation: labelPulse 1.2s ease-in-out infinite;
}

@keyframes labelPulse {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 1; }
}

/* ═══ KEY PRESS RIPPLE ═══ */
.key::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle, rgba(255,255,255,0.15) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
.key:active::after {
  opacity: 1;
  transition: opacity 0.05s;
}

/* ═══ PANELS / OVERLAYS ═══ */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 90;
  transition: opacity 0.25s;
}
.overlay--hidden {
  opacity: 0;
  pointer-events: none;
}

.panel {
  position: absolute;
  top: 10%;
  left: 5%;
  right: 5%;
  bottom: 10%;
  background: linear-gradient(to bottom, #22223a, #1a1a30);
  border-radius: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 1px rgba(255,255,255,0.1);
  overflow: hidden;
  transition: opacity 0.25s, transform 0.25s;
}

.panel--hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px) scale(0.97);
}

.panel__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.panel__header h2 {
  font-size: 16px;
  font-weight: 700;
  color: #e0e0f0;
  letter-spacing: 0.5px;
}

.panel__close {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.08);
  color: #a0a0c0;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.panel__close:active {
  background: rgba(255,255,255,0.15);
}

.panel__body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  -webkit-overflow-scrolling: touch;
}

.panel__body::-webkit-scrollbar {
  width: 4px;
}
.panel__body::-webkit-scrollbar-track {
  background: transparent;
}
.panel__body::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
}

.panel__footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.panel__action {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: rgba(232, 80, 80, 0.15);
  color: #e85050;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.panel__action:active {
  background: rgba(232, 80, 80, 0.25);
}

.panel__select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  color: #c8c8e0;
  font-family: var(--font-ui);
  font-size: 14px;
  margin-bottom: 10px;
  -webkit-appearance: none;
  outline: none;
}

.panel__input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  color: #c8c8e0;
  font-family: var(--font-mono);
  font-size: 16px;
  outline: none;
}
.panel__input:focus {
  border-color: var(--accent-teal);
}

.conv-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.conv-row .panel__select {
  width: 40%;
  flex-shrink: 0;
  margin-bottom: 0;
}
.conv-arrow {
  text-align: center;
  font-size: 20px;
  color: var(--accent-teal);
  margin: 4px 0;
}

/* History item */
.history-item {
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(255,255,255,0.03);
  margin-bottom: 6px;
  cursor: pointer;
  transition: background 0.15s;
}
.history-item:active {
  background: rgba(255,255,255,0.08);
}
.history-item__expr {
  font-family: var(--font-mono);
  font-size: 13px;
  color: #8888a8;
  margin-bottom: 2px;
}
.history-item__result {
  font-family: var(--font-mono);
  font-size: 17px;
  font-weight: 600;
  color: #c8c8e0;
}

/* Constants item */
.const-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(255,255,255,0.03);
  margin-bottom: 4px;
  cursor: pointer;
  transition: background 0.15s;
}
.const-item:active {
  background: rgba(255,255,255,0.08);
}
.const-item__name {
  font-size: 13px;
  color: #a0a0c0;
}
.const-item__symbol {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--accent-teal);
  font-weight: 600;
}
.const-item__value {
  font-family: var(--font-mono);
  font-size: 12px;
  color: #8888a8;
}

/* Function list item */
.func-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(255,255,255,0.03);
  margin-bottom: 4px;
  cursor: pointer;
  transition: background 0.15s;
}
.func-item:active {
  background: rgba(255,255,255,0.08);
}
.func-item__name {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--accent-teal);
  font-weight: 600;
}
.func-item__desc {
  font-size: 12px;
  color: #8888a8;
}

/* Mode buttons */
.mode-group {
  margin-bottom: 16px;
}
.mode-group h3 {
  font-size: 13px;
  color: #8888a8;
  margin-bottom: 8px;
  font-weight: 600;
}
.mode-options {
  display: flex;
  gap: 6px;
}
.mode-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  background: rgba(255,255,255,0.03);
  color: #a0a0c0;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.mode-btn--active {
  background: rgba(78, 205, 196, 0.15);
  border-color: var(--accent-teal);
  color: var(--accent-teal);
}
.mode-btn:active {
  background: rgba(78, 205, 196, 0.1);
}

/* ═══ RESPONSIVE ═══ */

/* Small phones */
@media (max-height: 680px) {
  :root {
    --key-gap: 3px;
    --calc-padding: 6px;
  }
  .display {
    min-height: 90px;
    padding: 6px 10px;
  }
  .display__expression { font-size: 16px; }
  .display__result { font-size: 22px; min-height: 28px; }
  .key { min-height: 32px; }
  .key__label { font-size: 12px; }
  .key--num .key__label { font-size: 15px; }
  .key--op .key__label { font-size: 15px; }
  .key--equals .key__label { font-size: 18px; }
  .key__shift-label, .key__alpha-label { font-size: 7px; }
  .toolbar { margin-bottom: 3px; }
  .toolbar__btn { height: 26px; font-size: 10px; }
}

/* Medium phones */
@media (min-height: 681px) and (max-height: 800px) {
  .display {
    min-height: 105px;
  }
  .key { min-height: 36px; }
}

/* Tall phones (iPhone Pro Max, etc.) */
@media (min-height: 801px) {
  .display {
    min-height: 130px;
  }
  .key { min-height: 42px; }
  .key__label { font-size: 15px; }
  .key--num .key__label { font-size: 20px; }
  .key--op .key__label { font-size: 20px; }
}

/* Desktop */
@media (min-width: 500px) {
  .calculator {
    max-height: 900px;
    border-radius: 20px;
    box-shadow:
      0 40px 80px rgba(0,0,0,0.4),
      0 0 1px rgba(255,255,255,0.08),
      inset 0 1px 0 rgba(255,255,255,0.05);
    margin: 20px auto;
  }
}

/* ═══ ANIMATIONS ═══ */
@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.display__result {
  animation: slideUp 0.15s ease-out;
}

/* ═══ ACCESSIBILITY ═══ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ═══ LANDSCAPE PREVENTION ═══ */
@media (orientation: landscape) and (max-height: 500px) {
  .calculator {
    padding: 4px;
  }
  .display { min-height: 60px; padding: 4px 8px; }
  .display__expression { font-size: 14px; }
  .display__result { font-size: 18px; min-height: 22px; }
  .key { min-height: 28px; }
  .key__label { font-size: 11px; }
  .key--num .key__label { font-size: 14px; }
  .toolbar { display: none; }
  .key__shift-label, .key__alpha-label { display: none; }
}

/* ═══ PWA STANDALONE ADJUSTMENTS ═══ */
@media all and (display-mode: standalone) {
  body {
    background: var(--bg-calc);
  }
}

/* ═══ DARK MODE SCROLLBAR ═══ */
::-webkit-scrollbar {
  width: 0;
  height: 0;
}

/* ═══ MATHEMATICAL TYPESETTING ═══ */
.frac {
  display: inline-flex;
  flex-direction: column;
  vertical-align: middle;
  text-align: center;
  font-size: 0.82em;
  padding: 0 4px;
  line-height: 1.1;
  position: relative;
  top: -1px;
}

.num {
  border-bottom: 1.5px solid currentColor;
  padding-bottom: 2px;
  min-height: 15px;
}

.den {
  padding-top: 2px;
  min-height: 15px;
}

sup {
  font-size: 0.72em;
  vertical-align: super;
  position: relative;
  top: -0.2em;
  padding-left: 1px;
}

sub {
  font-size: 0.72em;
  vertical-align: sub;
  position: relative;
  bottom: -0.1em;
}
