/* ============================================================
   Styles -- Professional Calculator (Light Theme)
   ============================================================ */

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

/* === Body === */
body {
  font-family: var(--font-family-sans);
  min-height: 100dvh;
  min-height: 100vh; /* fallback */
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 16px;
  background: var(--color-bg);
  overflow-x: hidden;
}

body::before { display: none; }

/* === Calculator Shell === */
.calculator {
  background: var(--color-surface);
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: var(--radius-2xl);
  width: 100%;
  max-width: var(--container-max-width);
  box-shadow: var(--shadow-calc);
  position: relative;
  margin: auto 0;
  animation: calc-appear 0.5s ease both;
}

@keyframes calc-appear {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
}

/* Thin top highlight */
.calculator::before {
  content: '';
  position: absolute;
  top: 0;
  left: 8%;
  right: 8%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.7), transparent);
  z-index: 2;
  border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
}

/* === Display (LCD Screen) === */
.display {
  background: var(--color-display);
  padding: 18px 16px 12px;
  margin: var(--calc-padding) var(--calc-padding) 6px;
  border-radius: var(--radius-md);
  position: relative;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.15);
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.display::after { display: none; }

.display__expression {
  color: var(--color-text-muted);
  font-family: var(--font-family-mono);
  font-size: clamp(0.8rem, 2.5vw, 0.95rem);
  font-weight: var(--font-weight-normal);
  line-height: var(--line-height-normal);
  min-height: 1.4em;
  overflow-x: auto;
  white-space: nowrap;
  text-align: right;
  scrollbar-width: none;
  -ms-overflow-style: none;
  letter-spacing: 0.02em;
}

.display__expression::-webkit-scrollbar { display: none; }

.display__result {
  color: var(--color-text-result);
  font-family: var(--font-family-mono);
  font-size: clamp(1.75rem, 5.5vw, 2.5rem);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-height: 1.15em;
  word-break: break-all;
  transition: color var(--transition-fast);
  letter-spacing: -0.02em;
}

.display--error .display__result {
  color: var(--color-text-error);
}

/* Memory indicator */
.memory-indicator {
  position: absolute;
  top: 10px;
  right: 54px;
  color: var(--color-text-muted);
  font-family: var(--font-family-mono);
  font-size: 0.6rem;
  font-weight: var(--font-weight-semibold);
  padding: 2px 6px;
  border-radius: var(--radius-full);
  background: rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(0, 0, 0, 0.08);
  letter-spacing: 0.06em;
  user-select: none;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.memory-indicator.visible {
  opacity: 1;
}

/* Mode badge */
.mode-badge {
  position: absolute;
  top: 10px;
  right: 14px;
  background: rgba(0, 0, 0, 0.08);
  color: var(--color-text-muted);
  font-family: var(--font-family-mono);
  font-size: 0.6rem;
  font-weight: var(--font-weight-semibold);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  letter-spacing: 0.08em;
  user-select: none;
  border: 1px solid rgba(0, 0, 0, 0.1);
  text-transform: uppercase;
}

/* === Button Base === */
button {
  outline: none;
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-bottom-color: rgba(0, 0, 0, 0.09);
  border-radius: var(--radius-lg);
  padding: var(--padding-btn);
  font-family: var(--font-family-sans);
  font-size: 1rem;
  font-weight: var(--font-weight-medium);
  color: var(--color-text-primary);
  cursor: pointer;
  transition:
    background var(--transition-fast),
    transform var(--transition-fast),
    box-shadow var(--transition-fast);
  user-select: none;
  min-height: var(--min-touch-target);
  min-width: var(--min-touch-target);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-btn);
}

/* Subtle top sheen */
button::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 45%;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.35), transparent);
  pointer-events: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

/* === Button Variants === */
.btn-number {
  background: var(--color-btn-number);
  font-weight: var(--font-weight-semibold);
  font-size: 1.1rem;
}

.btn-operator {
  background: var(--color-btn-operator);
  color: #fff;
  font-size: 1.25rem;
  font-weight: var(--font-weight-bold);
  border-color: rgba(255, 255, 255, 0.2);
  border-bottom-color: rgba(0, 0, 0, 0.12);
}

.btn-function {
  background: var(--color-btn-function);
  font-size: 0.73rem;
  font-weight: var(--font-weight-medium);
  color: var(--color-neutral-700);
  border-color: rgba(255, 255, 255, 0.3);
  border-bottom-color: rgba(0, 0, 0, 0.06);
}

