/* ============================================================
   Audiobook Player — styles.css
   Mobile-first, optimized for iPhone Safari
   ============================================================ */

/* ---- Reset & base ---- */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg:            #0f0f11;
  --color-surface:       #1a1a1f;
  --color-surface-2:     #222228;
  --color-border:        #2a2a33;
  --color-text:          #e8e8f0;
  --color-text-muted:    #8888a0;
  --color-accent:        #4fc3f7;     /* current-word highlight: teal-blue */
  --color-accent-bg:     rgba(79, 195, 247, 0.18);
  --color-amber:         #f5a623;     /* saved highlight: warm amber */
  --color-amber-bg:      rgba(245, 166, 35, 0.18);
  --color-select-bg:     rgba(124, 106, 245, 0.2);

  --header-height:       56px;
  --chapter-bar-height:  36px;
  --controls-height:     104px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-reading: Georgia, "Times New Roman", serif;

  --transition: 160ms ease;
  --drawer-width: min(280px, 80vw);
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  height: 100%;
}

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  height: 100%;
  overflow: hidden;
  /* Safe area insets for iPhone notch / home indicator */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---- Loading overlay ---- */

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: var(--color-bg);
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

/* ---- Error overlay ---- */

.error-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: var(--color-bg);
}

.error-content {
  text-align: center;
  max-width: 360px;
}

.error-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
}

.error-message {
  color: var(--color-text-muted);
  line-height: 1.5;
}

/* ---- Player layout (fixed full-screen) ---- */

.player-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  position: fixed;
  inset: 0;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---- Header ---- */

.player-header {
  height: var(--header-height);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 0 0.5rem;
  gap: 0.5rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
}

.book-title {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: -0.01em;
}

/* ---- Chapter title bar ---- */

.chapter-title-bar {
  height: var(--chapter-bar-height);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 0 1rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.chapter-title-text {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ---- Text area ---- */

.text-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1.5rem 1.25rem 2rem;
  /* Prevent rubber-band bounce from interfering with scroll sync */
  overscroll-behavior: contain;
}

.text-para {
  font-family: var(--font-reading);
  font-size: 1.15rem;
  line-height: 1.9;
  color: var(--color-text);
  margin-bottom: 1.4rem;
  /* Allow word-level wrapping */
  word-break: break-word;
  hyphens: auto;
}

/* Wider screens: slightly larger type */
@media (min-width: 600px) {
  .text-para {
    font-size: 1.2rem;
  }
  .text-area {
    max-width: 680px;
    margin: 0 auto;
    padding: 2rem 2rem 3rem;
  }
}

.word {
  cursor: pointer;
  border-radius: 3px;
  transition: background var(--transition);
  /* Prevent iOS long-press text selection when tapping to highlight */
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.word:hover {
  background: var(--color-surface-2);
}

/* Currently spoken word */
.word.current-word {
  background: var(--color-accent-bg);
  color: var(--color-accent);
  border-radius: 3px;
}

/* Selection in progress */
.word.selecting {
  background: var(--color-select-bg);
  border-radius: 2px;
}

/* Saved highlight */
.word.saved-highlight {
  background: var(--color-amber-bg);
  color: var(--color-amber);
  border-radius: 3px;
  cursor: pointer;
}

.no-text {
  color: var(--color-text-muted);
  font-style: italic;
}

/* ---- Save highlight bar (floating above controls) ---- */

.save-highlight-bar {
  position: fixed;
  bottom: calc(var(--controls-height) + 0.75rem + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.5rem;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 100px;
  padding: 0.4rem 0.75rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  z-index: 50;
  white-space: nowrap;
}

/* ---- Controls bar ---- */

.controls-bar {
  flex-shrink: 0;
  height: var(--controls-height);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  padding: 0.4rem 0.75rem 0.25rem;
  gap: 0.25rem;
}

.controls-top {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.controls-scrubber {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ---- Icon buttons ---- */

.icon-btn {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 1.15rem;
  /* 44pt minimum touch target for iOS */
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  cursor: pointer;
  flex-shrink: 0;
  transition: color var(--transition), background var(--transition);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.icon-btn:hover,
.icon-btn:active {
  color: var(--color-text);
  background: var(--color-surface-2);
}

.control-btn {
  font-size: 1.05rem;
}

.control-btn--play {
  font-size: 1.4rem;
  width: 52px;
  height: 52px;
  background: var(--color-accent);
  color: #000;
  border-radius: 50%;
  flex-shrink: 0;
}
.control-btn--play:hover {
  background: var(--color-accent);
  opacity: 0.85;
  color: #000;
}

/* ---- Speed buttons ---- */

.speed-controls {
  display: flex;
  gap: 0.25rem;
  margin-left: auto;
}

.speed-btn {
  background: none;
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  /* Minimum 44pt tall touch target */
  min-height: 44px;
  padding: 0 0.5rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.speed-btn:hover {
  color: var(--color-text);
  border-color: var(--color-text-muted);
}

.speed-btn--active {
  background: var(--color-accent);
  color: #000;
  border-color: var(--color-accent);
}

/* ---- Scrubber / range input ---- */

.scrubber {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  cursor: pointer;
  outline: none;
}

.scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-accent);
  cursor: pointer;
  box-shadow: 0 0 0 3px rgba(79, 195, 247, 0.25);
}

.scrubber::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-accent);
  cursor: pointer;
  border: none;
}

.time-display {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 36px;
  flex-shrink: 0;
}
#time-total {
  text-align: right;
}

/* ---- Drawer overlay ---- */

.drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.55);
}

