/* =====================================================================
 * 塔罗占卜 · 样式
 * ===================================================================*/

:root {
  color-scheme: dark;
  --bg:        #0a0614;
  --ink:       #ede9fe;
  --ink-soft:  #c4b5fd;
  --ink-dim:   #8b7fb8;
  --line:      rgba(196, 181, 253, .16);
  --line-soft: rgba(196, 181, 253, .10);
  --violet:    #a855f7;
  --violet-2:  #7c3aed;
  --panel:     rgba(24, 15, 48, .62);
  --panel-2:   rgba(18, 11, 38, .80);
  --radius:    16px;
}

* { box-sizing: border-box; }

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

body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    radial-gradient(1000px 660px at 50% -12%, rgba(124, 58, 237, .42), transparent 62%),
    radial-gradient(820px 600px at 106% 104%, rgba(76, 29, 149, .50), transparent 60%),
    radial-gradient(820px 600px at -8% 96%, rgba(67, 56, 202, .34), transparent 60%);
  background-attachment: fixed;
  background-repeat: no-repeat;
  -webkit-font-smoothing: antialiased;
}

/* ================= 顶栏 ================= */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 22px;
  backdrop-filter: blur(14px);
  background: linear-gradient(180deg, rgba(10, 6, 20, .88), rgba(10, 6, 20, 0));
  -webkit-app-region: drag;
}
.topbar button { -webkit-app-region: no-drag; }

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-soft);
  opacity: .78;
}
.brand-mark { font-size: 13px; }
.brand-text { font-size: 11px; letter-spacing: .42em; }

/* 试用版剩余次数 */
.trial-badge {
  -webkit-app-region: no-drag;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid rgba(192, 132, 252, .26);
  background: rgba(192, 132, 252, .10);
  color: rgba(216, 196, 255, .82);
  font-size: 11px;
  letter-spacing: .04em;
  white-space: nowrap;
  user-select: none;
}
.trial-badge.empty {
  border-color: rgba(148, 140, 170, .22);
  background: rgba(148, 140, 170, .08);
  color: rgba(196, 181, 253, .45);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, .03);
  color: var(--ink-soft);
  font-size: 14px;
  cursor: pointer;
  transition: background .2s, border-color .2s, color .2s;
}
.icon-btn:hover {
  background: rgba(196, 181, 253, .12);
  border-color: rgba(196, 181, 253, .42);
  color: var(--ink);
}

/* ================= 页面容器 ================= */
.page {
  max-width: 880px;
  margin: 0 auto;
  padding: 4px 24px 72px;
}

/* ================= 标题 ================= */
.hero { text-align: center; padding: 22px 0 4px; }

