:root {
  --blue:     #4296E0;
  --blue2:    #5B7FFF;
  --green:    #2ecc71;
  --yellow:   #f1c40f;
  --orange:   #f39c12;
  --red:      #e74c3c;
  --purple:   #9b59b6;
  --bg:       #F0F4F8;
  --surface:  #FFFFFF;
  --text-1:   #0F1623;
  --text-2:   #4A5568;
  --text-3:   #8B95A8;
  --border:   #E2E8F0;
  --radius:   18px;
  --radius-sm:12px;
  --shadow:   0 2px 12px rgba(15,22,35,0.08), 0 1px 3px rgba(15,22,35,0.05);
  --shadow-lg:0 8px 32px rgba(15,22,35,0.12), 0 2px 8px rgba(15,22,35,0.06);
}

.mono { font-family: var(--mono); font-size: 12px; white-space: nowrap;}

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

html {
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, 'SF Pro Display', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text-1);
  min-height: 100vh;
  max-width: 430px;
  margin: 0 auto;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ══════ HEADER ══════ */
.header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 14px 18px 10px;
  padding-top: calc(14px + env(safe-area-inset-top));
}
.header-inner {
  display: flex; justify-content: space-between; align-items: center;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.back-btn {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--bg); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2); text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.back-btn svg { width: 18px; height: 18px; }
.header-title { font-size: 18px; font-weight: 700; color: var(--text-1); line-height: 1.2; }
.header-sub   { font-size: 12px; color: var(--text-3); }
.header-right { display: flex; gap: 8px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--bg); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2); transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:active { background: var(--border); }
.header-clock {
  font-size: 11px; color: var(--text-3);
  margin-top: 6px; letter-spacing: 0.03em;
}

/* ══════ LOADING ══════ */
.loading-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px;
}
.loading-spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay p { font-size: 14px; color: var(--text-3); }
.loading-overlay.hidden { display: none; }

/* ══════ MAIN ══════ */
.main {
  padding: 20px 16px 0;
  transition: opacity 0.4s ease;
}
.main.visible { opacity: 1 !important; }

/* ══════ SECTIONS ══════ */
.section { margin-bottom: 24px; }
.section-label {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-3); margin-bottom: 10px; padding-left: 2px;
}

/* ══════ ANIMATION ══════ */
.anim-card {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.5s ease var(--delay, 0s),
              transform 0.5s ease var(--delay, 0s);
}
.anim-card.visible {
  opacity: 1; transform: translateY(0);
}

