/* Console */
body[data-page="admin"] { --max: 1320px; }
body[data-page="admin"] .topbar { margin-bottom: 24px; border-radius: 12px; }
body[data-page="admin"] .console { gap: 24px; }
body[data-page="admin"] .console.show { grid-template-columns: 204px minmax(0, 1fr); }
body[data-page="admin"] .side {
  padding: 12px; border: 1px solid var(--panel-border);
  border-radius: 12px; background: rgba(18,12,32,.88); gap: 8px;
}
body[data-page="admin"] .side button { min-height: 46px; padding: 12px; line-height: 1.5; }
body[data-page="admin"] .panel { padding: clamp(18px, 2.3vw, 30px); border-radius: 12px; margin-bottom: 24px; }
body[data-page="admin"] .panel-head {
  padding-bottom: 16px; margin-bottom: 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
body[data-page="admin"] .panel-head h2 { font-size: 1.2rem; line-height: 1.5; }
body[data-page="admin"] .form-grid { gap: 18px 22px; }
body[data-page="admin"] .form-row { gap: 8px; margin-bottom: 18px; }
body[data-page="admin"] .form-row label { font-size: .85rem; letter-spacing: 0; color: #d9d1e5; }
body[data-page="admin"] .field { min-height: 46px; }
body[data-page="admin"] .actions {
  padding-top: 18px; margin-top: 18px; border-top: 1px solid rgba(255,255,255,.08);
}
body[data-page="admin"] .row-item { padding: 16px; gap: 16px; margin-bottom: 12px; }
body[data-page="admin"] .row-item > div:first-child { flex: 1 1 220px; min-width: 0; }
body[data-page="admin"] .row-item .r-title { line-height: 1.6; }
body[data-page="admin"] .row-item .r-meta { line-height: 1.8; margin-top: 5px; }
body[data-page="admin"] .row-btns { justify-content: flex-end; }
body[data-page="admin"] .row-btns button { min-height: 40px; font-size: .8rem; }
body[data-page="admin"] .gate-wrap { padding-block: clamp(24px, 6vh, 72px); }
body[data-page="admin"] .gate-card { width: min(100%, 460px); }
body[data-page="admin"] .udetail-card { max-height: calc(100dvh - 32px); }

/* Lottery lobby and activity detail */
body[data-page="lottery"] { --max: 1160px; }
body[data-page="lottery"] .nav { border-radius: 12px; }
body[data-page="lottery"] .section { padding: clamp(20px, 3vw, 32px); }
body[data-page="lottery"] .section-head { gap: 10px 24px; align-items: baseline; margin-bottom: 24px; }
body[data-page="lottery"] .section-head h2 { margin: 0; line-height: 1.5; }
body[data-page="lottery"] .section-head .sub { line-height: 1.7; max-width: 38em; }
body[data-page="lottery"] .dash-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 270px), 1fr)); gap: 20px;
}
body[data-page="lottery"] .dash-card {
  display: flex; flex-direction: column; min-width: 0;
  padding: 24px; border-radius: 12px;
}
body[data-page="lottery"] .dash-card h3 { font-size: 1.15rem; line-height: 1.6; }
body[data-page="lottery"] .dash-card .d-desc { line-height: 1.8; margin-bottom: 20px; }
body[data-page="lottery"] .dash-card .d-meta { margin-top: auto; gap: 8px; }
.activity-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 24px; align-items: stretch; }
.activity-layout > * { min-width: 0; }
body[data-page="lottery"] .activity-layout .hero { padding: 30px; }
body[data-page="lottery"] .activity-layout .hero h1 { font-size: clamp(1.8rem, 3.2vw, 2.8rem); line-height: 1.25; }
body[data-page="lottery"] .activity-layout .wheel-section { justify-content: center; padding: 30px 22px; }
body[data-page="lottery"] .wheel-stage { width: 100%; max-width: 420px; height: auto; aspect-ratio: 1; flex-shrink: 0; }
body[data-page="lottery"] .record-item,
body[data-page="lottery"] .winner-item { padding: 16px 18px; gap: 12px 20px; line-height: 1.65; margin-bottom: 12px; }
body[data-page="lottery"] .modal .sub { line-height: 1.75; }
body[data-page="lottery"] .auth-tabs { margin-bottom: 22px; }
body[data-page="lottery"] .auth-tab { min-height: 44px; }
body[data-page="lottery"] #auth-send-code { width: 100%; margin-top: 10px; min-height: 44px; }
body[data-page="lottery"] .modal-actions .btn { flex: 1; min-height: 46px; }
@media (max-width: 1024px) {
  body[data-page="admin"] .console.show { grid-template-columns: minmax(0, 1fr); }
  body[data-page="admin"] .side {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    position: static; padding: 10px; gap: 6px; overflow: visible;
  }
  body[data-page="admin"] .side button { text-align: center; white-space: normal; }
}
@media (max-width: 800px) {
  .activity-layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  body[data-page="lottery"] .activity-layout .hero { padding: 24px 20px; }
  body[data-page="lottery"] .activity-layout .wheel-section { padding: 28px 20px; }
  body[data-page="lottery"] .wheel-stage { max-width: 380px; }
}
@media (max-width: 520px) {
  body[data-page="admin"] .side { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  body[data-page="admin"] .topbar { gap: 16px; padding: 16px; }
  body[data-page="admin"] .topbar-right { width: 100%; justify-content: space-between; }
  body[data-page="admin"] .panel { padding: 18px 14px; border-radius: 12px; }
  body[data-page="admin"] .row-btns { width: 100%; justify-content: flex-start; }
  body[data-page="admin"] .row-btns button { flex: 1 1 auto; min-height: 44px; }
  body[data-page="admin"] .actions > .btn { flex: 1 1 120px; }
  body[data-page="admin"] .panel-head > .btn { width: 100%; }
  body[data-page="lottery"] .nav { position: relative; top: 0; padding: 12px; }
  body[data-page="lottery"] .dash-card { padding: 20px; }
  body[data-page="lottery"] .section-head { align-items: flex-start; flex-direction: column; gap: 6px; }
  body[data-page="lottery"] .record-item .r-time { flex-basis: 100%; }
  body[data-page="lottery"] .record-item .r-code { max-width: 100%; }
}

body[data-page="lottery"] .slider-captcha {
  padding: 16px; border: 1px solid rgba(167,139,250,.28); border-radius: 12px;
  background: rgba(167,139,250,.10);
  touch-action: pan-y;
}
.captcha-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; font-weight: 600; }
.captcha-badge { font-size: .72rem; font-weight: 400; color: #aaf7da; border: 1px solid rgba(101,246,194,.25); border-radius: 12px; padding: 4px 8px; }
body[data-page="lottery"] .cap-board { width: 300px; aspect-ratio: 300 / 160; min-height: 120px; background: #211a32; border: 1px solid rgba(255,255,255,.1); }
#cap-state { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; text-align: center; font-size: .86rem; line-height: 1.7; color: #d8cde8; }
#cap-state[hidden] { display: none; }
body[data-page="lottery"] .cap-refresh { position: static; width: 100%; min-height: 40px; margin-top: 12px; border-radius: 10px; font-size: .82rem; }
body[data-page="lottery"] .cap-click-hint { margin-top: 8px; font-size: .88rem; line-height: 1.7; padding: 8px 0 0; }
@media (max-width: 360px) {
  body[data-page="lottery"] .slider-captcha { padding: 10px; }
}

.activity-rules { margin-top: 16px; text-align: left; }
.activity-rules summary { cursor: pointer; padding: 10px 0; font-size: .85rem; color: #c4bdd6; }
.activity-rules .form-help { line-height: 1.8; padding: 8px 0; }
#rule-probabilities { margin-top: 8px; }

/* Stable control sizing and keyboard feedback across desktop and touch screens. */
body[data-page] .btn { min-height: 44px; }
body[data-page="admin"] .mini-btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
body[data-page] button:disabled { cursor: not-allowed; opacity: .62; }
body[data-page] :is(button, a, input, summary):focus-visible { outline: var(--focus-w) solid var(--gold); outline-offset: var(--focus-offset); }
body[data-page="lottery"] .cap-board { margin-inline: auto; }
body[data-page="lottery"] #cap-click-hint { min-height: 2.8em; }
body[data-page="lottery"] #draw-hint { min-height: 3em; line-height: 1.6; }
body[data-page="lottery"] #auth-send-code { min-height: 44px; font-variant-numeric: tabular-nums; }
body[data-page="lottery"] .activity-rules { border-top: 1px solid rgba(255,255,255,.08); padding-top: 4px; }
@media (prefers-reduced-motion: reduce) {
  body[data-page] *, body[data-page] *::before, body[data-page] *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
}

/* Refined record rows, long titles and focus states. */
body[data-page="admin"] .row-item > span:first-child { flex: 1 1 220px; min-width: 0; overflow-wrap: anywhere; }
body[data-page="admin"] .row-btns { flex-wrap: wrap; gap: 8px; }
body[data-page="admin"] .code-tag { user-select: all; overflow-wrap: anywhere; }
body[data-page="admin"] .field:disabled { opacity: .7; }
body[data-page="admin"] .udetail-card { overscroll-behavior: contain; }
body[data-page="lottery"] .dash-card { transition: border-color var(--dur) ease, box-shadow var(--dur) ease; }
body[data-page="lottery"] .dash-card:focus-visible { outline: var(--focus-w) solid var(--gold); outline-offset: var(--focus-offset); }
body[data-page="lottery"] .dash-card:hover { border-color: rgba(211,182,255,.45); box-shadow: 0 10px 30px rgba(0,0,0,.16); }
body[data-page="lottery"] .winner-item { gap: 12px; flex-wrap: wrap; }
body[data-page="lottery"] .winner-item > span { min-width: 0; overflow-wrap: anywhere; }
body[data-page="lottery"] .r-code { user-select: all; }
@media (max-width: 600px) {
  body[data-page="admin"] .row-btns { justify-content: flex-start; }
  body[data-page="admin"] .row-item > span:first-child { flex-basis: 100%; }
  body[data-page="lottery"] .winner-item > span:last-child { flex-basis: 100%; justify-content: space-between; }
}

/* Mobile forms: keep every value readable and every action reachable. */
body[data-page="admin"] .prize-field { display: block; margin: 0; min-width: 0; }
body[data-page="admin"] .prize-field > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
body[data-page="admin"] .prize-field input { width: 100%; }
body[data-page="admin"] .prize-row { align-items: stretch; }
body[data-page="admin"] .prize-row .del-row { min-height: 44px; }
body[data-page="lottery"] :is(.modal-backdrop, .gate-overlay),
body[data-page="admin"] .udetail-overlay {
  top: var(--visible-top, 0px); bottom: auto;
  height: 100vh; height: var(--visible-height, 100dvh);
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  overflow-y: auto;
}
body[data-page="admin"] .udetail-card { max-height: calc(var(--visible-height, 100dvh) - 24px); }
body[data-page="lottery"] :is(.modal, .gate-card) { flex-shrink: 0; }
body[data-page="lottery"] .modal-actions { flex-wrap: wrap; }
body[data-page="lottery"] .modal-actions .btn { white-space: normal; }
@media (max-width: 600px) {
  body[data-page="admin"] .prize-grid-head { display: none; }
  body[data-page="admin"] .prize-row { position: relative; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; padding: 14px; border: 1px solid rgba(255,255,255,.12); border-radius: 14px; background: rgba(255,255,255,.025); }
  body[data-page="admin"] .prize-name { grid-column: 1 / -1; padding-right: 52px; }
  body[data-page="admin"] .prize-field > span { position: static; display: block; width: auto; height: auto; clip-path: none; margin-bottom: 6px; font-size: 13px; color: #d9d1e5; }
  body[data-page="admin"] .prize-row .del-row { position: absolute; top: 35px; right: 14px; width: 44px; height: 46px; }
  body[data-page="admin"] :is(.form-grid, .form-grid-2) { grid-template-columns: minmax(0, 1fr); }
  body[data-page="admin"] #ud-close { flex-shrink: 0; min-width: 44px; min-height: 44px; }
  body[data-page="admin"] .udetail-head { padding: 14px; }
  body[data-page="admin"] #ud-body { padding: 14px; }
  body[data-page="admin"] .ud-grid { grid-template-columns: minmax(64px, auto) minmax(0, 1fr); gap: 10px; }
  body[data-page="lottery"] .activity-layout .hero { padding: 20px 16px; }
  body[data-page="lottery"] .activity-layout .hero h1 { font-size: clamp(1.5rem, 6vw, 2rem); line-height: 1.4; }
  body[data-page="lottery"] .activity-layout .wheel-section { padding: 24px 12px; }
  body[data-page="lottery"] :is(.modal, .gate-card) { padding: 22px 16px; border-radius: 12px; }
  body[data-page="lottery"] :is(.nav-user button, .nav-user a.nav-action, .back-link, .cap-refresh) { min-height: 44px; }
  body[data-page="lottery"] .record-item > span { min-width: 0; max-width: 100%; }
  body[data-page="lottery"] .claim-code-box .code { font-size: clamp(1.15rem, 5vw, 1.6rem); overflow-wrap: anywhere; }
}

/* Light theme: admin/lottery surfaces follow the shared tokens (assets/theme.css).
   Dark values above stay untouched; these overrides only apply in light mode. */
html[data-theme="light"] body[data-page="admin"] .side {
  background: var(--surface); border-color: var(--border);
}
html[data-theme="light"] body[data-page="admin"] .panel-head,
html[data-theme="light"] body[data-page="admin"] .actions { border-color: var(--border-soft); }
html[data-theme="light"] body[data-page="admin"] .form-row label,
html[data-theme="light"] body[data-page="admin"] .prize-field > span { color: var(--muted); }
html[data-theme="light"] body[data-page] :is(button, a, input, summary):focus-visible,
html[data-theme="light"] body[data-page="lottery"] .dash-card:focus-visible { outline-color: var(--gold); }
html[data-theme="light"] body[data-page="lottery"] .slider-captcha {
  border-color: var(--border); background: var(--surface-2);
}
html[data-theme="light"] body[data-page="lottery"] .captcha-badge {
  color: var(--green); border-color: var(--border);
}
html[data-theme="light"] body[data-page="lottery"] .cap-board { border-color: var(--border); }
html[data-theme="light"] body[data-page="lottery"] .activity-rules { border-top-color: var(--border-soft); }
html[data-theme="light"] body[data-page="lottery"] .activity-rules summary { color: var(--muted); }
html[data-theme="light"] body[data-page="lottery"] .dash-card:hover {
  border-color: var(--accent-2); box-shadow: var(--shadow);
}
html[data-theme="light"] body[data-page="lottery"] #wheel-svg text { fill: #52657e; }
html[data-theme="light"] body[data-page="lottery"] #wheel-svg circle { fill: rgba(18, 34, 58, .06); }
@media (max-width: 600px) {
  html[data-theme="light"] body[data-page="admin"] .prize-row {
    background: var(--surface-2); border-color: var(--border);
  }
}
html[data-theme="light"] body[data-page="admin"] .panel-head h2 { color: var(--text); }
html[data-theme="light"] body[data-page="admin"] .side button.current {
  color: var(--gold); background: rgba(148, 106, 0, .10); border-color: rgba(148, 106, 0, .35);
}
html[data-theme="light"] body[data-page="lottery"] .chip {
  color: var(--gold); background: var(--surface-2); border-color: rgba(148, 106, 0, .35);
}
html[data-theme="light"] body[data-page="lottery"] .chip strong { color: var(--text); }
html[data-theme="light"] body[data-page="lottery"] .chip.live {
  color: var(--green); border-color: rgba(14, 124, 86, .40);
}
html[data-theme="light"] body[data-page="lottery"] .chip.live::before {
  background: var(--green); box-shadow: 0 0 10px rgba(14, 124, 86, .5);
}
html[data-theme="light"] body[data-page="lottery"] .chip.ended {
  color: var(--red); border-color: rgba(194, 47, 66, .40);
}
html[data-theme="light"] body[data-page="lottery"] .modal {
  background: var(--surface); border-color: var(--border);
  box-shadow: 0 24px 60px rgba(23, 35, 59, .25);
}
html[data-theme="light"] body[data-page="lottery"] h1 { background-color: var(--text); }
html[data-theme="light"] body[data-page="lottery"] .gate-overlay { background: rgba(214, 51, 132, .38); }
