:root {
  --bg: #faf8f5;
  --bg-surface: #ffffff;
  --text-primary: #1a1a1a;
  --text-secondary: #6b6560;
  --text-muted: #9e9892;
  --border: #e8e4df;
  --border-focus: #b8b0a6;
  --accent-primary: #1a1a1a;
  --accent-danger: #c62828;
  --accent-danger-hover: #9a1f1f;
  --accent-muted: #78736d;
  --accent-muted-hover: #5a5550;
  --font-body: 'Source Sans 3', system-ui, -apple-system, sans-serif;
  --font-display: 'Newsreader', Georgia, serif;
  --font-screenplay: 'Courier Prime', 'Courier New', Courier, monospace;
}

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

html {
  scroll-behavior: smooth;
}

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

/* Subtle grain texture overlay */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0.025;
  pointer-events: none;
  z-index: 1000;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
}

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

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

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

.app-container {
  max-width: 760px;
  margin: 0 auto;
  padding: 40px 24px 60px;
  animation: fadeInUp 0.6s ease-out;
}

.app-header {
  margin-bottom: 48px;
  text-align: left;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--border);
}

.app-title {
  font-family: var(--font-display);
  font-size: 2.8rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.app-subtitle {
  font-size: 1rem;
  font-weight: 300;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* Prompt Section */
.prompt-section {
  margin-bottom: 24px;
  animation: fadeInUp 0.6s ease-out 0.1s both;
}

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

.prompt-label {
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}

.toggle-label {
  cursor: pointer;
  user-select: none;
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: color 0.2s;
}

.toggle-label:hover {
  color: var(--text-secondary);
}

.toggle-label input[type="checkbox"] {
  accent-color: var(--text-primary);
  cursor: pointer;
}

.prompt-textarea,
.prompt-input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-primary);
  background: var(--bg-surface);
  resize: vertical;
  transition: border-color 0.2s, box-shadow 0.2s;
  line-height: 1.5;
}

.prompt-textarea:focus,
.prompt-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.06);
}

.prompt-textarea::placeholder,
.prompt-input::placeholder {
  color: var(--text-muted);
  font-weight: 300;
}

/* Controls */
.controls-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 36px;
  animation: fadeInUp 0.6s ease-out 0.2s both;
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s, transform 0.1s;
  white-space: nowrap;
}

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

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

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

.btn-primary:hover:not(:disabled) {
  background: #333;
}

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

.btn-danger:hover:not(:disabled) {
  background: var(--accent-danger-hover);
}

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

.btn-muted:hover:not(:disabled) {
  background: var(--accent-muted-hover);
}

.screenplay-toggle {
  cursor: pointer;
  user-select: none;
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 4px;
  transition: color 0.2s;
}

.screenplay-toggle:hover {
  color: var(--text-secondary);
}

.screenplay-toggle input[type="checkbox"] {
  accent-color: var(--text-primary);
  cursor: pointer;
}

/* Story Display */
.story-area {
  min-height: 100px;
  animation: fadeInUp 0.6s ease-out 0.3s both;
}

.story-content {
  white-space: pre-wrap;
  font-family: var(--font-display);
  font-size: 1.15rem;
  line-height: 1.75;
  color: var(--text-primary);
  letter-spacing: 0.005em;
}

.story-content.screenplay {
  font-family: var(--font-screenplay);
  font-size: 1rem;
  line-height: 1.6;
}

.story-content.has-content {
  padding: 28px 0;
  border-top: 1px solid var(--border);
}

/* 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.4;
}

.empty-state-text {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-style: italic;
  font-weight: 300;
}

/* Loader */
.loader {
  margin-top: 20px;
  padding: 16px 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 300;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideIn 0.3s ease-out;
}

.loader-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: pulse 1.2s ease-in-out infinite;
}

.loader-dot:nth-child(2) { animation-delay: 0.2s; }
.loader-dot:nth-child(3) { animation-delay: 0.4s; }

/* Footer */
.app-footer {
  margin-top: 60px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.8;
  animation: fadeInUp 0.6s ease-out 0.4s both;
}

.app-footer a {
  color: var(--text-secondary);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s, color 0.2s;
}

.app-footer a:hover {
  color: var(--text-primary);
  border-bottom-color: var(--text-primary);
}

.footer-sep {
  margin: 0 8px;
  color: var(--border);
}

/* Settings Panel */
.settings-toggle {
  margin-top: 16px;
  animation: fadeInUp 0.6s ease-out 0.25s both;
}

.settings-btn {
  background: none;
  border: none;
  font-family: var(--font-body);
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 0;
  transition: color 0.2s;
  letter-spacing: 0.02em;
}

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

.settings-panel {
  margin-top: 12px;
  padding: 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  animation: slideIn 0.3s ease-out;
}

.settings-field {
  margin-bottom: 14px;
}

.settings-field:last-child {
  margin-bottom: 0;
}

.settings-field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.settings-field input,
.settings-field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text-primary);
  background: var(--bg);
  transition: border-color 0.2s;
}

.settings-field input:focus,
.settings-field select:focus {
  outline: none;
  border-color: var(--border-focus);
}

/* Mobile adjustments */
@media (max-width: 640px) {
  .app-container {
    padding: 24px 16px 40px;
  }

  .app-title {
    font-size: 2rem;
  }

  .controls-row {
    gap: 8px;
  }

  .btn {
    padding: 9px 14px;
    font-size: 0.82rem;
  }

  .story-content {
    font-size: 1.05rem;
  }
}