:root {
  --ink: #1B1815;
  --ink-soft: #262220;
  --paper: #EDE6D6;
  --paper-dim: #C9BFA8;
  --brass: #C9A227;
  --brass-soft: #8f7420;
  --teal: #2F6F63;
  --danger: #A6432F;
  --radius: 14px;
  --font-display: "Fraunces", serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  background:
    radial-gradient(1200px 400px at 50% -10%, rgba(201,162,39,0.08), transparent 60%),
    var(--ink);
}

.view { display: none; flex: 1; flex-direction: column; min-height: 0; }
.view-active { display: flex; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 12px;
  gap: 12px;
}

.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: 0.5px;
  margin: 0;
  color: var(--paper);
}
.brand-dot { color: var(--brass); }

.icon-btn {
  background: var(--ink-soft);
  border: 1px solid rgba(201,162,39,0.25);
  color: var(--paper);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

/* ---------- Biblioteca ---------- */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 40px;
  gap: 6px;
}

.waveform-mark {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  height: 42px;
  margin-bottom: 18px;
}
.waveform-mark span {
  width: 6px;
  border-radius: 3px;
  background: var(--brass);
  animation: sway 1.8s ease-in-out infinite;
}
.waveform-mark span:nth-child(1){ height: 14px; animation-delay: 0s;}
.waveform-mark span:nth-child(2){ height: 30px; animation-delay: .15s; background: var(--teal);}
.waveform-mark span:nth-child(3){ height: 42px; animation-delay: .3s;}
.waveform-mark span:nth-child(4){ height: 24px; animation-delay: .45s; background: var(--teal);}
.waveform-mark span:nth-child(5){ height: 12px; animation-delay: .6s;}
@keyframes sway { 0%,100% { transform: scaleY(0.7);} 50% { transform: scaleY(1);} }
@media (prefers-reduced-motion: reduce) { .waveform-mark span { animation: none; } }

.empty-title { font-family: var(--font-display); font-size: 19px; margin: 0; color: var(--paper); }
.empty-sub { color: var(--paper-dim); font-size: 14px; margin: 0; max-width: 30ch; }

.library-list { list-style: none; margin: 0; padding: 8px 16px 100px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }

.book-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--ink-soft);
  border: 1px solid rgba(201,162,39,0.15);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
}
.book-spine {
  width: 6px;
  align-self: stretch;
  border-radius: 3px;
  background: var(--brass);
  flex-shrink: 0;
}
.book-info { flex: 1; min-width: 0; }
.book-title { font-family: var(--font-display); font-weight: 600; font-size: 16px; margin: 0 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-meta { font-family: var(--font-mono); font-size: 12px; color: var(--paper-dim); display: flex; gap: 8px; align-items: center; }
.book-fmt { text-transform: uppercase; letter-spacing: 0.5px; color: var(--teal); }
.book-progress { height: 3px; background: rgba(201,191,168,0.2); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.book-progress > div { height: 100%; background: var(--brass); }
.book-delete { background: none; border: none; color: var(--paper-dim); font-size: 18px; padding: 6px; cursor: pointer; }

.fab {
  position: absolute;
  right: 20px;
  bottom: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--brass);
  color: var(--ink);
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0,0,0,0.4);
}

.import-progress { position: absolute; left: 20px; right: 20px; bottom: 24px; background: var(--ink-soft); border: 1px solid rgba(201,162,39,0.25); border-radius: var(--radius); padding: 12px 14px; }
.import-progress-bar { height: 4px; background: rgba(201,191,168,0.2); border-radius: 2px; overflow: hidden; margin-bottom: 8px; }
#import-progress-fill { height: 100%; width: 30%; background: var(--brass); animation: indet 1.2s ease-in-out infinite; }
@keyframes indet { 0% { transform: translateX(-100%);} 100% { transform: translateX(330%);} }
#import-progress-label { margin: 0; font-size: 13px; color: var(--paper-dim); }

/* ---------- Lector ---------- */
.reader-title { font-family: var(--font-display); font-size: 17px; margin: 0; text-align: center; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 8px; }
.reader-body { flex: 1; overflow-y: auto; padding: 8px 22px 20px; }
.reader-text { font-family: var(--font-display); font-size: 19px; line-height: 1.65; color: var(--paper-dim); white-space: pre-wrap; }
.reader-text .chunk { padding: 2px 0; }
.reader-text .chunk.is-current { color: var(--paper); background: rgba(201,162,39,0.12); border-radius: 4px; }

.player { padding: 10px 20px calc(18px + env(safe-area-inset-bottom)); border-top: 1px solid rgba(201,162,39,0.15); background: var(--ink-soft); }
.player-progress input[type="range"] { width: 100%; }
.player-time { display: flex; justify-content: center; font-family: var(--font-mono); font-size: 12px; color: var(--paper-dim); margin-top: 2px; }
.player-controls { display: flex; align-items: center; justify-content: center; gap: 22px; margin: 10px 0 6px; }
.ctrl-btn { background: none; border: none; color: var(--paper); font-size: 14px; font-family: var(--font-mono); cursor: pointer; }
.ctrl-main { width: 58px; height: 58px; border-radius: 50%; background: var(--brass); color: var(--ink); font-size: 22px; display: flex; align-items: center; justify-content: center; }
.player-meta { display: flex; justify-content: center; align-items: center; gap: 14px; }
.badge { font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--teal); border: 1px solid var(--teal); border-radius: 20px; padding: 3px 10px; }
.link-btn { background: none; border: none; color: var(--brass); font-family: var(--font-mono); font-size: 12px; cursor: pointer; text-decoration: underline; }

/* ---------- Panel de ajustes (bottom sheet) ---------- */
.sheet-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.55); display: flex; align-items: flex-end; z-index: 40; }
.sheet { width: 100%; max-width: 560px; margin: 0 auto; background: var(--ink-soft); border-radius: 20px 20px 0 0; padding: 10px 22px calc(22px + env(safe-area-inset-bottom)); max-height: 88vh; overflow-y: auto; }
.sheet-handle { width: 40px; height: 4px; background: var(--paper-dim); border-radius: 2px; margin: 6px auto 14px; opacity: 0.5; }
.sheet-title { font-family: var(--font-display); margin: 0 0 14px; font-size: 20px; }

.field-group { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.field-label { font-size: 13px; color: var(--paper-dim); }
.field-hint { font-size: 11px; color: var(--paper-dim); margin: -4px 0 0; }

.segmented { display: flex; background: var(--ink); border-radius: 10px; padding: 3px; }
.segmented-btn { flex: 1; background: none; border: none; color: var(--paper-dim); padding: 9px; border-radius: 8px; font-size: 13px; cursor: pointer; }
.segmented-btn.is-active { background: var(--brass); color: var(--ink); font-weight: 600; }

select, input[type="password"], input[type="text"] {
  background: var(--ink);
  border: 1px solid rgba(201,162,39,0.3);
  color: var(--paper);
  padding: 10px 12px;
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 14px;
}
input[type="range"] { accent-color: var(--brass); width: 100%; }

.btn-primary { width: 100%; background: var(--brass); color: var(--ink); border: none; padding: 14px; border-radius: 10px; font-weight: 600; font-size: 15px; cursor: pointer; }

.toast { position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%); background: var(--ink-soft); border: 1px solid var(--brass); color: var(--paper); padding: 10px 18px; border-radius: 30px; font-size: 13px; z-index: 60; max-width: 85%; text-align: center; }
