.home-page,
.memorial-home-php {
  background: #080706;
}

.home-page .site-header {
  background: #080706;
  border-bottom-color: rgba(222, 185, 123, .14);
}

.family-gallery {
  height: calc(60vh - 82px);
  min-height: 460px;
  background-color: #000;
  background-image:
    linear-gradient(rgba(0, 0, 0, .16), rgba(0, 0, 0, .3)),
    url("beijing.gif");
  background-size: 100% 100%, 350px 263px;
  background-repeat: no-repeat, repeat;
  background-position: center, center top;
}

.family-gallery::before {
  z-index: 0;
  opacity: 1;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 34%, rgba(0, 0, 0, .18) 74%, rgba(0, 0, 0, .52) 100%);
  background-size: auto;
}

.family-gallery::after {
  content: none;
}

.family-generations {
  display: grid;
  grid-template-rows: 1fr 1fr 1.35fr;
  gap: .8vh;
  width: min(1060px, 86vw);
  padding: 1.5vh 4vw 1.2vh;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 70%, rgba(91, 43, 18, .42), transparent 62%),
    linear-gradient(135deg, rgba(28, 19, 13, .97), rgba(10, 8, 6, .98));
  border-left: 1px solid rgba(183, 130, 71, .13);
  border-right: 1px solid rgba(183, 130, 71, .13);
  box-shadow: 0 0 54px 28px rgba(0, 0, 0, .72);
}

.family-generation {
  min-height: 0;
  flex: none;
}

.family-generation::after {
  bottom: -.5vh;
}

.family-generation:first-child .ancestor-photo {
  height: min(17.5vh, 174px);
}

.family-generation:nth-child(2) .ancestor-photo {
  height: min(15.5vh, 154px);
}

.incense-offering {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.incense-offering::before {
  content: none;
}

.incense-offering img {
  width: min(50vw, 560px);
  max-height: 100%;
  object-fit: contain;
  position: relative;
  z-index: 1;
  mix-blend-mode: screen;
  filter: brightness(.94) drop-shadow(0 12px 22px rgba(0, 0, 0, .8));
}

.present-box {
  grid-template-columns: 62px 1fr auto;
}

.chrysanthemum-mark {
  width: 58px;
  height: 58px;
  object-fit: contain;
  border: 0;
  border-radius: 0;
  background: transparent;
  filter: drop-shadow(0 5px 8px rgba(68, 62, 46, .16));
}

.forum-reply {
  min-height: 70px;
}

.flower-cell {
  width: 100%;
  min-width: 0;
  display: flex;
  flex-wrap: nowrap;
  gap: 1px;
  align-items: center;
  overflow-x: auto;
  scrollbar-width: thin;
  padding: 3px 18px;
}

.flower-cell img {
  flex: 0 0 39px;
  width: 39px;
  height: 39px;
  object-fit: contain;
  filter: drop-shadow(0 3px 5px rgba(80, 72, 50, .15));
}

/* 桌面端约按上 60%、下 40% 分配空间；跟帖按可用高度尽量多显示。 */
.home-page {
  height: auto;
  min-height: 100vh;
  overflow-y: auto;
}

.memorial-home-php {
  height: auto;
}

.flower-thread {
  height: clamp(380px, 40vh, 500px);
  min-height: 380px;
}

.forum-thread {
  grid-template-rows: 44px minmax(0, 1fr);
}

.forum-scroll {
  height: auto;
  min-height: 0;
  overflow-y: scroll;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.forum-reply {
  height: auto;
  min-height: 70px;
}

.tribute-text {
  min-width: 0;
  max-height: 62px;
  overflow-y: auto;
  padding: 8px 18px;
  color: #4f5853;
  line-height: 1.7;
  word-break: break-word;
}

.present-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.present-actions form {
  margin: 0;
}

.present-actions .primary {
  padding: 9px 12px;
  font-size: 12px;
  text-decoration: none;
}

.position-guide {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin: 0 0 18px;
  padding: 12px 15px;
  background: #f6f1e7;
  border-left: 3px solid #b39764;
  color: #6d6f6b;
  font-size: 12px;
}

.position-guide b {
  color: #5c4a2d;
}

.designated-upload {
  margin-bottom: 22px;
  padding: 15px;
  background: #fbfaf7;
  border: 1px solid #e0dacd;
}

.designated-upload select,
.designated-upload input {
  display: block;
  min-width: 130px;
  margin-top: 5px;
  padding: 8px;
  border: 1px solid #d6d0c4;
  background: #fff;
}

.designated-upload label small {
  display: block;
  margin-top: 4px;
  color: #92948f;
}

.photo-position {
  margin: -10px -10px 10px;
  padding: 7px 10px;
  background: #183e33;
  color: #f5ead7;
  font-size: 11px;
  text-align: center;
}

.photo-admin-grid .photo-edit-form {
  grid-template-columns: repeat(3, 1fr);
}

.photo-admin-grid .photo-edit-form .replace-photo,
.photo-admin-grid .photo-edit-form button {
  grid-column: 1 / -1;
}

.admin-edit-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(130px, 1fr));
  gap: 7px;
  min-width: 360px;
}

