:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-alt: #faf8f4;
  --border: #e4ded2;
  --text: #1f2421;
  --muted: #66635b;
  --accent: #2f6b56;
  --accent-hover: #255746;
  --accent-soft: #e6f0ec;
  --warm-soft: #fef7e6;
  --warm-border: #edd79b;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(31, 36, 33, 0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

.container {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 18px;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  min-height: 62px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 8px;
  padding-bottom: 8px;
}

.header-left, .header-right, .main-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.08rem;
  color: var(--text);
  margin-right: 6px;
}
.brand:hover { text-decoration: none; }
.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 7px;
  object-fit: cover;
  flex-shrink: 0;
}

.nav-link {
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover {
  background: var(--surface-alt);
  color: var(--text);
  text-decoration: none;
}
.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.nav-link.nav-wall {
  border: 1px solid var(--border);
}
.nav-link.nav-wall.active {
  border-color: var(--accent);
}

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  font-size: 0.84rem;
  font-weight: 600;
}

.role-badge {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.inline-form { display: inline; margin: 0; }

/* Main layout */
.page-main {
  flex: 1;
  padding-top: 24px;
  padding-bottom: 48px;
}

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.85rem;
}
.footer-inner {
  min-height: 54px;
  padding: 14px 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 20px;
}
.footer-copy p { margin: 0; line-height: 1.5; }
.footer-copyright { margin-top: 4px; font-size: 0.82rem; }
.footer-copy a { color: var(--accent); text-decoration: underline; }

/* Cards & Buttons */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 9px 15px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-sm { padding: 6px 10px; font-size: 0.84rem; border-radius: 8px; }
.btn-block { width: 100%; }

.btn-primary { background: var(--accent); color: #ffffff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { background: #efece3; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--surface-alt); }

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
  border-color: #f3c4be;
}
.btn-danger-ghost:hover:not(:disabled) { background: var(--danger-soft); }

/* Typography & Hero */
h1, h2, h3 { margin: 0 0 8px 0; line-height: 1.25; }
h1 { font-size: 1.65rem; font-weight: 800; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 0.85rem; }

.hero-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 22px;
}

.section-block { margin-bottom: 28px; }
.section-title {
  font-size: 1.08rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 0.9rem;
  color: var(--muted);
}

/* Inputs & Forms */
.stack-form { display: flex; flex-direction: column; gap: 14px; }
.field-group { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.field-label { font-size: 0.88rem; font-weight: 600; color: var(--text); }
.text-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
}
.text-input:focus {
  outline: 2px solid rgba(47, 107, 86, 0.25);
  border-color: var(--accent);
}
.textarea-input { resize: vertical; min-height: 86px; }

/* Login */
.login-wrap {
  max-width: 640px;
  margin: 32px auto;
}
.login-card + .login-card { margin-top: 16px; }
.login-card h1 { font-size: 1.45rem; margin-bottom: 8px; }
.login-card h2 { font-size: 1.15rem; margin-bottom: 6px; }
.login-card p { margin-bottom: 16px; font-size: 0.94rem; }
.intro-card p { margin-bottom: 12px; }
.intro-card .intro-closing { margin-bottom: 0; }
.landing-list {
  margin: 0 0 12px 20px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.94rem;
  line-height: 1.5;
}
.why-list { margin-bottom: 0; gap: 8px; }
.card-footnote { margin: 14px 0 0; text-align: center; }
.card-footnote a { color: var(--accent); text-decoration: underline; }
.legal-card-wrap { max-width: 720px; margin: 28px auto; }
.legal-card h1 { font-size: 1.5rem; margin-bottom: 4px; }
.legal-card h2 { font-size: 1.08rem; margin: 20px 0 8px; }
.legal-card p { margin: 0 0 12px; font-size: 0.95rem; line-height: 1.6; }
.legal-card a { color: var(--accent); text-decoration: underline; }
.legal-header { margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.legal-actions { margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--border); }
.legal-actions .btn { text-decoration: none; color: inherit; }
.access-request-card { margin-top: 16px; }
.access-request-panel { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.hp-field {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* Alerts & Toast */
.alert {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.9rem;
  margin-bottom: 14px;
}
.alert-success { background: var(--accent-soft); color: var(--accent); border: 1px solid #b9dacd; }
.alert-error { background: var(--danger-soft); color: var(--danger); border: 1px solid #f7c7c2; }
.alert-warn { background: var(--warm-soft); color: #7c5809; border: 1px solid var(--warm-border); }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: #ffffff;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}

/* Monthly Folders Grid */
.month-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 12px;
}
.month-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--text);
  transition: transform 0.12s, border-color 0.12s;
}
.month-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  text-decoration: none;
}
.month-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.folder-icon { font-size: 1.35rem; }
.month-name { font-size: 1.25rem; font-weight: 800; }
.month-sub { font-size: 0.86rem; color: var(--accent); font-weight: 600; }

.count-pill {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.month-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}
.pill-link {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 600;
}
.pill-link.active, .pill-link:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
  text-decoration: none;
}

