:root,
html[data-theme="light"] {
  --bg: #f2f4fa;
  --bg-elevated: #ffffff;
  --text: #141824;
  --muted: #6b7385;
  --accent: #4f6bff;
  --accent-soft: rgba(79, 107, 255, 0.14);
  --accent-ink: #ffffff;
  --line: rgba(20, 24, 36, 0.08);
  --shadow: 0 10px 30px rgba(24, 32, 64, 0.08);
  --danger: #d64055;
  --warn: #b4233a;
  --app-header: 52px;
  --tabbar: 64px;
  --shell-max: 520px;
  color-scheme: light;
}
html[data-theme="light"] {
  background-color: #f2f4fa;
}
html[data-theme="dark"] {
  --bg: #0e1017;
  --bg-elevated: #171a24;
  --text: #eef1f8;
  --muted: #9aa3b5;
  --accent: #7b93ff;
  --accent-soft: rgba(123, 147, 255, 0.18);
  --accent-ink: #0e1017;
  --line: rgba(255, 255, 255, 0.08);
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  --danger: #ff7b8e;
  --warn: #fecdd3;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body.app-body {
  min-height: 100vh;
  background: radial-gradient(circle at 0% 0%, var(--accent-soft), transparent 42%), var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Segoe UI", sans-serif;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
img, video { max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
.skip { position: absolute; left: -999px; top: 8px; }
.skip:focus { left: 8px; background: var(--bg-elevated); padding: 8px 12px; z-index: 100; }

.app-frame {
  width: 100%;
  max-width: var(--shell-max);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--bg);
  box-shadow: 0 0 0 1px var(--line);
  position: relative;
}
@media (min-width: 560px) {
  .app-frame { box-shadow: var(--shadow), 0 0 0 1px var(--line); }
}

.app-header {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--shell-max);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--app-header);
  padding: 8px 14px calc(8px + env(safe-area-inset-top, 0px));
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  backdrop-filter: blur(16px) saturate(1.2);
  border-bottom: 1px solid var(--line);
}
.app-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
  flex: 1;
  min-width: 0;
}
.app-title.truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-back {
  flex-shrink: 0;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

.app-main {
  padding: calc(var(--app-header) + 10px) 12px calc(var(--tabbar) + 16px + env(safe-area-inset-bottom, 0px));
  min-height: 100vh;
}
.app-main:has(+ .tabbar) { padding-bottom: calc(var(--tabbar) + 20px + env(safe-area-inset-bottom, 0px)); }

.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: var(--shell-max);
  z-index: 45;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 6px 10px calc(6px + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  backdrop-filter: blur(18px) saturate(1.25);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px;
  border-radius: 14px;
  color: var(--muted);
  font-size: 11px;
  -webkit-tap-highlight-color: transparent;
}
.tab.on {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}
.tab-ico {
  font-size: 18px;
  line-height: 1;
}

.home-search { margin: 0 0 10px; }
.home-search input,
.panel input,
.panel textarea,
.panel select,
.people input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg-elevated);
  border-radius: 14px;
  padding: 12px 14px;
}
.home-search input { box-shadow: var(--shadow); }

.filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 0 10px;
  scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }
