/* ═══════════════════════════════════════════════════════════
   CALCPRO — style.css
   Design: Glassmorphism · JetBrains Mono display · Indigo/Violet/Cyan
   Author: CalcPro (Senior Frontend Engineer)
═══════════════════════════════════════════════════════════ */

/* ─── Custom Selection Color ─── */
::selection {
  background: rgba(99, 102, 241, 0.35);
  color: #f8fafc;
}

/* ═══════════════════════════════════════════════════════════
   CSS CUSTOM PROPERTIES
═══════════════════════════════════════════════════════════ */
:root {
  /* Colors */
  --bg:          #0B1120;
  --bg-2:        #0f1729;
  --card:        #111827;
  --card-2:      #1a2235;
  --primary:     #6366F1;
  --primary-glow:rgba(99, 102, 241, 0.35);
  --secondary:   #8B5CF6;
  --accent:      #06B6D4;
  --accent-glow: rgba(6, 182, 212, 0.25);
  --danger:      #EF4444;
  --success:     #10B981;
  --text:        #F8FAFC;
  --text-muted:  #94A3B8;
  --text-dim:    #475569;
  --border:      rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.13);
  --glass-bg:    rgba(17, 24, 39, 0.7);
  --glass-bg-2:  rgba(17, 24, 39, 0.5);
  --inset:       rgba(0, 0, 0, 0.3);

  /* Buttons */
  --btn-num-bg:  rgba(30, 41, 59, 0.8);
  --btn-num-hover: rgba(51, 65, 85, 0.9);
  --btn-fn-bg:   rgba(42, 55, 78, 0.8);
  --btn-fn-hover: rgba(59, 76, 105, 0.9);
  --btn-op-bg:   rgba(99, 102, 241, 0.2);
  --btn-op-hover: rgba(99, 102, 241, 0.35);
  --btn-eq-bg:   linear-gradient(135deg, #6366F1, #8B5CF6);
  --btn-mem-bg:  rgba(6, 182, 212, 0.12);
  --btn-sci-bg:  rgba(139, 92, 246, 0.15);

  /* Shadows */
  --shadow-card: 0 25px 60px rgba(0,0,0,0.5), 0 0 0 1px var(--border);
  --shadow-btn:  0 2px 8px rgba(0,0,0,0.3);
  --shadow-eq:   0 4px 20px rgba(99,102,241,0.4);
  --shadow-display: inset 0 2px 16px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.05);

  /* Typography */
  --font-display: 'JetBrains Mono', 'Courier New', monospace;
  --font-ui:      'Inter', system-ui, sans-serif;

  /* Sizing */
  --calc-width:  380px;
  --btn-radius:  14px;
  --card-radius: 24px;
  --transition:  0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light Theme */
[data-theme="light"] {
  --bg:          #EEF2FF;
  --bg-2:        #E0E7FF;
  --card:        rgba(255, 255, 255, 0.85);
  --card-2:      rgba(238, 242, 255, 0.8);
  --text:        #0F172A;
  --text-muted:  #475569;
  --text-dim:    #94A3B8;
  --border:      rgba(99, 102, 241, 0.12);
  --border-strong: rgba(99, 102, 241, 0.25);
  --glass-bg:    rgba(255, 255, 255, 0.7);
  --glass-bg-2:  rgba(238, 242, 255, 0.6);
  --inset:       rgba(0, 0, 0, 0.06);

  --btn-num-bg:  rgba(224, 231, 255, 0.8);
  --btn-num-hover: rgba(199, 210, 254, 0.9);
  --btn-fn-bg:   rgba(209, 213, 219, 0.7);
  --btn-fn-hover: rgba(156, 163, 175, 0.5);
  --btn-op-bg:   rgba(99, 102, 241, 0.12);
  --btn-op-hover: rgba(99, 102, 241, 0.22);
  --btn-mem-bg:  rgba(6, 182, 212, 0.1);
  --btn-sci-bg:  rgba(139, 92, 246, 0.1);

  --shadow-card: 0 25px 60px rgba(99,102,241,0.15), 0 0 0 1px var(--border);
  --shadow-btn:  0 2px 8px rgba(0,0,0,0.08);
  --shadow-eq:   0 4px 20px rgba(99,102,241,0.35);
  --shadow-display: inset 0 2px 12px rgba(0,0,0,0.07), inset 0 1px 0 rgba(255,255,255,0.8);
}

