:root {
  --bg: #f7f1e8;
  --paper: rgba(255, 253, 248, 0.93);
  --paper-strong: #fffdf8;
  --ink: #252525;
  --muted: #756d63;
  --soft: #9a9085;
  --line: rgba(86, 66, 42, 0.1);
  --primary: #b8873d;
  --primary-dark: #805e32;
  --danger: #a95c4c;
  --green: #2f6b4f;
  --shadow: 0 16px 42px rgba(68, 51, 34, 0.08);
  --radius: 16px;
}

/* Refined product surface */
:root {
  --bg: #f3f5f2;
  --paper: rgba(255, 255, 255, 0.96);
  --paper-strong: #ffffff;
  --ink: #202521;
  --muted: #687069;
  --soft: #8c938d;
  --line: rgba(32, 50, 38, 0.11);
  --primary-dark: #6f532c;
  --green: #356c54;
  --shadow: 0 10px 30px rgba(30, 44, 34, 0.07);
  --radius: 8px;
}

body {
  background: #f3f5f2;
}

.side-nav {
  background: rgba(250, 251, 249, 0.94);
}

.card,
.hero-card,
.option-card,
.history-item,
.order-item,
.product-card,
.modal-card,
.user-mini {
  border-radius: 8px;
}

.card,
.hero-card {
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(30, 44, 34, 0.055);
}

.hero-card {
  background: #fff;
}

.primary-btn {
  background: var(--primary);
  box-shadow: 0 8px 18px color-mix(in srgb, var(--primary) 22%, transparent);
}

.secondary-btn,
.ghost-btn {
  border-color: rgba(72, 84, 75, 0.18);
  background: #fff;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  border-radius: 7px;
}

.nav-btn::before {
  width: 18px;
  color: var(--soft);
  font-size: 16px;
  font-weight: 500;
  text-align: center;
}

.nav-btn[data-route="home"]::before { content: "⌂"; }
.nav-btn[data-route="create"]::before { content: "+"; }
.nav-btn[data-route="profile"]::before { content: "档"; font-size: 12px; }
.nav-btn[data-route="story"]::before { content: "阅"; font-size: 12px; }
.nav-btn[data-route="ending"]::before { content: "终"; font-size: 12px; }
.nav-btn[data-route="export"]::before { content: "⇩"; }
.nav-btn[data-route="mine"]::before { content: "人"; font-size: 13px; }
.nav-btn[data-route="orders"]::before { content: "单"; font-size: 12px; }

.brand-logo,
.avatar-image {
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  color: transparent;
}

