/* Reset & Base */
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
:root{
  --bg:#f5f6fa;
  --surface:#fff;
  --primary:#165DFF;
  --primary-dark:#0e42d2;
  --success:#00B42A;
  --text:#1d2129;
  --text2:#4e5969;
  --text3:#86909C;
  --border:#e5e6eb;
  --radius:12px;
  --shadow:0 2px 12px rgba(0,0,0,0.08);
  --safe-bottom:env(safe-area-inset-bottom,0px);
  --header-h:56px;
  --tab-h:56px;
  --nav-h:48px;
}
html,body{height:100%;overflow:hidden;font-family:-apple-system,BlinkMacSystemFont,'PingFang SC','Hiragino Sans GB','Microsoft YaHei',sans-serif;background:var(--bg);color:var(--text);-webkit-tap-highlight-color:transparent;touch-action:manipulation}
#app{height:100%;display:flex;flex-direction:column;max-width:100vw}

/* Header */
.header{
  background:linear-gradient(135deg,var(--primary),var(--primary-dark));
  color:#fff;padding:12px 16px 8px;flex-shrink:0;position:relative;z-index:10
}
.header-top{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px}
.title{font-size:18px;font-weight:700;letter-spacing:0.5px}
.pdf-toggle{display:flex;gap:6px}
.pdf-btn{padding:4px 12px;border:1px solid rgba(255,255,255,0.3);border-radius:16px;background:transparent;color:rgba(255,255,255,0.7);font-size:12px;cursor:pointer;transition:all 0.2s}
.pdf-btn.active{background:rgba(255,255,255,0.2);color:#fff;border-color:rgba(255,255,255,0.5)}
.progress-info{display:flex;justify-content:space-between;font-size:11px;color:rgba(255,255,255,0.7);margin-bottom:4px}
.progress-bar{height:3px;background:rgba(255,255,255,0.2);border-radius:2px;overflow:hidden}
.progress-fill{height:100%;background:#fff;border-radius:2px;transition:width 0.3s ease}

/* Content */
.content{
  flex:1;overflow:hidden;position:relative;
  padding-bottom:calc(var(--tab-h) + var(--nav-h) + var(--safe-bottom))
}
.tab-panel{display:none;height:100%;overflow:auto;-webkit-overflow-scrolling:touch}
.tab-panel.active{display:flex;flex-direction:column}

/* Tab: Problem */
.page-container{
  flex:1;display:flex;justify-content:center;align-items:flex-start;
  padding:8px;background:#e8e8e8;min-height:100%
}
.page-img{
  width:100%;max-width:500px;height:auto;border-radius:4px;
  box-shadow:0 4px 16px rgba(0,0,0,0.15);background:#fff;
  display:block;object-fit:contain
}

/* Tab: Solve */
.solve-area{
  flex:1;padding:16px;display:flex;flex-direction:column;min-height:100%
}
.solve-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:12px}
.solve-title{font-size:16px;font-weight:600}
.clear-btn{
  padding:6px 14px;border:1px solid var(--border);border-radius:8px;
  background:var(--surface);font-size:13px;color:var(--text2);cursor:pointer
}
.solve-input{
  flex:1;min-height:240px;padding:16px;border:1px solid var(--border);
  border-radius:12px;font-size:16px;line-height:1.7;resize:none;
  outline:none;font-family:inherit;background:var(--surface);color:var(--text)
}
.solve-input:focus{border-color:var(--primary)}
.solve-tips{margin-top:12px;font-size:12px;color:var(--text3)}

/* Tab: Answer */
.answer-area{
  flex:1;padding:16px;display:flex;flex-direction:column;min-height:100%
}
.answer-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:12px}
.answer-title{font-size:16px;font-weight:600}
.toggle-ans-btn{
  padding:8px 20px;border:none;border-radius:8px;
  background:var(--primary);color:#fff;font-size:14px;cursor:pointer
}
.toggle-ans-btn.showing{background:var(--success)}
.answer-content{
  flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;
  border:2px dashed var(--border);border-radius:12px;padding:16px;min-height:200px
}
.answer-img{width:100%;max-width:500px;height:auto;border-radius:4px;box-shadow:0 2px 8px rgba(0,0,0,0.1)}
.answer-placeholder{font-size:16px;color:var(--text3)}

/* Tab Bar */
.tab-bar{
  position:fixed;bottom:calc(var(--nav-h) + var(--safe-bottom));left:0;right:0;
  height:var(--tab-h);display:flex;background:var(--surface);
  border-top:1px solid var(--border);z-index:20
}
.tab-btn{
  flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;
  gap:2px;border:none;background:transparent;color:var(--text3);
  font-size:11px;cursor:pointer;transition:all 0.2s;padding:4px
}
.tab-btn.active{color:var(--primary)}
.tab-btn .tab-icon{font-size:22px;line-height:1}

