:root {
  color-scheme: dark;
  --bg: #14110d;
  --panel: #1d1811;
  --panel-2: #262019;
  --border: #382d20;
  --text: #f2ede4;
  --muted: #9c9182;
  --orange: #d97757;
  --orange-soft: rgba(217, 119, 87, 0.14);
  --orange-border: rgba(217, 119, 87, 0.4);
  --green: #4ade80;
  --red: #f87171;
  --amber: #f0b94d;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background: radial-gradient(1000px 500px at 50% -8%, #241c14 0%, var(--bg) 55%);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 40px;
  max-width: 520px;
  margin-inline: auto;
}

.app-header {
  padding: 16px 14px 8px;
  position: sticky; top: 0; z-index: 5;
  background: linear-gradient(180deg, var(--bg) 70%, transparent);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  font-size: 26px; width: 42px; height: 42px; border-radius: 12px;
  background: var(--orange-soft); border: 1px solid var(--orange-border);
  display: flex; align-items: center; justify-content: center;
}
h1 { font-size: 18px; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
.sub { color: var(--muted); font-size: 11.5px; margin-top: 1px; }

/* ---- Equity header (always visible, small font, click to expand) ---- */
.equity-header {
  margin-top: 10px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 8px 12px; cursor: pointer; font-size: 11.5px;
}
.equity-header .row1 { display: flex; justify-content: space-between; align-items: center; }
.equity-header .total { font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }
.equity-header .growth { font-variant-numeric: tabular-nums; }
.equity-header .growth.pos { color: var(--green); }
.equity-header .growth.neg { color: var(--red); }
.equity-header .timer { color: var(--muted); }
.equity-header .chevron { color: var(--muted); font-size: 10px; transition: transform 0.15s; }
.equity-header.open .chevron { transform: rotate(90deg); }
.equity-header .detail {
  display: none; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border);
  gap: 6px; flex-direction: column;
}
.equity-header.open .detail { display: flex; }
.equity-header .acc-row { display: flex; justify-content: space-between; }
.equity-header .acc-row .name { color: var(--muted); }
.equity-header .reset-link { color: var(--orange); text-decoration: underline; font-size: 10.5px; margin-top: 4px; }

.tabs {
  display: flex; gap: 4px; padding: 10px 14px 6px;
  position: sticky; top: 62px; z-index: 5; background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.tab {
  flex: 1; background: transparent; border: none; color: var(--muted);
  font-size: 12.5px; font-weight: 600; padding: 9px 4px; border-radius: 9px 9px 0 0;
  cursor: pointer; position: relative; transition: color 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--orange); }
.tab.active::after {
  content: ""; position: absolute; left: 10%; right: 10%; bottom: -7px; height: 2px;
  background: var(--orange); border-radius: 2px;
}

main { padding: 12px 14px 0; }

