/* Base, layout and shared components. Screen-specific styles live in views.css. */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
  overscroll-behavior-y: none;
  scroll-padding-top: calc(var(--safe-top) + 64px);
}

/* No double-tap zoom anywhere (spec §23.1): scrolling, taps and pinch stay. touch-action is not
   inherited but applies along the ancestors, so the root covers cards and blank space alike. */
html, body { touch-action: manipulation; }
/* Child mode (ui/zoom-guard.js): no pinch zoom either. */
html.is-kid-mode, html.is-kid-mode body { touch-action: pan-x pan-y; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
a { color: inherit; -webkit-tap-highlight-color: transparent; }
/* No double-tap-to-zoom wait on anything tappable: taps react at once. */
a, summary, label, input, select, textarea, [role="button"] { touch-action: manipulation; }
img, svg { display: block; }
svg { flex-shrink: 0; }
h1, h2, h3, h4, p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
[hidden] { display: none !important; }

:focus { outline: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.num { font-family: var(--font-rounded); font-variant-numeric: tabular-nums; }

/* ---------- App shell ---------- */

.app { min-height: 100dvh; overflow-x: clip; }

.splash {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, var(--hero-2), var(--hero-1));
}
.splash-mark {
  width: 88px; height: 88px;
  border-radius: 24px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.25);
  animation: splash-breathe 1.6s var(--ease-out) infinite alternate;
}
@keyframes splash-breathe { from { transform: scale(0.96); } to { transform: scale(1.03); } }

.view { min-height: 100dvh; animation: view-in var(--dur-2) var(--ease-out) backwards; } /* no fill afterwards: a filling transform would trap the fixed tab bar */
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.app.has-vt .view { animation: none; }

::view-transition-old(root), ::view-transition-new(root) { animation-duration: 200ms; }
.tabbar { view-transition-name: tabbar; }

/* ---------- Page chrome: sticky top bar + hero ---------- */

.page { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: calc(var(--safe-top) + 56px);
  padding: var(--safe-top) max(calc(var(--gutter) - 4px), var(--safe-right)) 0 max(calc(var(--gutter) - 4px), var(--safe-left));
  background: var(--hero-2);
  color: var(--hero-text);
  box-shadow: 0 1px 0 var(--hero-2); /* hides sub-pixel seams against the hero */
  transition: box-shadow var(--dur-2) var(--ease-out);
}
.page.is-scrolled .topbar { box-shadow: 0 1px 0 var(--hero-line), 0 8px 24px rgba(30, 8, 44, 0.22); }
.topbar-side { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar-side--end { justify-content: flex-end; }
.topbar-title {
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 52vw;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-out);
}
.page.is-scrolled .topbar-title { opacity: 1; transform: none; }

.hero {
  position: relative;
  overflow: hidden;
  overflow: clip; /* clip, unlike hidden, is not scrollable, so focus/scrollIntoView cannot shift it sideways */
  margin-top: -1px;
  padding: 3px var(--gutter) 44px;
  padding-left: max(var(--gutter), var(--safe-left));
  padding-right: max(var(--gutter), var(--safe-right));
  color: var(--hero-text);
  background:
    radial-gradient(120% 90% at 100% 100%, var(--hero-glow) 0%, transparent 55%),
    linear-gradient(180deg, var(--hero-2) 0%, var(--hero-1) 100%);
  border-radius: 0 0 32px 32px;
}
.hero::before,
.hero::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}
.hero::before {
  width: 180px; height: 180px;
  right: -60px; top: -70px;
  background: radial-gradient(circle at 35% 35%, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0) 70%);
}
.hero::after {
  width: 120px; height: 120px;
  left: -40px; bottom: -50px;
  background: radial-gradient(circle at 50% 50%, rgba(255, 107, 90, 0.30), rgba(255, 107, 90, 0) 70%);
}
.hero > * { position: relative; z-index: 1; }
.hero-title { font-size: 32px; line-height: 1.15; font-weight: 800; letter-spacing: 0.01em; }
.hero-sub { margin-top: 6px; font-size: 15px; color: var(--hero-text-2); }

.page-body {
  position: relative;
  z-index: 2;
  flex: 1;
  margin-top: -24px;
  padding: 0 max(var(--gutter), var(--safe-right)) calc(40px + var(--safe-bottom)) max(var(--gutter), var(--safe-left));
}
.page.has-tabbar .page-body { padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 40px); }