/* Page Navigation */
.page-nav{
  position:fixed;bottom:0;left:0;right:0;
  height:var(--nav-h);display:flex;align-items:center;
  background:var(--surface);border-top:1px solid var(--border);
  padding:0 12px;z-index:20;
  padding-bottom:var(--safe-bottom)
}
.nav-btn{
  width:44px;height:36px;border:1px solid var(--border);
  border-radius:8px;background:var(--surface);font-size:16px;
  cursor:pointer;display:flex;align-items:center;justify-content:center;
  color:var(--text);flex-shrink:0
}
.nav-btn:active{background:var(--bg)}
.nav-center{
  flex:1;display:flex;align-items:center;justify-content:center;
  gap:4px;font-size:13px;color:var(--text2);cursor:pointer;padding:8px;
  margin:0 8px;border-radius:8px;white-space:nowrap;overflow:hidden
}
.nav-center:active{background:var(--bg)}
.nav-arrow{font-size:10px;color:var(--text3)}

/* Bottom Sheet */
.bottom-sheet-overlay{
  position:fixed;inset:0;background:rgba(0,0,0,0.4);
  z-index:30;opacity:0;visibility:hidden;transition:all 0.3s
}
.bottom-sheet-overlay.show{opacity:1;visibility:visible}
.bottom-sheet{
  position:fixed;bottom:0;left:0;right:0;z-index:31;
  background:var(--surface);border-radius:16px 16px 0 0;
  max-height:70vh;display:flex;flex-direction:column;
  transform:translateY(100%);transition:transform 0.3s cubic-bezier(0.16,1,0.3,1);
  padding-bottom:calc(var(--safe-bottom) + var(--nav-h))
}
.bottom-sheet.show{transform:translateY(0)}
.sheet-handle{
  width:36px;height:4px;border-radius:2px;background:var(--border);
  margin:8px auto 0
}
.sheet-header{
  display:flex;justify-content:space-between;align-items:center;
  padding:12px 16px;border-bottom:1px solid var(--border)
}
.sheet-header span{font-size:16px;font-weight:600}
.sheet-close{padding:6px 16px;border:none;border-radius:8px;background:var(--primary);color:#fff;font-size:14px;cursor:pointer}

/* School tabs in sheet */
.school-tabs{
  display:flex;flex-wrap:wrap;gap:6px;padding:12px 16px;
  border-bottom:1px solid var(--border);overflow-x:auto
}
.school-tag{
  padding:5px 12px;border-radius:16px;font-size:12px;
  border:1px solid var(--border);background:var(--surface);
  color:var(--text2);cursor:pointer;white-space:nowrap;transition:all 0.2s
}
.school-tag.active{color:#fff;border-color:transparent}

/* Section list in sheet */
.section-list{flex:1;overflow-y:auto;padding:4px 0}
.section-item{
  display:flex;align-items:center;gap:12px;padding:10px 16px;
  cursor:pointer;transition:background 0.15s;border-left:3px solid transparent
}
.section-item:active{background:var(--bg)}
.section-item.active{
  background:#f0f5ff;border-left-color:var(--primary)
}
.section-item .dot{width:8px;height:8px;border-radius:50%;flex-shrink:0}
.section-item .sinfo{flex:1;min-width:0}
.section-item .sname{font-size:14px;font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.section-item .sdesc{font-size:11px;color:var(--text3);margin-top:1px}
.section-item .spage{font-size:11px;color:var(--text3);font-family:monospace}

/* Page transition */
.page-img.loading{opacity:0.5}

/* Loading State */
.loading-overlay{
  position:absolute;inset:0;display:flex;align-items:center;
  justify-content:center;background:var(--bg);z-index:5
}
.spinner{width:32px;height:32px;border:3px solid var(--border);border-top-color:var(--primary);border-radius:50%;animation:spin 0.8s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}

/* Scrollbar */
::-webkit-scrollbar{width:4px}
::-webkit-scrollbar-thumb{background:var(--border);border-radius:2px}

/* Dark Mode Support */
@media (prefers-color-scheme:dark){
  :root{
    --bg:#1a1a1a;
    --surface:#2a2a2a;
    --text:#e5e6eb;
    --text2:#a9a9b0;
    --text3:#6b6b76;
    --border:#383838;
  }
  .page-container{background:#111}
  .section-item.active{background:#1a2744}
}
