:root {
  --primary: #FF6B6B;      /* 珊瑚红 */
  --secondary: #4ECDC4;    /* 薄荷绿 */
  --background: #FFF9F5;   /* 暖白 */
  --text: #2D3436;         /* 深灰 */
  --accent: #FFE66D;       /* 柠檬黄 */
}

/* 基础样式 */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--background);
  color: var(--text);
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

#app {
  width: 100%;
  max-width: 480px; /* 移动端优先 */
  background-color: #fff;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
}

/* 头部导航 */
.app-header {
  background-color: var(--primary);
  color: white;
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 1.2rem;
  font-weight: bold;
}

.age-selector select {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  padding: 8px;
  border-radius: 4px;
  font-size: 0.9rem;
}

/* 视图切换 */
.view {
  display: none;
  padding: 20px;
}

.view.active {
  display: block;
  animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 首页组件 */
.hero {
  text-align: center;
  margin-bottom: 24px;
}

.hero h1 {
  font-size: 1.5rem;
  margin-bottom: 8px;
  color: var(--text);
}

.hero p {
  color: #666;
  font-size: 0.9rem;
}

.story-input {
  background: #f8f9fa;
  padding: 16px;
  border-radius: 12px;
  margin-bottom: 24px;
}

textarea {
  width: 100%;
  height: 100px;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 12px;
  resize: none;
  font-size: 1rem;
  margin-bottom: 12px;
}

.action-buttons {
  display: flex;
  gap: 12px;
}

.primary-btn {
  background-color: var(--primary);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 24px;
  font-weight: bold;
  flex: 2;
  cursor: pointer;
  transition: transform 0.1s;
}

.primary-btn:active {
  transform: scale(0.98);
}

.secondary-btn {
  background-color: white;
  border: 1px solid #ddd;
  padding: 12px;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}

/* 故事列表 */
.story-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
}

.story-card {
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  cursor: pointer;
  transition: transform 0.2s;
}

.story-card:hover {
  transform: translateY(-2px);
}

.story-cover {
  width: 100%;
  height: 100px;
  object-fit: cover;
}

.story-info {
  padding: 8px;
}

.story-info h3 {
  margin: 0 0 4px 0;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.age-tag {
  background: var(--secondary);
  color: white;
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
}

/* 阅读器视图 */
.reader-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 80px); /* 减去头部高度 */
}

.nav-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 1rem;
  margin-bottom: 12px;
  cursor: pointer;
  align-self: flex-start;
}

.carousel {
  flex: 1;
  background: #f0f0f0;
  border-radius: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  position: relative;
}

.story-page {
  display: none;
  width: 100%;
  height: 100%;
  flex-direction: column;
}

.story-page.active {
  display: flex;
}

.page-image {
  width: 100%;
  height: 60%;
  object-fit: cover;
}

.page-text {
  padding: 16px;
  font-size: 1.1rem;
  line-height: 1.6;
  height: 40%;
  overflow-y: auto;
}

.controls {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.control-btn {
  background: var(--primary);
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
}

.progress-bar {
  flex: 1;
  height: 6px;
  background: #eee;
  border-radius: 3px;
  overflow: hidden;
}

#progress-fill {
  height: 100%;
  background: var(--secondary);
  width: 0%;
  transition: width 0.2s linear;
}

/* 加载遮罩 */
#loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255,255,255,0.9);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 100;
}

.hidden {
  display: none !important;
}

.spinner {
  border: 4px solid #f3f3f3;
  border-top: 4px solid var(--primary);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* 响应式适配 */
@media (min-width: 768px) {
  #app {
    max-width: 800px;
    height: 90vh;
  }
  
  .story-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .reader-container {
    flex-direction: row;
    height: 100%;
  }

  .carousel {
    flex: 2;
    margin-right: 20px;
  }

  .controls {
    flex-direction: column;
    width: 60px;
  }
}
