/* =============================================
   EL CUENTO DEL PERRITO — Estilos
   Diseño para alumnos de 2° grado primaria
   ============================================= */

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

:root {
  --color-inicio: #4caf50;
  --color-inicio-light: #e8f5e9;
  --color-inicio-border: #a5d6a7;
  --color-conflicto: #ff9800;
  --color-conflicto-light: #fff3e0;
  --color-conflicto-border: #ffcc80;
  --color-desenlace: #2196f3;
  --color-desenlace-light: #e3f2fd;
  --color-desenlace-border: #90caf9;
  --color-bg: #fffef7;
  --color-header-bg: #fff8e1;
  --font-main: 'Nunito', sans-serif;
  --font-title: 'Fredoka One', cursive;
  --shadow-card: 0 4px 18px rgba(0,0,0,0.10);
  --radius-card: 20px;
  --radius-chip: 30px;
}

body {
  font-family: var(--font-main);
  background: var(--color-bg);
  color: #333;
  min-height: 100vh;
}

/* ---- HEADER ---- */
header {
  background: linear-gradient(135deg, #fff8e1 0%, #ffe0b2 100%);
  border-bottom: 4px solid #ffcc02;
  padding: 22px 16px 16px;
  text-align: center;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 6px;
}

h1 {
  font-family: var(--font-title);
  font-size: clamp(1.8rem, 5vw, 2.8rem);
  color: #e65100;
  letter-spacing: 1px;
  text-shadow: 2px 2px 0 #ffcc02;
}

.paw {
  font-size: 2rem;
  animation: wobble 2.5s ease-in-out infinite;
}
.paw:last-child { animation-delay: 1.2s; }

@keyframes wobble {
  0%, 100% { transform: rotate(-8deg); }
  50%       { transform: rotate(8deg); }
}

.subtitle {
  font-size: 1rem;
  color: #795548;
  font-weight: 600;
  max-width: 600px;
  margin: 0 auto;
}

/* ---- MAIN ---- */
main {
  max-width: 1050px;
  margin: 28px auto 40px;
  padding: 0 16px;
}

/* ---- STORY TABLE ---- */
.story-table {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: white;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  border: 2.5px solid #ffe082;
}

/* ---- STORY ROW (2-column table row) ---- */
.story-row {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 0;
  min-height: 260px;
}

/* ---- COLUMN: IMAGE ---- */
.col-image {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 22px 16px 22px 22px;
  gap: 10px;
  border-right: 2.5px dashed #ffe082;
  background: #fffdf0;
}

.part-badge {
  font-family: var(--font-title);
  font-size: 1.15rem;
  padding: 6px 18px;
  border-radius: var(--radius-chip);
  font-weight: 400;
  letter-spacing: 0.5px;
  align-self: stretch;
  text-align: center;
}

.badge-inicio    { background: var(--color-inicio-light); color: #2e7d32; border: 2px solid var(--color-inicio-border); }
.badge-conflicto { background: var(--color-conflicto-light); color: #e65100; border: 2px solid var(--color-conflicto-border); }
.badge-desenlace { background: var(--color-desenlace-light); color: #1565c0; border: 2px solid var(--color-desenlace-border); }

.image-frame {
  border-radius: 14px;
  overflow: hidden;
  border: 3px solid #ffe082;
  box-shadow: 0 3px 12px rgba(0,0,0,0.13);
  width: 100%;
  max-width: 220px;
  aspect-ratio: 4/3;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
}

.image-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.frame-inicio    { border-color: var(--color-inicio-border); }
.frame-conflicto { border-color: var(--color-conflicto-border); }
.frame-desenlace { border-color: var(--color-desenlace-border); }

.image-caption {
  font-size: 0.82rem;
  color: #8d6e63;
  font-weight: 700;
  text-align: center;
  font-style: italic;
}

/* ---- COLUMN: WRITE ---- */
.col-write {
  padding: 22px 24px 22px 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---- SUGGESTIONS BOX ---- */
.suggestions-box {
  border-radius: 14px;
  padding: 12px 14px;
  border: 2px dashed;
}

.sb-inicio    { background: var(--color-inicio-light); border-color: var(--color-inicio-border); }
.sb-conflicto { background: var(--color-conflicto-light); border-color: var(--color-conflicto-border); }
.sb-desenlace { background: var(--color-desenlace-light); border-color: var(--color-desenlace-border); }

.sug-title {
  font-size: 0.82rem;
  font-weight: 800;
  color: #5d4037;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.sug-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  font-family: var(--font-main);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 5px 13px;
  border-radius: var(--radius-chip);
  border: none;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, opacity 0.12s;
  box-shadow: 0 2px 5px rgba(0,0,0,0.10);
}

.chip:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.18);
}

.chip:active {
  transform: scale(0.95);
  opacity: 0.85;
}

#chips-inicio    .chip { background: var(--color-inicio); color: white; }
#chips-conflicto .chip { background: var(--color-conflicto); color: white; }
#chips-desenlace .chip { background: var(--color-desenlace); color: white; }

/* ---- WRITE LABEL ---- */
.write-label {
  font-size: 0.92rem;
  color: #4a4a4a;
  font-weight: 600;
}

/* ---- TEXTAREA ---- */
.story-area {
  font-family: var(--font-main);
  font-size: 1.05rem;
  line-height: 1.9;
  border-radius: 12px;
  border: 2.5px solid #e0e0e0;
  padding: 12px 14px;
  resize: vertical;
  width: 100%;
  color: #333;
  background: white;
  transition: border-color 0.2s, box-shadow 0.2s;
  flex: 1;
  /* lined paper effect */
  background-image: repeating-linear-gradient(
    to bottom,
    transparent,
    transparent calc(1.9em - 1px),
    #f0f0f0 calc(1.9em - 1px),
    #f0f0f0 1.9em
  );
  background-size: 100% 1.9em;
  background-attachment: local;
}

.ta-inicio:focus    { border-color: var(--color-inicio); box-shadow: 0 0 0 3px rgba(76,175,80,0.15); outline: none; }
.ta-conflicto:focus { border-color: var(--color-conflicto); box-shadow: 0 0 0 3px rgba(255,152,0,0.15); outline: none; }
.ta-desenlace:focus { border-color: var(--color-desenlace); box-shadow: 0 0 0 3px rgba(33,150,243,0.15); outline: none; }

/* ---- WORD COUNT ---- */
.word-count {
  font-size: 0.75rem;
  color: #9e9e9e;
  font-weight: 600;
  text-align: right;
}

/* ---- DIVIDER ---- */
.row-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  background: #fffdf0;
  border-top: 1.5px dashed #ffe082;
  border-bottom: 1.5px dashed #ffe082;
  height: 36px;
}

.divider-line {
  flex: 1;
  height: 2px;
  background: linear-gradient(to right, transparent, #ffe082, transparent);
}

.divider-icon {
  font-size: 1.1rem;
}

/* ---- ACTIONS BAR ---- */
.actions-bar {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 28px;
}

.btn {
  font-family: var(--font-main);
  font-size: 1rem;
  font-weight: 800;
  padding: 12px 28px;
  border-radius: var(--radius-chip);
  border: none;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.15s;
  letter-spacing: 0.3px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.15);
}

.btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.2);
}

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