.filters.tight { padding: 0; }
.chip {
  flex-shrink: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  color: var(--muted);
  background: var(--bg-elevated);
  font-size: 13px;
}
.chip.on {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

.masonry {
  display: block;
  columns: 3;
  column-gap: 8px;
}

.card {
  break-inside: avoid;
  display: block;
  margin: 0 0 8px;
  background: var(--bg-elevated);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.cover-open {
  display: block;
  width: 100%;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  text-align: left;
  color: inherit;
  background: transparent;
}
.cover { position: relative; background: #1a1d28; }
.cover img { display: block; width: 100%; height: auto; }
.cover.placeholder {
  min-height: 140px;
  display: grid;
  align-items: end;
  padding: 12px;
  background: linear-gradient(145deg, var(--accent-soft), transparent 55%), var(--bg-elevated);
}
.badge {
  position: absolute;
  left: 8px;
  bottom: 8px;
  background: rgba(10, 12, 18, 0.72);
  color: #fff;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 10px;
}
.badge.warn { left: auto; right: 8px; background: rgba(180, 35, 58, 0.9); }
.card-body { padding: 6px 8px 8px; }
.card-body h2 {
  font-size: 12px;
  font-weight: 600;
  margin: 0 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 2px;
  font-size: 11px;
}
.card-actions .text { font-size: 11px; }
.card-actions a.text { text-decoration: underline; color: var(--accent); }
.card-body p { display: none; }
.meta { display: flex; gap: 8px; flex-wrap: wrap; font-size: 11px; color: var(--muted); }

.btn, button.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 14px;
  padding: 10px 16px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 70%, #9b7bff));
  color: var(--accent-ink);
  font-weight: 600;
  cursor: pointer;
}
.btn.block { width: 100%; }
.icon, button.text {
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--text);
}
button.text { padding: 0; text-decoration: underline; color: var(--accent); }

.pager { display: flex; gap: 16px; padding: 8px 0 4px; }
.empty, .panel {
  margin: 8px 0;
  padding: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.panel h1, .panel h2, .info h1, .empty h1 {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 700;
}
.lead, .about { color: var(--muted); font-size: 14px; }
.compose { display: grid; gap: 12px; }
@media (min-width: 980px) {
  .compose { grid-template-columns: 1fr 1fr; }
}
label { display: grid; gap: 6px; margin: 10px 0; font-size: 14px; }
.hint { color: var(--muted); }
.preview { width: 100%; border-radius: 14px; margin: 8px 0; }

.profile-hero {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 18px 16px;
  margin-bottom: 12px;
  border-radius: 18px;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.profile-hero h2 { margin: 0 0 4px; font-size: 20px; }
.avatar {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: 700;
  color: var(--accent-ink);
  background: linear-gradient(135deg, var(--accent), #9b7bff);
}
.menu {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.menu li { border-bottom: 1px solid var(--line); }
.menu li:last-child { border-bottom: 0; }
.menu a, .menu-btn, .menu form button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}
.menu a { text-decoration: none; }
.menu-btn.danger, .menu form button.danger { color: var(--danger); }

.viewer { display: grid; gap: 16px; }
.stage { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.frame {
  overflow: hidden;
  width: fit-content;
  max-width: 100%;
  border-radius: 16px;
  background: #000;
}
@media (min-width: 980px) {
  .viewer { grid-template-columns: minmax(0, max-content) minmax(0, 1fr); align-items: start; }
}
.stage video, #gallery-main {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(58vh, 520px);
  object-fit: contain;
  background: #000;
  border-radius: 16px;
}
.thumbs { display: flex; gap: 8px; overflow-x: auto; padding-top: 8px; }
.thumbs button { border: 0; padding: 0; background: transparent; cursor: pointer; }
.thumbs img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; }
.prompt-box { margin: 8px 0 12px; }
.prompt {
  white-space: pre-wrap;
  font-size: 15px;
  margin: 0;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}
.prompt.is-open {
  display: block;
  -webkit-line-clamp: unset;
  overflow: visible;
}
.prompt-actions { display: flex; gap: 14px; margin-top: 6px; }
.edit { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }

.flash {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 14px;
}
.flash.ok { background: rgba(34, 160, 107, 0.14); color: #16704a; }
.flash.err { background: rgba(214, 64, 85, 0.12); color: var(--warn); }
html[data-theme="dark"] .flash.ok { color: #8ce4b8; }
.people { list-style: none; padding: 0; display: grid; gap: 12px; }
.people li { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.people form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.people input { width: auto; min-width: 120px; }

.viewer-layer {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: calc(var(--app-header) + 12px) 12px calc(var(--tabbar) + 12px);
  background: rgba(8, 10, 16, 0.92);
}
.viewer-layer[hidden] { display: none !important; }
.viewer-close {
  position: fixed;
  top: calc(var(--app-header) + 6px);
  right: max(12px, calc(50% - 250px));
  z-index: 81;
  border: 0;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 26px;
  cursor: pointer;
}
.viewer-shell { width: min(100%, 420px); }
.viewer-shell video,
.viewer-shell img {
  display: block;
  width: 100%;
  max-height: calc(100vh - var(--app-header) - var(--tabbar) - 32px);
  object-fit: contain;
  border-radius: 14px;
  background: #000;
}
.viewer-status { margin: 10px 0 0; text-align: center; color: #eef1f8; font-size: 14px; }

@media (min-width: 900px) {
  :root { --shell-max: 1180px; }
  body.app-body { padding: 16px 0; }
  .app-frame {
    display: grid;
    grid-template-columns: 210px minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "side head"
      "side main";
    min-height: calc(100vh - 32px);
    border-radius: 22px;
    overflow: hidden;
  }
  .app-header {
    position: sticky;
    top: 0;
    left: auto;
    transform: none;
    max-width: none;
    width: auto;
    grid-area: head;
    padding: 14px 24px;
  }
  .app-title { font-size: 22px; }
  .app-main {
    grid-area: main;
    padding: 16px 24px 28px;
    min-height: 0;
  }
  .tabbar {
    position: sticky;
    top: 0;
    left: auto;
    bottom: auto;
    transform: none;
    max-width: none;
    width: auto;
    height: auto;
    min-height: calc(100vh - 32px);
    grid-area: side;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 22px 14px;
    border-top: 0;
    border-right: 1px solid var(--line);
  }
  .tab {
    flex-direction: row;
    justify-content: flex-start;
    gap: 10px;
    padding: 12px 14px;
    font-size: 15px;
  }
  .tab-ico { font-size: 16px; width: 28px; text-align: center; }
  .home-search input { padding: 14px 16px; font-size: 15px; }
  .masonry { columns: 5; column-gap: 14px; }
  .card { margin-bottom: 14px; border-radius: 16px; }
  .card-body h2 { font-size: 14px; }
  .card-actions, .card-actions .text { font-size: 12px; }
  .meta { font-size: 12px; }
  .viewer-shell { width: min(100%, 760px); }
  .viewer-shell video,
  .viewer-shell img {
    max-height: calc(100vh - var(--app-header) - 48px);
  }
  .viewer-layer {
    padding: calc(var(--app-header) + 16px) 24px 24px;
  }
  .viewer-close {
    right: max(24px, calc(50% - var(--shell-max) / 2 + 24px));
  }
  .compose { grid-template-columns: 1fr 1fr; gap: 20px; }
  .profile-hero { padding: 22px 20px; }
}
