:root {
  --bg: #0a0c0f;
  --panel: rgba(19, 22, 27, 0.86);
  --panel-solid: #13161b;
  --line: rgba(255, 255, 255, 0.085);
  --text: #f3f5f7;
  --muted: #aab2bd;
  --accent: #b7f36b;
  --accent-soft: rgba(183, 243, 107, 0.12);
  --danger: #ff7b7b;
  --mono: "DM Mono", ui-monospace, monospace;
  --sans: "Manrope", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { color-scheme: dark; scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.5'/%3E%3C/svg%3E");
  z-index: 20;
}

.ambient { position: fixed; pointer-events: none; filter: blur(100px); border-radius: 50%; opacity: 0.1; }
.ambient-one { width: 430px; height: 430px; background: #a3ff6b; top: -260px; left: 20%; }
.ambient-two { width: 360px; height: 360px; background: #6bbdff; right: -220px; top: 45%; opacity: 0.07; }

.shell { width: min(1420px, calc(100% - 48px)); margin: 0 auto; position: relative; z-index: 1; }

.topbar { height: 84px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.brand { color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 12px; font-size: 13px; font-weight: 700; letter-spacing: 0.11em; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; color: #0a0c0f; background: var(--accent); border-radius: 9px; letter-spacing: 0; font-size: 15px; }
.brand-muted { color: #737a84; }
.live-pill { display: flex; align-items: center; gap: 8px; color: var(--muted); font: 11px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); animation: pulse 2s ease-out infinite; }
.live-pill.error .live-dot { background: var(--danger); box-shadow: 0 0 0 4px rgba(255,123,123,.12); animation: none; }

.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 32px; padding: 74px 0 42px; }
.eyebrow { color: var(--accent); font: 500 12px var(--mono); letter-spacing: 0.15em; margin: 0 0 12px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 16px; font-size: clamp(44px, 6vw, 80px); line-height: .98; letter-spacing: -0.055em; font-weight: 500; }
.hero-copy { max-width: 640px; color: var(--muted); font-size: 18px; line-height: 1.7; margin: 0; }
.refresh-button { display: flex; align-items: center; gap: 9px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.035); color: #d6dbe1; padding: 12px 17px; font: 600 14px var(--sans); cursor: pointer; transition: .2s ease; }
.refresh-button:hover { border-color: rgba(183,243,107,.4); color: var(--accent); background: var(--accent-soft); }
.refresh-button:disabled { opacity: .6; cursor: wait; }
.refresh-button svg, .search-box svg { width: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.refresh-button.loading svg { animation: spin 1s linear infinite; }

.metrics { display: grid; grid-template-columns: 1.25fr repeat(3, 1fr); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; background: var(--panel); backdrop-filter: blur(18px); }
.metric-card { min-height: 160px; padding: 28px; border-left: 1px solid var(--line); }
.metric-card:first-child { border-left: 0; }
.metric-card.primary { background: linear-gradient(135deg, rgba(183,243,107,.10), transparent 62%); }
.metric-label { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; margin-bottom: 22px; }
.metric-icon { color: var(--accent); }
.metric-value { font: 500 clamp(25px, 2.25vw, 36px) var(--mono); letter-spacing: -0.045em; margin-bottom: 12px; white-space: nowrap; }
.metric-sub { color: #929aa5; font-size: 13px; }
.positive { color: var(--accent) !important; }
.negative { color: var(--danger) !important; }

.insights-grid { display: grid; grid-template-columns: 1.15fr .85fr; gap: 18px; margin-top: 18px; }
.panel { border: 1px solid var(--line); border-radius: 16px; background: var(--panel); backdrop-filter: blur(18px); }
.panel-heading, .positions-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 26px 28px; border-bottom: 1px solid var(--line); }
.panel-heading h2, .positions-heading h2 { margin: 0; font-size: 23px; font-weight: 650; letter-spacing: -0.03em; }
.panel-heading .eyebrow, .positions-heading .eyebrow { margin-bottom: 7px; }
.panel-note { color: #8e96a1; font: 11px var(--mono); text-transform: uppercase; letter-spacing: .08em; }

.allocation-layout { min-height: 310px; display: grid; grid-template-columns: .9fr 1.1fr; align-items: center; padding: 25px; }
.donut-wrap { display: grid; place-items: center; }
.donut { width: 190px; height: 190px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(#262a30 0 100%); position: relative; transition: background .5s ease; }
.donut::after { content: ""; width: 120px; height: 120px; background: var(--panel-solid); border: 1px solid var(--line); border-radius: 50%; position: absolute; }
.donut-center { position: relative; z-index: 1; text-align: center; display: grid; }
.donut-center strong { font: 500 27px var(--mono); }
.donut-center span { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .1em; margin-top: 4px; }
.legend { display: grid; gap: 12px; }
.legend-row { display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 10px; font-size: 14px; }
.legend-dot { width: 7px; height: 7px; border-radius: 50%; }
.legend-name { color: #bac0c8; }
.legend-value { color: var(--muted); font: 12px var(--mono); }

.movers { padding: 10px 28px 18px; }
.mover { padding: 18px 0; border-bottom: 1px solid var(--line); }
.mover:last-child { border-bottom: 0; }
.mover-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.ticker-lockup { display: flex; align-items: center; gap: 12px; }
.ticker-badge { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; background: rgba(255,255,255,.055); color: #dfe3e8; font: 500 9px var(--mono); letter-spacing: -.04em; }
.mover-logo { width: 34px; height: 34px; flex: 0 0 34px; display: grid; place-items: center; border-radius: 9px; background: #fff; overflow: hidden; }
.mover-logo img { width: 28px; height: 28px; object-fit: contain; }
.ticker-name strong { display: block; font: 600 14px var(--mono); }
.ticker-name span { color: #9098a3; font-size: 12px; }
.mover-return { font: 600 14px var(--mono); }
.return-track { height: 3px; background: #262a30; border-radius: 3px; overflow: hidden; }
.return-fill { height: 100%; border-radius: 3px; background: var(--accent); transform-origin: left; animation: grow .7s ease both; }

.positions-panel { margin-top: 18px; overflow: hidden; }
.activity-panel { margin-top: 18px; overflow: hidden; }
.activity-count { color: var(--accent); background: var(--accent-soft); border: 1px solid rgba(183,243,107,.18); border-radius: 999px; padding: 8px 11px; font: 600 11px var(--mono); letter-spacing: .05em; text-transform: uppercase; }
.activity-list { display: grid; }
.activity-loading { min-height: 140px; display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.activity-card { position: relative; display: grid; grid-template-columns: 48px minmax(0,1fr) 120px; align-items: center; gap: 16px; min-height: 100px; padding: 19px 24px 19px 28px; border-bottom: 1px solid var(--line); color: inherit; }
.activity-accent { position: absolute; inset: 18px auto 18px 0; width: 3px; background: var(--accent); border-radius: 0 3px 3px 0; box-shadow: 0 0 14px rgba(183,243,107,.35); }
.activity-card.sell .activity-accent { background: var(--danger); box-shadow: 0 0 14px rgba(255,123,123,.3); }
.activity-logo { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 13px; background: #fff; overflow: hidden; }
.activity-logo img { width: 32px; height: 32px; object-fit: contain; }
.activity-main { min-width: 0; }
.activity-title { display: flex; align-items: baseline; gap: 10px; }
.activity-title strong { font: 600 16px var(--mono); }
.activity-title span { color: #9aa2ad; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-details { display: flex; align-items: center; gap: 10px; color: #b4bac2; font: 12px var(--mono); margin-top: 8px; }
.activity-badge { padding: 5px 9px; border-radius: 6px; color: var(--accent); background: var(--accent-soft); font: 700 12px var(--sans); }
.activity-badge.sell { color: var(--danger); background: rgba(255,123,123,.1); }
.activity-note { color: #c0c5cc; font-size: 13px; line-height: 1.65; margin: 11px 0 0; max-width: 840px; }
.activity-meta { display: grid; justify-items: end; gap: 3px; }
.activity-meta strong { font: 600 16px var(--mono); }
.activity-meta span { color: #8b939e; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
.activity-meta time { color: #a8afb8; font: 12px var(--mono); margin-top: 7px; }
.activity-footnote { color: #818995; padding: 15px 28px; font: 10px var(--mono); letter-spacing: .05em; text-transform: uppercase; }
.search-box { width: min(290px, 45vw); height: 40px; display: flex; align-items: center; gap: 10px; padding: 0 13px; background: rgba(255,255,255,.035); border: 1px solid var(--line); border-radius: 10px; color: #747b85; }
.search-box input { width: 100%; border: 0; outline: 0; color: var(--text); background: transparent; font: 14px var(--sans); }
.search-box input::placeholder { color: #656c75; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 940px; }
th { color: #8d95a0; font: 600 11px var(--mono); letter-spacing: .09em; text-transform: uppercase; text-align: left; padding: 17px 24px; border-bottom: 1px solid var(--line); }
td { color: #d0d5db; font-size: 14px; padding: 19px 24px; border-bottom: 1px solid rgba(255,255,255,.065); }
tbody tr { transition: background .15s ease; }
tbody tr:hover { background: rgba(255,255,255,.022); }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-family: var(--mono); }
.asset-cell { display: flex; align-items: center; gap: 13px; min-width: 210px; }
.table-logo { width: 34px; height: 34px; flex: 0 0 34px; display: grid; place-items: center; border-radius: 9px; background: #fff; overflow: hidden; }
.table-logo img { width: 28px; height: 28px; object-fit: contain; }
.asset-cell strong { display: block; color: #f2f4f6; font: 600 14px var(--mono); }
.asset-copy { min-width: 0; display: block; }
.asset-copy span { display: block; color: #949ca7; font-size: 12px; margin-top: 4px; max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.allocation-cell { display: grid; grid-template-columns: 1fr 42px; align-items: center; gap: 12px; min-width: 140px; }
.allocation-track { height: 3px; background: #262a30; border-radius: 2px; overflow: hidden; }
.allocation-fill { height: 100%; background: var(--accent); border-radius: 2px; }
.allocation-number { color: #adb4be; font: 12px var(--mono); text-align: right; }
.loading-row { height: 170px; text-align: center; color: var(--muted); }
.empty-state { padding: 60px 20px; text-align: center; color: var(--muted); font-size: 13px; }

footer { display: flex; justify-content: space-between; color: #7f8792; font: 10px var(--mono); letter-spacing: .1em; text-transform: uppercase; padding: 34px 4px 48px; }
.toast { position: fixed; right: 24px; bottom: 24px; max-width: 360px; color: #dfe3e8; background: #1b1f25; border: 1px solid var(--line); border-radius: 10px; padding: 13px 16px; font-size: 12px; box-shadow: 0 15px 45px rgba(0,0,0,.35); transform: translateY(20px); opacity: 0; pointer-events: none; transition: .25s ease; z-index: 30; }
.toast.visible { transform: translateY(0); opacity: 1; }

:lang(th) { font-family: "Noto Sans Thai", var(--sans); letter-spacing: 0; }
th:lang(th) { color: #b7bec7; font-size: 14px; font-weight: 600; line-height: 1.5; letter-spacing: .01em; padding-block: 20px; }

@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(183,243,107,.25); } 70% { box-shadow: 0 0 0 7px rgba(183,243,107,0); } 100% { box-shadow: 0 0 0 0 rgba(183,243,107,0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes grow { from { transform: scaleX(0); } }

@media (max-width: 1050px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .metric-card:nth-child(3) { border-left: 0; border-top: 1px solid var(--line); }
  .metric-card:nth-child(4) { border-top: 1px solid var(--line); }
  .insights-grid { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .shell { width: min(100% - 28px, 1420px); }
  .topbar { height: 70px; }
  .brand-muted { display: none; }
  .hero { align-items: flex-start; flex-direction: column; padding: 52px 2px 30px; }
  .hero-copy { font-size: 16px; }
  .refresh-button { width: 100%; justify-content: center; }
  .metrics { grid-template-columns: 1fr; }
  .metric-card { min-height: 135px; padding: 23px; border-left: 0; border-top: 1px solid var(--line); }
  .metric-card:first-child { border-top: 0; }
  .allocation-layout { grid-template-columns: 1fr; gap: 28px; padding: 30px 24px; }
  .panel-heading, .positions-heading { padding: 22px; }
  .activity-heading { flex-direction: row; align-items: center; }
  .activity-card { grid-template-columns: 44px minmax(0,1fr); gap: 12px; padding: 18px 18px 18px 22px; }
  .activity-meta { grid-column: 2; grid-row: 2; display: flex; justify-content: flex-start; justify-items: start; gap: 7px; align-items: baseline; }
  .activity-meta span { display: none; }
  .activity-meta time { margin: 0; }
  .activity-note { font-size: 13px; }
  .positions-heading { align-items: stretch; flex-direction: column; }
  .search-box { width: 100%; }
  th:first-child { width: calc(100vw - 30px); min-width: calc(100vw - 30px); text-align: center; }
  td:first-child { width: calc(100vw - 30px); min-width: calc(100vw - 30px); }
  .asset-cell { width: min(250px, calc(100vw - 78px)); min-width: 0; display: grid; grid-template-columns: 38px minmax(0, 1fr); align-items: center; gap: 12px; margin-inline: auto; text-align: left; }
  .asset-cell > .table-logo, .asset-cell > .ticker-badge { display: grid; place-items: center; margin: 0; }
  .asset-copy span { width: 100%; max-width: none; }
  .movers { padding-inline: 22px; }
  footer { gap: 20px; line-height: 1.6; }
}

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