/* ============ 设计令牌 ============ */
:root {
  --bg: #fff6f1;
  --bg-grad:
    radial-gradient(900px 600px at -10% -10%, rgba(255, 140, 170, 0.28), transparent 60%),
    radial-gradient(800px 560px at 110% 0%, rgba(255, 190, 110, 0.26), transparent 58%),
    radial-gradient(800px 600px at 50% 120%, rgba(160, 150, 255, 0.24), transparent 60%);
  --surface: rgba(255, 255, 255, 0.8);
  --surface-solid: #ffffff;
  --surface-2: rgba(255, 240, 236, 0.9);
  --glass: rgba(255, 250, 247, 0.72);
  --text: #2b1f24;
  --text-2: #5c4a51;
  --muted: #998890;
  --border: rgba(120, 40, 60, 0.09);
  --accent: #ff6b8b;
  --accent-2: #ff9f5a;
  --rim: linear-gradient(145deg, #ffffff, #ffe3e8);
  --shadow: 0 1px 2px rgba(90, 30, 40, 0.04), 0 12px 32px -14px rgba(160, 60, 80, 0.22);
  --shadow-lg: 0 2px 4px rgba(90, 30, 40, 0.05), 0 30px 60px -22px rgba(180, 60, 90, 0.38);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Inter, Roboto, sans-serif;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #130f1a;
  --bg-grad:
    radial-gradient(900px 600px at -10% -10%, rgba(255, 107, 139, 0.16), transparent 60%),
    radial-gradient(800px 560px at 110% 0%, rgba(255, 159, 90, 0.12), transparent 58%),
    radial-gradient(800px 600px at 50% 120%, rgba(140, 120, 255, 0.16), transparent 60%);
  --surface: rgba(30, 24, 40, 0.8);
  --surface-solid: #1d1726;
  --surface-2: rgba(42, 34, 54, 0.9);
  --glass: rgba(19, 15, 26, 0.72);
  --text: #f1e9ef;
  --text-2: #c7b8c2;
  --muted: #94859a;
  --border: rgba(255, 255, 255, 0.07);
  --accent: #ff7f9c;
  --accent-2: #ffb070;
  --rim: linear-gradient(145deg, #2f2640, #1a1522);
  --shadow: 0 0 0 1px rgba(255, 255, 255, 0.02), 0 12px 30px -12px rgba(0, 0, 0, 0.7);
  --shadow-lg: 0 0 0 1px rgba(255, 255, 255, 0.03), 0 30px 60px -20px rgba(0, 0, 0, 0.85);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; font-family: var(--font); font-size: 15px; line-height: 1.55; color: var(--text);
  background: var(--bg-grad), var(--bg); background-attachment: fixed;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 20; height: calc(60px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  display: flex; align-items: center; gap: 6px;
  background: var(--glass); backdrop-filter: saturate(1.6) blur(18px); -webkit-backdrop-filter: saturate(1.6) blur(18px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 17px; margin-right: auto; }
.brand img { border-radius: 9px; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; color: var(--text-2); transition: background 0.2s, transform 0.15s; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(0.92); }
#themeBtn .moon { display: none; }
[data-theme="dark"] #themeBtn .sun { display: none; }
[data-theme="dark"] #themeBtn .moon { display: block; }

/* 布局 */
.layout {
  max-width: 1080px; margin: 0 auto; display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 28px; align-items: start;
  padding: 24px max(16px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.stage { position: sticky; top: 84px; display: flex; flex-direction: column; align-items: center; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; gap: 18px; padding-top: 14px; } .stage { position: static; } }

.title-in {
  width: 100%; max-width: 440px; text-align: center; font-size: 26px; font-weight: 800; letter-spacing: 0.02em;
  background: transparent; border: 0; border-bottom: 2px dashed transparent; padding: 4px 8px; border-radius: 0; transition: border-color 0.2s;
}
.title-in:hover { border-bottom-color: var(--border); }
.title-in:focus { outline: none; border-bottom-color: var(--accent); }
.title-in::placeholder { color: var(--muted); }

/* 转盘 */
.wheel-wrap { position: relative; width: min(84vw, 440px); aspect-ratio: 1; margin: 34px auto 22px; }
.wheel-wrap::before {
  content: ""; position: absolute; inset: -18px; border-radius: 50%; pointer-events: none;
  background: conic-gradient(from 0deg, #ff8a8a, #ffb36b, #ffd966, #9be38f, #6fbcff, #c493ff, #ff94cc, #ff8a8a);
  filter: blur(26px); opacity: 0.38;
}
.rim { position: absolute; inset: -12px; border-radius: 50%; background: var(--rim); box-shadow: var(--shadow-lg), inset 0 2px 6px rgba(255, 255, 255, 0.6); }
#wheel { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 50%; will-change: transform; }
.pointer { position: absolute; left: 50%; top: -30px; width: 44px; height: 56px; transform: translateX(-50%); transform-origin: 50% 30%; z-index: 3; filter: drop-shadow(0 6px 8px rgba(120, 30, 50, 0.3)); }
.hub {
  position: absolute; left: 50%; top: 50%; width: 23%; aspect-ratio: 1; transform: translate(-50%, -50%); z-index: 2; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffffff, #ffe6ec 70%);
  box-shadow: 0 10px 22px -6px rgba(120, 30, 50, 0.45), inset 0 -5px 12px rgba(255, 107, 139, 0.25), 0 0 0 5px rgba(255, 255, 255, 0.65);
  font-weight: 900; font-size: clamp(17px, 5vw, 26px); letter-spacing: 0.04em; color: var(--accent); transition: transform 0.15s var(--ease);
}
.hub:not(:disabled) { animation: pulse 2.4s ease-in-out infinite; }
.hub:active { transform: translate(-50%, -50%) scale(0.93); }
.hub:disabled { opacity: 1; color: var(--muted); }
@keyframes pulse { 50% { box-shadow: 0 10px 22px -6px rgba(120, 30, 50, 0.45), inset 0 -5px 12px rgba(255, 107, 139, 0.25), 0 0 0 10px rgba(255, 107, 139, 0.18); } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 44px; padding: 0 18px; border-radius: 13px; font-weight: 650; background: var(--surface-2); transition: transform 0.15s var(--ease), filter 0.2s; white-space: nowrap; }
.btn:not(:disabled):active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 10px 22px -10px var(--accent); }
.btn.ghost { background: transparent; border: 1px solid var(--border); }
.btn.danger { background: rgba(255, 90, 110, 0.12); color: #f0506e; }
.btn.sm { height: 34px; padding: 0 12px; font-size: 13.5px; border-radius: 10px; }
.btn.big { height: 56px; min-width: min(320px, 80vw); border-radius: 999px; font-size: 18px; font-weight: 800; letter-spacing: 0.04em; }
.last { min-height: 24px; margin: 12px 0 0; color: var(--muted); font-size: 14px; text-align: center; }
.last b { color: var(--text); }

/* 面板 */
.side { display: grid; gap: 14px; }
.panel { margin: 0; min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 24px; padding: 18px; box-shadow: var(--shadow); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
fieldset.panel:disabled { opacity: 0.6; }
.panel h2 { margin: 0; font-size: 16px; font-weight: 750; display: flex; align-items: baseline; gap: 6px; }
.panel > h2 { margin-bottom: 8px; }
.p-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.p-head h2 { margin-right: auto; }
.count { font-size: 13px; font-weight: 500; color: var(--muted); }
.add { display: flex; gap: 8px; }
.input { flex: 1; min-width: 0; height: 46px; padding: 0 14px; border-radius: 13px; background: var(--surface-2); border: 1.5px solid transparent; font-size: 16px; }
.input:focus { outline: none; border-color: var(--accent); background: var(--surface-solid); }
.tip { margin: 8px 2px 10px; font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.tip b { color: var(--text-2); }
.list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; max-height: 340px; overflow-y: auto; overscroll-behavior: contain; }
@media (max-width: 860px) { .list { max-height: none; } }
.list li { display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 12px; border-radius: 12px; background: var(--surface-2); animation: pop 0.25s var(--ease); }
@keyframes pop { from { opacity: 0; transform: scale(0.94); } }
.list li.empty { grid-column: 1 / -1; justify-content: center; padding: 20px 12px; color: var(--muted); font-size: 14px; background: transparent; border: 1.5px dashed var(--border); text-align: center; }
.dot { width: 12px; height: 12px; border-radius: 4px; flex: none; }
.item-in { flex: 1; min-width: 0; height: 34px; border: 0; background: transparent; font-size: 15px; font-weight: 600; padding: 0; }
.item-in:focus { outline: none; }
.del { width: 30px; height: 30px; border-radius: 9px; color: var(--muted); font-size: 18px; line-height: 1; flex: none; }
.del:hover { background: var(--surface-solid); color: #f0506e; }
.presets-head { margin: 14px 2px 8px; font-size: 13px; font-weight: 650; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 6px 12px; border-radius: 99px; font-size: 13.5px; font-weight: 600; background: var(--surface-2); color: var(--text-2); border: 1.5px solid transparent; transition: all 0.15s; }
.chip:hover { border-color: var(--accent); }

.hist { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.hist li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 12px; background: var(--surface-2); font-size: 14px; }
.hist li b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist li span { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tally { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tally span { font-size: 12.5px; padding: 3px 10px; border-radius: 99px; background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); font-weight: 650; }
.small { font-size: 13.5px; margin: 0; }

.set-row { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.set-row:last-child { border-bottom: 0; padding-bottom: 0; }
.set-row .lbl { flex: 1; min-width: 150px; }
.set-row .lbl b { display: block; font-weight: 650; }
.set-row .lbl span { font-size: 12.5px; color: var(--muted); }
.switch { position: relative; width: 50px; height: 30px; border-radius: 99px; background: rgba(120, 100, 110, 0.25); transition: background 0.25s; flex: none; }
.switch::after { content: ""; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 0.25s var(--ease); }
.switch[aria-checked="true"] { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }
.seg { display: inline-flex; padding: 4px; border-radius: 12px; background: var(--surface-2); gap: 2px; }
.seg button { padding: 6px 12px; border-radius: 9px; font-size: 13.5px; font-weight: 600; color: var(--text-2); }
.seg button[aria-pressed="true"] { background: var(--surface-solid); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
.foot { text-align: center; font-size: 12.5px; color: var(--muted); margin: 4px 0 0; }

/* 结果弹窗 */
.modal-bg { position: fixed; inset: 0; z-index: 40; background: rgba(30, 10, 20, 0.45); backdrop-filter: blur(4px); animation: fade 0.25s; }
@keyframes fade { from { opacity: 0; } }
.modal {
  position: fixed; z-index: 41; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(420px, calc(100vw - 32px));
  background: var(--surface-solid); border-radius: 28px; padding: 28px 22px 22px; text-align: center; box-shadow: var(--shadow-lg);
  animation: popIn 0.45s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes popIn { from { opacity: 0; transform: translate(-50%, -46%) scale(0.85); } }
.res-lbl { font-size: 15px; font-weight: 650; color: var(--muted); letter-spacing: 0.06em; }
.res-val {
  margin: 8px 0 4px; font-size: clamp(34px, 11vw, 52px); font-weight: 900; line-height: 1.2; word-break: break-word;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.res-note { min-height: 20px; margin: 0 0 14px; font-size: 13px; color: var(--muted); }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; height: 48px; }
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 45; }

.toast { position: fixed; left: 50%; bottom: calc(26px + env(safe-area-inset-bottom)); z-index: 60; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow-lg); transition: all 0.3s var(--ease); max-width: calc(100vw - 32px); display: flex; gap: 12px; align-items: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { color: var(--accent-2); font-weight: 750; }

@media (max-width: 480px) {
  .title-in { font-size: 22px; }
  .panel { padding: 15px; border-radius: 20px; }
  .list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .p-head .btn.sm { padding: 0 10px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }
