/* ═══════════════════════════════════════════════════════
   style.css — MasterCalc
   Full viewport, no scroll on desktop.
   Glassmorphism neon dark theme + clean light theme.
   Fonts: Share Tech Mono (display) + Outfit (body)
═══════════════════════════════════════════════════════ */

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

/* ── Screen-reader only ── */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ═══════════════════════════════════════════════════════
   CSS VARIABLES — Dark (default)
═══════════════════════════════════════════════════════ */
:root {
  /* Backgrounds */
  --bg:          #0d0d1a;
  --bg2:         #12122a;
  --glass:       rgba(255,255,255,.045);
  --glass2:      rgba(255,255,255,.09);
  --display-bg:  rgba(0,0,0,.40);

  /* Borders */
  --border:      rgba(255,255,255,.08);
  --border2:     rgba(255,255,255,.16);

  /* Text */
  --text:        #f0eeff;
  --muted:       rgba(220,215,255,.48);

  /* Accent colours */
  --accent:      #7c6ffa;
  --accent2:     #f472b6;
  --green:       #34d399;
  --red:         #f87171;
  --yellow:      #fbbf24;
  --cyan:        #38bdf8;

  /* Button fills */
  --btn-num:     rgba(255,255,255,.07);
  --btn-num-h:   rgba(255,255,255,.15);
  --btn-op:      rgba(124,111,250,.18);
  --btn-op-h:    rgba(124,111,250,.36);
  --btn-fn:      rgba(255,255,255,.11);
  --btn-fn-h:    rgba(255,255,255,.22);
  --btn-sci:     rgba(56,189,248,.12);
  --btn-sci-h:   rgba(56,189,248,.28);
  --btn-eq:      linear-gradient(135deg,#7c6ffa,#f472b6);
  --btn-eq-h:    linear-gradient(135deg,#9b8ffc,#f79cd0);

  /* Shadows */
  --shadow-card: 0 24px 64px rgba(0,0,0,.55);
  --shadow-btn:  0 4px 16px rgba(0,0,0,.3);
  --glow-accent: 0 0 20px rgba(124,111,250,.4);

  /* Layout */
  --topbar-h:   56px;
  --sidebar-w:  290px;
  --radius-xl:  22px;
  --radius-lg:  16px;
  --radius-md:  11px;
  --radius-sm:  8px;
  --gap:        8px;

  /* Fonts */
  --mono: 'Share Tech Mono', monospace;
  --sans: 'Outfit', sans-serif;
}

/* ═══════════════════════════════════════════════════════
   CSS VARIABLES — Light
═══════════════════════════════════════════════════════ */
[data-theme="light"] {
  --bg:         #eeeeff;
  --bg2:        #e2e0ff;
  --glass:      rgba(255,255,255,.72);
  --glass2:     rgba(255,255,255,.92);
  --display-bg: rgba(230,228,255,.7);
  --border:     rgba(80,60,200,.1);
  --border2:    rgba(80,60,200,.22);
  --text:       #1a1040;
  --muted:      rgba(30,20,80,.5);
  --accent:     #5b4ef5;
  --btn-num:    rgba(255,255,255,.85);
  --btn-num-h:  rgba(255,255,255,1);
  --btn-op:     rgba(91,78,245,.13);
  --btn-op-h:   rgba(91,78,245,.28);
  --btn-fn:     rgba(80,60,200,.1);
  --btn-fn-h:   rgba(80,60,200,.22);
  --btn-sci:    rgba(14,165,233,.12);
  --btn-sci-h:  rgba(14,165,233,.27);
  --shadow-card:0 16px 48px rgba(80,60,200,.14);
  --shadow-btn: 0 2px 8px rgba(80,60,200,.12);
  --glow-accent:0 0 16px rgba(91,78,245,.3);
}

/* ═══════════════════════════════════════════════════════
   BASE
═══════════════════════════════════════════════════════ */
html { height: 100%; font-size: 16px; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  /* Full viewport — no page scroll on desktop */
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: background .35s, color .3s;
}

/* Subtle dot grid */
body::before {
  content: '';
  position: fixed; inset: 0;
  background-image:
    radial-gradient(circle, rgba(124,111,250,.06) 1px, transparent 1px);
  background-size: 32px 32px;
  pointer-events: none;
  z-index: 0;
}

/* ═══════════════════════════════════════════════════════
   TOPBAR
═══════════════════════════════════════════════════════ */
.topbar {
  position: relative; z-index: 200;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 18px;
  background: rgba(0,0,0,.28);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(22px);
  flex-shrink: 0;
}
[data-theme="light"] .topbar { background: rgba(220,215,255,.5); }

.topbar-logo {
  font-family: var(--mono);
  font-size: 1.05rem;
  color: var(--accent);
  letter-spacing: .08em;
  text-shadow: var(--glow-accent);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Tab nav */
.topbar-nav {
  display: flex;
  gap: 3px;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 4px;
  flex-shrink: 0;
}
.tab-btn {
  padding: 6px 18px;
  border-radius: 100px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: color .25s, background .25s;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 12px rgba(124,111,250,.4);
}
/* Focus visible */
.tab-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Right controls */
.topbar-controls { display: flex; gap: 7px; flex-shrink: 0; }
.ctrl-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--glass);
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .22s;
  color: var(--text);
}
.ctrl-btn:hover { background: var(--glass2); border-color: var(--border2); transform: scale(1.08); }
.ctrl-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ═══════════════════════════════════════════════════════
   SHELL + SIDEBAR
═══════════════════════════════════════════════════════ */
.shell {
  position: relative; z-index: 1;
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* ── History sidebar ── */
.history-panel {
  width: 0;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width .35s cubic-bezier(.22,1,.36,1);
}
.history-panel.open { width: var(--sidebar-w); }

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  white-space: nowrap;
  min-width: var(--sidebar-w);
}
.history-title { font-size: 14px; font-weight: 700; color: var(--text); }
.history-actions { display: flex; gap: 6px; }

.hbtn-clear {
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--red);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}
.hbtn-clear:hover { background: rgba(248,113,113,.12); border-color: var(--red); }
.hbtn-clear:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

