/* =========================================================
   TradeQuest Design System
   ========================================================= */
:root {
  --bg: #070b16;
  --bg-2: #0b1122;
  --surface: rgba(20, 28, 52, 0.72);
  --surface-solid: #121a31;
  --surface-2: #18223f;
  --surface-3: #212d52;
  --line: rgba(130, 150, 220, 0.14);
  --line-strong: rgba(130, 150, 220, 0.28);
  --text: #e9eefc;
  --text-2: #a8b3d6;
  --text-3: #6f7ba3;
  --bull: #12e0a0;
  --bull-soft: rgba(18, 224, 160, 0.14);
  --bear: #ff4d6d;
  --bear-soft: rgba(255, 77, 109, 0.14);
  --accent: #6c8cff;
  --accent-2: #9b6cff;
  --accent-soft: rgba(108, 140, 255, 0.16);
  --gold: #ffc94d;
  --gold-soft: rgba(255, 201, 77, 0.14);
  --info: #3cc8ff;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.7);
  --glow-bull: 0 0 0 1px rgba(18, 224, 160, 0.4), 0 10px 40px -10px rgba(18, 224, 160, 0.5);
  --glow-accent: 0 0 0 1px rgba(108, 140, 255, 0.45), 0 10px 40px -10px rgba(108, 140, 255, 0.55);
  --font-head: 'Kanit', 'IBM Plex Sans Thai', system-ui, sans-serif;
  --font-body: 'IBM Plex Sans Thai', 'Kanit', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  --sidebar-w: 248px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 700px at 85% -10%, rgba(108, 140, 255, 0.16), transparent 60%),
              radial-gradient(900px 600px at -10% 110%, rgba(18, 224, 160, 0.10), transparent 60%),
              var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
#bg-grid {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse at 50% 0%, black 0%, transparent 70%);
  opacity: 0.35;
}
h1, h2, h3, h4 { font-family: var(--font-head); font-weight: 600; margin: 0 0 0.4em; line-height: 1.25; letter-spacing: 0.1px; }
h1 { font-size: clamp(26px, 3.2vw, 38px); }
h2 { font-size: clamp(21px, 2.3vw, 27px); }
h3 { font-size: 18px; }
p { margin: 0 0 0.8em; }
a { color: var(--accent); text-decoration: none; }
button { font: inherit; color: inherit; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--text-2); }
.dim { color: var(--text-3); }
.up, .bull { color: var(--bull); }
.down, .bear { color: var(--bear); }
.gold { color: var(--gold); }
.accent { color: var(--accent); }
.center { text-align: center; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.app { position: relative; z-index: 1; display: flex; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  padding: 22px 16px; display: flex; flex-direction: column; gap: 6px; overflow-y: auto;
  background: linear-gradient(180deg, rgba(13, 20, 40, 0.92), rgba(9, 13, 27, 0.92));
  border-right: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 20px; cursor: pointer; }
.brand img { width: 40px; height: 40px; }
.brand b { font-family: var(--font-head); font-size: 21px; font-weight: 700; display: block; line-height: 1.1; letter-spacing: 0.3px; }
.brand b span { background: linear-gradient(90deg, var(--bull), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand small { color: var(--text-3); font-size: 12px; }
.nav-label { font-size: 11px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--text-3); padding: 12px 12px 4px; font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px;
  color: var(--text-2); font-weight: 500; transition: all .18s; position: relative;
}
.nav-item .ic { width: 22px; text-align: center; font-size: 18px; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: linear-gradient(90deg, var(--accent-soft), transparent); color: var(--text); }
.nav-item.active::before { content: ''; position: absolute; left: -16px; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: var(--accent); }
.nav-item .tag { margin-left: auto; font-size: 10px; padding: 1px 7px; border-radius: 99px; background: var(--gold-soft); color: var(--gold); font-weight: 600; }
.sidebar-foot { margin-top: auto; padding: 14px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); font-size: 13px; color: var(--text-2); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px;
  padding: 14px 28px; background: rgba(7, 11, 22, 0.75); backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}
.topbar .page-title { font-family: var(--font-head); font-size: 18px; font-weight: 600; }
.topbar .spacer { flex: 1; }
.view { padding: 28px; max-width: 1320px; width: 100%; margin: 0 auto; animation: viewIn .35s ease; }
@keyframes viewIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.level-pill { display: flex; align-items: center; gap: 10px; padding: 6px 14px 6px 6px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); cursor: pointer; }
.level-pill .lv { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-family: var(--font-head); background: conic-gradient(var(--gold) var(--p, 0%), var(--surface-3) 0); position: relative; font-size: 13px; }
.level-pill .lv::after { content: ''; position: absolute; inset: 3px; border-radius: 50%; background: var(--surface-solid); z-index: 0; }
.level-pill .lv span { position: relative; z-index: 1; }
.level-pill .meta { line-height: 1.2; }
.level-pill .meta b { font-size: 13px; display: block; }
.level-pill .meta small { font-size: 11px; color: var(--text-3); }
.stat-pill { display: flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); font-weight: 600; font-size: 14px; }

