/* Reset and Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  color: #e0e0e0;
  min-height: 100vh;
}

/* Main app container - CENTERED with flexbox */
.app {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

/* Container for all content - keeps max width */
.container {
  width: 100%;
  max-width: 800px;
}

/* Header */
.app-header {
  text-align: center;
  padding: 30px;
  margin-bottom: 30px;
  background: rgba(168, 85, 247, 0.05);
  border-bottom: 3px solid #a855f7;
  border-radius: 12px;
}

.app-header h1 {
  font-size: 2.5rem;
  background: linear-gradient(135deg, #a855f7 0%, #c084fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 10px;
  font-weight: 700;
}

.passage-id {
  color: #888;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Story Selection */
.story-select {
  background: rgba(37, 37, 37, 0.8);
  padding: 40px;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(168, 85, 247, 0.2);
}

.story-select h2 {
  color: #a855f7;
  margin-bottom: 30px;
  text-align: center;
  font-size: 1.8rem;
}

.story-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-bottom: 30px;
}

.story-button {
  padding: 20px;
  background: rgba(51, 51, 51, 0.8);
  color: #e0e0e0;
  border: 2px solid #444;
  border-radius: 12px;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: left;
}

.story-button:hover {
  background: rgba(58, 58, 58, 0.9);
  border-color: #a855f7;
  transform: translateX(5px);
}

.story-button.selected {
  background: rgba(168, 85, 247, 0.2);
  border-color: #a855f7;
  color: #fff;
}

.start-button {
  width: 100%;
  padding: 18px;
  background: linear-gradient(135deg, #a855f7 0%, #9333ea 100%);
  color: #ffffff;
  border: none;
  border-radius: 12px;
  font-size: 1.2rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.start-button:hover {
  background: linear-gradient(135deg, #c084fc 0%, #a855f7 100%);
  transform: scale(1.02);
}

/* Passage Display */
.passage {
  background: rgba(37, 37, 37, 0.8);
  padding: 40px;
  border-radius: 16px;
  margin-bottom: 20px;
  line-height: 1.8;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(168, 85, 247, 0.1);
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.1rem;
}

.passage p {
  margin-bottom: 15px;
}

.passage p:last-child {
  margin-bottom: 0;
}

/* Markdown Styles */
.passage h1,
.passage h2,
.passage h3 {
  color: #a855f7;
  margin-top: 1.5em;
  margin-bottom: 0.5em;
}

.passage h1 {
  font-size: 2rem;
  border-bottom: 2px solid #a855f7;
  padding-bottom: 0.3em;
}

.passage h2 {
  font-size: 1.6rem;
}

.passage h3 {
  font-size: 1.3rem;
}

.passage strong {
  color: #c084fc;
  font-weight: 600;
}

.passage em {
  color: #d8b4fe;
  font-style: italic;
}

.passage code {
  background: rgba(26, 26, 26, 0.6);
  color: #ff6b6b;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: 'Monaco', monospace;
  font-size: 0.9em;
}

.passage a {
  color: #a855f7;
  text-decoration: none;
  border-bottom: 1px solid #a855f7;
}

.passage a:hover {
  color: #c084fc;
}

/* Choices */
.choices {
  background: rgba(37, 37, 37, 0.8);
  padding: 40px;
  border-radius: 16px;
  margin-bottom: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(168, 85, 247, 0.1);
}

.choices h3 {
  margin-bottom: 20px;
  color: #a855f7;
  font-size: 1.3rem;
  text-align: center;
}

.choice-button {
  display: block;
  width: 100%;
  padding: 15px 20px;
  margin-bottom: 12px;
  background: rgba(51, 51, 51, 0.8);
  color: #e0e0e0;
  border: 2px solid #a855f7;
  border-radius: 12px;
  font-size: 1.05rem;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: left;
}

.choice-button:hover:not(:disabled) {
  background: linear-gradient(135deg, #a855f7 0%, #9333ea 100%);
  color: #ffffff;
  transform: translateX(5px);
}

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

.choice-button:last-child {
  margin-bottom: 0;
}

/* Ending */
.ending {
  text-align: center;
  padding: 50px 30px;
  background: rgba(37, 37, 37, 0.8);
  border-radius: 16px;
  margin-bottom: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  border: 2px solid #a855f7;
}

.ending h2 {
  color: #a855f7;
  margin-bottom: 25px;
  font-size: 2.2rem;
}

/* Buttons */
.restart-button,
.small-button,
.retry-button {
  padding: 12px 28px;
  background: linear-gradient(135deg, #a855f7 0%, #9333ea 100%);
  color: #ffffff;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.restart-button:hover,
.small-button:hover,
.retry-button:hover {
  background: linear-gradient(135deg, #c084fc 0%, #a855f7 100%);
  transform: translateY(-2px);
}

/* Footer */
.app-footer {
  text-align: center;
  padding: 20px 0;
  margin-top: 20px;
  border-top: 2px solid rgba(168, 85, 247, 0.2);
}

/* Loading & Error */
.loading,
.error {
  text-align: center;
  padding: 50px 30px;
  background: rgba(37, 37, 37, 0.8);
  border-radius: 16px;
  border: 1px solid rgba(168, 85, 247, 0.2);
}

.loading {
  color: #a855f7;
  font-size: 1.3rem;
}

.error {
  color: #ff6b6b;
}

.error h2 {
  margin-bottom: 15px;
  color: #ff6b6b;
}

.error button {
  margin-top: 20px;
}

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

  .app-header h1 {
    font-size: 2rem;
  }

  .passage,
  .choices,
  .story-select {
    padding: 25px;
  }
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.passage,
.choices,
.ending {
  animation: fadeIn 0.4s ease-out;
}

/* Render Directives Container */
.render-directives {
  margin: 25px 0;
  animation: fadeIn 0.5s ease-out;
}

/* Individual directive spacing */
.render-directives>* {
  margin: 20px 0;
}

/* Add a subtle glow effect for render directive containers */
.render-directives>div {
  animation: fadeIn 0.6s ease-out;
}

/* Save/Load Menus */
.save-menu,
.load-menu {
  background: rgba(37, 37, 37, 0.8);
  padding: 40px;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(168, 85, 247, 0.2);
}

/* Save Form */
.save-form {
  margin-bottom: 30px;
}

.save-form label {
  display: block;
  color: #a855f7;
  margin-bottom: 10px;
  font-size: 1.1rem;
  font-weight: 600;
}

.save-input {
  width: 100%;
  padding: 15px;
  background: rgba(51, 51, 51, 0.8);
  border: 2px solid #a855f7;
  border-radius: 8px;
  color: #e0e0e0;
  font-size: 1rem;
  margin-bottom: 20px;
  transition: border-color 0.3s;
}

.save-input:focus {
  outline: none;
  border-color: #c084fc;
  background: rgba(58, 58, 58, 0.9);
}

.save-buttons {
  display: flex;
  gap: 15px;
}

.save-button,
.cancel-button,
.load-button,
.delete-button,
.back-button {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.save-button,
.load-button {
  background: linear-gradient(135deg, #a855f7 0%, #9333ea 100%);
  color: #ffffff;
  flex: 1;
}

.save-button:hover,
.load-button:hover {
  background: linear-gradient(135deg, #c084fc 0%, #a855f7 100%);
  transform: translateY(-2px);
}

.cancel-button,
.back-button {
  background: rgba(51, 51, 51, 0.8);
  color: #e0e0e0;
  border: 2px solid #666;
  flex: 1;
}

.cancel-button:hover,
.back-button:hover {
  background: rgba(58, 58, 58, 0.9);
  border-color: #888;
}

.delete-button {
  background: rgba(255, 107, 107, 0.2);
  color: #ff6b6b;
  border: 2px solid #ff6b6b;
  padding: 8px 16px;
  font-size: 0.9rem;
}

.delete-button:hover {
  background: rgba(255, 107, 107, 0.3);
  border-color: #ff8888;
}

/* Save Message */
.save-message {
  padding: 15px 20px;
  border-radius: 8px;
  margin-top: 20px;
  font-size: 1rem;
  text-align: center;
  animation: fadeIn 0.3s ease-out;
}

.save-message.success {
  background: rgba(81, 207, 102, 0.2);
  border: 2px solid #51cf66;
  color: #51cf66;
}

.save-message.error {
  background: rgba(255, 107, 107, 0.2);
  border: 2px solid #ff6b6b;
  color: #ff6b6b;
}

/* Save Info */
.save-info {
  margin-top: 30px;
  padding: 20px;
  background: rgba(26, 26, 26, 0.6);
  border-radius: 8px;
  border: 1px solid rgba(168, 85, 247, 0.2);
}

.save-info p {
  color: #c084fc;
  margin: 5px 0;
}

/* Save List */
.save-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-bottom: 30px;
  max-height: 500px;
  overflow-y: auto;
  padding-right: 10px;
}

.save-list::-webkit-scrollbar {
  width: 8px;
}

.save-list::-webkit-scrollbar-track {
  background: rgba(26, 26, 26, 0.6);
  border-radius: 4px;
}

.save-list::-webkit-scrollbar-thumb {
  background: #a855f7;
  border-radius: 4px;
}

.save-slot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  background: rgba(51, 51, 51, 0.8);
  border: 2px solid rgba(168, 85, 247, 0.3);
  border-radius: 12px;
  transition: all 0.3s ease;
}

.save-slot:hover {
  background: rgba(58, 58, 58, 0.9);
  border-color: #a855f7;
  transform: translateX(5px);
}

.save-slot-info {
  flex: 1;
}

.save-slot-info h3 {
  color: #a855f7;
  margin-bottom: 8px;
  font-size: 1.2rem;
}

.save-detail {
  color: #c084fc;
  font-size: 0.9rem;
  margin: 3px 0;
}

.save-date {
  color: #888;
  font-size: 0.85rem;
  margin-top: 8px;
}

.save-slot-actions {
  display: flex;
  gap: 10px;
}

.no-saves {
  text-align: center;
  color: #888;
  padding: 40px;
  font-size: 1.1rem;
}

/* Footer Buttons */
.footer-buttons {
  display: flex;
  gap: 15px;
  justify-content: center;
  flex-wrap: wrap;
}

.load-from-menu-button {
  width: 100%;
  padding: 15px;
  margin-top: 10px;
  background: rgba(51, 51, 51, 0.8);
  color: #a855f7;
  border: 2px solid #a855f7;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.load-from-menu-button:hover {
  background: rgba(168, 85, 247, 0.2);
  border-color: #c084fc;
  transform: scale(1.02);
}

/* Responsive */
@media (max-width: 768px) {
  .save-slot {
    flex-direction: column;
    gap: 15px;
  }

  .save-slot-actions {
    width: 100%;
  }

  .save-button,
  .cancel-button,
  .load-button,
  .delete-button {
    flex: 1;
  }

  .footer-buttons {
    flex-direction: column;
  }

  .footer-buttons .small-button {
    width: 100%;
  }
}