/* ==================================================================
   闲庄录 · 抽签转盘 · 墨玉青瓷主题
   闲=青瓷冷绿  庄=赭石暖褐  已抽=灰  结构线=鎏金  底=宣纸
   ================================================================== */

:root {
  --xian: #3E7C6B;
  --xian-light: #6BAF98;
  --xian-dark: #2A5A4D;
  --xian-pale: #E4EFEA;

  --zhuang: #A65A3E;
  --zhuang-light: #C98A66;
  --zhuang-dark: #7E3F2A;

  --used: #CFCBC0;
  --used-light: #DEDACF;
  --used-dark: #A9A497;

  --gold: #C8A96A;
  --gold-dark: #9A7F45;

  --ink: #1C2B28;
  --ink-mute: #5A6E68;
  --paper: #F2EFE6;
  --paper-warm: #FAF8F1;
  --paper-deep: #E4DFD1;

  --radius: 10px;
  --shadow-sm: 0 1px 3px rgb(28 43 40 / .08);
  --shadow: 0 4px 16px rgb(28 43 40 / .08);
  --shadow-lg: 0 12px 40px rgb(28 43 40 / .16);

  --ease: cubic-bezier(.4, 0, .2, 1);
  --header-h: 62px;
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

h1, h2, p { margin: 0; }
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

:focus-visible { outline: 2px solid var(--xian); outline-offset: 2px; border-radius: 4px; }

/* ==================================================================
   顶栏
   ================================================================== */
.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 60;
  background: rgb(242 239 230 / .88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--paper-deep);
}
.topbar-inner {
  max-width: 1160px;
  margin: 0 auto;
  padding: 0 24px;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand { display: flex; align-items: center; gap: 10px; flex: none; }
.brand-seal {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  background: var(--xian);
  color: var(--paper-warm);
  border-radius: 4px;
  font-family: "Songti SC", "SimSun", serif;
  font-size: 17px;
  font-weight: 700;
}
.brand-text {
  font-family: "Songti SC", "SimSun", serif;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 3px;
}

/* 进度条 */
.progress { display: flex; align-items: center; gap: 12px; min-width: 0; }
.progress-text {
  font-size: 12px;
  color: var(--ink-mute);
  letter-spacing: 1px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.progress-track {
  width: 140px;
  height: 6px;
  background: var(--paper-deep);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  display: block;
  height: 100%;
  background: var(--xian);
  border-radius: 3px;
  transition: width .45s var(--ease), background-color .3s var(--ease);
}
.progress-fill.is-low { background: var(--zhuang); }

/* ==================================================================
   舞台
   ================================================================== */
.stage {
  min-height: 100vh;
  padding: calc(var(--header-h) + 44px) 0 60px;
  background:
    radial-gradient(ellipse 70% 45% at 50% 0%, rgb(62 124 107 / .06), transparent 70%),
    var(--paper);
}
.stage-inner { max-width: 1160px; margin: 0 auto; padding: 0 24px; }

/* ==================================================================
   布局
   ================================================================== */
.wheel-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 36px;
  align-items: start;
}

.wheel-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.wheel-frame {
  position: relative;
  width: 100%;
  max-width: 540px;
  /* 双保险撑出正圆：
     ① aspect-ratio —— 现代浏览器直接生效
     ② padding-top:100% —— 老浏览器（Safari 15- / Edge 88-）的兜底
     JS 还会再补一次显式 height，三重保障 */
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 45%, var(--paper-warm) 0%, var(--paper) 70%);
  border-radius: 50%;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

/* 老浏览器兜底：aspect-ratio 不生效时用 padding 撑高度
   配合 @supports 让现代浏览器跳过这段 */
@supports not (aspect-ratio: 1 / 1) {
  .wheel-frame {
    height: 0;
    padding-top: 100%;
  }
  /* padding 撑高后，内容需要绝对定位，否则会被挤出 */
  .wheel-frame > * {
    position: absolute;
    inset: 0;
  }
}
/* 画布定位说明：
   显示尺寸完全交给 CSS（inset:0 + 撑满容器），
   JS 只设置 canvas.width/height 位图分辨率。
   若 JS 写内联 style.width，会与下面的 width:100% 冲突导致溢出偏移。 */
.wheel-frame canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: block;
  will-change: transform;
  transform: rotate(0deg);
}

/* 顶部鎏金指针 */
.wheel-pointer {
  position: absolute;
  top: 8px; left: 50%;
  margin-left: -9px;
  z-index: 12;
  width: 0; height: 0;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-top: 20px solid var(--ink);
  filter: drop-shadow(0 2px 4px rgb(28 43 40 / .3));
}

