/* === reset & base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-0: #0a0a0f;
  --bg-1: #11121a;
  --bg-2: #1a1c26;
  --bg-3: #232634;
  --line: #2a2d3a;
  --txt: #e8e9ee;
  --txt-dim: #8b8e9c;
  --accent: #7c5cff;
  --accent-2: #00d4aa;
  --op: #ff8c42;
  --equals: #7c5cff;
  --danger: #ff5470;
  --shadow: 0 10px 40px rgba(0,0,0,0.4);
  --radius: 14px;
  --mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
}

html, body {
  height: 100%;
  background: radial-gradient(ellipse at top, #15121f 0%, var(--bg-0) 60%);
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  min-height: 100vh;
}

/* === layout === */
.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 18px;
  width: 100%;
  max-width: 880px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  box-shadow: var(--shadow);
}

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; max-width: 460px; }
  .history-panel { order: 2; max-height: 220px; }
}

/* === history panel === */
.history-panel {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  min-height: 520px;
}

.history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.history-head h2 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--txt-dim);
}

.history-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding-right: 4px;
}

.history-list::-webkit-scrollbar { width: 6px; }
.history-list::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 3px; }

.history-list li {
  padding: 10px 12px;
  margin-bottom: 6px;
  background: var(--bg-1);
  border: 1px solid transparent;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.history-list li:hover:not(.history-empty) {
  border-color: var(--accent);
  transform: translateX(2px);
}

.history-list .h-expr {
  color: var(--txt-dim);
  font-size: 11px;
  margin-bottom: 4px;
}

.history-list .h-res {
  color: var(--txt);
  font-weight: 600;
}

.history-empty {
  text-align: center;
  color: var(--txt-dim);
  font-style: italic;
  cursor: default !important;
}

/* === calculator === */
.calc {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.calc-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 4px 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 14px;
  color: var(--txt-dim);
}

.brand .accent { color: var(--accent); }

.brand .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 8px var(--accent-2);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.modes {
  display: flex;
  gap: 6px;
  align-items: center;
}

.mode-btn, .ang-toggle, .ghost-btn {
  background: var(--bg-2);
  color: var(--txt-dim);
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s;
  font-family: inherit;
}

.mode-btn:hover, .ang-toggle:hover, .ghost-btn:hover {
  color: var(--txt);
  border-color: var(--accent);
}

.mode-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* transitions.dev: tabs sliding */
.t-tabs {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px;
  border-radius: 48px;
  background: var(--bg-2);
  border: 1px solid var(--line);
}
.t-tabs .t-tab {
  position: relative;
  appearance: none;
  border: 0;
  background: transparent;
  height: 30px;
  padding: 4px 12px;
  color: var(--txt-dim);
  cursor: pointer;
  border-radius: 48px;
  z-index: 1;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  transition: color 200ms cubic-bezier(0.22, 1, 0.36, 1);
}
.t-tabs .t-tab:not([aria-selected="true"]):hover,
.t-tabs .t-tab[aria-selected="true"] {
  color: var(--txt);
}
.t-tabs-pill {
  position: absolute;
  top: 3px;
  left: 0;
  height: 30px;
  width: 0;
  background: var(--accent);
  border-radius: 48px;
  transform: translateX(0);
  transition:
    transform 200ms cubic-bezier(0.22, 1, 0.36, 1),
    width     200ms cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform, width;
  z-index: 0;
  pointer-events: none;
}

.ang-toggle.rad { color: var(--accent-2); border-color: var(--accent-2); }

.ghost-btn { padding: 6px 10px; font-size: 14px; }

/* === display === */
.display {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  text-align: right;
  position: relative;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.memory-indicator {
  position: absolute;
  top: 10px;
  left: 14px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent-2);
  letter-spacing: 1px;
}

.expression {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--txt-dim);
  min-height: 20px;
  word-break: break-all;
  margin-bottom: 6px;
}

.result {
  font-family: var(--mono);
  font-size: 36px;
  font-weight: 600;
  color: var(--txt);
  word-break: break-all;
  line-height: 1.1;
}

.result.error { color: var(--danger); font-size: 22px; }

/* === memory row === */
.memory-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.mem-btn {
  background: var(--bg-2);
  color: var(--txt-dim);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--mono);
}

.mem-btn:hover { color: var(--accent-2); border-color: var(--accent-2); }
.mem-btn:active { transform: scale(0.96); }

/* === keypad === */
.keypad { display: flex; flex-direction: column; gap: 8px; }

.sci-row {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.2s;
  opacity: 0;
}

.sci-row.open {
  max-height: 200px;
  opacity: 1;
}

.main-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 8px;
}

/* equals spans 2 rows wouldn't fit nicely; keep it as single tall button */
.equals {
  grid-column: 4;
  grid-row: 6;
}

.key {
  background: var(--bg-3);
  color: var(--txt);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 16px 0;
  font-size: 17px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.1s;
  user-select: none;
}

.key:hover { background: #2c3040; transform: translateY(-1px); }
.key:active { transform: translateY(0) scale(0.97); }

.key.sci {
  background: var(--bg-2);
  font-family: var(--mono);
  font-size: 13px;
  padding: 12px 0;
  color: var(--accent-2);
}

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

.key.op {
  background: var(--bg-2);
  color: var(--op);
  font-weight: 600;
  font-size: 20px;
}

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

.key.util {
  background: var(--bg-2);
  color: var(--danger);
  font-size: 15px;
  font-weight: 600;
}

.key.util:hover { background: var(--danger); color: white; }

.key.num { font-family: var(--mono); font-weight: 600; }

.key.equals {
  background: linear-gradient(135deg, var(--accent), #5b3fd9);
  color: white;
  font-size: 24px;
  font-weight: 700;
  border: none;
}

.key.equals:hover {
  filter: brightness(1.1);
  box-shadow: 0 4px 16px rgba(124, 92, 255, 0.4);
}

/* === hint === */
.hint {
  text-align: center;
  font-size: 11px;
  color: var(--txt-dim);
  font-family: var(--mono);
  padding-top: 4px;
}

/* === scientific mode tweaks === */
body.scientific .sci-row { max-height: 200px; opacity: 1; }

/* press feedback */
.key.flash {
  animation: flash 0.2s;
}

@keyframes flash {
  0% { background: var(--accent); color: white; }
  100% { }
}

/* === hint with trial info === */
.hint {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.trial-info {
  color: var(--accent-2);
  font-weight: 600;
}

/* ============================================ */
/* ===== PAYWALL / PAYMENT MODALS ===== */
/* ============================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeIn 0.25s ease;
}

.modal-overlay.show {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* === main paywall === */
.modal {
  background: linear-gradient(160deg, var(--bg-1), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 32px 28px 24px;
  max-width: 760px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  /* transitions.dev modal */
  transform-origin: center;
  transform: scale(0.96);
  opacity: 0;
  pointer-events: none;
  transition:
    transform 250ms cubic-bezier(0.22, 1, 0.36, 1),
    opacity   250ms cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform, opacity;
}
.modal.is-open {
  transform: scale(1);
  opacity: 1;
  pointer-events: auto;
}
.modal.is-closing {
  transform: scale(0.96);
  opacity: 0;
  pointer-events: none;
  transition:
    transform 150ms cubic-bezier(0.22, 1, 0.36, 1),
    opacity   150ms cubic-bezier(0.22, 1, 0.36, 1);
}

.modal::-webkit-scrollbar { width: 6px; }
.modal::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 3px; }

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-3);
  color: var(--txt-dim);
  border: none;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.15s;
}

.modal-close:hover { background: var(--danger); color: white; transform: rotate(90deg); }

.modal-icon {
  font-size: 48px;
  text-align: center;
  margin-bottom: 8px;
  filter: drop-shadow(0 0 12px rgba(124, 92, 255, 0.4));
}

.modal h2 {
  text-align: center;
  font-size: 24px;
  margin-bottom: 6px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal-sub {
  text-align: center;
  color: var(--txt-dim);
  font-size: 13px;
  margin-bottom: 18px;
}

.locked-result {
  background: var(--bg-0);
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 14px 18px;
  text-align: center;
  margin-bottom: 22px;
  font-family: var(--mono);
}

.lock-expr {
  color: var(--txt-dim);
  font-size: 14px;
  margin-bottom: 4px;
}

.lock-blur {
  color: var(--accent);
  font-size: 28px;
  letter-spacing: 6px;
  filter: blur(2px);
  user-select: none;
}

/* === plans grid === */
.plans {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

@media (max-width: 640px) {
  .plans { grid-template-columns: 1fr; }
}

.plan {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 14px;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  color: var(--txt);
  position: relative;
  display: flex;
  flex-direction: column;
}

.plan:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: 0 8px 24px rgba(124, 92, 255, 0.2);
}

.plan-premium {
  border-color: var(--accent);
  background: linear-gradient(160deg, var(--bg-2), rgba(124, 92, 255, 0.1));
}

.plan-premium:hover {
  box-shadow: 0 8px 24px rgba(124, 92, 255, 0.4);
}

.plan-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.plan-head h3 {
  font-size: 16px;
  font-weight: 700;
}

.plan-badge {
  background: var(--accent);
  color: white;
  font-size: 9px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
  letter-spacing: 1px;
  position: absolute;
  top: -8px;
  right: 12px;
}

.plan-price {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.price-old {
  color: var(--txt-dim);
  font-size: 12px;
  text-decoration: line-through;
}

.price-new {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent-2);
  font-family: var(--mono);
}

.plan-premium .price-new { color: var(--accent); }

.price-period {
  color: var(--txt-dim);
  font-size: 11px;
}

.plan-feats {
  list-style: none;
  flex: 1;
  margin-bottom: 14px;
  font-size: 12px;
  line-height: 1.8;
  color: var(--txt-dim);
}

.plan-feats li { padding: 0; }

.plan-cta {
  display: block;
  text-align: center;
  background: var(--bg-3);
  color: var(--txt);
  padding: 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s;
}

.plan-premium .plan-cta {
  background: linear-gradient(135deg, var(--accent), #5b3fd9);
  color: white;
}

.plan-ad .plan-cta {
  background: var(--accent-2);
  color: var(--bg-0);
}

.plan:hover .plan-cta { filter: brightness(1.15); }

.plan:disabled, .plan.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.modal-foot {
  text-align: center;
  font-size: 11px;
  color: var(--txt-dim);
  font-style: italic;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

/* ============================================ */
/* ===== AD PLAYER MODAL ===== */
/* ============================================ */
.ad-overlay { z-index: 1100; }

.ad-box {
  background: #000;
  border: 1px solid var(--line);
  border-radius: 14px;
  max-width: 520px;
  width: 100%;
  overflow: hidden;
  animation: slideUp 0.3s ease;
}

.ad-banner {
  background: linear-gradient(135deg, #ff6b00, #ff3366);
  color: white;
  padding: 32px 24px;
  text-align: center;
  position: relative;
}

.ad-banner::before {
  content: 'AD';
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0,0,0,0.5);
  color: white;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  letter-spacing: 1px;
}

.ad-logo {
  font-size: 14px;
  font-weight: 600;
  opacity: 0.9;
  margin-bottom: 8px;
}

.ad-banner h3 {
  font-size: 22px;
  margin-bottom: 8px;
}

.ad-banner p {
  font-size: 13px;
  opacity: 0.95;
  margin-bottom: 14px;
}

.ad-fake-btn {
  display: inline-block;
  background: white;
  color: #ff3366;
  padding: 8px 18px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 13px;
  animation: wiggle 1.5s infinite;
}

@keyframes wiggle {
  0%, 100% { transform: rotate(-2deg); }
  50% { transform: rotate(2deg); }
}

.ad-progress {
  height: 4px;
  background: #222;
}

.ad-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-2);
  transition: width 0.1s linear;
}

.ad-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  background: var(--bg-1);
  color: var(--txt-dim);
  font-size: 12px;
  font-family: var(--mono);
}

.ad-skip {
  background: var(--bg-3);
  color: var(--txt-dim);
  border: 1px solid var(--line);
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
}

.ad-skip:not(:disabled) {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  cursor: pointer;
}

.ad-skip:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================ */
/* ===== PAYMENT PROCESSING MODAL ===== */
/* ============================================ */
.pay-box {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 36px 28px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  animation: slideUp 0.3s ease;
}

.pay-spinner {
  width: 56px;
  height: 56px;
  border: 4px solid var(--bg-3);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 20px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.pay-box h3 {
  font-size: 18px;
  margin-bottom: 6px;
}

.pay-box p {
  color: var(--txt-dim);
  font-size: 13px;
  margin-bottom: 18px;
}

.pay-progress {
  height: 6px;
  background: var(--bg-3);
  border-radius: 3px;
  overflow: hidden;
}

.pay-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.2s ease;
}

/* success state */
.pay-box.success .pay-spinner {
  border: 4px solid var(--accent-2);
  border-top-color: var(--accent-2);
  animation: none;
  position: relative;
}

.pay-box.success .pay-spinner::after {
  content: '✓';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-2);
  font-size: 32px;
  font-weight: 700;
}

/* transitions.dev: reduced-motion guard */
@media (prefers-reduced-motion: reduce) {
  .modal { transition: none !important; }
  .t-tabs-pill, .t-tabs .t-tab { transition: none !important; }
}
