/*
 * Heyming OS Calculator — Tier-1 rebuild.
 *
 * Built on brand tokens + HOSDL primitives. The old terminal-green LED
 * display and bevel-style keys are gone; the new chrome is a flat
 * iOS/macOS Calculator-inspired card with the Heyming violet accent.
 *
 * Functionality is preserved 1:1: every data-calc, data-mode, data-target,
 * data-expr, and element id the calculator.js / graph-mode.js modules
 * bind to is intact.
 */

* {
  box-sizing: border-box;
}

body.calc-page {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 16px 32px;
  background: var(--surface-0);
  color: var(--text-1);
  font-family: var(--font-ui);
}

body.calc-page--graph {
  padding-top: 0;
}

/* Screen-reader-only page title — h1 lives at the top for crawlers and
 * AT, but visually the .hos-app-header title carries the brand. */
.page-title {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Header — overrides .hos-app-header to span full width and stack the
 * segmented control under identity on narrow screens. */
.hos-app-header {
  width: 100%;
  max-width: 880px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

@media (max-width: 520px) {
  .hos-app-header {
    flex-direction: column;
    align-items: stretch;
  }
  .calc-mode-nav {
    align-self: stretch;
    justify-content: stretch;
  }
  .calc-mode-nav > button {
    flex: 1;
  }
}

/* App body */
.calc-app {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.calc-app--graph {
  max-width: 880px;
}

.calc-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.calc-panel[hidden] {
  display: none !important;
}

/* ─── Standard mode ────────────────────────────────────────────────── */

.calculator-display {
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: 28px 20px 24px;
  text-align: right;
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
  font-size: 48px;
  font-weight: 300;
  letter-spacing: -0.02em;
  color: var(--text-1);
  min-height: 96px;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  line-height: 1.1;
}

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

.calculator-button {
  height: 64px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  color: var(--text-1);
  border-radius: var(--radius-lg);
  cursor: pointer;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.005em;
  transition: background var(--motion-hover), border-color var(--motion-hover),
    transform var(--motion-hover);
  -webkit-tap-highlight-color: transparent;
}

.calculator-button:hover {
  background: var(--surface-1);
  border-color: var(--hairline-accent);
}

.calculator-button:active {
  transform: scale(0.96);
}

/* Utility row (C, ±, %) — softer surface so they read as "modifier". */
.calculator-button.calc-key--util {
  background: var(--surface-1);
  color: var(--accent-primary-hover);
  font-weight: 600;
}

.calculator-button.operator {
  background: var(--accent-primary-bg);
  color: var(--text-on-accent);
  border-color: transparent;
  font-weight: 600;
}

.calculator-button.operator:hover {
  background: var(--accent-primary-bg-hover);
}

.calculator-button.equals {
  background: var(--accent-primary);
  color: var(--text-on-accent);
  border-color: transparent;
  font-weight: 700;
}

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

@media (max-width: 480px) {
  .calculator-display {
    font-size: 40px;
    padding: 24px 16px 20px;
    min-height: 84px;
  }
  .calculator-button {
    height: 56px;
    font-size: 20px;
  }
}

/* ─── Graph mode ───────────────────────────────────────────────────── */

.calc-panel--graph {
  width: 100%;
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: 20px;
  gap: 14px;
}

.graph-expr-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.graph-expr-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
  min-width: 4.5rem;
}

.graph-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.graph-swatch--f {
  background: var(--accent-primary);
}
.graph-swatch--g {
  background: var(--warning);
}

.graph-expr-field {
  position: relative;
  flex: 1;
  min-width: 0;
}

.graph-expr-input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 36px 10px 14px;
  font-family: var(--font-mono);
  font-size: 14px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
  background: var(--surface-0);
  color: var(--text-1);
  transition: border-color var(--motion-hover), box-shadow var(--motion-hover);
}

.graph-expr-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-primary-soft);
}

.graph-expr-clear {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-3);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--motion-hover), color var(--motion-hover), background var(--motion-hover);
}

.graph-expr-field--has-value .graph-expr-clear,
.graph-expr-field:focus-within .graph-expr-clear {
  opacity: 1;
  pointer-events: auto;
}

.graph-expr-clear:hover {
  color: var(--text-1);
  background: var(--surface-2);
}

.graph-error {
  margin: 0;
  font-size: var(--text-caption);
  color: var(--danger);
}

.graph-toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.graph-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.graph-preset {
  padding: 5px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--hairline-strong);
  background: var(--surface-2);
  color: var(--text-1);
  cursor: pointer;
  transition: border-color var(--motion-hover), background var(--motion-hover);
}

.graph-preset:hover {
  border-color: var(--accent-primary);
  background: var(--accent-primary-soft);
}

.graph-view-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
}

.graph-range {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--font-ui);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-3);
  font-weight: 600;
}

.graph-range input {
  width: 72px;
  padding: 6px 8px;
  font-family: var(--font-mono);
  font-size: 13px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-0);
  color: var(--text-1);
  transition: border-color var(--motion-hover), box-shadow var(--motion-hover);
}

.graph-range input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-primary-soft);
}

.graph-btn {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text-1);
  cursor: pointer;
  transition: background var(--motion-hover), border-color var(--motion-hover);
}

.graph-btn:hover {
  background: var(--accent-primary-bg);
  color: var(--text-on-accent);
  border-color: transparent;
}

.graph-canvas-wrap {
  position: relative;
}

.graph-canvas {
  display: block;
  width: 100%;
  height: min(52vh, 360px);
  min-height: 220px;
  border-radius: var(--radius);
  border: 1px solid var(--hairline-strong);
  background: var(--surface-0);
  touch-action: none;
  cursor: crosshair;
}

.graph-canvas:active {
  cursor: grabbing;
}

.graph-tooltip {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--hairline-strong);
  background: var(--surface-1);
  box-shadow: var(--shadow-card);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-1);
  white-space: nowrap;
}

.graph-tooltip[hidden] {
  display: none !important;
}

.graph-tooltip-line {
  display: block;
}

.graph-hint {
  margin: 0;
  font-size: var(--text-caption);
  color: var(--text-3);
  text-align: center;
}