.title {
  margin: 0;
  font-family: "Songti SC", "STSong", "Noto Serif SC", serif;
  font-size: clamp(30px, 4.4vw, 44px);
  font-weight: 600;
  letter-spacing: .26em;
  text-indent: .26em;
  background: linear-gradient(180deg, #f5f3ff, #c4b5fd 58%, #a78bfa);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 34px rgba(168, 85, 247, .34);
}

.subtitle {
  margin: 12px 0 0;
  font-size: 11px;
  letter-spacing: .52em;
  text-indent: .52em;
  color: rgba(196, 181, 253, .58);
}

/* ================= 提问区 ================= */
.ask-box {
  margin-top: 30px;
  padding: 20px 20px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  backdrop-filter: blur(12px);
  box-shadow: 0 20px 52px -28px rgba(0, 0, 0, .9), inset 0 1px 0 rgba(255, 255, 255, .045);
  transition: opacity .3s, transform .3s, border-color .3s;
}
.ask-box.locked { border-color: rgba(168, 85, 247, .26); }

/* 锁定只作用于输入区，停止按钮必须还能点 */
.ask-box.locked .ask-label,
.ask-box.locked .ask-input,
.ask-box.locked .chip {
  opacity: .42;
  pointer-events: none;
}

.ask-label {
  display: block;
  margin-bottom: 10px;
  font-size: 12px;
  letter-spacing: .22em;
  color: rgba(196, 181, 253, .72);
}

.ask-input {
  display: block;
  width: 100%;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(8, 5, 18, .62);
  color: var(--ink);
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.72;
  resize: vertical;
  min-height: 84px;
  outline: none;
  transition: border-color .22s, box-shadow .22s, background .22s;
}
.ask-input::placeholder { color: rgba(139, 127, 184, .62); }
.ask-input:focus {
  border-color: rgba(168, 85, 247, .62);
  background: rgba(12, 7, 26, .82);
  box-shadow: 0 0 0 3px rgba(168, 85, 247, .14);
}

.ask-foot {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.examples {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  flex: 1 1 380px;
}

.chip {
  padding: 6px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  background: rgba(255, 255, 255, .022);
  color: rgba(196, 181, 253, .68);
  font-family: inherit;
  font-size: 11.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: all .2s;
}
.chip:hover {
  border-color: rgba(196, 181, 253, .46);
  background: rgba(196, 181, 253, .10);
  color: var(--ink);
}

/* ================= 按钮 ================= */
.btn {
  position: relative;
  border: none;
  border-radius: 999px;
  padding: 11px 26px;
  font-family: inherit;
  font-size: 13px;
  letter-spacing: .16em;
  text-indent: .16em;
  cursor: pointer;
  user-select: none;
  transition: transform .22s, box-shadow .22s, background .22s, opacity .22s;
}
.btn-primary {
  color: #fff;
  background-image: linear-gradient(135deg, #7c3aed, #a855f7 55%, #c084fc);
  box-shadow: 0 10px 28px -8px rgba(168, 85, 247, .70), inset 0 1px 0 rgba(255, 255, 255, .28);
}
.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 14px 34px -8px rgba(168, 85, 247, .92), inset 0 1px 0 rgba(255, 255, 255, .34);
}
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled {
  opacity: .28;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}
.btn-sm { padding: 9px 20px; font-size: 12.5px; }
.btn-stop {
  background-image: linear-gradient(135deg, #6d28d9, #9f1239) !important;
}

.mini-btn {
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .03);
  color: rgba(196, 181, 253, .78);
  font-family: inherit;
  font-size: 11.5px;
  cursor: pointer;
  transition: all .2s;
}
.mini-btn:hover:not(:disabled) {
  border-color: rgba(196, 181, 253, .5);
  color: var(--ink);
  background: rgba(196, 181, 253, .10);
}
.mini-btn:disabled { opacity: .3; cursor: not-allowed; }

/* ================= 卡牌 ================= */
.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
  margin: 32px auto 0;
  max-width: 660px;
}
.cards:empty { display: none; }

/* 抽牌前的空位：虚线框里透出一点牌背 */
.card-slot-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.card-slot {
  position: relative;
  width: 100%;
  aspect-ratio: 300 / 527;
  overflow: hidden;
  border: 1px dashed rgba(196, 181, 253, .16);
  border-radius: 9px;
  background: linear-gradient(180deg, rgba(124, 58, 237, .05), rgba(124, 58, 237, .012));
  user-select: none;
}
.card-slot img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: .16;
  filter: saturate(.5);
}

.slot-label {
  margin: 14px 0 0;
  font-size: 10.5px;
  letter-spacing: .34em;
  text-indent: .34em;
  color: rgba(196, 181, 253, .46);
}

.card-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: cardIn .5s cubic-bezier(.2, .7, .3, 1) both;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(22px) scale(.965); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.card-scene {
  position: relative;
  width: 100%;
  aspect-ratio: 300 / 527;
  perspective: 1400px;
  cursor: pointer;
  outline: none;
  animation: floaty 5.5s ease-in-out infinite;
  animation-delay: var(--float-delay, 0s);
  transform: rotate(var(--tilt, 0deg));
}
.card-scene.flipped { animation: none; transform: rotate(var(--tilt, 0deg)); }

