*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100dvh;
  overflow-x: hidden;
  transition: background 0.5s ease, color 0.5s ease;
}

body[dir="rtl"] {
  font-family: 'Vazirmatn', 'Inter', system-ui, sans-serif;
}

/* ── Ambient background ── */
.ambient-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.7;
  animation: orb-float 18s ease-in-out infinite;
}

.orb-1 {
  width: 55vw;
  height: 55vw;
  max-width: 420px;
  max-height: 420px;
  background: var(--accent-soft);
  top: -10%;
  left: -15%;
  animation-delay: 0s;
}

.orb-2 {
  width: 45vw;
  height: 45vw;
  max-width: 360px;
  max-height: 360px;
  background: var(--bg-gradient-1);
  bottom: 10%;
  right: -10%;
  animation-delay: -6s;
}

.orb-3 {
  width: 30vw;
  height: 30vw;
  max-width: 240px;
  max-height: 240px;
  background: var(--bg-gradient-2);
  top: 40%;
  left: 50%;
  transform: translateX(-50%);
  animation-delay: -12s;
}

@keyframes orb-float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(3%, 4%) scale(1.05); }
  66% { transform: translate(-2%, 2%) scale(0.95); }
}

.orb-3 {
  animation-name: orb-float-center;
}

@keyframes orb-float-center {
  0%, 100% { transform: translate(-50%, 0) scale(1); }
  50% { transform: translate(-48%, -3%) scale(1.08); }
}

/* ── App shell ── */
.app-shell {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  gap: 18px;
  animation: shell-in 0.7s cubic-bezier(0.23, 1, 0.32, 1) both;
}

@keyframes shell-in {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.app-header {
  width: 100%;
  max-width: 420px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-title {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--accent) 0%, var(--text-primary) 120%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 24px var(--accent-glow));
}

.header-actions {
  display: flex;
  gap: 10px;
}

/* ── Mode tabs with sliding indicator ── */
.mode-tabs {
  position: relative;
  width: 100%;
  max-width: 420px;
  display: flex;
  padding: 5px;
  gap: 0;
  border-radius: 22px;
  isolation: isolate;
}

.mode-indicator {
  position: absolute;
  top: 5px;
  left: 5px;
  width: calc((100% - 10px) / 3);
  height: calc(100% - 10px);
  border-radius: 16px;
  background: var(--accent);
  box-shadow: 0 4px 20px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  transition: transform 0.45s cubic-bezier(0.23, 1, 0.32, 1);
  z-index: 0;
}

.mode-tabs[data-active="1"] .mode-indicator { transform: translateX(100%); }
.mode-tabs[data-active="2"] .mode-indicator { transform: translateX(200%); }

body[dir="rtl"] .mode-tabs[data-active="1"] .mode-indicator { transform: translateX(-100%); }
body[dir="rtl"] .mode-tabs[data-active="2"] .mode-indicator { transform: translateX(-200%); }

.mode-tab {
  position: relative;
  z-index: 1;
  flex: 1;
  padding: 11px 8px;
  border: none;
  border-radius: 16px;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.35s ease, transform 0.2s ease;
}

.mode-tab.active {
  color: var(--accent-text);
}

.mode-tab:not(.active):hover {
  color: var(--text-primary);
}

.mode-tab:active {
  transform: scale(0.96);
}

/* ── Cards ── */
.card {
  border-radius: 28px;
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--card-border);
  box-shadow:
    0 8px 32px var(--card-shadow-dark),
    0 1px 0 var(--card-shadow-light) inset,
    15px 15px 40px var(--card-shadow-dark),
    -8px -8px 24px var(--card-shadow-light);
  transition: background 0.5s ease, box-shadow 0.5s ease, border-color 0.5s ease;
}

.calculator-card {
  width: 100%;
  max-width: 420px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  overflow: hidden;
}

/* ── View transitions ── */
#calc-view,
#graph-view {
  animation: view-in 0.4s cubic-bezier(0.23, 1, 0.32, 1) both;
}

@keyframes view-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.hidden {
  display: none !important;
}

