:root {
  --bg: #f6f4f2;
  --surface: #ffffff;
  --ink: #221c18;
  --muted: #7a716a;
  --line: #ebe4dd;
  --header: #4a2419;
  --header-2: #6b3828;
  --accent: #1f7a4d;
  --accent-dark: #155a39;
  --soft-red: #b94a3c;
  --year: #efb06a;
  --year-on: #ffffff;
  --red: #c62828;
  --blue: #1e56c9;
  --green: #2e7d32;
  --radius: 16px;
  --shadow: 0 6px 18px rgba(40, 24, 16, 0.06);
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: #ebe7e3;
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body.app-body {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 50px;
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  align-items: center;
  padding: 0 6px;
  background: linear-gradient(180deg, var(--header-2), var(--header));
  color: #fff8f5;
}
.hdr-title {
  margin: 0;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.03em;
}
.hdr-btn {
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 13px;
  padding: 10px 8px;
  cursor: pointer;
  opacity: 0.92;
}
.hdr-btn:active { opacity: 0.65; }

.app-main {
  padding: 12px 12px calc(28px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* 父节点切换 */
.root-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  position: sticky;
  top: 50px;
  z-index: 25;
  padding: 2px 0 4px;
  background: linear-gradient(180deg, var(--bg) 70%, transparent);
}
.root-tab {
  border: 2px solid #c9957a;
  border-radius: 14px;
  padding: 13px 8px;
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  background: #fff4ee;
  color: #6b3828;
  cursor: pointer;
  letter-spacing: 0.02em;
  line-height: 1.25;
}
.root-tab.active {
  background: linear-gradient(180deg, #6b3828, #4a2419);
  color: #fff8f5;
  border-color: #4a2419;
}
.root-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.root-panel[hidden] {
  display: none !important;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 12px;
}

.section-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}

/* Pick grid — compact recommendation cards */
.pick-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  min-height: 72px;
}
.pick-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 2px 6px;
  border-radius: 10px;
  background: #faf8f6;
  border: 1px solid var(--line);
  min-width: 0;
  text-align: center;
}
.pick-card .ball {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.12);
  position: relative;
  flex: 0 0 auto;
}
.pick-card .ball::after {
  content: "";
  position: absolute;
  top: 5px;
  left: 7px;
  width: 10px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255,255,255,0.32);
  transform: rotate(-18deg);
}
.pick-card .ball.red { background: radial-gradient(circle at 32% 28%, #ef6b6b, var(--red)); }
.pick-card .ball.blue { background: radial-gradient(circle at 32% 28%, #6f92ef, var(--blue)); }
.pick-card .ball.green { background: radial-gradient(circle at 32% 28%, #5ecf75, var(--green)); }
.pick-card .ball.sx {
  border-radius: 10px;
  font-size: 15px;
  background: #2b3648;
}
.pick-card .ball.sx::after { display: none; }

.pick-meta {
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}
.pick-meta .pct {
  font-size: 12px;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.25;
  margin-top: 1px;
}
.pick-meta .gap,
.pick-meta .stat {
  font-size: 10px;
  color: var(--muted);
  line-height: 1.3;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pick-meta .stat { color: #8a827a; }

.tray-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 28px 8px;
}

.result-summary {
  margin: 10px 2px 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
  min-height: 1.2em;
}

.tool-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.tool-btn {
  border: 1px solid #e4b5ad;
  background: #fff;
  color: var(--soft-red);
  border-radius: 9px;
  padding: 10px 0;
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}
.tool-btn:active { background: #fff6f4; }

/* Generate */
.gen-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.gen-label {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
}
.gen-select {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  font: inherit;
  background: #fff;
  color: var(--ink);
}

.gen-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.cta {
  border: 0;
  border-radius: 12px;
  padding: 14px 8px;
  font: inherit;
  font-size: 15px;
  font-weight: 750;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(180deg, #2ea56a, var(--accent));
  box-shadow: 0 3px 0 var(--accent-dark);
}
.cta:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--accent-dark);
}
.cta-dark {
  background: linear-gradient(180deg, #4a5568, #2f3a4a);
  box-shadow: 0 3px 0 #1d2430;
}
.gen-meta {
  margin: 12px 2px 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

/* Detail */
.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.detail-head h2 {
  margin: 0;
  font-size: 15px;
}
.linkish {
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.detail-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
}
.detail-row {
  display: grid;
  grid-template-columns: 26px 38px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #faf8f6;
}
.detail-row .rank {
  text-align: center;
  color: var(--muted);
  font-weight: 700;
  font-size: 12px;
}
.detail-row .info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
  min-width: 0;
}
.detail-row .info small,
.detail-row .rate small {
  color: var(--muted);
  font-size: 11px;
}
.detail-row .rate {
  text-align: right;
}
.detail-row .rate em {
  font-style: normal;
  font-weight: 800;
  color: var(--accent);
}

.lotto-ball {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 13px;
}
.lotto-ball.red { background: var(--red); }
.lotto-ball.blue { background: var(--blue); }
.lotto-ball.green { background: var(--green); }
.lotto-ball.sx {
  border-radius: 10px;
  background: #2b3648;
}

/* History */
.year-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 10px;
  scrollbar-width: none;
}
.year-tabs::-webkit-scrollbar { display: none; }
.year-tab {
  flex: 0 0 auto;
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  background: var(--year);
  color: #5a3210;
  cursor: pointer;
}
.year-tab.active {
  background: var(--year-on);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px #dfb684;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: min(60vh, 520px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.hist-head {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 7px;
}
.hist-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 5px;
}
.hist-cell {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.hist-num {
  text-align: center;
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  padding: 8px 0 7px;
  border-radius: 6px 6px 0 0;
}
.hist-num.red { background: var(--red); }
.hist-num.blue { background: var(--blue); }
.hist-num.green { background: var(--green); }
.hist-cell.tema .hist-num {
  outline: 2px solid rgba(255, 214, 120, 0.85);
  outline-offset: -2px;
}
.hist-tag {
  text-align: center;
  font-size: 10px;
  color: #6f675f;
  background: #f8f5f2;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 6px 6px;
  padding: 4px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 平码助手：列头命中次数/几率 + 期数平码/特码 */
.sx-board-card {
  padding-top: 10px;
}
.sx-board-card .year-tabs {
  margin-bottom: 8px;
  padding-bottom: 8px;
}
.sx-col-head {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr)) 40px;
  gap: 3px;
  margin-bottom: 6px;
  padding: 0 1px;
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
}
.sx-col-h {
  text-align: center;
  min-width: 0;
  line-height: 1.15;
}
.sx-col-h .n {
  display: block;
  font-size: 11px;
  font-weight: 800;
  color: var(--accent);
}
.sx-col-h .p {
  display: block;
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  opacity: 0.85;
}
.sx-col-h.tema-h {
  font-size: 11px;
  font-weight: 800;
  color: var(--soft-red);
  align-self: center;
}
.sx-board-scroll {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(100vh - 220px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 8px;
}
.sx-hist-item {
  padding-bottom: 2px;
}
.sx-rec-head {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 650;
}
.sx-rec-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr)) 40px;
  gap: 3px;
  align-items: stretch;
}
.sx-cell .sx-box,
.sx-tema .sx-box {
  text-align: center;
  color: #fff;
  font-weight: 800;
  border-radius: 5px;
  min-width: 0;
}
.sx-cell .sx-box {
  font-size: 12px;
  padding: 9px 0;
  background: var(--green);
}
.sx-cell.hit .sx-box {
  background: var(--red);
}
.sx-tema .sx-box {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
  font-size: 12px;
  padding: 4px 0;
  min-height: 34px;
  background: var(--red);
  line-height: 1.1;
}
.sx-tema .sx-box small {
  font-size: 9px;
  font-weight: 700;
  opacity: 0.95;
}
.sx-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
}
.sx-pager .pg-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  font: inherit;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
  color: var(--ink);
}
.sx-pager .pg-btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.sx-pager .pg-info {
  font-size: 12px;
  color: var(--muted);
}

.footnote {
  margin: 2px 4px 0;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}
.empty {
  padding: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* Login */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background:
    radial-gradient(800px 380px at 50% -8%, #c9a796 0%, transparent 55%),
    linear-gradient(180deg, #6b3828 0%, #3a1b13 42%, #f6f4f2 42%);
}
.login-wrap { width: 100%; max-width: 390px; }
.login-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow);
}
.login-card .brand {
  margin: 0;
  text-align: center;
  font-size: 22px;
  color: var(--header);
}
.login-card .sub {
  margin: -4px 0 2px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
.login-field input {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  font: inherit;
  font-size: 15px;
  background: #fff;
  color: var(--ink);
}
.login-field input:focus {
  outline: 2px solid rgba(74, 36, 25, 0.16);
  border-color: #b98978;
}
.login-submit {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 13px;
  font: inherit;
  font-size: 16px;
  font-weight: 750;
  color: #fff;
  background: linear-gradient(180deg, #6b3828, var(--header));
  cursor: pointer;
  margin-top: 2px;
}
.login-error { margin: 0; color: var(--red); font-size: 13px; }
.login-tip {
  margin: 0;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

@media (min-width: 480px) {
  body.app-body {
    margin-top: 16px;
    margin-bottom: 16px;
    border-radius: 18px;
    overflow-x: hidden;
    overflow-y: auto;
    max-height: calc(100vh - 32px);
    min-height: calc(100vh - 32px);
    box-shadow: 0 12px 40px rgba(40, 24, 16, 0.12);
  }
}
