:root {
  color-scheme: light;
  --paper: #f7f6f0;
  --panel: #fffefa;
  --ink: #27241f;
  --muted: #777168;
  --line: #e5e0d7;
  --soft: #f0ede6;
  --violet: #6251c9;
  --violet-weak: #ede9ff;
  --green: #27785f;
  --peach: #f4b49d;
  --shadow: 0 24px 80px rgba(66, 55, 36, .12);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; overflow-x: hidden; }
body {
  margin: 0;
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    linear-gradient(90deg, rgba(39,36,31,.035) 1px, transparent 1px),
    linear-gradient(rgba(39,36,31,.035) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
}

.desktop-canvas {
  min-height: 100vh;
  display: grid;
  place-items: stretch center;
  padding: 18px;
}

.app-window {
  width: min(1120px, 100%);
  height: calc(100vh - 36px);
  min-height: 620px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
}
.brand {
  color: #1f2340;
  font-weight: 900;
  text-decoration: none;
}
.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.login-btn, .quota-pill {
  height: 32px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
  white-space: nowrap;
}
.quota-pill {
  color: var(--muted);
  font-size: 13px;
}
.login-btn { font-weight: 700; }
.login-btn.secondary {
  background: #f8f6ef;
  color: var(--muted);
}

.login-panel {
  position: relative;
  z-index: 9;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto 130px auto;
  gap: 8px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: #fbfaf6;
}
.login-panel[hidden] { display: none; }

.my-pages-panel {
  position: relative;
  z-index: 9;
  width: 100%;
  max-height: 280px;
  overflow: auto;
  padding: 14px 24px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfaf6;
}
.my-pages-panel[hidden] { display: none; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.panel-head strong {
  font-size: 15px;
}
.panel-head button {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}
.my-pages-list {
  display: grid;
  gap: 8px;
}
.my-page-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.my-page-main {
  min-width: 0;
  display: grid;
  gap: 3px;
}
.my-page-title {
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.my-page-meta {
  color: var(--muted);
  font-size: 12px;
}
.my-page-badge {
  display: inline-grid;
  place-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #111;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}
.my-page-item a,
.my-page-item button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
  text-decoration: none;
  font-size: 13px;
}

.chat-canvas {
  flex: 1 1 auto;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
  padding: 26px 18px 16px;
  background:
    radial-gradient(circle at 50% 0, rgba(98,81,201,.05), transparent 380px),
    #fbfaf6;
}
.messages {
  width: min(760px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 15px;
  overflow: auto;
  padding: 0 0 18px;
}
.msg {
  width: fit-content;
  max-width: min(620px, 88%);
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  line-height: 1.62;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 6px 18px rgba(60, 48, 30, .04);
}
.msg.assistant {
  position: relative;
  margin-left: 42px;
}
.msg.assistant::before {
  content: "✣";
  position: absolute;
  left: -34px;
  top: 10px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--violet-weak);
  color: var(--violet);
  font-size: 13px;
}
.msg.user {
  align-self: flex-end;
  background: #eeeaff;
  border-color: #ded7ff;
  color: #302775;
}
.msg.system {
  align-self: center;
  max-width: 90%;
  background: transparent;
  border: 0;
  box-shadow: none;
  color: var(--muted);
  font-size: 13px;
}

.action-card {
  align-self: flex-start;
  width: min(580px, calc(100% - 42px));
  margin-left: 42px;
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.84);
  box-shadow: 0 10px 28px rgba(60,48,30,.06);
}
.action-card[data-disabled="1"] {
  opacity: .58;
}
.action-title {
  font-weight: 900;
  color: #24203f;
}
.action-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}
.preset-row {
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 10px;
}
.preset-row button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: #302b24;
  font-weight: 700;
}
.preset-row button:hover {
  border-color: var(--violet);
  color: var(--violet);
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.publish-btn {
  min-width: 138px;
  min-height: 42px;
  border: 0;
  border-radius: 999px;
  background: var(--violet);
  color: #fff;
  font-weight: 900;
  box-shadow: 0 10px 24px rgba(98,81,201,.24);
}
.generate-card .publish-btn {
  animation: pulse 1.4s ease-in-out infinite;
}
.ghost-btn {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 0 16px;
  font-weight: 800;
}
@keyframes pulse {
  50% { transform: translateY(-1px); box-shadow: 0 14px 30px rgba(98,81,201,.32); }
}

.adult-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}
.adult-toggle input { width: auto; }
.turnstile-box {
  min-height: 65px;
}
.live-preview-card {
  width: min(700px, calc(100% - 42px));
  padding: 0;
  overflow: hidden;
  border-color: rgba(98,81,201,.35);
  background: #111218;
  box-shadow: 0 18px 50px rgba(27,22,60,.18);
}
.live-preview-head {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  border-bottom: 1px solid rgba(255,255,255,.12);
  color: #ecfdf8;
  font-size: 12px;
}
.live-preview-head > div {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #39ffb6;
  box-shadow: 0 0 18px rgba(57,255,182,.9);
  animation: liveBlink 1s steps(2, start) infinite;
}
.live-preview-status {
  color: rgba(236,253,248,.7);
  white-space: nowrap;
}
.live-preview-frame {
  display: block;
  width: 100%;
  height: 360px;
  border: 0;
  background:
    linear-gradient(rgba(57,255,182,.08) 1px, transparent 1px),
    #0b0c10;
  background-size: 100% 12px;
}
.live-preview-note {
  padding: 10px 14px 12px;
  border-top: 1px solid rgba(255,255,255,.1);
  color: rgba(236,253,248,.66);
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.live-preview-card.is-stopped .live-dot {
  animation: none;
  background: #a9a9b6;
  box-shadow: none;
}
@keyframes liveBlink {
  50% { opacity: .25; }
}
.delivery-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(60,48,30,.07);
}
.url-box {
  padding: 12px;
  border-radius: 12px;
  background: var(--soft);
  color: var(--green);
  font-weight: 800;
  overflow-wrap: anywhere;
}
.delivery-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.delivery-actions button, .delivery-actions a, .email-row button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  text-decoration: none;
}
.qr-canvas {
  width: 164px;
  height: 164px;
  border: 1px solid var(--line);
  background: #fff;
  image-rendering: pixelated;
}
.qr-fallback {
  width: 164px;
  min-height: 164px;
  display: grid;
  place-items: center;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: #fbfaf6;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  line-height: 1.5;
}
.email-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.composer {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
  padding: 13px 18px 16px;
  border-top: 1px solid var(--line);
  background: #fff;
}
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  outline: none;
  padding: 10px 12px;
}
textarea {
  resize: none;
  min-height: 42px;
  max-height: 120px;
}
input:focus, textarea:focus { border-color: var(--violet); }
.upload-card {
  align-self: flex-start;
  width: min(520px, calc(100% - 42px));
  margin-left: 42px;
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px dashed #cfc7f7;
  border-radius: 16px;
  background: #faf8ff;
}
.upload-card strong {
  color: #342c7d;
}
.upload-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}
.upload-card-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}
.upload-card label,
.composer button {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--violet);
  font-weight: 900;
}
.upload-card label {
  min-height: 40px;
  padding: 0 12px;
  background: #fff;
  cursor: pointer;
}
.upload-card label input { display: none; }
.composer button {
  background: var(--violet);
  color: #fff;
}