/* ═══════════════════════════════════════════════════════════
   RESET & BASE
═══════════════════════════════════════════════════════════ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* Eliminate 300ms tap delay on all mobile browsers */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-x: hidden;
  transition: background var(--transition-slow), color var(--transition-slow);
}

button {
  cursor: pointer;
  border: none;
  outline: none;
  font-family: inherit;
  background: none;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ═══════════════════════════════════════════════════════════
   ANIMATED MESH BACKGROUND
═══════════════════════════════════════════════════════════ */
.bg-mesh {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.mesh-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(110px);
  opacity: 0.55;
  animation: orb-drift 14s ease-in-out infinite;
}

.mesh-orb-1 {
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(99,102,241,0.5), transparent 65%);
  top: -180px; left: -120px;
  animation-duration: 16s;
}

.mesh-orb-2 {
  width: 500px; height: 500px;
  background: radial-gradient(circle, rgba(139,92,246,0.4), transparent 65%);
  bottom: -150px; right: -100px;
  animation-delay: -6s;
  animation-duration: 20s;
}

.mesh-orb-3 {
  width: 400px; height: 400px;
  background: radial-gradient(circle, rgba(6,182,212,0.3), transparent 65%);
  top: 40%; left: 50%;
  transform: translate(-50%, -50%);
  animation-delay: -11s;
  animation-duration: 12s;
}

[data-theme="light"] .mesh-orb { opacity: 0.2; }

@keyframes orb-drift {
  0%, 100% { transform: translate(0, 0) scale(1); }
  30%       { transform: translate(30px, -40px) scale(1.08); }
  60%       { transform: translate(-25px, 30px) scale(0.94); }
}

/* ═══════════════════════════════════════════════════════════
   LOADING SCREEN
═══════════════════════════════════════════════════════════ */
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loading-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-ring {
  width: 52px;
  height: 52px;
  position: relative;
}

.loader-ring div {
  position: absolute;
  inset: 0;
  border: 3px solid transparent;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.loader-ring div:nth-child(2) {
  inset: 8px;
  border-top-color: var(--secondary);
  animation-duration: 1.3s;
  animation-direction: reverse;
}

.loader-ring div:nth-child(3) {
  inset: 16px;
  border-top-color: var(--accent);
  animation-duration: 1.7s;
}

.loader-ring div:nth-child(4) {
  inset: 22px;
  border-top-color: var(--primary);
  animation-duration: 2.1s;
  animation-direction: reverse;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loader-text {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.15em;
}

/* ═══════════════════════════════════════════════════════════
   TOAST NOTIFICATIONS
═══════════════════════════════════════════════════════════ */
.toast-container {
  position: fixed;
  bottom: 32px;
  right: 24px;
  z-index: 900;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  background: var(--card-2);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 12px 20px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 200px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  animation: toast-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  pointer-events: auto;
}

.toast.toast-out {
  animation: toast-out 0.3s ease forwards;
}

.toast-icon { font-size: 1rem; }

.toast.success .toast-icon { filter: hue-rotate(100deg) saturate(2); }
.toast.error   .toast-icon { filter: hue-rotate(350deg) saturate(2); }
.toast.info    .toast-icon { filter: none; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(60px) scale(0.9); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(60px); }
}

/* ═══════════════════════════════════════════════════════════
   APP LAYOUT
═══════════════════════════════════════════════════════════ */
.app {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  gap: 20px;
}

/* ═══════════════════════════════════════════════════════════
   APP HEADER
═══════════════════════════════════════════════════════════ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 760px;
  padding: 0 4px;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.05em;
}

.brand-icon {
  font-size: 1.2rem;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-controls {
  display: flex;
  gap: 8px;
}

.ctrl-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--glass-bg-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.ctrl-btn:hover {
  background: var(--glass-bg);
  border-color: var(--border-strong);
  color: var(--text);
  transform: translateY(-1px);
}

.ctrl-btn[aria-pressed="true"],
.ctrl-btn.active {
  background: rgba(99, 102, 241, 0.2);
  border-color: rgba(99, 102, 241, 0.4);
  color: var(--primary);
}

.ctrl-icon { pointer-events: none; }

/* ═══════════════════════════════════════════════════════════
   CALCULATOR LAYOUT (calculator + history side-by-side)
═══════════════════════════════════════════════════════════ */
.calc-layout {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
  max-width: 760px;
}

/* ═══════════════════════════════════════════════════════════
   HISTORY PANEL
═══════════════════════════════════════════════════════════ */
.history-panel {
  width: 260px;
  flex-shrink: 0;
  background: var(--glass-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border-strong);
  border-radius: var(--card-radius);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  animation: panel-slide 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-height: 540px;
  display: flex;
  flex-direction: column;
}

.history-panel[hidden] {
  display: none;
}

@keyframes panel-slide {
  from { opacity: 0; transform: translateX(-20px) scale(0.96); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.history-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.history-clear-btn {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-dim);
  padding: 4px 8px;
  border-radius: 6px;
  transition: all var(--transition);
}

.history-clear-btn:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-track { background: transparent; }
.history-list::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}

.history-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 40px 16px;
  color: var(--text-dim);
}

