@import url('https://fonts.googleapis.com/css2?family=Quicksand:wght@400;500;600;700&display=swap');

:root {
  --bg: #FFF8F0;
  --bg-card: #FFFFFF;
  --primary: #FF7B54;
  --primary-light: #FFB26B;
  --secondary: #7EC8E3;
  --accent: #C9B1FF;
  --success: #7ED99F;
  --text: #3D3D3D;
  --text-light: #8B8B8B;
  --shadow: 0 4px 20px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.12);
  --radius: 20px;
  --radius-sm: 12px;
  --font: 'Quicksand', -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1A1A2E;
    --bg-card: #25253E;
    --text: #F0F0F0;
    --text-light: #A0A0B0;
    --shadow: 0 4px 20px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.4);
  }
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: clamp(16px, 3.5vw, 22px);
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* === Layout === */
.page {
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 1.5rem;
  flex-direction: column;
  align-items: center;
}
.page.active {
  display: flex;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem 2rem;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  touch-action: manipulation;
  min-height: 60px;
  min-width: 60px;
}
.btn:active {
  transform: scale(0.95);
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  box-shadow: 0 4px 15px rgba(255,123,84,0.35);
}
.btn-secondary {
  background: var(--secondary);
  color: white;
  box-shadow: 0 4px 15px rgba(126,200,227,0.35);
}
.btn-accent {
  background: linear-gradient(135deg, var(--accent), #E0D0FF);
  color: var(--text);
  box-shadow: 0 4px 15px rgba(201,177,255,0.35);
}
.btn-ghost {
  background: transparent;
  color: var(--text-light);
  box-shadow: none;
}
.btn-round {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  padding: 0;
  font-size: 1.8rem;
}
.btn-big {
  padding: 1.5rem 3rem;
  font-size: 1.4rem;
  border-radius: 25px;
}

/* === Navigation Arrows === */
.nav-arrows {
  display: flex;
  align-items: center;
  gap: 2rem;
  margin-top: auto;
  padding: 1.5rem 0;
}
.nav-arrows .btn-round {
  width: 80px;
  height: 80px;
  font-size: 2rem;
}

/* === Cards === */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 0.2s;
}
.card:active {
  transform: scale(0.97);
}

/* === Home Page === */
.home-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 600px;
  margin-bottom: 1.5rem;
}
.home-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
}
.lang-switch {
  display: flex;
  gap: 0.3rem;
}
.lang-switch button {
  padding: 0.3rem 0.6rem;
  border: 2px solid transparent;
  border-radius: 8px;
  background: var(--bg-card);
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-light);
}
.lang-switch button.active {
  border-color: var(--primary);
  color: var(--primary);
}

.stories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
  width: 100%;
  max-width: 600px;
  margin-bottom: 2rem;
}

.story-card {
  cursor: pointer;
  position: relative;
}
.story-card img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
}
.story-card .story-info {
  padding: 0.8rem;
}
.story-card .story-title {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.3rem;
}
.story-card .story-status {
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  display: inline-block;
  font-weight: 600;
}
.story-status.ready {
  background: var(--success);
  color: white;
}
.story-status.generating {
  background: var(--primary-light);
  color: white;
  animation: pulse 2s infinite;
}
.story-status.error {
  background: #FF6B6B;
  color: white;
}
.story-card .story-rating {
  color: #FFD700;
  font-size: 0.8rem;
  margin-top: 0.3rem;
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-light);
}
.empty-state p {
  margin-bottom: 2rem;
  font-size: 1.1rem;
}

/* === Create Flow === */
.create-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  width: 100%;
  max-width: 500px;
  text-align: center;
  gap: 1.5rem;
}

.create-prompt {
  font-size: 1.3rem;
  font-weight: 600;
  line-height: 1.4;
  min-height: 3em;
}

.mic-btn {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #FF4444);
  border: none;
  color: white;
  font-size: 2.5rem;
  cursor: pointer;
  position: relative;
  transition: transform 0.2s;
}
.mic-btn:active {
  transform: scale(0.9);
}
.mic-btn.listening {
  animation: pulse-mic 1.5s infinite;
}
.mic-btn.listening::after {
  content: '';
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 3px solid var(--primary);
  animation: ripple 1.5s infinite;
}

.transcript {
  font-size: 1.1rem;
  color: var(--text);
  min-height: 2em;
  font-style: italic;
  opacity: 0.8;
}

