:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #7b8794;
  --border: #e4e7eb;
  --key: #f0f2f5;
  --key-hover: #e2e6ea;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --radius: 12px;
  --header-h: 64px;
}

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

html { scroll-behavior: smooth; scroll-padding-top: var(--header-h); }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: white;
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main { flex: 1; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
ul { list-style: none; }

.wrapper {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* ---------- Header / Navbar ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header__inner {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo { font-size: 1.25rem; font-weight: 700; color: var(--text); }
.logo:hover { text-decoration: none; }

.nav ul { display: flex; gap: 0.25rem; }

.nav a {
  display: block;
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  color: var(--text);
  font-weight: 500;
}

.nav a:hover,
.nav a.active { background: #dbeafe; color: var(--accent); text-decoration: none; }

.nav-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  padding: 0.5rem;
  background: none;
  border: none;
  cursor: pointer;
}

.nav-toggle span {
  width: 24px;
  height: 2px;
  background: var(--text);
  transition: transform 0.2s, opacity 0.2s;
}

.nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ---------- Hero ---------- */
.hero {
  padding: 4rem 0;
  text-align: center;
  background: linear-gradient(135deg, #dbeafe, #eff6ff);
}

.hero h1 { font-size: clamp(1.8rem, 5vw, 2.8rem); margin-bottom: 0.75rem; }
.hero p { max-width: 560px; margin: 0 auto 1.5rem; color: var(--muted); }

.btn {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  font-weight: 600;
  transition: background 0.15s;
}

.btn:hover { background: var(--accent-hover); text-decoration: none; }

/* ---------- Sections ---------- */
.section { padding: 3rem 0; }
.section--alt { background: var(--surface); border-block: 1px solid var(--border); }
.section__title { font-size: 1.6rem; margin-bottom: 0.75rem; }
.section__lead { color: var(--muted); }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.card {
  padding: 1.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.card h3 { margin-bottom: 0.4rem; }
.card p { color: var(--muted); font-size: 0.95rem; }

/* ---------- Calculator (unchanged) ---------- */
.container {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  justify-content: center;
  align-items: flex-start;
}

.calculator,
.history {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.calculator { width: 720px; max-width: 100%; }

.display {
  width: 100%;
  padding: 1rem;
  margin-bottom: 1rem;
  font-size: 2rem;
  text-align: right;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}

.keys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.key {
  padding: 1rem 0;
  font-size: 1.25rem;
  border: none;
  border-radius: 8px;
  background: #343a40;
  color: white;
  cursor: pointer;
  transition: background 0.15s;
}

.key:hover { background: #282d31;}
.key:active { transform: scale(0.96); }
.key--op { background: #dbeafe; color: var(--accent); }
.key--op:hover { background: #bfdbfe; }
.key--equal { background: var(--accent); color: #fff; }
.key--equal:hover { background: var(--accent-hover); }

.history { width: 320px; max-width: 100%; }

.history__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.history__head h2 { font-size: 1rem; font-weight: 600; }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.85rem;
  cursor: pointer;
}

.history__list { max-height: 340px; overflow-y: auto; }

.history__list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  cursor: pointer;
}

.history__list li:last-child { border-bottom: none; }
.history__list .expr { color: var(--muted); display: block; }
.history__list .result { font-weight: 600; }
.history__list .empty { color: var(--muted); cursor: default; }

/* ---------- Footer ---------- */
.site-footer {
  background: #1f2933;
  color: #cbd2d9;
  padding: 1.5rem 0;
  font-size: 0.9rem;
}

.footer__inner {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  justify-content: space-between;
  align-items: center;
}

.footer__links { display: flex; gap: 1rem; }
.site-footer a { color: #cbd2d9; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .nav-toggle { display: flex; }

  .nav {
    position: absolute;
    top: var(--header-h);
    left: 0;
    right: 0;
    display: none;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 1rem 1rem;
  }

  .nav.open { display: block; }
  .nav ul { flex-direction: column; }

  .hero { padding: 3rem 0; }
  .section { padding: 2rem 0; }
  .footer__inner { flex-direction: column; text-align: center; }
}

@media (max-width: 380px) {
  .display { font-size: 1.5rem; }
  .key { font-size: 1.1rem; padding: 0.85rem 0; }
  .history { width: 368px; max-width: 100%; }
}
