:root {
  color-scheme: dark;
  --bg: #07111f;
  --surface: #0d1928;
  --surface-2: #122235;
  --line: #20364f;
  --muted: #7f97b4;
  --text: #f4f8ff;
  --blue: #50a6ff;
  --blue-2: #1c74ff;
  --green: #2fd46c;
  --red: #ff5262;
  --purple: #a06cff;
  --orange: #ffba55;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--bg); min-height: 100%; overscroll-behavior: none; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100%;
  background:
    radial-gradient(circle at 85% -10%, rgba(37, 111, 255, .21), transparent 32rem),
    linear-gradient(180deg, #07111f 0%, #081321 100%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; }
button { touch-action: manipulation; }

.app-shell { max-width: 760px; min-height: 100dvh; margin: 0 auto; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  min-height: calc(64px + var(--safe-top));
  padding: calc(12px + var(--safe-top)) 18px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(7, 17, 31, .86);
  border-bottom: 1px solid rgba(75, 113, 151, .22);
  backdrop-filter: blur(18px) saturate(135%);
  -webkit-backdrop-filter: blur(18px) saturate(135%);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 11px;
  background: linear-gradient(145deg, #64b8ff, #1c72ff);
  color: white;
  font-size: 21px;
  font-weight: 900;
  box-shadow: 0 8px 24px rgba(34, 125, 255, .34);
}

.brand-copy { display: flex; flex: 1; flex-direction: column; line-height: 1.05; }
.brand-copy strong { color: var(--blue); font-size: 17px; letter-spacing: .04em; }
.brand-copy span { color: var(--muted); font-size: 8px; letter-spacing: .16em; margin-top: 4px; }

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--blue);
  font-size: 21px;
}

.offline-badge { color: var(--orange); font-size: 10px; font-weight: 800; letter-spacing: .08em; }

main { padding-bottom: calc(96px + var(--safe-bottom)); }
.page { display: none; padding: 22px 16px 28px; animation: page-in .2s ease-out; }
.page.active { display: block; }
@keyframes page-in { from { opacity: 0; transform: translateY(4px); } }

.hero-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.eyebrow { margin: 0 0 7px; color: var(--blue); font-size: 10px; font-weight: 850; letter-spacing: .12em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(23px, 7vw, 32px); line-height: 1.08; letter-spacing: -.025em; }
h2 { margin-bottom: 0; font-size: 18px; line-height: 1.25; }

.round-pill {
  flex: none;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(15, 31, 50, .8);
  color: var(--muted);
  font-size: 9px;
  letter-spacing: .1em;
}
.round-pill strong { color: var(--text); }

.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.metric-card {
  min-width: 0;
  padding: 12px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(150deg, rgba(18, 34, 53, .96), rgba(10, 23, 38, .96));
  box-shadow: 0 10px 28px rgba(0, 0, 0, .12);
}
.metric-card span { display: block; overflow: hidden; color: var(--muted); font-size: 8px; letter-spacing: .05em; white-space: nowrap; }
.metric-card strong { display: block; margin-top: 7px; overflow: hidden; color: var(--blue); font-size: 21px; text-overflow: ellipsis; }
.metric-card strong.positive { color: var(--green); }
.metric-card strong.purple, .purple { color: var(--purple); }

.chart-card, .prediction-box, .result-card, .panel, .dataset-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(155deg, rgba(14, 29, 47, .98), rgba(9, 21, 35, .98));
  box-shadow: 0 16px 40px rgba(0, 0, 0, .14);
}
.chart-card { overflow: hidden; margin-bottom: 12px; }
.chart-toolbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 13px 7px; }
.symbol { font-weight: 850; font-size: 13px; }
.timeframe { margin-left: 6px; padding: 3px 6px; border-radius: 5px; background: #1b3048; color: var(--muted); font-size: 9px; }
.legend { display: flex; gap: 9px; font-size: 9px; }
.legend-fast { color: #ff6a62; }
.legend-slow { color: #52e1e3; }

.chart-wrap { position: relative; width: 100%; height: min(62vw, 360px); min-height: 250px; }
#chart { display: block; width: 100%; height: 100%; touch-action: pan-y; }
.chart-loading { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px; background: #0a1624; color: var(--muted); font-size: 12px; }
.chart-loading[hidden] { display: none; }
.spinner { width: 28px; height: 28px; border: 2px solid #28405b; border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.ohlc-row { min-height: 31px; padding: 7px 12px 9px; overflow: hidden; border-top: 1px solid rgba(45, 70, 97, .45); color: var(--muted); font: 9px ui-monospace, SFMono-Regular, Menlo, monospace; white-space: nowrap; text-overflow: ellipsis; }

.prediction-box, .result-card, .panel { padding: 16px; }
.prediction-box { margin-bottom: 12px; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-heading.compact { margin-bottom: 18px; }
.reward-note { flex: none; color: var(--muted); font-size: 9px; line-height: 1.4; }
.direction-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.direction-button {
  min-height: 76px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid;
  border-radius: 15px;
  color: white;
  transition: transform .12s ease, filter .12s ease;
}
.direction-button:active { transform: scale(.97); filter: brightness(1.14); }
.direction-button:disabled { opacity: .48; }
.direction-button.buy { border-color: rgba(47, 212, 108, .38); background: linear-gradient(145deg, rgba(34, 174, 91, .24), rgba(19, 75, 48, .28)); }
.direction-button.sell { border-color: rgba(255, 82, 98, .38); background: linear-gradient(145deg, rgba(214, 57, 75, .25), rgba(80, 26, 37, .3)); }
.direction-icon { font-size: 30px; line-height: 1; }
.buy .direction-icon, .buy strong { color: var(--green); }
.sell .direction-icon, .sell strong { color: var(--red); }
.direction-button span:last-child { display: flex; flex-direction: column; align-items: flex-start; }
.direction-button strong { font-size: 19px; }
.direction-button small { color: var(--muted); font-size: 10px; margin-top: 3px; }

.result-card { margin-bottom: 12px; }
.result-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 13px; }
.result-status { margin-bottom: 5px; color: var(--green); font-size: 10px; font-weight: 850; letter-spacing: .1em; }
.result-status.wrong { color: var(--red); }
.result-xp { padding: 7px 10px; border-radius: 10px; background: rgba(47, 212, 108, .12); color: var(--green); }
.result-xp.wrong { background: rgba(255, 82, 98, .12); color: var(--red); }
.versus-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; margin-bottom: 12px; }
.versus-row div { padding: 12px 8px; display: flex; flex-direction: column; align-items: center; border: 1px solid var(--line); border-radius: 12px; background: rgba(6, 15, 26, .55); }
.versus-row span { color: var(--muted); font-size: 8px; letter-spacing: .07em; }
.versus-row strong { margin-top: 5px; font-size: 17px; }
.versus-row .arrow { color: var(--blue); font-size: 17px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.detail-grid div { padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: rgba(5, 15, 26, .5); }
.detail-grid span { display: block; color: var(--muted); font-size: 8px; }
.detail-grid strong { display: block; margin-top: 5px; font-size: 13px; }
.explanation { margin-top: 10px; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; background: rgba(14, 27, 43, .7); }
.explanation summary { padding: 12px 0; color: var(--blue); font-size: 11px; font-weight: 750; }
.explanation p { margin-bottom: 9px; color: #b8c8db; font-size: 12px; line-height: 1.55; }
.explanation ul { margin: 0 0 12px; padding-left: 18px; color: #b8c8db; font-size: 12px; line-height: 1.55; }

.primary-button, .secondary-button, .danger-button, .file-button {
  min-height: 48px;
  display: inline-grid;
  place-items: center;
  border-radius: 13px;
  font-size: 12px;
  font-weight: 850;
  letter-spacing: .03em;
}
.primary-button { width: 100%; margin-top: 12px; border: 0; background: linear-gradient(135deg, #59b1ff, #287dff); color: #041121; box-shadow: 0 10px 28px rgba(42, 128, 255, .24); }
.secondary-button { border: 1px solid var(--line); background: var(--surface); color: var(--text); }

.stats-overview { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-bottom: 12px; }
.overview-card { padding: 15px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); }
.overview-card span { color: var(--muted); font-size: 9px; }
.overview-card strong { display: block; margin-top: 6px; font-size: 23px; }
.panel { margin-bottom: 12px; }
.direction-stats { display: grid; gap: 17px; }
.direction-row-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 7px; font-size: 12px; }
.direction-row-header span { color: var(--muted); }
.bar-track { height: 8px; overflow: hidden; border-radius: 99px; background: #071321; }
.bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, #3186ff, #57beff); }
.empty-state { padding: 18px 4px; color: var(--muted); font-size: 12px; text-align: center; }
.history-list { display: grid; gap: 8px; }
.history-item { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 9px; padding: 10px; border: 1px solid var(--line); border-radius: 11px; }
.history-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); box-shadow: 0 0 12px rgba(47, 212, 108, .5); }
.history-item.wrong .history-dot { background: var(--red); box-shadow: 0 0 12px rgba(255, 82, 98, .5); }
.history-item div { display: flex; flex-direction: column; }
.history-item span { font-size: 11px; }
.history-item small { margin-top: 2px; color: var(--muted); font-size: 9px; }
.history-item strong { color: var(--green); font-size: 11px; }
.history-item.wrong strong { color: var(--red); }

.dataset-card { display: flex; align-items: center; gap: 13px; padding: 15px; margin-bottom: 12px; }
.dataset-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 13px; background: rgba(67, 157, 255, .14); color: var(--blue); font-size: 23px; }
.dataset-card div:last-child { min-width: 0; display: flex; flex-direction: column; }
.dataset-card span { color: var(--muted); font-size: 8px; }
.dataset-card strong { margin-top: 4px; overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.dataset-card small { margin-top: 4px; color: var(--green); }
.import-panel > p:not(.eyebrow), .danger-panel > p:not(.eyebrow), .install-help li { color: #9eb0c5; font-size: 12px; line-height: 1.55; }
.file-button { width: 100%; margin-top: 10px; border: 1px solid rgba(80, 166, 255, .45); background: rgba(44, 126, 255, .15); color: var(--blue); }
.help-note { margin: 12px 0 0; color: var(--muted) !important; font-size: 10px !important; }
.import-progress { margin-top: 14px; }
.import-progress div { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; }
progress { width: 100%; height: 7px; margin-top: 7px; border: 0; border-radius: 20px; overflow: hidden; accent-color: var(--blue); }
.danger-text { color: var(--red); }
.danger-button { border: 1px solid rgba(255, 82, 98, .42); background: rgba(255, 82, 98, .12); color: var(--red); }
.danger-panel .danger-button { width: 100%; margin-top: 5px; }
.install-help ol { margin-bottom: 0; padding-left: 20px; }
.install-help li + li { margin-top: 5px; }

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 60;
  width: min(100%, 760px);
  min-height: calc(68px + var(--safe-bottom));
  padding: 7px 20px calc(7px + var(--safe-bottom));
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  transform: translateX(-50%);
  border-top: 1px solid rgba(68, 102, 137, .26);
  background: rgba(8, 19, 32, .9);
  backdrop-filter: blur(20px) saturate(135%);
  -webkit-backdrop-filter: blur(20px) saturate(135%);
}
.nav-button { min-height: 51px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border: 0; background: transparent; color: #66809c; }
.nav-button span { font-size: 21px; }
.nav-button small { font-size: 9px; }
.nav-button.active { color: var(--blue); }

.toast { position: fixed; left: 50%; bottom: calc(84px + var(--safe-bottom)); z-index: 90; width: max-content; max-width: calc(100% - 32px); padding: 11px 15px; transform: translate(-50%, 20px); border: 1px solid var(--line); border-radius: 12px; background: #172a3e; box-shadow: 0 12px 35px rgba(0, 0, 0, .36); color: var(--text); font-size: 11px; opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; padding: 18px; display: grid; place-items: center; background: rgba(2, 8, 14, .74); backdrop-filter: blur(8px); }
.modal-backdrop[hidden] { display: none; }
.modal { width: min(100%, 380px); padding: 22px; border: 1px solid var(--line); border-radius: 20px; background: #101e2e; box-shadow: 0 24px 80px rgba(0, 0, 0, .5); text-align: center; }
.modal-icon { display: grid; place-items: center; width: 50px; height: 50px; margin: 0 auto 14px; border-radius: 50%; background: rgba(255, 82, 98, .14); color: var(--red); font-size: 23px; font-weight: 900; }
.modal p { color: var(--muted); font-size: 12px; line-height: 1.55; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 18px; }

@media (min-width: 620px) {
  .page { padding-inline: 24px; }
  .chart-wrap { height: 380px; }
  .metric-card { padding: 16px; }
  .metric-card strong { font-size: 25px; }
}

@media (max-width: 365px) {
  .page { padding-inline: 12px; }
  .reward-note { display: none; }
  .chart-wrap { min-height: 230px; }
  .direction-button { min-height: 70px; padding-inline: 7px; }
  .direction-icon { font-size: 25px; }
}

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