button {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 14px; font-size: 13px; cursor: pointer;
  transition: transform 0.06s ease, filter 0.15s ease;
}
button:active { transform: scale(0.97); }
button:hover { filter: brightness(1.15); }
button.primary { background: var(--orange); color: #1a0f08; border: none; font-weight: 700; }
button.danger { background: linear-gradient(180deg, #fb7373, #e35555); color: #2a0a0a; border: none; font-weight: 700; }
button:disabled { opacity: 0.45; cursor: default; }

.card {
  background: linear-gradient(180deg, var(--panel), #171209);
  border: 1px solid var(--border); border-radius: 16px;
  padding: 14px; margin-bottom: 12px;
  box-shadow: 0 8px 20px -16px rgba(0,0,0,0.8);
}

/* ---- Overview tab ---- */
.stat-row { display: flex; gap: 10px; margin-bottom: 12px; }
.stat {
  flex: 1; background: linear-gradient(180deg, var(--panel), #171209);
  border: 1px solid var(--border); border-radius: 14px; padding: 12px;
}
.stat .label { color: var(--muted); font-size: 11px; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.03em; }
.stat .value { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .value.pos { color: var(--green); }
.stat .value.neg { color: var(--red); }
.stat .hint { color: var(--muted); font-size: 10px; margin-top: 3px; line-height: 1.3; }

.action-row { display: flex; gap: 8px; margin-bottom: 12px; }
.action-row button { flex: 1; }

.banner {
  background: #3a2a0f; border: 1px solid #6b4d1a; color: #ffd479; border-radius: 12px;
  padding: 11px 13px; font-size: 12.5px; margin-bottom: 12px; line-height: 1.4;
}
.banner.info { background: var(--orange-soft); border-color: var(--orange-border); color: #f0c4ae; }

.active-list h2, .events h2, .market h2 { font-size: 13px; margin: 4px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 700; }

/* ---- Coins tab: compact list, expandable ---- */
.coin-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 13px;
  padding: 11px 12px; margin-bottom: 8px; cursor: pointer;
}
.coin-row:hover { border-color: var(--orange-border); }
.coin-icon {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; position: relative;
  background: var(--panel-2); border: 1px solid var(--border); overflow: hidden;
}
.coin-icon img { width: 100%; height: 100%; object-fit: cover; display: block; }
.coin-icon .icon-fallback {
  display: none; align-items: center; justify-content: center; width: 100%; height: 100%;
  font-size: 12px; font-weight: 700; color: var(--orange);
}
.coin-icon.img-failed img { display: none; }
.coin-icon.img-failed .icon-fallback { display: flex; }
.coin-row .name-wrap { flex: 1; min-width: 0; }
.coin-row .coin-name { font-weight: 700; font-size: 14.5px; }
.coin-row .coin-note { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.coin-row .coin-price { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chevron { color: var(--muted); font-size: 11px; transition: transform 0.15s; }
.chevron.open { transform: rotate(90deg); color: var(--orange); }

.coin-detail {
  background: var(--panel-2); border: 1px solid var(--border); border-top: none;
  border-radius: 0 0 13px 13px; margin: -10px 0 8px; padding: 12px; font-size: 12.5px;
}
.pistons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 4px 0 10px; }
.piston {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px; font-size: 12px; display: flex; flex-direction: column; gap: 6px;
}
.piston.empty { align-items: center; justify-content: center; min-height: 60px; color: var(--muted); font-style: italic; }
.piston .dir { color: var(--orange); font-weight: 700; font-size: 10px; letter-spacing: 0.02em; }
.piston .row { display: flex; justify-content: space-between; color: var(--muted); gap: 6px; }
.phase-badge {
  display: inline-block; border: 1px solid; border-radius: 20px; padding: 3px 9px;
  font-size: 10.5px; font-weight: 700; width: fit-content;
}
.target-line { color: var(--text); font-size: 11px; line-height: 1.4; opacity: 0.9; }
.target-line b { color: var(--orange); }
.waiting-line { color: var(--amber); font-size: 11px; font-style: italic; }

.toggle {
  width: 40px; height: 23px; border-radius: 12px; background: var(--panel-2);
  border: 1px solid var(--border); position: relative; cursor: pointer; flex-shrink: 0;
  transition: background 0.15s;
}
.toggle.on { background: var(--green); border-color: var(--green); }
.toggle .dot {
  position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%;
  background: #fff; transition: left 0.15s; box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.toggle.on .dot { left: 19px; }
.toggle.small { width: 34px; height: 20px; }
.toggle.small .dot { width: 14px; height: 14px; }
.toggle.small.on .dot { left: 16px; }

.settings-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; }
.settings-row .label { color: var(--muted); }

/* Leverage stepper - buttons only, no draggable slider (accidental-flick risk) */
.lev-stepper { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.lev-stepper button {
  padding: 6px 10px; font-size: 12px; font-weight: 700; min-width: 34px;
}
.lev-val { flex: 1; text-align: center; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 14px; }

.global-lev-card {
  background: linear-gradient(180deg, var(--panel), #171209); border: 1px solid var(--orange-border);
  border-radius: 14px; padding: 12px 14px; margin-bottom: 12px;
}
.global-lev-card .title { font-weight: 700; font-size: 13px; margin-bottom: 2px; }
.global-lev-card .hint { color: var(--muted); font-size: 11px; margin-bottom: 8px; }
.global-lev-card .lev-stepper { margin-bottom: 8px; }
.global-lev-card .lev-stepper button { flex: 0 0 auto; }
.global-lev-card .apply-btn { width: 100%; }

.mini-btn {
  width: 26px; height: 26px; padding: 0; border-radius: 8px; font-size: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--panel); color: var(--muted); flex-shrink: 0;
}
.mini-btn:hover { color: var(--red); border-color: var(--red); }
.detail-actions { display: flex; gap: 8px; margin-top: 10px; }
.detail-actions button { flex: 1; font-size: 12px; padding: 8px; }

/* ---- Market tab ---- */
.signal-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 13px;
  padding: 12px; margin-bottom: 8px;
}
.signal-card .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.signal-card .coin-name { font-weight: 700; font-size: 13.5px; }
.confirmed-pill {
  font-size: 10px; font-weight: 700; border-radius: 20px; padding: 3px 8px; border: 1px solid;
}
.confirmed-pill.yes { color: var(--green); border-color: var(--green); background: rgba(74,222,128,0.1); }
.confirmed-pill.no { color: var(--muted); border-color: var(--border); }
.signal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; font-size: 12px; }
.signal-grid .k { color: var(--muted); }
.signal-grid .v { font-variant-numeric: tabular-nums; text-align: right; }
.signal-grid .v.hit { color: var(--amber); font-weight: 700; }

/* ---- Journal ---- */
.events { background: linear-gradient(180deg, var(--panel), #171209); border: 1px solid var(--border); border-radius: 16px; padding: 14px; }
.event-row {
  font-size: 12px; padding: 8px 0; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; gap: 8px; align-items: flex-start;
}
.event-row:last-child { border-bottom: none; }
.event-detail { color: var(--muted); }
.event-pnl { font-weight: 700; white-space: nowrap; }
.event-pnl.pos { color: var(--green); }
.event-pnl.neg { color: var(--red); }

.row.muted { color: var(--muted); font-style: italic; font-size: 12px; }
.error { color: var(--red); text-align: center; padding: 30px 10px; font-size: 13px; line-height: 1.6; }
.empty-state { text-align: center; color: var(--muted); font-size: 12.5px; padding: 24px 10px; }