.spin-btn {
  position: relative;
  z-index: 14;
  width: 25%;
  aspect-ratio: 1 / 1;
  max-width: 132px;
  border: 1px solid var(--gold);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #FDFCF7, var(--paper));
  color: var(--ink);
  font-family: "Songti SC", "SimSun", serif;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 3px;
  margin-left: 3px;
  box-shadow: var(--shadow), inset 0 1px 0 rgb(255 255 255 / .8);
  transition: transform .2s var(--ease), box-shadow .2s var(--ease), opacity .2s;
}
.spin-btn:hover:not(:disabled) {
  transform: scale(1.04);
  box-shadow: 0 6px 22px rgb(28 43 40 / .18), inset 0 1px 0 rgb(255 255 255 / .8);
}
.spin-btn:disabled { cursor: not-allowed; }
.spin-btn.is-spinning { opacity: .75; }
.spin-btn.is-spinning .spin-btn-label { font-size: 14px; letter-spacing: 1px; }

.btn-link {
  background: none;
  border: 1px solid var(--paper-deep);
  border-radius: 999px;
  padding: 7px 18px;
  font-size: 13px;
  color: var(--ink-mute);
  letter-spacing: 1px;
  transition: all .2s var(--ease);
}
.btn-link:hover { border-color: var(--zhuang); color: var(--zhuang); }

/* ==================================================================
   侧栏
   ================================================================== */
.side { display: flex; flex-direction: column; gap: 18px; }

.search-card, .stat-card {
  background: var(--paper-warm);
  border: 1px solid var(--paper-deep);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

/* 字符格 */
.cell {
  flex: 1;
  min-width: 0;
  aspect-ratio: 1 / 1;
  max-width: 42px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  font-family: "Songti SC", "SimSun", serif;
  font-size: 15px;
  font-weight: 700;
  color: #FFFDF7;
  animation: cell-in .3s var(--ease) backwards;
}
.cell-xian { background: var(--xian); }
.cell-zhuang { background: var(--zhuang); }

@keyframes cell-in {
  from { opacity: 0; transform: translateY(-5px) scale(.92); }
  to { opacity: 1; transform: none; }
}

/* ==================================================================
   搜索
   ================================================================== */
.search-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.search-head h2 {
  font-family: "Songti SC", "SimSun", serif;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 2px;
}
.search-hint { font-size: 11px; color: var(--ink-mute); }

.search-box { position: relative; margin-bottom: 10px; }
.search-box input {
  width: 100%;
  padding: 11px 34px 11px 14px;
  border: 1px solid var(--paper-deep);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  letter-spacing: 2px;
  transition: border-color .2s var(--ease), background-color .2s var(--ease);
}
.search-box input::placeholder { color: #A9B3AF; letter-spacing: 1px; }
.search-box input:focus {
  outline: none;
  border-color: var(--xian);
  background: #fff;
}
.search-box input::-webkit-search-cancel-button { display: none; }

.search-clear {
  position: absolute;
  right: 8px; top: 50%;
  transform: translateY(-50%);
  width: 22px; height: 22px;
  border: 0;
  border-radius: 50%;
  background: var(--paper-deep);
  color: var(--ink-mute);
  font-size: 15px;
  line-height: 1;
  display: grid;
  place-items: center;
}
.search-clear:hover { background: var(--zhuang); color: #fff; }

.search-stat {
  font-size: 12px;
  color: var(--ink-mute);
  letter-spacing: .5px;
  margin-bottom: 8px;
  min-height: 18px;
}

/* 重新打乱按钮 */
.search-reshuffle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 10px;
  padding: 5px 12px;
  border: 1px solid var(--paper-deep);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink-mute);
  font-size: 12px;
  letter-spacing: 1px;
  transition: all .2s var(--ease);
}
.search-reshuffle:hover {
  border-color: var(--xian);
  color: var(--xian);
  background: var(--xian-pale);
}
.search-reshuffle:active { transform: scale(.96); }
.search-reshuffle .icon { width: 13px; height: 13px; }
.search-reshuffle[hidden] { display: none; }

.search-results {
  max-height: 268px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scrollbar-width: thin;
}
.search-results::-webkit-scrollbar { width: 6px; }
.search-results::-webkit-scrollbar-thumb { background: var(--paper-deep); border-radius: 3px; }

.no-hit {
  font-size: 13px;
  color: var(--ink-mute);
  text-align: center;
  padding: 18px 0;
}
.more-note {
  font-size: 11px;
  color: var(--ink-mute);
  text-align: center;
  padding: 8px 0 2px;
}

.hit {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--paper);
  transition: background-color .15s var(--ease);
}
.hit:hover { background: var(--xian-pale); }
.hit.is-used { opacity: .5; }

