/* CSS Variables */
:root {
  --bg: #f9f7f4;
  --bg-elevated: #ffffff;
  --bg-hover: #f0ede8;
  --bg-accent: #fff8f5;
  --text: #2d2a26;
  --text-muted: #6b6560;
  --text-dim: #9a948d;
  --accent: #e85d35;
  --accent-hover: #d14820;
  --accent-dark: #b8401a;
  --accent-soft: rgba(232, 93, 53, 0.1);
  --border: #e8e4df;
  --border-light: #f0ede8;
  --success: #2d9d5c;
  --error: #d93636;
  --speaker-a: #4a6dd8;
  --speaker-b: #c94a8a;
  
  --font-mono: 'Space Mono', monospace;
  --font-display: 'Sora', sans-serif;
  --font-body: 'Inter', sans-serif;
  
  --radius: 8px;
  --radius-lg: 12px;
  
  --shadow-sm: 0 1px 3px rgba(45, 42, 38, 0.06), 0 1px 2px rgba(45, 42, 38, 0.04);
  --shadow-md: 0 4px 12px rgba(45, 42, 38, 0.08), 0 2px 4px rgba(45, 42, 38, 0.04);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* Container - WIDER */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 5rem 2rem 3rem;
  min-height: 100vh;
}

/* Centered layout for input page */
.container.is-centered {
  padding-top: 28vh;
}

/* Header */
.header {
  margin-bottom: 1.5rem;
}

/* Hide header during loading state */
.container.is-loading .header {
  display: none;
}

.header-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

/* Nav button (new video) - left aligned, no border */
.btn-nav {
  align-self: flex-start;
  margin-top: 0;
  margin-bottom: 0.5rem;
  padding: 0.5rem 0;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  background: transparent;
  color: var(--text-muted);
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-nav:hover {
  color: var(--text);
}

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

.logo-link {
  text-decoration: none;
}

.logo-link:hover .logo {
  color: var(--accent);
}

.logo {
  font-family: var(--font-display);
  font-size: 4rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--text);
  transition: color 0.2s ease;
}

.logo-accent {
  color: var(--accent-dark);
  transition: color 0.2s ease;
}

.logo-link:hover .logo-accent {
  color: var(--accent-dark);
}

/* Sections */
.section {
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.section.hidden {
  display: none;
}

/* Input Section */
.input-section {
  display: grid;
  grid-template-columns: 1fr;
  gap: 3rem;
  max-width: 800px;
  margin: 0 auto;
}

@media (min-width: 700px) {
  .input-section {
    grid-template-columns: 2fr 1fr;
    gap: 4rem;
  }
}

.input-wrapper {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.input-group {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

#url-input {
  flex: 1;
  min-width: 250px;
  padding: 1rem 1.25rem;
  font-family: var(--font-body);
  font-size: 0.9375rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  outline: none;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#url-input:focus {
  border-color: var(--accent);
  box-shadow: var(--shadow-md), 0 0 0 3px var(--accent-soft);
}

#url-input::placeholder {
  color: var(--text-dim);
  font-style: italic;
}

.btn-primary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 1.5rem;
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  font-weight: 700;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-arrow {
  transition: transform 0.2s ease;
}

.btn-primary:hover:not(:disabled) .btn-arrow {
  transform: translateX(3px);
}

/* Preview Card */
.preview-card {
  display: flex;
  gap: 1rem;
  padding: 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  animation: slideUp 0.3s ease;
}

.preview-card.hidden {
  display: none;
}

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

.preview-thumbnail {
  width: 120px;
  height: 68px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--border-light);
}

.preview-info {
  flex: 1;
  min-width: 0;
}

.preview-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 0.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.preview-author {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* About Text */
.about-text {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.5;
  text-align: center;
}

@media (min-width: 700px) {
  .about-text {
    text-align: left;
  }
}

.about-text p {
  margin-bottom: 0.75rem;
}

.about-text .note {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-style: italic;
}

/* Loading Section */
.loading-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 28vh;
  min-height: 50vh;
}