.admin-edit-form label {
  color: #777b76;
  font-size: 10px;
}

.admin-edit-form input,
.admin-edit-form select,
.member-message-edit textarea {
  display: block;
  width: 100%;
  margin-top: 3px;
  padding: 6px 7px;
  border: 1px solid #d3cdc1;
  background: #fff;
}

.admin-edit-form button {
  align-self: end;
}

.member-create-form {
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding: 14px;
  border: 1px solid #ded7ca;
  background: #faf8f3;
}

.member-create-form input {
  width: 150px;
}

.member-message-edit {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 8px;
  min-width: 340px;
}

.member-message-edit textarea {
  min-height: 64px;
  resize: vertical;
}

.tribute-delete-form,
.user-delete-form {
  margin-top: 7px;
}

.tribute-delete-form .danger,
.user-delete-form .danger {
  border-color: #cba6a0;
  color: #8b403a;
}

.setting-switch-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  padding: 16px 18px;
  border: 1px solid #ded7ca;
  background: #faf8f3;
}

.setting-switch {
  display: flex;
  align-items: center;
  gap: 13px;
  cursor: pointer;
}

.setting-switch input {
  width: 22px;
  height: 22px;
  accent-color: #183e33;
}

.setting-switch b,
.setting-switch small {
  display: block;
}

.setting-switch b {
  margin-bottom: 4px;
  color: #34433c;
}

.setting-switch small,
.setting-readonly {
  color: #7f837e;
  font-size: 12px;
}