.btn-equals {
  background: var(--color-btn-equals-flat);
  background-image: var(--color-btn-equals);
  font-size: 1.25rem;
  font-weight: var(--font-weight-bold);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.15);
  border-bottom-color: rgba(0, 0, 0, 0.12);
}

.btn-clear {
  background: var(--color-btn-clear);
  color: #fff;
  font-weight: var(--font-weight-bold);
  border-color: rgba(255, 255, 255, 0.15);
  border-bottom-color: rgba(0, 0, 0, 0.12);
}

/* Active operator highlight */
.btn-operator.active {
  outline: 2px solid var(--color-accent-light);
  outline-offset: -2px;
  box-shadow: 0 0 12px rgba(245, 166, 35, 0.3);
}

/* === Parentheses Counter === */
.paren-counter {
  position: absolute;
  top: 10px;
  left: 14px;
  color: var(--color-text-muted);
  font-family: var(--font-family-mono);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  opacity: 0;
  transition: opacity var(--transition-fast);
  user-select: none;
}

.paren-counter.visible { opacity: 1; }

/* === Copy Toast === */
.display__result {
  cursor: pointer;
  position: relative;
}

.copy-toast {
  position: absolute;
  bottom: 100%;
  right: 0;
  background: var(--color-neutral-800);
  color: #fff;
  font-size: var(--font-size-xs);
  font-family: var(--font-family-sans);
  padding: 4px 12px;
  border-radius: var(--radius-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  white-space: nowrap;
  z-index: 5;
}

.copy-toast.show { opacity: 1; }

/* === Help Button === */
.help-btn {
  position: absolute;
  top: 10px;
  left: 14px;
  background: transparent;
  border: 1px solid rgba(0, 0, 0, 0.15) !important;
  color: var(--color-text-muted);
  width: 24px;
  height: 24px;
  min-height: 24px;
  min-width: 24px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: var(--font-weight-bold);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity var(--transition-fast);
  z-index: 2;
  box-shadow: none;
}

.help-btn::before { display: none; }

.help-btn:hover {
  opacity: 1;
  border-color: rgba(0, 0, 0, 0.3) !important;
  color: #2a3a28;
  transform: none;
  box-shadow: none;
}

/* === Help Modal === */
.help-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 100;
  justify-content: center;
  align-items: center;
  padding: var(--space-4);
}

.help-overlay.open { display: flex; }

.help-modal {
  background: #fff;
  border-radius: var(--radius-xl);
  padding: 20px 24px;
  max-width: 400px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  color: var(--color-text-primary);
  font-family: var(--font-family-sans);
  font-size: var(--font-size-sm);
  line-height: 1.5;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
}

.help-modal h2 {
  font-size: 1.05rem;
  margin-bottom: var(--space-3);
  font-weight: var(--font-weight-semibold);
  color: var(--color-neutral-900);
}