/* ── Display ── */
.display {
  position: relative;
  background: var(--display-bg);
  border-radius: 18px;
  padding: 18px 20px;
  min-height: 108px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
  overflow: hidden;
  border: 1px solid var(--panel-border);
  box-shadow:
    inset 0 2px 12px rgba(0, 0, 0, 0.15),
    0 0 40px var(--display-glow);
  transition: background 0.5s ease, box-shadow 0.5s ease;
}

.display-shine {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.12), transparent);
  pointer-events: none;
}

body[dir="rtl"] .display {
  align-items: flex-start;
}

.display-expression {
  font-size: 0.82rem;
  color: var(--text-secondary);
  min-height: 1.3em;
  word-break: break-all;
  text-align: right;
  width: 100%;
  direction: ltr;
  font-variant-numeric: tabular-nums;
  opacity: 0;
  animation: fade-slide-in 0.35s ease 0.05s both;
}

.display-value {
  font-size: clamp(2.2rem, 8vw, 3.2rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  word-break: break-all;
  text-align: right;
  width: 100%;
  direction: ltr;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.display-value.bump {
  animation: display-bump 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.display-value.flash {
  animation: result-flash 0.5s ease;
}

@keyframes display-bump {
  0% { transform: scale(1); opacity: 1; }
  40% { transform: scale(1.04); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes result-flash {
  0% { color: var(--text-primary); text-shadow: none; }
  30% { color: var(--accent); text-shadow: 0 0 20px var(--accent-glow); }
  100% { color: var(--text-primary); text-shadow: none; }
}

@keyframes fade-slide-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.display-value.error {
  color: #ff6b7a;
  font-size: clamp(1.1rem, 5vw, 1.6rem);
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* ── Keypad ── */
#calc-view {
  display: flex;
  flex-direction: column;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin-top: 18px;
  column-gap: 15px;
  row-gap: 12px;
}

.keypad .calc-btn {
  opacity: 0;
  animation: btn-pop-in 0.4s cubic-bezier(0.34, 1.4, 0.64, 1) both;
  animation-delay: calc(var(--i, 0) * 0.025s);
}

@keyframes btn-pop-in {
  from { opacity: 0; transform: scale(0.7) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Calc buttons ── */
.calc-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  border: 1px solid transparent;
  border-radius: 18px;
  background: var(--btn-bg);
  box-shadow:
    5px 5px 10px var(--btn-shadow-dark),
    -4px -4px 10px var(--btn-shadow-light),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  font-size: clamp(1.1rem, 4vw, 1.4rem);
  font-weight: 600;
  font-family: inherit;
  color: var(--btn-text);
  cursor: pointer;
  overflow: hidden;
  transition:
    transform 0.35s cubic-bezier(0.23, 1, 0.32, 1),
    box-shadow 0.35s ease,
    border-radius 0.35s cubic-bezier(0.23, 1, 0.32, 1),
    border-color 0.3s ease;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.calc-btn .btn-label {
  position: relative;
  z-index: 3;
  transition: transform 0.5s cubic-bezier(0.23, 1, 0.32, 1), color 0.3s ease;
}

.calc-btn .btn-circle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  width: 120%;
  height: 120%;
  background: var(--accent);
  border-radius: 50%;
  opacity: 0;
  transition: transform 0.55s cubic-bezier(0.23, 1, 0.32, 1), opacity 0.4s ease;
  z-index: 1;
}

.calc-btn .btn-ripple {
  position: absolute;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.35;
  transform: scale(0);
  animation: ripple-out 0.55s ease-out forwards;
  z-index: 2;
  pointer-events: none;
}

@keyframes ripple-out {
  to { transform: scale(2.5); opacity: 0; }
}

.calc-btn:hover .btn-circle,
.calc-btn:focus-visible .btn-circle,
.calc-btn.pressed .btn-circle {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}

.calc-btn:hover .btn-label,
.calc-btn:focus-visible .btn-label,
.calc-btn.pressed .btn-label {
  color: var(--accent-text);
  transform: scale(1.06);
}

.calc-btn:active,
.calc-btn.pressed {
  transform: scale(0.92);
  border-radius: 14px;
  box-shadow:
    2px 2px 6px var(--btn-shadow-dark),
    -2px -2px 6px var(--btn-shadow-light),
    inset 0 2px 8px rgba(0, 0, 0, 0.12);
}

.calc-btn.operator {
  color: var(--accent);
  border-color: var(--accent-dim);
  text-shadow: 0 0 20px var(--accent-glow);
}

.calc-btn.function {
  font-size: clamp(0.85rem, 3.5vw, 1.05rem);
  color: var(--text-secondary);
}

.calc-btn.wide {
  grid-column: span 2;
  aspect-ratio: auto;
  min-height: 54px;
}

.calc-btn.sm {
  font-size: clamp(0.62rem, 2.4vw, 0.8rem);
  border-radius: 12px;
  aspect-ratio: auto;
  min-height: 42px;
}

#keypad[style*="repeat(5"] {
  margin-top: 18px;
  column-gap: 11px;
  row-gap: 10px;
}

/* ── Magic equals button ── */
.calc-btn.magic {
  background: var(--magic-bg);
  color: var(--accent-text);
  border: 2px solid var(--magic-border);
  box-shadow:
    0 0 20px var(--accent-glow),
    0 4px 16px rgba(0, 0, 0, 0.2);
  font-size: clamp(1.4rem, 5vw, 1.8rem);
  font-weight: 700;
  animation: magic-pulse 3s ease-in-out infinite;
}

@keyframes magic-pulse {
  0%, 100% { box-shadow: 0 0 16px var(--accent-glow), 0 4px 16px rgba(0, 0, 0, 0.2); }
  50% { box-shadow: 0 0 28px var(--accent-glow), 0 4px 20px rgba(0, 0, 0, 0.25); }
}

.calc-btn.magic .spark {
  position: absolute;
  width: 8px;
  height: auto;
  filter: drop-shadow(0 0 0 var(--accent));
  z-index: 0;
  transition: all 0.75s cubic-bezier(0.05, 0.83, 0.43, 0.96);
  pointer-events: none;
}

.calc-btn.magic .spark svg {
  width: 100%;
  height: auto;
  fill: var(--accent);
}

.calc-btn.magic .spark-1 { top: 20%; left: 20%; width: 14px; }
.calc-btn.magic .spark-2 { top: 45%; left: 45%; width: 8px; transition-duration: 0.9s; }
.calc-btn.magic .spark-3 { top: 40%; left: 40%; width: 5px; }
.calc-btn.magic .spark-4 { top: 20%; left: 40%; width: 7px; }
.calc-btn.magic .spark-5 { top: 25%; left: 45%; width: 10px; transition-duration: 0.65s; }
.calc-btn.magic .spark-6 { top: 5%; left: 50%; width: 5px; }

.calc-btn.magic:hover,
.calc-btn.magic:focus-visible,
.calc-btn.magic.pressed {
  background: transparent;
  color: var(--accent);
  box-shadow: 0 0 32px var(--accent-glow);
  animation: none;
}

.calc-btn.magic:hover .spark-1,
.calc-btn.magic.pressed .spark-1 { top: -60%; left: -20%; filter: drop-shadow(0 0 10px var(--accent)); z-index: 4; }
.calc-btn.magic:hover .spark-2,
.calc-btn.magic.pressed .spark-2 { top: -20%; left: 5%; filter: drop-shadow(0 0 10px var(--accent)); z-index: 4; }
.calc-btn.magic:hover .spark-3,
.calc-btn.magic.pressed .spark-3 { top: 55%; left: 20%; filter: drop-shadow(0 0 10px var(--accent)); z-index: 4; }
.calc-btn.magic:hover .spark-4,
.calc-btn.magic.pressed .spark-4 { top: 30%; left: 80%; filter: drop-shadow(0 0 10px var(--accent)); z-index: 4; }
.calc-btn.magic:hover .spark-5,
.calc-btn.magic.pressed .spark-5 { top: 25%; left: 105%; filter: drop-shadow(0 0 10px var(--accent)); z-index: 4; }
.calc-btn.magic:hover .spark-6,
.calc-btn.magic.pressed .spark-6 { top: 5%; left: 55%; filter: drop-shadow(0 0 10px var(--accent)); z-index: 4; }

.calc-btn.magic:hover .btn-circle,
.calc-btn.magic.pressed .btn-circle { opacity: 0; transform: translate(-50%, -50%) scale(0); }
.calc-btn.magic .btn-label { z-index: 5; }

/* ── Icon buttons ── */
.icon-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--panel-border);
  border-radius: 50%;
  background: var(--glass);
  backdrop-filter: blur(12px);
  box-shadow:
    4px 4px 12px var(--card-shadow-dark),
    -3px -3px 10px var(--card-shadow-light);
  color: var(--accent);
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.4s cubic-bezier(0.23, 1, 0.32, 1), box-shadow 0.4s ease;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  position: relative;
  z-index: 2;
  transition: transform 0.5s cubic-bezier(0.23, 1, 0.32, 1), stroke 0.3s ease;
}

.animated-icon-btn .circle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  width: 130%;
  height: 130%;
  background: var(--accent);
  border-radius: 50%;
  opacity: 0;
  transition: transform 0.55s cubic-bezier(0.23, 1, 0.32, 1), opacity 0.4s ease;
  z-index: 1;
}

.animated-icon-btn:hover .circle,
.animated-icon-btn:focus-visible .circle {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}

.animated-icon-btn:hover svg,
.animated-icon-btn:focus-visible svg {
  stroke: var(--accent-text);
  transform: rotate(15deg);
}

#btn-theme:hover svg { transform: rotate(180deg); }

.animated-icon-btn:active { transform: scale(0.88); }

#btn-theme .icon-moon { display: none; }
[data-mode="light"] #btn-theme .icon-sun { display: none; }
[data-mode="light"] #btn-theme .icon-moon { display: block; }

.close-btn svg { stroke: var(--text-primary); }
.close-btn:hover svg { transform: rotate(90deg); }

/* ── Settings panel ── */
.settings-panel {
  border: none;
  padding: 0;
  max-width: 400px;
  width: calc(100% - 32px);
  color: var(--text-primary);
  background: var(--glass);
  backdrop-filter: blur(24px);
}

.settings-panel::backdrop {
  background: var(--overlay);
  backdrop-filter: blur(8px);
  animation: backdrop-in 0.35s ease;
}

@keyframes backdrop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.settings-panel[open] {
  animation: panel-in 0.45s cubic-bezier(0.34, 1.3, 0.64, 1);
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(28px) scale(0.92); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 24px 0;
}

.settings-header h2 {
  font-size: 1.2rem;
  font-weight: 600;
}

.settings-body {
  padding: 20px 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.setting-group label:first-child {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.segmented-control {
  display: flex;
  background: var(--display-bg);
  border-radius: 14px;
  padding: 4px;
  gap: 4px;
  border: 1px solid var(--panel-border);
}

.segment {
  flex: 1;
  padding: 10px 16px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
}

.segment.active {
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.theme-swatches {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  border: 2px solid transparent;
  border-radius: 14px;
  background: var(--display-bg);
  cursor: pointer;
  transition: all 0.35s cubic-bezier(0.23, 1, 0.32, 1);
  font-family: inherit;
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.swatch:hover { transform: translateY(-2px); }

.swatch-dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.swatch.active {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 20px var(--accent-dim);
}

.swatch.active .swatch-dot {
  transform: scale(1.1);
  box-shadow: 0 0 16px var(--accent-glow);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 16px;
  background: var(--display-bg);
  border-radius: 14px;
  cursor: pointer;
  font-size: 0.88rem;
  border: 1px solid var(--panel-border);
  transition: border-color 0.3s ease;
}

.toggle-row > span:first-of-type {
  flex: 1;
  min-width: 0;
  text-align: start;
  line-height: 1.4;
}

.toggle-row:hover { border-color: var(--accent-dim); }
.toggle-row + .toggle-row { margin-top: 8px; }

.toggle-row input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.toggle-slider {
  --knob-size: 20px;
  --knob-pad: 3px;
  --toggle-travel: calc(46px - var(--knob-size) - var(--knob-pad) * 2);
  position: relative;
  width: 46px;
  height: 26px;
  background: var(--btn-shadow-dark);
  border-radius: 13px;
  transition: background 0.35s ease, box-shadow 0.35s ease;
  flex-shrink: 0;
  margin-inline-start: auto;
}

.toggle-slider::after {
  content: '';
  position: absolute;
  top: var(--knob-pad);
  inset-inline-start: var(--knob-pad);
  width: var(--knob-size);
  height: var(--knob-size);
  background: var(--text-primary);
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: transform 0.4s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.toggle-row input:checked + .toggle-slider {
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.toggle-row input:checked + .toggle-slider::after {
  transform: translateX(var(--toggle-travel));
}

[dir="rtl"] .toggle-row input:checked + .toggle-slider::after {
  transform: translateX(calc(-1 * var(--toggle-travel)));
}

/* ── Install button ── */
.install-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px 20px;
  border: 2px solid var(--accent);
  border-radius: 16px;
  background: var(--display-bg);
  color: var(--accent);
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  overflow: hidden;
  transition: all 0.5s cubic-bezier(0.23, 1, 0.32, 1);
  box-shadow: 0 0 20px var(--accent-dim);
}

.install-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  position: relative;
  z-index: 2;
}

.install-btn .circle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  width: 120%;
  height: 200%;
  background: var(--accent);
  border-radius: 50%;
  opacity: 0;
  transition: transform 0.55s cubic-bezier(0.23, 1, 0.32, 1), opacity 0.4s ease;
  z-index: 1;
}

.install-btn span:not(.circle) {
  position: relative;
  z-index: 2;
}

.install-btn:hover .circle,
.install-btn:focus-visible .circle {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}

.install-btn:hover,
.install-btn:focus-visible {
  color: var(--accent-text);
  box-shadow: 0 0 28px var(--accent-glow);
}

.install-btn:active {
  transform: scale(0.97);
}

.install-hint,
.install-done {
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.78rem;
  line-height: 1.5;
  text-align: start;
}

.install-hint {
  background: var(--accent-dim);
  color: var(--text-secondary);
  border: 1px solid var(--panel-border);
}

.install-done {
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--accent);
  text-align: center;
  font-weight: 500;
}

#install-section.is-installed .install-btn {
  display: none;
}

/* ── Graph view ── */
.graph-view {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  min-width: 0;
}

.graph-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  text-shadow: 0 0 20px var(--accent-glow);
}

.graph-fn-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 0;
}

.graph-fn-row label {
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
  color: var(--accent);
}

.graph-input {
  flex: 1;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 12px 16px;
  border: 2px solid var(--panel-border);
  border-radius: 14px;
  background: var(--display-bg);
  color: var(--text-primary);
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.graph-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim), 0 0 20px var(--accent-glow);
}

