/* Calculator: only what the shared tools.css does not cover */

/* ---------- Display ---------- */
.calc-display {
  position: relative;
  padding: 0.875rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.calc-history {
  min-height: 1.375rem;
  padding-inline-end: 3rem;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.8125rem;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calc-history-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
}

.calc-result {
  display: block;
  width: 100%;
  margin-top: 0.125rem;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: clamp(1.75rem, 1.2rem + 3vw, 2.75rem);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: left;
}

/* ---------- Programmer readouts ---------- */
.base-grid {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.75rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.base-cell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-width: 0;
  padding: 0.25rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: var(--mono);
  font-size: 0.8125rem;
}

.base-cell > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.base-name {
  color: var(--accent-text);
  font-weight: 700;
}

/* ---------- Keypad ---------- */
.keys {
  display: grid;
  gap: 0.5rem;
  grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr));
}

.keys--5 {
  --cols: 5;
}

.keys--6 {
  --cols: 6;
}

.key {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 3.25rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color 0.12s ease,
    border-color 0.12s ease,
    transform 0.08s ease;
}

.key:active:not(:disabled) {
  transform: scale(0.96);
  background: var(--surface-3);
}

.key:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.key--op {
  border-color: transparent;
  background: var(--accent);
  color: var(--on-accent);
}

.key--op:active:not(:disabled) {
  background: var(--accent-hover);
}

.key--fn {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 0.9375rem;
}

.key--util {
  color: var(--accent-text);
}

.key--eq {
  border-color: transparent;
  background: var(--success);
  color: var(--bg);
}

.key--compact {
  font-size: 0.8125rem;
}

.key--span-2 {
  grid-column: span 2;
}

.key--span-3 {
  grid-column: span 3;
}

.key--row-2 {
  grid-row: span 2;
}

@media (hover: hover) {
  .key:hover:not(:disabled) {
    border-color: var(--accent);
  }
}

@media (min-width: 640px) {
  .key {
    min-height: 3.75rem;
  }

  .base-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 380px) {
  .keys {
    gap: 0.375rem;
  }

  .key {
    min-height: 3rem;
    font-size: 1rem;
  }

  .key--fn {
    font-size: 0.8125rem;
  }
}

/* ---------- Graph ---------- */
.graph-layout {
  display: grid;
  gap: 1.25rem;
}

.range-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.graph-canvas {
  width: 100%;
  max-width: 36rem;
  aspect-ratio: 1;
  justify-self: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

@media (min-width: 900px) {
  .graph-layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr);
    align-items: start;
  }
}

/* ---------- History ---------- */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.history-item {
  display: block;
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  text-align: start;
  cursor: pointer;
}

.history-item:hover {
  border-color: var(--accent);
}

.history-expression,
.history-result {
  font-family: var(--mono);
  text-align: left;
}

.history-expression {
  color: var(--muted);
  font-size: 0.875rem;
}

.history-result {
  font-size: 1.125rem;
  font-weight: 700;
}

.history-time {
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.75rem;
}
