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

/* ── Base ───────────────────────────────────────────────────── */
:root {
  --color-bg:          #f5f5f5;
  --color-card:        #ffffff;
  --color-border:      #e0e0e0;
  --color-text:        #1a1a1a;
  --color-muted:       #6b7280;
  --color-primary:     #16a34a;
  --color-primary-h:   #15803d;
  --color-error-bg:    #fef2f2;
  --color-error-text:  #b91c1c;
  --color-error-border:#fecaca;
  --color-code-bg:     #f8f8f8;
  --shadow-card:       0 2px 12px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.06);
  --radius-card:       12px;
  --radius-input:      8px;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--color-text);
  background-color: var(--color-bg);
  padding: 2rem 1rem;
  min-height: 100vh;
}

/* ── Layout ─────────────────────────────────────────────────── */
.container {
  max-width: 800px;
  margin: 0 auto;
}

/* ── Card ───────────────────────────────────────────────────── */
.card {
  background: var(--color-card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 2rem;
}

/* ── Index page ─────────────────────────────────────────────── */
.page-title {
  font-size: 1.75rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
}

.page-subtitle {
  text-align: center;
  color: var(--color-muted);
  margin-bottom: 2rem;
  font-size: 0.95rem;
}

/* ── Form ───────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.4rem;
  color: var(--color-text);
}

.form-input {
  display: block;
  width: 100%;
  padding: 0.65rem 0.9rem;
  font-size: 1rem;
  font-family: inherit;
  color: var(--color-text);
  background: #fff;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-input);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input::placeholder {
  color: #a0aec0;
}

.form-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15);
}

.btn-submit {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--color-primary);
  border: none;
  border-radius: var(--radius-input);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  margin-top: 0.25rem;
}

.btn-submit:hover {
  background: var(--color-primary-h);
}

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

.btn-icon {
  font-size: 0.85rem;
  opacity: 0.9;
}

.form-hint {
  margin-top: 1rem;
  font-size: 0.82rem;
  color: var(--color-muted);
  text-align: center;
}

.form-hint code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.8rem;
  background: var(--color-code-bg);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  border: 1px solid var(--color-border);
}

/* ── Result page – nav & meta ───────────────────────────────── */
.back-link {
  display: inline-block;
  color: var(--color-primary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 1.25rem;
  transition: opacity 0.15s;
}

.back-link:hover {
  opacity: 0.75;
}

.job-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  font-size: 0.82rem;
  color: var(--color-muted);
}

.job-id-label {
  font-weight: 600;
}

.job-id {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.78rem;
  background: var(--color-code-bg);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  border: 1px solid var(--color-border);
  word-break: break-all;
}

/* ── Spinner ────────────────────────────────────────────────── */
@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  display: inline-block;
  width: 36px;
  height: 36px;
  border: 3.5px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  flex-shrink: 0;
}

.processing-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 2.5rem 1rem;
  text-align: center;
}

/* ── Status badges ──────────────────────────────────────────── */
.status-badge {
  display: inline-block;
  padding: 0.35em 0.85em;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.status-downloading {
  background: #dbeafe;
  color: #1d4ed8;
}

.status-transcribing {
  background: #ffedd5;
  color: #c2410c;
}

.status-analyzing {
  background: #f3e8ff;
  color: #7e22ce;
}

/* ── Error box ──────────────────────────────────────────────── */
.error-box {
  background: var(--color-error-bg);
  border: 1.5px solid var(--color-error-border);
  border-radius: var(--radius-input);
  padding: 1.25rem 1.5rem;
}

.error-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-error-text);
  margin-bottom: 0.5rem;
}

.error-message {
  color: var(--color-error-text);
  font-size: 0.92rem;
  white-space: pre-wrap;
}

/* ── Notice box (fallback warning) ──────────────────────────── */
.notice-box {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: var(--radius-input);
  padding: 0.65rem 0.85rem;
  margin-bottom: 1.5rem;
  font-size: 0.88rem;
  line-height: 1.5;
  color: #78350f;
}

.notice-icon {
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background: #d97706;
  color: #ffffff;
  font-weight: 700;
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  margin-top: 0.1rem;
}

.notice-message strong {
  color: #7c2d12;
  font-weight: 700;
  margin-right: 0.25rem;
}

