[hidden] { display: none !important; }
:root {
  --bg: #f6f1e7; --surface: #fffdf8; --surface-2: #efe7d8; --ink: #2d2620; --muted: #8a7d6e; --line: #e4d9c6;
  --accent: #b5583a; --accent-ink: #fff; --gold: #b8913a;
  --hit: #4f8a5b; --hit-bg: #e3efe3; --miss: #b5483a; --miss-bg: #f6e1dc; --wait: #a37a1c; --wait-bg: #f5ebd2;
  --tile: #fbf6ec; --tile-line: #d9c9ad;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 16px rgba(60, 40, 20, .06);
  --serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", "Noto Serif CJK SC", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #1a1714; --surface: #24201c; --surface-2: #2e2924; --ink: #ece4d8; --muted: #a0948a; --line: #3a332c;
  --accent: #d9774f; --accent-ink: #1a1714; --gold: #d6b264;
  --hit: #8cc79a; --hit-bg: #23352a; --miss: #ec8b78; --miss-bg: #3d2520; --wait: #e2bf63; --wait-bg: #3a3020;
  --tile: #2b2621; --tile-line: #4a4036;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-family: var(--sans); font-size: 16px; line-height: 1.6; min-height: 100vh; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; margin: 0; letter-spacing: .02em; }

.wrap { max-width: 720px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 96px); }

/* 顶栏 */
.topbar { display: flex; align-items: center; gap: 8px; padding: 8px 0 16px; }
.topbar h1 { font-size: 24px; flex: 1; }
.topbar .sub { display: block; font-family: var(--sans); font-size: 12px; font-weight: 400; color: var(--muted); letter-spacing: .1em; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); display: inline-grid; place-items: center; font-size: 18px; flex: none; }
.back { border: 0; background: none; font-size: 15px; color: var(--muted); padding: 8px 0; }

/* 按钮 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--miss); }
.btn.block { width: 100%; }
.btn.sm { height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.fab { position: fixed; right: max(16px, calc(50vw - 344px)); bottom: calc(env(safe-area-inset-bottom) + 20px); height: 52px; padding: 0 22px; border-radius: 26px; box-shadow: 0 6px 20px rgba(181, 88, 58, .35); z-index: 5; font-size: 16px; }

/* 卡片 */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; box-shadow: var(--shadow); }
.stack > * + * { margin-top: 12px; }

