/* ============================================================
   MathLingua · 桌面端应用外壳
   左侧导航 + 顶栏 + 内容区，向下优雅回退到平板 / 手机
   ============================================================ */

.app-shell {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--canvas);
}

/* ============================ 左侧导航 ============================ */
.sidebar {
  width: var(--sidebar-w);
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: calc(20px + var(--safe-top)) 16px 18px;
  background: var(--white);
  border-right: 2px solid var(--line);
  overflow-y: auto;
}

.brand {
  display: flex; align-items: center; gap: 11px;
  padding: 4px 6px 6px;
}
.brand-mark {
  width: 46px; height: 46px; flex: none;
  display: grid; place-items: center;
  font-size: 25px; line-height: 1;
  background: linear-gradient(135deg, #e9ffd9, #d7f7ff);
  border-radius: 15px;
  box-shadow: 0 3px 0 #d6f0c6;
  animation: owlBob 3.6s ease-in-out infinite;
}
@keyframes owlBob {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-4px) rotate(3deg); }
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text b {
  font-size: 18px; font-weight: 900; letter-spacing: 0.2px;
  color: var(--green-deep); line-height: 1.2;
}
.brand-text small {
  font-size: 11.5px; font-weight: 800; color: var(--text-muted);
  letter-spacing: 1.2px;
}

.nav { display: flex; flex-direction: column; gap: 6px; }