.graph-canvas-wrap {
  position: relative;
  width: 100%;
  border-radius: 18px;
  overflow: hidden;
  background: var(--display-bg);
  border: 1px solid var(--panel-border);
  box-shadow:
    inset 0 2px 16px rgba(0, 0, 0, 0.12),
    0 0 30px var(--display-glow);
  transition: box-shadow 0.4s ease;
}

.graph-canvas-wrap.plotting {
  box-shadow:
    inset 0 2px 16px rgba(0, 0, 0, 0.12),
    0 0 40px var(--accent-glow);
}

#graph-canvas {
  display: block;
  width: 100%;
}

.graph-range {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  width: 100%;
  min-width: 0;
}

.graph-range label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.graph-range label > span {
  text-align: start;
}

.graph-range input {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 2px solid var(--panel-border);
  border-radius: 12px;
  background: var(--display-bg);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.graph-range input:focus {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent-dim);
}

.graph-auto-y { margin: 0; }

.plot-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 15px 32px;
  border: 2px solid var(--accent);
  border-radius: 100px;
  background: transparent;
  color: var(--accent);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 0 24px var(--accent-dim);
  transition: all 0.55s cubic-bezier(0.23, 1, 0.32, 1);
}

.plot-btn .text {
  position: relative;
  z-index: 2;
  transition: color 0.4s ease, transform 0.4s ease;
}