.character-image-container {
  width: 100%;
  max-width: 350px;
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
}
.character-image-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* === Progress === */
.progress-container {
  width: 100%;
  max-width: 400px;
}
.progress-bar {
  width: 100%;
  height: 12px;
  background: var(--bg-card);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 1rem;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--success));
  border-radius: 6px;
  transition: width 0.5s ease;
  width: 0%;
}
.progress-text {
  text-align: center;
  margin-top: 0.5rem;
  color: var(--text-light);
  font-size: 0.85rem;
}

/* === Reader === */
.reader-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 600px;
  flex: 1;
}

.reader-image {
  width: 100%;
  aspect-ratio: 4/3;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  margin-bottom: 1.5rem;
  background: var(--bg-card);
}
.reader-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reader-text {
  font-size: 1.2rem;
  line-height: 1.7;
  text-align: center;
  padding: 0 1rem;
  flex: 1;
  display: flex;
  align-items: center;
}

.reader-controls {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 1rem 0;
  margin-top: auto;
}

.page-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
  padding: 0.5rem 0;
}
.page-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-light);
  opacity: 0.3;
  transition: opacity 0.3s, transform 0.3s;
}
.page-dot.active {
  opacity: 1;
  background: var(--primary);
  transform: scale(1.3);
}

/* === Rating === */
.rating-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 2rem 0;
}
.stars {
  display: flex;
  gap: 0.5rem;
}
.star {
  font-size: 2.5rem;
  cursor: pointer;
  transition: transform 0.2s;
  filter: grayscale(1);
  opacity: 0.4;
}
.star.active {
  filter: grayscale(0);
  opacity: 1;
}
.star:active {
  transform: scale(1.2);
}

/* === Screensaver / Idle === */
.screensaver {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.screensaver.active {
  display: flex;
}
.screensaver img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius);
  transition: opacity 2s ease;
}
.screensaver .tap-hint {
  position: absolute;
  bottom: 2rem;
  color: rgba(255,255,255,0.3);
  font-size: 0.8rem;
}

/* === Loader / Spinner === */
.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid var(--bg-card);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-character {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

/* === Animations === */
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}
@keyframes pulse-mic {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255,75,75,0.4); }
  50% { transform: scale(1.05); box-shadow: 0 0 0 20px rgba(255,75,75,0); }
}
@keyframes ripple {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.5); opacity: 0; }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes confetti {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(-200px) rotate(720deg); opacity: 0; }
}

.fade-in {
  animation: fadeIn 0.5s ease forwards;
}

/* === Form Inputs === */
.text-input {
  width: 100%;
  max-width: 350px;
  padding: 0.8rem 1.2rem;
  border: 2px solid var(--bg-card);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 1.1rem;
  background: var(--bg-card);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}
.text-input:focus {
  border-color: var(--primary);
}

.select-input {
  width: 100%;
  padding: 0.7rem 1rem;
  border: 2px solid var(--bg-card);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 1rem;
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  outline: none;
}
.select-input:focus {
  border-color: var(--primary);
}

.settings-group {
  width: 100%;
  margin-bottom: 1rem;
}
.settings-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.3rem;
  font-size: 0.9rem;
}

.toggle-label {
  display: flex !important;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}
.toggle-label input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
}

/* === Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-box {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

/* === Review Badge === */
.review-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--primary);
  color: white;
  font-size: 0.6rem;
  font-weight: 700;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* === Story Card Actions === */
.story-card-actions {
  display: flex;
  gap: 0.3rem;
  margin-top: 0.3rem;
}
.story-card-actions button {
  padding: 0.2rem 0.5rem;
  border: none;
  border-radius: 6px;
  font-size: 0.7rem;
  cursor: pointer;
  font-family: var(--font);
  font-weight: 600;
}
.btn-approve {
  background: var(--success);
  color: white;
}
.btn-hide {
  background: var(--text-light);
  color: white;
}
.btn-delete {
  background: transparent;
  color: #FF6B6B;
  font-size: 0.9rem !important;
}

/* === Utility === */
.hidden { display: none !important; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-2 { margin-bottom: 1rem; }
.text-center { text-align: center; }
.text-light { color: var(--text-light); }
.text-sm { font-size: 0.85rem; }

/* === Responsive === */
@media (max-width: 400px) {
  .btn-big { padding: 1.2rem 2rem; font-size: 1.2rem; }
  .mic-btn { width: 80px; height: 80px; font-size: 2rem; }
  .create-prompt { font-size: 1.1rem; }
  .nav-arrows .btn-round { width: 65px; height: 65px; }
}

@media (min-width: 768px) {
  .stories-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
