:root {
  --bg: #0a0a0a;
  --bg-accent: #111111;
  --panel: rgba(255, 255, 255, 0.04);
  --panel-border: rgba(255, 255, 255, 0.1);
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.5);
  --accent: #ff3b30;
  --focus: #ff3b30;
  --paper: #ffffff;
  --ink: #0a0a0a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  color: var(--text);
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  justify-content: center;
  padding: 48px 24px 64px;
}

.app {
  width: min(1100px, 100%);
  display: flex;
  flex-direction: column;
  gap: 32px;
  animation: rise 0.7s ease-out;
}

.support-banner {
  display: block;
  text-align: center;
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.9rem;
  text-decoration: none;
  transition: all 0.2s ease;
}

.support-banner:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--accent);
  color: rgba(255, 255, 255, 0.9);
}

.support-banner span {
  color: var(--accent);
  font-weight: 600;
}

.hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
}

.eyebrow {
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  color: var(--muted);
  margin: 0 0 8px;
}

h1 {
  font-family: "Fraunces", serif;
  font-size: clamp(2rem, 3vw, 3rem);
  margin: 0 0 8px;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  max-width: 480px;
}

.stats {
  display: flex;
  gap: 24px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 16px 20px;
  backdrop-filter: blur(12px);
}

.stat-label {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-value {
  margin: 6px 0 0;
  font-size: 1.2rem;
  font-weight: 600;
}

.layout {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  padding: 24px;
  backdrop-filter: blur(14px);
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 380px;
}

.input-panel {
  position: relative;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-panel label {
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

#docTitle {
  border-radius: 14px;
  border: none;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: "Space Grotesk", sans-serif;
  color: var(--ink);
  background: var(--paper);
  box-shadow: inset 0 0 0 1px rgba(17, 19, 26, 0.08);
  transition: box-shadow 0.2s ease;
}

#docTitle:focus {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--accent);
}

#textInput {
  flex: 1;
  border-radius: 16px;
  border: none;
  padding: 16px;
  font-size: 1rem;
  font-family: "Space Grotesk", sans-serif;
  color: var(--ink);
  background: var(--paper);
  box-shadow: inset 0 0 0 1px rgba(17, 19, 26, 0.08);
  resize: vertical;
  min-height: 220px;
  transition: box-shadow 0.2s ease;
}

#textInput:focus {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.file-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

#pdfInput {
  display: none;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, border 0.2s ease;
}

.file-button:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.16);
}

.file-status {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.file-status.error {
  color: #ff6b63;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0.01em;
}

.toggle input {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

.controls {
  display: flex;
  gap: 12px;
}

button {
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, border 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.16);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

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

button.primary {
  background: var(--accent);
  color: #ffffff;
}

button.primary:hover {
  background: #ff5147;
}

button.ghost {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.2);
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
}

.hint span {
  color: var(--text);
  font-weight: 600;
}

.reader-panel {
  position: relative;
  justify-content: flex-start;
  gap: 20px;
}

.reader-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.reader-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.reader-doc {
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: none;
  color: rgba(246, 247, 251, 0.7);
}

.toolbar-actions {
  display: flex;
  gap: 10px;
}

.reader {
  position: relative;
  background: #000000;
  border-radius: 20px;
  height: 300px;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.gaze-line {
  position: absolute;
  top: 15%;
  bottom: 15%;
  width: 2px;
  background: rgba(255, 255, 255, 0.08);
  left: 50%;
  transform: translateX(-50%);
}

.live-wpm {
  position: absolute;
  bottom: 12px;
  left: 16px;
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.4);
  letter-spacing: 0.05em;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.live-wpm.visible {
  opacity: 1;
}

.context-view {
  position: absolute;
  inset: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  line-height: 2;
  color: rgba(255, 255, 255, 0.75);
  overflow-y: auto;
  padding: 30px 50px;
}

.context-view p {
  max-width: 700px;
  text-align: left;
}

.context-view.hidden {
  display: none;
}

.context-view .highlight {
  color: var(--accent);
  font-weight: 700;
}

.context-toggle {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.7);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 10;
}

.context-toggle:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.context-toggle.hidden {
  display: none;
}

.context-nav {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  z-index: 10;
}

.context-nav.hidden {
  display: none;
}

.context-nav-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.7);
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.context-nav-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.context-nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.context-view-active .word-display,
.context-view-active .gaze-line {
  display: none;
}

.auto-pace {
  position: absolute;
  bottom: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  font-size: 0.75rem;
}

.auto-pace-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  white-space: nowrap;
}

.auto-pace-toggle input {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  cursor: pointer;
}

.auto-pace-toggle input:checked + span {
  color: var(--accent);
}

.auto-pace-settings {
  display: none;
  align-items: center;
  gap: 10px;
}

.auto-pace-settings.visible {
  display: flex;
}