.plot-btn .circle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  width: 120%;
  height: 300%;
  background: var(--accent);
  border-radius: 50%;
  opacity: 0;
  transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1), opacity 0.4s ease;
}

.plot-btn:hover .circle,
.plot-btn:focus-visible .circle,
.plot-btn.plotting .circle {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}

.plot-btn:hover .text,
.plot-btn:focus-visible .text,
.plot-btn.plotting .text {
  color: var(--accent-text);
  transform: scale(1.04);
}

.plot-btn:active { transform: scale(0.96); }

.graph-presets {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.presets-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.preset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.preset-chip {
  padding: 7px 14px;
  border: 1px solid var(--panel-border);
  border-radius: 100px;
  background: var(--display-bg);
  color: var(--text-secondary);
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.72rem;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.23, 1, 0.32, 1);
  direction: ltr;
}

.preset-chip:hover,
.preset-chip:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--accent-dim);
}

.preset-chip.active {
  border-color: var(--accent);
  color: var(--accent-text);
  background: var(--accent);
  box-shadow: 0 4px 16px var(--accent-glow);
}

/* ── Footer ── */
.app-footer {
  position: relative;
  width: 100%;
  max-width: 420px;
  margin-top: 8px;
  padding: 20px 20px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
  overflow: hidden;
}

