/* ============================================================
   ARITHMETICA — Arcane Calculator
   Palette + fonts pulled from portfolio shared.css
============================================================ */

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

:root {
  --bg:           #07070f;
  --surface:      #0d0d1e;
  --surface-2:    #111128;
  --border:       rgba(255,255,255,0.07);
  --border-hi:    rgba(255,255,255,0.13);
  --teal:         #00ffc8;
  --teal-dim:     rgba(0,255,200,0.18);
  --teal-glow:    rgba(0,255,200,0.08);
  --magenta:      #ff00aa;
  --gold:         #ffd700;
  --text:         #ddd8cc;
  --text-dim:     #6a6660;
  --text-mid:     #9a9590;
  --font-display: 'Cinzel', serif;
  --font-mono:    'Share Tech Mono', monospace;
  --font-body:    'EB Garamond', serif;
  --radius:       10px;
}

html, body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  overflow-x: hidden;
}

/* ── Background ── */
.bg-grid {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    linear-gradient(rgba(0,255,200,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,255,200,0.025) 1px, transparent 1px);
  background-size: 40px 40px;
}
.bg-orb {
  position: fixed; border-radius: 50%; filter: blur(90px);
  opacity: 0.15; pointer-events: none; z-index: 0;
  animation: orb-drift 22s ease-in-out infinite alternate;
}
.orb-1 { width: 500px; height: 500px; background: #001a40; top: -120px; left: -120px; }
.orb-2 { width: 400px; height: 400px; background: #003320; bottom: -100px; right: -100px; animation-duration: 28s; }
@keyframes orb-drift { from { transform: translate(0,0); } to { transform: translate(30px,25px); } }

/* ── Layout ── */
.wrapper {
  position: relative; z-index: 1;
  min-height: 100vh;
  display: flex; flex-direction: column; align-items: center;
  padding: 2.5rem 1rem 3rem;
  gap: 1.5rem;
}

/* ── Header ── */
.calc-header { text-align: center; }
.header-runes {
  font-family: var(--font-display); font-size: 0.65rem;
  letter-spacing: 0.6em; color: var(--teal); opacity: 0.4; margin-bottom: 0.5rem;
}
.calc-header h1 {
  font-family: var(--font-display); font-size: clamp(1.8rem, 4vw, 2.8rem);
  font-weight: 700; color: #fff;
  text-shadow: 0 0 30px rgba(0,255,200,0.2);
  letter-spacing: 0.06em; margin-bottom: 0.2rem;
}
.header-sub {
  font-family: var(--font-body); font-style: italic;
  color: var(--text-dim); font-size: 0.95rem;
}

/* ── Shell ── */
.calc-shell {
  width: 100%; max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border-hi);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 0 60px rgba(0,0,0,0.6), 0 0 0 1px rgba(0,255,200,0.04);
}

/* ── Display ── */
.display-panel {
  background: #050510;
  padding: 1.2rem 1.4rem 1rem;
  border-bottom: 1px solid var(--border);
  min-height: 150px;
  display: flex; flex-direction: column; justify-content: flex-end;
  position: relative;
}
.display-mode {
  position: absolute; top: 0.8rem; left: 1.2rem;
  font-family: var(--font-mono); font-size: 0.6rem;
  letter-spacing: 0.2em; color: var(--teal); opacity: 0.5;
}
.display-history {
  font-family: var(--font-mono); font-size: 0.75rem;
  color: var(--text-dim); text-align: right; min-height: 1.1em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.display-expr {
  font-family: var(--font-mono); font-size: 0.9rem;
  color: var(--text-mid); text-align: right; min-height: 1.3em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 0.15rem;
}
.display-main {
  font-family: var(--font-mono);
  font-size: clamp(1.8rem, 6vw, 2.8rem);
  color: #fff; text-align: right;
  text-shadow: 0 0 20px rgba(0,255,200,0.3);
  line-height: 1.15;
  word-break: break-all;
  transition: color 0.15s;
}
.display-main.error { color: var(--magenta); text-shadow: 0 0 20px rgba(255,0,170,0.4); }
.display-main.result { color: var(--teal); }
.display-hint {
  font-family: var(--font-mono); font-size: 0.58rem;
  letter-spacing: 0.08em; color: var(--text-dim); opacity: 0.5;
  text-align: right; margin-top: 0.4rem;
}

/* ── Tabs ── */
.tab-strip {
  display: flex; border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.tab {
  flex: 1; background: none; border: none; cursor: pointer;
  font-family: var(--font-display); font-size: 0.6rem;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--text-dim); padding: 0.7rem 0.5rem;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.tab:hover  { color: var(--text); }
.tab.active { color: var(--teal); border-bottom-color: var(--teal); }

/* ── Keypad ── */
.keypad { padding: 0.9rem; }
.keypad.hidden { display: none; }

/* ── Standard Grid ── */
.key-grid { display: grid; gap: 0.55rem; }
.standard-grid { grid-template-columns: repeat(4, 1fr); }

/* ── Scientific Grid ── */
.sci-grid { grid-template-columns: repeat(6, 1fr); }

/* ── Keys ── */
.key {
  border: none; border-radius: var(--radius); cursor: pointer;
  font-family: var(--font-mono); font-size: 0.95rem;
  padding: 0.75rem 0.3rem;
  transition: background 0.12s, transform 0.08s, box-shadow 0.12s;
  position: relative; overflow: hidden;
  user-select: none;
}
.key::after {
  content: ''; position: absolute; inset: 0; border-radius: var(--radius);
  background: rgba(255,255,255,0.06); opacity: 0; transition: opacity 0.12s;
}
.key:hover::after  { opacity: 1; }
.key:active { transform: scale(0.94); }

.key.num  { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.key.op   { background: rgba(0,255,200,0.07); color: var(--teal); border: 1px solid rgba(0,255,200,0.2); font-size: 1.1rem; }
.key.op:hover { background: rgba(0,255,200,0.14); box-shadow: 0 0 12px rgba(0,255,200,0.1); }
.key.func { background: rgba(255,255,255,0.05); color: var(--text-mid); border: 1px solid var(--border); font-size: 0.82rem; }
.key.sci  { background: rgba(255,215,0,0.06); color: var(--gold); border: 1px solid rgba(255,215,0,0.18); font-size: 0.78rem; padding: 0.65rem 0.2rem; }
.key.sci:hover { background: rgba(255,215,0,0.12); box-shadow: 0 0 10px rgba(255,215,0,0.08); }
.key.eq   {
  background: linear-gradient(135deg, rgba(0,255,200,0.22), rgba(0,200,160,0.12));
  color: var(--teal); border: 1px solid rgba(0,255,200,0.4);
  font-size: 1.2rem; font-weight: bold;
  box-shadow: 0 0 14px rgba(0,255,200,0.1);
}
.key.eq:hover { box-shadow: 0 0 24px rgba(0,255,200,0.25); background: linear-gradient(135deg, rgba(0,255,200,0.32), rgba(0,200,160,0.18)); }
.key.active-op { background: rgba(0,255,200,0.18) !important; box-shadow: 0 0 14px rgba(0,255,200,0.2); }
.key[data-action="toggle-deg"] { font-size: 0.7rem; }

/* ── Constants Panel ── */
.constants-list { display: flex; flex-direction: column; gap: 1rem; padding: 0.2rem 0; }
.const-group-label {
  font-family: var(--font-display); font-size: 0.58rem;
  letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--teal); opacity: 0.5; margin-bottom: 0.4rem;
}
.const-btn {
  display: flex; justify-content: space-between; align-items: center;
  width: 100%; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.65rem 1rem; cursor: pointer;
  font-family: var(--font-mono); font-size: 0.88rem; color: var(--text);
  transition: background 0.15s, border-color 0.15s;
  text-align: left;
}
.const-btn:hover { background: rgba(0,255,200,0.06); border-color: rgba(0,255,200,0.25); }
.const-btn span { color: var(--text-dim); font-size: 0.8rem; }

/* ── History ── */
.history-section {
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.history-toggle {
  width: 100%; background: none; border: none; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.75rem 1.1rem;
  font-family: var(--font-display); font-size: 0.62rem;
  letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--text-dim);
  transition: color 0.2s;
}
.history-toggle:hover { color: var(--text); }
.history-arrow { transition: transform 0.25s; }
.history-arrow.open { transform: rotate(180deg); }
.history-list { max-height: 200px; overflow-y: auto; padding: 0.5rem 1rem 0.75rem; }
.history-list.hidden { display: none; }
.history-empty { font-family: var(--font-body); font-style: italic; font-size: 0.85rem; color: var(--text-dim); text-align: center; padding: 0.5rem 0; }
.history-item {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 0.4rem 0; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: color 0.15s;
}
.history-item:last-child { border-bottom: none; }
.history-item:hover .hist-expr { color: var(--text); }
.hist-expr { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-dim); flex: 1; }
.hist-result { font-family: var(--font-mono); font-size: 0.88rem; color: var(--teal); margin-left: 0.8rem; }

/* ── Back link ── */
.back-link { font-family: var(--font-body); font-size: 0.9rem; }
.back-link a { color: var(--text-dim); text-decoration: none; transition: color 0.2s; }
.back-link a:hover { color: var(--teal); }

/* ── Ripple ── */
@keyframes key-ripple {
  from { transform: scale(0); opacity: 0.4; }
  to   { transform: scale(2.5); opacity: 0; }
}
.ripple {
  position: absolute; border-radius: 50%;
  width: 60px; height: 60px;
  background: rgba(0,255,200,0.25);
  animation: key-ripple 0.4s ease-out forwards;
  pointer-events: none;
}

/* ── Responsive ── */
@media (max-width: 520px) {
  .sci-grid { grid-template-columns: repeat(4, 1fr); }
  .sci-grid .key.sci:nth-child(n+19) { grid-column: span 1; }
}
