:root {
  --bg: #f3f8ff;
  --bg-accent: #fff7dd;
  --card: #ffffff;
  --ink: #1f2d3d;
  --muted: #60758a;
  --line: #d6e2ee;
  --brand: #2782f5;
  --brand-2: #26b36f;
  --danger: #f76767;
  --nav-height: 52px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top right, var(--bg-accent) 0%, var(--bg) 44%, #ecf3ff 100%);
}

.page {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 14px 12px 84px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.title {
  font-size: 24px;
  margin: 0;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.profile-line {
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.profile-line button {
  padding: 4px 10px;
}

.login-tabs .badge {
  background: #eef5ff;
  color: #355a84;
}

.form-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-line-label {
  width: 64px;
  flex: 0 0 64px;
  color: #355a84;
  font-size: 13px;
  font-weight: 600;
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  flex-direction: column;
  justify-content: center;
  padding: 24px 12px 88px;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 14% 12%, rgba(255, 210, 120, 0.34), rgba(255, 210, 120, 0) 36%),
    radial-gradient(circle at 86% 18%, rgba(79, 157, 255, 0.3), rgba(79, 157, 255, 0) 38%),
    radial-gradient(circle at 50% 100%, rgba(108, 214, 160, 0.28), rgba(108, 214, 160, 0) 46%),
    linear-gradient(180deg, #f7f9ff 0%, #eef3ff 52%, #e7efff 100%);
}

.login-page::before,
.login-page::after {
  content: "";
  position: absolute;
  width: 320px;
  height: 320px;
  border-radius: 999px;
  pointer-events: none;
  z-index: 0;
}

.login-page::before {
  top: -100px;
  right: -70px;
  background: radial-gradient(circle, rgba(43, 134, 246, 0.22) 0%, rgba(43, 134, 246, 0) 70%);
}

.login-page::after {
  bottom: -120px;
  left: -70px;
  background: radial-gradient(circle, rgba(38, 179, 111, 0.18) 0%, rgba(38, 179, 111, 0) 72%);
}

.login-card {
  width: min(600px, 100%);
  padding: 16px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.92), rgba(246, 250, 255, 0.92));
  box-shadow: 0 24px 48px rgba(37, 79, 129, 0.16), 0 6px 14px rgba(37, 79, 129, 0.08);
  backdrop-filter: blur(6px);
  position: relative;
  z-index: 1;
  margin: 0 auto 12px;
}

.login-head h2 {
  margin-bottom: 6px;
  font-size: 30px;
  letter-spacing: 0.5px;
}

.login-head .meta {
  font-size: 13px;
}

.login-hint {
  margin-top: -2px;
}

.login-page .form-line input {
  text-align: center;
  background: rgba(255, 255, 255, 0.92);
  border-color: #c9dbf1;
  border-radius: 12px;
}

.login-page .form-line-label {
  color: #2e5c92;
  font-weight: 700;
}

.login-page button[type="submit"] {
  margin-top: 4px;
  padding: 10px 14px;
  border-radius: 12px;
  background: linear-gradient(135deg, #2a82f2, #3ca1ff);
  box-shadow: 0 8px 18px rgba(42, 130, 242, 0.3);
}

.setup-modal-body {
  border-radius: 18px;
  box-shadow: 0 18px 36px rgba(30, 68, 108, 0.2);
}

.setup-card {
  margin-top: 0;
}

.section {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 8px 24px rgba(28, 72, 131, 0.08);
  margin-bottom: 12px;
}

.section h2 {
  margin: 0 0 10px;
  font-size: 18px;
}

.panel-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding-bottom: 2px;
  margin-bottom: 12px;
}

.tab-btn {
  width: 100%;
  border: 1px solid var(--line);
  background: #f6faff;
  color: #3c5874;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 600;
}

.tab-btn.active {
  background: linear-gradient(135deg, #2b86f6, #4aa3ff);
  color: #fff;
  border-color: #2b86f6;
  box-shadow: 0 4px 12px rgba(43, 134, 246, 0.26);
}

.panel {
  display: none;
  animation: panelFade 0.2s ease;
}

.panel.active {
  display: block;
}

.parent-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 10px;
  margin-bottom: 0;
}

.parent-scroll {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding-right: 2px;
}

.parent-scroll > .panel.active {
  flex: 1;
  min-height: 0;
}

.parent-page {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--nav-height));
  min-height: 0;
  overflow: hidden;
  padding: 14px 12px 0;
}

