:root {
  --bg-primary: #0d0e12;
  --bg-card: #161821;
  --bg-card-hover: #1f2230;
  --border-color: #272a38;
  --accent-orange: #ff6b22;
  --accent-orange-light: #ff8533;
  --accent-orange-glow: rgba(255, 107, 34, 0.35);
  --accent-blue: #3b82f6;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --safe-bottom: env(safe-area-inset-bottom, 16px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  overflow-x: hidden;
  height: 100vh;
  height: 100dvh;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  position: relative;
  background-color: var(--bg-primary);
}

/* 顶部状态栏 */
.top-nav {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background-color: rgba(13, 14, 18, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  z-index: 50;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-logo-img {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  object-fit: cover;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.status-indicator-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--accent-orange);
  box-shadow: 0 0 8px var(--accent-orange-glow);
}

.app-title {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.5px;
}

.model-badge {
  font-size: 11px;
  color: #ff9d5c;
  background: rgba(255, 107, 34, 0.12);
  border: 1px solid rgba(255, 107, 34, 0.3);
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 500;
}

.nav-right .status-ready {
  font-size: 13px;
  color: var(--accent-orange);
  font-weight: 500;
}

.api-key-badge {
  background: rgba(255, 107, 34, 0.15);
  border: 1px solid rgba(255, 107, 34, 0.4);
  color: #ff9d5c;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}
.api-key-badge:active {
  transform: scale(0.95);
  background: rgba(255, 107, 34, 0.3);
}

.icon-btn {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}

/* 视图容器 */
.view {
  display: none;
  flex: 1;
  overflow-y: auto;
  position: relative;
}

.view.active {
  display: flex;
  flex-direction: column;
}

/* 首页 Hero 区域 (作业助手) */
.hero-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  text-align: center;
}

.hero-logo-wrap {
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hero-logo-img {
  width: 96px;
  height: 96px;
  border-radius: 22px;
  object-fit: cover;
  box-shadow: 0 12px 36px rgba(37, 99, 235, 0.4), 0 4px 12px rgba(0, 0, 0, 0.5);
  border: 2px solid rgba(255, 255, 255, 0.15);
  animation: floatBounce 3s ease-in-out infinite alternate;
}

@keyframes floatBounce {
  from { transform: translateY(0); }
  to { transform: translateY(-6px); }
}

.hero-title {
  font-size: 26px;
  font-weight: 800;
  line-height: 1.3;
  margin-bottom: 12px;
  letter-spacing: 0.5px;
}

.gradient-text {
  background: linear-gradient(135deg, #ff9248, #ff5500);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-desc {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
  max-width: 340px;
  margin-bottom: 28px;
}

.action-btn-group {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 32px;
}

.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 52px;
  background: linear-gradient(135deg, #ff7e33, #ff500a);
  color: #fff;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 20px var(--accent-orange-glow);
  transition: transform 0.15s, box-shadow 0.15s;
}

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

.btn-secondary {
  width: 100%;
  height: 48px;
  background: var(--bg-card);
  color: #e5e7eb;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-secondary:active {
  background: var(--bg-card-hover);
}

.file-btn-wrapper {
  position: relative !important;
  overflow: hidden !important;
  cursor: pointer !important;
  -webkit-tap-highlight-color: transparent !important;
  user-select: none !important;
}

.file-overlay-input {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  opacity: 0 !important;
  cursor: pointer !important;
  z-index: 10 !important;
  font-size: 0 !important;
  display: block !important;
}

/* 首页 3 大特性卡片 */
.feature-cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
}

.feature-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 16px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.feature-card-title {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  margin-bottom: 4px;
}

.feature-card-sub {
  font-size: 11px;
  color: var(--text-muted);
}

/* PWA 桌面安装条 */
.pwa-banner {
  margin-top: 22px;
  width: 100%;
  background: rgba(255, 107, 34, 0.12);
  border: 1px solid rgba(255, 107, 34, 0.35);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.pwa-banner-left {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
}

.pwa-icon {
  font-size: 24px;
}

.pwa-banner-text strong {
  font-size: 13.5px;
  color: #fff;
  display: block;
}

.pwa-subtext {
  font-size: 11px;
  color: #ff9d5c;
  margin-top: 2px;
}

.pwa-btn {
  background: linear-gradient(135deg, #ff7e33, #ff500a);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 4px 12px var(--accent-orange-glow);
}

/* 安装指引弹窗 */
.install-guide-card {
  max-width: 390px;
}

.guide-steps {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 16px 0;
}

.guide-step-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: #141722;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 12px;
}

.step-num {
  width: 24px;
  height: 24px;
  background: var(--accent-orange);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: bold;
  flex-shrink: 0;
}

.step-content strong {
  font-size: 13.5px;
  color: #fff;
  display: block;
  margin-bottom: 3px;
}

.step-content p {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* 编辑器头部信息 */
.editor-header-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: #11131a;
  border-bottom: 1px solid var(--border-color);
  font-size: 12px;
}

.page-pill {
  background: #232736;
  padding: 2px 8px;
  border-radius: 8px;
  font-weight: 600;
  margin-right: 6px;
}

.candidate-pill {
  color: var(--text-secondary);
}

.timing-stats {
  color: #9ca3af;
  font-family: monospace;
}

/* 画布舞台区域 */
.editor-stage-wrap {
  flex: 1;
  position: relative;
  background: #090a0d;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stage-container {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  display: inline-block;
}

.homework-image {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 200px);
  object-fit: contain;
}

.boxes-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* 题目选框样式 (可拖拽微调) */
.question-box {
  position: absolute;
  pointer-events: auto;
  border: 2px dashed var(--accent-blue);
  background: rgba(59, 130, 246, 0.08);
  border-radius: 6px;
  touch-action: none;
  cursor: move;
  transition: border-color 0.15s, background 0.15s;
}

.question-box.is-wrong {
  border-color: #ff4d4f;
  background: rgba(255, 77, 79, 0.12);
  border-style: solid;
}

.question-box.is-collected {
  border-color: var(--accent-green) !important;
  background: rgba(16, 185, 129, 0.12) !important;
}

/* 选框顶部徽章与操作按钮 */
.box-header-tag {
  position: absolute;
  top: -26px;
  left: -2px;
  background: rgba(30, 34, 48, 0.95);
  border: 1px solid var(--accent-blue);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  color: #fff;
  white-space: nowrap;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 4px;
}

.question-box.is-wrong .box-header-tag {
  border-color: #ff4d4f;
  color: #ff7875;
}

.question-box.is-collected .box-header-tag {
  border-color: var(--accent-green);
  color: #52c41a;
}

.box-actions {
  position: absolute;
  top: 4px;
  right: 4px;
  display: flex;
  gap: 4px;
  z-index: 10;
}

.box-act-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(20, 22, 30, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.1s, background 0.1s;
}

.box-act-btn:active {
  transform: scale(0.9);
}

.btn-collect {
  background: var(--accent-orange);
  border-color: var(--accent-orange);
  font-weight: bold;
}

.question-box.is-collected .btn-collect {
  background: var(--accent-green);
  border-color: var(--accent-green);
}

.btn-teach {
  background: #4f46e5;
  border-color: #6366f1;
  font-size: 11px;
  width: auto;
  padding: 0 6px;
  border-radius: 12px;
}

/* 缩放手柄 */
.resize-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #fff;
  border: 2px solid #ff6b22;
  border-radius: 2px;
  pointer-events: auto;
}

.handle-tl { top: -5px; left: -5px; cursor: nwse-resize; }
.handle-tr { top: -5px; right: -5px; cursor: nesw-resize; }
.handle-bl { bottom: -5px; left: -5px; cursor: nesw-resize; }
.handle-br { bottom: -5px; right: -5px; cursor: nwse-resize; }

/* 提示条 */
.stage-hint {
  padding: 6px 12px;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-secondary);
  background: #11131a;
  border-top: 1px solid var(--border-color);
}

