/* ==========================================================================
   main.css — 视觉规范与通用组件（阶段一）
   配色与规则依据《K线过山车_V1.0_DSH开发需求文档》§2
   ========================================================================== */

/* ---------- 1. 设计令牌 ---------- */
:root {
  /* 主色板（文档 §2.2） */
  --c-pink: #f5a9c8;
  --c-pink-deep: #ec8fb6;
  --c-lilac: #c8b6e8;
  --c-lilac-deep: #a98fd6;
  --c-bg: #fff8fc;
  --c-bg-soft: #fdf1f8;
  --c-loss: #e85d75;
  --c-profit: #73b99a;
  --c-dark: #292331;

  /* 中性色 */
  --c-ink: #292331;
  --c-ink-soft: #5d5568;
  --c-ink-faint: #8d8598;
  --c-line: #f0dfe9;
  --c-card: #ffffff;

  /* 圆角 / 阴影 / 间距 */
  --r-xl: 28px;
  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;
  --r-pill: 999px;

  --sh-card: 0 22px 50px -28px rgba(41, 35, 49, 0.38);
  --sh-btn: 0 10px 22px -12px rgba(236, 143, 182, 0.9);
  --sh-focus: 0 0 0 3px rgba(200, 182, 232, 0.75);

  --s-1: 6px;
  --s-2: 12px;
  --s-3: 18px;
  --s-4: 26px;
  --s-5: 38px;
  --s-6: 56px;

  /* 字体：优先圆体，保证“日系轻量”观感；均为系统字体，无外网依赖 */
  --font-sans: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Yu Gothic UI",
    "Meiryo", "PingFang SC", "Microsoft YaHei UI", system-ui, -apple-system, sans-serif;
  --font-num: "Cascadia Mono", "SF Mono", Consolas, ui-monospace, monospace;

  /* 动效 */
  --t-fast: 120ms ease;
  --t-base: 220ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

/* ---------- 2. 重置 ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--c-ink);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden; /* 单页游戏，禁止整页滚动，避免拖动时误滚 */
}

h1,
h2,
h3,
p {
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: none;
  box-shadow: var(--sh-focus);
}

/* ---------- 3. 背景装饰层 ---------- */
.bg-decor {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% -10%, #fff 0%, var(--c-bg) 46%, #fdeef8 100%);
}

.bg-decor__blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(46px);
  opacity: 0.5;
  animation: blob-float 16s ease-in-out infinite alternate;
}

.bg-decor__blob--pink {
  width: 460px;
  height: 460px;
  top: -140px;
  left: -120px;
  background: radial-gradient(circle, var(--c-pink) 0%, rgba(245, 169, 200, 0) 70%);
}

.bg-decor__blob--lilac {
  width: 520px;
  height: 520px;
  right: -160px;
  bottom: -200px;
  background: radial-gradient(circle, var(--c-lilac) 0%, rgba(200, 182, 232, 0) 70%);
  animation-delay: -6s;
}

.bg-decor__blob--mint {
  width: 340px;
  height: 340px;
  top: 42%;
  left: 56%;
  background: radial-gradient(circle, #ffe3ee 0%, rgba(255, 227, 238, 0) 70%);
  opacity: 0.55;
  animation-delay: -11s;
}

.bg-decor__spark {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--s);
  height: var(--s);
  background: #fff;
  border-radius: 2px;
  transform: rotate(45deg);
  box-shadow: 0 0 10px 2px rgba(245, 169, 200, 0.9);
  opacity: 0.85;
  animation: spark-twinkle 3.6s ease-in-out infinite;
  animation-delay: var(--delay, 0s);
}

@keyframes blob-float {
  from {
    transform: translate3d(0, 0, 0) scale(1);
  }
  to {
    transform: translate3d(24px, -28px, 0) scale(1.08);
  }
}

@keyframes spark-twinkle {
  0%,
  100% {
    opacity: 0.15;
    transform: rotate(45deg) scale(0.7);
  }
  50% {
    opacity: 0.9;
    transform: rotate(45deg) scale(1);
  }
}

/* ---------- 4. 屏幕容器与路由 ---------- */
.app-shell {
  position: relative;
  z-index: 1;
  height: 100dvh;
  width: 100%;
}

/* 只有带 .is-active 的屏幕可见；后续阶段新增屏幕时复用此机制 */
.screen {
  display: none;
  height: 100%;
  width: 100%;
}

.screen.is-active {
  display: block;
  animation: screen-in var(--t-base) both;
}

@keyframes screen-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- 5. 按钮 ---------- */
.btn {
  --btn-bg: var(--c-card);
  --btn-fg: var(--c-ink);
  --btn-bd: var(--c-line);

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 22px;
  border: 1px solid var(--btn-bd);
  border-radius: var(--r-pill);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.02em;
  cursor: pointer;
  user-select: none;
  transition: transform var(--t-fast), box-shadow var(--t-base),
    background-color var(--t-base), border-color var(--t-base), color var(--t-base);
}

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

.btn:active:not(:disabled) {
  transform: translateY(1px) scale(0.99);
}

/* 主要按钮：樱花粉渐变 */
.btn--primary {
  --btn-fg: #4a2334;
  --btn-bd: transparent;
  background: linear-gradient(135deg, var(--c-pink) 0%, #f7bcd4 55%, var(--c-lilac) 100%);
  box-shadow: var(--sh-btn);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
}

.btn--primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #f39ac0 0%, #f3b0cc 55%, #bfa9e6 100%);
  box-shadow: 0 14px 26px -10px rgba(236, 143, 182, 0.95);
}

/* 次要按钮：淡紫描边 */
.btn--secondary {
  --btn-fg: #5b4680;
  --btn-bd: #ded2f2;
  --btn-bg: #faf7ff;
}

