:root {
  color-scheme: light;
  --bg: #f4f1ec;
  --card: #fffdf9;
  --ink: #25231f;
  --muted: #74716a;
  --line: #e6e0d8;
  --accent: #a85f3f;
  --accent-deep: #77422d;
  --accent-soft: #f3dfd5;
  --accent-line: #dfc3b4;
  --gold: #b88743;
  --ok: #52765c;
  --warn: #ad6c32;
  --bad: #ad443b;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-pill: 999px;
  --shadow: 0 12px 34px rgba(73, 57, 43, 0.07);
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at 15% -6%, rgba(196, 132, 94, 0.09), transparent 30%),
    var(--bg);
  color: var(--ink);
  font-family: "Noto Sans CJK SC", "Noto Sans SC", "Microsoft YaHei",
    "PingFang SC", "Hiragino Sans GB", sans-serif;
  line-height: 1.55;
  padding-bottom: env(safe-area-inset-bottom);
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

.splash {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 7px;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 40%, rgba(168, 95, 63, 0.11), transparent 30%),
    var(--bg);
  transition: opacity 0.28s ease, visibility 0.28s ease;
}

.splash.is-leaving {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-mark {
  width: 66px;
  height: 66px;
  display: grid;
  place-items: center;
  margin-bottom: 5px;
  border-radius: 19px;
  background: linear-gradient(145deg, #c87855, #894e37);
  color: #fffaf4;
  font-size: 26px;
  font-weight: 750;
  box-shadow: 0 14px 30px rgba(114, 63, 42, 0.2);
}

.splash strong {
  font-size: 20px;
  letter-spacing: 0.02em;
}

.splash span {
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: 0.1em;
}

.app-shell {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: calc(82px + env(safe-area-inset-top)) 14px
    calc(108px + env(safe-area-inset-bottom));
}

.topbar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 40;
  padding: calc(9px + env(safe-area-inset-top)) 14px 9px;
  border-bottom: 1px solid rgba(230, 224, 216, 0.8);
  background: rgba(244, 241, 236, 0.9);
  backdrop-filter: blur(18px) saturate(1.08);
  -webkit-backdrop-filter: blur(18px) saturate(1.08);
}

.brand {
  width: min(100%, 692px);
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 auto;
}

.brand-mark {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(145deg, #c87855, #894e37);
  color: #fffaf4;
  font-size: 18px;
  font-weight: 750;
  box-shadow: 0 7px 18px rgba(118, 66, 44, 0.16);
}

.brand-copy {
  min-width: 0;
}

.brand-copy h1 {
  margin: 0;
  font-size: 21px;
  line-height: 1.25;
  font-weight: 760;
}

.brand-copy p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11.5px;
}

.main {
  min-width: 0;
}

.page {
  display: grid;
  gap: 12px;
}

.status-line {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 2px 0;
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
}

.status-line strong {
  color: var(--accent-deep);
  font-size: 12px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(82, 118, 92, 0.1);
}

.status-separator {
  color: #b5afa7;
}

.status-spacer {
  flex: 1;
}

.hero-card,
.panel,
.quick-card {
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--card);
  box-shadow: var(--shadow);
}

.hero-card {
  position: relative;
  overflow: hidden;
  padding: 18px;
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 100% 0, rgba(168, 95, 63, 0.12), transparent 36%),
    linear-gradient(150deg, #fffdf9, #fbf6f0);
}

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

.hero-head div {
  display: grid;
  gap: 2px;
}

.hero-head span {
  color: var(--muted);
  font-size: 11px;
}

.hero-head strong {
  color: var(--ink);
  font-size: 17px;
  font-weight: 730;
}

.soft-pill {
  flex: 0 0 auto;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: 10.5px;
  font-weight: 700;
}

.digit-stage {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0 17px;
}

.digit-block {
  min-width: 0;
  display: grid;
  place-items: center;
  gap: 5px;
  padding: 14px 6px 12px;
  border: 1px solid rgba(223, 195, 180, 0.86);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
}

.digit-block span {
  color: var(--muted);
  font-size: 10px;
}

.digit-block strong {
  color: var(--accent-deep);
  font-size: 42px;
  line-height: 1;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.hero-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding-top: 13px;
  border-top: 1px solid rgba(223, 195, 180, 0.56);
}

