/* ===== 全局 ===== */
:root {
  --bg: #FFF8E7;
  --primary: #FF6B35;
  --secondary: #4ECDC4;
  --accent: #A8E6CF;
  --danger: #FF4757;
  --text: #2D3436;
  --text-light: #636E72;
  --card: #FFFFFF;
  --shadow: rgba(0,0,0,0.08);
  --radius: 20px;
}

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

body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

body.reading-mode .app-header {
  display: none;
}

body.reading-mode #app {
  max-width: 100%;
  padding: 10px 10px 24px;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
}

/* ===== 顶部标题 ===== */
.app-header {
  text-align: center;
  padding: 20px 0 12px;
}

.header-icon {
  font-size: 44px;
  animation: bounce 2s infinite;
}

.app-header h1 {
  font-size: 30px;
  color: var(--primary);
  font-weight: 800;
  letter-spacing: 2px;
}

.header-sub {
  font-size: 15px;
  color: var(--text-light);
  margin-top: 4px;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* ===== 书架 ===== */
.bookshelf-list {
  margin-bottom: 20px;
}

.empty-tip {
  text-align: center;
  color: var(--text-light);
  padding: 40px 0;
  font-size: 16px;
}

.book-item {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 4px 20px var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.book-info {
  flex: 1;
}

.book-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.book-pages {
  font-size: 13px;
  color: var(--text-light);
  margin-top: 4px;
}

.book-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn-read-book {
  background: var(--secondary);
  color: white;
}

.btn-enroll-more {
  background: var(--primary);
  color: white;
}

.btn-delete-book {
  background: #ddd;
  color: var(--text-light);
}

/* ===== 录入 ===== */
.enroll-header {
  text-align: center;
  margin-bottom: 12px;
}

.enroll-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
}

.enroll-page-num {
  font-size: 16px;
  color: var(--text-light);
  margin-top: 4px;
}

.enroll-status {
  text-align: center;
  font-size: 16px;
  color: var(--primary);
  padding: 8px 0;
}

.enroll-bottom-btns {
  margin-top: 16px;
}

/* ===== 拍照上传 ===== */
.capture-area {
  background: var(--card);
  border-radius: var(--radius);
  min-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 4px 20px var(--shadow);
  margin-bottom: 16px;
  position: relative;
}

.capture-placeholder { text-align: center; color: var(--text-light); }
.placeholder-icon { font-size: 56px; margin-bottom: 8px; }
.placeholder-sub { font-size: 13px; margin-top: 4px; color: #aaa; }

.preview-img {
  width: 100%;
  height: auto;
  max-height: 320px;
  object-fit: contain;
}

.capture-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
  flex-direction: column;
}

.capture-buttons-secondary {
  margin-top: 0;
}

.capture-buttons .btn-large,
#btn-enroll-go,
.enroll-bottom-btns .btn-large {
  width: 100%;
  display: block;
}

.capture-buttons .btn-large,
.enroll-bottom-btns .btn-large,
#btn-enroll-go {
  min-height: 58px;
  font-size: 19px;
  letter-spacing: 0.5px;
}

.enroll-bottom-btns {
  display: flex;
}

.batch-enroll-panel {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 12px;
  box-shadow: 0 4px 20px var(--shadow);
}

.batch-enroll-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
}

.batch-enroll-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
}

.batch-enroll-summary {
  font-size: 13px;
  color: var(--text-light);
}

.batch-enroll-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.batch-enroll-item {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  background: #FFF9F2;
  border-radius: 14px;
}

.batch-enroll-thumb {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  object-fit: cover;
  background: #f2f2f2;
}

.batch-enroll-item-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.batch-enroll-item-meta {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 4px;
}

.batch-enroll-item-status {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  text-align: right;
}

.batch-enroll-item-status.is-success {
  color: #35a853;
}

.batch-enroll-item-status.is-error {
  color: var(--danger);
}

.batch-enroll-actions {
  margin-top: 16px;
  margin-bottom: 0;
}

/* ===== 按钮 ===== */
.btn {
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn-large { padding: 16px 28px; font-size: 20px; border-radius: 16px; }
.btn-medium { padding: 12px 20px; font-size: 17px; border-radius: 12px; }
.btn-small { padding: 8px 16px; font-size: 14px; border-radius: 8px; }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { transform: scale(1.05); }
.btn-primary:active { transform: scale(0.95); }

.btn-secondary { background: var(--secondary); color: white; }
.btn-secondary:hover { transform: scale(1.05); }
.btn-secondary:active { transform: scale(0.95); }

.btn-action {
  background: linear-gradient(135deg, var(--primary), #FF8C42);
  color: white;
  width: 100%;
  padding: 18px;
  font-size: 22px;
  border-radius: 16px;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,107,53,0.4); }
  50% { box-shadow: 0 0 0 12px rgba(255,107,53,0); }
}

.btn-close { background: #ddd; color: var(--text); }

#btn-enroll-go {
  margin-top: 4px;
}

/* ===== 阅读 ===== */
.read-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.read-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  flex: 1;
  min-width: 180px;
}

.read-pages-count {
  font-size: 13px;
  color: var(--text-light);
}

.read-match-status {
  text-align: center;
  font-size: 16px;
  color: var(--text-light);
  padding: 4px 0 8px;
  margin-bottom: 8px;
}

.read-camera-area {
  background: #000;
  border-radius: 22px;
  overflow: hidden;
  margin: 0 -6px 14px;
  width: calc(100% + 12px);
  min-height: clamp(360px, 72vh, 760px);
  height: clamp(360px, 72vh, 760px);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: 0 10px 32px rgba(0,0,0,0.22);
}

