*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #0b4570;
  color: #111;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  padding: 16px;
  text-align: center;
  color: #fff;
}

.app-header h1 {
  margin: 0;
  font-size: 1.8rem;
}

.app-header .tagline {
  margin: 4px 0 0;
  font-size: 0.95rem;
  opacity: 0.9;
}

.app-main {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 980px;
  margin: 0 auto 24px;
}

.form-card,
.story-card,
.info-card {
  background: #ffffff;
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}

/* Form */

.form-card h2 {
  margin-top: 0;
}

.form-row {
  display: flex;
  flex-direction: column;
  margin-bottom: 10px;
}

.form-row label {
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.form-row input,
.form-row textarea,
.chapter-select-row select {
  padding: 8px;
  border-radius: 6px;
  border: 1px solid #c7d1dd;
  font-size: 0.95rem;
}

.form-row textarea {
  resize: vertical;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

button {
  border-radius: 999px;
  border: none;
  cursor: pointer;
  padding: 8px 16px;
  font-size: 0.9rem;
  font-weight: 600;
}

button:disabled {
  opacity: 0.6;
  cursor: default;
}

.primary-btn {
  background: #0077ff;
  color: #fff;
}

.secondary-btn {
  background: #f2f5f9;
  color: #111;
}

.danger-btn {
  background: #ff4d4d;
  color: #fff;
}

/* Story */

.story-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.story-header h2 {
  margin: 0;
}

.chapter-select-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
}

.chapter-select-row label {
  font-weight: 600;
}

.chapter-select-row select {
  min-width: 140px;
}

.chapter-info {
  opacity: 0.7;
}

#storyContainer h3 {
  margin-top: 0;
  margin-bottom: 10px;
}

/* Viktigt: texten inte ihoptryckt */
#storyContent {
  white-space: pre-line; /* bevarar radbrytningar */
  line-height: 1.5;
  font-size: 0.97rem;
}

/* Info-kort */

.info-card h3 {
  margin-top: 0;
}

/* Spinner overlay */

.spinner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.spinner-overlay.hidden {
  display: none;
}

.spinner-box {
  background: #ffffff;
  padding: 18px 22px;
  border-radius: 10px;
  text-align: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid #cdd6e0;
  border-top-color: #0077ff;
  margin: 0 auto 8px;
  animation: spin 0.9s linear infinite;
}

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

/* Toast */

.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #222;
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  opacity: 0.96;
  z-index: 1000;
}

.toast.hidden {
  display: none;
}

/* Responsiv layout */

@media (min-width: 900px) {
  .app-main {
    display: grid;
    grid-template-columns: 1.1fr 1.3fr;
    grid-template-rows: auto auto auto;
    gap: 16px;
  }

  .form-card {
    grid-column: 1 / 2;
    grid-row: 1 / 2;
  }

  .story-card {
    grid-column: 2 / 3;
    grid-row: 1 / 3;
  }

  .info-card:nth-of-type(1) {
    grid-column: 1 / 2;
    grid-row: 2 / 3;
  }

  .info-card:nth-of-type(2),
  .info-card:nth-of-type(3) {
    grid-column: 1 / 2;
  }
}