/* ---- Chapter drawer ---- */

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--drawer-width);
  z-index: 100;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  overflow: hidden;
  animation: slideInLeft 0.2s ease;
}

@keyframes slideInLeft {
  from { transform: translateX(-100%); }
  to   { transform: translateX(0); }
}

/* ---- Highlights panel ---- */

.highlights-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--drawer-width);
  z-index: 100;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  overflow: hidden;
  animation: slideInRight 0.2s ease;
}

@keyframes slideInRight {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

/* ---- Shared drawer header ---- */

.drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.drawer__title {
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-text-muted);
}

/* ---- Chapter list ---- */

.chapter-list {
  list-style: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  padding: 0.5rem 0;
}

.chapter-item {
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  color: var(--color-text);
  cursor: pointer;
  line-height: 1.4;
  transition: background var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.chapter-item:hover,
.chapter-item:active {
  background: var(--color-surface-2);
}

.chapter-item--active {
  color: var(--color-accent);
  font-weight: 600;
}

/* ---- Highlights list ---- */

.highlights-list {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  padding: 0.75rem;
}

.no-highlights {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  line-height: 1.6;
  padding: 0.5rem;
}

.highlight-item {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
}

.highlight-item__chapter {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin-bottom: 0.35rem;
}

.highlight-item__text {
  font-family: var(--font-reading);
  font-size: 0.88rem;
  color: var(--color-amber);
  background: var(--color-amber-bg);
  border-left: 3px solid var(--color-amber);
  padding: 0.4rem 0.6rem;
  border-radius: 0 4px 4px 0;
  margin: 0 0 0.5rem;
  cursor: pointer;
  line-height: 1.5;
  quotes: none;
  display: block;
}

.highlight-item__text:hover {
  opacity: 0.85;
}

.highlight-item__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.highlight-item__date {
  font-size: 0.72rem;
  color: var(--color-text-muted);
}

/* ---- Buttons (shared) ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1rem;
  border: none;
  border-radius: 100px;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity var(--transition), background var(--transition);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  white-space: nowrap;
  /* Comfortable height for thumbs */
  min-height: 44px;
}

.btn--amber {
  background: var(--color-amber);
  color: #000;
}
.btn--amber:hover { opacity: 0.9; }

.btn--ghost-light {
  background: var(--color-surface);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}
.btn--ghost-light:hover {
  color: var(--color-text);
}

.btn--ghost-sm {
  background: none;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 5px;
}
.btn--ghost-sm:hover {
  color: #e05c5c;
  border-color: #e05c5c;
}

/* ---- Focus rings ---- */

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