.bottomnav { display: none; }

/* ---------- Grid ---------- */
.grid { display: grid; gap: 18px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: 12px; }
.stack > * + * { margin-top: 14px; }
.section { margin-top: 32px; }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-head h2 { margin: 0; }

/* ---------- Card ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); backdrop-filter: blur(12px); position: relative;
}
.card.pad-lg { padding: 28px; }
.card.tight { padding: 14px; }
.card.hover { transition: transform .2s, border-color .2s, box-shadow .2s; cursor: pointer; }
.card.hover:hover { transform: translateY(-3px); border-color: var(--line-strong); box-shadow: var(--glow-accent); }
.card.glow-bull { box-shadow: var(--glow-bull); }
.card-title { font-family: var(--font-head); font-size: 16px; font-weight: 600; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }

.hero {
  position: relative; overflow: hidden; border-radius: 26px; padding: 36px;
  background: linear-gradient(135deg, rgba(108, 140, 255, 0.22), rgba(18, 224, 160, 0.10) 55%, rgba(155, 108, 255, 0.18));
  border: 1px solid var(--line-strong);
}
.hero h1 { max-width: 640px; }
.hero .glowtext { background: linear-gradient(90deg, var(--bull), var(--info), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: var(--surface-2); color: var(--text); font-weight: 600; cursor: pointer;
  font-family: var(--font-head); font-size: 15px; letter-spacing: .2px;
  transition: transform .12s, filter .15s, box-shadow .2s, background .2s; user-select: none; white-space: nowrap;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; transform: none; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; box-shadow: 0 8px 26px -8px rgba(108, 140, 255, .7); }
.btn.buy { background: linear-gradient(135deg, #12e0a0, #0bb57f); border-color: transparent; color: #04130d; box-shadow: 0 8px 26px -8px rgba(18, 224, 160, .7); }
.btn.sell { background: linear-gradient(135deg, #ff4d6d, #e0284a); border-color: transparent; color: #fff; box-shadow: 0 8px 26px -8px rgba(255, 77, 109, .7); }
.btn.gold { background: linear-gradient(135deg, #ffd56b, #ffb020); color: #2a1a00; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 7px 13px; font-size: 13px; border-radius: 10px; }
.btn.lg { padding: 15px 28px; font-size: 17px; border-radius: 14px; }
.btn.block { width: 100%; }

/* ---------- Chips / badges ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 11px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-3); color: var(--text-2); border: 1px solid var(--line); }
.chip.bull { background: var(--bull-soft); color: var(--bull); border-color: transparent; }
.chip.bear { background: var(--bear-soft); color: var(--bear); border-color: transparent; }
.chip.gold { background: var(--gold-soft); color: var(--gold); border-color: transparent; }
.chip.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* ---------- Stats ---------- */
.stat { padding: 16px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); }
.stat .k { font-size: 12px; color: var(--text-3); font-weight: 500; }
.stat .v { font-family: var(--font-head); font-size: 24px; font-weight: 600; line-height: 1.3; }
.stat .s { font-size: 12px; color: var(--text-2); }

