:root {
  --bg: #121212;
  --surface: rgba(255, 255, 255, 0.04);
  --border: rgba(255, 255, 255, 0.08);
  --text: #f5f5f5;
  --muted: rgba(255, 255, 255, 0.55);
  --accent: #7c4dff;
  --accent-soft: rgba(124, 77, 255, 0.25);
  --danger: #ff5252;
  --warn: #ffd54f;
  --radius: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

body {
  padding-bottom: env(safe-area-inset-bottom);
}

a {
  color: var(--accent);
}

#app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #1a1a1a;
  border-bottom: 1px solid var(--border);
}

#app-header h1 {
  flex: 1;
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#app-header .btn-icon {
  flex-shrink: 0;
}

#app-main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 100px;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 14px;
  line-height: 1.4;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.card-row {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.cover {
  width: 64px;
  height: 84px;
  border-radius: 14px;
  background: linear-gradient(135deg, #5e35b1, #ab47bc);
  display: grid;
  place-items: center;
  font-size: 1.6rem;
  flex-shrink: 0;
}

.card-body {
  flex: 1;
  min-width: 0;
}

.card-title {
  margin: 0 0 6px;
  font-size: 1.2rem;
  line-height: 1.25;
}

.card-meta {
  color: rgba(255, 255, 255, 0.7);
  margin: 0 0 10px;
}

.progress-tag {
  color: var(--warn);
  font-size: 0.82rem;
  margin-bottom: 10px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent-soft);
  color: #fff;
}

.btn-filled {
  background: var(--accent);
  color: #fff;
}

.btn-outline {
  background: transparent;
  color: #fff;
  border: 1px solid var(--border);
}

.btn-danger {
  color: var(--danger);
  background: rgba(255, 82, 82, 0.12);
}

.btn-icon {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 12px;
  background: transparent;
  border: 1px solid var(--border);
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
}

.fab {
  position: fixed;
  right: 20px;
  bottom: 24px;
  z-index: 30;
  border: none;
  border-radius: 999px;
  padding: 14px 20px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

.empty {
  text-align: center;
  padding: 48px 24px;
}

.empty h2 {
  margin: 16px 0 8px;
}

.empty p {
  color: var(--muted);
  margin-bottom: 24px;
}

.list-item {
  cursor: pointer;
  transition: border-color 0.2s;
}

.list-item.actions-open {
  border-color: rgba(124, 77, 255, 0.5);
}

.list-item .num {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5e35b1, #ab47bc);
  display: grid;
  place-items: center;
  font-weight: 700;
  flex-shrink: 0;
}

.chapter-actions {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.chapter-actions.visible {
  display: flex;
}

.frase-item {
  padding: 14px;
  margin-bottom: 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.frase-item.active {
  background: rgba(33, 150, 243, 0.18);
  border-color: rgba(33, 150, 243, 0.35);
}

.frase-item p {
  margin: 0 0 10px;
  font-size: 1.05rem;
  line-height: 1.45;
}

.frase-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Lector */
.lector-modo {
  background: rgba(0, 0, 0, 0.35);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.lector-frase-grande {
  font-size: 1.55rem;
  line-height: 1.4;
  text-align: center;
  padding: 20px 8px;
  min-height: 180px;
}

.lector-controls {
  position: sticky;
  bottom: 0;
  background: #161616;
  border-top: 1px solid var(--border);
  padding: 12px 16px 20px;
  margin: 0 -16px -100px;
}

.lector-controls.modo-manejo .btn-play {
  width: 72px;
  height: 72px;
  font-size: 2rem;
  border-radius: 50%;
}

.control-row {
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  gap: 8px;
}

.slider-row {
  margin-bottom: 8px;
}

.slider-row label {
  font-size: 0.85rem;
  color: var(--muted);
}

.slider-row-compact {
  margin-bottom: 4px;
}

.slider-row-compact label {
  font-size: 0.8rem;
}

input[type="range"] {
  width: 100%;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.switch-row input {
  width: 20px;
  height: 20px;
}

.bluetooth-hint {
  display: flex;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 12px;
}

.loading {
  text-align: center;
  padding: 40px;
  color: var(--muted);
}

.error-box {
  background: rgba(183, 28, 28, 0.2);
  border: 1px solid rgba(255, 82, 82, 0.4);
  padding: 16px;
  border-radius: var(--radius);
  margin: 16px 0;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal {
  width: 100%;
  max-width: 420px;
  background: #1e1e1e;
  border-radius: 20px;
  padding: 20px;
  border: 1px solid var(--border);
}

.modal h2 {
  margin: 0 0 16px;
  font-size: 1.2rem;
}

.modal label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.modal input,
.modal textarea,
.modal select {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #2a2a2a;
  color: #fff;
  font-family: inherit;
  margin-bottom: 14px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  background: #323232;
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  z-index: 200;
  max-width: 90vw;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.toast.error {
  background: #b71c1c;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 90;
  background: #1e1e1e;
  border-radius: 20px 20px 0 0;
  padding: 8px 0 24px;
  border-top: 1px solid var(--border);
}

.sheet button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 16px 20px;
  border: none;
  background: none;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
}

.sheet button:hover {
  background: rgba(255, 255, 255, 0.05);
}

.hidden {
  display: none !important;
}
