:root {
  --bg: #0b0f14;
  --bg-2: #11161d;
  --card: #161d26;
  --border: #232c38;
  --fg: #e8edf3;
  --muted: #8b98a8;
  --accent: #f0b429;
  --accent-2: #ffd45e;
  --green: #22c55e;
  --red: #ef4444;
  --blue: #3b82f6;
  --purple: #a855f7;
  --radius: 14px;
}

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

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, var(--accent-2), var(--accent) 60%, #b97f0e);
  color: #1a1205;
  font-weight: 800; font-size: 22px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 12px rgba(240,180,41,.35);
}
h1 { font-size: 18px; font-weight: 700; }
.sub { font-size: 12px; color: var(--muted); }

.icon-btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--fg);
  width: 40px; height: 40px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn .spin { display: inline-block; }
.icon-btn.loading .spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
  padding: 8px 16px;
  position: sticky; top: 0;
  background: linear-gradient(var(--bg), rgba(11,15,20,.92));
  z-index: 5;
}
.tab {
  flex: 1;
  padding: 10px 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1205;
}

/* Main */
main { flex: 1; padding: 4px 16px 24px; }
.panel { display: none; animation: fade .18s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card h2 { font-size: 16px; margin-bottom: 12px; }
.row-between { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.row-between h2 { margin-bottom: 0; }
.hint { font-size: 11px; color: var(--muted); }

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

/* Controls */
.controls { margin-bottom: 14px; }
.field { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
select {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
}
select.compact { padding: 5px 8px; font-size: 12px; }

/* Balls */
.balls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  min-height: 64px;
  align-items: center;
  padding: 10px 0;
}
.ball {
  width: 52px; height: 52px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 800;
  color: #fff;
  box-shadow: inset 0 -4px 8px rgba(0,0,0,.35), 0 3px 8px rgba(0,0,0,.4);
  animation: pop .25s ease both;
}
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
.ball.xtra {
  outline: 3px solid rgba(255,255,255,.35);
  outline-offset: 2px;
  font-size: 18px;
}
.ball-label { width: 100%; text-align: center; font-size: 11px; color: var(--muted); letter-spacing: 1px; }

.c-red { background: radial-gradient(circle at 32% 30%, #ff8a80, #e53935 65%, #b71c1c); }
.c-blue { background: radial-gradient(circle at 32% 30%, #82b1ff, #1e88e5 65%, #0d47a1); }
.c-green { background: radial-gradient(circle at 32% 30%, #b9f6ca, #43a047 65%, #1b5e20); }
.c-purple { background: radial-gradient(circle at 32% 30%, #e1bee7, #8e24aa 65%, #4a148c); }
.c-orange { background: radial-gradient(circle at 32% 30%, #ffcc80, #fb8c00 65%, #e65100); }
.c-yellow { background: radial-gradient(circle at 32% 30%, #fff59d, #f9a825 65%, #f57f17); color: #3e2c00; }
.c-pink { background: radial-gradient(circle at 32% 30%, #f8bbd0, #d81b60 65%, #880e4f); }

/* Buttons */
.predict-actions { display: flex; gap: 10px; margin-top: 12px; }
button.primary, button.ghost {
  flex: 1;
  padding: 14px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  border: none;
}
button.primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #1a1205;
}
button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  flex: 0 0 120px;
}
button:disabled { opacity: .4; cursor: not-allowed; }

/* Chart */
.chart { display: flex; flex-direction: column; gap: 3px; margin-bottom: 16px; }
.chart-row { display: flex; align-items: center; gap: 8px; }
.chart-num {
  width: 26px; height: 26px; flex: 0 0 26px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff;
}
.chart-bar-track { flex: 1; height: 10px; background: var(--bg-2); border-radius: 5px; overflow: hidden; }
.chart-bar { height: 100%; border-radius: 5px; background: linear-gradient(90deg, #2e7d32, var(--accent)); transition: width .4s ease; }
.chart-val { width: 34px; text-align: right; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

.freq-lists { display: flex; gap: 16px; }
.freq-lists > div { flex: 1; }
.freq-lists h3 { font-size: 12px; margin-bottom: 8px; }
h3.hot { color: var(--accent); }
h3.cold { color: var(--blue); }
.tagrow { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  min-width: 30px; height: 30px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff;
  padding: 0 4px;
}
.tag em { font-style: normal; opacity: .8; font-weight: 500; font-size: 10px; }

/* History */
.history { display: flex; flex-direction: column; gap: 8px; }
.hist-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.hist-date { font-size: 12px; color: var(--muted); width: 78px; flex: 0 0 78px; line-height: 1.3; }
.hist-date b { display: block; color: var(--fg); font-size: 13px; }
.hist-balls { display: flex; gap: 5px; flex-wrap: wrap; }
.mini-ball {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; color: #fff;
  box-shadow: inset 0 -3px 6px rgba(0,0,0,.3);
}
.mini-ball.xtra { outline: 2px solid rgba(255,255,255,.35); outline-offset: 1px; }

/* Footer */
.app-footer {
  display: flex;
  justify-content: space-between;
  padding: 12px 16px 20px;
  border-top: 1px solid var(--border);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--accent);
  color: #1a1205;
  font-weight: 700;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 6px 20px rgba(0,0,0,.5);
  opacity: 0;
  transition: all .3s ease;
  z-index: 50;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
