:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --panel: #ffffff;
  --text: #15171a;
  --muted: #6f7782;
  --line: #dde2e8;
  --key: #f4f6f8;
  --key-hover: #e9edf2;
  --accent: #1d74f5;
  --accent-hover: #0f63df;
  --accent-soft: #eaf2ff;
  --danger: #c0392b;
  --shadow: 0 18px 55px rgba(20, 28, 40, 0.11);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button {
  font: inherit;
}

.shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.calculator {
  width: min(100%, 380px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.display {
  min-height: 128px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 10px;
  padding: 26px 24px 20px;
  border-bottom: 1px solid var(--line);
}

.expression {
  width: 100%;
  min-height: 48px;
  overflow: hidden;
  text-align: right;
  font-size: clamp(32px, 10vw, 46px);
  line-height: 1.1;
  font-weight: 650;
  letter-spacing: 0;
  word-break: break-all;
}

.status {
  min-height: 20px;
  text-align: right;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

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

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

.key {
  min-width: 0;
  aspect-ratio: 1 / 0.78;
  border: 0;
  background: var(--key);
  color: var(--text);
  cursor: pointer;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 0;
  transition: background 140ms ease, color 140ms ease;
}

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

.key:focus-visible {
  outline: 3px solid var(--accent-soft);
  outline-offset: -3px;
}

.utility {
  color: var(--muted);
  background: #fbfcfd;
}

.operator {
  color: var(--accent);
  background: #f8fbff;
}

.equals {
  background: var(--accent);
  color: #ffffff;
}

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

.key:disabled {
  cursor: wait;
  opacity: 0.62;
}

@media (max-width: 420px) {
  .shell {
    padding: 12px;
  }

  .calculator {
    width: 100%;
  }

  .display {
    min-height: 118px;
    padding: 22px 18px 18px;
  }

  .key {
    aspect-ratio: 1 / 0.86;
  }
}

/* --- Bagian Riwayat Perhitungan --- */
.history-panel {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
  margin-top: 10px;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
  margin-bottom: 10px;
}

.clear-history-btn {
  background: transparent;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 140ms ease;
}

.clear-history-btn:hover {
  background: #fef2f2;
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 180px;
  overflow-y: auto;
}

.history-item {
  font-size: 0.85rem;
  padding: 8px 10px;
  background: var(--key);
  border-radius: 6px;
  cursor: pointer;
  transition: background 140ms ease, transform 100ms ease;
  word-break: break-all;
  border: 1px solid transparent;
  font-weight: 500;
}

.history-item:hover {
  background: var(--key-hover);
  border-color: var(--line);
  transform: translateY(-1px);
}

.empty-history {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  padding: 12px 0;
  font-style: italic;
}