/* ---------- Buttons ---------- */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 0 22px;
  border: 0;
  border-radius: var(--r-pill);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
  transition: transform var(--dur-1) var(--ease-out), opacity var(--dur-1), box-shadow var(--dur-2), background-color var(--dur-2);
}
.btn svg { width: 22px; height: 22px; }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-block { display: flex; width: 100%; }
.btn-lg { min-height: 58px; font-size: 18px; border-radius: 20px; }
.btn-sm { min-height: 44px; padding: 0 16px; font-size: 15px; }
.btn-sm svg { width: 19px; height: 19px; }

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, #8A43B0 0%, var(--mangosteen) 55%, #571F73 100%);
  box-shadow: 0 1px 2px rgba(62, 20, 82, 0.2), 0 8px 20px rgba(107, 47, 138, 0.30), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
.btn-cta {
  color: var(--cta-text);
  background:
    radial-gradient(120% 140% at 30% 0%, rgba(255, 255, 255, 0.55) 0%, rgba(255, 255, 255, 0) 45%),
    linear-gradient(135deg, var(--cta-1) 0%, var(--cta-2) 55%, var(--cta-3) 100%);
  box-shadow: var(--shadow-cta), inset 0 1px 0 rgba(255, 255, 255, 0.6), inset 0 -2px 0 rgba(170, 70, 0, 0.18);
  font-weight: 800;
  letter-spacing: 0.02em;
}
.btn-secondary { color: var(--accent); background: var(--accent-soft); }
.btn-tonal { color: var(--text); background: var(--surface-3); }
.btn-ghost { color: var(--accent); background: transparent; }
.btn-danger { color: #fff; background: var(--danger); }
.btn-danger-text { color: var(--danger); background: var(--danger-soft); }
.btn-glass { color: #fff; background: var(--hero-glass); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
.btn-glass:active:not(:disabled) { background: var(--hero-glass-strong); }
.btn.is-busy { pointer-events: none; }
.btn.is-busy > :not(.spinner) { opacity: 0.35; }
.btn.is-busy .spinner { position: absolute; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px; height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  transition: transform var(--dur-1) var(--ease-out), background-color var(--dur-2);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active:not(:disabled) { transform: scale(0.92); }
.icon-btn:disabled { opacity: 0.35; }
.icon-btn--glass { background: var(--hero-glass); color: #fff; -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
.icon-btn--glass:active:not(:disabled) { background: var(--hero-glass-strong); }
.icon-btn--soft { background: var(--surface-3); color: var(--text-2); }
.icon-btn--danger { color: var(--danger); }

.text-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
}
.text-btn svg { width: 18px; height: 18px; }

.spinner {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2.5px solid currentColor;
  border-right-color: transparent;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.is-spinning { animation: spin 0.9s linear infinite; }

/* ---------- Cards ---------- */

.card {
  position: relative;
  background: var(--surface);
  border-radius: var(--r-l);
  box-shadow: var(--shadow-2);
  padding: 18px;
}
.card + .card, .card + .section, .section + .card, .section + .section { margin-top: var(--gap); }
.card-head { display: flex; align-items: center; gap: 10px; min-height: 32px; margin-bottom: 14px; }
.card-head h2, .card-head h3 { font-size: 17px; font-weight: 700; flex: 1; min-width: 0; }
.card-head .text-btn { margin: -8px -4px; }
.badge-icon {
  display: inline-grid;
  place-items: center;
  width: 32px; height: 32px;
  border-radius: 10px;
  color: #fff;
  flex-shrink: 0;
}
.badge-icon svg { width: 19px; height: 19px; }
.badge-icon--pineapple { background: linear-gradient(135deg, #FFD45C, #FFAA1F); color: #5A3500; }
.badge-icon--mangosteen { background: linear-gradient(135deg, #9B55C2, var(--mangosteen)); }
.badge-icon--leaf { background: linear-gradient(135deg, #5CC78A, #2E9A5E); }
.badge-icon--coral { background: linear-gradient(135deg, #FF8E7A, #F2554A); }
.badge-icon--blue { background: linear-gradient(135deg, #6E9BFF, #2D6CF0); }
.badge-icon--ink { background: linear-gradient(135deg, #5A4A68, #2A1E35); }

.divider { height: 1px; background: var(--line); margin: 16px 0; border: 0; }
.divider--dashed { height: 0; background: none; border-top: 1.5px dashed var(--line-strong); }

.section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 26px 4px 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
}

.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: 13px; }

/* ---------- Chips & tags ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 26px;
  padding: 0 10px;
  border-radius: var(--r-pill);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  background: var(--surface-3);
  color: var(--text-2);
}
.chip svg { width: 14px; height: 14px; }
.chip--ssq { background: #FFE4E0; color: #C22B27; }
.chip--dlt { background: #E2EBFF; color: #1E4FC2; }
.chip--pl5 { background: var(--game-pl5-soft); color: var(--game-pl5); }
.chip--pl3 { background: var(--game-pl3-soft); color: var(--game-pl3); }
.chip--fc3d { background: var(--game-fc3d-soft); color: var(--game-fc3d); }
.chip--qxc { background: var(--game-qxc-soft); color: var(--game-qxc); }
.chip--qlc { background: var(--game-qlc-soft); color: var(--game-qlc); }
.chip--kl8 { background: var(--game-kl8-soft); color: var(--game-kl8); }
.chip--accent { background: var(--accent-soft); color: var(--accent); }
.chip--pineapple { background: var(--pineapple-soft); color: #8A5600; }
.chip--leaf { background: var(--leaf-soft); color: #1F7F4A; }
.chip--coral { background: var(--coral-soft); color: #B8361F; }
@media (prefers-color-scheme: dark) {
  .chip--ssq { background: rgba(232, 67, 63, 0.20); color: #FF9A8F; }
  .chip--dlt { background: rgba(45, 108, 240, 0.22); color: #9DBBFF; }
  .chip--pineapple { color: #FFD06A; }
  .chip--leaf { color: #6FE0A2; }
  .chip--coral { color: #FF9A8C; }
}

/* 「预估」 next to a draw date / issue counted from a predicted 休市 entry. Shorter than any text line
   it sits in (≤ 18px), so adding it never changes a row's height. */
.est-tag {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  height: 18px;
  padding: 0 6px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
  background: var(--pineapple-soft);
  color: #8A5600;
}
@media (prefers-color-scheme: dark) { .est-tag { color: #FFD06A; } }
/* Same tag for an announced (official) 休市 entry. */
.est-tag--official { background: var(--leaf-soft); color: #1F7F4A; }
@media (prefers-color-scheme: dark) { .est-tag--official { color: #6FE0A2; } }

.pill-option {
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--r-pill);
  border: 1.5px solid var(--line-strong);
  background: transparent;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-2);
  transition: background-color var(--dur-2), color var(--dur-2), border-color var(--dur-2), transform var(--dur-1);
}
.pill-option:active { transform: scale(0.96); }
.pill-option[aria-pressed="true"] { background: var(--accent-soft); border-color: transparent; color: var(--accent); }

/* ---------- Segmented control ---------- */

.seg {
  --n: 2;
  --i: 0;
  position: relative;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  padding: 3px;
  border-radius: 16px;
  background: var(--surface-3);
  isolation: isolate;
}
.seg-thumb {
  position: absolute;
  top: 3px; bottom: 3px; left: 3px;
  width: calc((100% - 6px) / var(--n));
  transform: translateX(calc(var(--i) * 100%));
  border-radius: 13px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(42, 30, 53, 0.10), 0 3px 10px rgba(42, 30, 53, 0.08);
  transition: transform 320ms var(--ease-out);
  z-index: -1;
}
.seg-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 6px;
  border: 0;
  background: none;
  border-radius: 13px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
  transition: color var(--dur-2);
}
.seg-item svg { width: 18px; height: 18px; }
.seg-item[aria-selected="true"], .seg-item[aria-checked="true"] { color: var(--text); }
.seg-count { font-family: var(--font-rounded); font-size: 13px; opacity: 0.7; }
.seg-dot { flex-shrink: 0; width: 7px; height: 7px; margin-left: -2px; border-radius: 50%; background: var(--coral); }
.seg--card .seg-item[aria-selected="true"] .seg-dot { background: var(--pineapple); }

.seg--glass { background: var(--hero-glass); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); }
.seg--glass .seg-thumb { background: #fff; box-shadow: 0 2px 10px rgba(30, 8, 44, 0.22); }
.seg--glass .seg-item { color: rgba(255, 255, 255, 0.82); }
.seg--glass .seg-item[aria-selected="true"], .seg--glass .seg-item[aria-checked="true"] { color: var(--mangosteen-deep); }
@media (prefers-color-scheme: dark) {
  .seg-thumb { background: #4A3A56; }
  .seg--glass .seg-thumb { background: rgba(255, 255, 255, 0.92); }
}

/* ---------- Stepper ---------- */

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  flex-shrink: 0;
}
.stepper-btn {
  display: grid;
  place-items: center;
  width: 44px; height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(42, 30, 53, 0.08), 0 2px 6px rgba(42, 30, 53, 0.06);
  transition: transform var(--dur-1) var(--ease-out), opacity var(--dur-2);
}
.stepper-btn svg { width: 20px; height: 20px; }
.stepper-btn:active:not(:disabled) { transform: scale(0.9); }
.stepper-btn:disabled { opacity: 0.32; box-shadow: none; cursor: default; }
.stepper-value {
  min-width: 44px;
  text-align: center;
  font-family: var(--font-rounded);
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.stepper-value.bump { animation: bump 260ms var(--ease-spring); }
@keyframes bump { 40% { transform: scale(1.22); } }
@media (prefers-color-scheme: dark) { .stepper-btn { background: #3D2F49; } }

/* ---------- Switch ---------- */

.switch { position: relative; display: inline-flex; flex-shrink: 0; }
.switch input {
  position: absolute;
  inset: -6px;
  width: calc(100% + 12px);
  height: calc(100% + 12px);
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}
.switch-track {
  width: 52px; height: 32px;
  border-radius: var(--r-pill);
  background: var(--line-strong);
  padding: 2px;
  transition: background-color var(--dur-2) var(--ease-out);
}
.switch-thumb {
  display: block;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18), 0 0 1px rgba(0, 0, 0, 0.2);
  transition: transform 300ms var(--ease-spring);
}
.switch input:checked + .switch-track { background: var(--leaf); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--focus); outline-offset: 2px; }
.switch input:disabled + .switch-track { opacity: 0.4; }

/* ---------- Form fields ---------- */

.field { display: grid; gap: 8px; }
.field + .field { margin-top: 14px; }
.field-label { font-size: 14px; font-weight: 600; color: var(--text-2); padding: 0 4px; }
.field-hint { font-size: 13px; color: var(--text-3); padding: 0 4px; }
.input-wrap { position: relative; display: flex; align-items: center; }
.input {
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  border: 1.5px solid var(--line-strong);
  border-radius: 16px;
  background: var(--surface);
  font-size: 17px;
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
  transition: border-color var(--dur-2), box-shadow var(--dur-2);
}
.input::placeholder { color: var(--text-3); }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input-wrap .input { padding-right: 52px; }
.input-wrap .icon-btn { position: absolute; right: 4px; color: var(--text-3); }
input[type="date"].input { min-width: 0; display: flex; align-items: center; }
input[type="date"].input::-webkit-date-and-time-value { text-align: left; }
.form-error {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 14px;
  font-weight: 500;
  /* Scrolled into view in a sheet: keep a gap to the footer instead of touching it. */
  scroll-margin-block: var(--gap);
}
.form-error svg { width: 18px; height: 18px; }

/* ---------- Lists (settings style) ---------- */

.list {
  background: var(--surface);
  border-radius: var(--r-m);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 10px 16px;
  border: 0;
  background: none;
  text-align: left;
  text-decoration: none;
  color: var(--text);
  font-size: 16px;
  position: relative;
}
.row + .row::before {
  content: "";
  position: absolute;
  top: 0; right: 0;
  left: 60px;
  height: 1px;
  background: var(--line);
}
.row--plain + .row--plain::before, .row--plain + .row::before { left: 16px; }
button.row:active, a.row:active { background: var(--surface-3); }
.row-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.row-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-detail { color: var(--text-3); font-size: 15px; }
.row-sub--wrap { white-space: normal; }
.row-chevron { width: 18px; height: 18px; color: var(--text-3); }
.row--danger { color: var(--danger); }
.row--danger .row-title { font-weight: 600; }

/* ---------- Balls ---------- */

.ball {
  --size: 38px;
  --c: var(--ball-red);
  --cl: var(--ball-red-light);
  --cd: var(--ball-red-dark);
  position: relative;
  display: inline-grid;
  place-items: center;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  flex-shrink: 0;
  font-family: var(--font-rounded);
  font-size: calc(var(--size) * 0.42);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: -0.02em;
  color: #fff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
  background:
    radial-gradient(ellipse 42% 30% at 40% 20%, rgba(255, 255, 255, 0.85) 0%, rgba(255, 255, 255, 0) 100%),
    radial-gradient(circle at 50% 35%, var(--cl) 0%, var(--c) 48%, var(--cd) 100%);
  box-shadow:
    inset 0 -3px 6px rgba(0, 0, 0, 0.16),
    0 1px 2px rgba(0, 0, 0, 0.14),
    0 5px 10px -4px var(--c);
}
.ball--blue { --c: var(--ball-blue); --cl: var(--ball-blue-light); --cd: var(--ball-blue-dark); }
.ball--gold { --c: #F5A400; --cl: #FFE07A; --cd: #B86E00; color: #4A2C00; text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35); }
.ball--sm { --size: 30px; }
.ball--xs { --size: 24px; font-weight: 700; }
.ball--lg { --size: 44px; }
.ball--miss {
  background: var(--surface);
  color: var(--c);
  text-shadow: none;
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--c) 42%, transparent);
}
@media (prefers-color-scheme: dark) {
  .ball--miss { background: transparent; color: color-mix(in srgb, var(--cl) 80%, #fff); }
}
.ball--dan { box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.16), 0 0 0 2px var(--surface), 0 0 0 4px var(--pineapple), 0 5px 10px -4px var(--c); }
.ball--dan.ball--miss { box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--c) 42%, transparent), 0 0 0 2px var(--surface), 0 0 0 3.5px var(--pineapple); }
.ball-star {
  position: absolute;
  top: -3px; right: -3px;
  width: 15px; height: 15px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--pineapple);
  color: #5A3500;
  box-shadow: 0 0 0 1.5px var(--surface);
}
.ball-star svg { width: 10px; height: 10px; }

.balls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.balls-sep { width: 1.5px; height: 22px; margin: 0 3px; border-radius: 1px; background: var(--line-strong); }
.balls-label {
  display: inline-grid;
  place-items: center;
  min-width: 26px;
  height: 22px;
  padding: 0 6px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-2);
  background: var(--surface-3);
}
.balls-label--dan { background: var(--pineapple-soft); color: #8A5600; }
@media (prefers-color-scheme: dark) { .balls-label--dan { color: #FFD06A; } }
.zone-lines { display: grid; gap: 10px; }
.zone-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; }
/* label + balls: wrapped balls stay aligned with the first ball after the label. A last run that does not fit
   beside the previous one in full starts its own line (basis = its one-row width) instead of being squeezed
   into a one-ball column; on its own line it shrinks to the line and its balls wrap. */
.zone-run { display: flex; align-items: baseline; gap: inherit; }
.zone-run--grow { flex: 1 1 auto; }
.zone-run-balls { display: flex; flex-wrap: wrap; align-items: baseline; gap: inherit; }

.ball.pop { animation: ball-pop 520ms var(--ease-spring) both; animation-delay: calc(var(--i, 0) * 55ms); }
@keyframes ball-pop {
  0% { opacity: 0; transform: scale(0.2) translateY(10px) rotate(-60deg); }
  60% { opacity: 1; transform: scale(1.14) rotate(8deg); }
  100% { opacity: 1; transform: none; }
}

/* ---------- Bottom tab bar (floating capsule) ---------- */

.tabbar {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: max(calc(var(--safe-bottom) - 8px), 14px);
  transform: translateX(-50%);
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 2px;
  width: min(360px, calc(100% - 2 * var(--gutter)));
  height: var(--tabbar-h);
  padding: 5px;
  border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--bg-elevated) 78%, transparent);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  backdrop-filter: blur(22px) saturate(180%);
  box-shadow: 0 0 0 0.5px var(--line-strong), 0 10px 30px rgba(42, 30, 53, 0.16), 0 2px 6px rgba(42, 30, 53, 0.08);
}
.tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  white-space: nowrap;
  border-radius: var(--r-pill);
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-2);
  transition: background-color var(--dur-2), color var(--dur-2);
}
.tab svg { width: 22px; height: 22px; }
.tab[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.tab:active { transform: scale(0.97); }

/* ---------- Toast ---------- */

.toast-host {
  position: fixed;
  z-index: 200;
  top: calc(var(--safe-top) + 10px);
  left: 0; right: 0;
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 0 max(var(--gutter), var(--safe-right)) 0 max(var(--gutter), var(--safe-left));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  min-height: 48px;
  padding: 10px 12px 10px 16px;
  border-radius: 20px;
  background: rgba(36, 22, 46, 0.92);
  color: #fff;
  font-size: 15px;
  font-weight: 500;
  box-shadow: 0 12px 32px rgba(20, 6, 30, 0.30);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  pointer-events: auto;
  animation: toast-in 360ms var(--ease-spring) both;
}
.toast.is-leaving { animation: toast-out 220ms var(--ease-out) both; }
.toast-icon { width: 22px; height: 22px; flex-shrink: 0; }
.toast--success .toast-icon { color: #6FE0A2; }
.toast--error .toast-icon { color: #FF9A8C; }
.toast--info .toast-icon { color: var(--pineapple); }
.toast-text { flex: 1; min-width: 0; padding-right: 4px; }
.toast-action {
  position: relative;
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}
.toast-action::after { content: ""; position: absolute; inset: -5px -4px; } /* 44px tap target */
@keyframes toast-in { from { opacity: 0; transform: translateY(-16px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-10px) scale(0.98); } }

/* ---------- Bottom sheet ---------- */

.sheet-root { position: fixed; inset: 0; z-index: 100; }
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 8, 28, 0.42);
  opacity: 0;
  transition: opacity 320ms var(--ease-out);
}
.sheet {
  position: absolute;
  left: 0; right: 0;
  bottom: var(--kb, 0px);
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - var(--safe-top) - 16px - var(--kb, 0px));
  margin: 0 auto;
  max-width: 600px;
  background: var(--bg-elevated);
  border-radius: 30px 30px 0 0;
  box-shadow: 0 -10px 40px rgba(20, 8, 28, 0.20);
  transform: translateY(105%);
  transition: transform 420ms var(--ease-out), bottom 200ms var(--ease-out);
  outline: none;
}
.sheet-root.is-open .sheet-backdrop { opacity: 1; }
.sheet-root.is-open .sheet { transform: translateY(var(--drag, 0px)); }
.sheet-root.is-dragging .sheet { transition: none; }
.sheet-grabber {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  height: 22px;
  touch-action: none;
}
.sheet-grabber::before { content: ""; width: 38px; height: 5px; border-radius: 3px; background: var(--line-strong); }
.sheet-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 calc(var(--gutter) - 4px) 8px var(--gutter);
  touch-action: none;
}
.sheet-head h2 { flex: 1; min-width: 0; font-size: 20px; font-weight: 700; }
/* 36px visual circle inside a 44px tap target */
.sheet-head .icon-btn { position: relative; isolation: isolate; width: 44px; height: 44px; margin: -4px -4px -4px 0; color: var(--text-2); }
.sheet-head .icon-btn::before { content: ""; position: absolute; inset: 4px; z-index: -1; border-radius: 50%; background: var(--surface-3); }
.sheet-head .icon-btn svg { width: 18px; height: 18px; }
.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 4px var(--gutter) 18px;
}
.sheet-foot {
  flex-shrink: 0;
  display: grid;
  gap: 8px;
  padding: 10px var(--gutter) calc(var(--safe-bottom) + 12px);
  border-top: 1px solid var(--line);
  background: var(--bg-elevated);
}
.sheet-root.no-foot .sheet-body { padding-bottom: calc(var(--safe-bottom) + 18px); }
.sheet-root.kb-open .sheet-foot { padding-bottom: 12px; }
.sheet-root.kb-open .sheet { border-radius: 30px 30px 0 0; }

/* Action sheet (menu) */
.menu { display: grid; gap: 10px; }
.menu .list { box-shadow: none; background: var(--surface-3); }
@media (prefers-color-scheme: dark) { .menu .list { background: var(--surface-2); } }

/* ---------- Confirm dialog ---------- */

.dialog-root {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: grid;
  place-items: center;
  padding: 24px;
}
.dialog-backdrop { position: absolute; inset: 0; background: rgba(20, 8, 28, 0.42); animation: fade-in 200ms both; }
.dialog {
  position: relative;
  width: min(320px, 100%);
  padding: 24px 20px 16px;
  border-radius: 26px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow-3);
  text-align: center;
  animation: dialog-in 320ms var(--ease-spring) both;
}
.dialog-icon {
  width: 52px; height: 52px;
  margin: 0 auto 12px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--danger-soft);
  color: var(--danger);
}
.dialog-icon svg { width: 26px; height: 26px; }
.dialog-icon--accent { background: var(--accent-soft); color: var(--accent); }
.dialog h2 { font-size: 19px; font-weight: 700; }
.dialog p { margin-top: 8px; font-size: 15px; color: var(--text-2); }
.dialog-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 20px; }
.dialog-actions .btn { min-height: 48px; padding: 0 12px; }
.dialog-root.is-leaving .dialog { animation: dialog-out 160ms var(--ease-out) both; }
.dialog-root.is-leaving .dialog-backdrop { animation: fade-out 160ms both; }
@keyframes dialog-in { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: none; } }
@keyframes dialog-out { to { opacity: 0; transform: scale(0.95); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }

/* ---------- Empty & loading states ---------- */

.empty {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 36px 20px 30px;
  text-align: center;
}
.empty-art { width: 128px; height: 104px; }
.empty h3 { font-size: 17px; font-weight: 700; }
.empty p { font-size: 14px; color: var(--text-2); max-width: 260px; }
.empty .btn { margin-top: 6px; }

.skeleton {
  border-radius: 12px;
  background: linear-gradient(90deg, var(--surface-3) 0%, var(--surface-2) 50%, var(--surface-3) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.skeleton-card { height: 150px; border-radius: var(--r-l); }
.skeleton-card + .skeleton-card { margin-top: 14px; }

/* ---------- Confetti ---------- */

.confetti-canvas { position: fixed; inset: 0; z-index: 180; pointer-events: none; width: 100%; height: 100%; }

/* ---------- Disclaimer ---------- */

.disclaimer {
  margin: 28px 8px 0;
  text-wrap: pretty;
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
  color: var(--text-3);
}

/* ---------- Lottery ticket items (cards, confirm page, result sheet) ---------- */

/* One row per bets[] item: index | balls | 玩法 / ×倍数 / 中奖 tags. Layout grid lives in views.css. */
.ticket-bet-balls { min-width: 0; }
.ticket-bet-balls .balls, .ticket-bet-balls .zone-line { gap: 5px; }
.ticket-bet-balls .ball--sm { --size: var(--ball-row); }
.ticket-bet-tags { grid-area: tags; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; padding-top: 4px; }
.ticket-bet-balls { grid-area: balls; }
.ticket-bet .ticket-bet-index { grid-area: idx; }
.ticket-bet { grid-template-areas: "idx balls tags"; }
.ticket-bet.no-index { grid-template-areas: "balls tags"; }
.ticket-bet.is-lines { grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "idx tags" "idx balls"; row-gap: 8px; }
.ticket-bet.is-lines.no-index { grid-template-columns: minmax(0, 1fr); grid-template-areas: "tags" "balls"; }
.ticket-bet.is-lines .ticket-bet-tags { flex-direction: row; flex-wrap: wrap; align-items: center; padding-top: 0; }
.ticket-bet.is-lines .ticket-bet-index { margin-top: 0; }
.ticket-bet.is-hit {
  border-radius: 12px;
  background: color-mix(in srgb, var(--pineapple-soft) 50%, transparent);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--pineapple-soft) 50%, transparent);
}
.bet-tag {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--text-3);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}
.bet-tag--multiple { background: var(--accent-soft); color: var(--accent); }
.bet-tag--dantuo { background: var(--pineapple-soft); color: #8A5600; }
.bet-tag--mult { background: var(--coral-soft); color: #B8361F; font-size: 12px; font-variant-numeric: tabular-nums; }
.bet-tag--win { background: linear-gradient(135deg, #FFB020 0%, #FF6B5A 100%); color: #fff; }
.bet-tag--count { height: auto; padding: 0 2px; background: none; color: var(--text-3); font-weight: 600; }
@media (prefers-color-scheme: dark) {
  .bet-tag--dantuo { color: #FFD06A; }
  .bet-tag--mult { color: #FF9A8C; }
}

/* 选号页: after generating, point at 拍票 instead of an in-app 已买 flow (spec §7). */
.results-next {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  padding: 14px 14px 14px 16px;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--r-l);
  color: var(--text);
  text-decoration: none;
  transition: transform var(--dur-1) var(--ease-out), background-color var(--dur-2);
}
.results-next:active { transform: scale(0.98); background: var(--surface-3); }
.results-next-text { flex: 1; min-width: 0; display: grid; gap: 2px; }
.results-next-text strong { font-size: 15.5px; font-weight: 700; }
.results-next-text span { font-size: 13px; color: var(--text-2); }

/* Result sheet shown when a saved ticket is already settled. */
.result-sheet { display: grid; gap: 14px; }
.result-sheet .ticket { box-shadow: none; border-color: var(--line); }
.result-sheet .ticket.is-won { border-color: transparent; }
.result-hero { display: grid; justify-items: center; gap: 4px; padding: 20px 16px 18px; border-radius: var(--r-l); text-align: center; }
.result-hero-icon {
  display: grid;
  place-items: center;
  width: 56px; height: 56px;
  margin-bottom: 4px;
  border-radius: 20px;
  color: #fff;
  background: linear-gradient(135deg, #FFB020 0%, #FF6B5A 100%);
  box-shadow: 0 10px 24px rgba(255, 107, 90, 0.35);
}
.result-hero-icon svg { width: 30px; height: 30px; }
.result-hero-title { font-size: 22px; font-weight: 800; }
.result-hero-amount { font-size: 36px; font-weight: 800; line-height: 1.1; color: #E2462F; font-variant-numeric: tabular-nums; }
.result-hero-sub { font-size: 13.5px; color: var(--text-2); }
.result-hero--win { background: linear-gradient(135deg, #FFF3CF 0%, #FFE3DA 100%); color: #6A2A00; }
.result-hero--float { background: var(--warning-soft); color: #8A5600; }
.result-hero--float .result-hero-icon { background: linear-gradient(135deg, #FFD45C, #FFAA1F); color: #5A3500; box-shadow: none; }
.result-hero--lose { background: var(--surface-3); color: var(--text); }
.result-hero--lose .result-hero-icon { background: var(--surface); color: var(--coral); box-shadow: var(--shadow-1); }
@media (prefers-color-scheme: dark) {
  .result-hero--win { background: linear-gradient(135deg, rgba(255, 194, 51, 0.18) 0%, rgba(255, 107, 90, 0.18) 100%); color: #FFE6B0; }
  .result-hero-amount { color: #FF8A6E; }
  .result-hero--float { color: #FFD06A; }
}

/* Confirm page extras + 修改记录 sheet. */
.entry-tip { margin: -8px 4px 0; font-size: 12.5px; color: var(--text-3); }
.entry-bet .ticket-bet-index { background: var(--surface-3); }
.entry-bet.is-invalid .ticket-bet-index { background: var(--danger); color: #fff; }
.entry-bet .entry-bet-placeholder { min-height: 30px; }
.entry-raw { border-top: 1px solid var(--line); }
.entry-raw summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  list-style: none;
}
.entry-raw summary::-webkit-details-marker { display: none; }
.entry-raw summary svg { width: 18px; height: 18px; transition: transform var(--dur-2); }
.entry-raw[open] summary svg { transform: rotate(180deg); }
.entry-raw-text {
  max-height: 260px;
  margin: 0;
  padding: 12px;
  overflow: auto;
  border-radius: 14px;
  background: var(--surface-3);
  color: var(--text-2);
  font: 12.5px/1.55 ui-monospace, "SF Mono", Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-all;
}
.edit-sheet { display: grid; gap: 16px; }
.edit-sheet .field + .field { margin-top: 0; }
.edit-sheet .sheet-section-title { margin: 4px 2px -6px; }
.edit-sheet .sheet-note { margin-top: 0; }
/* 账本 per-game cards sit side by side: the stacked-card margin must not push the second one down. */
.game-cards > .card + .card { margin-top: 0; }

/* ---------- Loading and press feedback ---------- */

/* Top progress bar (ui/progress.js): only appears when a page or request takes over 150 ms. */
.progress {
  position: fixed;
  z-index: 260;
  top: var(--safe-top);
  left: 0;
  right: 0;
  height: 3px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 200ms var(--ease-out);
}
.progress-fill {
  display: block;
  height: 100%;
  border-radius: 0 3px 3px 0;
  background: linear-gradient(90deg, var(--pineapple), var(--coral));
  box-shadow: 0 0 8px rgba(255, 194, 51, 0.55);
  transform: scaleX(0);
  transform-origin: 0 50%;
}
.progress.is-active { opacity: 1; }
.progress.is-active .progress-fill { transform: scaleX(0.9); transition: transform 8s cubic-bezier(0.1, 0.7, 0.2, 1); }
.progress.is-done { opacity: 0; transition: opacity 200ms ease 180ms; }
.progress.is-done .progress-fill { transform: scaleX(1); transition: transform 180ms var(--ease-out); }

/* Pressed states for tappables that have no transform-based one of their own. */
.text-btn, .seg-item, .toast-action, .boss-done, .entry-photo, .ledger-table summary { transition-property: opacity, color, background-color, transform; transition-duration: var(--dur-1); }
.text-btn:active, .ledger-table summary:active { opacity: 0.55; }
.seg-item:active { opacity: 0.7; }
.toast-action:active { background: rgba(255, 255, 255, 0.28); }
.boss-done:active, .entry-photo:active { transform: scale(0.97); }
.toast.is-tappable { cursor: pointer; }
.toast.is-tappable:active { background: rgba(36, 22, 46, 0.8); }
/* While a request runs, the button keeps its size and shows a spinner; a second tap does nothing. */
.is-busy { pointer-events: none; }
.text-btn.is-busy > :not(.spinner), .row.is-busy > :not(.spinner) { opacity: 0.35; }
.text-btn.is-busy .spinner, .row.is-busy .spinner { position: absolute; left: 50%; top: 50%; margin: -10px 0 0 -10px; }
.text-btn.is-busy, .row.is-busy { position: relative; }

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0ms !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
  .spinner, .is-spinning { animation-duration: 1.2s !important; animation-iteration-count: infinite !important; }
  .skeleton { animation: none; }
}
