.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg-glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px 6px;
  flex-wrap: wrap;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-badge {
  font-size: 20px;
  animation: hop 2.5s ease-in-out infinite;
  display: inline-block;
}

.app-title {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: .5px;
  white-space: nowrap;
  color: var(--brand-d);
  font-family: var(--font-num);
}

.op-switch {
  margin: 0;
  border-radius: 999px;
  background: var(--muted);
  border-color: var(--line);
}

.op-switch .seg-btn {
  min-height: 40px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 999px;
}

.op-switch .seg-btn.is-on {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 2px 6px rgba(109, 63, 217, 0.28);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.act-btn {
  min-height: 36px;
  padding: 0 10px;
  border-radius: var(--r-md);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  border: 1.5px solid var(--line);
  background: var(--card);
}

.act-icon { font-size: 15px; }

@media (max-width: 720px) {
  .header-brand {
    flex: 1 1 100%;
    flex-wrap: wrap;
  }
  .op-switch {
    display: flex;
    width: 100%;
  }
  .op-switch .seg-btn {
    flex: 1 1 0;
    padding: 0 4px;
    font-size: 12px;
  }
}

@media (max-width: 480px) {
  .act-btn {
    padding: 0 8px;
  }
  .act-btn .act-text {
    display: none;
  }
  .act-icon { font-size: 18px; }
}

.div-story { margin-bottom: 12px; }

.tabbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 2px 14px 8px;
}

.tab {
  min-height: 44px;
  border: 1.5px solid transparent;
  background: var(--card);
  border-radius: var(--r-md);
  font-size: clamp(13px, 3.7vw, 15px);
  font-weight: 600;
  color: var(--ink-2);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  box-shadow: 0 2.5px 0 var(--line);
  transition: transform .08s ease, box-shadow .08s ease, background .12s;
}

.tab:active {
  transform: translateY(2px);
  box-shadow: 0 0.5px 0 var(--line);
}

.tab.is-on {
  color: var(--brand-d);
  background: var(--brand-l);
  border-color: rgba(139, 92, 246, 0.35);
  box-shadow: 0 3px 0 rgba(109, 63, 217, 0.25);
  transform: translateY(-1px);
}

/* ---------- settings ---------- */

.settings {
  position: fixed;
  top: calc(56px + env(safe-area-inset-top));
  right: 12px;
  z-index: 40;
  padding: 0;
}

.settings-inner {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: 0 10px 30px rgba(91, 63, 150, .16);
  padding: 14px 16px;
  min-width: 270px;
  max-width: min(92vw, 340px);
  max-height: calc(100vh - 72px - env(safe-area-inset-top));
  overflow-y: auto;
  overscroll-behavior: contain;
  animation: fadein .18s ease-out both;
}

.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
}

.set-row-end { justify-content: flex-end; padding-top: 12px; }

.set-label { font-size: 14px; color: var(--ink); }

.set-note {
  font-size: 12px;
  color: var(--ink-3);
  padding: 4px 0 0;
  margin: 0;
}

/* ---------- main ---------- */

.app-main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px;
}

/* 只用 opacity 做入场，避免 transform 造成 containing block 而破坏弹层的 fixed 定位 */
.panel { animation: fadein .2s ease-out both; }

/* ---------- explore ---------- */

.pickers {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.picker {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.picker-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 10px;
}

.stepper-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.pv {
  display: inline-block;
  min-width: 32px;
  text-align: center;
  font-family: var(--font-num);
  font-size: 26px;
  font-weight: 700;
  color: var(--brand-d);
  flex-shrink: 0;
}

.nums {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 6px;
  width: 100%;
}

.num {
  grid-column: span 2;
  aspect-ratio: 1;
  min-height: 44px;
  min-width: 0;
  border: 1.5px solid var(--line-2);
  border-radius: var(--r-md);
  background: var(--card);
  font-family: var(--font-num);
  font-size: 19px;
  font-weight: 700;
  color: var(--ink);
  box-shadow: 0 3px 0 var(--line-2);
  padding: 0;
  transition: transform .08s ease, box-shadow .08s ease, background .15s;
}

.num:nth-child(6) {
  grid-column: 2 / span 2;
}

.num:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--line-2);
}

