/* =========================================
   Reset & Tipografia
   ========================================= */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

/* =========================================
   Paletas de Cores Profissionais (Eye-friendly)
   ========================================= */
:root {
  /* MODO CLARO (Padrão) */
  --bg-body: #e2e8f0;
  --bg-calc: #ffffff;
  --bg-display: #ffffff;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  
  /* Botões: Números */
  --btn-num: #f1f5f9;
  --btn-num-text: #0f172a;
  
  /* Botões: Funções (sin, cos, etc) */
  --btn-func: #e0f2fe;
  --btn-func-text: #0369a1;
  
  /* Botões: Operadores (+, -, *, /) */
  --btn-op: #dbeafe;
  --btn-op-text: #1d4ed8;
  
  /* Botões: Perigo (AC, DEL) - Suave, não gritante */
  --btn-danger: #fee2e2;
  --btn-danger-text: #b91c1c;
  
  /* Botão: Igual */
  --btn-equals: #3b82f6;
  --btn-equals-text: #ffffff;
  
  --shadow-calc: 0 20px 40px rgba(0, 0, 0, 0.08);
  --border-display: 1px solid #f1f5f9;
}

body.dark-mode {
  /* MODO ESCURO (Descanso visual) */
  --bg-body: #0f172a;
  --bg-calc: #1e293b;
  --bg-display: #1e293b;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  
  --btn-num: #334155;
  --btn-num-text: #f8fafc;
  
  --btn-func: #0f172a;
  --btn-func-text: #38bdf8;
  
  --btn-op: #1e3a8a;
  --btn-op-text: #bfdbfe;
  
  --btn-danger: #450a0a; /* Fundo vermelho ultra escuro */
  --btn-danger-text: #fca5a5; /* Texto rosa suave */
  
  --btn-equals: #2563eb;
  --btn-equals-text: #ffffff;
  
  --shadow-calc: 0 20px 40px rgba(0, 0, 0, 0.4);
  --border-display: 1px solid #334155;
}

body {
  background-color: var(--bg-body);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  transition: background-color 0.3s ease;
}

/* =========================================
   Calculadora Layout
   ========================================= */
.calc-container {
  background-color: var(--bg-calc);
  width: 100%;
  max-width: 360px;
  border-radius: 28px;
  padding: 24px;
  box-shadow: var(--shadow-calc);
  position: relative;
  z-index: 10;
  transition: all 0.3s ease;
}

/* HUD / Header */
.calc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.header-left {
  display: flex;
  gap: 8px;
}

.calc-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
}

.icon-btn {
  background: transparent;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text-main);
  padding: 8px;
  border-radius: 50%;
  transition: background 0.2s, transform 0.1s;
}

.icon-btn:hover { background: rgba(128, 128, 128, 0.15); }
.icon-btn:active { transform: scale(0.9); }

/* Ativa visualmente o botão quando modo científico está ligado */
.sci-active {
  background: rgba(56, 189, 248, 0.2) !important;
}

/* =========================================
   Display
   ========================================= */
.calc-display {
  background-color: var(--bg-display);
  border-bottom: var(--border-display);
  padding: 10px 10px 24px;
  text-align: right;
  margin-bottom: 24px;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.expression {
  font-size: 1.1rem;
  color: var(--text-muted);
  min-height: 24px;
  margin-bottom: 4px;
  word-wrap: break-word;
}

.result {
  font-size: 3rem;
  font-weight: 300;
  color: var(--text-main);
  word-wrap: break-word;
  line-height: 1;
  letter-spacing: -1px;
}

/* =========================================
   Teclado (Grid)
   ========================================= */
.calc-keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.calc-btn {
  border: none;
  border-radius: 16px;
  padding: 18px 10px;
  font-size: 1.2rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.1s, filter 0.2s;
}

.calc-btn:active { transform: scale(0.92); }
.calc-btn:hover { filter: brightness(0.95); }

/* Classes das cores dos botões */
.num-btn { background-color: var(--btn-num); color: var(--btn-num-text); }
.func-btn { background-color: var(--btn-func); color: var(--btn-func-text); font-size: 1.05rem; }
.op-btn { background-color: var(--btn-op); color: var(--btn-op-text); font-size: 1.4rem; }
.danger-btn { background-color: var(--btn-danger); color: var(--btn-danger-text); font-weight: 600; }
.equals-btn { background-color: var(--btn-equals); color: var(--btn-equals-text); font-size: 1.4rem; }

/* Botão 0 ocupando duas colunas */
.span-2 {
  grid-column: span 2;
  border-radius: 16px;
  text-align: left;
  padding-left: 24px;
}

/* =========================================
   Modo Científico (Lógica de Toggle Visual)
   ========================================= */
.sci-btn {
  display: none; /* Escondido por padrão */
}

/* Quando a classe 'scientific-mode' é adicionada via JS */
.scientific-mode .sci-btn {
  display: block; /* Entra no grid automaticamente */
}

/* =========================================
   Painel de Histórico Lateral
   ========================================= */
#history-panel {
  position: fixed;
  top: 0;
  right: -350px;
  width: 300px;
  height: 100%;
  background-color: var(--bg-calc);
  box-shadow: -10px 0 40px rgba(0,0,0,0.15);
  padding: 24px;
  display: flex;
  flex-direction: column;
  transition: right 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 100;
}

#history-panel.visible { right: 0; }

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  color: var(--text-main);
  border-bottom: var(--border-display);
  padding-bottom: 12px;
}

#history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 8px;
}

/* Custom scrollbar */
#history-list::-webkit-scrollbar { width: 6px; }
#history-list::-webkit-scrollbar-track { background: transparent; }
#history-list::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 4px; }

.history-item {
  padding: 14px;
  background-color: var(--btn-num);
  border-radius: 12px;
  color: var(--text-main);
  font-weight: 500;
  font-family: monospace;
  font-size: 1rem;
}

#clear-history-btn {
  margin-top: 20px;
  padding: 14px;
  background-color: var(--btn-danger);
  color: var(--btn-danger-text);
  border: none;
  border-radius: 12px;
  font-weight: bold;
  cursor: pointer;
  transition: 0.2s;
}

#clear-history-btn:hover { filter: brightness(0.9); }