@keyframes floaty {
  0%, 100% { transform: translateY(0) rotate(var(--tilt, 0deg)); }
  50%      { transform: translateY(-7px) rotate(var(--tilt, 0deg)); }
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform .88s cubic-bezier(.45, .05, .2, 1);
  will-change: transform;
}
.card-scene.flipped .card-inner { transform: rotateY(180deg); }

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 9px;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 16px 38px -12px rgba(0, 0, 0, .92), 0 0 0 1px rgba(190, 165, 230, .16);
  transition: box-shadow .35s ease, filter .35s ease;
}
.card-scene:not(.flipped):hover .card-face {
  box-shadow: 0 22px 48px -12px rgba(139, 92, 246, .62), 0 0 0 1px rgba(203, 175, 255, .62);
}
.card-face img { display: block; width: 100%; height: 100%; object-fit: cover; }

/* 正面：老牌纸的暖白底，图片没加载出来也不至于破图 */
.card-face--front {
  transform: rotateY(180deg);
  background: #efe6d2;
}
.card-face--front img.reversed { transform: rotate(180deg); }

/* 翻过来之后的一层纸面高光，鼠标移上去才亮 */
.card-face--front::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(118deg, rgba(255, 255, 255, .30) 0%, rgba(255, 255, 255, .06) 26%, rgba(255, 255, 255, 0) 48%);
  opacity: 0;
  transition: opacity .38s ease;
  pointer-events: none;
}
.card-scene.flipped:hover .card-face--front::after { opacity: 1; }
.card-scene.flipped:hover .card-face { filter: brightness(1.06); }

.card-info {
  position: relative;
  z-index: 3;          /* 翻转后的 3D 层可能压住文字，抬上来 */
  margin-top: 14px;
  text-align: center;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .45s ease .26s, transform .45s ease .26s;
}
.card-info.show { opacity: 1; transform: translateY(0); }

.card-pos {
  margin: 0;
  font-size: 10.5px;
  letter-spacing: .34em;
  text-indent: .34em;
  color: rgba(196, 181, 253, .66);
}
.card-name {
  margin: 6px 0 0;
  font-size: 16px;
  font-weight: 500;
  color: #f7f4ff;
}
.card-orient {
  margin: 4px 0 0;
  font-size: 12px;
  font-weight: 600;
}
.card-orient.up { color: #6ee7b7; }
.card-orient.rev { color: #fb7185; }

.hint {
  margin: 18px 0 0;
  text-align: center;
  font-size: 11px;
  letter-spacing: .18em;
  color: rgba(196, 181, 253, .40);
}

/* ================= 解读区 ================= */
.reading {
  margin-top: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  box-shadow: 0 26px 60px -34px rgba(0, 0, 0, .95), inset 0 1px 0 rgba(255, 255, 255, .04);
  overflow: hidden;
  animation: fadeUp .45s ease both;
}

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

.reading-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 22px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(124, 58, 237, .07);
}
.reading-title {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12px;
  letter-spacing: .28em;
  color: rgba(196, 181, 253, .82);
}
.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #a855f7;
  box-shadow: 0 0 10px 2px rgba(168, 85, 247, .72);
}
.reading-actions { display: flex; gap: 8px; }

.reading-body {
  padding: 24px 26px 8px;
  font-size: 15px;
  line-height: 1.95;
  color: #e4ddfa;
  word-break: break-word;
}
.reading-body:empty { display: none; }

/* 正文排版 */
.reading-body h3 {
  margin: 26px 0 10px;
  padding-left: 12px;
  border-left: 2px solid rgba(168, 85, 247, .72);
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: .06em;
  color: #d8ccff;
}
.reading-body h3:first-child { margin-top: 4px; }
.reading-body p { margin: 0 0 14px; }
.reading-body strong { color: #f0e9ff; font-weight: 600; }
.reading-body ul, .reading-body ol { margin: 0 0 14px; padding-left: 22px; }
.reading-body li { margin: 5px 0; }
.reading-body code {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(168, 85, 247, .16);
  font-size: 13px;
}

/* 打字光标 */
.caret {
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 2px;
  vertical-align: -2px;
  background: #c084fc;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.reading-status {
  padding: 0 26px;
  font-size: 12.5px;
  line-height: 1.7;
  color: rgba(196, 181, 253, .66);
}
.reading-status:not(:empty) { padding-bottom: 20px; }
.reading-status.error { color: #fca5a5; }
.reading-status.error code {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(248, 113, 113, .14);
}

/* 等待中的三点 */
.thinking { display: inline-flex; gap: 5px; vertical-align: middle; }
.thinking i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #a855f7;
  opacity: .35;
  animation: bounce 1.2s infinite;
}
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce {
  0%, 60%, 100% { opacity: .28; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-4px); }
}

