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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, sans-serif;
  background: #1a1a2e;
  color: #f0f0f0;
}

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

.hidden {
  display: none !important;
}

/* Loading state */
#loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 1rem;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: #a855f7;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Main viewer - default mobile portrait layout */
#viewer {
  display: flex;
  flex-direction: column;
  height: 100%;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
}

/* Panel image container */
#panel-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  min-height: 0;
  background: #0f0f1a;
}

#panel-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

/* Text container for parent to read */
#text-container {
  background: linear-gradient(to bottom, #1e1e3a, #1a1a2e);
  padding: 1.25rem 1.5rem;
  min-height: 140px;
  max-height: 35vh;
  overflow-y: auto;
  border-top: 1px solid rgba(168, 85, 247, 0.2);
}

#dialogues {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.dialogue {
  line-height: 1.5;
  font-size: 1.1rem;
}

.dialogue-narrator {
  font-style: italic;
  color: #c4b5fd;
}

.dialogue-character {
  color: #f0f0f0;
}

.dialogue-speaker {
  font-weight: 700;
  color: #a855f7;
}

/* Title card styles */
.title-card {
  text-align: center;
  padding: 2rem;
}

.title-card h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: #fff;
}

.title-card .creator {
  font-size: 1rem;
  color: #a78bfa;
  margin-bottom: 1.5rem;
}

.title-card .tap-hint {
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.6);
  animation: pulse 2s ease-in-out infinite;
}

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

/* End card styles */
.end-card {
  text-align: center;
  padding: 2rem;
}

.end-card h2 {
  font-size: 1.5rem;
  color: #a855f7;
  margin-bottom: 1rem;
}

.end-card .restart-btn {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  background: #a855f7;
  color: white;
  border-radius: 2rem;
  text-decoration: none;
  font-weight: 600;
  margin-top: 1rem;
  cursor: pointer;
  border: none;
  font-size: 1rem;
}

.end-card .restart-btn:hover {
  background: #9333ea;
}

/* Progress dots */
#progress {
  padding: 0.75rem 1rem 1rem;
  background: #1a1a2e;
}

#dots {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  transition: all 0.2s ease;
  cursor: pointer;
}

.dot.active {
  background: #a855f7;
  transform: scale(1.2);
}

.dot.viewed {
  background: rgba(168, 85, 247, 0.5);
}

/* Error state */
#error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 2rem;
}

#error h1 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

#error p {
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: 1.5rem;
}

#error a {
  color: #a855f7;
  text-decoration: none;
}

/* ===========================================
   LANDSCAPE / TABLET / IPAD LAYOUT
   Side-by-side: image on left, text on right
   =========================================== */

@media (min-width: 768px) and (orientation: landscape),
       (min-width: 1024px) {

  #viewer {
    flex-direction: row;
    flex-wrap: wrap;
  }

  /* Main content area: image + text side by side */
  #viewer-content {
    display: flex;
    flex: 1;
    min-height: 0;
    width: 100%;
  }

  #panel-container {
    flex: 3;
    padding: 2rem;
    border-top: none;
  }

  #panel-image {
    max-height: 100%;
    border-radius: 12px;
  }

  #text-container {
    flex: 2;
    max-height: none;
    min-height: auto;
    border-top: none;
    border-left: 1px solid rgba(168, 85, 247, 0.2);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: linear-gradient(to right, #1e1e3a, #1a1a2e);
  }

  #dialogues {
    gap: 1rem;
  }

  .dialogue {
    font-size: 1.25rem;
    line-height: 1.6;
  }

  .title-card h1 {
    font-size: 2.25rem;
  }

  .title-card .creator {
    font-size: 1.15rem;
  }

  .title-card .tap-hint {
    font-size: 1.05rem;
  }

  .end-card h2 {
    font-size: 2rem;
  }

  /* Progress dots at the bottom, spanning full width */
  #progress {
    width: 100%;
    padding: 1rem 2rem;
  }

  .dot {
    width: 10px;
    height: 10px;
  }
}

/* Large desktop / TV screens */
@media (min-width: 1400px) {
  #panel-container {
    flex: 2;
    padding: 3rem;
  }

  #text-container {
    flex: 1;
    padding: 3rem;
    max-width: 500px;
  }

  .dialogue {
    font-size: 1.4rem;
  }

  .title-card h1 {
    font-size: 2.5rem;
  }
}

/* Phone landscape - compact side-by-side */
@media (max-height: 500px) and (orientation: landscape) {
  #panel-container {
    flex: 2;
    padding: 0.75rem;
  }

  #text-container {
    flex: 1;
    padding: 0.75rem 1rem;
    min-width: 200px;
  }

  .dialogue {
    font-size: 0.9rem;
    line-height: 1.4;
  }

  #dialogues {
    gap: 0.5rem;
  }

  #progress {
    padding: 0.5rem;
  }

  .dot {
    width: 6px;
    height: 6px;
  }

  .title-card {
    padding: 1rem;
  }

  .title-card h1 {
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
  }

  .title-card .creator {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
  }
}