.hbtn-close {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--glass);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .2s;
}
.hbtn-close:hover { color: var(--text); background: var(--glass2); }
.hbtn-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.history-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: var(--sidebar-w);
}
.history-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 28px 10px; }

.hist-item {
  padding: 10px 12px;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all .2s;
}
.hist-item:hover { background: var(--glass2); border-color: var(--border2); }
.hist-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hist-expr   { font-size: 11.5px; color: var(--muted); margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-result { font-family: var(--mono); font-size: 15px; font-weight: 700; color: var(--accent); }
.hist-time   { font-size: 10px; color: var(--muted); margin-top: 3px; }

/* Mobile overlay */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 299;
  backdrop-filter: blur(4px);
  transition: opacity .3s;
}
.overlay.hidden { display: none; }

/* ═══════════════════════════════════════════════════════
   CONTENT AREA + PANELS
═══════════════════════════════════════════════════════ */
.content {
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  min-height: 0;
}

.panel {
  display: none;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  animation: fadeSlide .28s ease both;
}
.panel.active { display: flex; flex-direction: column; }

@keyframes fadeSlide {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* ═══════════════════════════════════════════════════════
   CALCULATOR — MODE BAR
═══════════════════════════════════════════════════════ */
.mode-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 420px;
  margin-bottom: 10px;
}