.num.is-on {
  background: var(--brand);
  border-color: var(--brand-d);
  color: #fff;
  box-shadow: 0 3px 0 var(--brand-d);
  transform: translateY(-1px);
}

.num.is-off,
.num:disabled {
  opacity: .35;
  box-shadow: none;
  transform: none;
}

.nums.nums-wide {
  grid-template-columns: repeat(7, 1fr);
}

.nums.nums-wide .num,
.nums.nums-wide .num:nth-child(6) {
  grid-column: auto;
  aspect-ratio: auto;
  min-height: 44px;
  font-size: 16px;
}

.slider-row {
  display: none !important;
}

.viewswitch {
  display: flex;
  gap: 6px;
  margin: 18px 0 8px;
  overflow-x: auto;
  padding: 4px 2px;
  position: relative;
  z-index: 1;
}

.vs {
  flex: 1 0 auto;
  min-height: 44px;
  padding: 0 14px;
  border: 1.5px solid var(--line-2);
  border-radius: var(--r-md);
  background: var(--card);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-2);
  box-shadow: 0 2.5px 0 var(--line-2);
  white-space: nowrap;
  transition: transform .08s, box-shadow .08s;
}

.vs:active {
  transform: translateY(2px);
  box-shadow: 0 0.5px 0 var(--line-2);
}

.vs.is-on {
  background: var(--accent-l);
  border-color: var(--accent);
  color: var(--accent-d);
  box-shadow: 0 3px 0 var(--accent);
  transform: translateY(-1px);
  position: relative;
  z-index: 2;
}

/* ---------- 具象道具皮肤选择栏 ---------- */
.skin-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 12px;
  flex-wrap: wrap;
}

.skin-bar-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
}

.skin-options {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 2px;
}

.skin-opt {
  border: 1.5px solid var(--line-2);
  background: var(--card);
  border-radius: var(--r-md);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  box-shadow: 0 2px 0 var(--line-2);
  white-space: nowrap;
  transition: transform .08s, box-shadow .08s, background .15s;
}

.skin-opt:active {
  transform: translateY(2px);
  box-shadow: 0 0 0 var(--line-2);
}

.skin-opt.is-on {
  background: var(--accent-l);
  border-color: var(--accent);
  color: var(--accent-d);
  box-shadow: 0 2.5px 0 var(--accent);
}

.stage {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 16px 12px;
  min-height: min(42vh, 420px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.sumline {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.sum-row {
  font-family: var(--font-num);
  font-size: clamp(18px, 4.6vw, 26px);
  letter-spacing: 1px;
  text-align: center;
}

.sum-row.sum-add { color: var(--ink-2); }
.sum-row.sum-mul { font-weight: 500; }
.sum-row.sum-div { font-weight: 600; color: var(--ink); }

.sum-row .op { color: var(--ink-3); }

.tk-brand { color: var(--brand-d); }
.tk-accent { color: var(--accent-d); }
.tk-quot { color: var(--ok-text); font-weight: 700; }

.sum-desc {
  font-size: 16px;
  color: var(--ink-2);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 2px;
}

.sum-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  background: var(--brand-l);
  color: var(--brand-d);
  padding: 2px 6px;
  border-radius: var(--r-sm);
}

.sum-think {
  font-size: 16px;
  color: var(--brand-d);
  background: rgba(139, 92, 246, 0.08);
  border: 1px dashed rgba(139, 92, 246, 0.3);
  padding: 5px 12px;
  border-radius: var(--r-md);
  margin-top: 4px;
}

.sum-legend {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 2px;
}

.sum-commute {
  color: var(--brand-d);
  font-weight: 500;
}

.explore-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  padding-bottom: env(safe-area-inset-bottom);
  flex-wrap: wrap;
}

.explore-actions .btn {
  flex: 1 1 auto;
  min-width: 80px;
}

/* ---------- table ---------- */

.table-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.stat {
  font-size: 15px;
  font-weight: 500;
  color: var(--brand-d);
}

.table-scroll-hint {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--brand-d);
  background: var(--brand-l);
  padding: 3px 10px;
  border-radius: var(--r-full);
  font-weight: 500;
  border: 1px solid rgba(79, 70, 229, 0.15);
  user-select: none;
  -webkit-user-select: none;
}

@media (min-width: 640px) {
  .table-scroll-hint {
    display: none !important;
  }
}

.table-split {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: start;
}

