/* CSS Variables */
:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --text-primary: #eaeaea;
  --text-secondary: #a0a0a0;
  --accent: #e94560;
  --accent-dim: #b8354d;
  --success: #4ade80;
  --btn-bg: #0f3460;
  --btn-hover: #1a4980;
  --progress-bg: #2a2a4a;
  --tick-color: rgba(255, 255, 255, 0.3);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --text-primary: #1a1a2e;
    --text-secondary: #666666;
    --accent: #e94560;
    --accent-dim: #b8354d;
    --btn-bg: #e0e0e0;
    --btn-hover: #d0d0d0;
    --progress-bg: #d0d0d0;
    --tick-color: rgba(0, 0, 0, 0.2);
  }
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

/* View container */
.view {
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

/* Landing Page */
#landing {
  position: relative;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
}

/* Info button - bottom center */
.info-btn {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: none;
  border: none;
  color: var(--text-secondary);
  opacity: 0.4;
  cursor: pointer;
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  padding: 8px 16px;
  transition: opacity 0.2s;
  z-index: 10;
}

.info-btn:hover {
  opacity: 0.8;
}

.landing-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 400px;
  height: 100%;
  padding: 0 24px;
}

/* Branding - positioned in upper area */
.branding {
  position: absolute;
  top: 18%;
  text-align: center;
}

.wordmark {
  font-size: 4.5rem;
  font-weight: 300;
  letter-spacing: -0.03em;
  margin: 0 0 10px;
  color: var(--text-primary);
}

.tagline {
  font-size: 1.4rem;
  color: var(--text-secondary);
  margin: 0;
}

/* Media card - positioned to align with RSVP */
.media-card {
  position: absolute;
  bottom: 25%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: calc(100% - 48px);
  max-width: 280px;
  padding: 14px 18px;
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s, box-shadow 0.2s;
}

.media-card:hover {
  transform: scale(1.02);
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.media-card:active {
  transform: scale(0.98);
}

.media-info {
  text-align: left;
}

.media-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 1px;
}

.media-author {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin: 0 0 4px;
}

.media-time {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin: 0;
}

.media-time .time-normal {
  text-decoration: line-through;
  opacity: 0.5;
}

.media-time .time-fast {
  color: var(--accent);
}

.media-play {
  width: 38px;
  height: 38px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
  margin-left: 12px;
}

.media-play svg {
  width: 16px;
  height: 16px;
  margin-left: 2px; /* optical centering */
}

/* Info Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
}

.modal-content {
  position: relative;
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 32px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.modal-content h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0 0 16px;
  color: var(--text-primary);
}

.modal-content p {
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text-secondary);
  margin: 0 0 12px;
}

.modal-content p:last-child {
  margin-bottom: 0;
}

.modal-content strong {
  color: var(--text-primary);
}

.modal-note {
  font-size: 0.85rem !important;
  opacity: 0.7;
  margin-top: 20px !important;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, background 0.2s;
}

.modal-close:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.1);
}

/* Reader View */
#reader {
  position: relative;
}

/* Chapter bar (in footer, at very bottom) */
.chapter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding-top: 8px;
  margin-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.chapter-bar .nav-btn {
  width: 28px;
  height: 28px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chapter-bar .nav-btn:hover {
  background: var(--btn-bg);
  color: var(--text-primary);
}

.chapter-bar .nav-btn:active {
  transform: scale(0.95);
}

.chapter-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Unified progress bar with chapter ticks */
.unified-progress {
  flex: 1;
  position: relative;
  height: 4px;
  background: var(--progress-bg);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: var(--text-secondary);
  width: 0%;
  transition: width 0.15s;
  z-index: 1;
}

.chapter-ticks {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  pointer-events: none;
}

.chapter-tick {
  position: absolute;
  top: 0;
  width: 1px;
  height: 100%;
  background: var(--tick-color);
}

/* Main reader area */
.reader-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  overflow: hidden;
}

/* Unified mode history - above the RSVP */
.unified-history {
  position: absolute;
  top: 10px;
  left: 0;
  right: 0;
  bottom: 45%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding: 0 16px 20px;
  overflow: hidden;
}

.unified-line {
  font-size: clamp(0.8rem, 2.2vw, 1rem);
  line-height: 1.6;
  text-align: left;
  width: 100%;
  padding: 2px 0;
}

.unified-line.completed {
  color: var(--text-secondary);
  opacity: 0.7;
}

.unified-line.current {
  color: var(--text-secondary);
  opacity: 0.4;
  font-style: italic;
}

/* RSVP display - positioned at bottom third */
.rsvp-container {
  position: absolute;
  bottom: 25%;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
}

.orp-guide {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  opacity: 0.4;
}

.orp-top {
  border-top: 6px solid var(--accent);
}

.orp-bottom {
  border-bottom: 6px solid var(--accent);
}

.word-display {
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
  font-size: clamp(1.5rem, 8vw, 4rem);
  font-weight: 500;
  white-space: nowrap;
  letter-spacing: 0.02em;
  width: 100%;
}

#word-before {
  flex: 1;
  text-align: right;
  min-width: 0;
}

#word-pivot {
  color: var(--accent);
  flex-shrink: 0;
}

#word-after {
  flex: 1;
  text-align: left;
  min-width: 0;
}

/* Bottom bar */
.reader-footer {
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
  background: var(--bg-secondary);
  z-index: 10;
}

.controls-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.footer-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.footer-center {
  flex: 1;
  text-align: center;
}

#time-remaining {
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.footer-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-btn-small {
  width: 36px;
  height: 36px;
  background: var(--btn-bg);
  border: none;
  border-radius: 6px;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.control-btn-small:hover {
  background: var(--btn-hover);
}

.control-btn-small:active {
  transform: scale(0.95);
}

.wpm-btn {
  width: 32px;
  height: 32px;
  background: var(--btn-bg);
  border: none;
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.wpm-btn:hover {
  background: var(--btn-hover);
}

.wpm-btn:active {
  transform: scale(0.95);
}

.wpm-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 40px;
  margin: 0 4px;
}

#wpm-display {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1;
}

.wpm-label {
  font-size: 0.6rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.turbo-btn {
  width: 44px;
  height: 36px;
  background: var(--btn-bg);
  border: none;
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.turbo-btn:hover {
  background: var(--btn-hover);
}

.turbo-btn:active,
.turbo-btn.active {
  background: var(--accent);
  color: white;
}

/* Tap zones (edges for chapter nav) */
.tap-zone {
  position: absolute;
  top: 60px;
  bottom: 70px;
  z-index: 5;
}

.tap-left {
  left: 0;
  width: 20%;
}

.tap-right {
  right: 0;
  width: 20%;
}

/* Tablet and up */
@media (min-width: 768px) {
  h1 {
    font-size: 3rem;
  }

  .subtitle {
    font-size: 1.5rem;
  }

  .mode-btn {
    padding: 20px 32px;
  }

  .unified-line {
    font-size: 1.2rem;
  }
}

/* Desktop */
@media (min-width: 1024px) {
  .landing-content {
    max-width: 500px;
  }

  .tap-zone {
    cursor: pointer;
  }

  .tap-left:hover,
  .tap-right:hover {
    background: rgba(255, 255, 255, 0.02);
  }
}