.mode-switch {
  position: relative;
  display: inline-flex;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 4px;
}
.mode-btn {
  position: relative; z-index: 1;
  padding: 7px 22px;
  border-radius: 100px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: color .3s;
  white-space: nowrap;
}
.mode-btn.active { color: #fff; }
.mode-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* Ink slider inside mode switch */
.mode-ink {
  position: absolute;
  top: 4px; bottom: 4px; left: 4px;
  width: calc(50% - 4px);
  background: var(--accent);
  border-radius: 100px;
  transition: transform .35s cubic-bezier(.34,1.56,.64,1);
  box-shadow: 0 2px 12px rgba(124,111,250,.45);
  pointer-events: none;
}
.mode-ink.right { transform: translateX(100%); }

.swipe-tip {
  font-size: 11px;
  color: var(--muted);
  opacity: .6;
  white-space: nowrap;
}

/* ═══════════════════════════════════════════════════════
   CALCULATOR — STAGE (holds both cards, CSS-only toggle)
═══════════════════════════════════════════════════════ */
.calc-stage {
  width: 100%;
  max-width: 420px;
  position: relative;
}

/* Both cards always in DOM — toggled with visibility + display */
.calc-card {
  width: 100%;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 14px;
  backdrop-filter: blur(22px);
  box-shadow: var(--shadow-card);
  transition: opacity .3s, transform .3s;
}

/* Scientific card hidden by default */
.sci-card {
  display: none;
  max-width: 580px;
}
/* When sci mode active — set via JS toggling classes on stage */
.calc-stage.sci-mode .calc-card:not(.sci-card) { display: none; }
.calc-stage.sci-mode .sci-card                 { display: block; }
.calc-stage.sci-mode                            { max-width: 580px; }

/* Slide animations — added/removed by JS */
.slide-left  { animation: slideLeft  .3s ease both; }
.slide-right { animation: slideRight .3s ease both; }
@keyframes slideLeft  { from{opacity:0;transform:translateX( 50px)} to{opacity:1;transform:none} }
@keyframes slideRight { from{opacity:0;transform:translateX(-50px)} to{opacity:1;transform:none} }

/* ── Display ── */
.display {
  position: relative;
  background: var(--display-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 14px 10px;
  margin-bottom: 12px;
  min-height: 84px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
}
.disp-expr {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--muted);
  text-align: right;
  min-height: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.disp-result {
  font-family: var(--mono);
  font-size: clamp(22px, 5vw, 34px);
  font-weight: 400;
  color: var(--text);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.1;
  text-shadow: 0 0 18px rgba(124,111,250,.28);
  transition: font-size .15s;
}
.disp-copy {
  position: absolute;
  top: 9px; right: 10px;
  background: none; border: none;
  font-size: 13px; color: var(--muted);
  cursor: pointer; opacity: .55; padding: 3px 5px;
  border-radius: 5px; transition: all .2s;
}
.disp-copy:hover { opacity: 1; color: var(--accent); }
.disp-copy:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.disp-extras {
  position: absolute;
  top: 9px; right: 10px;
  display: flex; gap: 6px; align-items: center;
}
.degrad-btn {
  padding: 3px 9px;
  border-radius: 7px;
  border: 1px solid rgba(52,211,153,.4);
  background: rgba(52,211,153,.1);
  color: var(--green);
  font-family: var(--sans);
  font-size: 10.5px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: .06em;
  transition: all .2s;
}
.degrad-btn:hover { background: rgba(52,211,153,.22); }
.degrad-btn:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* ── Button grid base ── */
.btn-grid { display: grid; gap: var(--gap); }

/* Normal grid: 4 columns */
.ng {
  grid-template-columns: repeat(4, 1fr);
}
/* Scientific grid: 5 columns */
.sg {
  grid-template-columns: repeat(5, 1fr);
}

/* Span helpers */
.wide  { grid-column: span 2; }
.wide2 { grid-column: span 2; }
.full  { grid-column: span 5; }

/* ── Button base ── */
.btn {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 54px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .11s, background .18s, box-shadow .18s, border-color .18s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  color: var(--text);
  background: var(--btn-num);
}
.btn:hover  { transform: translateY(-1px); }
.btn:active { transform: scale(.93); }

/* Ripple on press */
.btn::after {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(circle, rgba(255,255,255,.22) 0%, transparent 70%);
  opacity: 0;
  transition: opacity .28s;
  pointer-events: none;
}
.btn:active::after { opacity: 1; transition: none; }

/* Focus visible for keyboard nav */
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  z-index: 1;
}

/* Num */
.btn.num  { background: var(--btn-num); }
.btn.num:hover { background: var(--btn-num-h); border-color: var(--border2); }

/* Operator */
.btn.op   { background: var(--btn-op); border-color: rgba(124,111,250,.2); color: #b0a5fd; font-size: 18px; }
.btn.op:hover { background: var(--btn-op-h); color: var(--text); box-shadow: 0 3px 14px rgba(124,111,250,.18); }

/* Function */
.btn.fn   { background: var(--btn-fn); border-color: var(--border2); color: var(--muted); }
.btn.fn:hover { background: var(--btn-fn-h); color: var(--text); }

/* Scientific */
.btn.sci  { background: var(--btn-sci); border-color: rgba(56,189,248,.18); color: #67d8f5; font-size: 12.5px; font-weight: 700; min-height: 44px; }
.btn.sci:hover { background: var(--btn-sci-h); color: #fff; box-shadow: 0 2px 10px rgba(56,189,248,.18); }

/* Equals */
.btn.eq   { background: var(--btn-eq); border: none; color: #fff; font-size: 20px; font-weight: 700; box-shadow: 0 4px 18px rgba(124,111,250,.35); }
.btn.eq:hover { background: var(--btn-eq-h); box-shadow: 0 6px 24px rgba(124,111,250,.52); transform: translateY(-2px); }

/* Delete/backspace */
.btn.del  { color: var(--red) !important; }
.btn.del:hover { border-color: rgba(248,113,113,.35); background: rgba(248,113,113,.12) !important; }

/* ═══════════════════════════════════════════════════════
   CONVERTER / CURRENCY CARDS
═══════════════════════════════════════════════════════ */
.conv-card {
  width: 100%;
  max-width: 560px;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 24px 24px 20px;
  backdrop-filter: blur(22px);
  box-shadow: var(--shadow-card);
}

.card-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 18px;
}

.conv-type-row { margin-bottom: 18px; }

/* Row with from/swap/to */
.conv-body {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}
.conv-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 110px;
}
.field-lbl {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .09em;
}

/* Select */
.sel {
  width: 100%;
  padding: 10px 32px 10px 12px;
  background: var(--glass2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath fill='%23888' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  transition: border-color .22s;
}
.sel:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,111,250,.14); }
.sel:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sel option { background: var(--bg2); color: var(--text); }

/* Inputs */
.field-inp {
  width: 100%;
  padding: 12px 14px;
  background: var(--glass2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 400;
  outline: none;
  transition: border-color .22s, box-shadow .22s;
}
.field-inp:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,111,250,.14); }
.field-inp::placeholder { color: var(--muted); font-family: var(--sans); font-size: 14px; font-weight: 400; }
.out-inp { color: var(--accent); cursor: default; }
.out-inp:focus { border-color: var(--border); box-shadow: none; }

/* Swap button */
.swap-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--glass);
  color: var(--accent);
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .28s;
  flex-shrink: 0;
  align-self: flex-end;
}
.swap-btn:hover { background: rgba(124,111,250,.18); border-color: var(--accent); transform: rotate(180deg); }
.swap-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* Formula + rate info */
.conv-formula, .rate-line {
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  font-style: italic;
  min-height: 18px;
}
.rate-line { font-size: 14px; font-weight: 600; color: var(--accent); font-style: normal; }
.rate-updated { text-align: center; font-size: 11px; color: var(--muted); margin-top: 4px; }