.hit-cells { display: flex; gap: 2px; flex: 1; min-width: 0; }
.hit-cells .cell {
  max-width: none;
  width: 100%;
  aspect-ratio: 1 / 1;
  font-size: 9px;
  border-radius: 2px;
  animation: none;
  /* 已抽中的格子整体降饱和 */
}
.hit.is-used .cell { filter: grayscale(1); }
.cell.is-hit {
  box-shadow: 0 0 0 1.5px var(--gold), 0 0 6px rgb(200 169 106 / .7);
  border-radius: 3px;
}
.hit-tag {
  font-size: 10px;
  color: var(--ink-mute);
  border: 1px solid var(--paper-deep);
  border-radius: 3px;
  padding: 1px 5px;
  flex: none;
  letter-spacing: .5px;
}
.hit.is-used .hit-tag { color: var(--used-dark); border-color: var(--used); }

/* ==================================================================
   统计
   ================================================================== */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin-bottom: 16px; }
.stat {
  background: var(--paper);
  border-radius: 6px;
  padding: 12px 6px;
  text-align: center;
}
.stat strong {
  display: block;
  font-family: "Songti SC", "SimSun", serif;
  font-size: 21px;
  color: var(--xian);
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}
.stat span { font-size: 11px; color: var(--ink-mute); letter-spacing: 1px; }

.balance-bar {
  display: flex;
  height: 26px;
  border-radius: 5px;
  overflow: hidden;
  font-size: 11px;
  margin-bottom: 10px;
}
.balance-bar span {
  display: grid;
  place-items: center;
  color: #FFFDF7;
  letter-spacing: .5px;
  transition: width .4s var(--ease);
  white-space: nowrap;
  overflow: hidden;
}
.bb-xian { background: var(--xian); }
.bb-zhuang { background: var(--zhuang); }

.stat-note { font-size: 11px; color: var(--ink-mute); letter-spacing: .5px; }

/* ==================================================================
   ES Module 加载失败提示
   ================================================================== */
.module-hint {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 100;
  width: min(420px, calc(100vw - 40px));
  background: #FDF6E8;
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  color: var(--ink);
}
.module-hint p { margin: 0 0 6px; }
.module-hint p:last-child { margin-bottom: 0; }
.module-hint strong {
  display: block;
  font-family: "Songti SC", "SimSun", serif;
  font-size: 15px;
  margin-bottom: 8px;
  color: var(--zhuang-dark);
}
.module-hint a {
  color: var(--xian);
  font-weight: 700;
  text-decoration: underline;
}

/* ==================================================================
   结果展示区（页面顶部，原大标题位置）
   ------------------------------------------------------------------
   独立 DOM，不随 canvas 旋转。
   位于转盘**上方**，是页面的第一视觉焦点：
     标签「本次抽中」+ 10 格字符条 + 行号/次数
   ================================================================== */
.stage-head {
  text-align: center;
  margin-bottom: 34px;
  min-height: 116px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.stage-head-label {
  font-family: "Songti SC", "SimSun", serif;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 6px;
  margin-left: 6px;
  color: var(--ink-mute);
}
.stage-head-label::after {
  content: '';
  display: block;
  width: 28px; height: 1px;
  background: var(--gold);
  margin: 8px auto 0;
}
.stage-head-meta {
  font-size: 12px;
  color: var(--ink-mute);
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
  min-height: 17px;
}

/* ---------- 10 格字符条 ---------- */
.center-strip {
  display: flex;
  gap: 5px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s var(--ease);
}
.center-strip.is-visible {
  opacity: 1;
  visibility: visible;
}

.cs-cell {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 5px;
  border: 1px solid;
  display: grid;
  place-items: center;
  font-family: "Songti SC", "SimSun", serif;
  font-size: 17px;
  font-weight: 700;
  color: #FFFDF7;
  line-height: 1;
  animation: cs-in .26s var(--ease) backwards;
}
@keyframes cs-in {
  from { opacity: 0; transform: translateY(-5px) scale(.86); }
  to { opacity: 1; transform: none; }
}

/* 转动时不显示结果 */
#result-head.is-spinning .center-strip {
  opacity: 0 !important;
  visibility: hidden;
}

.icon-btn {
  background: none;
  border: 0;
  padding: 6px;
  color: var(--ink-mute);
  border-radius: 6px;
  display: inline-flex;
  transition: background-color .2s var(--ease), color .2s var(--ease);
}
.icon-btn:hover { background: var(--paper-deep); color: var(--ink); }

/* ==================================================================
   历史记录按钮（顶栏）
   ================================================================== */