@media (max-width: 760px) {
  .desktop-canvas {
    display: block;
    padding: 0;
    background: var(--panel);
  }
  .app-window {
    width: 100%;
    max-width: 100vw;
    height: 100vh;
    height: 100dvh;
    min-height: 100vh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
  }
  .topbar {
    display: grid;
    grid-template-columns: auto 1fr;
    position: sticky;
    top: 0;
    z-index: 5;
    min-height: 54px;
    width: 100vw;
    max-width: 100vw;
    padding: 0 14px;
    background: rgba(255,254,250,.94);
    backdrop-filter: blur(12px);
  }
  .top-actions { gap: 6px; }
  .brand { flex: 0 0 auto; }
  .top-actions {
    display: flex;
    justify-self: end;
    justify-content: flex-end;
    max-width: calc(100vw - 120px);
  }
  .quota-pill {
    display: none;
  }
  .login-btn {
    height: 30px;
    padding: 0 8px;
    font-size: 13px;
  }
  .login-panel {
    grid-template-columns: 1fr;
    padding: 10px 14px;
  }
  .my-pages-panel {
    max-height: 42vh;
    padding: 10px 14px;
  }
  .my-page-item {
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .my-page-badge { display: none; }
  .my-page-item a { display: none; }
  .chat-canvas {
    min-height: 0;
    padding: 18px 12px 10px;
  }
  .messages { gap: 12px; }
  .msg {
    max-width: calc(100% - 44px);
    font-size: 14px;
  }
  .msg.assistant {
    margin-left: 30px;
    max-width: calc(100% - 38px);
  }
  .msg.assistant::before { left: -30px; }
  .preset-row {
    justify-content: flex-start;
    overflow-x: auto;
    flex-wrap: nowrap;
  }
  .preset-row button {
    flex: 0 0 auto;
  }
  .action-card { width: calc(100% - 30px); margin-left: 30px; }
  .live-preview-card { width: calc(100% - 30px); }
  .live-preview-head {
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    padding: 8px 12px;
  }
  .live-preview-frame { height: 300px; }
  .email-row {
    grid-template-columns: 1fr;
  }
  .composer {
    grid-template-columns: 1fr 44px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  }
  .upload-card { width: calc(100% - 30px); margin-left: 30px; }
  .upload-card-actions { grid-template-columns: 1fr; }
}
