:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1c2333;
  --muted: #6b7280;
  --accent: #6366f1;
  --accent-2: #06b6d4;
  --border: #e5e7eb;
  --danger: #ef4444;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1220;
    --card: #171b2e;
    --text: #e9ebf5;
    --muted: #9aa1b5;
    --border: #2a2f45;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1220;
  --card: #171b2e;
  --text: #e9ebf5;
  --muted: #9aa1b5;
  --border: #2a2f45;
}
* { box-sizing: border-box; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  margin: 0;
  padding: 32px 16px;
}
.wrap { max-width: 640px; margin: 0 auto; }
h1 {
  text-align: center;
  font-size: 1.6rem;
  margin-bottom: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.subtitle { text-align: center; color: var(--muted); margin-bottom: 24px; font-size: 0.95rem; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.05);
}
.field { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
label { flex: 1 1 220px; font-weight: 600; font-size: 0.95rem; }
input[type="text"], input[type="number"] {
  flex: 1 1 140px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color .15s;
}
input:focus { border-color: var(--accent); }
button {
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: white;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
  transition: transform .1s, opacity .15s;
}
button:hover { opacity: 0.92; }
button:active { transform: scale(0.97); }
.resultado { margin-top: 10px; font-size: 1.05rem; font-weight: 600; min-height: 1.4em; }
.error { color: var(--danger); font-weight: 500; }
.historial-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.historial-header h2 { font-size: 1.1rem; margin: 0; }
.btn-secundario {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-weight: 500;
  padding: 6px 12px;
  font-size: 0.85rem;
}
ul#lista-historial { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; }
ul#lista-historial li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}
ul#lista-historial li:last-child { border-bottom: none; }
.op-tag {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: .3px;
  color: white;
  white-space: nowrap;
}
.op-tag.bin { background: var(--accent); }
.op-tag.dec { background: var(--accent-2); }
.entrada-salida { flex: 1; overflow-wrap: anywhere; }
.hora { color: var(--muted); font-size: 0.78rem; white-space: nowrap; }
.vacio { color: var(--muted); text-align: center; padding: 12px 0; font-size: 0.9rem; }
.theme-toggle {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}
#btnTema {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.btn-top {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  cursor: pointer;
  transition: transform .1s, opacity .15s;
}

.btn-top:hover {
  opacity: 0.92;
  background: var(--bg);
}

.btn-top:active {
  transform: scale(0.97);
}