:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --accent: #f59e0b;
  --accent-dark: #d97706;
  --ink: #1e1b2e;
  --muted: #6b6478;
  --border: #e7e4f0;
  --bg: #f6f5fb;
  --card-bg: #ffffff;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 1px 2px rgba(30, 27, 46, 0.04), 0 12px 28px -8px rgba(76, 70, 130, 0.12);
  --shadow-card-hover: 0 1px 2px rgba(30, 27, 46, 0.05), 0 18px 36px -10px rgba(76, 70, 130, 0.18);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  background-image: radial-gradient(60% 50% at 50% 0%, #ecebfa 0%, var(--bg) 60%);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 40px 20px 80px;
}

.app-header {
  position: relative;
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 28px;
}

.logo-badge {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 8px 18px -6px rgba(79, 70, 229, 0.5);
}

.logo-badge svg {
  width: 28px;
  height: 28px;
}

.app-header h1 {
  position: relative;
  z-index: 1;
  margin: 0;
  font-family: 'Playfair Display', 'Inter', serif;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: var(--ink);
}

.greeting-bubble {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 22px;
  margin-bottom: 24px;
  font-size: 15px;
  line-height: 1.65;
  color: #423d52;
  box-shadow: var(--shadow-card);
}

.main-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 22px;
}

.main-nav-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--muted);
  transition: background .2s var(--ease), color .2s var(--ease), border-color .2s var(--ease);
}

.main-nav-btn .tab-icon { width: 16px; height: 16px; }

.main-nav-btn.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.main-nav-btn:not(.active):hover {
  border-color: #c9c3e3;
  color: var(--ink);
}

.view { display: none; }
.view.active { display: block; }

.history-list-card { padding: 10px; }

.history-empty {
  padding: 24px 18px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s var(--ease);
  border: 1px solid transparent;
  text-align: left;
  background: none;
  width: 100%;
  font-family: inherit;
}

.history-item:hover { background: var(--bg); }
.history-item.active { background: var(--primary-light); border-color: #d8d3f5; }

.history-item-icon {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 10px;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.history-item-icon svg { width: 18px; height: 18px; }

.history-item-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-item-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-date {
  font-size: 12px;
  color: var(--muted);
}

.greeting-bubble::before {
  content: "";
  position: absolute;
  left: 0;
  top: 14px;
  bottom: 14px;
  width: 4px;
  border-radius: 4px;
  background: linear-gradient(180deg, var(--primary), var(--accent));
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-card);
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 5px;
  margin-bottom: 22px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 14px;
  border: none;
  background: transparent;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
  transition: background .2s var(--ease), color .2s var(--ease), box-shadow .2s var(--ease);
}

.tab-icon { width: 18px; height: 18px; flex-shrink: 0; }

.tab-btn.active {
  background: var(--card-bg);
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(30, 27, 46, 0.08);
}

.tab-btn:not(.active):hover {
  color: var(--ink);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 40px 16px;
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  background: var(--bg);
  transition: border-color .2s var(--ease), background .2s var(--ease), transform .2s var(--ease);
}

.dropzone-icon {
  width: 30px;
  height: 30px;
  color: var(--primary);
}

.dropzone:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.dropzone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
}

#youtubeInput {
  width: 100%;
  min-height: 44px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  background: var(--bg);
  transition: border-color .2s var(--ease), background .2s var(--ease);
}

#youtubeInput:hover { border-color: #c9c3e3; }

.primary-btn, .secondary-btn {
  font-family: inherit;
  cursor: pointer;
}

.primary-btn:focus-visible,
.secondary-btn:focus-visible,
.tab-btn:focus-visible,
#youtubeInput:focus-visible,
.dropzone:focus-within {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.primary-btn {
  margin-top: 22px;
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 18px;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.1px;
  box-shadow: 0 8px 20px -6px rgba(79, 70, 229, 0.55);
  transition: transform .15s var(--ease), box-shadow .15s var(--ease), opacity .15s var(--ease);
}

.primary-btn .btn-icon { width: 18px; height: 18px; }

.primary-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px -6px rgba(79, 70, 229, 0.6);
}

.primary-btn:active { transform: translateY(0); }
.primary-btn:disabled { opacity: .6; cursor: not-allowed; transform: none; box-shadow: none; }

.secondary-btn {
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  transition: background .2s var(--ease), border-color .2s var(--ease);
}

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

