/* =====================================================================
   Tiltless v3 — motion, mobile layout and new feature styles.
   Loaded after styles.css (which holds the base design).
   ===================================================================== */
:root {
  --amber: #fbbf24;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.45);
  --mobile-nav-h: 64px;
}
[data-theme="light"] { --shadow-lg: 0 24px 60px rgba(15, 23, 42, 0.16); }
@property --pct { syntax: "<percentage>"; inherits: false; initial-value: 50%; }
@property --p { syntax: "<percentage>"; inherits: false; initial-value: 0%; }

body { transition: background-color 0.25s ease; }
::selection { background: var(--purple-soft); }
:focus-visible { outline: 2px solid var(--purple); outline-offset: 2px; border-radius: 6px; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- Keyframes ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideL { from { opacity: 0; transform: translateX(-14px); } to { opacity: 1; transform: none; } }
@keyframes slideR { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }
@keyframes draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes growY { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes growX { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes pop { 0% { transform: scale(0.6); opacity: 0; } 60% { transform: scale(1.06); opacity: 1; } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-6px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }
@keyframes shimmer { from { background-position: -400px 0; } to { background-position: 400px 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes ping { 0% { transform: scale(1); opacity: 0.55; } 80%, 100% { transform: scale(2.4); opacity: 0; } }
@keyframes sheen { from { transform: translateX(-120%) skewX(-20deg); } to { transform: translateX(320%) skewX(-20deg); } }
@keyframes radarIn { from { transform: scale(0.2); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- Page entrance (staggered) ---------- */
.panel.active { animation: fade 0.22s ease both; }
.entering .card, .entering .stat-card, .entering .lb-wrap > *, .entering .ins-block {
  animation: rise 0.5s var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 40ms);
}
.swap-l { animation: slideL 0.32s var(--ease-out) both; }
.swap-r { animation: slideR 0.32s var(--ease-out) both; }
.shake { animation: shake 0.42s ease both; }

/* ---------- Buttons: tactile press + smoother hovers ---------- */
.primary-btn, .ghost-btn, .danger-btn, .icon-btn, .ccy-chip, .seg button, .range-tabs button, .nav-item, .link-btn, .demo-pill {
  transition: background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease, opacity 0.18s;
}
.primary-btn:active:not(:disabled), .ghost-btn:active:not(:disabled), .danger-btn:active:not(:disabled), .icon-btn:active, .ccy-chip:active, .seg button:active, .demo-pill:active { transform: scale(0.97); }
.primary-btn:hover:not(:disabled) { box-shadow: 0 6px 18px -8px var(--purple); }
.link-btn:hover { opacity: 0.8; }
.danger-btn.solid { background: var(--red); color: #fff; border-color: var(--red); }
.danger-btn.solid:hover:not(:disabled) { background: #ef4444; }
#news-refresh.spinning { pointer-events: none; opacity: 0.6; }

/* ---------- Cards: subtle hover ---------- */
.card { transition: border-color 0.2s ease, box-shadow 0.25s ease, background-color 0.25s; }
.stat-card:hover, .ins-block:hover { border-color: var(--border-strong); box-shadow: 0 10px 30px -18px rgba(0, 0, 0, 0.6); }
.stat-card h2 { font-variant-numeric: tabular-nums; }

/* ---------- Sidebar active indicator (slides between items) ---------- */
.nav { position: relative; }
.nav-indicator {
  position: absolute; left: 0; right: 0; top: 0; height: 38px; opacity: 0;
  border-radius: var(--radius-sm); background: var(--purple-soft);
  transition: transform 0.35s var(--ease-out), height 0.35s var(--ease-out), opacity 0.2s;
  pointer-events: none; z-index: 0;
}
.nav .nav-item { position: relative; z-index: 1; }
.nav .nav-item.active { background: transparent; }
.nav-item .nav-icon { transition: transform 0.2s var(--ease-out), color 0.2s; }
.nav-item:hover .nav-icon { transform: translateX(2px); }
.sidebar { transition: width 0.25s var(--ease-out); }
.user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* sync status */
.sync-status { display: flex; align-items: center; gap: 10px; padding: 6px 12px; font-size: 12px; color: var(--text-muted); }
/* nothing to say when everything is saved: the status only appears while saving or if a save failed */
.sync-status[data-state="ok"] { display: none; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex-shrink: 0; position: relative; margin: 0 5px; transition: background-color 0.2s; }
.sync-status[data-state="saving"] .sync-dot { background: var(--amber); }
.sync-status[data-state="saving"] .sync-dot::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: inherit; animation: ping 1.1s ease-out infinite; }
.sync-status[data-state="error"] .sync-dot { background: var(--red); }
.sync-status[data-state="error"] { color: var(--red); }
.sync-status[data-state="local"] .sync-dot { background: var(--text-muted); }
.app-shell.collapsed .sync-status { justify-content: center; padding: 6px 0; }
.app-shell.collapsed .lang-switch.side-lang { display: none; }

/* language + theme switches */
.lang-switch { display: inline-flex; gap: 2px; padding: 3px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--border); }
.lang-switch button { padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 700; color: var(--text-dim); transition: background-color 0.18s, color 0.18s; }
.lang-switch button.active { background: var(--purple); color: #fff; }
.side-lang { margin: 2px 12px 6px; align-self: flex-start; }
.pref-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; color: var(--text-dim); }
.pref-row:last-child { border-bottom: 0; }

/* ---------- Sliding segmented controls ---------- */
.seg-slider { position: relative; isolation: isolate; }
.seg-slider .seg-pill {
  position: absolute; top: 3px; bottom: 3px; left: 0; width: 0; border-radius: 7px;
  background: var(--purple); z-index: -1; transition: transform 0.35s var(--ease-out), width 0.35s var(--ease-out);
}
.auth-tabs.seg-slider .seg-pill { top: 4px; bottom: 4px; border-radius: 8px; }
.seg-slider button.active { background: transparent !important; color: #fff; }
.seg button { transition: background-color 0.2s, color 0.2s; }

/* ---------- Banners ---------- */
.local-banner { padding: 9px 32px; font-size: 12.5px; background: rgba(251, 191, 36, 0.1); color: var(--amber); border-bottom: 1px solid rgba(251, 191, 36, 0.25); }
.banner { animation: rise 0.35s var(--ease-out) both; }
.owner-banner { animation: fade 0.25s ease both; }

/* ---------- PF ring + discipline bar animate their values ---------- */
.mini-ring { transition: --pct 0.8s var(--ease-out); }
.pnl-fill { transition: left 0.6s var(--ease-out), width 0.6s var(--ease-out), background-color 0.3s; }
.pnl-zero { transition: left 0.6s var(--ease-out); }
.trade-dots .dot { transition: background-color 0.25s, border-color 0.25s; }
.trade-dots .dot.filled { animation: pop 0.4s var(--ease-out) both; animation-delay: calc(var(--i) * 60ms); }
.trade-dots .dot.over { border-color: var(--red); background: var(--red); }

/* ---------- Chart ---------- */
.chart-anim .chart-line { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1s var(--ease-in-out) forwards; }
.chart-anim .chart-area { animation: fade 0.8s ease 0.35s both; }
.chart-anim .chart-end { animation: fade 0.4s ease 0.9s both; }
.end-pulse { transform-box: fill-box; transform-origin: center; animation: ping 2.4s ease-out infinite; }
.chart-tip { opacity: 0; transition: opacity 0.12s ease; }
.chart-tip.show { opacity: 1; }
.chart-wrap { touch-action: pan-y; }

/* Flag emoji: Windows has no flag glyphs, so use Noto (Google Fonts only ships the glyphs used) */
.flag { font-family: "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji", sans-serif; font-size: 14px; letter-spacing: -1px; }

/* ---------- Tables ---------- */
/* sideways scrolling only: rows sliding in (rise animation) must not flash a vertical
   scrollbar that shifts the columns (.imp-table opts back in to vertical scroll) */
.table-scroll { overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }
.trade-row td:first-child { white-space: nowrap; }
.trades-table tbody .trade-row { animation: rise 0.4s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 35ms); }
.user-chip { font-size: 10.5px; font-weight: 600; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim); margin-left: 4px; }

/* ---------- Empty states ---------- */
.empty-glyph { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; font-size: 22px; color: var(--purple); background: var(--purple-soft); animation: pop 0.5s var(--ease-out) both; }
.demo-pill { cursor: pointer; }
.demo-pill:hover { background: rgba(var(--ac-rgb), 0.24); }

/* ---------- Calendar ---------- */
.cal-cell { transition: border-color 0.18s, background-color 0.18s, transform 0.18s var(--ease-out), box-shadow 0.18s; }
.cal-cell[data-key]:hover { transform: translateY(-2px); }
.cal-cell.win { background: linear-gradient(180deg, transparent 40%, rgba(52, 211, 153, 0.09)); }
.cal-cell.loss { background: linear-gradient(180deg, transparent 40%, rgba(248, 113, 113, 0.09)); }
.cell-pnl-c { display: none; font-size: 11px; font-weight: 700; }
/* desktop months whose amounts don't fit the cells show the short form (set by fitCalCells) */
.cal-grid.tight .cell-pnl { display: none; }
.cal-grid.tight .cell-pnl-c { display: block; font-size: 14px; margin-top: 2px; }
.today-badge { min-width: 22px; text-align: center; }
.r-bar { transform-origin: bottom; animation: growY 0.6s var(--ease-out) both; animation-delay: calc(var(--i) * 70ms); transition: height 0.5s var(--ease-out); }
.r-bar.neg { background: var(--red); }
.week { animation: rise 0.4s var(--ease-out) both; animation-delay: calc(var(--i) * 50ms); }
.week-label small { color: var(--text-muted); font-weight: 500; margin-left: 4px; }
.day-head { flex-wrap: wrap; row-gap: 10px; }
.day-head .primary-btn, .day-head .ghost-btn, .day-nav h3 { white-space: nowrap; }
.day-nav h3 { font-size: 15px; }

/* ---------- Tags ---------- */
.tag.pop { animation: pop 0.3s var(--ease-out) both; }
.tag i:hover { opacity: 1; color: var(--red); }

/* ---------- Overlays: modal / lightbox / dialogs / sheet ---------- */
.modal-overlay, .lightbox, .dlg-overlay, .sheet-overlay { opacity: 0; transition: opacity 0.2s ease; }
.modal-overlay.open, .lightbox.open, .dlg-overlay.open, .sheet-overlay.open { opacity: 1; }
.modal { transform: translateY(14px) scale(0.98); transition: transform 0.28s var(--ease-out); }
.modal-overlay.open .modal { transform: none; }
.lightbox-stage { transform: scale(0.96); transition: transform 0.25s var(--ease-out); }
.lightbox.open .lightbox-stage { transform: none; }
.img-drop { transition: border-color 0.18s, color 0.18s, background-color 0.18s; }
.img-drop img { animation: fade 0.3s ease both; max-height: 260px; object-fit: contain; }

.dlg-overlay { position: fixed; inset: 0; z-index: 600; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(3px); }
.dlg-overlay.hidden { display: none; }
.dlg { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 16px; padding: 22px; box-shadow: var(--shadow-lg); transform: translateY(10px) scale(0.97); transition: transform 0.26s var(--ease-out); }
.dlg-overlay.open .dlg { transform: none; }
.dlg-title { font-size: 16px; margin-bottom: 8px; line-height: 1.35; }
.dlg-body { color: var(--text-dim); font-size: 13.5px; line-height: 1.5; margin-bottom: 14px; }
.dlg-input { width: 100%; font: inherit; font-size: 14px; color: var(--text); background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 9px; padding: 10px 12px; margin: 4px 0 14px; outline: none; }
.dlg-input:focus { border-color: var(--purple); box-shadow: 0 0 0 3px var(--purple-soft); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Toasts ---------- */
.toast-host { position: fixed; right: 20px; bottom: 20px; z-index: 700; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px; max-width: 380px;
  padding: 12px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg); font-size: 13px; color: var(--text);
  opacity: 0; transform: translateY(12px) scale(0.98); transition: opacity 0.22s ease, transform 0.3s var(--ease-out);
  position: relative; overflow: hidden;
}
.toast.in { opacity: 1; transform: none; }
.toast-body { display: flex; flex-direction: column; gap: 2px; }
.toast-body b { font-size: 13px; }
.toast-body span { color: var(--text-dim); }
.toast-ico { font-size: 16px; }
.toast.error { border-color: rgba(248, 113, 113, 0.4); }
.toast.error .toast-ico { color: var(--red); }
.toast.ok .toast-ico { color: var(--green); }
.toast-act { margin-left: 6px; padding: 5px 10px; border-radius: 7px; font-size: 12px; font-weight: 700; color: var(--purple); background: var(--purple-soft); }
.toast.achv { border-color: rgba(251, 191, 36, 0.45); background: linear-gradient(135deg, rgba(251, 191, 36, 0.12), var(--surface) 60%); }
.toast.achv::after { content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 40%; background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.16), transparent); animation: sheen 1.3s var(--ease-in-out) 0.3s both; }

/* ---------- Skeleton loaders ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 0, rgba(255, 255, 255, 0.07) 40%, var(--surface-2) 80%);
  background-size: 800px 100%; animation: shimmer 1.3s linear infinite; border-radius: 10px;
}
[data-theme="light"] .skeleton { background-image: linear-gradient(90deg, #eef0f4 0, #f8f9fb 40%, #eef0f4 80%); }
.sk-row { height: 38px; margin: 6px 0; }
.sk-card { height: 86px; }
.candles.skeleton { height: 130px; }
.news-empty { padding: 14px 0; }

/* ---------- News ---------- */
.event-row, .feed-card { animation: rise 0.38s var(--ease-out) both; animation-delay: calc(min(var(--i, 0), 12) * 30ms); }
.event-row.past { opacity: 0.6; }
a.feed-card.link { transition: border-color 0.2s, background-color 0.2s, transform 0.2s var(--ease-out); }
a.feed-card.link:hover { transform: translateY(-2px); }
.impact.pulse { position: relative; }
.impact.pulse::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: inherit; animation: ping 1.6s ease-out infinite; }
.news-next-strip { animation: rise 0.35s var(--ease-out) both; }

/* ---------- Button spinner (auth) ---------- */
.auth-submit { position: relative; }
.auth-submit .spinner { display: none; width: 15px; height: 15px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.35); border-top-color: #fff; animation: spin 0.7s linear infinite; }
.auth-submit.loading .spinner { display: inline-block; }

/* ---------- Auth screen ---------- */
.auth-overlay { transition: opacity 0.3s ease; overflow: hidden; }
.auth-overlay.leaving { opacity: 0; pointer-events: none; }
.auth-glow {
  position: absolute; width: 620px; height: 620px; border-radius: 50%; filter: blur(90px); opacity: 0.3;
  background: radial-gradient(circle at 30% 30%, var(--purple), transparent 60%), radial-gradient(circle at 70% 70%, var(--green), transparent 55%);
  animation: spin 40s linear infinite; pointer-events: none;
}
.auth-card { position: relative; animation: rise 0.6s var(--ease-out) both; }
.auth-lang { position: absolute; top: 14px; right: 14px; }
.auth-lang button { padding: 3px 8px; font-size: 11px; }
.brand-logo { transition: transform 0.6s var(--ease-out); }
.brand:hover .brand-logo { transform: rotate(135deg); }

/* ---------- Boot: don't flash the login card while we check for a saved session ---------- */
.boot-spinner { display: none; }
.booting .auth-card { visibility: hidden; }
.booting .boot-spinner {
  display: block; position: fixed; left: 50%; top: 50%; width: 30px; height: 30px; margin: -15px 0 0 -15px; z-index: 400;
  border-radius: 50%; border: 3px solid var(--purple-soft); border-top-color: var(--purple); animation: spin 0.8s linear infinite;
}

/* ---------- Score card ---------- */
.edge-pie { position: relative; }
.edge-pie span { position: absolute; inset: 0; border-radius: 50%; background: conic-gradient(var(--purple) 0 var(--p), transparent var(--p)); transition: --p 0.9s var(--ease-out); }
.score-wrap { display: flex; flex-direction: column; gap: 4px; }
.score-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.score-big { display: flex; align-items: baseline; gap: 4px; }
.score-num { font-size: 44px; font-weight: 800; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; line-height: 1; }
.score-of { color: var(--text-muted); font-weight: 600; }
.score-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; text-align: right; }
.grade-pill { font-size: 11.5px; font-weight: 700; padding: 3px 10px; border-radius: 999px; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); border: 1px solid color-mix(in srgb, var(--c) 35%, transparent); }
.radar { width: 100%; max-width: 300px; height: auto; align-self: center; overflow: visible; }
.rd-ring { fill: none; stroke: var(--border-strong); stroke-width: 1; }
.rd-axis { stroke: var(--border); stroke-width: 1; }
.rd-shape { fill: color-mix(in srgb, var(--purple) 22%, transparent); stroke: var(--purple); stroke-width: 2; stroke-linejoin: round; animation: radarIn 0.8s var(--ease-out) 0.1s both; }
.rd-dot { fill: var(--purple); animation: fade 0.3s ease both; animation-delay: calc(0.6s + var(--i) * 60ms); }
.rd-label { fill: var(--text-dim); font-size: 10.5px; font-weight: 600; }

