:root {
  --bg: #d7d9dd;
  --panel: #f3f4f6;
  --panel-2: #e7eaee;
  --text: #1f2a35;
  --muted: #536272;
  --steel: #2f475f;
  --steel-2: #3f5f7f;
  --accent: #f08c2e;
  --accent-2: #d97515;
  --line: #b8c0c8;
  --danger: #bb3a2d;
  --ok: #2b7a45;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.45), rgba(0, 0, 0, 0) 45%),
    repeating-linear-gradient(
      45deg,
      rgba(47, 71, 95, 0.06) 0,
      rgba(47, 71, 95, 0.06) 10px,
      rgba(47, 71, 95, 0.02) 10px,
      rgba(47, 71, 95, 0.02) 20px
    ),
    var(--bg);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  padding: 0;
}

.top-link {
  width: 100%;
  text-align: center;
  padding: 12px 16px;
  background: linear-gradient(90deg, var(--steel), var(--steel-2));
  border-bottom: 1px solid rgba(255, 255, 255, 0.25);
}

.top-link a {
  font-size: 24px;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
}

.app {
  width: min(980px, 100%);
  margin-top: 16px;
  padding: 0 16px 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.card {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 26px rgba(22, 33, 45, 0.15);
  overflow: hidden;
}

.card-header {
  padding: 12px 16px;
  background: linear-gradient(90deg, var(--steel), var(--steel-2));
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.card-header a {
  color: inherit;
  text-decoration: none;
}

.calculator {
  padding: 14px;
}

.display-wrap {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 10px;
}

.formula-preview {
  min-height: 22px;
  font-size: 13px;
  color: var(--muted);
  word-break: break-all;
}

.display {
  width: 100%;
  border: none;
  outline: none;
  font-size: 30px;
  color: var(--text);
  text-align: right;
  background: transparent;
  padding: 4px 0 0;
}

.precision-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 10px;
}

.precision-label {
  font-size: 13px;
  color: var(--muted);
  margin-right: 2px;
}

.precision-option {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  padding: 4px 10px;
  line-height: 1.2;
}

.precision-option.active {
  background: linear-gradient(180deg, #4f6d87, #37556e);
  color: #fff;
  border-color: #37556e;
}

.status {
  min-height: 20px;
  font-size: 13px;
  margin-bottom: 10px;
}

.status.error { color: var(--danger); }
.status.info { color: var(--ok); }

.keypad {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

button {
  border: 1px solid #9aa5af;
  border-radius: 10px;
  background: linear-gradient(180deg, #fff, #e7edf3);
  color: var(--text);
  font-size: 18px;
  padding: 12px 10px;
  cursor: pointer;
  transition: transform 0.05s ease, filter 0.2s ease;
}

button:hover { filter: brightness(0.98); }
button:active { transform: translateY(1px); }

.op { background: linear-gradient(180deg, #f6b26f, #ee9b3a); font-weight: 700; }
.func { background: linear-gradient(180deg, #d8e1ea, #bccad8); font-weight: 700; }
.full { grid-column: span 5; }
.equal { background: linear-gradient(180deg, #4f6d87, #37556e); color: #fff; font-weight: 700; }
.danger { background: linear-gradient(180deg, #d35749, #b53f34); color: #fff; }

.history {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-tip {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  max-height: 500px;
  overflow: auto;
}

.history-item {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 10px;
  display: grid;
  gap: 4px;
  cursor: pointer;
}

.history-item.active {
  outline: 2px solid var(--accent);
  background: #fff8ef;
}

.history-formula {
  font-size: 14px;
  color: var(--muted);
  word-break: break-all;
}

.history-result {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  word-break: break-all;
}

.empty {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 18px;
  text-align: center;
  background: #fbfcfd;
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .history-list { max-height: 320px; }
}