.home-page {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--nav-height));
  min-height: 0;
  overflow: hidden;
  padding: 14px 12px 0;
}

.home-dashboard-section {
  flex: 0 0 auto;
}

.home-recent-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin-bottom: 0;
}

.home-recent-scroll {
  flex: 1;
  min-height: 0;
  max-height: clamp(200px, 32vh, 300px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 2px;
}

.metric-bar {
  margin-top: 6px;
  height: 8px;
  border-radius: 999px;
  background: #e7eef8;
  overflow: hidden;
}

.metric-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #2b86f6, #4aa3ff);
}

.manage-panel.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.manage-tools {
  flex: 0 0 auto;
}

.card-actions {
  align-items: center;
}

.card-save-btn {
  margin-left: auto;
}

.card-admin-list {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 2px;
}

.manage-inner-panel {
  display: none;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.manage-inner-panel.active {
  display: flex;
  flex-direction: column;
}

.parent-inner-tabs {
  margin-bottom: 8px;
}

.reward-balance-meta {
  margin-bottom: 8px;
  font-size: 13px;
}

.reward-item .reward-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.reward-redeem-btn {
  white-space: nowrap;
}

@keyframes panelFade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fbfdff;
}

.item strong {
  font-size: 15px;
}

.meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: #f8fbff;
}

.metric .k {
  color: var(--muted);
  font-size: 12px;
}

.metric .v {
  font-size: 20px;
  font-weight: 700;
}

.metric-full {
  grid-column: 1 / -1;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.draw-count-row {
  justify-content: center;
}

.draw-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}

.draw-task-scroll {
  max-height: clamp(240px, 38vh, 420px);
  overflow-y: auto;
  padding-right: 2px;
}

.draw-task-scroll-compact {
  max-height: clamp(180px, 30vh, 280px);
}

.draw-page {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--nav-height));
  min-height: 0;
  overflow: hidden;
  padding: 14px 12px 0;
}

.draw-top-section {
  flex: 0 0 auto;
}

.draw-task-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin-bottom: 0;
}

.draw-task-section .draw-task-scroll {
  flex: 1;
  min-height: 0;
}

.bag-page {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--nav-height));
  min-height: 0;
  overflow: hidden;
  padding: 14px 12px 0;
}

.bag-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin-bottom: 0;
}

.bag-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.bag-toolbar {
  margin-bottom: 8px;
}

.task-scroll {
  max-height: clamp(320px, 58vh, 620px);
  overflow-y: auto;
  padding-right: 2px;
}

.task-page {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--nav-height));
  min-height: 0;
  overflow: hidden;
  padding: 14px 12px 0;
}

.task-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin-bottom: 0;
}

.task-scroll-fill {
  flex: 1;
  max-height: none;
  min-height: 0;
}

.task-toolbar {
  margin-bottom: 8px;
}

.task-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.task-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.task-done-btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.task-badges {
  margin-top: 0;
}