.history-empty-icon { font-size: 2rem; opacity: 0.5; }
.history-empty p { font-size: 0.82rem; }

.history-item {
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background var(--transition);
  border: 1px solid transparent;
  margin-bottom: 4px;
}

.history-item:hover {
  background: var(--btn-fn-bg);
  border-color: var(--border);
}

.history-expr {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: var(--font-display);
  margin-bottom: 4px;
  word-break: break-all;
}

.history-result {
  font-size: 1rem;
  font-weight: 600;
  font-family: var(--font-display);
  color: var(--text);
}

.history-time {
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-top: 3px;
}

/* ═══════════════════════════════════════════════════════════
   CALCULATOR CARD
═══════════════════════════════════════════════════════════ */
.calculator {
  width: var(--calc-width);
  flex-shrink: 0;
  background: var(--glass-bg);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border: 1px solid var(--border-strong);
  border-radius: var(--card-radius);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  padding: 20px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ─── DISPLAY SECTION ─── */
.display-section {
  background: var(--inset);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px 16px;
  box-shadow: var(--shadow-display);
  min-height: 120px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.display-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.memory-indicator {
  font-size: 0.68rem;
  font-weight: 700;
  font-family: var(--font-display);
  color: var(--accent);
  background: rgba(6, 182, 212, 0.15);
  border: 1px solid rgba(6, 182, 212, 0.3);
  border-radius: 4px;
  padding: 1px 5px;
  letter-spacing: 0.05em;
}

.memory-indicator[hidden] { display: none !important; }

.mode-indicator {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-left: auto;
  margin-right: 10px;
}

.copy-btn {
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  transition: all var(--transition);
}

.copy-btn:hover {
  color: var(--primary);
  background: rgba(99, 102, 241, 0.12);
}

.expression-display {
  font-family: var(--font-display);
  font-size: 0.78rem;
  color: var(--text-dim);
  text-align: right;
  min-height: 18px;
  word-break: break-all;
  padding-right: 2px;
  transition: color var(--transition);
}

.main-display {
  font-family: var(--font-display);
  font-size: 2.6rem;
  font-weight: 600;
  color: var(--text);
  text-align: right;
  letter-spacing: -0.03em;
  line-height: 1;
  padding: 8px 2px 0;
  word-break: break-all;
  transition: font-size var(--transition), color var(--transition);
  user-select: text;
  cursor: text;
}

/* Auto-shrink display font for long numbers */
.main-display.shrink-1 { font-size: 2rem; }
.main-display.shrink-2 { font-size: 1.5rem; }
.main-display.shrink-3 { font-size: 1.15rem; }

.main-display.error-state { color: var(--danger); }
.main-display.result-state {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ─── MEMORY ROW ─── */
.memory-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

/* ─── SCIENTIFIC ROW ─── */
.sci-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  animation: row-expand 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.sci-row[hidden] { display: none; }

@keyframes row-expand {
  from { opacity: 0; transform: scaleY(0.7); transform-origin: top; }
  to   { opacity: 1; transform: scaleY(1); }
}

/* ─── KEYPAD GRID ─── */
.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

/* ═══════════════════════════════════════════════════════════
   BUTTONS
═══════════════════════════════════════════════════════════ */
.btn {
  position: relative;
  height: 62px;
  border-radius: var(--btn-radius);
  font-family: var(--font-ui);
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background var(--transition),
    transform var(--transition),
    box-shadow var(--transition),
    color var(--transition);
  overflow: hidden;
  box-shadow: var(--shadow-btn);
  border: 1px solid var(--border);
  user-select: none;
  -webkit-user-select: none;
}

/* Ripple effect base */
.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at center, rgba(255,255,255,0.18), transparent 60%);
  opacity: 0;
  transition: opacity 0.5s ease;
  pointer-events: none;
}

.btn:active::after { opacity: 1; }

/* ─── Button Types ─── */
.btn-num {
  background: var(--btn-num-bg);
}
.btn-num:hover {
  background: var(--btn-num-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.btn-fn {
  background: var(--btn-fn-bg);
  font-size: 0.9rem;
  font-weight: 600;
}
.btn-fn:hover {
  background: var(--btn-fn-hover);
  transform: translateY(-2px);
}

.btn-op {
  background: var(--btn-op-bg);
  color: var(--primary);
  border-color: rgba(99, 102, 241, 0.25);
  font-size: 1.2rem;
  font-weight: 600;
}
.btn-op:hover {
  background: var(--btn-op-hover);
  color: #fff;
  transform: translateY(-2px);
  border-color: rgba(99, 102, 241, 0.45);
}

.btn-eq {
  background: var(--btn-eq-bg);
  color: #fff;
  font-size: 1.2rem;
  font-weight: 700;
  border: none;
  box-shadow: var(--shadow-eq);
}
.btn-eq:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(99,102,241,0.5);
  filter: brightness(1.1);
}

.btn-mem {
  height: 38px;
  background: var(--btn-mem-bg);
  border-color: rgba(6, 182, 212, 0.2);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.03em;
  border-radius: 10px;
}
.btn-mem:hover {
  background: rgba(6, 182, 212, 0.22);
  transform: translateY(-1px);
}

.btn-sci {
  height: 38px;
  background: var(--btn-sci-bg);
  border-color: rgba(139, 92, 246, 0.2);
  font-size: 0.72rem;
  font-weight: 700;
  font-family: var(--font-display);
  color: var(--secondary);
  border-radius: 10px;
}
.btn-sci:hover {
  background: rgba(139, 92, 246, 0.25);
  transform: translateY(-1px);
}

/* AC button danger highlight */
.btn[data-action="ac"] {
  color: var(--danger);
}
.btn[data-action="ac"]:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
}

/* Backspace button */
.btn[data-action="backspace"] { font-size: 1.15rem; }

/* Active/press state */
.btn:active {
  transform: translateY(0) scale(0.97) !important;
  filter: brightness(0.9);
}

/* Keyboard-highlighted button */
.btn.key-active {
  transform: translateY(0) scale(0.96) !important;
  filter: brightness(1.2);
  border-color: var(--primary);
}

/* Last row: ( ) 0 . ⌫ = spans correctly */
/* Row 5 has 6 items in 4-column grid — use span */
.btn[data-action="("],
.btn[data-action=")"] {
  /* no span needed, they just use 1 col each */
}

.btn[data-action="="] {
  /* no span */
}

/* ═══════════════════════════════════════════════════════════
   RIPPLE OVERLAY (JS-injected)
═══════════════════════════════════════════════════════════ */
.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  transform: scale(0);
  animation: ripple-expand 0.55s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  pointer-events: none;
}

