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

:root {
  --bg:        #1a1a2e;
  --surface:   #16213e;
  --surface2:  #0f3460;
  --accent:    #e94560;
  --accent2:   #533483;
  --text:      #eaeaea;
  --text-dim:  #8a8aaa;
  --digit-bg:  #1e2a4a;
  --digit-fg:  #eaeaea;
  --op-bg:     #0f3460;
  --op-fg:     #7ec8e3;
  --fn-bg:     #1e2a4a;
  --fn-fg:     #c8a2ff;
  --eq-bg:     #e94560;
  --eq-fg:     #fff;
  --radius:    14px;
  --gap:       8px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px 12px 48px;
}

/* ===== APP CONTAINER ===== */
.app {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0,0,0,.6);
}

/* ===== ONGLETS ===== */
.tabs {
  display: flex;
  background: var(--surface2);
}
.tab {
  flex: 1;
  padding: 14px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color .2s, border-bottom .2s;
  border-bottom: 3px solid transparent;
}
.tab.active {
  color: var(--accent);
  border-bottom: 3px solid var(--accent);
}
.tab-content { display: none; padding: 16px; }
.tab-content.active { display: block; }

/* ===== AFFICHAGE ===== */
.display {
  background: #0a0a1a;
  border-radius: var(--radius);
  padding: 14px 18px 10px;
  margin-bottom: 12px;
  min-height: 90px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
}
.display-expr {
  color: var(--text-dim);
  font-size: 15px;
  min-height: 22px;
  word-break: break-all;
  text-align: right;
}
.display-result {
  font-size: 42px;
  font-weight: 300;
  color: var(--text);
  word-break: break-all;
  text-align: right;
  line-height: 1.1;
}

/* ===== MÉMOIRE ===== */
.memory-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 8px 10px;
  background: #0a0a1a;
  border-radius: var(--radius);
}
.mem-label { font-size: 11px; color: var(--text-dim); margin-right: 2px; }
.mem-slots { display: flex; gap: 5px; flex: 1; flex-wrap: wrap; }
.mem-slot {
  padding: 4px 9px;
  border-radius: 8px;
  background: var(--digit-bg);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color .15s, color .15s;
  position: relative;
}
.mem-slot.active { border-color: var(--accent); color: var(--text); }
.mem-slot.filled { color: var(--fn-fg); }
.mem-slot .mem-val {
  display: block;
  font-size: 9px;
  font-weight: 400;
  color: var(--text-dim);
  max-width: 44px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn-mem-action {
  padding: 4px 8px;
  background: var(--surface2);
  border: none;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-mem-action:hover { background: var(--accent2); color: #fff; }

/* ===== CLAVIER ===== */
.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
}
.btn {
  padding: 0;
  height: 64px;
  border: none;
  border-radius: var(--radius);
  font-size: 20px;
  font-weight: 500;
  cursor: pointer;
  transition: filter .1s, transform .08s;
  user-select: none;
  display: flex; align-items: center; justify-content: center;
}
.btn:active { filter: brightness(1.3); transform: scale(.95); }
.btn.digit  { background: var(--digit-bg); color: var(--digit-fg); }
.btn.op     { background: var(--op-bg);    color: var(--op-fg); }
.btn.fn     { background: var(--fn-bg);    color: var(--fn-fg); font-size: 16px; }
.btn.eq     { background: var(--eq-bg);    color: var(--eq-fg); font-weight: 700; }
.btn.wide   { grid-column: span 2; }

/* ===== HISTORIQUE ===== */
.history-section {
  margin-top: 14px;
  background: #0a0a1a;
  border-radius: var(--radius);
  padding: 10px 12px;
  max-height: 200px;
  display: flex;
  flex-direction: column;
}
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.history-header button {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 11px;
  cursor: pointer;
  font-weight: 600;
}
#history-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}
#history-list li {
  padding: 6px 4px;
  border-bottom: 1px solid #1a1a2e;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  transition: background .1s;
  border-radius: 6px;
}
#history-list li:hover { background: #1a1a2e; }
#history-list li .h-expr { color: var(--text-dim); }
#history-list li .h-res  { color: var(--fn-fg); font-weight: 600; }
#history-list:empty::after {
  content: 'Aucun calcul encore.';
  color: var(--text-dim);
  font-size: 12px;
  display: block;
  text-align: center;
  padding: 8px 0;
}

/* ===== CONVERTISSEUR ===== */
.conv-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}
.conv-cat {
  padding: 6px 12px;
  border: 2px solid var(--surface2);
  border-radius: 20px;
  background: none;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.conv-cat.active, .conv-cat:hover {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(233,69,96,.1);
}
.conv-form { display: flex; flex-direction: column; gap: 10px; }
.conv-row { display: flex; gap: 8px; }
.conv-row input {
  flex: 1;
  padding: 12px 14px;
  background: #0a0a1a;
  border: 2px solid var(--surface2);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 18px;
  outline: none;
  transition: border-color .15s;
}
.conv-row input:focus { border-color: var(--accent); }
.conv-row select {
  padding: 10px 10px;
  background: var(--surface2);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  min-width: 90px;
}
.conv-arrow {
  display: block;
  width: 48px;
  margin: 0 auto;
  padding: 6px 0;
  background: var(--surface2);
  border: none;
  border-radius: 50%;
  font-size: 22px;
  color: var(--text-dim);
  cursor: pointer;
  transition: color .15s, background .15s, transform .2s;
}
.conv-arrow:hover { color: var(--text); background: var(--accent2); }
.conv-arrow:active { transform: rotate(180deg); }
#btn-convert {
  padding: 14px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: .05em;
  transition: filter .15s;
}
#btn-convert:hover { filter: brightness(1.15); }
#conv-rate-info {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  min-height: 16px;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 4px; }