.loading-content {
  text-align: center;
  max-width: 400px;
}

.loading-video-info {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  margin-bottom: 2.5rem;
  text-align: left;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
  overflow: hidden;
}

.loading-video-info > div {
  min-width: 0;
}

.loading-thumbnail {
  width: 80px;
  height: 45px;
  object-fit: cover;
  border-radius: 4px;
}

.loading-title {
  font-family: var(--font-display);
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.3;
  margin-bottom: 0.125rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

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

.loader {
  width: 200px;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 1.5rem;
  overflow: hidden;
}

.loader-bar {
  height: 100%;
  width: 40%;
  background: var(--accent);
  border-radius: 2px;
  animation: loading 1.5s ease-in-out infinite;
}

@keyframes loading {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

.loading-status {
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.loading-dots span {
  animation: dots 1.4s infinite;
  opacity: 0;
}

.loading-dots span:nth-child(1) { animation-delay: 0s; }
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dots {
  0%, 20% { opacity: 0; }
  40%, 100% { opacity: 1; }
}

.loading-estimate {
  font-size: 0.8125rem;
  color: var(--text-dim);
}

/* Results Section */
.results-section {
  animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Results Header - Horizontal Layout */
.results-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.results-video-info {
  display: flex;
  gap: 1rem;
  flex: 1;
  min-width: 0;
}

.results-thumbnail {
  width: 140px;
  height: 79px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}

.results-meta {
  flex: 1;
  min-width: 0;
}

.results-title {
  font-family: var(--font-display);
  font-size: 1.375rem;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 0.25rem;
}

.results-author {
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* Abstract Section */
.abstract-section {
  margin-bottom: 2.5rem;
}

.abstract-section.hidden {
  display: none;
}

.results-abstract {
  font-size: 0.9375rem;
  font-style: italic;
  color: var(--text-muted);
  line-height: 1.55;
  padding: 1.25rem 1.5rem;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  border-left: 3px solid var(--accent);
  box-shadow: var(--shadow-sm);
}

/* Tabs Header - with actions on right */
.tabs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.tabs {
  display: flex;
  gap: 0;
}

.tab {
  padding: 0.75rem 1.25rem;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 700;
}

.tabs-actions {
  display: flex;
  gap: 0.5rem;
  padding-bottom: 0.5rem;
}

/* Content Box with copy button */
.content-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.content-header {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-hover);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

/* Mobile download buttons - hidden on desktop */
.mobile-download-btns {
  display: none;
  gap: 0.5rem;
}

.btn-copy {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.625rem;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-copy:hover {
  background: var(--bg);
  border-color: var(--text-dim);
  color: var(--text);
}

.btn-copy.copied {
  background: rgba(45, 157, 92, 0.1);
  border-color: var(--success);
  color: var(--success);
}

.copy-icon {
  font-size: 0.875rem;
}

.tab-content {
  display: none;
}

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

/* Buttons */
.btn-secondary {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.875rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
  background: var(--bg);
  border-color: var(--text-dim);
}

.btn-ghost {
  padding: 0.625rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  background: transparent;
  color: var(--text-muted);
  border: none;
  cursor: pointer;
  transition: color 0.2s ease;
  white-space: nowrap;
}

.btn-ghost:hover {
  color: var(--text);
}

/* Transcript Container */
.transcript-container {
  max-height: 55vh;
  overflow-y: auto;
  padding: 1rem;
}

.transcript-container::-webkit-scrollbar {
  width: 6px;
}

.transcript-container::-webkit-scrollbar-track {
  background: var(--bg);
  border-radius: 3px;
}

.transcript-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.transcript-container::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

/* Transcript Chunks */
.transcript-chunk {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border-light);
}

.transcript-chunk:last-child {
  border-bottom: none;
}

.transcript-chunk.has-speaker {
  padding-left: 1rem;
  border-left: 3px solid var(--speaker-a);
}

.transcript-chunk.speaker-b {
  border-left-color: var(--speaker-b);
}

.chunk-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.chunk-timestamp {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.chunk-speaker {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--speaker-a);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.125rem 0.5rem;
  background: rgba(74, 109, 216, 0.1);
  border-radius: 4px;
}

.chunk-speaker.speaker-b {
  color: var(--speaker-b);
  background: rgba(201, 74, 138, 0.1);
}

.chunk-text {
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--text);
}

/* Summary / Sparknotes */
.summary-container {
  max-height: 55vh;
  overflow-y: auto;
  padding: 1rem;
}

.sparknotes-content {
  padding: 0;
}

.sparknotes-loading {
  text-align: center;
  padding: 3rem;
}

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

.sparknotes-loading p {
  margin-top: 1rem;
  color: var(--text-muted);
}

.sparknotes-placeholder {
  text-align: center;
  padding: 3rem;
}

.sparknotes-placeholder.hidden {
  display: none;
}

.sparknotes-placeholder p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

.sparknotes-result {
  line-height: 1.8;
}

.sparknotes-result.hidden {
  display: none;
}

.sparknotes-result h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 1.5rem;
  line-height: 1.3;
}

.sparknotes-result h2 {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
  margin: 2rem 0 0.75rem;
}

.sparknotes-result h2:first-child {
  margin-top: 0;
}

.sparknotes-result h3 {
  font-family: var(--font-body);
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
  margin: 1.5rem 0 0.5rem;
}

.sparknotes-result p {
  margin-bottom: 1rem;
  color: var(--text);
}

.sparknotes-result ul {
  margin: 0.5rem 0 1rem 1.5rem;
}

.sparknotes-result li {
  margin-bottom: 0.5rem;
  color: var(--text);
}

.sparknotes-result strong {
  color: var(--text);
  font-weight: 700;
}

.sparknotes-result blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1rem;
  margin: 1rem 0;
  color: var(--text-muted);
  font-style: italic;
}

/* Error Toast */
.error-toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: var(--error);
  color: white;
  border-radius: var(--radius);
  font-size: 0.875rem;
  animation: slideIn 0.3s ease;
  z-index: 1000;
  box-shadow: var(--shadow-md);
}

.error-toast.hidden {
  display: none;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.error-dismiss {
  background: transparent;
  border: none;
  color: white;
  font-size: 1.25rem;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.error-dismiss:hover {
  opacity: 1;
}

/* Responsive */
@media (max-width: 700px) {
  .tabs-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }
  
  .tabs-actions {
    padding-bottom: 0;
  }
  
  .results-header {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 500px) {
  .container {
    padding: 2rem 1.75rem;
    overflow-x: hidden;
  }

  .container.is-centered,
  .container.is-loading {
    padding-top: 20vh;
    padding-left: 2.5rem;
    padding-right: 2.5rem;
  }

  .loading-content {
    max-width: calc(100vw - 4rem);
    box-sizing: border-box;
  }

  .logo {
    font-size: 3rem;
  }

  /* Inline button inside input */
  .input-group {
    position: relative;
    gap: 0;
  }

  #url-input {
    padding-right: 7.5rem;
  }

  .btn-primary {
    position: absolute;
    right: 0.375rem;
    top: 50%;
    transform: translateY(-50%);
    padding: 0.625rem 1rem;
    font-size: 0.8125rem;
    border-radius: 6px;
  }

  .btn-primary:hover:not(:disabled) {
    transform: translateY(-50%);
  }
  
  .tabs-header {
    align-items: center;
  }
  
  .tabs {
    justify-content: center;
    width: 100%;
  }
  
  /* Hide desktop download buttons on mobile */
  .tabs-actions {
    display: none;
  }
  
  /* Show mobile download buttons */
  .mobile-download-btns {
    display: flex;
  }
  
  .content-header {
    justify-content: space-between;
  }
  
  .results-video-info {
    flex-direction: column;
  }
  
  .results-thumbnail {
    width: 100%;
    height: auto;
    aspect-ratio: 16/9;
  }
  
  .chunk-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }
}