.hint-tag {
  background: rgba(255, 107, 34, 0.2);
  color: #ff9d5c;
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: bold;
}

/* 编辑器底部工具栏 (1:1 还原 demo) */
.editor-bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px calc(var(--safe-bottom) + 8px);
  background: rgba(18, 20, 28, 0.98);
  border-top: 1px solid var(--border-color);
  gap: 8px;
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 11px;
  cursor: pointer;
  padding: 4px 6px;
}

.tool-btn svg {
  stroke: var(--text-secondary);
}

.tool-btn:active {
  color: #fff;
}

.tool-btn:active svg {
  stroke: #fff;
}

.mistake-badge-pill {
  background: #251614;
  border: 1px solid #792b21;
  color: #ff7875;
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-export {
  background: linear-gradient(135deg, #ff7e33, #ff500a);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px var(--accent-orange-glow);
}

.btn-export:active {
  transform: scale(0.96);
}

/* 加载动画 (全局全屏遮罩) */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: rgba(13, 14, 18, 0.88);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 3px solid rgba(255, 107, 34, 0.2);
  border-top-color: var(--accent-orange);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 14px;
}

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

.loading-text {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
}

.loading-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* AI 名师讲解抽屉 (Drawer) */
.drawer-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 200;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.drawer-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}

.drawer-content {
  position: relative;
  background: #151824;
  border-top: 1px solid #2e3347;
  border-radius: 20px 20px 0 0;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.drawer-handle {
  width: 36px;
  height: 4px;
  background: #3c4257;
  border-radius: 2px;
  margin: 10px auto 4px;
}

.teacher-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 18px 12px;
  border-bottom: 1px solid var(--border-color);
}

