/* NEBULA CALC — CSS DESIGN SYSTEM */

/* Font & Global resets */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  transition: background-color 0.4s ease, border-color 0.4s ease, color 0.3s ease;
}

:root {
  /* Color Palette - Dark Glassmorphism (Default) */
  --bg-color: #090d16;
  --card-bg: rgba(255, 255, 255, 0.04);
  --card-border: rgba(255, 255, 255, 0.08);
  --text-color: #f8fafc;
  --text-secondary: #94a3b8;
  
  /* Buttons - Dark Theme */
  --key-bg-num: rgba(255, 255, 255, 0.05);
  --key-bg-num-hover: rgba(255, 255, 255, 0.09);
  --key-bg-sci: rgba(255, 255, 255, 0.03);
  --key-bg-sci-hover: rgba(255, 255, 255, 0.07);
  --key-bg-op: rgba(59, 130, 246, 0.12);
  --key-bg-op-hover: rgba(59, 130, 246, 0.22);
  --key-text-op: #3b82f6;
  --key-bg-special: rgba(148, 163, 184, 0.08);
  --key-bg-special-hover: rgba(148, 163, 184, 0.16);
  --key-text-special: #e2e8f0;
  --key-bg-danger: rgba(239, 68, 68, 0.12);
  --key-bg-danger-hover: rgba(239, 68, 68, 0.22);
  --key-text-danger: #ef4444;
  --key-bg-mem: rgba(255, 255, 255, 0.015);
  --key-bg-mem-hover: rgba(255, 255, 255, 0.05);
  --key-text-mem: #64748b;
  --key-bg-primary: #3b82f6;
  --key-bg-primary-hover: #2563eb;
  --key-text-primary: #f8fafc;
  
  --accent-color: #22c55e;
  --accent-glow: rgba(34, 197, 94, 0.25);
  --glass-blur: blur(18px);
  --border-radius: 22px;
  
  /* Decorative Orbs */
  --orb-1-color: rgba(59, 130, 246, 0.2);
  --orb-2-color: rgba(34, 197, 94, 0.15);
  --orb-3-color: rgba(139, 92, 246, 0.15);
  
  /* Shadows */
  --shadow-card: 0 25px 50px -12px rgba(0, 0, 0, 0.6), 
                 inset 0 1px 0 rgba(255, 255, 255, 0.1);
  --shadow-button: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Light Theme Variables */
body.light-theme {
  --bg-color: #f1f5f9;
  --card-bg: rgba(255, 255, 255, 0.35);
  --card-border: rgba(15, 23, 42, 0.08);
  --text-color: #0f172a;
  --text-secondary: #475569;
  
  /* Buttons - Light Theme */
  --key-bg-num: rgba(15, 23, 42, 0.04);
  --key-bg-num-hover: rgba(15, 23, 42, 0.08);
  --key-bg-sci: rgba(15, 23, 42, 0.02);
  --key-bg-sci-hover: rgba(15, 23, 42, 0.06);
  --key-bg-op: rgba(59, 130, 246, 0.08);
  --key-bg-op-hover: rgba(59, 130, 246, 0.16);
  --key-text-op: #2563eb;
  --key-bg-special: rgba(71, 85, 105, 0.06);
  --key-bg-special-hover: rgba(71, 85, 105, 0.12);
  --key-text-special: #1e293b;
  --key-bg-danger: rgba(220, 38, 38, 0.08);
  --key-bg-danger-hover: rgba(220, 38, 38, 0.16);
  --key-text-danger: #dc2626;
  --key-bg-mem: rgba(15, 23, 42, 0.015);
  --key-bg-mem-hover: rgba(15, 23, 42, 0.04);
  --key-text-mem: #64748b;
  --key-bg-primary: #3b82f6;
  --key-bg-primary-hover: #1d4ed8;
  --key-text-primary: #f8fafc;
  
  --accent-color: #16a34a;
  --accent-glow: rgba(22, 163, 74, 0.15);
  
  /* Decorative Orbs */
  --orb-1-color: rgba(59, 130, 246, 0.1);
  --orb-2-color: rgba(34, 197, 94, 0.08);
  --orb-3-color: rgba(139, 92, 246, 0.08);
  
  /* Shadows */
  --shadow-card: 0 25px 50px -12px rgba(15, 23, 42, 0.15), 
                 inset 0 1px 0 rgba(255, 255, 255, 0.4);
  --shadow-button: 0 4px 8px rgba(0, 0, 0, 0.05);
}

body {
  font-family: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow-x: hidden;
  position: relative;
}

/* Background floating glow orbs */
.glow-bg-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  z-index: -1;
  pointer-events: none;
  mix-blend-mode: screen;
}

