:root {
  --primary: #667eea;
  --primary-dark: #5a67d8;
  --secondary: #764ba2;
  --accent: #f093fb;
  --bg: #0f0f23;
  --card-bg: #1a1a2e;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #2d3748;
  --success: #48bb78;
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  min-height: 100vh;
  color: var(--text);
  line-height: 1.6;
}

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 40px 20px;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 40px;
}

h1 {
  font-size: 3rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
  letter-spacing: -1px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 1.2rem;
}

/* Characters */
.characters {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 40px;
  flex-wrap: wrap;
}

.character {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.character-img-wrapper {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid transparent;
  background: linear-gradient(var(--card-bg), var(--card-bg)) padding-box,
              linear-gradient(135deg, var(--primary), var(--secondary)) border-box;
  box-shadow: 0 8px 32px rgba(102, 126, 234, 0.2);
  transition: transform 0.3s, box-shadow 0.3s;
}

.character-img-wrapper:hover {
  transform: translateY(-5px) scale(1.05);
  box-shadow: 0 12px 40px rgba(102, 126, 234, 0.3);
}

.character-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.character-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}

.character-tag {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--card-bg);
  padding: 2px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

/* Form */
.form-card {
  background: var(--card-bg);
  border-radius: 24px;
  padding: 40px;
  border: 1px solid var(--border);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  margin-bottom: 40px;
}

.form-group {
  margin-bottom: 28px;
}

label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
  font-size: 1rem;
}

.label-icon {
  font-size: 1.2rem;
}

textarea {
  width: 100%;
  padding: 16px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 16px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  resize: vertical;
  transition: border-color 0.2s, box-shadow 0.2s;
}

textarea::placeholder {
  color: var(--text-muted);
}

textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

/* Button */
button[type="submit"] {
  width: 100%;
  padding: 18px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: white;
  border: none;
  border-radius: 16px;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 8px 32px rgba(102, 126, 234, 0.3);
}

button[type="submit"]:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(102, 126, 234, 0.4);
}

button[type="submit"]:active:not(:disabled) {
  transform: translateY(0);
}

button[type="submit"]:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-icon {
  font-size: 1.4rem;
}

/* Loading */
.loading {
  display: none;
  text-align: center;
  padding: 60px 20px;
}

.loading.active {
  display: block;
}

.loading-content {
  max-width: 400px;
  margin: 0 auto;
}

.spinner {
  width: 60px;
  height: 60px;
  border: 4px solid rgba(102, 126, 234, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 24px;
}

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

.loading-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}

.loading-status {
  color: var(--text-muted);
  margin-bottom: 24px;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

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

/* Story Result */
.story-result {
  display: none;
}

.story-result.active {
  display: block;
}

.story-title {
  text-align: center;
  font-size: 2.2rem;
  font-weight: 800;
  margin-bottom: 40px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.panels {
  display: flex;
  flex-direction: column;
  gap: 40px;
  margin-bottom: 40px;
}

.panel {
  background: var(--card-bg);
  border-radius: 24px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  transition: transform 0.3s;
}

.panel:hover {
  transform: translateY(-4px);
}

.panel-image-wrapper {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

.panel-image-wrapper.loading {
  display: flex;
  align-items: center;
  justify-content: center;
}

.panel-image-wrapper.loading .spinner {
  width: 40px;
  height: 40px;
  margin: 0;
}

.panel-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.panel-text {
  padding: 28px;
  font-size: 1.15rem;
  line-height: 1.7;
  color: var(--text);
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
}

.panel-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}

.new-story-btn {
  display: block;
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  padding: 16px;
  background: transparent;
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: 16px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
}

.new-story-btn:hover {
  border-color: var(--primary);
  background: rgba(102, 126, 234, 0.1);
}

/* Error state */
.error-message {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fc8181;
  padding: 16px;
  border-radius: 12px;
  margin-bottom: 20px;
  text-align: center;
}

/* Responsive */
@media (max-width: 640px) {
  h1 {
    font-size: 2rem;
  }
  
  .characters {
    gap: 16px;
  }
  
  .character-img-wrapper {
    width: 80px;
    height: 80px;
  }
  
  .form-card {
    padding: 24px;
  }
  
  .story-title {
    font-size: 1.6rem;
  }
}