.pace-field {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pace-field label {
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.pace-field input {
  width: 56px;
  padding: 4px 6px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  color: #ffffff;
  font-size: 0.75rem;
  font-family: inherit;
  text-align: center;
}

.pace-field input:focus {
  outline: none;
  border-color: var(--accent);
}

.word-display {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 32px;
  font-family: "Fraunces", serif;
  font-size: clamp(2.2rem, 5vw, 4.4rem);
  letter-spacing: 0.02em;
  color: var(--text);
}

.word-left {
  text-align: right;
}

.word-focus {
  color: var(--focus);
  font-weight: 700;
  padding: 0 4px;
}

.word-right {
  text-align: left;
}

.reader-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 24px 18px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.6);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.5);
  transition:
    max-height 0.3s ease,
    opacity 0.3s ease,
    transform 0.3s ease,
    padding 0.3s ease,
    border 0.3s ease;
  max-height: 300px;
  overflow: hidden;
}

.reader-controls.closed {
  max-height: 0;
  opacity: 0;
  transform: translateY(20px);
  padding: 0 18px;
  border-color: transparent;
  pointer-events: none;
}

.customize-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px 20px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.55);
  transition:
    max-height 0.3s ease,
    opacity 0.3s ease,
    transform 0.3s ease,
    padding 0.3s ease,
    border 0.3s ease;
  max-height: 260px;
  overflow: hidden;
}

.customize-panel.closed {
  max-height: 0;
  opacity: 0;
  transform: translateY(-10px);
  padding: 0 20px;
  border-color: transparent;
  pointer-events: none;
}

.customize-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.customize-title {
  margin: 0;
  font-size: 0.8rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.color-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

#focusColorPicker {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: transparent;
  cursor: pointer;
}

#focusColorPicker:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.color-swatch {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: transparent;
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
  position: relative;
}

.color-swatch::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--swatch);
  margin-right: 6px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4);
}

.controls-centered {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.reader-jump {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.reader-jump button {
  padding: 8px 14px;
  font-size: 0.85rem;
}

.speed-slider {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 400px;
}

.speed-label-min,
.speed-label-max {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.4);
  min-width: 28px;
  text-align: center;
}

.slider-track {
  flex: 1;
  position: relative;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.slider-track input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: transparent;
  cursor: pointer;
  position: relative;
}

.slider-track input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  background: linear-gradient(to right, var(--accent), rgba(255, 255, 255, 0.15));
  border-radius: 3px;
}

.slider-track input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: #ffffff;
  border-radius: 50%;
  margin-top: -6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  transition: transform 0.15s ease;
}

.slider-track input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.slider-track input[type="range"]::-moz-range-track {
  height: 6px;
  background: linear-gradient(to right, var(--accent), rgba(255, 255, 255, 0.15));
  border-radius: 3px;
}

.slider-track input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: #ffffff;
  border: none;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  transition: transform 0.15s ease;
}

.wpm-display {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  color: #ffffff;
  letter-spacing: 0.05em;
}

.history {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-title {
  margin: 0;
  font-size: 0.8rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.history-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.9rem;
  color: var(--text);
}

.history-row span:first-child {
  color: var(--muted);
}

.reader-panel.fullscreen {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: #000000;
  border-radius: 0;
  padding: 24px 32px 28px;
  border: none;
}

.reader-panel.fullscreen .reader {
  height: auto;
  background: #000000;
  border-radius: 18px;
}

.reader-panel.fullscreen .word-display {
  font-size: clamp(3rem, 8vw, 6rem);
}

.reader-panel.fullscreen .reader-controls {
  margin-top: auto;
}


@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.library {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.library-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.library-title {
  margin: 0;
  font-size: 0.8rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.library-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.library-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 240px;
  overflow-y: auto;
}

.library-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.03);
}

.library-item.active {
  border-color: rgba(255, 59, 48, 0.6);
  box-shadow: 0 0 0 1px rgba(255, 59, 48, 0.2);
}

.library-name {
  margin: 0;
  font-weight: 600;
  color: var(--text);
}

.library-meta {
  margin: 6px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.library-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.library-actions button {
  padding: 6px 12px;
  font-size: 0.75rem;
}

.drop-overlay {
  position: absolute;
  inset: 16px;
  border-radius: 18px;
  border: 2px dashed rgba(255, 59, 48, 0.5);
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  text-align: center;
  padding: 24px;
}

.input-panel.drag-over .drop-overlay {
  opacity: 1;
}

@media (max-width: 960px) {
  .hero {
    flex-direction: column;
    align-items: flex-start;
  }

  .stats {
    width: 100%;
    justify-content: space-between;
  }

  .panel {
    min-height: auto;
  }
}

@media (max-width: 600px) {
  body {
    padding: 32px 16px 48px;
  }

  .controls {
    flex-direction: column;
  }

  .file-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .speed {
    flex-direction: column;
    align-items: flex-start;
  }

  .dial-wrap {
    width: 120px;
    height: 120px;
  }
}
