:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --ink: #17201e;
  --muted: #60706c;
  --surface: #ffffff;
  --surface-2: #edf3ef;
  --surface-3: #f9fbf8;
  --line: #d7dfda;
  --teal: #2f6f6d;
  --teal-2: #dcece8;
  --coral: #d85f45;
  --plum: #7b497d;
  --gold: #b88a22;
  --shadow: 0 18px 42px rgba(24, 38, 34, 0.12);
  --radius: 8px;
  --side-width: 236px;
}

body[data-theme="night"] {
  color-scheme: dark;
  --bg: #141816;
  --ink: #f3f5ef;
  --muted: #b9c6bf;
  --surface: #202622;
  --surface-2: #2a342f;
  --surface-3: #171c19;
  --line: #3d4944;
  --teal: #76c8ba;
  --teal-2: #213d39;
  --coral: #ff9a7d;
  --plum: #d7a7da;
  --gold: #e2bc62;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  font-size: 16px;
  letter-spacing: 0;
}

button,
input,
textarea,
select {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

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

.app-frame {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--side-width) minmax(0, 1fr);
}

.side-rail {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  background: #14211f;
  color: #f8fbf7;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-button,
.rail-nav button,
.rail-tool {
  width: 100%;
  border: 0;
  color: inherit;
  background: transparent;
  text-align: left;
}

.brand-button {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 12px;
  align-items: center;
  padding: 6px;
  border-radius: var(--radius);
}

.brand-button:hover,
.brand-button:focus-visible {
  outline: 0;
  background: rgba(255, 255, 255, 0.08);
}

.brand-mark {
  width: 48px;
  aspect-ratio: 1;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: #f8fbf7;
  color: #14211f;
  font-weight: 800;
  font-size: 24px;
}

.brand-button strong {
  display: block;
  font-size: 17px;
  line-height: 1.25;
}

.brand-button small {
  display: block;
  color: rgba(248, 251, 247, 0.72);
  margin-top: 2px;
  font-size: 12px;
}

.rail-nav {
  display: grid;
  gap: 6px;
}

.rail-nav button,
.rail-tool {
  min-height: 44px;
  border-radius: var(--radius);
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 10px;
}

.rail-nav button:hover,
.rail-nav button:focus-visible,
.rail-tool:hover,
.rail-tool:focus-visible {
  outline: 0;
  background: rgba(255, 255, 255, 0.08);
}

.rail-nav button.is-active {
  background: #f8fbf7;
  color: #14211f;
}

.rail-glyph,
.button-icon {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  font-weight: 800;
}

.rail-tool {
  margin-top: auto;
  color: rgba(248, 251, 247, 0.86);
}

.main-panel {
  min-width: 0;
  padding: 24px 28px 48px;
}

.topbar {
  max-width: 1180px;
  margin: 0 auto 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.2;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.sync-badge {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
}

.sync-badge.online {
  background: var(--teal-2);
  color: var(--teal);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 14px;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary-button,
.quiet-button,
.danger-button,
.icon-button {
  min-height: 40px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 13px;
  background: var(--surface);
  color: var(--ink);
}

.primary-button {
  border-color: var(--teal);
  background: var(--teal);
  color: #ffffff;
}

.quiet-button:hover,
.quiet-button:focus-visible,
.icon-button:hover,
.icon-button:focus-visible {
  outline: 0;
  border-color: var(--teal);
}

.primary-button:hover,
.primary-button:focus-visible {
  outline: 0;
  filter: brightness(0.96);
}

.danger-button {
  color: #ffffff;
  border-color: #b83f33;
  background: #b83f33;
}

.danger-button.ghost {
  color: #b83f33;
  background: transparent;
}

.icon-button {
  width: 40px;
  padding: 0;
}

#app {
  max-width: 1180px;
  margin: 0 auto;
}

.view {
  display: grid;
  gap: 22px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 18px;
  align-items: stretch;
}

.family-stage,
.tool-panel,
.list-panel,
.backup-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.family-stage {
  min-height: 318px;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42%;
}

.stage-copy {
  padding: 26px;
  display: grid;
  align-content: center;
  gap: 18px;
}

.stage-copy h2 {
  margin: 0;
  font-size: 34px;
  line-height: 1.18;
}

.stage-copy p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.stage-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.stat {
  min-height: 82px;
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 12px;
  display: grid;
  align-content: center;
  gap: 4px;
}

.stat strong {
  font-size: 24px;
}

.stat span {
  color: var(--muted);
  font-size: 13px;
}

.stage-art {
  position: relative;
  min-height: 260px;
  background: var(--teal-2);
}

.stage-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.stage-art::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(20, 33, 31, 0.08);
}

.tool-panel {
  padding: 20px;
  display: grid;
  gap: 16px;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.panel-heading h2,
.panel-heading h3 {
  margin: 0;
  font-size: 20px;
}

.panel-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label,
.check-field {
  color: var(--muted);
  font-size: 14px;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-3);
  color: var(--ink);
  padding: 10px 11px;
}

.field textarea {
  min-height: 112px;
  resize: vertical;
  line-height: 1.55;
}

.field input[type="color"] {
  padding: 4px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.check-field {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-field input {
  width: 18px;
  height: 18px;
}

.member-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.member-card,
.message-card,
.wish-card,
.event-card,
.photo-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.member-card {
  min-height: 170px;
  padding: 16px;
  display: grid;
  gap: 14px;
}

.member-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.member-identity {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar {
  width: 54px;
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  overflow: hidden;
  flex: 0 0 auto;
  background: var(--member-color, var(--teal));
  color: #ffffff;
  font-weight: 800;
  font-size: 22px;
}

.avatar.small {
  width: 34px;
  font-size: 15px;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.member-name {
  min-width: 0;
}

.member-name strong {
  display: block;
  overflow-wrap: anywhere;
}

.member-name span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 14px;
}

.member-note {
  min-height: 42px;
  color: var(--muted);
  line-height: 1.55;
}

.member-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
}

.pill.hot {
  color: #ffffff;
  background: var(--coral);
}

.pill.gold {
  color: #17201e;
  background: #f0ce75;
}

.list-panel {
  padding: 18px;
}

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

.toolbar h2 {
  margin: 0;
  font-size: 20px;
}

.segment {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: var(--radius);
}

.segment button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  padding: 7px 11px;
  color: var(--muted);
  background: transparent;
}

.segment button.is-active {
  color: #ffffff;
  background: var(--teal);
}

.stack-list {
  display: grid;
  gap: 10px;
}

.message-card,
.wish-card,
.event-card {
  padding: 14px;
  display: grid;
  gap: 10px;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.card-person {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.card-person strong,
.card-title {
  overflow-wrap: anywhere;
}

.card-actions {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}

.message-text,
.wish-title {
  margin: 0;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.message-meta,
.wish-meta,
.event-meta,
.photo-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.wish-card.done {
  background: var(--surface-2);
}

.wish-card.done .wish-title {
  text-decoration: line-through;
  color: var(--muted);
}

.event-card {
  grid-template-columns: 88px minmax(0, 1fr) auto;
  align-items: center;
}

.countdown {
  width: 72px;
  aspect-ratio: 1;
  border-radius: var(--radius);
  background: var(--teal-2);
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--teal);
  font-weight: 800;
}

.countdown span {
  display: block;
  font-size: 12px;
  font-weight: 600;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
}

.photo-card {
  overflow: hidden;
  display: grid;
}

.photo-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--surface-2);
}

.photo-body {
  padding: 12px;
  display: grid;
  gap: 8px;
}

.empty-state {
  min-height: 120px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 22px;
}

.backup-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.backup-panel {
  padding: 18px;
  display: grid;
  gap: 12px;
  align-content: start;
}

.backup-panel h2 {
  margin: 0;
  font-size: 20px;
}

.backup-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.storage-line {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
}

.storage-line span {
  display: block;
  width: var(--storage, 0%);
  height: 100%;
  background: var(--teal);
}

.toast {
  position: fixed;
  z-index: 40;
  right: 24px;
  bottom: 24px;
  max-width: 340px;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--surface);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(17, 25, 23, 0.54);
}

.modal {
  width: min(640px, 100%);
  max-height: min(820px, calc(100vh - 36px));
  overflow: auto;
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}

.modal-header {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
}

.modal-body {
  padding: 16px;
}

.modal-open {
  overflow: hidden;
}

@media (max-width: 980px) {
  .app-frame {
    display: block;
  }

  .side-rail {
    position: sticky;
    z-index: 20;
    height: auto;
    padding: 12px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
  }

  .brand-button {
    grid-template-columns: 42px 1fr;
  }

  .brand-mark {
    width: 42px;
    font-size: 21px;
  }

  .rail-nav {
    grid-column: 1 / -1;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    min-width: 0;
    width: 100%;
  }

  .rail-nav button {
    min-width: 0;
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 4px;
    text-align: center;
  }

  .rail-tool {
    width: auto;
    margin: 0;
    grid-template-columns: 24px;
    padding: 8px 10px;
  }

  .rail-tool span:last-child {
    display: none;
  }

  .main-panel {
    padding: 18px 16px 42px;
  }

  .dashboard-grid,
  .family-stage,
  .backup-grid {
    grid-template-columns: 1fr;
  }

  .stage-art {
    min-height: 210px;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 15px;
  }

  .topbar {
    display: grid;
  }

  .topbar h1 {
    font-size: 25px;
  }

  .topbar-actions {
    justify-content: stretch;
  }

  .topbar-actions button {
    flex: 1 1 140px;
  }

  .stage-copy {
    padding: 20px;
  }

  .stage-copy h2 {
    font-size: 27px;
  }

  .stage-stats,
  .form-row {
    grid-template-columns: 1fr;
  }

  .event-card {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .event-card .card-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }

  .countdown {
    width: 56px;
  }

  .rail-nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
