/* 暗色神秘风，移动优先，无外部资源 */

:root {
  --bg: #07060d;
  --bg-soft: #100c1b;
  --ink: #ece6f5;
  --ink-dim: #b6accb;
  --muted: #7f7595;
  --gold: #d9b573;
  --gold-soft: #a98f5e;
  --gold-line: rgba(217, 181, 115, 0.24);
  --danger: #d98f8f;
  --serif: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", serif;
  --sans: system-ui, -apple-system, "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --radius: 14px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

/* hidden 属性必须压过下面所有 display 声明 */
[hidden] {
  display: none !important;
}

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

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* 背景：一层月晕 + 一层星点，纯 CSS，离线也有 */
body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

body::before {
  background:
    radial-gradient(120% 70% at 50% -10%, rgba(112, 82, 160, 0.32), transparent 62%),
    radial-gradient(70% 50% at 82% 8%, rgba(217, 181, 115, 0.1), transparent 70%),
    linear-gradient(180deg, #0a0812 0%, #07060d 55%, #05040a 100%);
}

body::after {
  background-image:
    radial-gradient(1.4px 1.4px at 12% 18%, rgba(255, 255, 255, 0.5), transparent),
    radial-gradient(1.2px 1.2px at 78% 12%, rgba(255, 255, 255, 0.35), transparent),
    radial-gradient(1.6px 1.6px at 64% 34%, rgba(255, 255, 255, 0.28), transparent),
    radial-gradient(1.2px 1.2px at 28% 52%, rgba(255, 255, 255, 0.22), transparent),
    radial-gradient(1.5px 1.5px at 88% 62%, rgba(255, 255, 255, 0.3), transparent),
    radial-gradient(1.2px 1.2px at 8% 76%, rgba(255, 255, 255, 0.24), transparent),
    radial-gradient(1.8px 1.8px at 46% 88%, rgba(255, 255, 255, 0.18), transparent);
  opacity: 0.75;
}

#app {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 18px) 20px
    calc(env(safe-area-inset-bottom, 0px) + 28px);
  display: flex;
  flex-direction: column;
}

/* ---------- 顶栏 ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  margin-bottom: 8px;
}

.brand {
  font-family: var(--serif);
  font-size: 15px;
  letter-spacing: 0.28em;
  color: var(--gold-soft);
  text-indent: 0.28em;
}

.brand-btn {
  background: none;
  border: 0;
  padding: 6px 10px 6px 0;
  cursor: pointer;
}

.topbar button {
  font-size: 13px;
  color: var(--muted);
  background: none;
  border: 0;
  padding: 6px 2px 6px 10px;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.topbar button:active {
  color: var(--gold);
}

/* ---------- 屏幕切换 ---------- */

main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 18px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.screen[hidden] {
  display: none;
}

.screen.is-in {
  opacity: 1;
  transform: none;
}

/* ---------- 口令 ---------- */

.gate {
  justify-content: center;
  text-align: center;
  padding: 8px 0 8vh;
}

.gate h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 30px;
  letter-spacing: 0.12em;
  margin: 0 0 30px;
  color: var(--ink);
}

.gate form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 300px;
  margin: 0 auto;
}

input[type="text"],
textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--gold-line);
  border-radius: var(--radius);
  padding: 13px 15px;
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
}

/* 口令明文可见：不用 password，避免安卓调起系统密码键盘、无法粘贴 */
.gate input[type="text"] {
  text-align: center;
  font-size: 17px;
  letter-spacing: 0.06em;
  font-variant-ligatures: none;
}

input[type="text"]:focus,
textarea:focus {
  border-color: rgba(217, 181, 115, 0.55);
  background: rgba(255, 255, 255, 0.05);
}

.gate-hint {
  margin: 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
  letter-spacing: 0.04em;
}

textarea {
  resize: none;
  min-height: 88px;
  line-height: 1.7;
}

textarea::placeholder,
input::placeholder {
  color: rgba(180, 170, 200, 0.42);
}

.error {
  min-height: 20px;
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--danger);
}

/* ---------- 按钮 ---------- */

button {
  font: inherit;
  cursor: pointer;
}

