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

:root {
  --bg-color: #fff;
  --text-color: #333;
  --text-secondary: #666;
  --border-color: #ddd;
  --input-bg: #fff;
  --button-bg: #f5f5f5;
  --button-hover: #e8e8e8;
  --button-disabled: #ccc;
  --primary-color: #007bff;
  --primary-hover: #0056b3;
  --progress-bg: #f0f0f0;
  --icon-hover: #f5f5f5;
  --loading-bg: rgba(255, 255, 255, 0.95);
  --spinner-bg: #f0f0f0;
  --anchor-color: #e74c3c;
}

[data-theme="dark"] {
  --bg-color: #000;
  --text-color: #fff;
  --text-secondary: #aaa;
  --border-color: #444;
  --input-bg: #111;
  --button-bg: #222;
  --button-hover: #333;
  --button-disabled: #444;
  --primary-color: #4da3ff;
  --primary-hover: #007bff;
  --progress-bg: #222;
  --icon-hover: #222;
  --loading-bg: rgba(0, 0, 0, 0.95);
  --spinner-bg: #333;
  --anchor-color: #ff6b6b;
}

html, body {
  width: 100%;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  line-height: 1.5;
  color: var(--text-color);
  background: var(--bg-color);
}

#app {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.landing {
  max-width: 90vw;
  width: 100%;
  text-align: center;
}

.landing h1 {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
  font-weight: 600;
}

#textInput {
  width: 100%;
  min-height: 8rem;
  padding: 0.75rem;
  font-size: 1rem;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  margin-bottom: 1rem;
  resize: vertical;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text-color);
}

.input-controls {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: stretch;
}

.file-picker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3rem;
  padding: 0.75rem 1.5rem;
  background: var(--button-bg);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.2s;
  color: var(--text-color);
}

.file-picker:hover {
  background: var(--button-hover);
}

.file-picker input[type="file"] {
  display: none;
}

#startReading {
  min-height: 3rem;
  padding: 0.75rem 1.5rem;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 0.5rem;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s;
}

#startReading:hover:not(:disabled) {
  background: var(--primary-hover);
}

#startReading:disabled {
  background: var(--button-disabled);
  cursor: not-allowed;
}

.reader-interface {
  width: 100%;
  max-width: 90vw;
  height: 100%;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
}

.reader-controls-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0;
}

.icon-button {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  min-width: 3rem;
  min-height: 3rem;
  padding: 0.5rem;
  border-radius: 0.25rem;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-color);
}

.icon-button:hover {
  background: var(--icon-hover);
}

.wpm-control {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  justify-content: center;
}

.wpm-control label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.wpm-control input[type="range"] {
  width: 8rem;
  min-width: 4rem;
  flex: 1;
  max-width: 12rem;
  height: 2.75rem;
  padding: 0.75rem 0;
  cursor: pointer;
}

.wpm-control span {
  min-width: 3rem;
  text-align: center;
  font-weight: 600;
}

.word-display {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  min-height: 30vh;
  padding: 1rem;
}

.word {
  font-size: clamp(2rem, 8vw, 4rem);
  font-weight: 500;
  text-align: center;
  line-height: 1.2;
}

.anchor {
  color: var(--anchor-color);
  font-weight: 700;
}

.reader-controls-bottom {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 0.75rem 0;
}

.progress-container {
  width: 100%;
  height: 2.75rem;
  background: var(--progress-bg);
  border-radius: 0.25rem;
  position: relative;
  cursor: pointer;
  overflow: hidden;
  min-height: 2.75rem;
}

.progress-bar {
  width: 100%;
  height: 0.5rem;
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
}

.progress-fill {
  height: 100%;
  background: var(--primary-color);
  border-radius: 0.25rem;
  transition: width 0.1s;
  width: 0%;
}

.playback-controls {
  display: flex;
  justify-content: center;
}

.play-button {
  width: 4rem;
  height: 4rem;
  min-width: 3.5rem;
  min-height: 3.5rem;
  border-radius: 50%;
  background: var(--primary-color);
  color: white;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.play-button:hover {
  background: var(--primary-hover);
}

.position-info {
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-secondary);
  min-height: 1.25rem;
}

.loading-indicator {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--loading-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.loading-indicator.hidden {
  display: none;
}

.spinner {
  width: 3rem;
  height: 3rem;
  border: 0.25rem solid var(--spinner-bg);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text {
  margin-top: 1rem;
  font-size: 1rem;
  color: var(--text-secondary);
}

@media (min-width: 480px) {
  .input-controls {
    flex-direction: row;
  }

  .file-picker,
  #startReading {
    flex: 1;
  }
}

@media (min-width: 600px) {
  .landing {
    max-width: 600px;
  }

  .word-display {
    min-height: 40vh;
  }

  .wpm-control input[type="range"] {
    width: 9.375rem;
  }

  .play-button {
    width: 4rem;
    height: 4rem;
    font-size: 1.5rem;
  }
}

@media (min-width: 768px) {
  #app {
    padding: 1.25rem;
  }

  .reader-interface {
    max-width: 900px;
  }

  .reader-controls-top {
    padding: 1rem 0;
  }

  .reader-controls-bottom {
    padding: 1rem 0;
  }
}

@media (min-width: 1024px) {
  .word {
    font-size: 4rem;
  }

  .play-button {
    width: 4rem;
    height: 4rem;
  }
}

@media (min-width: 768px) {
  @media (hover: hover) {
    .icon-button:hover,
    .file-picker:hover,
    #startReading:hover:not(:disabled),
    .play-button:hover {
      opacity: 0.9;
    }
  }
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text-color);
  transition: background 0.2s;
  min-height: 2.5rem;
}

.theme-toggle:hover {
  background: var(--button-hover);
}

.landing-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.landing-header h1 {
  font-size: 1.5rem;
  margin: 0;
  font-weight: 600;
}

.footer {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.footer a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.75rem;
  transition: color 0.2s;
}

.footer a:hover {
  color: var(--text-color);
}