.history-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--paper-deep);
  border-radius: 999px;
  background: var(--paper-warm);
  color: var(--ink-mute);
  font-size: 12px;
  letter-spacing: 1px;
  transition: all .2s var(--ease);
  white-space: nowrap;
}
.history-btn:hover {
  border-color: var(--xian);
  color: var(--xian);
}
.history-btn .icon { width: 15px; height: 15px; }
.history-badge {
  min-width: 16px;
  padding: 0 4px;
  height: 16px;
  border-radius: 8px;
  background: var(--xian);
  color: #FFFDF7;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.history-badge:empty { display: none; }

/* ==================================================================
   历史记录抽屉
   ================================================================== */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgb(28 43 40 / .5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  justify-content: flex-end;
  opacity: 0;
  visibility: hidden;
  transition: opacity .28s var(--ease), visibility .28s;
}
.drawer.is-open { opacity: 1; visibility: visible; }

.drawer-box {
  width: min(420px, 100%);
  height: 100%;
  background: var(--paper-warm);
  border-left: 1px solid var(--gold);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .32s var(--ease);
  box-shadow: -12px 0 40px rgb(28 43 40 / .18);
}
.drawer.is-open .drawer-box { transform: translateX(0); }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 22px;
  border-bottom: 1px solid var(--paper-deep);
  flex: none;
}
.drawer-head h2 {
  font-family: "Songti SC", "SimSun", serif;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 3px;
}

/* 关闭按钮：带文字，比纯图标更易识别 */
.drawer-close {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--paper-deep);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink-mute);
  font-size: 13px;
  letter-spacing: 1px;
  transition: all .2s var(--ease);
}
.drawer-close:hover {
  background: var(--zhuang-pale, #F5E7E0);
  border-color: var(--zhuang);
  color: var(--zhuang);
}
.drawer-close .icon { width: 15px; height: 15px; }

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px 28px;
  scrollbar-width: thin;
}
.drawer-body::-webkit-scrollbar { width: 7px; }
.drawer-body::-webkit-scrollbar-thumb { background: var(--paper-deep); border-radius: 4px; }

.history-empty {
  text-align: center;
  color: var(--ink-mute);
  font-size: 13px;
  padding: 60px 0;
  line-height: 2;
}
.history-empty span { font-size: 12px; opacity: .7; }

.history-summary {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 11px;
  color: var(--ink-mute);
  letter-spacing: .5px;
  padding: 10px 12px;
  background: var(--paper);
  border-radius: 6px;
  margin-bottom: 14px;
}

.history-list { display: flex; flex-direction: column; gap: 6px; }

.history-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 7px;
  background: var(--paper);
  animation: hist-in .28s var(--ease) backwards;
}
@keyframes hist-in {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: none; }
}

.h-seq {
  font-size: 11px;
  color: var(--gold-dark);
  font-variant-numeric: tabular-nums;
  min-width: 26px;
  flex: none;
  font-weight: 700;
}
.h-cells { display: flex; gap: 2px; flex: 1; min-width: 0; }
.h-cells .cell {
  max-width: none;
  width: 100%;
  aspect-ratio: 1 / 1;
  font-size: 9px;
  border-radius: 2px;
  animation: none;
}
.h-no, .h-time {
  font-size: 10px;
  color: var(--ink-mute);
  flex: none;
  font-variant-numeric: tabular-nums;
}
.h-no { min-width: 44px; text-align: right; }
.h-time { min-width: 46px; text-align: right; }

/* ==================================================================
   Toast
   ================================================================== */
.toast {
  position: fixed;
  left: 50%; bottom: 30px;
  z-index: 90;
  transform: translate(-50%, 14px);
  background: var(--ink);
  color: var(--paper-warm);
  padding: 11px 22px;
  border-radius: 999px;
  font-size: 13px;
  letter-spacing: 1px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s var(--ease), transform .25s var(--ease);
  box-shadow: var(--shadow-lg);
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

/* ==================================================================
   响应式
   ================================================================== */
@media (min-width: 900px) {
  .wheel-layout { grid-template-columns: 1.05fr .95fr; }
  .side { position: sticky; top: calc(var(--header-h) + 20px); }
}

@media (max-width: 640px) {
  .topbar-inner { padding: 0 16px; }
  .brand-text { display: none; }        /* 小屏只留印章 */
  .progress-track { width: 70px; }
  .history-btn span:not(.history-badge) { display: none; }
  .history-btn { padding: 7px 9px; }
  .stage-inner { padding: 0 16px; }
  .stage { padding-top: calc(var(--header-h) + 30px); }
  .stage-head { margin-bottom: 26px; min-height: 96px; }
  .cs-cell { width: 27px; height: 27px; font-size: 13px; border-radius: 4px; }
  .center-strip { gap: 3px; }
  .hit-cells .cell { font-size: 8px; }
  .drawer-box { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