/* ---------- Streak card ---------- */
.streak-card .card-head { margin-bottom: 10px; }
.streak-row { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.streak-row:last-child { border-bottom: 0; }
.streak-ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); font-size: 16px; filter: grayscale(1); opacity: 0.55; transition: filter 0.3s, opacity 0.3s, transform 0.3s var(--ease-out); }
.streak-ico.lit { filter: none; opacity: 1; background: rgba(251, 191, 36, 0.12); }
.streak-txt { flex: 1; display: flex; flex-direction: column; gap: 1px; font-size: 13px; }
.streak-txt small { color: var(--text-muted); font-size: 11.5px; }
.streak-num { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }

/* ---------- Insights page ---------- */
/* One vertical rhythm for the whole page: every block is 16px from the next
   (the heatmap, R-multiples and achievements cards used to sit flush). */
#insights-panel.active { display: flex; flex-direction: column; gap: 16px; }
#insights-panel > * { margin-top: 0; margin-bottom: 0; }
.ins-top { display: flex; justify-content: flex-end; margin-bottom: 16px; }
.ins-kpis { grid-template-columns: repeat(6, 1fr); }
.stat-card.mini h2 { font-size: 20px; margin-top: 8px; }
.stat-card.mini small { display: block; margin-top: 4px; }
.ins-hl { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.ins-hl:empty { display: none; }
.ins-hl > :only-child { grid-column: 1 / -1; }
.ins-block.hl h3 { font-size: 18px; margin: 6px 0; }
.ins-block.hl.good { border-color: rgba(52, 211, 153, 0.3); background: linear-gradient(160deg, var(--green-soft), var(--surface) 55%); }
.ins-block.hl.bad { border-color: rgba(248, 113, 113, 0.3); background: linear-gradient(160deg, var(--red-soft), var(--surface) 55%); }
/* masonry: two independent columns, so a short card is never stretched to its neighbour's height */
.ins-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.ins-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
/* a wide card with many rows ("By time of day") lists them in two columns */
.bar-list.two { display: grid; grid-auto-flow: column; grid-template-rows: repeat(var(--rows), auto); grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 40px; }
.ins-block h3 { font-size: 15px; margin-bottom: 14px; }
.ins-none { padding: 6px 0; font-size: 13px; }
.ins-empty { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 40px 20px; text-align: center; color: var(--text-dim); margin-bottom: 16px; }
.bar-list { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(110px, 1.1fr) 1.4fr minmax(84px, auto); align-items: center; gap: 12px; font-size: 13px; animation: rise 0.4s var(--ease-out) both; animation-delay: calc(var(--i) * 40ms); }
.bar-lbl { display: flex; flex-direction: column; min-width: 0; }
.bar-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.bar-lbl small { color: var(--text-muted); font-size: 11px; }
.bar-track { position: relative; height: 8px; border-radius: 4px; background: var(--surface-2); }
.bar-zero { position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--border-strong); }
.bar-fill { position: absolute; top: 0; bottom: 0; border-radius: 4px; animation: growX 0.7s var(--ease-out) both; animation-delay: calc(0.1s + var(--i) * 45ms); }
.bar-fill.pos { background: var(--green); transform-origin: left; }
.bar-fill.neg { background: var(--red); transform-origin: right; }
.bar-row strong { text-align: right; font-variant-numeric: tabular-nums; }
.ins-head-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.ins-head-row h3 { margin: 0; }