body.light-theme .glow-bg-orb {
  mix-blend-mode: multiply;
  filter: blur(140px);
}

.orb-1 {
  width: 500px;
  height: 500px;
  top: -10%;
  left: -10%;
  background-color: var(--orb-1-color);
  animation: floatOrb 22s infinite alternate ease-in-out;
}

.orb-2 {
  width: 450px;
  height: 450px;
  bottom: -5%;
  right: -5%;
  background-color: var(--orb-2-color);
  animation: floatOrb 18s infinite alternate-reverse ease-in-out;
}

.orb-3 {
  width: 350px;
  height: 350px;
  top: 50%;
  left: 60%;
  transform: translate(-50%, -50%);
  background-color: var(--orb-3-color);
  animation: floatOrb 25s infinite alternate ease-in-out;
}

@keyframes floatOrb {
  0% {
    transform: translate(0, 0) scale(1);
  }
  50% {
    transform: translate(60px, -40px) scale(1.1);
  }
  100% {
    transform: translate(-40px, 80px) scale(0.95);
  }
}

/* App Layout Wrapper */
.app-container {
  display: flex;
  gap: 24px;
  align-items: stretch;
  justify-content: center;
  width: 100%;
  max-width: 1200px;
  padding: 24px;
  flex-grow: 1;
}

/* Calculator Main Body Card */
.calculator-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-card);
  width: 100%;
  max-width: 400px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: relative;
  transform: translateY(20px);
  opacity: 0;
  animation: appEntrance 0.7s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: max-width 0.45s cubic-bezier(0.25, 1, 0.5, 1), transform 0.3s ease;
}

/* Expanded layout for Scientific Mode */
.calculator-card.scientific-active {
  max-width: 760px;
}

@keyframes appEntrance {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Calculator Header controls */
.calc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-color);
  font-family: 'Space Grotesk', sans-serif;
  user-select: none;
}

.logo-accent {
  color: var(--key-text-op);
  margin-right: 2px;
}

.header-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Button Styling (Icons) */
.icon-btn {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  outline: none;
  position: relative;
  overflow: hidden;
}

body.light-theme .icon-btn {
  background: rgba(0, 0, 0, 0.02);
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-color);
  transform: translateY(-1px);
}

body.light-theme .icon-btn:hover {
  background: rgba(0, 0, 0, 0.06);
}

.icon-btn:active {
  transform: scale(0.95);
}

.icon-btn.active {
  border-color: rgba(59, 130, 246, 0.3);
  color: var(--key-text-op);
  background: rgba(59, 130, 246, 0.08);
}

.icon-btn .icon {
  width: 18px;
  height: 18px;
  pointer-events: none;
}

/* Specific Label for SCI text button */
.btn-label-text {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.hidden {
  display: none !important;
}

/* Calculator Screen display area */
.calc-screen {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.03);
  border-radius: 16px;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: right;
  min-height: 140px;
  justify-content: flex-end;
  position: relative;
  overflow: hidden;
}

body.light-theme .calc-screen {
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(0, 0, 0, 0.03);
}

/* Indicators */
.screen-indicators {
  position: absolute;
  top: 12px;
  left: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}

.screen-indicators .indicator {
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.04);
}

body.light-theme .screen-indicators .indicator {
  background: rgba(0, 0, 0, 0.05);
}

#indicator-mode {
  margin-left: auto;
  color: var(--key-text-op);
}

#indicator-memory {
  background: var(--accent-glow);
  color: var(--accent-color);
}

