/* ============================================================
   ShortStory Forge - Design System
   A premium dark-mode first UI with glassmorphism effects
   ============================================================ */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Noto+Serif+SC:wght@400;600;700&display=swap');

/* --- CSS Custom Properties --- */
:root {
  /* Color Palette - Warm Reader (Paper Theme) */
  --bg-primary: #f8f5ee;
  --bg-secondary: #f0eadd;
  --bg-tertiary: #e6decb;
  --bg-card: rgba(255, 255, 255, 0.6);
  --bg-glass: rgba(255, 255, 255, 0.4);
  --bg-glass-hover: rgba(255, 255, 255, 0.7);
  --bg-glass-active: rgba(255, 255, 255, 0.9);

  --text-primary: #2c2825;
  --text-secondary: #645c55;
  --text-muted: #8c8279;
  --text-accent: #8b5a2b;

  --accent-primary: #8b5a2b;
  --accent-primary-hover: #6a4420;
  --accent-secondary: #5e7c60;
  --accent-tertiary: #b05e5e;
  --accent-success: #5e7c60;
  --accent-warning: #d99b48;
  --accent-danger: #b05e5e;
  --accent-pink: #a86c87;

  --gradient-accent: linear-gradient(135deg, #8b5a2b 0%, #a47864 100%);
  --gradient-warm: linear-gradient(135deg, #d99b48 0%, #b05e5e 50%, #a86c87 100%);
  --gradient-card: linear-gradient(135deg, rgba(139, 90, 43, 0.05) 0%, rgba(94, 124, 96, 0.05) 100%);
  --gradient-glow: radial-gradient(ellipse at center, rgba(139, 90, 43, 0.1) 0%, transparent 70%);

  --border-default: rgba(139, 90, 43, 0.15);
  --border-hover: rgba(139, 90, 43, 0.3);
  --border-accent: rgba(139, 90, 43, 0.4);

  --shadow-sm: 0 1px 3px rgba(139, 90, 43, 0.05);
  --shadow-md: 0 4px 12px rgba(139, 90, 43, 0.08);
  --shadow-lg: 0 8px 32px rgba(139, 90, 43, 0.12);
  --shadow-glow: 0 0 20px rgba(139, 90, 43, 0.15);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-serif: 'Noto Serif SC', serif;

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

/* Background ambient glow */
body::before {
  content: '';
  position: fixed;
  top: -30%;
  left: -10%;
  width: 60%;
  height: 60%;
  background: radial-gradient(ellipse, rgba(139, 90, 43, 0.05) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: '';
  position: fixed;
  bottom: -20%;
  right: -10%;
  width: 50%;
  height: 50%;
  background: radial-gradient(ellipse, rgba(94, 124, 96, 0.04) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* --- Layout --- */
.app-container {
  position: relative;
  z-index: 1;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
}

/* --- Header --- */
.header {
  padding: 24px 0;
  border-bottom: 1px solid var(--border-default);
  margin-bottom: 32px;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: var(--gradient-accent);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: var(--shadow-glow);
}

.logo-text {
  font-size: 1.25rem;
  font-weight: 700;
  background: var(--gradient-accent);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* --- Navigation Tabs --- */
.nav-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-glass);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 4px;
  margin-bottom: 32px;
}

.nav-tab {
  flex: 1;
  padding: 12px 20px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-normal);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.nav-tab:hover {
  color: var(--text-primary);
  background: var(--bg-glass-hover);
}

.nav-tab.active {
  color: var(--text-primary);
  background: var(--bg-tertiary);
  box-shadow: var(--shadow-sm);
}

.nav-tab-icon {
  font-size: 1.1rem;
}

/* --- Panels --- */
.panel {
  display: none;
  animation: fadeIn var(--transition-normal) ease-out;
}

.panel.active {
  display: block;
}

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

/* --- Cards --- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 24px;
  backdrop-filter: blur(12px);
  transition: all var(--transition-normal);
}

.card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-md);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* --- Section Title --- */
.section-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-default);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent-primary);
  color: white;
  box-shadow: 0 2px 8px rgba(139, 90, 43, 0.3);
}

.btn-primary:hover {
  background: var(--accent-primary-hover);
  box-shadow: 0 4px 16px rgba(139, 90, 43, 0.4);
}

.btn-secondary {
  background: var(--bg-glass);
  border-color: var(--border-default);
  color: var(--text-primary);
}

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

.btn-success {
  background: var(--accent-success);
  color: white;
}

.btn-danger {
  background: transparent;
  border-color: rgba(176, 94, 94, 0.3);
  color: var(--accent-danger);
}

.btn-danger:hover {
  background: rgba(176, 94, 94, 0.1);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  color: var(--text-primary);
  background: var(--bg-glass);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.8rem;
}

.btn-lg {
  padding: 14px 28px;
  font-size: 1rem;
  border-radius: var(--radius-lg);
}

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

.btn-icon {
  padding: 8px;
  border-radius: var(--radius-sm);
}

/* --- Gradient Button --- */
.btn-gradient {
  background: var(--gradient-accent);
  color: white;
  border: none;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(139, 90, 43, 0.3);
  position: relative;
  overflow: hidden;
}

.btn-gradient::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 0%, rgba(255,255,255,0.1) 50%, transparent 100%);
  transform: translateX(-100%);
  transition: transform 0.6s ease;
}