.footer-accent {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 60%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  box-shadow: 0 0 16px var(--accent-glow);
}

.footer-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
}

.footer-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.footer-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.footer-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  padding: 6px 14px;
  border-radius: 100px;
  border: 1px solid var(--panel-border);
  background: var(--display-bg);
  transition:
    color 0.35s ease,
    border-color 0.35s ease,
    box-shadow 0.35s ease,
    transform 0.35s cubic-bezier(0.23, 1, 0.32, 1);
}

.footer-name span {
  background: linear-gradient(135deg, var(--text-primary) 30%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  transition: -webkit-text-fill-color 0.35s ease;
}

.footer-arrow {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.6;
  transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.23, 1, 0.32, 1);
}

body[dir="rtl"] .footer-arrow {
  transform: scaleX(-1);
}

.footer-name:hover,
.footer-name:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 20px var(--accent-dim);
  transform: translateY(-2px);
}

.footer-name:hover span,
.footer-name:focus-visible span {
  -webkit-text-fill-color: transparent;
}

.footer-name:hover .footer-arrow,
.footer-name:focus-visible .footer-arrow {
  opacity: 1;
  transform: translate(2px, -2px);
}

body[dir="rtl"] .footer-name:hover .footer-arrow,
body[dir="rtl"] .footer-name:focus-visible .footer-arrow {
  transform: scaleX(-1) translate(2px, -2px);
}