/* 统计 */
.stats { display: grid; grid-template-columns: 1.3fr 1fr 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.stat b { display: block; font-family: var(--serif); font-size: 24px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.main b { color: var(--accent); }

/* 筛选 */
.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 34px; padding: 0 14px; border-radius: 17px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; white-space: nowrap; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.search { width: 100%; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); padding: 0 14px; margin-bottom: 14px; }
.select-inline { height: 34px; border-radius: 17px; border: 1px solid var(--line); background: var(--surface); padding: 0 10px; font-size: 14px; flex: none; }

/* 列表 */
.rec { display: block; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; box-shadow: var(--shadow); }
.rec + .rec { margin-top: 10px; }
.rec-meta { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.rec-meta .sp { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-q { font-family: var(--serif); font-size: 17px; font-weight: 600; margin: 6px 0 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rec-cards { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 11px; font-size: 12px; font-weight: 600; flex: none; }
.badge.sys { background: var(--surface-2); color: var(--ink); }
.badge.hit { background: var(--hit-bg); color: var(--hit); }
.badge.miss { background: var(--miss-bg); color: var(--miss); }
.badge.pending { background: var(--wait-bg); color: var(--wait); }
.empty { text-align: center; color: var(--muted); padding: 56px 16px; font-family: var(--serif); }
.empty .moon { font-size: 40px; display: block; margin-bottom: 8px; }

/* 表单 */
.field { display: block; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; letter-spacing: .04em; }
.input, .textarea, .select { width: 100%; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); padding: 10px 12px; outline: none; }
.input, .select { height: 46px; }
.textarea { min-height: 96px; resize: vertical; line-height: 1.6; }
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { height: 38px; border: 0; border-radius: 9px; background: transparent; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg.status button.on[data-v="hit"] { color: var(--hit); }
.seg.status button.on[data-v="miss"] { color: var(--miss); }
.seg.status button.on[data-v="pending"] { color: var(--wait); }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.section-title { display: flex; align-items: center; justify-content: space-between; font-family: var(--serif); font-size: 18px; margin: 24px 0 10px; }
.section-title small { font-family: var(--sans); font-size: 13px; color: var(--muted); font-weight: 400; }

/* 牌面 */
.spread { display: grid; gap: 8px; }
.slot { display: flex; flex-direction: column; align-items: stretch; gap: 4px; min-width: 0; }
.slot-label { font-size: 12px; line-height: 1.3; color: var(--muted); text-align: center; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-all; }
.slot-label input { width: 100%; border: 0; border-bottom: 1px dashed var(--line); background: transparent; text-align: center; font-size: 12px; color: var(--muted); padding: 0; }
.tile { position: relative; aspect-ratio: 3 / 5; max-width: 100%; border-radius: 10px; border: 1px solid var(--tile-line); background: var(--tile); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 6px 4px; text-align: center; overflow: hidden; }
.tile::before { content: ""; position: absolute; inset: 4px; border: 1px solid var(--tile-line); border-radius: 7px; pointer-events: none; opacity: .7; }
.tile .num { font-family: var(--serif); font-size: 11px; color: var(--gold); letter-spacing: .05em; }
.tile .nm { font-family: var(--serif); font-weight: 700; font-size: 15px; line-height: 1.25; word-break: break-all; }
.tile .rv { position: absolute; bottom: 6px; font-size: 11px; color: var(--miss); font-weight: 600; }
.tile.blank { border-style: dashed; background: transparent; color: var(--muted); font-size: 13px; }
.tile.blank::before { display: none; }
button.tile { cursor: pointer; }
.tile.pic { padding: 0; background: var(--surface-2); justify-content: flex-end; }
.tile.pic::before { display: none; }
.tile.pic img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; -webkit-user-select: none; user-select: none; }
.tile.pic.rev img { transform: rotate(180deg); }
.tile.pic .cap { position: relative; z-index: 1; width: 100%; padding: 3px 2px; background: var(--surface); background: color-mix(in srgb, var(--surface) 92%, transparent); font-family: var(--serif); font-weight: 700; font-size: 12px; line-height: 1.3; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.pic .cap b { color: var(--miss); margin-left: 2px; }
.pick-grid .tile.pic .cap { font-size: 11px; }
.spread.dense .tile.pic .cap { font-size: 10px; }
.spread.dense .tile .nm { font-size: 12px; }
.spread.dense .tile .num { font-size: 10px; }
.slot-x { border: 0; background: none; color: var(--muted); font-size: 12px; padding: 0; }

/* 照片 */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.photo { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); border: 0; padding: 0; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .del { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 12px; border: 0; background: rgba(0, 0, 0, .55); color: #fff; font-size: 14px; line-height: 24px; padding: 0; }
.photo.add { border: 1px dashed var(--line); background: transparent; color: var(--muted); display: grid; place-items: center; font-size: 13px; }

/* 详情 */
.detail-q { font-family: var(--serif); font-size: 22px; line-height: 1.4; margin: 6px 0 4px; }
.prose { white-space: pre-wrap; word-break: break-word; }
.muted { color: var(--muted); }
.label { font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: .04em; margin-bottom: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 20px; }
.actions .btn { flex: 1; min-width: 120px; }

/* 登录 */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login .card { width: 100%; max-width: 380px; padding: 28px 22px; }
.login .mark { width: 64px; height: 64px; border-radius: 18px; display: block; margin: 0 auto 12px; }
.login h1 { text-align: center; font-size: 26px; }
.login p.lead { text-align: center; color: var(--muted); font-size: 14px; margin: 6px 0 22px; }
.tip { font-size: 13px; color: var(--muted); background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.err { color: var(--miss); font-size: 14px; min-height: 1.4em; }

/* 弹窗 */
.mask { position: fixed; inset: 0; background: rgba(20, 14, 8, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease; }
.sheet { background: var(--bg); width: 100%; max-width: 640px; max-height: 88vh; border-radius: 20px 20px 0 0; display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom); animation: up .2s ease; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.sheet-head h3 { flex: 1; font-size: 18px; }
.sheet-body { overflow-y: auto; padding: 14px 16px 20px; -webkit-overflow-scrolling: touch; }
@media (min-width: 700px) { .mask { align-items: center; } .sheet { border-radius: 20px; } }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; }
.pick-grid .tile.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.menu-list button { display: flex; width: 100%; align-items: center; gap: 12px; text-align: left; height: 52px; border: 0; border-bottom: 1px solid var(--line); background: none; font-size: 16px; padding: 0 4px; }
.menu-list button:last-child { border-bottom: 0; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { display: flex; flex-direction: column; align-items: center; gap: 4px; border: 0; background: none; font-size: 12px; color: var(--muted); padding: 0; }
.swatch i { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--line); display: block; }
.swatch.on i { border-color: var(--accent); box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }
.share-img { width: 100%; border-radius: 12px; display: block; box-shadow: var(--shadow); -webkit-touch-callout: default; }
.viewer { position: fixed; inset: 0; background: rgba(0, 0, 0, .9); z-index: 60; display: grid; place-items: center; padding: 16px; }
.viewer img { max-width: 100%; max-height: 100%; border-radius: 8px; }

#toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 90px); transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 22px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 80; max-width: 86vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.offline { background: var(--wait-bg); color: var(--wait); font-size: 13px; padding: 8px 12px; border-radius: 10px; margin-bottom: 12px; }
.install { display: flex; gap: 10px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; margin-bottom: 14px; font-size: 13px; }
.install span { flex: 1; }

#print { display: none; }
@media print {
  #app, #modal-root, #toast { display: none !important; }
  #print { display: block; color: #000; font-size: 12pt; }
  #print .p-rec { page-break-inside: avoid; border-bottom: 1px solid #999; padding: 10pt 0; }
  #print h2 { font-size: 16pt; margin-bottom: 8pt; }
  #print .p-meta { color: #555; font-size: 10pt; }
  #print .p-q { font-weight: 700; font-size: 13pt; margin: 4pt 0; }
  #print .p-sec { margin-top: 4pt; white-space: pre-wrap; }
  #print .p-sec b { color: #333; }
}

/* 牌阵形状 / 选牌阵 / 占星骰子 */
.spread.shaped { row-gap: 10px; }
.spread-btn { text-align: left; display: flex; align-items: center; justify-content: space-between; gap: 6px; cursor: pointer; overflow: hidden; white-space: nowrap; }
.spread-btn small { color: var(--muted); font-size: 12px; flex: none; }
.spread-btn::after { content: "▾"; color: var(--muted); flex: none; }
.sp-desc { font-size: 13px; margin: -4px 0 10px; }
.sp-desc:empty { display: none; }
.sp-list { display: grid; gap: 8px; }
.sp-item { display: flex; gap: 12px; align-items: center; text-align: left; width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 10px 12px; }
.sp-item.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.sp-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.sp-text b { font-family: var(--serif); font-size: 16px; }
.sp-text small { color: var(--accent); font-size: 12px; font-weight: 600; }
.sp-text span { color: var(--muted); font-size: 13px; line-height: 1.5; }
.mini { flex: none; width: 64px; height: 64px; display: grid; gap: 2px; place-content: center; background: var(--surface-2); border-radius: 10px; padding: 4px; }
.mini i { display: block; background: var(--gold); border-radius: 2px; opacity: .85; }
.mini.free { place-items: center; font-size: 12px; color: var(--muted); }
.penta-tip { margin-top: 10px; line-height: 1.8; }
.penta-tip small { color: var(--muted); }
.tile.die .num { font-family: var(--sans); }
.tile.die.sym .num { font-family: "Segoe UI Symbol", "Apple Symbols", "Noto Sans Symbols", "Noto Sans Symbols 2", var(--sans); font-size: 30px; line-height: 1.15; color: var(--gold); margin-bottom: 4px; }
.spread.dense .tile.die.sym .num { font-size: 22px; }
.pick-grid .tile.die.sym .num { font-size: 24px; }
.section-title .btn.sm { font-family: var(--sans); }

.sys-rates { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); margin: -4px 0 12px; }
.sys-rates b { color: var(--ink); font-weight: 600; margin-right: 2px; }
.sys-rates small { font-size: 12px; }
.row > .field[hidden] { display: none !important; }