/* ================= 免责 ================= */
.disclaimer {
  margin: 34px 0 0;
  text-align: center;
  font-size: 11px;
  letter-spacing: .1em;
  color: rgba(139, 127, 184, .48);
}

/* ================= 弹窗 ================= */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(5, 3, 12, .72);
  backdrop-filter: blur(6px);
  animation: fadeIn .2s ease both;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-panel {
  position: relative;
  width: 100%;
  max-width: 468px;
  max-height: 86vh;
  overflow-y: auto;
  padding: 22px 24px 20px;
  border: 1px solid rgba(196, 181, 253, .20);
  border-radius: 18px;
  background: #13102a;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .95);
  animation: popIn .26s cubic-bezier(.2, .8, .3, 1) both;
}
@keyframes popIn {
  from { opacity: 0; transform: translateY(14px) scale(.975); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.modal-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .2em;
  color: var(--ink);
}

.field { margin-bottom: 18px; }
.field > label {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  letter-spacing: .14em;
  color: rgba(196, 181, 253, .74);
}

/* 服务商切换 */
.preset-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.preset {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 11px;
  text-align: left;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: rgba(30, 24, 56, .55);
  color: #ded6f5;
  cursor: pointer;
  font-family: inherit;
  transition: border-color .18s, background .18s;
}
.preset b { font-size: 12.5px; font-weight: 600; }
.preset span { font-size: 10.5px; line-height: 1.4; color: rgba(196, 181, 253, .58); }
.preset:hover { border-color: rgba(192, 132, 252, .45); }
.preset.on {
  border-color: rgba(192, 132, 252, .8);
  background: rgba(88, 60, 140, .42);
  box-shadow: 0 0 0 1px rgba(192, 132, 252, .18) inset;
}
.preset.on b { color: #f0e8ff; }

.field input,
.field select {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(8, 5, 18, .68);
  color: var(--ink);
  font-family: inherit;
  font-size: 13.5px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.field input:focus, .field select:focus {
  border-color: rgba(168, 85, 247, .62);
  box-shadow: 0 0 0 3px rgba(168, 85, 247, .12);
}
.field select option { background: #13102a; }

.key-row { display: flex; gap: 8px; }
.key-row input { flex: 1; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.key-row .mini-btn { flex: 0 0 auto; padding: 0 13px; }

.tip {
  margin: 8px 0 0;
  font-size: 11.5px;
  line-height: 1.75;
  color: rgba(139, 127, 184, .72);
}
.tip code {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(168, 85, 247, .15);
  color: #d8ccff;
}
.tip a { color: #c084fc; text-decoration: none; border-bottom: 1px dashed rgba(192, 132, 252, .5); }

.advanced {
  margin-bottom: 16px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 10px 13px;
  background: rgba(255, 255, 255, .015);
}
.advanced summary {
  font-size: 12px;
  color: rgba(196, 181, 253, .62);
  cursor: pointer;
  outline: none;
}
.advanced[open] summary { margin-bottom: 12px; }
.advanced .field { margin-bottom: 0; margin-top: 4px; }

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 6px;
}
.save-tip { font-size: 12px; color: #6ee7b7; }

.hidden { display: none !important; }

/* ================= 窄窗口 ================= */
@media (max-width: 760px) {
  .cards { gap: 14px; }
  .page { padding: 4px 16px 60px; }
  .ask-foot { flex-direction: column; align-items: stretch; }
  .ask-foot .btn { width: 100%; }

  /* 手机上示例按钮不能被拉成胶囊块：行高由内容决定，超长自动换行 */
  .examples {
    flex: 0 0 auto;
    align-items: flex-start;
    align-content: flex-start;
    overflow: visible;
  }
  .chip {
    flex: 0 0 auto;
    align-self: flex-start;
    white-space: normal;
    text-align: left;
    line-height: 1.35;
    font-size: 11px;
    padding: 5px 10px;
    max-width: 100%;
  }
}