/* Scrollable mathematical formula expression display */
.expression-area-wrapper {
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none;  /* IE/Edge */
}

.expression-area-wrapper::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.expression-display {
  font-family: 'Space Grotesk', monospace;
  font-size: 1.15rem;
  color: var(--text-secondary);
  min-height: 28px;
  direction: ltr;
  outline: none;
  user-select: text;
  text-overflow: clip;
}

/* Big result output display */
.result-area-wrapper {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.result-display {
  font-size: 2.5rem;
  font-weight: 600;
  color: var(--text-color);
  word-wrap: break-word;
  word-break: break-all;
  flex-grow: 1;
  text-align: right;
  line-height: 1.1;
  outline: none;
  user-select: text;
  transition: font-size 0.15s ease;
}

.result-actions {
  display: flex;
  align-self: center;
}

/* Small helper copy action btn */
.action-mini-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.action-mini-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-color);
}

body.light-theme .action-mini-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

.action-mini-btn .icon {
  width: 14px;
  height: 14px;
}

/* Tooltip copy toast */
.tooltip {
  position: absolute;
  bottom: 125%;
  right: 50%;
  transform: translateX(50%);
  background: var(--key-text-op);
  color: white;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.65rem;
  font-weight: 600;
  white-space: nowrap;
  animation: tooltipFade 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes tooltipFade {
  from {
    opacity: 0;
    transform: translate(50%, 4px);
  }
  to {
    opacity: 1;
    transform: translate(50%, 0);
  }
}

/* Grid Layout Workspace */
.workspace-grid-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  transition: all 0.45s ease;
}

/* Dual mode layouts */
.keypad {
  display: grid;
  gap: 10px;
}

.scientific-grid {
  grid-template-columns: repeat(4, 1fr);
  animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.standard-grid {
  grid-template-columns: repeat(4, 1fr);
}

/* Memory Row sub layout */
.memory-row {
  grid-column: span 4;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

/* Base Keypad Buttons */
.key {
  border: 1px solid rgba(255, 255, 255, 0.03);
  border-radius: 15px;
  height: 52px;
  font-size: 1.05rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  position: relative;
  outline: none;
  background-color: var(--key-bg-num);
  color: var(--text-color);
  box-shadow: var(--shadow-button);
  transition: transform 0.1s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.key:hover {
  background-color: var(--key-bg-num-hover);
  transform: translateY(-1px);
}

.key:active {
  transform: scale(0.94);
  background-color: rgba(255, 255, 255, 0.15) !important;
}

body.light-theme .key:active {
  background-color: rgba(0, 0, 0, 0.12) !important;
}

/* Scientific keys */
.key-sci {
  background-color: var(--key-bg-sci);
  color: var(--text-secondary);
  font-size: 0.85rem;
  height: 44px;
}

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

/* Operator Keys */
.key-operator {
  background-color: var(--key-bg-op);
  color: var(--key-text-op);
  font-size: 1.25rem;
  font-weight: 600;
}

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

/* Special helper keys (AC, backspace, negate, percent) */
.key-special {
  background-color: var(--key-bg-special);
  color: var(--key-text-special);
}

.key-special:hover {
  background-color: var(--key-bg-special-hover);
}

.key-special .icon {
  width: 18px;
  height: 18px;
}

/* Memory Keys */
.key-mem {
  background-color: var(--key-bg-mem);
  color: var(--key-text-mem);
  font-size: 0.72rem;
  font-weight: 600;
  height: 34px;
  border-radius: 8px;
}

.key-mem:hover {
  background-color: var(--key-bg-mem-hover);
  color: var(--text-color);
}

/* AC / Danger Button */
.key-danger {
  background-color: var(--key-bg-danger);
  color: var(--key-text-danger);
  font-weight: 600;
}

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

/* Equal / Primary Button */
.key-primary {
  background-color: var(--key-bg-primary);
  color: var(--key-text-primary);
  font-size: 1.35rem;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.35);
}

.key-primary:hover {
  background-color: var(--key-bg-primary-hover);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.45);
}

/* Focus outline styles for keyboard navigation accessibility */
.key:focus-visible, .icon-btn:focus-visible, .action-mini-btn:focus-visible {
  outline: 2px solid var(--key-text-op);
  outline-offset: 2px;
}

/* Side History Drawer */
.history-sidebar {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-card);
  width: 100%;
  max-width: 320px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  opacity: 0;
  transform: translateX(30px);
  animation: sidebarEntrance 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: all 0.4s ease;
}