@supports (height: 1svh) {
  .read-camera-area {
    min-height: clamp(360px, 72svh, 760px);
    height: clamp(360px, 72svh, 760px);
  }
}

.read-camera-area video {
  width: 100%;
  height: 100%;
  max-height: none;
  object-fit: cover;
  object-position: center;
}

.read-camera-area.is-photo-mode {
  min-height: 180px;
  height: 180px;
}

.read-camera-area.is-photo-mode .read-camera-guide {
  display: none;
}

.read-camera-guide {
  position: absolute;
  inset: 18px;
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-radius: 24px;
  box-shadow: inset 0 0 0 9999px rgba(0, 0, 0, 0.14);
  pointer-events: none;
}

.read-camera-guide::before,
.read-camera-guide::after {
  content: '';
  position: absolute;
  width: 26px;
  height: 26px;
  border-color: #4ECDC4;
  border-style: solid;
  pointer-events: none;
}

.read-camera-guide::before {
  top: -2px;
  left: -2px;
  border-width: 4px 0 0 4px;
  border-top-left-radius: 12px;
}

.read-camera-guide::after {
  right: -2px;
  bottom: -2px;
  border-width: 0 4px 4px 0;
  border-bottom-right-radius: 12px;
}

.read-camera-tip {
  margin: -4px 0 12px;
  color: var(--text-light);
  font-size: 14px;
  text-align: center;
}

.read-photo-fallback {
  margin-bottom: 16px;
}

.read-audio-actions {
  margin-bottom: 16px;
}

.read-audio-debug {
  margin: -6px 0 14px;
  font-size: 13px;
  line-height: 1.5;
  color: #E17055;
  text-align: center;
  padding: 0 10px;
}

/* ===== 故事卡片 ===== */
.story-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 4px 20px var(--shadow);
}

.story-label {
  font-size: 14px;
  color: var(--primary);
  font-weight: 700;
  margin-bottom: 8px;
}

.story-text {
  font-size: 20px;
  line-height: 1.8;
  color: var(--text);
}

/* ===== 识字卡片 ===== */
.chars-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 4px 20px var(--shadow);
}

.chars-label {
  font-size: 14px;
  color: var(--secondary);
  font-weight: 700;
  margin-bottom: 12px;
}

.chars-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 12px;
}

.char-item {
  background: linear-gradient(135deg, #FFF, #F8F8F8);
  border-radius: 12px;
  padding: 10px 6px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  border: 2px solid transparent;
}

.char-item:hover {
  transform: scale(1.08);
  border-color: var(--primary);
}

.char-item .char-zh {
  font-size: 32px;
  font-weight: 900;
  color: var(--primary);
  line-height: 1.2;
}

.char-item .char-py {
  font-size: 14px;
  color: var(--secondary);
  font-weight: 700;
  margin-top: 2px;
}

/* ===== 互动提示 ===== */
.tip-card {
  background: linear-gradient(135deg, #FFF8E7, #FFEAA7);
  border-radius: 14px;
  padding: 14px 18px;
  margin-bottom: 16px;
  text-align: center;
}

.tip-text {
  font-size: 17px;
  color: var(--text);
  font-weight: 600;
}

/* ===== 单字弹窗 ===== */
.char-popup {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.popup-content {
  background: var(--card);
  border-radius: 24px;
  padding: 28px 36px;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0,0,0,0.2);
  max-width: 360px;
  width: 90%;
}

.popup-char {
  font-size: 88px;
  color: var(--primary);
  font-weight: 900;
  line-height: 1.2;
  animation: popIn 0.3s ease-out;
}

.popup-pinyin {
  font-size: 32px;
  color: var(--secondary);
  font-weight: 700;
  margin: 4px 0;
}

.popup-meaning {
  font-size: 18px;
  color: var(--text);
  margin: 8px 0;
  line-height: 1.5;
}

.popup-fun {
  font-size: 16px;
  color: #E17055;
  background: #FFF3E0;
  padding: 8px 12px;
  border-radius: 8px;
  margin: 8px 0 16px;
  line-height: 1.5;
}

@keyframes popIn {
  from { transform: scale(0.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.popup-btns {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ===== 错误提示 ===== */
.error-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--danger);
  color: white;
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 16px;
  z-index: 300;
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from { transform: translateX(-50%) translateY(20px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* ===== 手机端适配 ===== */
@media (max-width: 480px) {
  #app { padding: 12px; }
  .app-header h1 { font-size: 26px; }
  .btn-large { padding: 14px 22px; font-size: 18px; }
  .popup-char { font-size: 72px; }
  .popup-pinyin { font-size: 26px; }
  .char-item .char-zh { font-size: 28px; }
  .story-text { font-size: 18px; }
  body.reading-mode #app { padding: 8px 8px 24px; }
  .read-match-status { font-size: 15px; }
  .read-camera-area {
    margin-left: -4px;
    margin-right: -4px;
    width: calc(100% + 8px);
    min-height: 72vh;
    height: 72vh;
  }
  @supports (height: 1svh) {
    .read-camera-area {
      min-height: 72svh;
      height: 72svh;
    }
  }
  .read-camera-area.is-photo-mode {
    min-height: 160px;
    height: 160px;
  }
  .batch-enroll-item {
    grid-template-columns: 48px 1fr;
  }
  .batch-enroll-item-status {
    grid-column: 1 / -1;
    text-align: left;
  }
}