.btn--secondary:hover:not(:disabled) {
  --btn-bd: var(--c-lilac);
  --btn-bg: #f4eeff;
}

/* 幽灵按钮：无底色 */
.btn--ghost {
  --btn-bg: transparent;
  --btn-bd: transparent;
  --btn-fg: var(--c-ink-soft);
}

.btn--ghost:hover:not(:disabled) {
  --btn-bg: rgba(200, 182, 232, 0.16);
  --btn-fg: var(--c-ink);
}

/* 大号按钮 */
.btn--lg {
  min-height: 58px;
  padding: 0 34px;
  font-size: 18px;
  border-radius: var(--r-pill);
}

/* 小号按钮（工具栏、次要操作） */
.btn--sm {
  min-height: 34px;
  padding: 0 14px;
  font-size: 13px;
  gap: 6px;
}

.btn--block {
  width: 100%;
}

/* 禁用态：降低对比度、去掉阴影、游标提示不可点 */
.btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  box-shadow: none;
  filter: grayscale(0.35);
  transform: none;
}

/* ---------- 6. 通用卡片与数据展示 ---------- */
.card {
  background: var(--c-card);
  border: 1px solid var(--c-line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-card);
}

/* 盈利 / 亏损：颜色 + 文字前缀必须同时出现，不允许只靠颜色区分 */
.value-profit {
  color: var(--c-profit);
}

.value-loss {
  color: var(--c-loss);
}

.num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

/* ---------- 7. 弹窗 ---------- */
.dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: min(80dvh, 720px);
  padding: 0;
  border: 1px solid #f3e2ee;
  border-radius: var(--r-xl);
  background: var(--c-card);
  color: var(--c-ink);
  box-shadow: 0 30px 70px -30px rgba(41, 35, 49, 0.55);
  overflow: hidden;
  /* 头部固定、内容区滚动、底部按钮固定 */
  flex-direction: column;
}

.dialog[open] {
  display: flex;
  animation: dialog-in var(--t-base) both;
}

.dialog::backdrop {
  background: rgba(73, 52, 70, 0.26);
  backdrop-filter: blur(2px);
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.dialog__head {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-4) var(--s-2);
  border-bottom: 1px solid var(--c-line);
  background: linear-gradient(180deg, #fff7fb 0%, #ffffff 100%);
}

.dialog__title {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.dialog__close {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border: 1px solid var(--c-line);
  border-radius: 50%;
  background: #fff;
  color: var(--c-ink-faint);
  cursor: pointer;
  transition: background-color var(--t-fast), color var(--t-fast);
}

.dialog__close:hover {
  background: #fdeef6;
  color: var(--c-loss);
}

/* 内容滚动区的外层：负责底部渐隐提示“还有内容” */
.dialog__scroll {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

.dialog__scroll::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 28px;
  background: linear-gradient(to top, #ffffff 12%, rgba(255, 255, 255, 0));
  opacity: 0;
  transition: opacity var(--t-fast);
  pointer-events: none;
}

.dialog__scroll.has-more::after {
  opacity: 1;
}

.dialog__body {
  flex: 1 1 auto;
  min-height: 0;
  padding: var(--s-3) var(--s-4);
  overflow-y: auto;
  overscroll-behavior: contain;
  font-size: 14.5px;
  line-height: 1.8;
  color: var(--c-ink-soft);
  /* 滚动容器被浏览器自动聚焦时不画焦点环（它不是可操作元素） */
  outline: none;
  box-shadow: none;
}

.dialog__scroll:focus,
.dialog__scroll:focus-visible {
  outline: none;
  box-shadow: none;
}

.dialog__body h3 {
  margin: var(--s-3) 0 var(--s-1);
  font-size: 15px;
  color: var(--c-ink);
}

.dialog__body h3:first-child {
  margin-top: 0;
}

.dialog__body ul {
  margin: 0;
  padding-left: 1.2em;
}

.dialog__body li + li {
  margin-top: 2px;
}

.dialog__body strong {
  color: var(--c-ink);
}

.dialog__foot {
  display: flex;
  flex: 0 0 auto;
  justify-content: flex-end;
  gap: var(--s-1);
  padding: var(--s-2) var(--s-4) var(--s-3);
  border-top: 1px solid #fbf1f6;
  background: #fffdfe;
}

/* ---------- 历史记录弹窗 ---------- */
.history__summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid #f4e6ee;
  font-size: 12.5px;
  color: var(--c-ink-soft);
}

.history__summary b {
  font-size: 14px;
  color: var(--c-ink);
}

.history__list {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.history__row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: baseline;
  gap: 12px;
  padding-bottom: 7px;
  border-bottom: 1px dashed #f4e6ee;
  font-size: 12.5px;
}

.history__row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.history__when {
  color: var(--c-ink-faint);
  font-size: 11.5px;
  white-space: nowrap;
}

.history__meta {
  color: var(--c-ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history__pnl {
  font-weight: 800;
  text-align: right;
  white-space: nowrap;
}

.history__empty {
  padding: 10px 0;
  color: var(--c-ink-faint);
  font-size: 13px;
}

/* ---------- 8. 轻提示 toast ---------- */
.toast-root {
  position: fixed;
  left: 50%;
  /* 抬到底部状态条上方，避免压住"平仓"按钮 */
  bottom: 96px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  max-width: min(78vw, 460px);
  padding: 11px 20px;
  border-radius: var(--r-pill);
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(41, 35, 49, 0.92);
  color: #fff6fa;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow: 0 16px 30px -18px rgba(41, 35, 49, 0.9);
  animation: toast-in 180ms ease both;
}

.toast.is-leaving {
  animation: toast-out 200ms ease both;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(-6px);
  }
}

/* ---------- 9. 可访问性：尊重“减少动态效果”偏好 ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