@keyframes sidebarEntrance {
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 12px;
}

body.light-theme .history-header {
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.history-header h3 {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 1.1rem;
}

.history-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.text-action-btn {
  background: transparent;
  border: none;
  color: var(--key-text-danger);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.text-action-btn:hover {
  background: var(--key-bg-danger);
}

.icon-btn-mini {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn-mini:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-color);
}

body.light-theme .icon-btn-mini:hover {
  background: rgba(0, 0, 0, 0.04);
}

.icon-btn-mini .icon {
  width: 16px;
  height: 16px;
}

/* History Scroll List */
.history-list {
  flex-grow: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 4px;
  max-height: 480px;
}

/* Scrollbar styles for history list */
.history-list::-webkit-scrollbar {
  width: 4px;
}

.history-list::-webkit-scrollbar-track {
  background: transparent;
}

.history-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}

body.light-theme .history-list::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
}

.empty-history-msg {
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-align: center;
  margin-top: 40px;
  font-style: italic;
}

/* History list row items */
.history-item {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  padding: 10px 14px;
  text-align: right;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  outline: none;
  animation: itemEntrance 0.3s ease forwards;
}

body.light-theme .history-item {
  background: rgba(0, 0, 0, 0.015);
  border: 1px solid rgba(0, 0, 0, 0.03);
}

.history-item:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.08);
}

body.light-theme .history-item:hover {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.06);
}

.history-item:focus-visible {
  outline: 2px solid var(--key-text-op);
}

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

.history-item-exp {
  font-size: 0.82rem;
  color: var(--text-secondary);
  word-break: break-all;
  font-family: 'Space Grotesk', monospace;
}

.history-item-val {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-color);
  word-break: break-all;
}

/* Footer elements */
.app-footer {
  margin-top: auto;
  padding: 24px 0 12px;
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-secondary);
  opacity: 0.7;
}

/* Sr-Only class for screen readers accessibility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Keyframe animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* -----------------------------------------------
   Responsive Breakpoints
   ----------------------------------------------- */

/* Wide Screen / Desktop */
@media (min-width: 768px) {
  /* When Scientific mode is active, the workspace grid transitions side-by-side */
  .calculator-card.scientific-active .workspace-grid-container {
    display: grid;
    grid-template-columns: 3.2fr 4fr;
  }
  
  .calculator-card.scientific-active .scientific-grid {
    grid-template-columns: repeat(4, 1fr);
    /* Bring scientific keys to the side */
  }
}

/* Medium Screen / Tablet */
@media (max-width: 900px) {
  .app-container {
    flex-direction: column;
    align-items: center;
  }
  
  .history-sidebar {
    max-width: 400px;
    height: 350px;
  }
  
  .history-list {
    max-height: 250px;
  }
}

/* Mobile Screen */
@media (max-width: 450px) {
  .app-container {
    padding: 12px;
  }
  
  .calculator-card {
    padding: 16px;
    gap: 16px;
  }
  
  .calc-screen {
    padding: 12px 16px;
    min-height: 120px;
  }
  
  .result-display {
    font-size: 2.1rem;
  }
  
  .key {
    height: 48px;
    border-radius: 12px;
    font-size: 0.98rem;
  }
  
  .key-sci {
    height: 38px;
    font-size: 0.78rem;
  }
  
  .key-mem {
    height: 30px;
    font-size: 0.68rem;
  }
  
  /* On mobile portrait with scientific mode active, they stack vertically */
  .workspace-grid-container {
    gap: 12px;
  }
  
  .scientific-grid {
    grid-template-columns: repeat(5, 1fr); /* Spans 5 columns on narrow portrait view to save vertical space! */
  }
  
  .history-sidebar {
    width: 100%;
    max-width: 100%;
  }
}