.hero-metrics div {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.hero-metrics span {
  color: var(--muted);
  font-size: 9.5px;
}

.hero-metrics strong {
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.quick-card {
  display: grid;
  gap: 3px;
  padding: 13px 14px;
  border-radius: 17px;
  box-shadow: 0 8px 24px rgba(73, 57, 43, 0.045);
}

.quick-card > span {
  color: var(--muted);
  font-size: 10.5px;
}

.quick-card strong {
  color: var(--ink);
  font-size: 20px;
  font-weight: 720;
  font-variant-numeric: tabular-nums;
}

.quick-card small {
  min-height: 1.35em;
  color: var(--muted);
  font-size: 9.5px;
}

.panel {
  padding: 16px;
  border-radius: var(--radius-lg);
}

.panel-first {
  margin-top: 2px;
}

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

.section-head h2 {
  margin: 0;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.35;
  font-weight: 730;
}

.section-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.55;
}

.text-button {
  flex: 0 0 auto;
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: var(--accent-deep);
  font-size: 11px;
  cursor: pointer;
}

.recent-list {
  display: grid;
  gap: 1px;
  margin-top: 10px;
}

.recent-row {
  display: grid;
  grid-template-columns: minmax(74px, 0.75fr) minmax(0, 1.7fr) auto;
  align-items: center;
  gap: 9px;
  padding: 9px 2px;
  border-bottom: 1px dashed #ece6de;
}

.recent-row:last-child {
  border-bottom: 0;
}

.recent-period {
  color: var(--muted);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}

.number-balls {
  display: flex;
  gap: 5px;
}

.number-ball {
  width: 29px;
  height: 29px;
  display: grid;
  place-items: center;
  border: 1px solid #ead9ce;
  border-radius: 50%;
  background: #fff9f4;
  color: var(--accent-deep);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.recent-meta {
  color: var(--muted);
  font-size: 9.5px;
  text-align: right;
  white-space: nowrap;
}

.segmented {
  display: grid;
  gap: 4px;
  margin-top: 12px;
  padding: 4px;
  border-radius: var(--radius-pill);
  background: #efebe5;
}

.compact-pills {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.segmented button {
  min-width: 0;
  padding: 7px 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, color 0.15s ease;
}

.segmented button.active {
  border-color: rgba(168, 95, 63, 0.12);
  background: #f3dfd5;
  color: var(--accent-deep);
  font-weight: 750;
  box-shadow: 0 1px 2px rgba(75, 56, 42, 0.06);
}

.segmented button:active {
  transform: scale(0.98);
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 9px 13px;
  margin: 11px 2px 7px;
  color: var(--muted);
  font-size: 9px;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.legend-dot {
  width: 14px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
}

.legend-dot.actual { background: #25231f; }
.legend-dot.ma5 { background: #bc6849; }
.legend-dot.ma10 { background: #7e8d68; }
.legend-dot.ma20 { background: #b08a48; }

.chart-frame {
  min-height: 290px;
  margin-top: 3px;
}

.trend-svg {
  width: 100%;
  height: auto;
  overflow: visible;
}

.trend-svg .grid-line {
  stroke: #e9e3db;
  stroke-width: 1;
}

.trend-svg .axis-label {
  fill: var(--muted);
  font-size: 9px;
}

.trend-svg .period-label {
  fill: var(--muted);
  font-size: 8.5px;
  text-anchor: middle;
}

.trend-svg .actual-line {
  fill: none;
  stroke: #25231f;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.trend-svg .actual-dot {
  fill: #fffdf9;
  stroke: #25231f;
  stroke-width: 1.4;
}

.trend-svg .ma5-line {
  fill: none;
  stroke: #bc6849;
  stroke-width: 1.7;
}

.trend-svg .ma10-line {
  fill: none;
  stroke: #7e8d68;
  stroke-width: 1.7;
}

.trend-svg .ma20-line {
  fill: none;
  stroke: #b08a48;
  stroke-width: 1.9;
}

.distribution-chart {
  display: grid;
  grid-template-columns: repeat(28, minmax(0, 1fr));
  align-items: end;
  gap: 2px;
  min-height: 168px;
  margin-top: 14px;
  padding-top: 9px;
  border-bottom: 1px solid var(--line);
}

.dist-column {
  min-width: 0;
  height: 142px;
  display: grid;
  grid-template-rows: 1fr auto;
  align-items: end;
  gap: 5px;
}

.dist-bar-wrap {
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.dist-bar {
  width: min(80%, 13px);
  min-height: 2px;
  border-radius: 5px 5px 2px 2px;
  background: linear-gradient(180deg, #c87957, #a65d3f);
}

.dist-label {
  color: var(--muted);
  font-size: 7px;
  text-align: center;
}

.footnote {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.55;
}

.position-grid {
  display: grid;
  gap: 16px;
  margin-top: 13px;
}

.position-block {
  display: grid;
  gap: 8px;
}

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

.position-title strong {
  font-size: 12px;
}

.position-title span {
  color: var(--muted);
  font-size: 9.5px;
}

.digit-frequency {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 3px;
  align-items: end;
}

.digit-frequency div {
  min-width: 0;
  display: grid;
  justify-items: center;
  gap: 4px;
}

.digit-frequency i {
  width: 100%;
  min-height: 3px;
  border-radius: 4px 4px 2px 2px;
  background: #d9a285;
}

.digit-frequency span {
  color: var(--muted);
  font-size: 8px;
}

.structure-kpis {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.structure-kpis div {
  display: grid;
  gap: 2px;
  padding: 10px;
  border-radius: 12px;
  background: #f8f4ef;
}

.structure-kpis span {
  color: var(--muted);
  font-size: 9.5px;
}

.structure-kpis strong {
  font-size: 16px;
}

.span-bars {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 4px;
  align-items: end;
  min-height: 120px;
  margin-top: 14px;
}

.span-column {
  display: grid;
  gap: 4px;
  align-items: end;
  justify-items: center;
}

.span-column i {
  width: 100%;
  min-height: 3px;
  border-radius: 5px 5px 2px 2px;
  background: #b78c5c;
}

.span-column span {
  color: var(--muted);
  font-size: 8px;
}

.note-panel {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.note-mark {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-family: Georgia, serif;
  font-size: 12px;
  font-weight: 700;
}

.note-panel strong {
  font-size: 12px;
}

.note-panel p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.55;
}

.data-summary,
.settings-list {
  display: grid;
  margin-top: 12px;
}

.data-summary > div,
.settings-list > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 11.5px;
}

.data-summary > div:last-child,
.settings-list > div:last-child {
  border-bottom: 0;
}

.data-summary span,
.settings-list span {
  color: var(--muted);
}

.data-summary strong,
.settings-list strong {
  color: var(--ink);
  text-align: right;
}

.action-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.primary-button,
.secondary-button,
.file-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 13px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
}

.primary-button {
  border: 1px solid rgba(168, 95, 63, 0.16);
  background: #f0d8cc;
  color: var(--accent-deep);
}

.secondary-button {
  border: 1px solid var(--line);
  background: #f7f3ee;
  color: var(--muted);
}

.primary-button:active,
.secondary-button:active,
.file-button:active {
  transform: scale(0.98);
}

.draw-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 9px;
  margin-top: 12px;
}

.field {
  display: grid;
  gap: 4px;
}

.field label {
  color: var(--muted);
  font-size: 10.5px;
}

.field input {
  width: 100%;
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  background: #fff;
  color: var(--ink);
  font-size: 16px;
}

.field input:focus {
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px rgba(168, 95, 63, 0.1);
}

.draw-form .primary-button {
  grid-column: 1 / -1;
}

.data-message {
  min-height: 1.2em;
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.5;
}

.local-data-status {
  margin-top: 8px;
  padding: 9px 10px;
  border-radius: 11px;
  background: #f8f4ef;
  color: var(--muted);
  font-size: 10.5px;
}

.install-button {
  width: 100%;
  margin-top: 10px;
}

.tabbar {
  position: fixed;
  left: 50%;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 50;
  width: min(calc(100% - 24px), 696px);
  transform: translateX(-50%);
}

.tabbar-inner,
.tabbar {
  pointer-events: none;
}

.tabbar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 2px;
  padding: 6px 8px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: var(--radius-pill);
  background: rgba(255, 253, 249, 0.84);
  box-shadow: 0 10px 28px rgba(72, 55, 42, 0.13);
  backdrop-filter: blur(18px) saturate(1.12);
  -webkit-backdrop-filter: blur(18px) saturate(1.12);
  pointer-events: auto;
}

.tab {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 7px 3px 6px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, color 0.15s ease;
}

.tab svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab[data-tab="home"].active svg {
  fill: currentColor;
  fill-opacity: 0.14;
}

.tab.active {
  background: #f1ddd2;
  color: var(--accent-deep);
  font-weight: 750;
}

.tab:active {
  transform: scale(0.98);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(104px + env(safe-area-inset-bottom));
  z-index: 90;
  max-width: calc(100% - 32px);
  padding: 9px 14px;
  border-radius: var(--radius-pill);
  background: rgba(38, 35, 31, 0.9);
  color: #fffdf9;
  font-size: 11px;
  box-shadow: 0 10px 24px rgba(44, 35, 28, 0.16);
  transform: translateX(-50%);
}

@media (max-width: 380px) {
  .app-shell {
    padding-left: 11px;
    padding-right: 11px;
  }

  .status-line {
    font-size: 10.5px;
  }

  .digit-block strong {
    font-size: 37px;
  }

  .quick-card strong {
    font-size: 18px;
  }

  .recent-row {
    grid-template-columns: 70px minmax(0, 1fr);
  }

  .recent-meta {
    grid-column: 2;
    text-align: left;
  }

  .number-ball {
    width: 27px;
    height: 27px;
  }

  .panel,
  .hero-card {
    padding: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