/* Achievements */
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.ach { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); position: relative; overflow: hidden; animation: rise 0.4s var(--ease-out) both; animation-delay: calc(var(--i) * 30ms); }
.ach-ico { width: 38px; height: 38px; flex-shrink: 0; display: grid; place-items: center; border-radius: 11px; font-size: 18px; background: var(--surface); }
.ach b { display: block; font-size: 13px; }
.ach small { color: var(--text-muted); font-size: 11.5px; line-height: 1.35; }
.ach.locked .ach-ico { filter: grayscale(1); opacity: 0.4; }
.ach.locked b { color: var(--text-dim); }
.ach.got { border-color: rgba(251, 191, 36, 0.35); background: linear-gradient(135deg, rgba(251, 191, 36, 0.09), var(--surface-2) 60%); }
.ach.got .ach-ico { background: rgba(251, 191, 36, 0.14); }
.ach.got::after { content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 35%; background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.08), transparent); transform: translateX(-120%) skewX(-20deg); }
.ach.got:hover::after { animation: sheen 0.9s var(--ease-in-out); }

/* ---------- Leaderboard ---------- */
#leaderboard-panel .lb-wrap { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
#leaderboard-panel .lb-tabs { align-self: flex-start; flex-wrap: wrap; }
table.lb { width: 100%; border-collapse: collapse; font-size: 14px; }
table.lb th, table.lb td { padding: 12px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
table.lb th { color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
table.lb th:first-child, table.lb td:first-child { text-align: center; width: 54px; }
table.lb th:nth-child(2), table.lb td:nth-child(2) { text-align: left; }
.lb-row { animation: rise 0.42s var(--ease-out) both; animation-delay: calc(var(--i) * 45ms); transition: background-color 0.18s; }
.lb-row.top .lb-rank { font-size: 18px; display: inline-block; animation: pop 0.5s var(--ease-out) both; animation-delay: calc(0.2s + var(--i) * 80ms); }
.lb-rank { font-weight: 700; }
.lb-user { display: flex; align-items: center; gap: 10px; }
.lb-av { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; background: var(--purple-soft); color: var(--purple); flex: none; }
.lb-you { font-size: 11px; color: var(--text-muted); }
tr.me { background: var(--purple-soft); }
.lb-empty { color: var(--text-muted); text-align: center !important; padding: 26px 0 !important; }
.lb-sub { color: var(--text-muted); font-size: 12px; margin-top: 12px; }

/* ---------- Owner ---------- */
.owner-content.entering .card { animation: rise 0.45s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 40ms); }

/* ---------- Settings feedback ---------- */
.save-note.flash { display: inline-block; animation: pop 0.35s var(--ease-out) both; }

/* ---------- Light-theme touch-ups ---------- */
[data-theme="light"] .nav-indicator { background: rgba(var(--ac-rgb), 0.12); }
[data-theme="light"] .auth-glow { opacity: 0.16; }
[data-theme="light"] .cal-cell.win { background: linear-gradient(180deg, transparent 40%, rgba(16, 185, 129, 0.08)); }
[data-theme="light"] .cal-cell.loss { background: linear-gradient(180deg, transparent 40%, rgba(239, 68, 68, 0.07)); }
[data-theme="light"] .ach.got::after, [data-theme="light"] .toast.achv::after { background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.6), transparent); }

