:root {
  --bg: #0d1117;
  --panel: #151b23;
  --panel-2: #1b232d;
  --line: #26303c;
  --text: #e6edf3;
  --muted: #8b98a8;
  --green: #2ee6a8;
  --red: #ff6b6b;
  --accent: #4cc2ff;
  --radius: 14px;
}

html, body { overflow-x: hidden; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 600px at 80% -10%, #16232f 0%, var(--bg) 55%);
  color: var(--text);
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: .2px; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 16px 0 8px; }
small { font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px clamp(14px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
  background: rgba(13, 17, 23, .82);
  backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand p { margin: 2px 0 0; font-size: 12.5px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 4px rgba(139,152,168,.12); }
.dot.live { background: var(--green); box-shadow: 0 0 0 4px rgba(46,230,168,.16); }
.dot.stale { background: #ffb020; box-shadow: 0 0 0 4px rgba(255,176,32,.16); }
.dot.down { background: var(--red); box-shadow: 0 0 0 4px rgba(255,107,107,.16); }
nav { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13.5px; }
nav a { color: var(--muted); }
nav a:hover { color: var(--text); text-decoration: none; }

main { padding: 20px clamp(12px, 4vw, 40px) 40px; display: grid; gap: 16px; max-width: 1280px; margin: 0 auto; }

.card {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }

.hero { display: grid; gap: 18px; grid-template-columns: minmax(200px, 1fr) auto auto; align-items: center; }
.label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.rate { font-size: clamp(34px, 7vw, 54px); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.05; }
.rate small { font-size: 16px; color: var(--muted); margin-left: 6px; font-weight: 500; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  min-width: 0; flex: 1 1 70px; padding: 8px 10px; border-radius: 10px; background: #111820;
  border: 1px solid var(--line); font-size: 12px; color: var(--muted);
}
.chip b { display: block; font-size: 14px; color: var(--text); font-variant-numeric: tabular-nums; }
.up { color: var(--green) !important; }
.down { color: var(--red) !important; }
.fees { display: flex; gap: 18px; flex-wrap: wrap; }
.fees b { display: block; font-variant-numeric: tabular-nums; }

.periods { display: flex; gap: 6px; flex-wrap: wrap; }
.periods button, .ghost, #tradeForm button {
  background: #111820; color: var(--muted); border: 1px solid var(--line);
  padding: 7px 11px; border-radius: 9px; cursor: pointer; font-size: 12.5px;
}
.periods button:hover, .ghost:hover { color: var(--text); border-color: #35424f; }
.periods button.active { color: #06121a; background: var(--green); border-color: var(--green); font-weight: 600; }
#tradeForm button { background: var(--green); color: #06121a; border-color: var(--green); font-weight: 600; }

.chart-wrap { position: relative; }
#chartCanvas { height: clamp(280px, 46vh, 520px); }
.legend {
  position: absolute; top: 8px; left: 10px; pointer-events: none;
  font-size: 12.5px; color: var(--muted); background: rgba(13,17,23,.55);
  padding: 4px 8px; border-radius: 8px; font-variant-numeric: tabular-nums;
}
.chart-foot { display: flex; justify-content: space-between; gap: 10px; margin-top: 8px; flex-wrap: wrap; font-size: 12.5px; }

.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.stat { background: #111820; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.stat span { display: block; font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat b { font-size: 18px; font-variant-numeric: tabular-nums; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.two ul, #levels ul { margin: 0; padding-left: 18px; }

.calc { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
label { display: block; font-size: 12.5px; color: var(--muted); }
input, select {
  width: 100%; margin-top: 5px; padding: 9px 10px; border-radius: 9px;
  border: 1px solid var(--line); background: #0d131a; color: var(--text); font-size: 14px;
  font-variant-numeric: tabular-nums;
}
input:focus, select:focus { outline: 2px solid rgba(76,194,255,.35); border-color: var(--accent); }

.table-wrap { overflow-x: auto; margin-top: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; }
td.num { font-variant-numeric: tabular-nums; }
tr:hover td { background: rgba(255,255,255,.02); }
.del { color: var(--red); cursor: pointer; background: none; border: 0; font-size: 15px; }

footer { padding: 0 clamp(12px, 4vw, 40px) 30px; max-width: 1280px; margin: 0 auto; }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1f2937; border: 1px solid var(--line); color: var(--text);
  padding: 10px 16px; border-radius: 10px; opacity: 0; transition: .2s; pointer-events: none; z-index: 30;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; }
  .two { grid-template-columns: 1fr; }
  .top { flex-direction: column; align-items: flex-start; }
}

/* --- narrow phones: nothing may stick out of the viewport --- */
@media (max-width: 560px) {
  .periods { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .periods button { flex: 0 0 auto; }
  .chips { gap: 6px; }
  .chip { flex: 1 1 56px; padding: 7px 8px; }
  .chip b { font-size: 13px; }
  .fees { gap: 12px; }
  .rate { font-size: 40px; }
  #chartCanvas { height: 260px; }
  .card { padding: 14px; }
  nav { gap: 10px; font-size: 13px; }
  .stat b { font-size: 16px; }
}
/* --- containment: nothing may widen the page --- */
main, .card, .hero, .chart-wrap, .periods, .chips, .fees, .table-wrap, .grid, .two { min-width: 0; max-width: 100%; }
#chartCanvas { width: 100%; max-width: 100%; min-width: 0; }
.table-wrap { overflow-x: auto; }