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

:root {
  --bg: #f5f5f5;
  --card-bg: #fff;
  --text: #333;
  --text-muted: #666;
  --accent: #e74c3c;
  --accent-light: rgba(231, 76, 60, 0.15);
  --border: #ddd;
}

[data-theme="dark"] {
  --bg: #1a1a1a;
  --card-bg: #252525;
  --text: #e0e0e0;
  --text-muted: #999;
  --accent-light: rgba(231, 76, 60, 0.25);
  --border: #404040;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 20px;
}

#app {
  max-width: 800px;
  margin: 0 auto;
}

.container {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 32px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.hidden {
  display: none !important;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
}

h1 {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 4px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 14px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 2px solid var(--border);
  border-radius: 10px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.icon-btn.small {
  width: 32px;
  height: 32px;
  border: none;
}

/* Tabs */
.input-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.tab {
  flex: 1;
  padding: 10px 16px;
  border: 2px solid var(--border);
  background: transparent;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text);
}

.tab:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Text Input */
#textInput {
  width: 100%;
  height: 150px;
  min-height: 100px;
  max-height: 400px;
  padding: 14px;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
  background: var(--card-bg);
  color: var(--text);
}

#textInput:focus {
  border-color: var(--accent);
}

/* URL Input */
#urlInput {
  width: 100%;
  padding: 14px;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
  background: var(--card-bg);
  color: var(--text);
}

#urlInput:focus {
  border-color: var(--accent);
}

.hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* Buttons */
.primary-btn {
  width: 100%;
  padding: 14px;
  margin-top: 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
}

.primary-btn:hover {
  opacity: 0.9;
}

.primary-btn:active {
  transform: scale(0.98);
}

.secondary-btn {
  padding: 10px 20px;
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--accent);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.secondary-btn:hover {
  background: var(--accent);
  color: #fff;
}

/* Input Section */
#inputSection {
  margin-bottom: 24px;
}

/* Reader Section */
#readerSection {
  border-top: 1px solid var(--border);
  padding-top: 24px;
}

#reader {
  background: var(--bg);
  border-radius: 16px;
  padding: 16px 24px;
  position: relative;
  overflow: hidden;
}

/* Word Display */
.word-display {
  position: relative;
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 0;
}

.word-display::before,
.word-display::after {
  content: '';
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 14px;
  background: var(--border);
}

.word-display::before {
  top: 5px;
}

.word-display::after {
  bottom: 5px;
}

#currentWord {
  font-size: 42px;
  font-weight: 400;
  letter-spacing: 2px;
  position: absolute;
  left: 50%;
  white-space: nowrap;
}

.word-before,
.word-after {
  color: var(--text);
}

.word-pivot {
  color: var(--accent);
  font-weight: 600;
}

/* Controls */
.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 0;
  flex-wrap: wrap;
}

.controls button {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-muted);
  transition: color 0.2s, background 0.2s;
}

.controls button:hover {
  background: var(--card-bg);
  color: var(--text);
}

#playPauseBtn {
  width: 50px;
  height: 50px;
  background: var(--accent-light);
  border-radius: 50%;
}

#playPauseBtn:hover {
  background: rgba(231, 76, 60, 0.25);
}

.speed-control {
  display: flex;
  align-items: center;
  gap: 10px;
}

#speedSlider {
  width: 100px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}

#speedSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--text);
  border-radius: 50%;
  cursor: pointer;
}

#wpmValue {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 60px;
}

#readingTime {
  font-size: 11px;
  color: var(--text-muted);
  min-width: 35px;
  text-align: right;
}

/* Progress Bar */
.progress-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--card-bg);
  border-radius: 0 0 14px 14px;
  overflow: hidden;
}

#progressFill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.1s linear;
}

/* Text View */
#textView {
  margin-top: 20px;
  max-height: 300px;
  overflow-y: auto;
  padding: 16px;
  background: var(--bg);
  border-radius: 12px;
  line-height: 1.8;
  font-size: 15px;
  scroll-behavior: smooth;
}

#textContent {
  color: var(--text-muted);
}

#textContent .word {
  display: inline;
  padding: 2px 0;
  border-radius: 3px;
  transition: background 0.15s, color 0.15s;
}

#textContent .word.active {
  background: var(--accent);
  color: #fff;
  padding: 2px 4px;
  margin: 0 -4px;
}

#textContent .word.read {
  color: var(--text);
}

#textContent .paragraph-break {
  height: 1em;
  width: 100%;
}

/* Article structured content */
#textContent p {
  margin-bottom: 12px;
}

#textContent .article-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
  line-height: 1.3;
}

#textContent .article-heading {
  font-weight: 600;
  color: var(--text);
  margin-top: 16px;
  margin-bottom: 8px;
  line-height: 1.3;
}

#textContent h2.article-heading {
  font-size: 17px;
}

#textContent h3.article-heading {
  font-size: 16px;
}

#textContent h4.article-heading,
#textContent h5.article-heading {
  font-size: 15px;
}

#textContent .article-quote {
  border-left: 3px solid var(--accent);
  padding-left: 14px;
  margin: 12px 0;
  font-style: italic;
  color: var(--text-muted);
}

#textContent .article-code {
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  font-size: 13px;
  background: var(--card-bg);
  padding: 10px 12px;
  border-radius: 8px;
  margin: 12px 0;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

#textContent .article-list {
  margin: 8px 0 12px 0;
  padding-left: 20px;
}

#textContent .article-list li {
  margin-bottom: 6px;
}

#textContent figcaption {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  margin: 4px 0 12px 0;
}

/* Finish Overlay */
#finishOverlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

#finishOverlay.hidden {
  display: none;
}

.finish-content {
  text-align: center;
  z-index: 2;
}

.finish-text {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 16px;
}

#confetti {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(350px) rotate(720deg);
    opacity: 0;
  }
}

/* Header Actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.extension-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: opacity 0.2s;
}

.extension-btn:hover {
  opacity: 0.7;
}

.extension-btn svg {
  flex-shrink: 0;
}

/* Loading Overlay */
#loadingOverlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  z-index: 100;
}

#loadingOverlay.visible {
  display: flex;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

#loadingOverlay p {
  color: #fff;
  font-size: 15px;
}

/* Error Toast */
#errorToast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #333;
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  transition: all 0.3s;
  z-index: 101;
}

#errorToast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Responsive */
@media (max-width: 600px) {
  body {
    padding: 10px;
  }

  .container {
    padding: 20px;
  }

  h1 {
    font-size: 22px;
  }

  .header-actions {
    gap: 8px;
  }

  .extension-btn span {
    display: none;
  }

  #currentWord {
    font-size: 32px;
  }

  .controls {
    gap: 8px;
  }

  #textView {
    max-height: 200px;
  }
}
