/* Bitcoin Market Pulse — mobile-first styles. Dark is the default look (as in the
   original dashboard); a light variant follows the device setting. */

:root {
  color-scheme: dark;
  --bg: #0e1117;
  --surface: #161b22;
  --surface-2: #1f2630;
  --border: #2a3240;
  --text: #f2f4f7;
  --text-2: #b4bcc8;
  --muted: #8a94a3;
  --accent: #f7931a;
  --accent-ink: #1a1206;
  --grid: rgba(180, 188, 200, 0.14);
  --focus: #7cb7ff;

  /* chart series (validated against --surface) */
  --c-price: #e58200;
  --c-ma20: #3dcb72;
  --c-ma50: #c02f36;
  --c-ma200: #8b7cf6;
  --c-ind: #5b9cf5;

  /* zone colors for gauges */
  --z-red: #e5484d;
  --z-orange: #f08c2e;
  --z-yellow: #e2c044;
  --z-lgreen: #8ccb5e;
  --z-green: #2fa35a;
  --z-blue: #3ba3e8;

  --buy: #2fa35a;
  --buy-bg: rgba(47, 163, 90, 0.16);
  --wait: #d4a72c;
  --wait-bg: rgba(212, 167, 44, 0.16);
  --sell: #e5484d;
  --sell-bg: rgba(229, 72, 77, 0.16);
  --warn-bg: rgba(212, 167, 44, 0.14);
  --warn-border: rgba(212, 167, 44, 0.5);
  --err-bg: rgba(229, 72, 77, 0.14);
  --err-border: rgba(229, 72, 77, 0.5);

  --radius: 14px;
  --gap: 12px;
  --pad: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --border: #dde1e7;
    --text: #12161c;
    --text-2: #3c4552;
    --muted: #5f6977;
    --grid: rgba(60, 69, 82, 0.12);
    --focus: #1d64d8;
    --c-price: #c2410c;
    --c-ma20: #15a34a;
    --c-ma50: #991b1b;
    --c-ma200: #7c3aed;
    --c-ind: #2563eb;
    --buy: #15803d;
    --wait: #a16207;
    --sell: #b91c1c;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  min-height: 100vh;
  overflow-x: hidden;
  overflow-wrap: break-word;
}

h1, h2, h3, p { margin: 0; }