/* ---------- View transitions (theme switch crossfade) ---------- */
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 0.3s; }

/* =====================================================================
   MOBILE
   ===================================================================== */
.mobile-nav, .sheet-overlay { display: none; }

/* form fields shrink with their column instead of forcing a minimum width */
.form-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-field { min-width: 0; }
.form-field input, .form-field select, .form-field textarea { width: 100%; min-width: 0; }
.modal { overflow-x: hidden; }

/* grid children must be allowed to shrink, or wide tables push the page sideways */
.left-col, .right-col, .journal-left, .trade-right, .main, .card { min-width: 0; }
@media (max-width: 1180px) {
  .ins-kpis { grid-template-columns: repeat(3, 1fr); }
  .middle-grid, .journal-grid, .trade-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 860px) {
  .sidebar { display: none; }
  html, body { overflow-x: clip; }
  .app-shell { padding-bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom)); }
  .topbar { padding: calc(16px + env(safe-area-inset-top)) 16px 6px; gap: 12px; }
  .topbar-title h1 { font-size: 22px; }
  .topbar-title p { font-size: 12.5px; }
  .topbar-actions { width: 100%; }
  .action-group { width: 100%; justify-content: space-between; flex-wrap: wrap; }
  .range-tabs { width: 100%; justify-content: space-between; }
  .range-tabs button { flex: 1; padding: 7px 4px; }
  .content { padding: 12px 16px 28px; }
  .owner-banner, .local-banner { padding: 9px 16px; }
  .card { padding: 16px; border-radius: 14px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-grid > .stat-card:first-child { grid-column: 1 / -1; }
  .stat-card h2 { font-size: 22px; margin-top: 8px; }
  .ins-kpis { grid-template-columns: repeat(2, 1fr); }
  .ins-kpis > .stat-card:first-child { grid-column: auto; }
  .chart-card { min-height: 0; }
  .chart-wrap { height: 240px; }
  .journal-summaries, .summary-body, .settings-grid, .news-grid, .ins-grid, .ins-hl, .reflect-grid, .reflect-emotions { grid-template-columns: 1fr; }
  /* one column on phones: dissolve the masonry columns and keep the original card order */
  .ins-grid { display: flex; flex-direction: column; }
  .ins-col { display: contents; }
  .bar-list.two { display: flex; flex-direction: column; }
  .cal-grid, .cal-weekdays { gap: 4px; }
  .cal-cell { min-height: 54px; padding: 5px; border-radius: 8px; }
  .cal-cell .cell-num { top: 4px; right: 6px; font-size: 11px; }
  .today-badge { font-size: 10px; padding: 1px 5px; }
  .cell-data { left: 3px; right: 3px; bottom: 4px; }
  .cell-trades, .cell-pnl { display: none; }
  .cell-pnl-c { display: block; text-align: center; }
  .cal-weekdays span { font-size: 11px; text-align: center; padding: 0; }
  .cal-actions { width: 100%; }
  .cal-actions > * { flex: 1; justify-content: center; }
  .day-detail { position: static; }
  .day-pnl { font-size: 30px; }
  .trade-title { font-size: 19px; }
  .trade-head-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; width: 100%; }
  .trade-head-actions > * { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; justify-content: center; padding: 9px 10px; }
  .trade-head-actions .ro-badge { grid-column: 1 / -1; }
  .charts-row { grid-template-columns: 1fr; }
  .candles, .candles.skeleton { height: 180px; }
  .news-controls { gap: 8px; }
  .news-controls .cal-nav { width: 100%; }
  .news-controls .cal-nav h3 { flex: 1; font-size: 15px; }
  .news-search { min-width: 0; width: 100%; flex: 1 1 100%; }
  .news-ccy { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .event-row { grid-template-columns: 44px 34px 10px 1fr; }
  .event-vals { grid-column: 4; font-size: 11px; }
  .form-row, .form-row:has(.form-field:nth-child(3)) { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .modal-body { padding: 16px; }
  .bar-row { grid-template-columns: minmax(90px, 1fr) 1fr auto; gap: 8px; }
  .owner-top, .owner-content { padding-left: 16px; padding-right: 16px; }
  .owner-stats { grid-template-columns: repeat(2, 1fr); }
  .toast-host { left: 12px; right: 12px; bottom: calc(var(--mobile-nav-h) + 12px + env(safe-area-inset-bottom)); align-items: stretch; }
  .toast { max-width: none; }
  /* ≥16px so iOS doesn't zoom on focus */
  input, select, textarea, .rf-input, .rf-note, .dlg-input, .user-select { font-size: 16px !important; }

  /* modal becomes a bottom sheet */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal { max-width: none; max-height: 92vh; border-radius: 18px 18px 0 0; transform: translateY(40px); padding-bottom: env(safe-area-inset-bottom); }
  .modal-overlay.open .modal { transform: none; }

  /* bottom navigation */
  .mobile-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 150;
    height: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--sidebar-bg) 88%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
  }
  .mobile-nav button { display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--text-muted); font-size: 18px; padding: 6px 0; -webkit-tap-highlight-color: transparent; transition: color 0.2s; }
  .mobile-nav button small { font-size: 10.5px; font-weight: 600; }
  .mobile-nav button.active { color: var(--purple); }
  .mobile-nav button.active span { display: inline-block; animation: pop 0.35s var(--ease-out); }
  .mobile-nav .mobile-add span { width: 46px; height: 46px; border-radius: 15px; display: grid; place-items: center; background: linear-gradient(135deg, var(--purple), var(--accent-deep)); color: #fff; font-size: 22px; box-shadow: 0 8px 20px -8px var(--purple); transition: transform 0.15s; }
  .mobile-nav .mobile-add:active span { transform: scale(0.92); }

  /* "More" sheet */
  .sheet-overlay { display: flex; position: fixed; inset: 0; z-index: 160; align-items: flex-end; background: rgba(0, 0, 0, 0.5); }
  .sheet-overlay.hidden { display: none; }
  .sheet { width: 100%; background: var(--surface); border-radius: 18px 18px 0 0; padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); transform: translateY(100%); transition: transform 0.32s var(--ease-out); }
  .sheet-overlay.open .sheet { transform: none; }
  .sheet-grip { width: 38px; height: 4px; border-radius: 2px; background: var(--border-strong); margin: 4px auto 10px; }
  .sheet-item { display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px 6px; font-size: 15px; font-weight: 600; border-bottom: 1px solid var(--border); text-align: left; }
  .sheet-item span:first-child { width: 22px; text-align: center; color: var(--text-dim); }
  .sheet-item.danger { color: var(--red); border-bottom: 0; }
  .sheet-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 6px; border-bottom: 1px solid var(--border); }
  .cal-cell[data-key]:hover { transform: none; }
}

@media (max-width: 420px) {
  .stat-card h2 { font-size: 19px; }
  .score-num { font-size: 38px; }
  .trade-top-row { grid-template-columns: 1fr 1fr; }
}

/* ---------- Reduced motion: keep it calm ---------- */
/* Settings → Animations → Reduced (html.rm) */
html.rm *, html.rm *::before, html.rm *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
html.rm .chart-anim .chart-line { stroke-dashoffset: 0; }
