:root{
  --bg:#0f172a;
  --card:rgba(15,23,42,.72);
  --card-solid:#111827;
  --text:#f8fafc;
  --muted:#94a3b8;
  --line:rgba(255,255,255,.1);
  --key:#1e293b;
  --key-hover:#27364a;
  --accent:#38bdf8;
  --accent-2:#a78bfa;
  --danger:#fb7185;
  --success:#22c55e;
  --shadow:0 24px 70px rgba(0,0,0,.35);
}

body.light{
  --bg:#eef4ff;
  --card:rgba(255,255,255,.78);
  --card-solid:#ffffff;
  --text:#0f172a;
  --muted:#64748b;
  --line:rgba(15,23,42,.1);
  --key:#f1f5f9;
  --key-hover:#e2e8f0;
  --shadow:0 24px 70px rgba(15,23,42,.12);
}

*{box-sizing:border-box}
html{scroll-behavior:smooth}
body{
  margin:0;
  min-height:100vh;
  font-family:Inter,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
  color:var(--text);
  background:
    radial-gradient(circle at top left, rgba(56,189,248,.32), transparent 34%),
    radial-gradient(circle at top right, rgba(167,139,250,.3), transparent 30%),
    var(--bg);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior:none;
}

button,input,select{
  font:inherit;
  -webkit-tap-highlight-color: transparent;
}

button{
  user-select:none;
  border:none;
  outline:none;
}

button:focus,
button:focus-visible,
button:active{
  outline:none;
  box-shadow:none;
}

.app-shell{
  width:min(1100px,100%);
  margin:0 auto;
  padding:18px;
  display:grid;
  gap:16px;
}

.hero-card,.calculator-card,.history-card{
  background:var(--card);
  backdrop-filter: blur(20px);
  border:1px solid var(--line);
  border-radius:28px;
  box-shadow:var(--shadow);
}

.hero-card{
  padding:22px;
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:14px;
}

.eyebrow{
  margin:0 0 6px;
  color:var(--accent);
  font-size:12px;
  font-weight:800;
  letter-spacing:.12em;
  text-transform:uppercase;
}

h1{
  margin:0;
  font-size:clamp(28px,5vw,46px);
  line-height:1;
}

.subtitle{
  margin:8px 0 0;
  color:var(--muted);
  font-size:14px;
}

.icon-btn,.copy-btn,.ghost-btn,.pill{
  color:var(--text);
  background:rgba(255,255,255,.08);
  border:1px solid var(--line);
  border-radius:999px;
  min-height:42px;
  padding:0 14px;
  cursor:pointer;
  transition:transform .18s ease, background .18s ease, opacity .18s ease;
}

.icon-btn{min-width:46px;font-size:20px}
.copy-btn{font-size:13px;font-weight:800}
.ghost-btn{font-weight:700;color:var(--muted)}

.icon-btn:active,.copy-btn:active,.ghost-btn:active,.pill:active,.key:active,.primary-action:active{
  transform:scale(.96);
}

.calculator-card{overflow:hidden}

.screen{
  margin:14px;
  padding:18px;
  border-radius:24px;
  background:linear-gradient(135deg,rgba(56,189,248,.16),rgba(167,139,250,.14));
  border:1px solid var(--line);
}

.screen-top{
  display:flex;
  justify-content:space-between;
  align-items:center;
  color:var(--muted);
  font-size:13px;
  font-weight:700;
}

.expression{
  min-height:26px;
  margin-top:18px;
  color:var(--muted);
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  text-align:right;
}

.result{
  min-height:62px;
  margin-top:4px;
  text-align:right;
  font-size:clamp(38px,10vw,66px);
  font-weight:800;
  line-height:1;
  word-break:break-all;
}

.tool-tabs{
  display:flex;
  gap:8px;
  padding:0 14px 14px;
  overflow:auto;
  scrollbar-width:none;
}

.tool-tabs::-webkit-scrollbar{display:none}

.tab{
  flex:0 0 auto;
  min-height:42px;
  padding:0 15px;
  border-radius:999px;
  background:var(--key);
  color:var(--muted);
  font-weight:800;
  cursor:pointer;
  transition:background .18s ease, color .18s ease, transform .18s ease;
}

.tab.active{
  color:#00111c;
  background:linear-gradient(135deg,var(--accent),var(--accent-2));
}

.tab:active{transform:scale(.96)}

