:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #14141f;
  --bg-tertiary: #1e1e2e;
  --bg-elev: #25253a;
  --text-primary: #ffffff;
  --text-secondary: #a0a0b0;
  --text-muted: #606070;
  --accent: #00d4ff;
  --accent-secondary: #00ff88;
  --danger: #ff4466;
  --warn: #ff9944;
  --purple: #c084fc;
  --focus-ring: #00d4ff;
  --focus-glow: rgba(0, 212, 255, 0.4);
  --radius-md: 12px;
  --radius-sm: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 600px;
  height: 600px;
  overflow: hidden;
  background: #000;
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
}

.screen {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
}

.screen.hidden { display: none; }

.focusable {
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease, background 0.12s ease;
  border: 2px solid transparent;
  cursor: pointer;
  outline: none;
}

.focusable:focus {
  border-color: var(--focus-ring);
  box-shadow: 0 0 20px var(--focus-glow);
  transform: scale(1.03);
  z-index: 2;
}

.hidden { display: none !important; }

/* Header */
.header {
  height: 38px;
  padding: 0 14px;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--bg-tertiary);
  flex-shrink: 0;
}

.spacer { flex: 1; }

.title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--text-secondary);
}

.badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  padding: 4px 9px;
  border-radius: 6px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.mode-badge {
  background: rgba(0, 212, 255, 0.12);
  color: var(--accent);
  border-color: rgba(0, 212, 255, 0.4);
}

.memory-badge {
  color: var(--text-muted);
  opacity: 0.4;
}

.memory-badge.active {
  background: rgba(0, 255, 136, 0.15);
  color: var(--accent-secondary);
  border-color: rgba(0, 255, 136, 0.4);
  opacity: 1;
}

.memory-badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
}

/* Display */
.display {
  background: var(--bg-primary);
  padding: 10px 18px 12px;
  flex-shrink: 0;
  height: 102px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  border-bottom: 1px solid var(--bg-tertiary);
  position: relative;
}

.mem-line {
  position: absolute;
  top: 8px;
  left: 18px;
  font-size: 11px;
  color: var(--accent-secondary);
  font-weight: 700;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.mem-line.show { opacity: 1; }

.expression {
  font-size: 17px;
  color: var(--text-secondary);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: rtl;
  min-height: 22px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.2px;
}

.result {
  font-size: 38px;
  font-weight: 600;
  color: var(--text-primary);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: rtl;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
  line-height: 1.05;
}

.result.preview {
  color: var(--text-secondary);
  font-size: 28px;
  font-weight: 500;
}

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

/* Grid */
.grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-auto-rows: 1fr;
  gap: 4px;
  padding: 5px;
  background: var(--bg-primary);
}

.btn {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 20px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  min-height: 44px;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
}

.btn sup {
  font-size: 0.65em;
  margin-left: 1px;
  vertical-align: super;
}

/* Color variants */
.btn-num {
  background: var(--bg-elev);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 22px;
}

.btn-num:focus {
  background: #2f2f48;
}

.btn-op {
  background: rgba(0, 212, 255, 0.13);
  color: var(--accent);
  font-weight: 700;
  font-size: 24px;
}

.btn-op:focus {
  background: rgba(0, 212, 255, 0.22);
}

.btn-fn {
  background: rgba(192, 132, 252, 0.12);
  color: var(--purple);
  font-size: 17px;
  font-weight: 700;
}

.btn-fn:focus {
  background: rgba(192, 132, 252, 0.22);
}

.btn-mem {
  background: rgba(0, 255, 136, 0.1);
  color: var(--accent-secondary);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.btn-mem:focus {
  background: rgba(0, 255, 136, 0.2);
}

.btn-action {
  background: rgba(255, 68, 102, 0.13);
  color: var(--danger);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 1px;
}

.btn-action:focus {
  background: rgba(255, 68, 102, 0.22);
}

.btn-const {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 19px;
  font-weight: 600;
}

.btn-const:focus {
  background: var(--bg-elev);
  color: var(--text-primary);
}

.btn-eq {
  background: var(--accent-secondary);
  color: #001a0d;
  font-weight: 900;
  font-size: 26px;
  letter-spacing: 1px;
}

.btn-eq:focus {
  background: #00ff95;
  box-shadow: 0 0 26px rgba(0, 255, 136, 0.7);
  border-color: var(--accent-secondary);
}
