/* ── Reset & Variables ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0f1117;
  --surface:    #1a1d27;
  --surface2:   #21253a;
  --border:     #2a2f45;
  --accent-grn: #1D9E75;
  --accent-yel: #EF9F27;
  --accent-red: #E24B4A;
  --accent-blu: #378ADD;
  --accent-pur: #9B59B6;
  --text-pri:   #e8eaf0;
  --text-sec:   #9aa0b5;
  --text-dim:   #5c6380;
  --radius:     12px;
  --font:       -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans TC', sans-serif;

  --c-voo:  #1D9E75;
  --c-qqq:  #378ADD;
  --c-gld:  #EF9F27;
  --c-vgit: #9B59B6;
  --c-grid: #E24B4A;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text-pri);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Header ── */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  position: sticky; top: 0; z-index: 100;
  backdrop-filter: blur(8px);
}
.header-inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
}
.header-brand { display: flex; align-items: center; gap: 8px; }
.header-icon  { font-size: 20px; }
.site-header h1 { font-size: 16px; font-weight: 700; }
.header-meta { font-size: 11px; color: var(--text-sec); display: flex; gap: 6px; align-items: center; }
.sep { color: var(--text-dim); }

/* ── Macro Strip ── */
.macro-strip {
  display: flex; overflow-x: auto; -webkit-overflow-scrolling: touch;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  padding: 0 8px;
  scrollbar-width: none;
}
.macro-strip::-webkit-scrollbar { display: none; }
.strip-item {
  display: flex; flex-direction: column; align-items: center;
  padding: 8px 14px; border-right: 1px solid var(--border);
  min-width: 80px; flex-shrink: 0;
}
.strip-item:last-child { border-right: none; }
.strip-label { font-size: 9px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 2px; }
.strip-val   { font-size: 14px; font-weight: 700; }