.footer-brand span {
  background: linear-gradient(135deg, var(--accent) 0%, var(--text-primary) 150%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.footer-sep {
  width: 32px;
  height: 4px;
  border-radius: 2px;
  background: var(--accent-dim);
  position: relative;
}

.footer-sep::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}

.footer-tagline {
  font-size: 0.72rem;
  font-style: italic;
  color: var(--text-secondary);
  line-height: 1.5;
  max-width: 28ch;
  opacity: 0.85;
}

@media (min-width: 480px) {
  .footer-inner {
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    gap: 20px;
  }

  .footer-sep {
    width: 4px;
    height: 48px;
    margin-top: 8px;
    align-self: center;
  }

  .footer-sep::after {
    width: 5px;
    height: 5px;
  }
}

/* ── Responsive ── */
@media (min-width: 768px) {
  .app-shell {
    justify-content: center;
    padding-top: 36px;
    gap: 20px;
  }

  .calculator-card { max-width: 400px; }
  .keypad { margin-top: 20px; column-gap: 16px; row-gap: 13px; }
  #keypad[style*="repeat(5"] { column-gap: 12px; row-gap: 11px; }
}

@media (max-width: 360px) {
  .calculator-card { padding: 16px; border-radius: 22px; }
  .keypad { margin-top: 14px; column-gap: 11px; row-gap: 9px; }
  #keypad[style*="repeat(5"] { column-gap: 8px; row-gap: 8px; }
  .calc-btn { border-radius: 14px; }
}

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

  .orb { animation: none; }
  .calc-btn.magic { animation: none; }
}