.teacher-avatar-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.teacher-avatar-img {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: cover;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
  border: 1.5px solid rgba(99, 102, 241, 0.4);
}

.teacher-avatar {
  font-size: 28px;
  background: rgba(99, 102, 241, 0.2);
  border-radius: 50%;
  padding: 4px;
}

.teacher-name {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
}

.teacher-model-tag {
  font-size: 11px;
  color: #a5b4fc;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 6px;
}

/* 语音播放控制 */
.audio-control-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: rgba(99, 102, 241, 0.12);
  border-bottom: 1px solid rgba(99, 102, 241, 0.2);
}

.audio-play-btn {
  background: #4f46e5;
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.audio-play-btn:active {
  background: #4338ca;
}

.audio-wave {
  display: flex;
  align-items: center;
  gap: 3px;
}

.audio-wave span {
  width: 3px;
  height: 12px;
  background: #818cf8;
  border-radius: 2px;
  transition: height 0.2s;
}

.audio-wave.playing span:nth-child(1) { animation: wave 0.6s infinite ease-in-out; }
.audio-wave.playing span:nth-child(2) { animation: wave 0.8s infinite ease-in-out 0.1s; }
.audio-wave.playing span:nth-child(3) { animation: wave 0.5s infinite ease-in-out 0.2s; }
.audio-wave.playing span:nth-child(4) { animation: wave 0.7s infinite ease-in-out 0.3s; }
.audio-wave.playing span:nth-child(5) { animation: wave 0.9s infinite ease-in-out 0.15s; }

@keyframes wave {
  0%, 100% { height: 6px; }
  50% { height: 18px; }
}

/* 讲解卡片滚动区 */
.teacher-sections-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px calc(var(--safe-bottom) + 20px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.section-card {
  background: #1d2130;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 14px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  color: #e2e8f0;
  margin-bottom: 8px;
}

.section-text {
  font-size: 13.5px;
  line-height: 1.6;
  color: #cbd5e1;
  white-space: pre-wrap;
}

.standard-ans-box {
  margin-top: 10px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13.5px;
  color: #34d399;
}

.ans-badge {
  background: #10b981;
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: bold;
  margin-right: 6px;
}

.btn-toggle-ans {
  margin-top: 8px;
  background: none;
  border: none;
  color: var(--accent-orange);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.variant-ans-box {
  margin-top: 8px;
  background: rgba(255, 107, 34, 0.08);
  border: 1px solid rgba(255, 107, 34, 0.2);
  border-radius: 8px;
  padding: 10px;
  font-size: 13px;
  color: #ff9d5c;
  line-height: 1.5;
}

/* 清洗设置弹窗 */
.popover-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  z-index: 210;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.popover-card {
  background: #1a1d29;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  width: 100%;
  max-width: 380px;
  padding: 20px;
}

.popover-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.setting-item {
  margin-bottom: 16px;
}

.setting-item label {
  display: block;
  font-size: 13px;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.setting-item input[type="range"] {
  width: 100%;
  accent-color: var(--accent-orange);
}

.checkbox-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.checkbox-item label {
  margin-bottom: 0;
  flex: 1;
}

.btn-primary-small {
  width: 100%;
  padding: 10px;
  background: var(--accent-orange);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}

/* Toast 提示 */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(22, 24, 33, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 300;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