button {
  border: 0;
  border-radius: 9px;
  padding: 8px 12px;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

button.secondary {
  background: var(--brand-2);
}

button.ghost {
  background: #eef5ff;
  color: #2e4d73;
}

.draw-tab-btn {
  width: 100%;
  min-width: 0;
}

.draw-tab-btn.active {
  background: linear-gradient(135deg, #2b86f6, #4aa3ff);
  color: #fff;
}

button.warn {
  background: var(--danger);
}

button[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px;
  font: inherit;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

textarea {
  min-height: 64px;
  resize: vertical;
}

.score-control {
  display: grid;
  grid-template-columns: 36px 1fr 36px;
  gap: 6px;
  align-items: center;
}

.score-btn {
  padding: 6px 0;
  font-size: 18px;
  line-height: 1;
}

.score-control input[type="number"] {
  text-align: center;
}

.card-edit-form > input[name="name"] {
  margin-bottom: 10px;
}

.card-edit-row {
  margin-bottom: 8px;
}

.card-edit-form .card-preview {
  margin: 2px 0 10px;
  line-height: 1.45;
}

.card-edit-form .row:last-child {
  margin-top: 2px;
}

.card-simple-item {
  display: block;
}

.card-simple-row {
  flex-wrap: nowrap;
  align-items: center;
  gap: 10px;
}

.card-simple-main {
  flex: 1;
  min-width: 0;
}

.card-thumb {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  border: 1px solid #d7e4f1;
  object-fit: cover;
  flex: 0 0 auto;
  background: #f7fbff;
  box-shadow: 0 6px 14px rgba(38, 78, 125, 0.12);
}

.card-thumb-sm {
  width: 44px;
  height: 44px;
  border-radius: 10px;
}

.bag-card-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.bag-card-main {
  flex: 1;
  min-width: 0;
}

.bag-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.bag-count {
  color: #234f86;
  font-size: 16px;
  font-weight: 700;
}

.bag-badges {
  margin-top: 4px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.rarity-普通 {
  background: #eaf4ee;
  color: #2b8a3e;
}

.rarity-稀有 {
  background: #e8f5ff;
  color: #1774b9;
}

.rarity-史诗 {
  background: #f3ebff;
  color: #7b2cbf;
}

.rarity-传说 {
  background: #fff1e6;
  color: #d9480f;
}

.type-study {
  background: #e8f5ff;
  color: #1774b9;
}

.rarity-common {
  background: #eaf4ee;
  color: #2b8a3e;
}

.rarity-rare {
  background: #e8f5ff;
  color: #1774b9;
}

.rarity-epic {
  background: #f3ebff;
  color: #7b2cbf;
}

.rarity-legend {
  background: #fff1e6;
  color: #d9480f;
}

.type-fun {
  background: #fff1e6;
  color: #d9480f;
}

.score-badge {
  background: #eef5ff;
  color: #355a84;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--nav-height);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: #ffffff;
  border-top: 1px solid var(--line);
  box-shadow: 0 -5px 18px rgba(45, 83, 126, 0.08);
}

.bottom-nav a {
  text-decoration: none;
  color: #6f859c;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 4px;
}

.bottom-nav a.active {
  color: var(--brand);
  font-weight: 700;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 16px 8px;
}

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 96px;
  background: #1d2b3a;
  color: #fff;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.toast.show {
  opacity: 0.96;
}

.draw-stage {
  position: relative;
  height: 220px;
  border-radius: 14px;
  border: 1px dashed #9fc2ed;
  background: linear-gradient(160deg, #edf6ff 0%, #fff7dd 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  margin-bottom: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.24s ease;
}

.draw-stage:hover {
  transform: translateY(-1px);
  box-shadow: inset 0 0 0 1px rgba(64, 132, 211, 0.18);
}

.draw-stage.disabled {
  opacity: 0.72;
  pointer-events: none;
}

.draw-stage-hint {
  position: absolute;
  bottom: 10px;
  color: #4a6683;
  font-size: 12px;
  font-weight: 600;
}

.draw-stage.is-opening {
  animation: drawStageFlash 0.34s ease;
}

.draw-stage.is-bursting {
  box-shadow: inset 0 0 0 1px rgba(43, 134, 246, 0.24), 0 0 0 6px rgba(43, 134, 246, 0.08);
}

.draw-burst {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.pack {
  width: 104px;
  height: 128px;
  border-radius: 12px;
  background: linear-gradient(180deg, #ff4d3a 0%, #e43a2a 100%);
  box-shadow: 0 14px 26px rgba(201, 63, 30, 0.3);
  position: relative;
  pointer-events: none;
  transform-origin: center 72%;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.pack-flap {
  position: absolute;
  left: 0;
  right: 0;
  top: -10px;
  height: 38px;
  border-radius: 12px 12px 6px 6px;
  background: linear-gradient(180deg, #ff705f 0%, #f24f3f 100%);
  box-shadow: 0 4px 10px rgba(214, 75, 47, 0.24);
  transform-origin: center bottom;
  transition: transform 0.2s ease;
}

.pack-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff8e9;
  font-size: 52px;
  font-weight: 800;
  text-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
}

.pack.opening {
  animation: packShake 0.46s ease-in-out infinite;
}

.pack.tearing .pack-flap {
  transform: rotateX(80deg) translateY(-8px);
}

.pack.opened {
  transform: scale(1.08) translateY(-8px);
  opacity: 0;
}

.draw-burst i {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 30% 30%, #fff, #ffea86 45%, #ffd454 100%);
  box-shadow: 0 0 10px rgba(255, 212, 84, 0.56);
  animation: burstDot 0.7s ease-out forwards;
  animation-delay: var(--delay, 0s);
}

@keyframes drawStageFlash {
  0% {
    box-shadow: inset 0 0 0 0 rgba(43, 134, 246, 0);
  }
  100% {
    box-shadow: inset 0 0 0 1px rgba(43, 134, 246, 0.2), 0 0 0 6px rgba(43, 134, 246, 0.07);
  }
}

@keyframes packShake {
  from {
    transform: translateX(-2px) rotate(-2deg);
  }
  to {
    transform: translateX(2px) rotate(2deg);
  }
}

@keyframes burstDot {
  from {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  to {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.2);
  }
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px;
}

.result-card {
  border-radius: 12px;
  border: 1px solid #d6e3f0;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  padding: 12px;
  transform: rotateY(90deg);
  transform-origin: center;
  animation: cardFlip 0.45s ease forwards;
  box-shadow: 0 10px 20px rgba(35, 79, 128, 0.1);
}

.draw-task-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.draw-task-main {
  flex: 1;
  min-width: 0;
}

.draw-task-badges {
  margin-top: 4px;
}

.reveal-modal-body {
  width: min(760px, calc(100% - 12px));
  max-height: min(78vh, 740px);
  overflow-y: auto;
  padding-bottom: 10px;
}

.reveal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.reveal-head h3 {
  margin: 0;
  font-size: 20px;
}

.reveal-meta {
  margin-top: 6px;
}

.reveal-grid {
  margin-top: 10px;
}

.reveal-card {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.reveal-card-main {
  flex: 1;
  min-width: 0;
}

.reveal-thumb {
  width: 96px;
  height: 96px;
  border-radius: 12px;
  flex: 0 0 auto;
}

.reveal-title {
  margin-top: 0;
  margin-bottom: 2px;
}

.reveal-badges {
  gap: 6px;
  margin-bottom: 2px;
}

body.modal-open {
  overflow: hidden;
}

@keyframes cardFlip {
  to {
    transform: rotateY(0deg);
  }
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(13, 29, 46, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal.show {
  display: flex;
}

.modal-body {
  width: min(520px, 100%);
  background: #fff;
  border-radius: 14px;
  padding: 14px;
  border: 1px solid var(--line);
}

@media (max-width: 540px) {
  .title {
    font-size: 22px;
  }
  .task-head {
    align-items: flex-start;
  }
}

@media (min-width: 920px) {
  .page {
    max-width: 1020px;
  }
  .metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .parent-scroll {
    max-height: calc(100vh - 220px);
  }
}

@media (min-width: 620px) {
  .panel-tabs {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}