.btn-preview { background: #7c4dff; color: white; }
.btn-clear   { background: #ef5350; color: white; }
.btn-print   { background: #00897b; color: white; }

/* ---- MODAL ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

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

.modal-box {
  background: white;
  border-radius: 24px;
  max-width: 620px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 30px 28px 24px;
  position: relative;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
  border: 3px solid #ffe082;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: #eeeeee;
  border: none;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  font-size: 1rem;
  cursor: pointer;
  font-weight: 700;
  color: #555;
  transition: background 0.15s;
}

.modal-close:hover { background: #e0e0e0; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 20px;
}

.modal-header h2 {
  font-family: var(--font-title);
  font-size: 1.7rem;
  color: #e65100;
}

.modal-header span { font-size: 1.6rem; }

.modal-content { display: flex; flex-direction: column; gap: 14px; }

.modal-part {
  border-radius: 14px;
  padding: 14px 16px;
}

.modal-part h3 {
  font-family: var(--font-title);
  font-size: 1.1rem;
  margin-bottom: 6px;
}

.modal-part p {
  font-size: 1rem;
  line-height: 1.75;
  color: #444;
  white-space: pre-wrap;
}

.mp-inicio    { background: var(--color-inicio-light); border: 2px solid var(--color-inicio-border); }
.mp-inicio h3 { color: #2e7d32; }

.mp-conflicto    { background: var(--color-conflicto-light); border: 2px solid var(--color-conflicto-border); }
.mp-conflicto h3 { color: #e65100; }

.mp-desenlace    { background: var(--color-desenlace-light); border: 2px solid var(--color-desenlace-border); }
.mp-desenlace h3 { color: #1565c0; }

.congrats {
  text-align: center;
  background: linear-gradient(135deg, #fff9c4, #ffe0b2);
  border: 2px solid #ffcc02;
  border-radius: 14px;
  padding: 14px;
  margin-top: 16px;
  font-size: 1.05rem;
  font-weight: 800;
  color: #e65100;
}

.congrats.hidden { display: none; }

.modal-empty {
  text-align: center;
  padding: 20px;
  color: #888;
  font-size: 1rem;
  font-weight: 600;
}
.modal-empty.hidden { display: none; }

/* ---- PRINT ---- */
@media print {
  header { background: none !important; border-bottom: 2px solid #ccc; }
  .actions-bar, .suggestions-box, .modal-overlay { display: none !important; }
  .story-row { grid-template-columns: 200px 1fr; break-inside: avoid; }
  .story-table { box-shadow: none; border: 2px solid #ccc; }
  .story-area {
    border: 1.5px solid #bbb !important;
    background-image: repeating-linear-gradient(
      to bottom, transparent, transparent calc(1.9em - 1px),
      #ddd calc(1.9em - 1px), #ddd 1.9em
    ) !important;
  }
}

/* ---- RESPONSIVE ---- */
@media (max-width: 680px) {
  .story-row {
    grid-template-columns: 1fr;
  }
  .col-image {
    border-right: none;
    border-bottom: 2.5px dashed #ffe082;
    padding-bottom: 14px;
  }
  .image-frame {
    max-width: 180px;
  }
}
