:root {
  --ink: #171513;
  --muted: #7a756e;
  --line: #e5e2db;
  --bg: #f7f6f3;
  --surface: #efeee9;
  --accent: #1f5c4a;
  --accent-deep: #143d33;
  --grad: linear-gradient(135deg, #1f5c4a 0%, #2a6f5a 55%, #143d33 100%);
  --danger: #b42318;
  --radius: 14px;
  --phone-max: 430px;
  --tabbar-h: 64px;
  --font: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --display: "ZCOOL XiaoWei", "Noto Serif SC", "Songti SC", serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { min-height: 100%; }

body {
  font-family: var(--font);
  color: var(--ink);
  background: #e8e6e1;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.phone {
  width: min(100%, var(--phone-max));
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 0 0 1px rgba(23, 21, 19, 0.04);
}

.pages {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.page {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding:
    max(12px, env(safe-area-inset-top))
    18px
    calc(var(--tabbar-h) + 22px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.page[hidden] { display: none !important; }

.page-top { padding-top: 4px; }

.page-title {
  font-size: 1.35rem;
  font-weight: 700;
}

/* —— 制作台（工坊感，避开通用 AI 紫） —— */
.page-studio {
  position: relative;
  gap: 18px;
  overflow: hidden;
}

.studio-atmosphere {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(120% 70% at 10% -10%, rgba(31, 92, 74, 0.14), transparent 55%),
    radial-gradient(90% 50% at 100% 20%, rgba(23, 21, 19, 0.06), transparent 50%),
    linear-gradient(180deg, #f3f1eb 0%, #f7f6f3 42%, #f7f6f3 100%);
}

.studio-atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}

.page-studio > *:not(.studio-atmosphere) {
  position: relative;
  z-index: 1;
}

.studio-brand {
  padding-top: 8px;
  animation: studioIn 0.55s ease both;
}

.studio-brand-mark {
  font-family: var(--display);
  font-size: 2rem;
  line-height: 1.15;
  letter-spacing: 0.08em;
  color: var(--ink);
  animation: brandSettle 0.7s ease both;
}

.studio-headline {
  margin-top: 14px;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.studio-sub {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.86rem;
  max-width: 18em;
}

.studio-home,
.studio-panel {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 18px;
  flex: 1;
  min-height: 0;
}

.studio-home[hidden],
.studio-panel[hidden] {
  display: none !important;
}

.feature-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 10px;
  border: 1px solid rgba(23, 21, 19, 0.12);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.2)),
    var(--surface);
  animation: studioIn 0.65s ease 0.06s both;
}

.feature-btn {
  appearance: none;
  min-height: 148px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-start;
  padding: 14px 12px;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  border: 1px solid rgba(23, 21, 19, 0.16);
  background: rgba(255, 255, 255, 0.78);
  transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.feature-btn:active {
  transform: scale(0.985);
}

.ref-label {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.ref-hint {
  margin: 10px 0 auto;
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0.02em;
  line-height: 1.4;
}

.ref-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #fff;
  background: var(--accent);
}

.panel-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 4px;
  animation: studioIn 0.4s ease both;
}

.panel-back {
  appearance: none;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(23, 21, 19, 0.14);
  background: #fff;
  color: var(--ink);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
}

.panel-titles h2 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.panel-titles p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.8rem;
}

.panel-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 9 / 14;
  max-height: 48vh;
  border: 1px solid rgba(23, 21, 19, 0.14);
  background: #fff;
  overflow: hidden;
  display: grid;
  place-items: center;
  animation: studioIn 0.5s ease 0.05s both;
}

.panel-media {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #111;
}

.panel-empty {
  color: var(--muted);
  font-size: 0.86rem;
  letter-spacing: 0.06em;
}

.panel-ref,
.panel-multi {
  display: none;
}

.panel-ref.is-show,
.panel-multi.is-show {
  display: block;
  animation: studioIn 0.55s ease 0.08s both;
}

.panel-multi.is-show {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.panel-soon[hidden],
.prompt-dock[hidden] {
  display: none !important;
}

.panel-ref-btn {
  appearance: none;
  width: 100%;
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px dashed rgba(23, 21, 19, 0.25);
  background: rgba(255, 255, 255, 0.7);
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.panel-ref-btn span {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.panel-ref-btn strong {
  font-size: 0.82rem;
  font-weight: 700;
}

.panel-ref-btn small {
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.3;
}

.panel-ref-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  flex: 0 0 auto;
  background: #ddd;
}

.panel-soon {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.5;
  padding: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.65);
}

/* 操作对话（底部面板） */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet[hidden] {
  display: none !important;
}

.sheet-mask {
  position: absolute;
  inset: 0;
  border: none;
  background: rgba(23, 21, 19, 0.42);
  cursor: pointer;
  animation: sheetFade 0.2s ease both;
}

.sheet-panel {
  position: relative;
  width: min(100%, var(--phone-max));
  padding: 10px 18px calc(18px + env(safe-area-inset-bottom));
  background: #f7f6f3;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -12px 40px rgba(23, 21, 19, 0.16);
  animation: sheetUp 0.28s ease both;
}

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: #d5d1c8;
  margin: 0 auto 14px;
}

.sheet-panel h3 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.sheet-desc {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.86rem;
}

.sheet-actions {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sheet-btn {
  appearance: none;
  width: 100%;
  border: 1px solid rgba(23, 21, 19, 0.14);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 14px 16px;
  cursor: pointer;
  text-align: center;
}

.sheet-btn.primary {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
}

.sheet-btn:active {
  transform: translateY(1px);
}

.sheet-cancel {
  appearance: none;
  width: 100%;
  margin-top: 12px;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  padding: 10px;
  cursor: pointer;
}

@keyframes sheetFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes sheetUp {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

.prompt-dock {
  display: flex;
  align-items: stretch;
  gap: 0;
  border: 1px solid rgba(23, 21, 19, 0.16);
  background: #fff;
  animation: studioIn 0.7s ease 0.12s both;
}

.prompt-dock input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 0.92rem;
  color: var(--ink);
  padding: 14px 14px;
}

.prompt-dock input::placeholder {
  color: #a39e96;
}

.btn-gen {
  flex: 0 0 auto;
  border: none;
  border-left: 1px solid rgba(23, 21, 19, 0.12);
  padding: 0 20px;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease;
}

.btn-gen:hover {
  background: var(--accent-deep);
}

.btn-gen:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-gen:active:not(:disabled) {
  transform: translateY(1px);
}

.status {
  min-height: 1.1em;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: -8px;
}

.status.error { color: var(--danger); }
.status.ok { color: var(--accent-deep); }

.tool-rail {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  border-top: 1px solid rgba(23, 21, 19, 0.12);
  animation: studioIn 0.75s ease 0.18s both;
}

.tool-item {
  appearance: none;
  border: none;
  border-right: 1px solid rgba(23, 21, 19, 0.1);
  background: transparent;
  padding: 14px 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s ease, background 0.2s ease;
}

.tool-item:last-child {
  border-right: none;
}

.tool-item:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.tool-item.is-active {
  color: var(--accent-deep);
  background: rgba(31, 92, 74, 0.08);
  box-shadow: inset 0 -2px 0 var(--accent);
}

@keyframes studioIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes brandSettle {
  from { opacity: 0; letter-spacing: 0.22em; }
  to { opacity: 1; letter-spacing: 0.08em; }
}

.frame {
  width: 100%;
  aspect-ratio: 9 / 16;
  max-height: 420px;
  border-radius: 20px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  position: relative;
}

.frame[hidden] {
  display: none !important;
}

.frame.loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(255,255,255,.6) 50%, transparent 70%);
  background-size: 200% 100%;
  animation: sheen 1.2s linear infinite;
}