.status {
  margin-top: 18px;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}

.status-text-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.status-estimate {
  font-size: 12.5px;
  font-weight: 500;
  color: #9089a8;
}

.progress-track {
  margin-top: 12px;
  height: 6px;
  border-radius: 6px;
  background: var(--primary-light);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 1s linear;
}

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

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

.error {
  margin-top: 18px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
}

.result-card { padding: 0; overflow: hidden; }

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 22px 26px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.result-header h2 {
  margin: 0;
  font-family: 'Playfair Display', 'Inter', serif;
  font-size: 19px;
  font-weight: 700;
}

.result-actions { display: flex; gap: 10px; }
.result-actions .primary-btn { margin-top: 0; width: auto; }

.result-preview {
  padding: 26px;
  line-height: 1.7;
  font-size: 14.5px;
  max-height: 70vh;
  overflow-y: auto;
}

.result-preview h1 {
  font-family: 'Playfair Display', 'Inter', serif;
  font-size: 23px;
  border-bottom: 3px solid var(--primary);
  padding-bottom: 10px;
}
.result-preview h2 { font-size: 18px; color: var(--primary-dark); margin-top: 28px; }
.result-preview h3 { font-size: 15.5px; margin-top: 20px; }
.result-preview blockquote {
  border-left: 4px solid var(--accent);
  background: #fffbeb;
  margin: 14px 0;
  padding: 11px 16px;
  border-radius: 10px;
}
.result-preview blockquote p { margin: 0; }
.result-preview hr { border: none; border-top: 1px solid var(--border); margin: 22px 0; }

#secretTrigger { cursor: default; }

.secret-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 13, 26, 0.6);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}

.secret-panel {
  background: #15131f;
  color: #e7e4f0;
  width: 100%;
  max-width: 680px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  border: 1px solid #2c2840;
  box-shadow: 0 30px 60px -12px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.secret-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid #2c2840;
}

.secret-panel-header h2 {
  margin: 0;
  font-family: 'Playfair Display', 'Inter', serif;
  font-size: 18px;
}

.secret-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: #a39ec2;
  cursor: pointer;
  border-radius: 8px;
}

.secret-close:hover { background: #221f33; color: #fff; }
.secret-close svg { width: 18px; height: 18px; }

.secret-tabs {
  display: flex;
  gap: 6px;
  padding: 14px 22px 0;
}

.secret-tab-btn {
  padding: 9px 14px;
  border: none;
  background: transparent;
  color: #a39ec2;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  border-bottom: 2px solid transparent;
  transition: color .2s var(--ease), border-color .2s var(--ease);
}

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

.secret-tab-panel { display: none; padding: 20px 22px 24px; overflow-y: auto; }
.secret-tab-panel.active { display: block; }

.usage-summary {
  display: flex;
  gap: 24px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.usage-summary .stat { display: flex; flex-direction: column; gap: 2px; }
.usage-summary .stat-value { font-size: 22px; font-weight: 700; color: #fff; font-family: 'Playfair Display', serif; }
.usage-summary .stat-label { font-size: 12px; color: #9089a8; }

.usage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.usage-table th {
  text-align: left;
  padding: 8px 10px;
  color: #9089a8;
  font-weight: 600;
  border-bottom: 1px solid #2c2840;
}

.usage-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #221f33;
  color: #d8d4e8;
}

.history-actions { margin-bottom: 14px; }
.history-actions .secondary-btn {
  display: inline-flex;
  background: #221f33;
  border-color: #2c2840;
  color: #e7e4f0;
  text-decoration: none;
}
.history-actions .secondary-btn:hover { background: #2c2840; }

.history-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  background: #0f0d1a;
  border: 1px solid #2c2840;
  border-radius: var(--radius-sm);
  padding: 16px;
  max-height: 50vh;
  overflow-y: auto;
  margin: 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

@media (max-width: 540px) {
  .app-header { flex-wrap: wrap; }
  .logo-badge { width: 48px; height: 48px; border-radius: 13px; }
  .logo-badge svg { width: 24px; height: 24px; }
  .app-header h1 { font-size: 26px; }
  .result-actions { width: 100%; }
  .result-actions .primary-btn, .result-actions .secondary-btn { flex: 1; }
  .tab-btn { flex-direction: column; gap: 4px; font-size: 12.5px; padding: 10px 6px; }
}
