:root {
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-border: #e2e8f0;
  --color-text: #0f172a;
  --color-text-muted: #64748b;
  --color-accent: #4f46e5;
  --color-accent-hover: #4338ca;

  --calc-bg: #1e1e24;
  --calc-display: #141418;
  --calc-digit: #2d2d36;
  --calc-digit-hover: #3a3a44;
  --calc-action: #38383f;
  --calc-action-hover: #45454d;
  --calc-text: #f1f5f9;
  --calc-text-dim: #94a3b8;

  --radius: 12px;
  --gap: 9px;
  --shadow: 0 4px 6px -1px rgba(0,0,0,.12), 0 2px 4px -2px rgba(0,0,0,.08);
}

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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

nav {
  width: 100%;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0 1.25rem;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.nav-brand {
  font-weight: 700;
  font-size: 1rem;
  color: var(--color-accent);
  text-decoration: none;
}

.nav-link {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  text-decoration: none;
}

.nav-link:hover { color: var(--color-text); }

header {
  width: 100%;
  max-width: 480px;
  padding: 2rem 1rem 0;
  text-align: center;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.025em;
}

.tagline {
  font-size: 0.95rem;
  color: var(--color-text-muted);
  margin: 0.35rem 0 1rem;
}

main {
  width: 100%;
  max-width: 480px;
  padding: 0 1rem 2rem;
  flex: 1;
}

footer {
  width: 100%;
  text-align: center;
  padding: 1.25rem 1rem;
  color: var(--color-text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}

footer a { color: var(--color-text-muted); }

/* Calculator widget */

.calculator {
  background: var(--calc-bg);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  margin: 1.25rem 0 0;
}

.calc-display {
  background: var(--calc-display);
  border-radius: 8px;
  padding: 0.875rem 1.25rem;
  margin-bottom: var(--gap);
  min-height: 82px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
  word-break: break-all;
}

.calc-display__expression {
  font-size: 0.875rem;
  color: var(--calc-text-dim);
  min-height: 1.2em;
}

.calc-display__current {
  font-size: 2.2rem;
  font-weight: 400;
  line-height: 1.15;
  color: var(--calc-text);
  letter-spacing: -0.02em;
}

/* Button grid */

.calc-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(5, 62px);
  gap: var(--gap);
}

.btn {
  border: none;
  border-radius: 8px;
  font-size: 1.2rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.1s ease, transform 0.06s ease;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  color: var(--calc-text);
}

.btn:active { transform: scale(0.94); }
.btn:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }

.btn--digit { background: var(--calc-digit); }
.btn--digit:hover { background: var(--calc-digit-hover); }

.btn--operator { background: var(--color-accent); }
.btn--operator:hover { background: var(--color-accent-hover); }

.btn--action { background: var(--calc-action); }
.btn--action:hover { background: var(--calc-action-hover); }

.btn--equals { background: var(--color-accent); }
.btn--equals:hover { background: var(--color-accent-hover); }

.btn--wide { grid-column: span 2; }

.btn[disabled] { background: transparent; cursor: default; pointer-events: none; }

/* Ad units */

.ad-unit { width: 100%; min-height: 90px; margin: 1rem 0; }
.ad-unit--content { margin-top: 1.5rem; }

/* Info section */

.info-section { margin-top: 2rem; }

.info-section h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--color-text);
}

.info-section h2:not(:first-child) { margin-top: 1.5rem; }

.info-section p,
.info-section ul {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  line-height: 1.65;
}

.info-section ul {
  padding-left: 1.25rem;
  margin-top: 0.4rem;
}

.info-section li { margin-bottom: 0.25rem; }

kbd {
  background: var(--color-border);
  border-radius: 4px;
  padding: 0.1em 0.4em;
  font-family: monospace;
  font-size: 0.85em;
  color: var(--color-text);
}

/* Responsive */

@media (max-width: 360px) {
  .calc-buttons { grid-template-rows: repeat(5, 54px); gap: 7px; }
  .btn { font-size: 1.05rem; }
  .calc-display__current { font-size: 1.8rem; }
}

@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
  .btn:active { transform: none; }
}