.primary {
  width: 100%;
  padding: 15px;
  border-radius: var(--radius);
  border: 1px solid rgba(217, 181, 115, 0.5);
  background: linear-gradient(180deg, rgba(217, 181, 115, 0.16), rgba(217, 181, 115, 0.06));
  color: var(--gold);
  font-family: var(--serif);
  font-size: 17px;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
  transition: transform 0.12s ease, background 0.2s ease, opacity 0.2s ease;
}

.primary:active {
  transform: scale(0.985);
  background: linear-gradient(180deg, rgba(217, 181, 115, 0.24), rgba(217, 181, 115, 0.1));
}

.primary[disabled] {
  opacity: 0.45;
  pointer-events: none;
}

.ghost {
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: transparent;
  color: var(--ink-dim);
  font-size: 15px;
  letter-spacing: 0.08em;
}

.ghost:active {
  border-color: var(--gold-line);
  color: var(--gold);
}

/* ---------- 首页 ---------- */

.home-head {
  margin-top: 6px;
}

.home-head h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 24px;
  letter-spacing: 0.1em;
  margin: 0 0 6px;
}

.home-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.04em;
}

.spread-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.spread {
  text-align: left;
  padding: 16px 14px;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.02);
  color: var(--ink-dim);
  transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.spread strong {
  display: block;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 17px;
  letter-spacing: 0.06em;
  color: var(--ink);
}

.spread span {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.spread[aria-checked="true"] {
  border-color: rgba(217, 181, 115, 0.55);
  background: rgba(217, 181, 115, 0.07);
}

.spread[aria-checked="true"] span {
  color: var(--gold-soft);
}

.q-label {
  display: block;
  font-size: 12px;
  letter-spacing: 0.2em;
  color: var(--muted);
  margin-bottom: -8px;
}

.home-foot {
  margin-top: auto;
  padding-top: 8px;
}

.home-foot .ghost {
  width: 100%;
}

/* ---------- 牌面 ---------- */

.cards {
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 6px 0 4px;
  perspective: 1200px;
}

.cards.single {
  gap: 0;
}

.card {
  position: relative;
  width: 100%;
  max-width: 210px;
  aspect-ratio: 2 / 3.4;
  transform-style: preserve-3d;
  transition: transform 0.75s cubic-bezier(0.2, 0.7, 0.2, 1);
  transform: rotateY(0deg);
}

.cards.three .card {
  max-width: 132px;
}

.card.is-revealed {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border: 1px solid var(--gold-line);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55);
}