button { font: inherit; color: inherit; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.muted { color: var(--muted); }

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) max(var(--pad), env(safe-area-inset-right)) 10px max(var(--pad), env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { flex: none; border-radius: 8px; }
.brand h1 { font-size: 1.05rem; line-height: 1.2; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.updated { font-size: 0.78rem; color: var(--muted); min-height: 1.1em; }

.actions { display: flex; gap: 8px; flex: none; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  min-width: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:disabled { opacity: 0.7; cursor: progress; }
.btn-ghost { background: var(--surface); color: var(--text); font-weight: 700; letter-spacing: 0.02em; }
.icon-refresh { width: 20px; height: 20px; }
.btn.spinning .icon-refresh { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 439px) {
  .btn .label { display: none; }
  .btn { padding: 0 10px; }
}

/* ---------------------------------------------------------------- banners */
.banner {
  margin: 12px var(--pad) 0;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 0.92rem;
  border: 1px solid var(--warn-border);
  background: var(--warn-bg);
}
.banner.error { border-color: var(--err-border); background: var(--err-bg); }
.link-btn {
  background: none;
  border: 0;
  padding: 8px 4px;
  min-height: 44px;
  color: var(--text);
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

/* ----------------------------------------------------------------- layout */
main {
  display: grid;
  gap: var(--gap);
  padding: 12px max(var(--pad), env(safe-area-inset-right)) 24px max(var(--pad), env(safe-area-inset-left));
  max-width: 1280px;
  margin: 0 auto;
}

.grid-top, .grid-ind, .chart-grid, .grid-info { display: grid; gap: var(--gap); grid-template-columns: minmax(0, 1fr); }

@media (min-width: 700px) {
  .grid-top { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .grid-ind { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-ind > :last-child { grid-column: 1 / -1; }
  .chart-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-wide { grid-column: 1 / -1; }
  .grid-info { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}
@media (min-width: 1040px) {
  :root { --gap: 16px; --pad: 24px; }
  .grid-top { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); }
  .grid-ind { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-ind > :last-child { grid-column: auto; }
  .chart-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ------------------------------------------------------------------ cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px var(--pad) var(--pad);
  min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; min-height: 28px; }
.card-head h2, .card-head h3 { font-size: 0.95rem; font-weight: 650; color: var(--text-2); letter-spacing: 0.01em; }
.card-body { display: grid; gap: 10px; }

.meta { font-size: 0.8rem; color: var(--muted); }
.note { font-size: 0.85rem; padding: 8px 10px; border-radius: 10px; }
.note.warn { background: var(--warn-bg); border: 1px solid var(--warn-border); }

.badge { display: inline-block; font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; margin-left: 8px; vertical-align: middle; }
.badge.warn { background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--text); }

details { border-top: 1px solid var(--border); padding-top: 6px; }
details > summary {
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-2);
  list-style: none;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸"; margin-right: 8px; transition: transform 0.15s; }
details[open] > summary::before { transform: rotate(90deg); }
details > p { font-size: 0.88rem; color: var(--text-2); margin-bottom: 8px; }
.err-detail { border-top: 0; padding-top: 0; }
.err-detail code { display: block; font-size: 0.75rem; color: var(--muted); overflow-wrap: anywhere; white-space: pre-wrap; }

.unavailable { border: 1px dashed var(--err-border); background: var(--err-bg); border-radius: 12px; padding: 10px 12px; font-size: 0.9rem; }
.unavail-title { font-weight: 700; margin-bottom: 2px; }

/* skeleton */
.skeleton { display: grid; gap: 10px; }
.skeleton span { display: block; height: 18px; border-radius: 8px; background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s infinite linear; }
.skeleton span:first-child { height: 34px; width: 70%; }
.skeleton span:nth-child(3) { width: 85%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ------------------------------------------------------------ price card */
.price-value { font-size: clamp(2rem, 9vw, 2.6rem); font-weight: 750; letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.price-change { font-weight: 650; font-variant-numeric: tabular-nums; }
.price-change.up { color: var(--buy); }
.price-change.down { color: var(--sell); }

.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 4px 0 0; }
.kv > div { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.kv dt { font-size: 0.76rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kv dd { margin: 0; font-weight: 650; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.line-key { display: inline-block; width: 16px; height: 0; border-top: 3px solid; flex: none; }
.k-ma20 { border-color: var(--c-ma20); }
.k-ma50 { border-color: var(--c-ma50); border-top-style: dashed; }
.k-ma200 { border-color: var(--c-ma200); border-top-style: dotted; }

/* ---------------------------------------------------- recommendation card */
.signal {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 6px 16px;
  border-radius: 12px;
  justify-self: start;
  border: 2px solid;
}
.signal .icon { font-size: 1.1rem; }
.signal-buy { color: var(--buy); background: var(--buy-bg); }
.signal-wait { color: var(--wait); background: var(--wait-bg); }
.signal-sell { color: var(--sell); background: var(--sell-bg); }
.signal-none { font-size: 1.05rem; letter-spacing: 0; color: var(--text); background: var(--warn-bg); border-color: var(--warn-border); }
.signal-exp { color: var(--text-2); }

.score-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 0.9rem; color: var(--text-2); }
.score-head strong { font-size: 1.2rem; color: var(--text); font-variant-numeric: tabular-nums; }
.scorebar { position: relative; display: flex; height: 12px; border-radius: 999px; overflow: visible; margin: 8px 0 4px; }
.scorebar > span:not(.marker) { height: 100%; }
.zone-sell { width: 45%; background: var(--sell-bg); border: 1px solid var(--sell); border-radius: 999px 0 0 999px; }
.zone-wait { width: 10%; background: var(--wait-bg); border-top: 1px solid var(--wait); border-bottom: 1px solid var(--wait); }
.zone-buy { width: 45%; background: var(--buy-bg); border: 1px solid var(--buy); border-radius: 0 999px 999px 0; }
.marker {
  position: absolute;
  top: 50%;
  width: 6px;
  height: 24px;
  border-radius: 3px;
  background: var(--text);
  border: 2px solid var(--surface);
  transform: translate(-50%, -50%);
  box-sizing: content-box;
}
.score-scale { position: relative; height: 1.2em; font-size: 0.72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.score-scale span { position: absolute; transform: translateX(-50%); }
.score-scale span:nth-child(1) { left: 0; transform: none; }
.score-scale span:nth-child(2) { left: 45%; }
.score-scale span:nth-child(3) { left: 55%; }
.score-scale span:nth-child(4) { right: 0; transform: none; }
.score .meta { margin-top: 4px; }

.contrib ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.contrib li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 8px 10px; background: var(--surface-2); border-radius: 10px; border-left: 4px solid var(--border); }
.contrib li.pos { border-left-color: var(--buy); }
.contrib li.neg { border-left-color: var(--sell); }
.contrib li.zero { border-left-color: var(--wait); }
.contrib li.na { border-left-style: dashed; }
.c-name { font-weight: 650; font-size: 0.92rem; }
.c-pts { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 0.9rem; text-align: right; }
.c-factors { grid-column: 1 / -1; font-size: 0.84rem; color: var(--text-2); }
.disclaimer-short { font-size: 0.82rem; color: var(--muted); font-style: italic; }

/* ------------------------------------------------------- indicator cards */
.ind-body { display: grid; grid-template-columns: minmax(0, 150px) minmax(0, 1fr); align-items: center; gap: 12px; }
.gauge { width: 100%; height: auto; display: block; }
.g-tick { font-size: 11px; fill: var(--muted); font-family: var(--font); }
.g-needle { stroke: var(--text); stroke-width: 4; stroke-linecap: round; }
.g-hub { fill: var(--text); stroke: var(--surface); stroke-width: 2; }
.ind-value .big { font-size: 2.2rem; font-weight: 750; line-height: 1.1; font-variant-numeric: tabular-nums; }
.ind-value .unit { font-size: 1rem; color: var(--muted); font-weight: 600; margin-left: 2px; }
.zone { display: flex; align-items: center; gap: 8px; font-weight: 650; margin-top: 4px; line-height: 1.25; }
.zone-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.zc-red { background: var(--z-red); }
.zc-orange { background: var(--z-orange); }
.zc-yellow { background: var(--z-yellow); }
.zc-lgreen { background: var(--z-lgreen); }
.zc-green { background: var(--z-green); }
.zc-blue { background: var(--z-blue); }
.impact { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 0.88rem; color: var(--text-2); background: var(--surface-2); padding: 8px 10px; border-radius: 10px; }
.impact strong { color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--buy); }
.neg { color: var(--sell); }
.impact strong.pos { color: var(--buy); }
.impact strong.neg { color: var(--sell); }

/* ----------------------------------------------------------------- charts */
.charts { display: grid; gap: var(--gap); }
.charts-head { display: grid; gap: 8px; }
.charts-head h2 { font-size: 1.15rem; }
.hint { font-size: 0.82rem; color: var(--muted); }

.range { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 6px; }
@media (min-width: 560px) { .range { grid-template-columns: repeat(8, minmax(0, 1fr)); } }
.range button {
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-2);
  font-weight: 650;
  cursor: pointer;
  touch-action: manipulation;
}
.range button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); }

.chip {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.82rem;
  font-weight: 650;
  cursor: pointer;
  position: relative;
}
.chip::after { content: ""; position: absolute; inset: -6px -2px; } /* 44px+ touch target */
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.chart-grid.is-loading .chart-card { opacity: 0.55; transition: opacity 0.2s; }
.chart { display: grid; gap: 6px; }
.chart-plot { width: 100%; min-height: 120px; }
.chart-plot svg { display: block; width: 100%; height: auto; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.chart-plot svg:focus-visible { outline: 3px solid var(--focus); }
.chart-empty { display: grid; place-items: center; min-height: 160px; color: var(--muted); text-align: center; font-size: 0.9rem; padding: 0 12px; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--border); }
.chart .tick { font-size: 11px; fill: var(--muted); font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart .ref { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; opacity: 0.8; }
.chart .ref-label { font-size: 10.5px; fill: var(--text-2); font-family: var(--font); paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
.chart .crosshair { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .hit { fill: transparent; cursor: crosshair; }

.chart-readout { min-height: 3.1em; font-size: 0.82rem; }
.ro-date { font-weight: 650; color: var(--text); }
.ro-hint { color: var(--muted); font-weight: 400; }
.ro-items { display: flex; flex-wrap: wrap; gap: 2px 14px; }
.ro-item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.ro-label { color: var(--text-2); }
.ro-value { font-weight: 650; font-variant-numeric: tabular-nums; }
.swatch { width: 22px; height: 8px; flex: none; }
.chart-note { font-size: 0.78rem; color: var(--muted); overflow-wrap: anywhere; }
.chart-note:empty { display: none; }

/* ------------------------------------------------------------ info cards */
.prose { font-size: 0.9rem; color: var(--text-2); }
.prose ul { margin: 0; padding-left: 1.1em; display: grid; gap: 6px; }

.footer { padding: 8px max(var(--pad), env(safe-area-inset-right)) calc(28px + env(safe-area-inset-bottom)) max(var(--pad), env(safe-area-inset-left)); max-width: 1280px; margin: 0 auto; display: grid; gap: 10px; justify-items: start; }
.disclaimer { font-size: 0.82rem; color: var(--muted); border-left: 3px solid var(--accent); padding-left: 10px; }
.install-hint { font-size: 0.8rem; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (forced-colors: active) {
  .signal, .btn, .range button, .chip { border: 1px solid CanvasText; }
}