@media (max-width: 680px) {
  .family-generations {
    grid-template-rows: 1fr 1fr 1.55fr;
    width: min(92vw, 470px);
    padding: 8px 10px 12px;
    gap: 5px;
  }

  .family-gallery {
    background-size: 100% 100%, 350px 263px;
  }

  .family-generation {
    min-height: 0;
  }

  .incense-offering img {
    width: min(88vw, 480px);
  }

  .present-box {
    grid-template-columns: 52px 1fr auto;
  }

  .flower-thread {
    height: 432px;
    min-height: 432px;
  }

  .forum-thread {
    grid-template-rows: 44px 312px;
  }

  .forum-scroll {
    height: 312px;
  }

  .present-actions {
    gap: 4px;
  }

  .present-actions .primary {
    padding: 7px 8px;
    font-size: 11px;
  }

  .chrysanthemum-mark {
    width: 50px;
    height: 50px;
  }

  .flower-cell img {
    flex-basis: 39px;
    width: 39px;
    height: 39px;
  }

  .flower-cell {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: stretch;
    padding: 4px 10px;
  }

  .forum-reply {
    grid-template-rows: 42px 62px;
    min-height: 104px;
  }

  .member-cell {
    grid-column: 2 / -1;
  }

  .text-reply .tribute-text {
    grid-column: 1 / -1;
    grid-row: 2;
    max-height: 62px;
  }

  .designated-upload,
  .admin-edit-form,
  .member-message-edit,
  .setting-switch-form {
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .setting-switch-form {
    display: grid;
  }
}

/* 手机端完整功能布局：导航、祭台、追思跟帖、会员中心与后台均可触控操作。 */
@media (max-width: 760px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
  }

  button,
  .primary,
  .auth-links a,
  .admin-jumps a,
  input,
  select,
  textarea {
    min-height: 44px;
  }

  input,
  select,
  textarea {
    max-width: 100%;
    font-size: 16px;
  }

  button,
  a,
  select,
  input[type="checkbox"],
  input[type="file"] {
    touch-action: manipulation;
  }

  .site-header,
  .home-page .site-header {
    height: auto;
    min-height: 70px;
    padding: 10px 14px 0;
    flex-wrap: wrap;
    gap: 8px 12px;
  }

  .site-brand {
    min-width: 0;
  }

  .site-brand i {
    width: 34px;
    height: 34px;
  }

  .site-brand b {
    max-width: 42vw;
    overflow: hidden;
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .site-brand small,
  .auth-links > span {
    display: none;
  }

  .auth-links {
    margin-left: auto;
    gap: 6px;
  }

  .auth-links a,
  .auth-links button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 11px;
  }

  .site-header nav {
    order: 3;
    display: flex;
    width: calc(100% + 28px);
    margin: 0 -14px;
    padding: 8px 14px 10px;
    gap: 8px;
    overflow-x: auto;
    border-top: 1px solid rgba(255, 255, 255, .12);
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .site-header nav::-webkit-scrollbar {
    display: none;
  }

  .site-header nav a {
    flex: 0 0 auto;
    display: inline-flex;
    min-height: 36px;
    align-items: center;
    padding: 6px 10px;
    border: 1px solid rgba(255, 255, 255, .14);
  }

  .home-page,
  .memorial-home-php {
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  .family-gallery {
    height: auto;
    min-height: 540px;
    overflow: hidden;
    background-size: 100% 100%, 350px 263px;
  }

  .family-generations {
    width: 100%;
    height: 540px;
    grid-template-rows: 130px 130px 265px;
    gap: 5px;
    padding: 7px 8px 8px;
    overflow: hidden;
    border: 0;
  }

  .family-generation {
    width: 100%;
    min-height: 0;
    overflow: hidden;
  }

  .family-photo-row {
    width: 100%;
    height: 100%;
    justify-content: flex-start;
    gap: 10px;
    padding: 8px 9px 12px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }

  .family-photo-row::before,
  .family-photo-row::after {
    content: "";
    flex: 1 0 0;
    min-width: 0;
  }

  .ancestor-photo,
  .family-generation:first-child .ancestor-photo,
  .family-generation:nth-child(2) .ancestor-photo {
    flex: 0 0 76px;
    width: 76px;
    height: 95px;
    scroll-snap-align: start;
  }

  .family-generation:first-child .ancestor-photo {
    flex-basis: 82px;
    width: 82px;
    height: 103px;
  }

  .incense-offering {
    width: 100%;
    min-height: 0;
  }

  .incense-offering img {
    width: 92%;
    max-width: 460px;
    max-height: 255px;
  }

  .flower-thread {
    --mobile-thread-height: clamp(312px, 55vh, 520px);
    display: grid;
    height: auto;
    min-height: 0;
    grid-template-columns: 1fr;
    grid-template-rows: auto calc(44px + var(--mobile-thread-height));
  }

  .present-box {
    min-height: 136px;
    grid-template-columns: 50px minmax(0, 1fr);
    gap: 8px 12px;
    padding: 12px 14px;
    border-right: 0;
    border-bottom: 1px solid #d6cfbf;
  }

  .chrysanthemum-mark {
    width: 50px;
    height: 50px;
  }

  .present-actions,
  .present-box > a.primary {
    grid-column: 1 / -1;
    width: 100%;
  }

  .present-actions .primary,
  .present-actions form,
  .present-actions form .primary,
  .present-box > a.primary {
    flex: 1 1 0;
    width: 100%;
    min-height: 44px;
    text-align: center;
  }

  .forum-thread {
    min-width: 0;
    grid-template-rows: 44px var(--mobile-thread-height);
  }

  .forum-toolbar {
    min-width: 0;
    gap: 8px;
    padding: 0 10px;
  }

  .forum-toolbar > div {
    min-width: 0;
    gap: 6px;
  }

  .forum-toolbar b {
    white-space: nowrap;
  }

  .forum-toolbar form,
  .forum-toolbar label {
    min-width: 0;
  }

  .forum-toolbar select {
    min-height: 34px;
    max-width: 105px;
    margin-left: 3px;
    padding: 4px 18px 4px 6px;
    font-size: 13px;
  }

  .forum-scroll {
    height: var(--mobile-thread-height);
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
  }

  .forum-reply {
    height: 104px;
    min-height: 104px;
    grid-template-columns: 34px 118px minmax(0, 1fr);
    grid-template-rows: 42px 62px;
  }

  .member-cell {
    grid-column: 2 / -1;
    min-width: 0;
  }

  .flower-cell {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: flex-start;
    overflow-x: auto;
    padding: 2px 8px;
    -webkit-overflow-scrolling: touch;
  }

  .flower-cell img {
    flex: 0 0 39px;
    width: 39px;
    height: 39px;
  }

  .text-reply .tribute-text {
    grid-column: 1 / -1;
    grid-row: 2;
    max-height: 62px;
    padding: 6px 10px;
  }

  .auth-shell {
    min-height: calc(100vh - 110px);
    padding: 24px 12px;
  }

  .auth-card,
  .auth-card.compact {
    width: 100%;
    max-width: 100%;
    padding: 26px 18px;
  }

  .auth-card h1 {
    font-size: 26px;
  }

  .two-fields {
    grid-template-columns: 1fr;
  }

  .container {
    width: 100%;
    padding: 28px 12px 56px;
  }

  .page-title {
    margin-bottom: 20px;
  }

  .page-title h1 {
    font-size: 26px;
    letter-spacing: .05em;
  }

  .admin-jumps {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 5px;
    -webkit-overflow-scrolling: touch;
  }

  .admin-jumps a {
    flex: 0 0 auto;
  }

  .stat-grid,
  .stat-grid.four {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  .stat-grid article {
    min-width: 0;
    padding: 15px 12px;
  }

  .stat-grid strong,
  .stat-grid .small-number {
    font-size: 23px;
  }

  .panel {
    margin: 16px 0;
    padding: 16px 12px;
  }

  .panel-title {
    display: block;
    margin-bottom: 15px;
  }

  .table-wrap {
    width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }

  .table-wrap table {
    min-width: 680px;
  }

  th,
  td {
    padding: 10px 8px;
  }

  .inline-create,
  .designated-upload,
  .member-create-form,
  .setting-switch-form {
    display: grid;
    width: 100%;
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .inline-create label,
  .inline-create input,
  .inline-create select,
  .designated-upload input,
  .designated-upload select,
  .member-create-form input {
    width: 100%;
    min-width: 0;
  }

  .inline-create button,
  .designated-upload button,
  .member-create-form button {
    width: 100%;
    grid-column: auto;
  }

  .admin-edit-form,
  .member-message-edit {
    grid-template-columns: 1fr;
    min-width: 250px;
  }

  .admin-edit-form button,
  .member-message-edit button,
  .tribute-delete-form button,
  .user-delete-form button {
    width: 100%;
  }

  .setting-switch {
    align-items: flex-start;
  }

  .setting-switch input {
    flex: 0 0 24px;
    min-height: 24px;
  }

  .photo-admin-grid {
    grid-template-columns: 1fr;
  }

  .photo-admin-grid .photo-edit-form {
    grid-template-columns: 1fr 1fr;
  }

  input[type="file"] {
    width: 100%;
    font-size: 14px;
  }

  .site-footer {
    display: block;
    padding: 22px 16px;
    line-height: 1.8;
  }
}

@media (max-width: 420px) {
  .site-brand b {
    max-width: 35vw;
    font-size: 13px;
  }

  .auth-links a,
  .auth-links button {
    padding: 7px 9px;
    font-size: 11px;
  }

  .family-gallery,
  .family-generations {
    min-height: 520px;
    height: 520px;
  }

  .family-generations {
    grid-template-rows: 120px 120px 250px;
  }

  .ancestor-photo,
  .family-generation:first-child .ancestor-photo,
  .family-generation:nth-child(2) .ancestor-photo {
    flex-basis: 70px;
    width: 70px;
    height: 88px;
  }

  .family-generation:first-child .ancestor-photo {
    flex-basis: 76px;
    width: 76px;
    height: 95px;
  }

  .present-box {
    grid-template-columns: 44px minmax(0, 1fr);
    padding: 11px 10px;
  }

  .chrysanthemum-mark {
    width: 44px;
    height: 44px;
  }

  .forum-toolbar span {
    display: none;
  }

  .stat-grid,
  .stat-grid.four {
    grid-template-columns: 1fr 1fr;
  }

  .panel {
    padding: 14px 10px;
  }

  .table-wrap table {
    min-width: 620px;
  }
}