@keyframes ripple-expand {
  to { transform: scale(4); opacity: 0; }
}

/* ═══════════════════════════════════════════════════════════
   APP FOOTER
═══════════════════════════════════════════════════════════ */
.app-footer {
  text-align: center;
  max-width: var(--calc-width);
}

.app-footer p {
  font-size: 0.68rem;
  color: var(--text-dim);
  line-height: 1.7;
}

.app-footer kbd {
  display: inline-block;
  background: var(--glass-bg-2);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: var(--font-display);
  font-size: 0.62rem;
  color: var(--text-muted);
  vertical-align: middle;
}

/* ═══════════════════════════════════════════════════════════
   SCROLLBAR
═══════════════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 6px;
}
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ═══════════════════════════════════════════════════════════
   REDUCED MOTION
═══════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ═══════════════════════════════════════════════════════════
   MOBILE TOUCH FIXES
   touch-action: manipulation  →  disables double-tap zoom
                                   so buttons fire instantly
                                   without the 300ms delay.
   -webkit-tap-highlight-color →  removes grey flash on iOS.
   user-select: none           →  stops long-press text select
                                   which was blocking taps.
═══════════════════════════════════════════════════════════ */

.btn {
  /* Already set above, but be explicit here too */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  /* Minimum Apple/Google recommended touch target */
  min-height: 44px;
  min-width:  44px;
}

