.page {
  flex: 1;
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.calc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.calc-head {
  display: flex;
  justify-content: flex-end;
  padding: 0 0 10px;
}
.icon-btn {
  appearance: none; background: transparent; border: none;
  width: 32px; height: 32px; border-radius: 999px; color: var(--muted);
  cursor: pointer; display: grid; place-items: center;
  transition: background 120ms, color 120ms;
}
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn[aria-pressed="true"] { background: var(--ink); color: white; }

.display {
  background: var(--hover); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 18px 16px; margin-bottom: 14px;
  min-height: 110px; display: flex; flex-direction: column; justify-content: flex-end; gap: 6px;
}
.display-row {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; min-height: 18px;
}
.display-row .copy-btn { flex-shrink: 0; margin-top: -2px; }
.display-expr {
  font-family: "JetBrains Mono", monospace; font-size: 13px; color: var(--muted);
  text-align: left; flex: 1; word-break: break-all; line-height: 1.5;
}
.display-value {
  font-family: "JetBrains Mono", monospace; font-weight: 600; font-size: 34px;
  color: var(--ink); text-align: right; word-break: break-all; line-height: 1.15;
  cursor: pointer; user-select: text; transition: color 120ms;
}
.display-value:hover { color: var(--accent-deep); }

.copy-btn {
  appearance: none; background: var(--surface); border: 1px solid var(--border);
  color: var(--sub); font-family: "Noto Sans JP", sans-serif; font-size: 11.5px;
  padding: 4px 10px 4px 8px; border-radius: 999px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px; opacity: 0.85;
  transition: opacity 120ms, background 120ms, color 120ms, border-color 120ms;
}
.copy-btn:hover { opacity: 1; background: var(--accent-soft); border-color: var(--accent); color: var(--accent-deep); }
.copy-btn.copied { background: var(--ok); border-color: var(--ok); color: #fff; opacity: 1; }

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

.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface);
  color: var(--ink); font-family: "Noto Sans JP", sans-serif; font-weight: 500;
  font-size: 18px; padding: 14px 0; border-radius: var(--radius);
  cursor: pointer; transition: transform 80ms, background 120ms, border-color 120ms, color 120ms;
  user-select: none;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: translateY(1px); }

.btn.util { background: var(--hover); color: var(--sub); font-size: 15px; }
.btn.util:hover { background: #e5e7eb; }

.btn.op {
  font-family: "JetBrains Mono", monospace; font-weight: 600; font-size: 19px;
}
.btn.op:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-deep); }

.btn.equal {
  background: var(--accent); border-color: var(--accent); color: white;
  font-weight: 700; font-size: 21px; box-shadow: inset 0 -2px 0 rgba(0,0,0,0.06);
}
.btn.equal:hover { background: var(--accent-deep); border-color: var(--accent-deep); }

.btn.clear { color: var(--danger); }
.btn.clear:hover { background: var(--danger-soft); border-color: #fca5a5; }

.history { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 14px; display: none; }
.history.is-open { display: block; }
.history-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.history-title {
  font-family: "JetBrains Mono", monospace; font-size: 11px;
  letter-spacing: 0.16em; color: var(--muted); text-transform: uppercase;
}
.history-clear {
  appearance: none; background: none; border: none; color: var(--muted);
  font: inherit; font-size: 12px; cursor: pointer; padding: 4px 8px;
  border-radius: 6px; transition: background 120ms, color 120ms;
}
.history-clear:hover { background: var(--hover); color: var(--sub); }
.history-list {
  list-style: none; padding: 0; max-height: 180px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
}
.history-empty { text-align: center; color: var(--muted); font-size: 12.5px; padding: 16px 0; }
.history-item {
  appearance: none; background: var(--hover); border: 1px solid transparent;
  border-radius: var(--radius); padding: 8px 12px; font: inherit;
  text-align: right; cursor: pointer; display: flex; flex-direction: column;
  gap: 2px; transition: background 120ms, border-color 120ms;
}
.history-item:hover { background: #e5e7eb; border-color: var(--accent); }
.history-expr { font-family: "JetBrains Mono", monospace; font-size: 11.5px; color: var(--muted); }
.history-result { font-family: "JetBrains Mono", monospace; font-weight: 600; font-size: 15px; color: var(--ink); }

kbd {
  display: inline-block; font-family: "JetBrains Mono", monospace; font-size: 11.5px;
  background: var(--hover); border: 1px solid var(--border); border-bottom-width: 2px;
  padding: 1px 7px; border-radius: 6px; color: var(--ink); margin: 0 2px; vertical-align: 1px;
}

@media (max-width: 420px) {
  .display-value { font-size: 30px; }
  .btn { font-size: 16px; padding: 12px 0; }
}