/* Word List & Search */
.list-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.index-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  flex: 1 1 360px;
  justify-content: flex-end;
}
.search-wrap { flex: 1 1 220px; max-width: 340px; }
.sort-select { width: auto; min-width: 170px; cursor: pointer; }

.word-list {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.word-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.word-row:last-child { border-bottom: none; }
.word-row:hover { background: var(--surface-alt); text-decoration: none; }
.word-row-main { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.word-title { font-weight: 700; font-size: 1.02rem; }
.word-meta { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 6px; }

.date-tag, .month-tag {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
}
.date-tag { background: #efece3; color: #47443d; font-variant-numeric: tabular-nums; }
.month-tag { background: var(--accent-soft); color: var(--accent); }
.row-arrow { color: var(--accent); font-weight: 700; white-space: nowrap; }

.empty-state { text-align: center; color: var(--muted); padding: 28px 18px; }

/* Vocabulary Document Reader */
.doc-shell { padding: 26px; }
.doc-header {
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
  margin-bottom: 22px;
}
.doc-header-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.doc-title { font-size: 1.85rem; font-weight: 800; }

.doc-reader {
  font-size: 1.03rem;
  line-height: 1.75;
  overflow-wrap: anywhere;
}
.doc-reader p { margin: 0 0 14px 0; }
.doc-reader ul, .doc-reader ol {
  margin: 0 0 16px 0;
  padding-left: 24px;
}
.doc-reader li { margin-bottom: 6px; }
.doc-reader p.entry-header {
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  padding: 12px 15px;
  border-radius: 0 10px 10px 0;
  margin-top: 20px;
}
.doc-reader p.section-heading {
  background: var(--warm-soft);
  border-left: 4px solid #d4a72c;
  padding: 9px 14px;
  border-radius: 0 10px 10px 0;
  font-weight: 700;
  margin-top: 22px;
}
.doc-reader p.example-quote {
  border-left: 3px solid var(--border);
  padding-left: 14px;
  color: #2f3530;
}
.doc-inline-img {
  display: block;
  max-width: 100%;
  height: auto;
  max-height: 520px;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin: 12px 0;
  cursor: zoom-in;
}
.plain-text-doc {
  white-space: pre-wrap;
  background: var(--surface-alt);
  padding: 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-family: inherit;
}
.doc-reader table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
}
.doc-reader th, .doc-reader td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
}

.doc-pager {
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* Comments & Pictures Wall */
.composer-card { margin-bottom: 22px; }
.composer-row { display: flex; flex-wrap: wrap; gap: 12px; }
.composer-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.file-picker-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.btn-file { margin: 0; }

.preview-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 4px;
}
.preview-item {
  width: 82px;
  height: 82px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.wall-feed {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.post-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.post-author-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.post-author { font-weight: 700; font-size: 1rem; }
.post-time { font-size: 0.84rem; color: var(--muted); }
.post-body {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.98rem;
  margin-bottom: 12px;
}

.post-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
}
.post-gallery.single {
  grid-template-columns: minmax(0, 440px);
}
.gallery-thumb-btn {
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-alt);
  cursor: zoom-in;
}
.gallery-thumb-btn img {
  width: 100%;
  height: 220px;
  object-fit: cover;
  display: block;
}
.post-gallery.single .gallery-thumb-btn img {
  height: auto;
  max-height: 460px;
  object-fit: contain;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(15, 18, 16, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: 94vw;
  max-height: 88vh;
  border-radius: 10px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.45);
}
.lightbox-close {
  position: fixed;
  top: 18px;
  right: 20px;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: none;
  background: rgba(255,255,255,0.2);
  color: #ffffff;
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
}
.lightbox-close:hover { background: rgba(255,255,255,0.32); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(15, 18, 16, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.modal-backdrop[hidden] { display: none; }
.modal-card {
  width: 100%;
  max-width: 500px;
  max-height: 92vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.modal-header h2 { font-size: 1.2rem; margin: 0; }
.modal-close {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.15rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.modal-close:hover { background: var(--surface-alt); color: var(--text); }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Header Chinese Tooltips */
[data-tooltip] {
  position: relative;
}
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%) translateY(-2px);
  padding: 5px 10px;
  border-radius: 7px;
  background: var(--text);
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 50;
  transition: opacity 0.14s ease, transform 0.14s ease, visibility 0.14s ease;
}
[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* Admin User Management */
.admin-users-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 18px;
  align-items: start;
}
.table-scroll { overflow-x: auto; }
.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.users-table th,
.users-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.users-table th {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}
.row-actions {
  display: flex;
  gap: 6px;
}
.btn-danger-text { color: var(--danger); }
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  cursor: pointer;
}
@media (max-width: 820px) {
  .admin-users-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .container { padding: 0 14px; }
  .header-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding-top: 10px;
    padding-bottom: 10px;
  }
  .header-left {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .main-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }
  .nav-link {
    text-align: center;
    padding: 9px 10px;
    font-size: 0.88rem;
  }
  .header-right {
    justify-content: space-between;
    width: 100%;
    padding-top: 4px;
    border-top: 1px solid var(--border);
  }
  .page-main { padding-top: 18px; padding-bottom: 36px; }
  .hero-bar { flex-direction: column; align-items: stretch; gap: 10px; margin-bottom: 18px; }
  .hero-actions .btn { width: 100%; }
  .month-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .month-card { padding: 14px; }
  .month-name { font-size: 1.12rem; }
  .index-controls {
    flex: 1 1 100%;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }
  .search-wrap, .sort-select { max-width: 100%; width: 100%; }
  .word-row { padding: 12px 13px; }
  .doc-shell { padding: 16px; }
  .doc-title { font-size: 1.45rem; }
  .doc-reader table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .doc-pager { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .doc-pager > a { grid-column: 1 / -1; order: 3; }
  .doc-pager > div .btn { width: 100%; }
  .composer-footer { flex-direction: column; align-items: stretch; }
  .file-picker-wrap { justify-content: space-between; }
  #wallSubmitBtn { width: 100%; min-height: 46px; }
  .post-gallery { grid-template-columns: repeat(2, 1fr); }
  .post-gallery.single { grid-template-columns: 1fr; }
  .gallery-thumb-btn img { height: 150px; }
  .card { padding: 15px; }
  .site-footer { padding-bottom: env(safe-area-inset-bottom); }
}

.post-translation {
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--surface-alt);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  color: var(--text);
  font-size: 0.96rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.translation-label {
  font-weight: 700;
  color: var(--accent);
  margin-right: 4px;
}
.post-translation-link-row {
  margin-top: 6px;
}
.translate-ext-link {
  display: inline-block;
  margin-left: 8px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}
.translate-ext-link:hover {
  text-decoration: underline;
}

/* Topic hashtag accordions */
.tag-accordion-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 14px;
}
.tag-accordion {
  padding: 0;
  overflow: hidden;
}
.tag-accordion-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 18px;
  cursor: pointer;
  user-select: none;
  font-size: 1.08rem;
  font-weight: 700;
}
.tag-accordion-summary::-webkit-details-marker {
  display: none;
}
.tag-accordion-summary:hover {
  background: var(--surface-alt);
}
.tag-accordion-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.tag-accordion-chevron {
  color: var(--muted);
  font-size: 1rem;
  transition: transform 0.18s ease;
}
.tag-accordion[open] .tag-accordion-chevron {
  transform: rotate(180deg);
}
.tag-accordion-body {
  border-top: 1px solid var(--border);
}
.tag-accordion-body .word-list {
  border: none;
  border-radius: 0;
  box-shadow: none;
}