.panel{
  display:none;
  padding:0 14px 14px;
  animation:fade .22s ease;
}

.panel.active{display:block}

@keyframes fade{
  from{opacity:0;transform:translateY(6px)}
  to{opacity:1;transform:translateY(0)}
}

.keypad,.scientific-grid{
  display:grid;
  grid-template-columns:repeat(4,1fr);
  gap:10px;
}

.scientific-grid{
  grid-template-columns:repeat(5,1fr);
  margin-bottom:12px;
}

.key{
  min-height:62px;
  border-radius:20px;
  background:var(--key);
  color:var(--text);
  font-size:22px;
  font-weight:800;
  cursor:pointer;
  transition:transform .16s ease, background .16s ease, filter .16s ease;
}

.key:hover{background:var(--key-hover)}
.key.soft{color:var(--accent)}
.key.operator{background:rgba(56,189,248,.18);color:var(--accent)}
.key.danger{background:rgba(251,113,133,.18);color:var(--danger)}
.key.equals{
  color:#001b10;
  background:linear-gradient(135deg,#22c55e,#86efac);
}
.key.sci{font-size:15px;min-height:52px;color:var(--accent)}
.wide{grid-column:span 2}
.full{grid-column:1/-1}

.compact .key{min-height:54px;font-size:19px}

.mini-row{
  display:flex;
  gap:8px;
  margin-bottom:12px;
}

.pill.active{
  color:#00111c;
  background:linear-gradient(135deg,var(--accent),var(--accent-2));
}

.form-grid{
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:12px;
}

label{
  color:var(--muted);
  font-size:13px;
  font-weight:800;
  display:grid;
  gap:8px;
}

input,select{
  width:100%;
  min-height:50px;
  border-radius:16px;
  border:1px solid var(--line);
  background:var(--key);
  color:var(--text);
  padding:0 14px;
  outline:none;
}

input:focus,select:focus{
  border-color:rgba(56,189,248,.7);
}

.primary-action{
  width:100%;
  min-height:54px;
  margin-top:14px;
  border-radius:18px;
  background:linear-gradient(135deg,var(--accent),var(--accent-2));
  color:#00111c;
  font-weight:900;
  cursor:pointer;
  transition:transform .18s ease, filter .18s ease;
}

.primary-action:hover{filter:brightness(1.05)}

.answer-card{
  margin-top:14px;
  padding:16px;
  border-radius:18px;
  background:rgba(255,255,255,.06);
  border:1px solid var(--line);
  color:var(--text);
  font-weight:800;
  line-height:1.6;
}

.history-card{
  padding:18px;
}

.history-head{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
}

.history-head h2{
  margin:0;
  font-size:18px;
}

.history-list{
  margin-top:14px;
  display:grid;
  gap:8px;
}

.history-item{
  padding:12px;
  border-radius:16px;
  background:rgba(255,255,255,.06);
  border:1px solid var(--line);
  color:var(--muted);
  font-size:13px;
}

.history-item strong{
  display:block;
  color:var(--text);
  font-size:15px;
  margin-bottom:4px;
}

.toast{
  position:fixed;
  left:50%;
  bottom:22px;
  transform:translate(-50%,24px);
  opacity:0;
  pointer-events:none;
  background:var(--card-solid);
  color:var(--text);
  border:1px solid var(--line);
  box-shadow:var(--shadow);
  padding:12px 18px;
  border-radius:999px;
  font-weight:900;
  transition:.24s ease;
  z-index:20;
}

.toast.show{
  opacity:1;
  transform:translate(-50%,0);
}

@media (min-width:860px){
  .app-shell{
    grid-template-columns:1.35fr .65fr;
    align-items:start;
  }
  .hero-card{grid-column:1/-1}
  .history-card{position:sticky;top:18px}
}

@media (max-width:560px){
  .app-shell{padding:10px;gap:10px}
  .hero-card{border-radius:22px;padding:16px}
  .calculator-card,.history-card{border-radius:24px}
  .screen{margin:10px;padding:14px;border-radius:20px}
  .panel{padding:0 10px 10px}
  .tool-tabs{padding:0 10px 10px}
  .keypad{gap:8px}
  .key{min-height:58px;border-radius:18px;font-size:20px}
  .scientific-grid{grid-template-columns:repeat(5,1fr);gap:8px}
  .key.sci{min-height:46px;font-size:13px;border-radius:15px}
  .form-grid{grid-template-columns:1fr}
  .result{min-height:54px}
}