@keyframes sheen {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}

.frame img,
.frame video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.placeholder {
  color: var(--muted);
  font-size: 0.85rem;
}

.history-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.history-title-gap { margin-top: 10px; }

.history-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scroll-snap-type: x mandatory;
}

.history-list:empty::after {
  content: "生成后会出现在这里";
  color: var(--muted);
  font-size: 0.8rem;
}

.thumb {
  flex: 0 0 auto;
  width: 64px;
  aspect-ratio: 9 / 16;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  scroll-snap-align: start;
  cursor: pointer;
  padding: 0;
  background: transparent;
}

.thumb.active {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb-video {
  display: grid;
  place-items: center;
  background: var(--surface);
}

.thumb-label { color: var(--accent); }

/* Feed */
.feed-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.feed-item {
  position: relative;
  aspect-ratio: 9 / 16;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.feed-item img,
.feed-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.feed-caption {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 14px 8px 8px;
  background: linear-gradient(transparent, rgba(0,0,0,.5));
  color: #fff;
  font-size: 0.68rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-hint {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 16px 2px;
}

.empty-hint[hidden] { display: none; }

/* Messages / Me */
.msg-list { list-style: none; }
.msg-item {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.msg-item.muted { opacity: 0.7; }
.msg-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 0.9rem;
}
.msg-meta span { color: var(--muted); font-size: 0.78rem; }
.msg-item p { color: var(--muted); font-size: 0.88rem; }

.me-card {
  border-radius: 16px;
  background: linear-gradient(145deg, #f1f4f2 0%, #f7f6f3 55%, #ffffff 100%);
  border: 1px solid var(--line);
  padding: 16px;
  box-shadow: 0 8px 24px rgba(23, 21, 19, 0.05);
}

.me-card-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.2rem;
  color: #fff;
  background: var(--grad);
  flex: 0 0 auto;
  box-shadow: 0 6px 14px rgba(110, 100, 220, 0.28);
}

.me-card-info {
  flex: 1;
  min-width: 0;
}

.me-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.me-name {
  font-size: 1.1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.vip-tag {
  flex: 0 0 auto;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--accent-deep);
  background: rgba(31, 92, 74, 0.1);
  border: 1px solid rgba(31, 92, 74, 0.22);
  border-radius: 999px;
  padding: 2px 8px;
}

.me-id {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
}

.me-recharge {
  flex: 0 0 auto;
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(20, 61, 51, 0.22);
}

.me-vip-bar {
  margin-top: 14px;
  padding: 12px 12px;
  border-radius: 14px;
  background: linear-gradient(90deg, #1a2421 0%, #243832 100%);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
}

.me-vip-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.me-vip-text strong {
  font-size: 0.9rem;
}

.me-vip-text span {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.65);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.me-vip-btn {
  flex: 0 0 auto;
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 7px 12px;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  color: #143d33;
  background: #d8e8e2;
  cursor: pointer;
}

.me-stats {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.me-stats li {
  padding: 14px 8px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.me-stats strong {
  font-size: 1.2rem;
  font-weight: 700;
}

.me-stats span {
  color: var(--muted);
  font-size: 0.75rem;
}

.me-history {
  margin-top: 4px;
}

.me-history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 0 2px;
}

.me-history-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
}

.me-history-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.me-history-count {
  font-size: 0.78rem;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
}

.me-history-clear {
  appearance: none;
  border: 1px solid #e2b4b4;
  background: #fff5f5;
  color: #b42318;
  font: inherit;
  font-size: 0.78rem;
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
}

.me-history-clear:active {
  background: #fde8e8;
}

.history-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.history-item {
  position: relative;
  aspect-ratio: 9 / 16;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface);
}

.history-open {
  position: absolute;
  inset: 0;
  border: none;
  padding: 0;
  margin: 0;
  background: transparent;
  cursor: pointer;
  appearance: none;
  font: inherit;
  color: inherit;
}

.history-del {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 999px;
  background: rgba(20, 20, 20, 0.55);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}

.history-del:active {
  background: rgba(180, 35, 24, 0.85);
}

.history-open img,
.history-open video,
.history-item img,
.history-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.history-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 8px 8px 6px;
  font-size: 0.68rem;
  color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.55));
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.me-history .empty-hint {
  margin-top: 8px;
}

.me-menu {
  list-style: none;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  margin-top: 12px;
}

.me-link {
  width: 100%;
  appearance: none;
  border: none;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  padding: 15px 14px;
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.me-menu li:last-child .me-link {
  border-bottom: none;
}

.me-link i {
  color: #c0c0c8;
  font-style: normal;
  font-size: 1.1rem;
}

/* Tab bar */
.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, var(--phone-max));
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding: 8px 10px env(safe-area-inset-bottom);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(247, 246, 243, 0.94);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  z-index: 20;
}

.tab {
  appearance: none;
  border: none;
  background: transparent;
  color: #a0a0aa;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font: inherit;
  font-size: 0.68rem;
  font-weight: 500;
  cursor: pointer;
}

.tab-ico {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 10px;
}

.tab-ico svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.tab[data-tab="work"] .tab-ico svg {
  fill: none;
}

.tab.is-active {
  color: var(--accent-deep);
}

.tab.is-active .tab-ico {
  background: rgba(31, 92, 74, 0.12);
  color: var(--accent);
}

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