/* ===========================================================================
 * Unified market charts — overview (/charts/market, .mkt-*) + per-series
 * detail (/charts/{dataset}/{slug}, .mktd-*). Single-purple-accent language,
 * self-contained (needs only common.css + bulma).
 * ------------------------------------------------------------------------- */
.mkt, .mktd {
    --accent: 260 91% 62%;
    max-width: 1320px;
    margin: 0 auto;
    padding: 20px 16px 40px;
}

/* Shared primitives ------------------------------------------------------- */
.mkt-eyebrow, .mkt-title, .mkt-sub { text-align: center; }
.mkt-eyebrow {
    margin: 0; font-size: 0.68rem; font-weight: 700; letter-spacing: 0.14em;
    text-transform: uppercase; color: hsl(var(--accent) / 0.95);
}
html.theme-light .mkt-eyebrow { color: hsl(260 70% 48%); }
.mkt-title { margin: 2px 0 0; font-size: clamp(1.5rem, 4vw, 2.1rem); font-weight: 800; letter-spacing: -0.015em; }
.mkt-sub { margin: 5px 0 0; font-size: 0.92rem; color: var(--bulma-text-weak, #8b8b9c); }
.mkt-head { max-width: 820px; margin: 8px auto 16px; }

/* Promo banner (feature free for everyone during the launch promo) + premium gate */
.mkt-promo {
    max-width: 760px; margin: 0 auto 16px; padding: 8px 14px; text-align: center;
    font-size: 0.85rem; line-height: 1.45; color: var(--bulma-text-weak, #8b8b9c);
    border: 1px solid rgba(22, 163, 74, 0.30); border-radius: 12px; background: rgba(22, 163, 74, 0.07);
}
html.theme-dark .mkt-promo { border-color: rgba(74, 222, 128, 0.30); background: rgba(74, 222, 128, 0.09); }
.mkt-promo a { color: hsl(var(--accent)); font-weight: 600; }
html.theme-light .mkt-promo a { color: hsl(260 70% 48%); }
.mkt-promo__tag {
    display: inline-block; margin-right: 6px; padding: 1px 8px; border-radius: 999px;
    font-size: 0.62rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
    color: #fff; background: #16a34a; vertical-align: 1px;
}
html.theme-dark .mkt-promo__tag { background: #22c55e; }
.mkt-gate { max-width: 620px; margin: 10px auto 0; text-align: center; }
.mkt-gate .mkt-sub { margin-bottom: 14px; }

.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 999px; background: hsl(var(--accent) / 0.08); border: 1px solid hsl(var(--accent) / 0.16); }
.seg-btn {
    border: none; background: transparent; color: var(--bulma-text-weak, #8b8b9c);
    font-size: 0.78rem; font-weight: 600; letter-spacing: 0.03em; padding: 4px 13px;
    border-radius: 999px; cursor: pointer; transition: background 120ms ease, color 120ms ease;
}
.seg-btn:hover { color: inherit; }
.seg-btn.is-active { background: hsl(var(--accent)); color: #fff; }
.seg-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px hsl(var(--accent) / 0.30); }

/* Token icon (art) with coloured-badge fallback (added by JS on 404) */
.mat-ic {
    position: relative; width: 28px; height: 28px; flex-shrink: 0;
    border-radius: 8px; overflow: hidden; display: inline-grid; place-items: center;
}
.mat-ic img { width: 100%; height: 100%; object-fit: contain; }
.mat-ic__badge { display: none; width: 100%; height: 100%; align-items: center; justify-content: center; font-size: 0.82rem; font-weight: 800; color: #fff; background: var(--mat, hsl(var(--accent))); }
.mat-ic.is-fallback .mat-ic__badge { display: flex; }

.delta { font-weight: 700; font-variant-numeric: tabular-nums; }
.delta.is-up { color: #16a34a; } .delta.is-down { color: #dc2626; }
html.theme-dark .delta.is-up { color: #4ade80; } html.theme-dark .delta.is-down { color: #f87171; }

/* Tabs -------------------------------------------------------------------- */
.mkt-tabs { display: flex; justify-content: center; gap: 8px; margin: 4px 0 18px; flex-wrap: wrap; }
.mkt-tab {
    display: inline-flex; align-items: center; gap: 8px; padding: 9px 18px; border-radius: 12px;
    border: 1px solid hsl(var(--accent) / 0.18); background: hsl(var(--accent) / 0.04);
    color: var(--bulma-text-weak, #8b8b9c); font-size: 0.95rem; font-weight: 700; cursor: pointer;
    transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.mkt-tab:hover { border-color: hsl(var(--accent) / 0.4); color: inherit; }
.mkt-tab.is-active { background: hsl(var(--accent)); color: #fff; border-color: hsl(var(--accent)); }
.mkt-tab__ic { font-size: 0.8rem; }

/* Controls ---------------------------------------------------------------- */
.mkt-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 12px; margin: 0 0 18px; }

/* Shared panel surface ---------------------------------------------------- */
.mkt-hero, .mkt-card { border: 1px solid hsl(var(--accent) / 0.14); border-radius: 16px; background: hsl(var(--accent) / 0.03); }
html.theme-light .mkt-hero, html.theme-light .mkt-card { border-color: hsl(var(--accent) / 0.16); background: hsl(var(--accent) / 0.02); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04); }

/* Hero -------------------------------------------------------------------- */
.mkt-hero { padding: 16px 18px 14px; margin-bottom: 16px; }
.mkt-hero__head { margin-bottom: 8px; }
.mkt-hero__head .mkt-eyebrow, .mkt-hero__title, .mkt-hero__head .mkt-sub { text-align: left; }
.mkt-hero__title { margin: 2px 0 0; font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; }
.mkt-logtag { margin-left: 6px; padding: 1px 7px; font-size: 0.6rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; vertical-align: 2px; color: var(--bulma-text-weak, #8b8b9c); border: 1px solid hsl(var(--accent) / 0.22); border-radius: 999px; }
.mkt-hero__scroll { overflow-x: auto; overscroll-behavior-x: contain; }
.mkt-hero__inner { position: relative; height: 430px; min-width: 680px; }
.mkt-hero__toprow { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* Freshness indicator: "updated N ago" (shown once data has loaded; dot breathes, flashes on a fresh update). */
.mkt-live, .mktd-live {
    display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
    font-size: 0.66rem; font-weight: 600;
    color: #16a34a; padding: 2px 9px; border-radius: 999px;
    border: 1px solid rgba(22, 163, 74, 0.35); background: rgba(22, 163, 74, 0.08);
}
.mkt-live__ago { font-variant-numeric: tabular-nums; }
html.theme-dark .mkt-live, html.theme-dark .mktd-live {
    color: #4ade80; border-color: rgba(74, 222, 128, 0.35); background: rgba(74, 222, 128, 0.10);
}
.mkt-live__dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: mktBreathe 2.4s ease-in-out infinite; }
.mkt-live.is-pulse .mkt-live__dot, .mktd-live.is-pulse .mkt-live__dot { animation: mktFlash 1.1s ease; }
@keyframes mktBreathe { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes mktFlash { 0% { transform: scale(1); } 40% { transform: scale(2.2); opacity: 0.5; } 100% { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .mkt-live__dot { animation: none !important; } }

/* Legend chips ------------------------------------------------------------ */
.mkt-legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.mkt-chip { display: inline-flex; align-items: center; gap: 7px; padding: 4px 11px 4px 9px; border-radius: 999px; border: 1px solid hsl(var(--accent) / 0.16); background: hsl(var(--accent) / 0.04); font-size: 0.76rem; cursor: pointer; transition: opacity 120ms ease, border-color 120ms ease; }
.mkt-chip:hover { border-color: hsl(var(--accent) / 0.4); }
.mkt-chip.is-off { opacity: 0.45; }
.mkt-chip.is-off .mkt-chip__val, .mkt-chip.is-off .mkt-chip__chg { visibility: hidden; }
.mkt-chip__dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.mkt-chip__name { font-weight: 600; }
.mkt-chip__val { color: var(--bulma-text-weak, #8b8b9c); font-variant-numeric: tabular-nums; }
.mkt-chip__chg { font-weight: 600; font-variant-numeric: tabular-nums; }
.mkt-chip__chg.is-up { color: #16a34a; } .mkt-chip__chg.is-down { color: #dc2626; }
html.theme-dark .mkt-chip__chg.is-up { color: #4ade80; } html.theme-dark .mkt-chip__chg.is-down { color: #f87171; }

.mkt-hint { text-align: center; font-size: 0.78rem; color: var(--bulma-text-weak, #8b8b9c); margin: 0 0 16px; }
.mkt-status { grid-column: 1 / -1; text-align: center; padding: 40px 0; color: var(--bulma-text-weak, #8b8b9c); }

/* Grid of per-series cards ------------------------------------------------ */
.mkt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 18px; }
.mkt-card { display: flex; flex-direction: column; transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease; }
.mkt-card:hover { border-color: hsl(var(--accent) / 0.5); transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.10); }
.mkt-card__open { display: flex; flex-direction: column; padding: 14px 16px 12px; color: inherit; text-decoration: none; }
.mkt-card__head { margin-bottom: 8px; }
.mkt-card__toprow { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mkt-card__title { display: flex; align-items: center; gap: 9px; min-width: 0; flex: 1; }
.mkt-dot { width: 13px; height: 13px; border-radius: 50%; flex-shrink: 0; background: var(--mat, hsl(var(--accent))); }
.mkt-card__name { font-size: 1.02rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mkt-card__now { flex-shrink: 0; font-size: 1.25rem; font-weight: 800; white-space: nowrap; font-variant-numeric: tabular-nums; }
.mkt-card__meta { display: block; margin-top: 4px; font-size: 0.72rem; line-height: 1.35; color: var(--bulma-text-weak, #8b8b9c); }
.mkt-card__meta .alt { font-variant-numeric: tabular-nums; }
.mkt-card__chart { position: relative; height: 165px; margin-top: 2px; }
.mkt-card__key { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 8px 0 0; font-size: 0.66rem; color: var(--bulma-text-weak, #8b8b9c); }
.mkt-card__key .k { display: inline-flex; align-items: center; gap: 4px; }
.mkt-card__key .k::before { content: ""; width: 12px; height: 0; border-top-width: 2px; border-top-style: solid; }
.mkt-card__key .k-price::before { border-top-color: var(--mat, hsl(var(--accent))); }
.mkt-card__key .k-median::before { border-top-style: dashed; border-top-color: #94a3b8; }
.mkt-card__key .k-vol::before { border-top-width: 7px; border-top-color: var(--mat, hsl(var(--accent))); opacity: 0.35; }
.mkt-card__tag { margin-left: auto; padding: 1px 8px; border-radius: 999px; font-size: 0.6rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--bulma-text-weak, #8b8b9c); border: 1px solid hsl(var(--accent) / 0.2); }
.mkt-card__go { font-size: 0.64rem; font-weight: 700; color: hsl(var(--accent)); }
html.theme-light .mkt-card__go { color: hsl(260 70% 48%); }

/* Methodology ------------------------------------------------------------- */
.mkt-method { margin: 26px auto 0; max-width: 900px; border: 1px solid hsl(var(--accent) / 0.14); border-radius: 12px; background: hsl(var(--accent) / 0.03); }
.mkt-method > summary { padding: 12px 16px; font-weight: 700; cursor: pointer; list-style: none; }
.mkt-method > summary::-webkit-details-marker { display: none; }
.mkt-method > summary::before { content: "＋ "; color: hsl(var(--accent)); font-weight: 700; }
.mkt-method[open] > summary::before { content: "－ "; }
.mkt-method__body { padding: 0 20px 14px; font-size: 0.85rem; line-height: 1.55; color: var(--bulma-text-weak, #8b8b9c); }
.mkt-method__body ul { margin: 0; padding-left: 18px; list-style: disc; }
.mkt-method__body li { margin: 6px 0; }
.mkt-method__body code { font-size: 0.82em; }

/* ===== Detail page ======================================================= */
.mktd-back { display: inline-block; margin-bottom: 12px; font-size: 0.82rem; font-weight: 600; color: hsl(var(--accent)); text-decoration: none; }
html.theme-light .mktd-back { color: hsl(260 70% 48%); }
.mktd-back:hover { text-decoration: underline; }

.mktd-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.mktd-id { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mktd-ic { width: 44px; height: 44px; border-radius: 12px; }
.mktd-ic .mat-ic__badge { font-size: 1.2rem; }
.mktd-dot { width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0; background: var(--mat, hsl(var(--accent))); }
.mktd-title { margin: 0; font-size: clamp(1.4rem, 3.4vw, 1.9rem); font-weight: 800; letter-spacing: -0.02em; }
.mktd-meta { margin: 3px 0 0; display: flex; align-items: center; gap: 10px; font-size: 0.75rem; }
.mktd-tag { padding: 1px 9px; border-radius: 999px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--bulma-text-weak, #8b8b9c); border: 1px solid hsl(var(--accent) / 0.2); }
.mktd-market { color: hsl(var(--accent)); text-decoration: none; font-weight: 600; }
html.theme-light .mktd-market { color: hsl(260 70% 48%); }
.mktd-market:hover { text-decoration: underline; }
.mktd-now { text-align: right; }
.mktd-price { display: block; font-size: 1.9rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.mktd-sub { display: block; margin-top: 3px; font-size: 0.78rem; color: var(--bulma-text-weak, #8b8b9c); }
.mktd-sub .alt { font-variant-numeric: tabular-nums; }

.mktd-controls { justify-content: flex-start; margin-bottom: 14px; }
.window-toggle { flex-wrap: wrap; }

.mktd-chartwrap { position: relative; border: 1px solid hsl(var(--accent) / 0.14); border-radius: 16px; background: hsl(var(--accent) / 0.03); padding: 14px 16px; }
html.theme-light .mktd-chartwrap { border-color: hsl(var(--accent) / 0.16); background: hsl(var(--accent) / 0.02); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04); }
.mktd-chart { position: relative; height: min(56vh, 460px); }
.mktd-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; margin: 0; font-weight: 600; color: var(--bulma-text-weak, #8b8b9c); background: hsl(var(--accent) / 0.04); border-radius: 16px; }
.mktd-loading[hidden] { display: none; }

.mktd-stats { display: flex; flex-wrap: wrap; gap: 12px; margin: 16px 0 0; }
.mktd-stat { flex: 1 1 120px; padding: 12px 14px; border: 1px solid hsl(var(--accent) / 0.14); border-radius: 12px; background: hsl(var(--accent) / 0.03); }
.mktd-stat__lbl { display: block; font-size: 0.66rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--bulma-text-weak, #8b8b9c); }
.mktd-stat__val { display: block; margin-top: 3px; font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.mktd-note { margin: 14px 0 0; font-size: 0.8rem; line-height: 1.5; color: var(--bulma-text-weak, #8b8b9c); }

@media (max-width: 560px) {
    .mkt-grid { grid-template-columns: 1fr; }
    .mktd-head { flex-direction: column; }
    .mktd-now { text-align: left; }
}

/* Phones (≈360px): fit everything to the viewport — no horizontal scroll, stacked tabs, tighter chrome. */
@media (max-width: 480px) {
    .mkt, .mktd { padding: 16px 10px 30px; }

    /* Tabs: full-width, stacked (the labels don't fit side-by-side) */
    .mkt-tabs { flex-direction: column; gap: 6px; margin-bottom: 14px; }
    .mkt-tab { width: 100%; justify-content: center; padding: 9px 12px; font-size: 0.9rem; }

    /* Controls: tighter pills so each group fits on its row */
    .mkt-controls { gap: 8px; margin-bottom: 14px; }
    .seg { padding: 2px; }
    .seg-btn { padding: 5px 10px; font-size: 0.74rem; letter-spacing: 0; }

    /* Hero: fill the viewport width instead of scrolling; slightly shorter */
    .mkt-hero { padding: 12px 10px 12px; }
    .mkt-hero__title { font-size: 1.05rem; }
    .mkt-hero__scroll { overflow-x: visible; }
    .mkt-hero__inner { min-width: 0; height: 300px; }

    /* Legend + cards */
    .mkt-legend { gap: 6px; }
    .mkt-chip { font-size: 0.72rem; padding: 3px 9px 3px 8px; }
    .mkt-card__open { padding: 12px 12px 10px; }
    .mkt-card__chart { height: 150px; }
    .mkt-card__now { font-size: 1.12rem; }

    /* Detail polish */
    .mktd-chartwrap { padding: 10px; }
    .mktd-chart { height: min(48vh, 320px); }
    .mktd-ic { width: 40px; height: 40px; }
    .mktd-price { font-size: 1.6rem; }
    .mktd-stat { flex: 1 1 44%; }
}
