/* 基础排版、重置与全局导航外壳 */

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  background: var(--bg-paper);
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg-paper);
  color: var(--ink-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.78;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

img, svg {
  display: block;
  max-width: 100%;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--brand);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

h1, h2, h3, h4, p, ul, ol {
  margin: 0;
}

.serif {
  font-family: var(--font-serif);
}

.kai {
  font-family: var(--font-kai);
}

.muted {
  color: var(--ink-muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#app {
  min-height: 100dvh;
  outline: none;
}

body.has-shell #app {
  min-height: calc(100dvh - var(--header-h));
}

.page {
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 24px 20px 56px;
}

.page-narrow {
  max-width: 760px;
}

.page-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 260px;
  color: var(--ink-muted);
  font-size: 14px;
}

/* 品牌徽标 */
.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink-primary);
  flex-shrink: 0;
}

.brand-lockup:hover {
  text-decoration: none;
}

.brand-mark {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(145deg, #2B6B5A 0%, #19453A 100%);
  color: #FAF7F0;
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
  user-select: none;
}

.brand-mark-plus {
  position: absolute;
  top: -3px;
  right: -3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #C43B2B;
  color: #FFFFFF;
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  border: 1.5px solid var(--bg-card);
}

[data-subject="en"] .brand-mark,
.brand-mark.is-en {
  background: linear-gradient(145deg, #2E4785 0%, #1A2A55 100%);
}

.brand-mark.is-en {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 14.5px;
  letter-spacing: -0.02em;
}

.shell-subject-seg {
  padding: 3px;
  border-radius: 9px;
}

.shell-subject-seg > button {
  min-height: 26px;
  padding: 2px 10px;
  font-size: 12.5px;
  border-radius: 6px;
}

.brand-name {
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.25;
}

/* 书房全局 56px 顶栏 */
.shell-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-h);
  background: color-mix(in srgb, var(--bg-paper) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-soft);
}

.shell-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: var(--page-max);
  height: 100%;
  margin: 0 auto;
  padding: 0 20px;
}

.shell-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.shell-divider {
  width: 1px;
  height: 18px;
  background: var(--border-strong);
  flex-shrink: 0;
}

.child-switcher {
  position: relative;
}

.child-switch-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 11px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-soft);
  background: var(--bg-card);
  color: var(--ink-primary);
  font-size: 13.5px;
  font-weight: 500;
  max-width: 210px;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.child-switch-btn:hover {
  border-color: var(--border-strong);
  background: var(--bg-subtle);
}

.child-switch-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.child-switch-grade {
  font-size: 12px;
  color: var(--ink-muted);
  white-space: nowrap;
}

.popover-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 224px;
  padding: 6px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-soft);
  background: var(--bg-card);
  box-shadow: var(--shadow-float);
  z-index: 60;
  animation: fade-up 0.14s ease;
}

.popover-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 9px 11px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-primary);
  font-size: 14px;
  text-align: left;
  transition: background-color 0.12s ease;
}

.popover-item:hover {
  background: var(--bg-subtle);
}

.popover-item.active {
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
}

.popover-item-meta {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.popover-item-sub {
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-muted);
}

.popover-sep {
  height: 1px;
  margin: 6px 4px;
  background: var(--border-soft);
}

.shell-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.shell-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  color: var(--ink-secondary);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.shell-link:hover {
  background: var(--bg-subtle);
  color: var(--ink-primary);
  text-decoration: none;
}

.shell-link.active {
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
}

/* 子页面精炼返回顶栏 */
.sub-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-h);
  background: color-mix(in srgb, var(--bg-paper) 94%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-soft);
}

.sub-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: var(--page-max);
  height: 100%;
  margin: 0 auto;
  padding: 0 16px;
}

.sub-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.sub-header-title {
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 700;
  color: var(--ink-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sub-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* 移动端底部三键 Dock */
.shell-dock {
  display: none;
}

@media (max-width: 899px) {
  .shell-header-inner {
    padding: 0 14px;
  }

  .shell-link-desktop,
  .shell-header .shell-subject-desktop {
    display: none;
  }

  .child-switch-grade {
    display: none;
  }

  .child-switch-btn {
    max-width: 136px;
    padding: 0 9px;
  }

  .page {
    padding: 18px 16px 40px;
  }

  body.has-dock #app {
    padding-bottom: calc(var(--dock-h) + env(safe-area-inset-bottom, 0px) + 22px);
  }

  .shell-dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 45;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    height: calc(var(--dock-h) + env(safe-area-inset-bottom, 0px));
    padding: 0 18px env(safe-area-inset-bottom, 0px);
    background: color-mix(in srgb, var(--bg-card) 96%, transparent);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--border-soft);
    box-shadow: 0 -4px 18px rgba(30, 36, 33, 0.05);
  }

  .dock-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    height: 48px;
    color: var(--ink-muted);
    font-size: 11.5px;
    font-weight: 500;
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: color 0.15s ease;
  }

  .dock-item:hover {
    text-decoration: none;
    color: var(--ink-primary);
  }

  .dock-item.active {
    color: var(--brand);
    font-weight: 600;
  }

  .dock-upload-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    margin-top: -18px;
    border-radius: 50%;
    border: 3px solid var(--bg-paper);
    background: linear-gradient(145deg, #2A6A59 0%, #19453A 100%);
    color: #FFFFFF;
    box-shadow: var(--shadow-float);
    transition: transform 0.15s ease, filter 0.15s ease;
  }

  .dock-upload-btn:active {
    transform: scale(0.95);
  }

  [data-subject="en"] .dock-upload-btn {
    background: linear-gradient(145deg, #2E4785 0%, #1A2A55 100%);
  }
}

@media (max-width: 420px) {
  .brand-name {
    font-size: 15.5px;
  }
  .shell-divider {
    display: none;
  }
}

/* 通用动画 */
@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse-dot {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.38);
    opacity: 0.45;
  }
}

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

.spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--brand);
  animation: spin 0.75s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