/* ══════ SUMMARY CARDS ══════ */
.cards-scroll {
  display: flex; gap: 12px;
  overflow-x: auto; padding-bottom: 8px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.cards-scroll::-webkit-scrollbar { display: none; }

.sum-card {
  flex: 0 0 130px; padding: 16px 14px 12px;
  border-radius: var(--radius);
  display: flex; flex-direction: column; gap: 4px;
  scroll-snap-align: start;
  color: white; position: relative; overflow: hidden;
  opacity: 0; transform: translateY(16px);
  animation: cardIn 0.5s ease var(--delay, 0s) forwards;
  box-shadow: var(--shadow);
}
@keyframes cardIn {
  to { opacity: 1; transform: translateY(0); }
}
.sum-card::before {
  content: ''; position: absolute;
  top: -20px; right: -20px;
  width: 80px; height: 80px; border-radius: 50%;
  background: rgba(255,255,255,0.12);
}
.sum-card.blue   { background: linear-gradient(135deg, #4296E0, #2E7BC4); }
.sum-card.green  { background: linear-gradient(135deg, #2ecc71, #27ae60); }
.sum-card.orange { background: linear-gradient(135deg, #f39c12, #d68910); }
.sum-card.blue2  { background: linear-gradient(135deg, #5B7FFF, #4160d9); }
.sum-card.yellow { background: linear-gradient(135deg, #f1c40f, #d4ac0d); }
.sum-card.red    { background: linear-gradient(135deg, #e74c3c, #c0392b); }

.sum-card-icon { width: 28px; height: 28px; opacity: 0.85; }
.sum-card-icon svg { width: 100%; height: 100%; }
.sum-card-num {
  font-size: 28px; font-weight: 800;
  line-height: 1; margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.sum-card-label { font-size: 11px; opacity: 0.85; font-weight: 500; }
.sum-card-bar {
  height: 4px; background: rgba(255,255,255,0.25);
  border-radius: 99px; margin-top: 8px; overflow: hidden;
}
.sum-card-fill {
  height: 100%; border-radius: 99px;
  background: rgba(255,255,255,0.7);
  width: 0%; transition: width 1.2s cubic-bezier(0.34,1.56,0.64,1);
}

/* ══════ CHART CARD ══════ */
.chart-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.chart-wrap { position: relative; height: 220px; width: 100%; }

/* ══════ PIE ══════ */
.pie-card { display: flex; flex-direction: column; gap: 16px; }
.pie-wrap { position: relative; height: 200px; width: 100%; }
.pie-legend {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.legend-item {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-2);
}
.legend-dot {
  width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0;
}

/* ══════ LEADERBOARD ══════ */
.leaderboard {
  margin-top: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.lb-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  opacity: 0; transform: translateX(-12px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.lb-item.visible { opacity: 1; transform: translateX(0); }
.lb-rank {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; flex-shrink: 0;
}
.lb-rank.gold   { background: #FEF3C7; color: #D97706; }
.lb-rank.silver { background: #F3F4F6; color: #6B7280; }
.lb-rank.bronze { background: #FEF0E6; color: #C2410C; }
.lb-rank.other  { background: var(--bg); color: var(--text-3); }
.lb-name { flex: 1; font-size: 14px; font-weight: 600; color: var(--text-1); }
.lb-count { font-size: 13px; font-weight: 700; color: var(--blue); }
.lb-bar-wrap { width: 100%; height: 4px; background: var(--bg); border-radius: 99px; margin-top: 4px; overflow: hidden; }
.lb-bar { height: 100%; border-radius: 99px; background: var(--blue); transition: width 1s ease; }

/* ══════ INSIGHTS ══════ */
.insights-wrap { display: flex; flex-direction: column; gap: 10px; }
.insight-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex; align-items: flex-start; gap: 12px;
  box-shadow: var(--shadow);
  border-left: 4px solid transparent;
}
.insight-card.good   { border-left-color: var(--green); }
.insight-card.warn   { border-left-color: var(--yellow); }
.insight-card.danger { border-left-color: var(--red); }
.insight-icon {
  width: 36px; height: 36px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.insight-icon svg { width: 18px; height: 18px; }
.insight-card.good   .insight-icon { background: #D1FAE5; color: #059669; }
.insight-card.warn   .insight-icon { background: #FEF9C3; color: #CA8A04; }
.insight-card.danger .insight-icon { background: #FEE2E2; color: #DC2626; }
.insight-title { font-size: 13px; font-weight: 700; color: var(--text-1); margin-bottom: 3px; }
.insight-desc  { font-size: 12px; color: var(--text-2); line-height: 1.5; }
.insight-badge {
  margin-top: 6px; display: inline-block;
  padding: 2px 10px; border-radius: 99px;
  font-size: 11px; font-weight: 700;
}
.badge-good   { background: #D1FAE5; color: #059669; }
.badge-warn   { background: #FEF9C3; color: #CA8A04; }
.badge-danger { background: #FEE2E2; color: #DC2626; }

#suspicious-table-div {
  position: relative;
  width: auto;
  height: auto;
  top: 0;
  left: 0;
  margin-top: 10px;
  justify-content: center;
  align-items: center;
  display: none;
}

.table-scroll { overflow-x: auto; }

.data-table {
  width: 100%; border-collapse: collapse;
  font-size: 13px;
}
.data-table thead tr {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.data-table th {
  padding: 10px 16px; text-align: left;
  font-size: 11px; font-weight: 600;
  color: var(--text-3); text-transform: uppercase; letter-spacing: 0.05em;
  white-space: nowrap;
}
.data-table td {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  color: var(--text-1); vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg); }
.data-table .table-loading {
  text-align: center; padding: 40px; color: var(--text-3);
  font-style: italic;
}

.table-scroll caption {
  display: table-caption;
  caption-side: top;
  margin-bottom: 8px;
  margin-top: 8px;
  font-family: var(--mono, monospace);
  font-size: 16px; 
  color: var(--text-2);
  text-align: center;
}

/* ══════ PREDICTIONS ══════ */
.prediction-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.pred-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 16px 14px;
  box-shadow: var(--shadow);
  text-align: center;
}
.pred-card.full { grid-column: 1 / -1; }
.pred-icon {
  width: 36px; height: 36px; margin: 0 auto 8px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}
.pred-icon svg { width: 18px; height: 18px; }
.pred-num  { font-size: 22px; font-weight: 800; color: var(--text-1); line-height: 1.1; }
.pred-label{ font-size: 11px; color: var(--text-3); margin-top: 3px; font-weight: 500; }

/* ══════ RECOMMENDATIONS ══════ */
.recs-wrap { display: flex; flex-direction: column; gap: 10px; }
.rec-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex; gap: 12px; align-items: flex-start;
  box-shadow: var(--shadow);
  opacity: 0; transform: translateY(10px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.rec-card.visible { opacity: 1; transform: translateY(0); }
.rec-num {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--blue2));
  color: white; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.rec-text { font-size: 13px; color: var(--text-2); line-height: 1.6; }
.rec-text strong { color: var(--text-1); }

/* ══════ TOAST ══════ */
.toast-wrap {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 200;
  pointer-events: none; width: 90%; max-width: 380px;
}
.toast {
  background: var(--text-1); color: #fff;
  padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s ease;
  display: flex; align-items: center; gap: 8px;
}
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastOut {
  to   { opacity: 0; transform: translateY(4px) scale(0.97); }
}

/* ══════ CHART GLOBAL OVERRIDES ══════ */
canvas { display: block; }
