:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --display: #f9fafb;
  --key: #f3f4f6;
  --key-hover: #e5e7eb;
  --fn: #e5e7eb;
  --fn-hover: #d1d5db;
  --op: #dbe6f1;
  --op-hover: #c7d7e8;
  --op-text: #1f4b73;
  --accent: #2f5d8a;
  --accent-hover: #264d73;
  --error: #b42318;
  --ring: #2f5d8a;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 8px 24px rgb(0 0 0 / 8%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #181b21;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --display: #111318;
    --key: #23272f;
    --key-hover: #2d323c;
    --fn: #2d323c;
    --fn-hover: #383e4a;
    --op: #1f3347;
    --op-hover: #28415a;
    --op-text: #cfe0f1;
    --accent: #4a7fb3;
    --accent-hover: #5a8fc3;
    --error: #f97066;
    --ring: #8ab4dd;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 35%);
  }
}

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

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.shell {
  width: 100%;
  max-width: 360px;
}

.brand {
  margin-bottom: 16px;
  text-align: center;
}

.brand h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.brand .platform {
  display: inline-block;
  margin-top: 10px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--op);
  color: var(--op-text);
  font-size: 0.85rem;
  font-weight: 600;
}

.brand .platform[hidden] {
  display: none;
}

.calc {
  padding: 16px;
  border-radius: 20px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.display {
  margin-bottom: 16px;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--display);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.expression {
  min-height: 1.4em;
  color: var(--muted);
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.value {
  display: block;
  min-height: 1.25em;
  font-size: 2.5rem;
  font-weight: 600;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.value.long {
  font-size: 1.6rem;
}

.value.error {
  color: var(--error);
  font-size: 1.4rem;
}

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

.key {
  min-height: 56px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--key);
  color: var(--text);
  font: inherit;
  font-size: 1.3rem;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 80ms ease, transform 80ms ease;
}

.key:hover {
  background: var(--key-hover);
}

.key:active,
.key.pressed {
  transform: scale(0.96);
}

.key:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.key.fn {
  background: var(--fn);
}

.key.fn:hover {
  background: var(--fn-hover);
}

.key.op {
  background: var(--op);
  color: var(--op-text);
}

.key.op:hover {
  background: var(--op-hover);
}

.key.op[data-key="%"] {
  font-size: 1.05rem;
}

.key.op.selected {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.key.eq {
  grid-column: 1 / -1;
  background: var(--accent);
  color: #fff;
}

.key.eq:hover {
  background: var(--accent-hover);
}

.key sup {
  font-size: 0.65em;
}

.foot {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

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