.avatar-gold { background: #b68b4b; }
.avatar-green { background: #4f8a6f; }
.avatar-red { background: #bb6258; }
.avatar-ink { background: #4c5350; }

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 18px 0;
  padding: 4px;
  border-radius: 8px;
  background: #eef1ed;
}

.auth-tab {
  min-height: 38px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.auth-tab.active {
  color: var(--ink);
  background: #fff;
  box-shadow: 0 3px 10px rgba(30, 44, 34, 0.08);
}

.text-btn {
  width: 100%;
  min-height: 42px;
  margin-top: 10px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
}

.danger-text { color: var(--danger); }

.avatar-options {
  display: flex;
  gap: 12px;
  margin-top: 10px;
}

.avatar-options button,
.profile-avatar {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 2px solid transparent;
  border-radius: 50%;
  color: #fff;
  background: #b68b4b;
  font-weight: 900;
}

.avatar-options button:nth-child(2) { background: #4f8a6f; }
.avatar-options button:nth-child(3) { background: #bb6258; }
.avatar-options button:nth-child(4) { background: #4c5350; }
.avatar-options button.active { border-color: var(--ink); box-shadow: 0 0 0 3px #fff; }

.account-strip {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.invite-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
}

.invite-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  color: #fff;
  background: var(--green);
  font-weight: 900;
}

.invite-copy .section-title,
.invite-copy .section-desc { margin: 0; }
.invite-copy .section-desc { margin-top: 4px; }
.invite-code { margin-top: 8px; color: var(--primary-dark); font-size: 13px; font-weight: 800; }
.compact-btn { width: auto; min-width: 104px; }

@media (max-width: 640px) {
  .invite-card {
    grid-template-columns: auto 1fr;
  }
  .invite-card .compact-btn {
    grid-column: 1 / -1;
    width: 100%;
  }
  .account-strip {
    grid-template-columns: auto 1fr;
  }
  .account-strip .compact-btn {
    grid-column: 1 / -1;
    width: 100%;
  }
  .mobile-nav .nav-btn::before { display: none; }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 16% 0%, rgba(211, 171, 104, 0.15), transparent 30%),
    linear-gradient(180deg, #fbf6ef 0%, #f8f1e7 45%, #fbf7f0 100%);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  transition: transform 0.16s ease, opacity 0.16s ease, box-shadow 0.16s ease;
}

button:active {
  transform: scale(0.985);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

a {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
}

.layout {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 238px minmax(0, 1fr);
}

.side-nav {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 26px 18px;
  border-right: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.62);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px 22px;
}

.brand-mark,
.avatar,
.hot-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  color: #fffaf0;
  background: linear-gradient(135deg, #d7b36f, #a87832);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,0.18), 0 10px 20px rgba(68, 51, 34, 0.14);
  font-weight: 900;
}

.brand-name {
  font-size: 20px;
  font-weight: 900;
}

.brand-sub {
  margin-top: 2px;
  color: var(--soft);
  font-size: 12px;
}

.nav-group {
  display: grid;
  gap: 7px;
}

.nav-btn {
  width: 100%;
  height: 42px;
  padding: 0 13px;
  border-radius: 13px;
  color: var(--muted);
  background: transparent;
  text-align: left;
  font-size: 14px;
  font-weight: 800;
}

.nav-btn.active {
  color: var(--primary-dark);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 8px 20px rgba(68, 51, 34, 0.07);
}

.nav-foot {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 22px;
}

.user-mini {
  appearance: none;
  width: 100%;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: 15px;
  background: rgba(255, 253, 248, 0.8);
}

.user-mini .avatar {
  width: 34px;
  height: 34px;
  font-size: 16px;
}

.user-mini-name {
  font-size: 13px;
  font-weight: 900;
}

.user-mini-action {
  margin-top: 2px;
  color: var(--soft);
  font-size: 12px;
}

.main {
  min-width: 0;
  padding: 28px clamp(18px, 4vw, 44px) 48px;
}

.mobile-top {
  display: none;
}

.mobile-nav {
  display: none;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.kicker {
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 900;
}

.page-title {
  margin: 8px 0 0;
  font-size: clamp(30px, 5vw, 48px);
  line-height: 1.22;
  letter-spacing: 0;
}

.page-desc {
  max-width: 680px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.75;
}

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

.primary-btn,
.secondary-btn,
.ghost-btn,
.danger-btn {
  min-height: 46px;
  padding: 0 20px;
  border-radius: 999px;
  font-weight: 900;
}

.primary-btn {
  color: #fff;
  background: linear-gradient(135deg, #d6b56e 0%, #b8873d 100%);
  box-shadow: 0 14px 28px rgba(165, 116, 49, 0.22);
}

.secondary-btn {
  color: var(--primary-dark);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(121, 96, 66, 0.18);
}

.ghost-btn {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.52);
  border: 1px solid rgba(121, 96, 66, 0.14);
}

.danger-btn {
  color: #fff;
  background: var(--danger);
}

.grid {
  display: grid;
  gap: 18px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

.card,
.hero-card,
.panel {
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.hero-card {
  position: relative;
  min-height: 264px;
  padding: clamp(28px, 5vw, 46px);
  overflow: hidden;
}

.hero-card::after {
  content: "闯";
  position: absolute;
  right: clamp(28px, 7vw, 88px);
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 116px;
  height: 116px;
  border-radius: 50%;
  color: #fff8e9;
  background: linear-gradient(135deg, #d7b36f, #a87832);
  box-shadow: inset 0 0 0 8px rgba(255,255,255,0.16), 0 18px 44px rgba(121, 85, 40, 0.18);
  font-size: 54px;
  font-weight: 900;
  opacity: 0.95;
}

.hero-card .content {
  position: relative;
  z-index: 2;
  max-width: 560px;
}

.quote {
  margin-top: 22px;
  color: var(--ink);
  font-size: clamp(24px, 4vw, 38px);
  font-weight: 900;
  line-height: 1.42;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 30px;
}

.card {
  padding: 24px;
}

.section-title {
  margin: 0 0 14px;
  font-size: 22px;
  font-weight: 900;
}

.section-desc {
  margin: -6px 0 18px;
  color: var(--soft);
  font-size: 14px;
  line-height: 1.7;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

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

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 14px;
  outline: none;
  color: var(--ink);
  background: rgba(247, 241, 232, 0.78);
}

.field input,
.field select {
  height: 48px;
  padding: 0 14px;
}

.field textarea {
  min-height: 132px;
  padding: 14px;
  line-height: 1.7;
  resize: vertical;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: rgba(184, 135, 61, 0.38);
  background: rgba(255, 253, 248, 0.92);
}

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

.option-card {
  appearance: none;
  width: 100%;
  min-height: 116px;
  padding: 16px;
  border: 1px solid var(--line);
  color: inherit;
  font: inherit;
  text-align: left;
  border-radius: 15px;
  background: rgba(255, 253, 248, 0.74);
  cursor: pointer;
}

.option-card.active {
  border-color: rgba(184, 135, 61, 0.5);
  box-shadow: 0 12px 28px rgba(68, 51, 34, 0.07);
}

.option-title {
  font-weight: 900;
}

.option-desc {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.pill-row,
.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill,
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 11px;
  border-radius: 999px;
  background: rgba(232, 217, 194, 0.72);
  color: #8d6b3f;
  font-size: 12px;
  font-weight: 800;
}

.stat-list {
  display: grid;
  gap: 12px;
}

.stat {
  display: grid;
  grid-template-columns: 56px 1fr 42px;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(0,0,0,0.06);
}

.fill {
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
}

.story-text,
.result-text,
.doc-text {
  color: #2f2d29;
  font-size: 16px;
  line-height: 1.92;
  white-space: pre-wrap;
}

.chapter-title {
  margin: 0;
  font-size: clamp(26px, 5vw, 40px);
  line-height: 1.32;
}

.choice-list {
  display: grid;
  gap: 14px;
}

.choice {
  appearance: none;
  width: 100%;
  color: inherit;
  font: inherit;
  text-align: left;
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 14px;
  padding: 18px;
  border-radius: 16px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: 0 12px 30px rgba(68, 51, 34, 0.05);
  cursor: pointer;
}

.choice-id {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: #fff;
  background: var(--primary);
  font-weight: 900;
}

.choice-text {
  font-weight: 900;
  line-height: 1.55;
}

.choice-meta {
  margin-top: 6px;
  color: var(--soft);
  font-size: 13px;
}

.history-item,
.order-item,
.product-card {
  display: grid;
  gap: 8px;
  padding: 18px;
  border-radius: 15px;
  background: rgba(247, 241, 232, 0.72);
}

.history-item {
  appearance: none;
  width: 100%;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.history-timeline {
  display: grid;
  gap: 18px;
  margin: 18px 0;
}

.history-choice,
.history-result {
  margin-top: 18px;
  padding: 16px;
  border-left: 3px solid rgba(184, 135, 61, 0.55);
  background: rgba(247, 241, 232, 0.58);
}

.history-choice p,
.history-result p {
  margin-bottom: 0;
}

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

.muted {
  color: var(--soft);
}

.small {
  font-size: 13px;
}

.empty {
  padding: 26px;
  border-radius: 16px;
  color: var(--soft);
  background: rgba(255,255,255,0.5);
  text-align: center;
}

.busy-layer {
  position: fixed;
  inset: 0;
  z-index: 35;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(251, 247, 240, 0.42);
  backdrop-filter: blur(3px);
}

.busy-card {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: min(86vw, 360px);
  padding: 14px 18px;
  border: 1px solid rgba(184, 135, 61, 0.2);
  border-radius: 999px;
  color: var(--primary-dark);
  background: rgba(255, 253, 248, 0.96);
  box-shadow: 0 18px 46px rgba(68, 51, 34, 0.14);
  font-weight: 800;
}

.busy-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
  animation: busyPulse 0.9s ease-in-out infinite alternate;
}

@keyframes busyPulse {
  from {
    transform: scale(0.7);
    opacity: 0.45;
  }
  to {
    transform: scale(1.15);
    opacity: 1;
  }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  z-index: 30;
  transform: translateX(-50%);
  max-width: min(88vw, 420px);
  padding: 12px 16px;
  border-radius: 999px;
  color: #fff;
  background: rgba(37, 37, 37, 0.88);
  font-size: 14px;
  box-shadow: 0 14px 34px rgba(0,0,0,0.18);
}

.modal.hidden,
.hidden {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(31, 27, 23, 0.32);
  backdrop-filter: blur(8px);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(460px, 100%);
  padding: 28px;
  border-radius: 22px;
  background: var(--paper-strong);
  box-shadow: 0 26px 68px rgba(31, 27, 23, 0.24);
}

.modal-card h2 {
  margin: 8px 0 8px;
}

.modal-card p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.7;
}

.modal-kicker {
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 900;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--muted);
  background: rgba(0,0,0,0.04);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 28px;
  color: var(--soft);
  font-size: 13px;
}

.doc-card h2 {
  margin-top: 0;
}

.doc-card h3 {
  margin: 24px 0 8px;
}

.doc-card p,
.doc-card li {
  color: var(--muted);
  line-height: 1.85;
}

.doc-card ul {
  padding-left: 20px;
}

@media (max-width: 900px) {
  .layout {
    display: block;
  }

  .side-nav {
    display: none;
  }

  .mobile-top {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 253, 248, 0.82);
    backdrop-filter: blur(18px);
  }

  .mobile-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 900;
  }

  .mobile-nav {
    display: flex;
    gap: 8px;
    margin: 0 -18px 22px;
    padding: 0 18px 10px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .mobile-nav::-webkit-scrollbar {
    display: none;
  }

  .mobile-nav .nav-btn {
    flex: 0 0 auto;
    width: auto;
    white-space: nowrap;
  }

  .main {
    padding: 18px 18px 40px;
  }

  .page-head {
    display: block;
  }

  .toolbar {
    justify-content: flex-start;
    margin-top: 16px;
  }

  .grid.two,
  .grid.three,
  .role-grid {
    grid-template-columns: 1fr;
  }

  .hero-card {
    min-height: 0;
    padding: 28px 24px;
  }

  .hero-card::after {
    right: -26px;
    top: 34px;
    width: 92px;
    height: 92px;
    font-size: 42px;
    opacity: 0.22;
  }

  .hero-actions {
    display: grid;
  }

  .primary-btn,
  .secondary-btn,
  .ghost-btn,
  .danger-btn {
    width: 100%;
  }

  .mobile-top .ghost-btn,
  .section-head .ghost-btn {
    width: auto;
    min-width: 88px;
  }

  .section-head {
    align-items: flex-start;
  }

  .section-head > div {
    min-width: 0;
    flex: 1;
  }
}

/* Final visual overrides */
body { background: #f3f5f2; }
.side-nav { background: rgba(250, 251, 249, 0.94); }
.card,
.hero-card,
.option-card,
.history-item,
.order-item,
.product-card,
.modal-card,
.user-mini { border-radius: 8px; }
.card,
.hero-card { border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(30, 44, 34, 0.055); }
.hero-card { background: #fff; }
.primary-btn { background: var(--primary); box-shadow: 0 8px 18px rgba(92, 71, 36, 0.14); }
.secondary-btn,
.ghost-btn { border-color: rgba(72, 84, 75, 0.18); background: #fff; }
.page-title { font-size: clamp(28px, 3vw, 40px); }

.nav-image-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  object-fit: contain;
}

.nav-btn.has-custom-icon::before { display: none; }
.hero-with-image { background-position: center; background-repeat: no-repeat; background-size: cover; }

.qq-btn {
  width: 100%;
  min-height: 44px;
  margin-top: 10px;
  border: 1px solid #c9dcef;
  border-radius: 8px;
  color: #1769aa;
  background: #f4f9fd;
  font-weight: 800;
}