/* API status */
.api-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 500;
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--yellow);
  animation: dotPulse 1.1s ease infinite;
}
.status-dot.ok    { background: var(--green); animation: none; }
.status-dot.error { background: var(--red);   animation: none; }
@keyframes dotPulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.35;transform:scale(.65)} }

/* Retry button */
.retry-btn {
  display: block;
  margin: 14px auto 0;
  padding: 9px 24px;
  border-radius: 100px;
  border: 1.5px solid var(--accent);
  background: rgba(124,111,250,.12);
  color: var(--accent);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all .22s;
}
.retry-btn:hover { background: rgba(124,111,250,.24); }
.retry-btn.hidden { display: none; }

/* ═══════════════════════════════════════════════════════
   TOAST + OFFLINE BAR
═══════════════════════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: 22px; left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  padding: 10px 22px;
  border-radius: 100px;
  font-size: 13.5px;
  font-weight: 600;
  z-index: 9999;
  box-shadow: 0 6px 24px rgba(124,111,250,.4);
  animation: toastIn .3s cubic-bezier(.34,1.56,.64,1) both;
  white-space: nowrap;
  pointer-events: none;
}
.toast.hidden { display: none; }
@keyframes toastIn {
  from { opacity:0; transform:translateX(-50%) translateY(14px); }
  to   { opacity:1; transform:translateX(-50%) translateY(0); }
}

.offline-bar {
  position: fixed;
  top: var(--topbar-h); left: 0; right: 0;
  background: var(--yellow);
  color: #333;
  text-align: center;
  padding: 6px;
  font-size: 12.5px;
  font-weight: 600;
  z-index: 9000;
}
.offline-bar.hidden { display: none; }

/* ═══════════════════════════════════════════════════════
   SCROLLBAR
═══════════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(124,111,250,.22); border-radius: 10px; }

/* ═══════════════════════════════════════════════════════
   RESPONSIVE — TABLET (≤ 860px)
═══════════════════════════════════════════════════════ */
@media (max-width: 860px) {
  .tab-btn { padding: 5px 12px; font-size: 12px; }
  --sidebar-w: 260px;
  .btn { min-height: 48px; font-size: 14px; }
  .btn.sci { min-height: 40px; font-size: 11.5px; }
  .disp-result { font-size: clamp(20px, 4vw, 28px); }
}