/* ── Main Layout — Mobile First ── */
.main-grid {
  max-width: 1200px; margin: 0 auto;
  padding: 12px;
  display: flex; flex-direction: column;
  gap: 12px;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card-title {
  font-size: 14px; font-weight: 700;
  margin-bottom: 14px; padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: baseline; gap: 6px;
}
.card-sub { font-size: 11px; color: var(--text-dim); font-weight: 400; }
.section-title { font-size: 14px; font-weight: 700; color: var(--text-pri); margin-bottom: 10px; }

/* ── AI Card ── */
.ai-text {
  font-family: var(--font);
  font-size: 13px; line-height: 1.9;
  color: var(--text-sec);
  white-space: pre-wrap; word-break: break-word;
}

/* ── HRP Card ── */
.hrp-inner { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.hrp-chart-wrap { width: 200px; height: 200px; flex-shrink: 0; }
.hrp-legend { list-style: none; width: 100%; }
.hrp-legend li {
  display: flex; align-items: center;
  padding: 5px 0; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.hrp-legend li:last-child { border-bottom: none; }
.legend-dot  { width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; flex-shrink: 0; }
.legend-name { flex: 1; color: var(--text-sec); }
.legend-pct  { font-weight: 700; margin-right: 8px; }
.legend-val  { font-size: 11px; color: var(--text-dim); }

/* ── TYD Timing ── */
.tyd-timing {
  margin-top: 14px;
  padding: 8px 12px;
  background: rgba(255,255,255,0.04);
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.tyd-label { flex: 1; }
.tyd-score { font-weight: 700; }

/* ── DCC Card ── */
.dcc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.dcc-sub-title { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.dcc-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 0; border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.dcc-row:last-child { border-bottom: none; }
.dcc-label { color: var(--text-sec); }
.dcc-val   { font-weight: 700; font-family: 'Courier New', monospace; font-size: 12px; }
.dcc-trend { font-size: 10px; color: var(--text-dim); margin-left: 4px; }
.dcc-params { font-size: 11px; color: var(--text-dim); margin-top: 10px; text-align: right; }

/* ── ETF Grid ── */
.etf-grid-wrap { }
.etf-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.etf-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  position: relative; overflow: hidden;
}
.etf-card::before {
  content: ""; position: absolute; top: 0; left: 0;
  width: 4px; height: 100%; border-radius: var(--radius) 0 0 var(--radius);
}
.etf-card[data-ticker="VOO"]::before  { background: var(--c-voo); }
.etf-card[data-ticker="QQQ"]::before  { background: var(--c-qqq); }
.etf-card[data-ticker="GLD"]::before  { background: var(--c-gld); }
.etf-card[data-ticker="VGIT"]::before { background: var(--c-vgit); }
.etf-card[data-ticker="GRID"]::before { background: var(--c-grid); }

.etf-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 10px; padding-left: 8px;
}
.etf-name-wrap { }
.etf-name   { font-size: 14px; font-weight: 700; }
.etf-ticker { font-size: 11px; color: var(--text-dim); margin-top: 1px; }
.etf-price-wrap { text-align: right; }
.etf-price  { font-size: 15px; font-weight: 700; }
.etf-chg    { font-size: 11px; display: block; margin-top: 1px; }
.chg-pos    { color: var(--accent-grn); }
.chg-neg    { color: var(--accent-red); }

.etf-metrics {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 4px 10px; margin: 10px 0; padding-left: 8px;
}
.metric { display: flex; justify-content: space-between; font-size: 12px; padding: 2px 0; }
.metric-label { color: var(--text-dim); }
.metric-val   { font-weight: 600; }

.etf-footer {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 6px; margin-top: 10px; padding-left: 8px;
}
.signal-badge {
  display: inline-block; padding: 3px 9px; border-radius: 6px;
  font-size: 11px; font-weight: 700; border: 1px solid;
}
.badge-strong-buy  { background: rgba(29,158,117,.18); color: var(--accent-grn); border-color: var(--accent-grn); }
.badge-buy         { background: rgba(76,175,131,.15); color: #4CAF83; border-color: #4CAF83; }
.badge-hold        { background: rgba(136,136,136,.12); color: #888; border-color: #555; }
.badge-sell        { background: rgba(239,159,39,.18); color: var(--accent-yel); border-color: var(--accent-yel); }
.badge-strong-sell { background: rgba(226,75,74,.18); color: var(--accent-red); border-color: var(--accent-red); }
.etf-conf { font-size: 11px; color: var(--text-sec); }
.etf-phase { font-size: 10px; color: var(--text-dim); width: 100%; margin-top: 2px; }

/* ── News ── */
.news-group       { margin-bottom: 14px; }
.news-group:last-child { margin-bottom: 0; }
.news-group-title { font-size: 12px; font-weight: 700; margin-bottom: 6px; }
.news-group ul    { list-style: none; }
.news-group li    { font-size: 12px; color: var(--text-sec); padding: 4px 0; border-bottom: 1px solid var(--border); }
.news-group li:last-child { border-bottom: none; }

/* ── Footer ── */
.site-footer {
  text-align: center; padding: 20px 16px;
  font-size: 11px; color: var(--text-dim);
  border-top: 1px solid var(--border);
  line-height: 1.8;
}

/* ── Utility ── */
.loading-msg { color: var(--text-dim); font-size: 12px; text-align: center; padding: 20px; }
.error-msg   { color: var(--accent-red); font-size: 12px; text-align: center; padding: 12px; }
.c-grn  { color: var(--accent-grn); }
.c-yel  { color: var(--accent-yel); }
.c-red  { color: var(--accent-red); }
.c-blu  { color: var(--accent-blu); }
.c-dim  { color: var(--text-dim); }

/* ── Regime Banner ── */
.regime-banner {
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  transition: background 0.3s;
}
.regime-banner.regime-on   { border-bottom-color: var(--accent-grn); }
.regime-banner.regime-trans { border-bottom-color: var(--accent-yel); }
.regime-banner.regime-off  { border-bottom-color: var(--accent-red); }

.regime-inner {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.regime-label {
  font-size: 0.72rem;
  color: var(--text-sec);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.regime-badge {
  font-size: 0.88rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--surface2);
}
.regime-badge.regime-on   { color: var(--accent-grn); border: 1px solid var(--accent-grn); }
.regime-badge.regime-trans { color: var(--accent-yel); border: 1px solid var(--accent-yel); }
.regime-badge.regime-off  { color: var(--accent-red); border: 1px solid var(--accent-red); }
.regime-details { font-size: 0.80rem; color: var(--text-sec); }

/* ── Tail Risk Bar ── */
.tail-risk-bar {
  background: rgba(226, 75, 74, 0.08);
  border-bottom: 1px solid rgba(226, 75, 74, 0.35);
  padding: 8px 20px;
}
.tail-risk-inner {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tail-risk-item {
  font-size: 0.82rem;
  color: #f08080;
}

/* ── Signal Light Row ── */
.signal-light-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 8px;
  margin: 8px 0 4px;
  font-size: 0.84rem;
}
.signal-light-row.sl-green  { background: rgba(29,158,117,0.12); }
.signal-light-row.sl-yellow { background: rgba(239,159,39,0.12); }
.signal-light-row.sl-red    { background: rgba(226,75,74,0.12); }

.sl-light  { font-size: 1.0rem; font-weight: 700; white-space: nowrap; }
.sl-reason { font-size: 0.78rem; color: var(--text-sec); flex: 1; }
.sl-delta  {
  font-size: 0.74rem;
  color: var(--accent-yel);
  background: rgba(239,159,39,0.15);
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
}

/* ── Tablet: ≥ 640px ── */
@media (min-width: 640px) {
  .etf-grid { grid-template-columns: 1fr 1fr; }
  .hrp-inner { flex-direction: row; align-items: flex-start; }
  .hrp-legend { max-width: 240px; }
  .dcc-grid { grid-template-columns: 1fr 1fr 1fr; }
}

/* ── Desktop: ≥ 1024px ── */
@media (min-width: 1024px) {
  .main-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "ai   hrp"
      "dcc  dcc"
      "etfs etfs"
      "news news";
    gap: 14px;
  }
  .ai-card      { grid-area: ai; }
  .hrp-card     { grid-area: hrp; }
  .dcc-card     { grid-area: dcc; }
  .etf-grid-wrap{ grid-area: etfs; }
  .news-card    { grid-area: news; }
  .etf-grid     { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1440px) {
  .etf-grid { grid-template-columns: repeat(5, 1fr); }
}