.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  border: 2px solid transparent;
  background: none;
  color: var(--text-soft);
  border-radius: 14px;
  padding: 11px 13px;
  font: inherit; font-size: 15px; font-weight: 800;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease,
    border-color 0.15s ease;
}
.nav-ico {
  font-size: 19px; width: 26px; text-align: center;
  filter: grayscale(0.75); transition: filter 0.15s ease;
}
.nav-item:hover { background: #f6f6f6; color: var(--text); }
.nav-item:hover .nav-ico { filter: none; }
.nav-item:active { transform: scale(0.985); }
.nav-item.active {
  background: var(--green-soft);
  color: var(--green-deep);
  border-color: #bdec8f;
  box-shadow: 0 3px 0 #d3f2b2;
}
.nav-item.active .nav-ico { filter: none; }

.nav-badge {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  background: var(--red); color: #fff;
  font-size: 11px; font-style: normal; font-weight: 800;
  min-width: 20px; height: 20px; line-height: 20px; text-align: center;
  border-radius: var(--radius-pill); padding: 0 5px;
  box-shadow: 0 2px 0 var(--red-dark);
}

/* 侧栏激励卡 */
.side-card {
  margin-top: 2px;
  padding: 14px;
  border-radius: var(--radius-lg);
  background: linear-gradient(160deg, #fff9ec, #fff3d8);
  border: 2px solid #ffe6ad;
  box-shadow: 0 3px 0 #ffe0a0;
}
.side-card-top { display: flex; align-items: center; gap: 10px; }
.side-card-emoji { font-size: 22px; line-height: 1; }
.side-card-top b { display: block; font-size: 14px; color: var(--orange-deep); }
.side-card-top small { font-size: 11.5px; font-weight: 700; color: #b58a4a; }
.side-card-bar {
  height: 8px; border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.8);
  margin: 11px 0 9px;
  overflow: hidden;
}
.side-card-bar i {
  display: block; height: 100%; width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #ffd24d, var(--orange));
  transition: width 0.5s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.side-card-note {
  font-size: 11.5px; font-weight: 700; color: #96784a; line-height: 1.5;
}

.side-user {
  margin-top: auto;
  display: flex; align-items: center; gap: 11px;
  padding: 12px;
  border-radius: var(--radius-lg);
  background: #f8f8f8;
  border: 2px solid var(--line);
}
.avatar {
  width: 42px; height: 42px; flex: none;
  display: grid; place-items: center;
  font-size: 22px;
  background: var(--white);
  border-radius: var(--radius-pill);
  box-shadow: 0 3px 0 var(--line);
}
.side-user-meta { flex: 1; min-width: 0; }
.side-user-meta b {
  display: block; font-size: 13px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.side-user-meta small { font-size: 11px; font-weight: 800; color: var(--text-muted); }
.xp-bar {
  height: 8px; border-radius: var(--radius-pill);
  background: #e7e7e7; overflow: hidden; margin: 5px 0 3px;
}
.xp-bar i {
  display: block; height: 100%; width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #7ce03a, var(--green));
  transition: width 0.5s cubic-bezier(0.2, 0.9, 0.3, 1);
}

/* ============================ 主区域 ============================ */
.main {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  overflow: hidden;
}

.topbar {
  flex: none;
  display: flex; align-items: center; justify-content: space-between;
  gap: 18px;
  padding: 16px 30px;
  background: rgba(247, 247, 247, 0.92);
  border-bottom: 2px solid rgba(0, 0, 0, 0.045);
  backdrop-filter: blur(6px);
}
.topbar-title { min-width: 0; }
.topbar-title h1 { font-size: 22px; font-weight: 900; letter-spacing: 0.2px; }
.topbar-title p {
  font-size: 13px; font-weight: 700; color: var(--text-muted);
  margin-top: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-stats { display: flex; align-items: center; gap: 8px; flex: none; }

.screens { flex: 1; min-height: 0; position: relative; }

.screen {
  display: none;
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 26px 30px 40px;
}
.screen.active { display: block; }
.screen.active.screen--flex { display: flex; flex-direction: column; }

/* ============================ 错题本 ============================ */
.nb-wrap { max-width: 1180px; margin: 0 auto; }

.nb-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 20px;
}
.nb-head h2 { font-size: 21px; font-weight: 900; margin-bottom: 4px; }
.nb-head p { font-size: 13px; font-weight: 700; color: var(--text-muted); }

.nb-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.nb-item {
  display: flex; flex-direction: column;
  background: var(--white);
  border: 2px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 18px;
}
.nb-item .nb-tag {
  align-self: flex-start;
  font-size: 11.5px; font-weight: 800; color: var(--blue-deep);
  background: var(--blue-soft);
  border-radius: var(--radius-pill);
  padding: 3px 10px; margin-bottom: 9px;
}
.nb-item .nb-q {
  font-size: 14.5px; font-weight: 800; line-height: 1.6;
  margin-bottom: 10px; color: var(--text);
}
.nb-item .nb-f {
  font-size: 22px; font-weight: 900; letter-spacing: 1px;
  margin-bottom: 12px; color: #2f2f2f;
  font-variant-numeric: tabular-nums;
}
.nb-item .nb-row {
  display: flex; gap: 8px; flex-wrap: wrap;
  font-size: 12.5px; font-weight: 800; margin-bottom: 14px;
}
.nb-item .nb-wrong {
  color: var(--red-deep); background: var(--red-soft);
  padding: 4px 10px; border-radius: 9px;
}
.nb-item .nb-right {
  color: var(--green-deep); background: var(--green-soft);
  padding: 4px 10px; border-radius: 9px;
}
.nb-actions { display: flex; gap: 9px; margin-top: auto; }

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
  background: var(--white);
  border: 2px dashed var(--line);
  border-radius: var(--radius-xl);
}
.empty-state .big { font-size: 56px; display: block; margin-bottom: 12px; }
.empty-state p { font-size: 14px; font-weight: 700; margin: 4px 0; }
.empty-state b { color: var(--green-deep); }

/* ============================ 练习小结 ============================ */
.summary-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100%;
  padding: 12px 0;
}
.summary-card {
  width: 100%; max-width: 760px;
  background: var(--white);
  border: 2px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: 0 6px 0 var(--line);
  padding: 32px;
  text-align: center;
}
.summary-emoji {
  font-size: 56px; line-height: 1; display: block;
  animation: summaryPop 0.55s cubic-bezier(0.2, 1.5, 0.4, 1);
}
@keyframes summaryPop {
  0% { transform: scale(0.3) rotate(-18deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
.summary-top h2 { font-size: 25px; font-weight: 900; margin: 10px 0 5px; color: var(--green-deep); }
.summary-top p { font-size: 14px; font-weight: 700; color: var(--text-muted); margin-bottom: 22px; }

.summary-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
}
.summary-stat {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: #f8faf5;
  border: 2px solid #eef3e8;
  border-radius: var(--radius-md);
  padding: 14px 8px;
}
.summary-stat span { font-size: 19px; }
.summary-stat b { font-size: 21px; font-weight: 900; font-variant-numeric: tabular-nums; }
.summary-stat small { font-size: 11.5px; font-weight: 800; color: var(--text-muted); }

.summary-tip {
  margin: 18px 0 22px;
  background: var(--yellow-soft);
  border: 2px solid #ffe8a3;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 13.5px; font-weight: 800; color: var(--yellow-deep);
  line-height: 1.6;
}
.summary-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.summary-actions .btn-3d { min-width: 230px; }

/* ============================ 平板 / 手机回退 ============================ */
@media (max-width: 1080px) {
  .app-shell { flex-direction: column; }

  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: calc(8px + var(--safe-top)) 16px 8px;
    border-right: none;
    border-bottom: 2px solid var(--line);
    overflow: visible;
  }
  .brand { padding: 0; flex: none; }
  .brand-mark { width: 38px; height: 38px; font-size: 21px; border-radius: 13px; }
  .brand-text small { display: none; }
  .brand-text b { font-size: 16px; }

  .nav { flex-direction: row; gap: 6px; margin-left: auto; }
  .nav-item { width: auto; padding: 9px 12px; font-size: 14px; }
  .nav-item.active { box-shadow: 0 2px 0 #d3f2b2; }
  .nav-badge { position: static; transform: none; margin-left: 2px; }

  .side-card, .side-user { display: none; }
}

@media (max-width: 860px) {
  .topbar { padding: 12px 18px; }
  .topbar-title h1 { font-size: 19px; }
  .topbar-title p { display: none; }
  .topbar-stats { gap: 6px; }
  .stat-pill { padding: 7px 10px; font-size: 13px; }
  .stat-pill b { font-size: 13px; }
  .screen { padding: 18px 18px 30px; }
  .nb-list { grid-template-columns: 1fr; }
  .summary-card { padding: 24px 18px; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .summary-actions .btn-3d { min-width: 0; width: 100%; }
}

@media (max-width: 560px) {
  .brand-text { display: none; }
  .nav { margin-left: 0; flex: 1; justify-content: space-between; }
  .nav-item { flex-direction: column; gap: 2px; padding: 7px 8px; font-size: 10.5px; }
  .nav-ico { font-size: 17px; }
  .topbar { padding: 10px 12px; gap: 8px; }
  .topbar-title h1 { font-size: 16px; }
  .topbar-stats .stat-pill.xp { display: none; }
  .stat-pill { padding: 6px 8px; font-size: 12px; }
  .stat-pill b { font-size: 12px; }
  .heart { font-size: 11px; }
  .icon-btn { width: 34px; height: 34px; font-size: 15px; border-radius: 11px; }
  .screen { padding: 14px 12px 26px; }
  .nb-head { flex-direction: column; align-items: stretch; gap: 10px; }
  .nb-head .btn-3d { width: 100%; }
}