/* ═══════════════════════════════════════════════════════
   RESPONSIVE — MOBILE (≤ 580px)
═══════════════════════════════════════════════════════ */
@media (max-width: 580px) {
  /* Allow scroll on mobile */
  body     { overflow: auto; height: auto; min-height: 100vh; }
  .shell   { overflow: visible; }
  .content { padding: 10px; align-items: flex-start; }
  .panel   { align-items: flex-start; }

  /* Topbar compact */
  .topbar       { padding: 0 10px; gap: 8px; }
  .topbar-logo  { font-size: .9rem; }
  .tab-btn      { padding: 5px 9px; font-size: 11px; }
  .ctrl-btn     { width: 32px; height: 32px; font-size: 14px; }

  /* Sidebar full-screen on mobile */
  .history-panel {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 300;
    width: 0 !important;
    transform: translateX(-100%);
    transition: transform .35s cubic-bezier(.22,1,.36,1), width 0s .36s;
  }
  .history-panel.open {
    width: 82vw !important;
    transform: translateX(0);
    transition: transform .35s cubic-bezier(.22,1,.36,1);
  }

  /* Calculator buttons */
  .btn       { min-height: 44px; font-size: 14px; border-radius: 8px; }
  .btn.sci   { min-height: 36px; font-size: 11px; }
  .btn-grid  { gap: 6px; }

  /* Display */
  .display       { min-height: 70px; }
  .disp-result   { font-size: 24px; }

  /* Mode bar */
  .mode-bar { max-width: 100%; }
  .calc-stage { max-width: 100% !important; }
  .sci-card   { max-width: 100% !important; }

  /* Converter */
  .conv-card  { padding: 16px 14px; }
  .conv-body  { gap: 10px; }
  .swap-btn   { width: 38px; height: 38px; font-size: 15px; }
  .field-inp  { font-size: 16px; padding: 10px 12px; }
}

/* ═══════════════════════════════════════════════════════
   RESPONSIVE — LARGE (≥ 1440px)
═══════════════════════════════════════════════════════ */
@media (min-width: 1440px) {
  .btn       { min-height: 60px; font-size: 17px; }
  .btn.sci   { min-height: 52px; font-size: 13.5px; }
  .disp-result { font-size: 40px; }
  .calc-card { max-width: 460px; }
}
