:root {
  color-scheme: dark;
  --ink: #f1eeff; --muted: #b9b2dd; --line: rgba(178, 166, 255, .22);
  --panel: rgba(29, 25, 74, .82); --panel-2: rgba(50, 43, 115, .85);
  --violet: #8d78ff; --blue: #5ea1ff; --gold: #ffd98a; --red: #ff6b81; --danger: #ff9aa8;
  --tabs: calc(58px + env(safe-area-inset-bottom));
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100%; color: var(--ink);
  font: 16px/1.6 system-ui, -apple-system, "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", sans-serif;
  background: #0d0b26 radial-gradient(120% 70% at 75% 0, #3a2477 0, transparent 60%) fixed no-repeat;
}
#sky { position: fixed; inset: 0; width: 100%; height: 100%; z-index: -1; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 19px; letter-spacing: .06em; }
h2 { font-size: 21px; }
h3 { font-size: 16px; }
.muted, .hint { color: var(--muted); }
.hint { font-size: 13px; }
.strong { font-weight: 600; overflow-wrap: anywhere; }
.error { color: var(--danger); font-size: 14px; }
.error:empty, .hint:empty { display: none; }

button, input, textarea { font: inherit; color: inherit; }
button {
  min-height: 42px; padding: 8px 16px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel-2); cursor: pointer; touch-action: manipulation;
}
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.primary { border: 0; background: linear-gradient(120deg, #7a5ff5, #3d7ff0); font-weight: 600; }
.wide { width: 100%; }
.link { border: 0; background: none; color: var(--gold); padding: 8px; }
.chip { min-height: 36px; padding: 4px 13px; border-radius: 99px; font-size: 14px; }
.gold { color: #2a1d00; background: var(--gold); border-color: transparent; font-weight: 600; }
input:not([type=checkbox]), textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: rgba(10, 8, 34, .7);
}
::placeholder { color: #9d95c9; opacity: 1; }
label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
label input, label textarea { font-size: 16px; color: var(--ink); }

.login { min-height: 100dvh; display: grid; align-content: center; gap: 10px; max-width: 360px; margin: auto; padding: 24px; text-align: center; }
.login h1 { font-size: 30px; }
.login form { display: grid; gap: 12px; margin-top: 18px; text-align: left; }

#app { height: 100dvh; max-width: 680px; margin: auto; display: flex; flex-direction: column; padding-bottom: var(--tabs); }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: calc(10px + env(safe-area-inset-top)) 16px 8px; }
.top h1 { white-space: nowrap; }
#model-chip { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.scroll { overflow-y: auto; gap: 14px; padding: 8px 16px 24px; }
.scroll > * { flex-shrink: 0; }

.day-note { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; font-size: 13px; color: var(--muted); padding: 0 16px; }
.messages { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.messages > * { flex-shrink: 0; }
.bubble { max-width: 84%; padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.bubble.user { align-self: flex-end; background: linear-gradient(120deg, #6549dd, #3565ca); border-bottom-right-radius: 6px; }
.bubble.wait { color: var(--muted); }
.sources { align-self: flex-end; max-width: 84%; font-size: 13px; display: grid; gap: 2px; text-align: right; }
.sources a { color: var(--blue); overflow-wrap: anywhere; }
.retry { align-self: flex-end; display: grid; gap: 6px; justify-items: end; max-width: 84%; text-align: right; }
.dock { padding: 8px 12px 10px; display: grid; gap: 8px; background: rgba(13, 11, 38, .82); border-top: 1px solid var(--line); }
.quick { display: flex; flex-wrap: wrap; gap: 8px; }
#act-draw { margin-left: auto; }
.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; min-width: 0; resize: none; max-height: 132px; border-radius: 20px; }
.round { flex: none; width: 44px; height: 46px; padding: 0; border-radius: 50%; }
.round[aria-pressed=true] { background: var(--gold); color: #2a1d00; }

.tabs { position: fixed; inset: auto 0 0; height: var(--tabs); padding-bottom: env(safe-area-inset-bottom); display: flex; justify-content: center; background: #100d2f; border-top: 1px solid var(--line); z-index: 2; }
.tabs button { flex: 1; max-width: 170px; border: 0; border-radius: 0; background: none; color: var(--muted); }
.tabs button[aria-current] { color: var(--gold); font-weight: 600; }

.panel, .card { display: grid; gap: 12px; padding: 16px; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); }
.panel > button { justify-self: start; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.inline-form { display: flex; gap: 8px; }
.inline-form button { flex: none; }
.memory { display: flex; gap: 8px; align-items: center; padding: 4px 0; }
.memory input { flex: 1; min-width: 0; }
.memory button { flex: none; padding: 8px 10px; font-size: 14px; }
.segmented { display: flex; border: 1px solid var(--line); border-radius: 14px; padding: 4px; background: rgba(10, 8, 34, .6); }
.segmented button { flex: 1; border: 0; background: none; color: var(--muted); padding: 6px; }
.segmented button[aria-pressed=true] { background: var(--panel-2); color: var(--ink); font-weight: 600; }
.switch { display: flex; align-items: center; gap: 10px; color: var(--ink); min-height: 42px; }
.switch input { width: 22px; height: 22px; accent-color: var(--violet); }
.meter { height: 8px; border-radius: 9px; background: rgba(10, 8, 34, .7); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--violet), var(--blue)); }
.meter.over i { background: var(--red); }

.card { align-self: stretch; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 10px; }
.card-head span { color: var(--muted); font-size: 13px; }
.sign { color: var(--gold); font-size: 17px; overflow-wrap: anywhere; }
.note { display: grid; gap: 8px; padding-top: 10px; border-top: 1px solid var(--line); }
.note-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; font-size: 14px; color: var(--muted); }
.balls { display: flex; flex-wrap: wrap; gap: 6px; }
.ball {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; color: #fff;
  font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; border: 2px solid transparent;
}
.ball.main { background: radial-gradient(circle at 32% 26%, #ff9fb0, #cf2f52 62%); }
.ball.extra { background: radial-gradient(circle at 32% 26%, #9cc8ff, #2a61c9 62%); }
.dlt .ball.main { background: radial-gradient(circle at 32% 26%, #9cc8ff, #2a61c9 62%); }
.dlt .ball.extra { background: radial-gradient(circle at 32% 26%, #ffe3a1, #a86a08 66%); }
.ball.hit { border-color: #fff; box-shadow: 0 0 0 3px var(--gold); }
.ball.miss { opacity: .45; }
.pop .ball { animation: pop .5s cubic-bezier(.2, 1.5, .4, 1) backwards; }
@keyframes pop { from { opacity: 0; transform: translateY(-26px) scale(.3); } }
details summary { cursor: pointer; min-height: 32px; color: var(--gold); font-size: 14px; }
.why { margin: 4px 0 0; padding: 0; list-style: none; display: grid; gap: 5px; font-size: 14px; }
.why li { display: grid; grid-template-columns: 30px 1fr; gap: 6px; }
.why b { font-variant-numeric: tabular-nums; }
.why em { font-style: normal; color: var(--muted); }
.card .row button { min-height: 38px; padding: 4px 12px; font-size: 14px; }
.card .row button[aria-pressed=true] { color: var(--gold); border-color: var(--gold); }
.note-top label { display: flex; align-items: center; gap: 6px; min-height: 34px; }
.note-top input { width: 19px; height: 19px; accent-color: var(--gold); }
#records, #random-result { display: grid; gap: 14px; }

dialog { width: min(430px, calc(100vw - 32px)); max-height: 86dvh; padding: 20px; border: 1px solid var(--line); border-radius: 22px; color: var(--ink); background: #1a1645; }
dialog[open], dialog form { display: grid; gap: 14px; }
dialog::backdrop { background: rgba(5, 4, 20, .5); }
/* 出号时收起页面，只留夜空，才能看见星星一颗颗亮起来 */
#app { transition: opacity .25s; }
body:has(#draw-dialog[open]) #app { opacity: 0; }
#draw-dialog { background: rgba(26, 22, 69, .5); margin-bottom: 24px; text-align: center; }
#draw-dialog::backdrop { background: none; }
.charge {
  --p: 0; justify-self: center; width: 150px; height: 150px; border: 0; border-radius: 50%; font-weight: 600;
  background: radial-gradient(circle, #32277d 62%, transparent 63%), conic-gradient(var(--gold) calc(var(--p) * 1turn), #51459f 0);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none;
}
.model-list { max-height: 46dvh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.model-list button { flex: none; text-align: left; display: grid; line-height: 1.35; }
.model-list small { color: var(--muted); overflow-wrap: anywhere; }
.model-list button[aria-pressed=true] { border-color: var(--gold); }
#toast {
  position: fixed; left: 50%; top: calc(58px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 9;
  width: max-content; max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 14px;
  background: #f1eeff; color: #1b1540; pointer-events: none;
}
#toast:empty { display: none; }
@media (prefers-reduced-motion: reduce) { .pop .ball { animation: none; } }
.round.off { opacity: .55; }