.help-modal h3 {
  font-size: 0.82rem;
  margin-top: var(--space-3);
  margin-bottom: var(--space-2);
  color: var(--color-primary);
  font-weight: var(--font-weight-semibold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.help-modal table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: var(--space-2);
}

.help-modal th,
.help-modal td {
  text-align: left;
  padding: 4px 8px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.help-modal th {
  color: var(--color-neutral-500);
  font-weight: var(--font-weight-medium);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.help-tip {
  margin-top: 8px;
  color: var(--color-neutral-500);
  font-size: 0.75rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.help-modal .close-help {
  display: block;
  margin: 12px auto 0;
  background: var(--color-neutral-100);
  color: var(--color-text-primary);
  border: 1px solid rgba(0, 0, 0, 0.08) !important;
  border-radius: var(--radius-md);
  padding: 8px 24px;
  cursor: pointer;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  box-shadow: none;
}

.help-modal .close-help:hover {
  background: var(--color-neutral-200);
  transform: none;
  box-shadow: none;
}

/* === History Panel === */
.history-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 100;
  justify-content: center;
  align-items: center;
  padding: var(--space-4);
}

.history-overlay.open { display: flex; }

.history-modal {
  background: #fff;
  border-radius: var(--radius-xl);
  padding: 20px 24px;
  max-width: 400px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  color: var(--color-text-primary);
  font-family: var(--font-family-sans);
  font-size: var(--font-size-sm);
  line-height: 1.5;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
}

.history-modal h2 {
  font-size: 1.05rem;
  margin-bottom: var(--space-3);
  font-weight: var(--font-weight-semibold);
  color: var(--color-neutral-900);
}

.history-list {
  max-height: 50vh;
  overflow-y: auto;
}

.history-empty {
  color: var(--color-neutral-400);
  text-align: center;
  padding: var(--space-6) 0;
  font-size: var(--font-size-sm);
}

.history-entry {
  display: flex;
  flex-direction: column;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.history-entry:hover {
  background: var(--color-neutral-100);
}

.history-entry__expr {
  font-family: var(--font-family-mono);
  font-size: 0.75rem;
  color: var(--color-neutral-500);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-entry__result {
  font-family: var(--font-family-mono);
  font-size: 1rem;
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
}

.history-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: 12px;
  justify-content: center;
}

.history-actions button {
  background: var(--color-neutral-100);
  color: var(--color-text-primary);
  border: 1px solid rgba(0, 0, 0, 0.08) !important;
  border-radius: var(--radius-md);
  padding: 8px 20px;
  cursor: pointer;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  box-shadow: none;
}

.history-actions button:hover {
  background: var(--color-neutral-200);
  transform: none;
  box-shadow: none;
}

.clear-history {
  color: var(--color-error) !important;
}

/* === Shortcut Hint === */
.shortcut-hint-btn {
  position: absolute;
  bottom: var(--space-2);
  left: var(--space-3);
  background: transparent;
  border: 1px solid var(--color-text-muted);
  color: var(--color-text-muted);
  width: 22px;
  height: 22px;
  min-height: 22px;
  min-width: 22px;
  border-radius: 50%;
  font-size: 11px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity var(--transition-fast);
  box-shadow: none;
}

.shortcut-hint-btn::before { display: none; }
.shortcut-hint-btn:hover { opacity: 1; transform: none; box-shadow: none; }

/* === Hover / Active States === */
button:hover {
  background-image: linear-gradient(var(--color-hover), var(--color-hover));
  transform: translateY(-1px);
  box-shadow: var(--shadow-btn-hover);
}

button:active {
  background-image: linear-gradient(var(--color-active), var(--color-active));
  transform: translateY(1px);
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.06);
  transition-duration: 40ms;
}

.btn-equals:hover {
  box-shadow: var(--shadow-btn-hover), 0 4px 14px rgba(51, 129, 245, 0.25);
}

.btn-operator:hover {
  box-shadow: var(--shadow-btn-hover), 0 4px 14px rgba(245, 166, 35, 0.25);
}

button:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
}

/* === Grid Layouts === */
.keypad-scientific {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--gap);
  padding: 6px var(--calc-padding) 2px;
}

.keypad-memory {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
  padding: 4px var(--calc-padding);
  margin: 2px 0;
  background: rgba(0, 0, 0, 0.02);
  border-top: 1px solid rgba(0, 0, 0, 0.04);
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.btn-memory {
  background: var(--color-neutral-200);
  font-size: 0.7rem;
  font-weight: var(--font-weight-semibold);
  color: var(--color-neutral-600);
  border-color: rgba(0, 0, 0, 0.04);
  border-bottom-color: rgba(0, 0, 0, 0.06);
  min-height: 36px;
  padding: 6px;
}

.btn-memory::before {
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.2), transparent);
}

.keypad-basic {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
  padding: 2px var(--calc-padding) var(--calc-padding);
}

/* === Responsive === */
@media (min-width: 768px) {
  :root { --gap: 6px; }

  body { align-items: center; }

  .btn-function { font-size: 0.78rem; }
  .keypad-memory { gap: 6px; }
}

@media (min-width: 1024px) {
  :root { --gap: 7px; }

  button { padding: 14px; }
  .btn-function { font-size: var(--font-size-sm); }
  .keypad-memory { gap: 7px; }
  .btn-memory { padding: 8px; }
}

/* === Ripple === */
@keyframes ripple {
  to { transform: scale(4); opacity: 0; }
}

.btn-ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.08);
  width: 20px;
  height: 20px;
  transform: scale(0);
  animation: ripple 0.45s ease-out;
  pointer-events: none;
}

/* === Result Pop === */
@keyframes result-pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.02); }
  100% { transform: scale(1); }
}

.display__result.pop {
  animation: result-pop 0.2s ease-out;
}