.table-wrap {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.mul-table {
  border-collapse: separate;
  border-spacing: 4px;
  width: 100%;
  min-width: 320px;
}

.mul-table th {
  font-family: var(--font-num);
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-2);
  padding: 2px;
}

.mul-table td { padding: 0; }

.cell {
  width: 100%;
  min-width: 40px;
  min-height: 44px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  font-family: var(--font-num);
  font-size: 17px;
  font-weight: 500;
  color: var(--ink);
  transition: transform .12s var(--ease);
}

.cell:active { transform: scale(.94); }

.cell.is-mastered { background: var(--ok-l); border-color: var(--ok); }
.cell.is-practice { background: var(--warn-l); border-color: var(--warn); }
.cell.is-wrong { border-color: var(--bad); }
.cell.is-on { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-l); }

.cell.is-div-cell {
  padding: 3px 1px;
  line-height: 1.15;
}

.div-cell-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.div-cell-eq {
  font-family: var(--font-num);
  font-size: clamp(10px, 2.6vw, 12px);
  color: var(--ink-2);
  white-space: nowrap;
}

.div-cell-ans {
  font-family: var(--font-num);
  font-size: clamp(12px, 3.2vw, 14px);
  font-weight: 700;
  color: var(--brand-d);
}

.cell.is-div-cell.is-mastered .div-cell-ans {
  color: var(--ok-text);
}

.cell.is-div-cell.is-wrong .div-cell-ans {
  color: var(--bad-text);
}

.cell-empty {
  min-height: 44px;
  border-radius: 10px;
  background: transparent;
}

.sum-board { margin-bottom: 8px; }

.sum-scroll-hint {
  display: inline-flex;
  align-items: center;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--brand-d);
  background: var(--brand-l);
  padding: 3px 10px;
  border-radius: var(--r-full);
  font-weight: 500;
}

.sum-totals {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 2px 8px;
}

.sum-total {
  flex: 0 0 auto;
  min-width: 40px;
  min-height: 40px;
  border: 1.5px solid var(--line-2);
  border-radius: 10px;
  background: var(--card);
  font-family: var(--font-num);
  font-size: 16px;
  font-weight: 700;
}

.sum-total.is-on {
  background: var(--brand);
  border-color: var(--brand-d);
  color: #fff;
}

.sum-eqs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px;
}

.detail-method {
  margin: 0 0 10px;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
}

.lv-name {
  font-size: 10px;
  line-height: 1.2;
  color: var(--ink-2);
  text-align: center;
  max-width: 76px;
}

/* 移动端弹层遮罩 */
.sheet-backdrop { display: none; }
.sheet-backdrop[hidden] { display: none !important; }

.detail {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 14px;
}

.detail-close {
  display: none;
  width: 100%;
  min-height: 44px;
  border: 1.5px solid var(--line-2);
  border-radius: var(--r-sm);
  background: var(--card);
  font-size: 15px;
  margin-bottom: 10px;
}

.detail-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.detail-eq {
  font-family: var(--font-num);
  font-size: clamp(26px, 7vw, 40px);
  font-weight: 500;
  letter-spacing: 1px;
}

.detail-koujue {
  font-size: 18px;
  color: var(--brand-d);
  font-weight: 500;
}

.detail-viz { margin: 10px 0; }

.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.detail-actions .btn { flex: 1; min-width: 110px; }

/* 防滚动穿透 */
body.no-scroll { overflow: hidden; }

/* ---------- responsive ---------- */

@media (min-width: 640px) {
  .app-main { padding: 20px; }
  .nums {
    grid-template-columns: repeat(9, 1fr);
  }
  .num {
    grid-column: auto;
    min-height: 46px;
    font-size: 20px;
  }
  .num:nth-child(6) {
    grid-column: auto;
  }
}

@media (min-width: 900px) {
  .pickers { grid-template-columns: 1fr 1fr; }
  .table-split.has-detail { grid-template-columns: 55fr 45fr; }
}

@media (max-width: 639px) {
  .sheet-backdrop {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 34;
    background: rgba(47, 42, 61, .35);
    animation: fadein .2s ease-out both;
  }

  .detail {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 35;
    max-height: 80dvh;
    max-height: 80vh;
    overflow-y: auto;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
    animation: rise .22s ease-out both;
  }

  .detail-close { display: block; }
}