.btn-gradient:hover::before {
  transform: translateX(100%);
}

.btn-gradient:hover {
  box-shadow: 0 6px 24px rgba(139, 90, 43, 0.4);
}

/* --- Forms --- */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-glass);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  transition: all var(--transition-fast);
  outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(139, 90, 43, 0.15);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-muted);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23645c55' viewBox='0 0 16 16'%3E%3Cpath d='M4.646 5.646a.5.5 0 01.708 0L8 8.293l2.646-2.647a.5.5 0 01.708.708l-3 3a.5.5 0 01-.708 0l-3-3a.5.5 0 010-.708z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* --- Grid Layout --- */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

@media (max-width: 768px) {
  .grid-2, .grid-3, .form-row {
    grid-template-columns: 1fr;
  }
}

/* --- Style Cards --- */
.style-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.style-card {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  transition: all var(--transition-normal);
  position: relative;
  overflow: hidden;
}

.style-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--gradient-accent);
  opacity: 0;
  transition: opacity var(--transition-normal);
}

.style-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.style-card:hover::before {
  opacity: 1;
}

.style-card.selected {
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-glow);
}

.style-card.selected::before {
  opacity: 1;
}

.style-card-name {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.style-card-author {
  font-size: 0.8rem;
  color: var(--text-accent);
  margin-bottom: 8px;
}

.style-card-desc {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.style-card-tone {
  margin-top: 10px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tone-tag {
  font-size: 0.7rem;
  padding: 3px 8px;
  background: rgba(139, 90, 43, 0.12);
  color: var(--text-accent);
  border-radius: 20px;
  border: 1px solid rgba(139, 90, 43, 0.2);
}

/* --- RSS Feed Section --- */
.feed-url-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.feed-url-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.feed-url-row .form-input {
  flex: 1;
}

.feed-results {
  margin-top: 20px;
}

.suggestion-card {
  background: var(--bg-glass);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: all var(--transition-normal);
}

.suggestion-card:hover {
  border-color: var(--accent-primary);
  background: var(--bg-glass-hover);
}

.suggestion-card.selected {
  border-color: var(--accent-primary);
  background: rgba(139, 90, 43, 0.08);
}

.suggestion-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.suggestion-idea {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.suggestion-meta {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.suggestion-tag {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 12px;
  background: rgba(94, 124, 96, 0.1);
  color: var(--accent-secondary);
  border: 1px solid rgba(94, 124, 96, 0.2);
}

/* --- Progress Panel --- */
.progress-container {
  max-width: 800px;
  margin: 0 auto;
}

.progress-bar-wrapper {
  background: var(--bg-glass);
  border-radius: 20px;
  height: 8px;
  margin-bottom: 16px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--gradient-accent);
  border-radius: 20px;
  transition: width 0.5s ease;
  width: 0%;
}

.progress-status {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 24px;
  font-size: 0.9rem;
}

.progress-log {
  background: var(--bg-glass);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 16px;
  max-height: 400px;
  overflow-y: auto;
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 0.82rem;
  line-height: 1.8;
}

.progress-log-entry {
  padding: 4px 0;
  border-bottom: 1px solid var(--border-default);
  animation: slideIn 0.3s ease-out;
}

.progress-log-entry:last-child {
  border-bottom: none;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}

/* --- Story Preview --- */
.story-preview {
  max-width: 800px;
  margin: 0 auto;
}

.chapter-preview {
  margin-bottom: 32px;
  padding: 24px;
  background: var(--bg-glass);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
}

.chapter-title {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chapter-content {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  line-height: 2;
  color: var(--text-primary);
  white-space: pre-wrap;
}

.chapter-word-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-sans);
}

/* --- Project List --- */
.project-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--bg-glass);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  transition: all var(--transition-normal);
  cursor: pointer;
}

.project-item:hover {
  border-color: var(--border-hover);
  background: var(--bg-glass-hover);
}

.project-info {
  flex: 1;
}

.project-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.project-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  gap: 12px;
}

.project-actions {
  display: flex;
  gap: 8px;
}

/* --- Status Badges --- */
.badge {
  font-size: 0.7rem;
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 500;
}

.badge-created {
  background: rgba(156, 163, 180, 0.15);
  color: var(--text-secondary);
}

.badge-writing {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-secondary);
}

.badge-completed {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-success);
}

.badge-error {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-danger);
}

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state-text {
  font-size: 0.95rem;
  margin-bottom: 20px;
}

/* --- Loading Spinner --- */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-default);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

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

/* --- Toast --- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 12px 20px;
  color: var(--text-primary);
  font-size: 0.85rem;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s ease-out;
  max-width: 400px;
}

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

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 900;
  display: none;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease-out;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: 32px;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 24px;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

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

::-webkit-scrollbar-thumb:hover {
  background: var(--border-hover);
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .app-container {
    padding: 0 16px;
  }

  .header-inner {
    flex-direction: column;
    align-items: flex-start;
  }

  .nav-tabs {
    flex-wrap: wrap;
  }

  .nav-tab {
    flex: 1 1 40%;
  }

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