/* ── Result sections ────────────────────────────────────────── */
.result-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  letter-spacing: -0.01em;
}

.result-section {
  margin-bottom: 1.75rem;
}

.result-section:last-child {
  margin-bottom: 0;
}

.badge-ai {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  background: #ede9fe;
  color: #7c3aed;
  border-radius: 4px;
  padding: 0.1em 0.5em;
  vertical-align: middle;
  margin-left: 0.4rem;
}

.section-heading {
  font-size: 1rem;
  font-weight: 700;
  padding-bottom: 0.4rem;
  margin-bottom: 0.85rem;
  border-bottom: 2px solid var(--color-border);
  color: var(--color-text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ── Copy button ────────────────────────────────────────────── */
.copy-btn {
  margin-left: auto;
  padding: 0.25rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 500;
  font-family: inherit;
  background: var(--color-code-bg);
  color: var(--color-muted);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s,
    border-color 0.15s;
}

.copy-btn:hover {
  background: #e5e7eb;
  color: var(--color-text);
}

.copy-btn:active {
  transform: translateY(1px);
}

.copy-btn.copied {
  background: #dcfce7;
  color: #166534;
  border-color: #86efac;
}

/* ── Info grid (definition list) ────────────────────────────── */
.info-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.4rem 1rem;
  font-size: 0.92rem;
}

.info-grid dt {
  font-weight: 600;
  color: var(--color-muted);
  white-space: nowrap;
}

.info-grid dd {
  color: var(--color-text);
  word-break: break-word;
}

.hashtags {
  color: #1d4ed8;
  font-size: 0.88rem;
}

/* ── Transcript / pre ───────────────────────────────────────── */
.transcript-block {
  display: block;
  background: var(--color-code-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-input);
  padding: 1rem 1.1rem;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.84rem;
  line-height: 1.7;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 400px;
  overflow-y: auto;
}

/* ── Key points list ────────────────────────────────────────── */
.key-points-list {
  padding-left: 1.35rem;
}

.key-points-list li {
  margin-bottom: 0.45rem;
  font-size: 0.94rem;
  line-height: 1.55;
}

.key-points-list li:last-child {
  margin-bottom: 0;
}

/* ── Video modal ────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  width: min(90vw, 800px);
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: #1a1a1a;
}
.modal-title {
  color: #fff;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: calc(100% - 2.5rem);
}
.modal-close {
  background: none;
  border: none;
  color: #aaa;
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 0.2rem;
}
.modal-close:hover { color: #fff; }
.modal-video {
  display: block;
  width: 100%;
  max-height: 70vh;
  background: #000;
}

.btn-play {
  flex-shrink: 0;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-play:hover { background: var(--color-primary-hover); }

.btn-delete {
  flex-shrink: 0;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  background: none;
  border: 1px solid #fca5a5;
  color: #ef4444;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-delete:hover { background: #fee2e2; }
.btn-delete:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Local video list ───────────────────────────────────────── */
.section-title {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.btn-refresh {
  background: none;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  font-size: 0.8rem;
  color: #666;
}

.btn-refresh:hover {
  background: #f5f5f5;
}

.video-card {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #eee;
  gap: 1rem;
}

.video-card:last-child {
  border-bottom: none;
}

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

.video-caption {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.video-meta {
  font-size: 0.8rem;
  color: #888;
  margin-top: 2px;
}

.btn-extract {
  white-space: nowrap;
  background: #2563eb;
  color: white;
  border: none;
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}

.btn-extract:hover {
  background: #1d4ed8;
}

.badge-cached {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  background: #dcfce7;
  color: #166534;
  border: 1px solid #86efac;
  border-radius: 999px;
  padding: 0.15em 0.6em;
  white-space: nowrap;
  vertical-align: middle;
  margin-left: 0.4rem;
}

.empty-msg {
  color: #999;
  font-size: 0.9rem;
  padding: 1rem 0;
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 600px) {
  body {
    padding: 1rem 0.75rem;
  }

  .card {
    padding: 1.25rem;
  }

  .page-title {
    font-size: 1.4rem;
  }

  .info-grid {
    grid-template-columns: 1fr;
  }

  .info-grid dt {
    margin-bottom: -0.2rem;
  }

  .transcript-block {
    max-height: 280px;
  }
}