.progress { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--bull), var(--accent)); transition: width .6s cubic-bezier(.2, .8, .2, 1); }
.progress.gold > i { background: linear-gradient(90deg, #ffd56b, #ff9d2e); }

/* ---------- Quiz / options ---------- */
.options { display: grid; gap: 10px; }
.option {
  text-align: left; padding: 14px 16px; border-radius: 14px; border: 1px solid var(--line-strong);
  background: var(--surface-2); cursor: pointer; transition: all .15s; display: flex; gap: 12px; align-items: center; font-size: 15px;
}
.option:hover:not(:disabled) { border-color: var(--accent); background: var(--surface-3); }
.option .key { flex: 0 0 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-3); font-weight: 700; font-size: 13px; font-family: var(--font-mono); }
.option.correct { border-color: var(--bull); background: var(--bull-soft); }
.option.correct .key { background: var(--bull); color: #04130d; }
.option.wrong { border-color: var(--bear); background: var(--bear-soft); animation: shake .35s; }
.option.wrong .key { background: var(--bear); color: #fff; }
.option:disabled { cursor: default; }
@keyframes shake { 0%, 100% { transform: none; } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

.explain { padding: 14px 16px; border-radius: 14px; background: var(--accent-soft); border-left: 3px solid var(--accent); font-size: 14.5px; }
.explain.good { background: var(--bull-soft); border-color: var(--bull); }
.explain.bad { background: var(--bear-soft); border-color: var(--bear); }
.tip { padding: 12px 14px; border-radius: 12px; background: var(--gold-soft); border-left: 3px solid var(--gold); font-size: 14px; }

/* ---------- Tabs / segmented ---------- */
.seg { display: inline-flex; padding: 4px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); gap: 4px; flex-wrap: wrap; }
.seg button { padding: 7px 14px; border-radius: 9px; border: 0; background: transparent; color: var(--text-2); cursor: pointer; font-weight: 600; font-size: 13px; }
.seg button.on { background: var(--surface-3); color: var(--text); box-shadow: 0 0 0 1px var(--line-strong); }

/* ---------- Form ---------- */
.input, select.input {
  width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: var(--bg-2); color: var(--text); font: inherit; outline: none; transition: border-color .15s;
}
.input:focus { border-color: var(--accent); }
label.lbl { font-size: 13px; color: var(--text-2); display: block; margin-bottom: 6px; font-weight: 500; }
input[type=range] { width: 100%; accent-color: var(--accent); }

/* ---------- Chart container ---------- */
.chart-box { position: relative; width: 100%; height: 420px; border-radius: 16px; overflow: hidden; background: linear-gradient(180deg, #0a1020, #080d1a); border: 1px solid var(--line); }
.chart-box.sm { height: 260px; }
.chart-box.lg { height: 520px; }
.chart-box canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.chart-legend { position: absolute; left: 12px; top: 10px; z-index: 2; font-family: var(--font-mono); font-size: 12px; color: var(--text-2); pointer-events: none; display: flex; gap: 12px; flex-wrap: wrap; }

/* ---------- Modal ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: rgba(3, 6, 14, 0.72); backdrop-filter: blur(6px); animation: fadeIn .2s; }
.modal { width: min(560px, 100%); max-height: 90vh; overflow: auto; background: var(--surface-solid); border: 1px solid var(--line-strong); border-radius: 22px; padding: 28px; box-shadow: 0 40px 100px -20px rgba(0, 0, 0, 0.8); animation: popIn .28s cubic-bezier(.2, 1.4, .4, 1); }
.modal.wide { width: min(860px, 100%); }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: scale(.92) translateY(10px); } }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 20px; top: 76px; z-index: 120; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.toast { pointer-events: auto; min-width: 240px; max-width: 340px; padding: 12px 16px; border-radius: 14px; background: var(--surface-solid); border: 1px solid var(--line-strong); box-shadow: var(--shadow); display: flex; gap: 12px; align-items: center; animation: toastIn .35s cubic-bezier(.2, 1.3, .4, 1); font-size: 14px; }
.toast .ic { font-size: 22px; }
.toast b { display: block; font-family: var(--font-head); font-weight: 600; }
.toast.xp { border-color: rgba(255, 201, 77, .4); }
.toast.out { animation: toastOut .3s forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(30px); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(30px); } }

#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 130; }

/* ---------- Mode cards (home) ---------- */
.mode-card { overflow: hidden; min-height: 190px; display: flex; flex-direction: column; }
.mode-card .emoji { font-size: 34px; width: 58px; height: 58px; display: grid; place-items: center; border-radius: 16px; background: var(--surface-3); margin-bottom: 14px; }
.mode-card p { color: var(--text-2); font-size: 14px; flex: 1; }
.mode-card .foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.mode-card::after { content: ''; position: absolute; width: 180px; height: 180px; right: -60px; top: -60px; border-radius: 50%; background: var(--c, var(--accent)); opacity: .12; filter: blur(30px); }

.badge-tile { text-align: center; padding: 16px 10px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--line); }
.badge-tile .e { font-size: 34px; filter: grayscale(1) opacity(.35); }
.badge-tile.got .e { filter: none; }
.badge-tile.got { border-color: rgba(255, 201, 77, .35); background: linear-gradient(180deg, var(--gold-soft), var(--surface-2)); }
.badge-tile b { display: block; font-size: 13px; margin-top: 6px; font-family: var(--font-head); font-weight: 600; }
.badge-tile small { color: var(--text-3); font-size: 11.5px; line-height: 1.35; display: block; }

.kbd { display: inline-block; padding: 1px 7px; border-radius: 6px; border: 1px solid var(--line-strong); background: var(--surface-3); font-family: var(--font-mono); font-size: 12px; color: var(--text-2); }
.divider { height: 1px; background: var(--line); margin: 18px 0; }
.big-num { font-family: var(--font-head); font-weight: 700; font-size: 44px; line-height: 1; }
.pulse { animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.pop { animation: popIn .3s cubic-bezier(.2, 1.4, .4, 1); }

table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th { text-align: left; color: var(--text-3); font-weight: 500; font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.tbl td { padding: 10px; border-bottom: 1px solid var(--line); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 10px; border: 2px solid var(--bg); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .sidebar { display: none; }
  .topbar { padding: 12px 16px; }
  .view { padding: 18px 16px 24px; }
  .g2, .g3 { grid-template-columns: minmax(0, 1fr); }
  .hero { padding: 24px; border-radius: 20px; }
  .chart-box { height: 340px; }
  .chart-box.lg { height: 400px; }
  .topbar .page-title { display: none; }
  .toasts { right: 12px; left: 12px; top: 70px; }
  .toast { max-width: none; }
  .bottomnav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); background: rgba(9, 13, 27, 0.94);
    border-top: 1px solid var(--line); backdrop-filter: blur(14px); justify-content: space-around;
  }
  .bottomnav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px; color: var(--text-3); padding: 4px 6px; border-radius: 10px; min-width: 54px; }
  .bottomnav a .ic { font-size: 20px; }
  .bottomnav a.active { color: var(--text); background: var(--surface-2); }
}
@media (max-width: 520px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-pill.hide-sm { display: none; }
  .level-pill .meta { display: none; }
  .level-pill { padding: 4px; }
}
@media (max-width: 520px) {
  .hero .btn.lg { white-space: normal; text-align: center; max-width: 100%; }
}

/* ---------- LearnTrader integration ---------- */
.lt-back { display: block; font-size: 13px; color: var(--text-2); padding: 6px 10px; margin: -6px 0 6px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); text-align: center; font-weight: 500; }
.lt-back:hover { color: var(--text); border-color: var(--line-strong); }
.lt-back-top { display: none; font-size: 13px; color: var(--text-2); font-weight: 600; white-space: nowrap; }
.lt-tier-pro { border-color: rgba(255, 201, 77, .35); background: linear-gradient(180deg, var(--gold-soft), var(--surface-2)); }
.lt-tier-up .btn.block + .btn.block { margin-top: 6px; }
.lt-lockcard { text-align: center; max-width: 560px; margin: 0 auto; border-color: rgba(255, 201, 77, .3); background: linear-gradient(180deg, rgba(255, 201, 77, .08), var(--surface) 55%); }
.lt-lockcard h3 { font-size: 20px; margin-top: 4px; }
.lt-lock-ic { font-size: 40px; width: 72px; height: 72px; margin: 0 auto 10px; display: grid; place-items: center; border-radius: 22px; background: var(--gold-soft); }
.lt-lockcard.tight .lt-lock-ic { font-size: 28px; width: 52px; height: 52px; border-radius: 16px; }
.lt-perks { text-align: left; display: inline-block; margin: 4px 0 12px; padding-left: 20px; color: var(--text-2); font-size: 14px; line-height: 1.9; }
.lt-lock { font-size: 11px; padding: 2px 8px; }
.modal .lt-lockcard { border: 0; box-shadow: none; background: transparent; padding: 0; backdrop-filter: none; }
@media (max-width: 860px) {
  .lt-back-top { display: inline-block; }
}
@media (max-width: 520px) {
  .lt-up span { display: none; }
}

.lt-foot { margin-top: auto; padding: 18px 28px 22px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px 18px; justify-content: space-between; font-size: 12.5px; color: var(--text-3); }
.lt-foot-links { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.lt-foot-links a { color: var(--text-3); }
.lt-foot-links a:hover { color: var(--text); }
@media (max-width: 860px) { .lt-foot { padding: 16px 16px 96px; } }