/* Ensure the calculator card never overflows the viewport */
.calculator {
  max-width: 100vw;
  box-sizing: border-box;
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
═══════════════════════════════════════════════════════════ */

/* Tablet — history panel collapses under calculator */
@media (max-width: 720px) {
  .calc-layout {
    flex-direction: column-reverse;
    align-items: center;
  }

  .history-panel {
    width: var(--calc-width);
    max-height: 220px;
  }
}

/* Mobile — ≤ 480px */
@media (max-width: 480px) {
  :root {
    --calc-width:  100%;
    --btn-radius:  12px;
    --card-radius: 18px;
  }

  /* Safe-area insets for notched phones (iPhone X+) */
  .app {
    padding: 12px env(safe-area-inset-right, 10px) calc(20px + env(safe-area-inset-bottom, 0px)) env(safe-area-inset-left, 10px);
    gap: 10px;
    min-height: 100dvh; /* dynamic viewport height — avoids browser chrome overlap */
  }

  .calculator {
    padding: 12px 10px 12px;
    gap: 8px;
    border-radius: var(--card-radius);
  }

  /* Buttons — tall enough for easy tapping */
  .btn {
    height:    58px;
    font-size: 1rem;
    border-radius: var(--btn-radius);
  }

  .btn-mem,
  .btn-sci {
    height:    38px;
    font-size: 0.7rem;
  }

  /* Display */
  .main-display { font-size: 2rem; }

  /* Tighter grid gaps on small screens */
  .keypad      { gap: 6px; }
  .memory-row,
  .sci-row     { gap: 5px; }

  /* History panel full width */
  .history-panel { width: 100%; }

  /* Hide keyboard hint footer — not relevant on touch */
  .app-footer { display: none; }

  /* App header — compact */
  .app-header { padding: 0 2px; }
  .app-brand  { font-size: 0.9rem; }

  /* Display section — more compact */
  .display-section {
    padding: 10px 12px 12px;
    min-height: 100px;
  }
}

/* Very small screens — e.g. iPhone SE (375px), older Androids */
@media (max-width: 375px) {
  .btn          { height: 52px; font-size: 0.93rem; }
  .btn-mem,
  .btn-sci      { height: 34px; font-size: 0.65rem; }
  .main-display { font-size: 1.75rem; }
  .keypad       { gap: 5px; }
}

/* Landscape mobile — reduce heights so everything fits */
@media (max-height: 600px) and (orientation: landscape) {
  .btn               { height: 46px; font-size: 0.88rem; }
  .btn-mem, .btn-sci { height: 32px; }
  .display-section   { min-height: 80px; padding: 8px 12px 8px; }
  .main-display      { font-size: 1.6rem; padding: 4px 2px 0; }
  .app               { gap: 6px; padding-top: 8px; }
  .calculator        { gap: 6px; padding: 10px 10px 8px; }
}