.card-back {
  background:
    radial-gradient(circle at 50% 42%, rgba(217, 181, 115, 0.16), transparent 55%),
    repeating-linear-gradient(45deg, rgba(217, 181, 115, 0.07) 0 1px, transparent 1px 9px),
    linear-gradient(160deg, #1a1428, #0d0a17 60%, #171125);
  display: grid;
  place-items: center;
}

.card-back::before {
  content: "";
  width: 46%;
  aspect-ratio: 1;
  border: 1px solid rgba(217, 181, 115, 0.35);
  border-radius: 50%;
}

.card-back::after {
  content: "✦";
  position: absolute;
  font-size: 20px;
  color: rgba(217, 181, 115, 0.75);
}

.card-front {
  transform: rotateY(180deg);
  background: #0b0813;
}

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

.card-label {
  margin-top: 10px;
  text-align: center;
}

.card-slot {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.card-name {
  font-family: var(--serif);
  font-size: 14px;
  letter-spacing: 0.08em;
  color: var(--ink);
  white-space: nowrap;
}

.card-side {
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.card-side.reversed {
  color: #b98d8d;
}

/* 洗牌 */

.shuffle {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 240px;
}

.shuffle .stack {
  position: relative;
  width: 120px;
  height: 200px;
}

.shuffle .stack i {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  border: 1px solid var(--gold-line);
  background:
    repeating-linear-gradient(45deg, rgba(217, 181, 115, 0.07) 0 1px, transparent 1px 9px),
    linear-gradient(160deg, #1a1428, #0d0a17 60%, #171125);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.5);
  animation: shuffle 1.05s ease-in-out infinite;
}

.shuffle .stack i:nth-child(1) {
  animation-delay: 0s;
}
.shuffle .stack i:nth-child(2) {
  animation-delay: 0.14s;
}
.shuffle .stack i:nth-child(3) {
  animation-delay: 0.28s;
}
.shuffle .stack i:nth-child(4) {
  animation-delay: 0.42s;
}

@keyframes shuffle {
  0%,
  100% {
    transform: translateX(0) rotate(0deg);
  }
  25% {
    transform: translateX(-26px) rotate(-5deg);
  }
  50% {
    transform: translateX(0) rotate(0deg);
  }
  75% {
    transform: translateX(26px) rotate(5deg);
  }
}

/* ---------- 解读 ---------- */

.reading-head {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.reading-question {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.03em;
  border-left: 2px solid var(--gold-line);
  padding-left: 10px;
  word-break: break-word;
}

.reading-text {
  font-family: var(--serif);
  font-size: 16.5px;
  line-height: 2;
  letter-spacing: 0.02em;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 120px;
}

.reading-text.is-streaming::after {  content: "";
  display: inline-block;
  width: 7px;
  height: 16px;
  margin-left: 3px;
  vertical-align: -2px;
  background: var(--gold);
  opacity: 0.7;
  animation: blink 1s step-end infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* ---------- 追问 ---------- */

.followups {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-top: 6px;
}

.followup {
  border-left: 2px solid var(--gold-line);
  padding-left: 13px;
}

.followup-q {
  margin: 0 0 7px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--gold-soft);
  letter-spacing: 0.02em;
  word-break: break-word;
}

.followup-q::before {
  content: "问 · ";
  color: var(--muted);
}

.followup-a {
  margin: 0;
  font-family: var(--serif);
  font-size: 15.5px;
  line-height: 2;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
}

.followup-a.is-empty {
  color: var(--muted);
  font-size: 13px;
}

.followup-a.is-streaming::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 15px;
  margin-left: 3px;
  vertical-align: -2px;
  background: var(--gold);
  opacity: 0.7;
  animation: blink 1s step-end infinite;
}

.followup-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin-top: 4px;
}

.followup-form textarea {
  min-height: 50px;
  font-size: 15px;
  padding: 12px 14px;
}

.primary.compact {
  width: auto;
  flex: 0 0 auto;
  padding: 12px 20px;
  font-size: 15px;
  letter-spacing: 0.12em;
  text-indent: 0.12em;
}

.history-followups {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

/* 逐字浮现：每个字单独淡入，柔和不跳。只动 opacity，不动布局 */
.fade-in {
  animation: fadeIn 360ms cubic-bezier(0.22, 0.08, 0.24, 1) both;
}

.fade-done {
  opacity: 1;
}

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

@media (prefers-reduced-motion: reduce) {
  .fade-in {
    animation: none;
  }
}

.thinking {  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.1em;
}

.thinking::after {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold-soft);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.2;
    transform: scale(0.8);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

.hint {
  margin: 0;
  font-size: 13px;
  color: var(--danger);
  line-height: 1.7;
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: auto;
  padding-top: 14px;
}

.actions button {
  flex: 1;
}

/* ---------- 历史 ---------- */

.history-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 8px;
}

.history-item {
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: var(--radius);
  padding: 14px;
  background: rgba(255, 255, 255, 0.02);
}

.history-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 8px;
}

.history-question {
  font-size: 13px;
  color: var(--ink-dim);
  margin: 0 0 8px;
  word-break: break-word;
}

.history-cards {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.history-cards img {
  width: 42px;
  aspect-ratio: 2 / 3.4;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid rgba(217, 181, 115, 0.2);
}

.history-text {
  font-family: var(--serif);
  font-size: 14px;
  line-height: 1.9;
  color: var(--ink-dim);
  white-space: pre-wrap;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-item.is-open .history-text {
  -webkit-line-clamp: unset;
  display: block;
}

.history-toggle {
  margin-top: 8px;
  font-size: 12px;
  color: var(--gold-soft);
  background: none;
  border: 0;
  padding: 0;
  letter-spacing: 0.08em;
}

.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  letter-spacing: 0.1em;
}

@media (max-width: 360px) {
  #app {
    padding-left: 14px;
    padding-right: 14px;
  }
  .cards.three {
    gap: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card,
  .screen,
  .shuffle .stack i {
    transition: none;
    animation: none;
  }
}
