:root {
  color-scheme: light dark;
  --bg:      light-dark(#fafafb, #0a0b0d);
  --panel:   light-dark(#ffffff, #101216);
  --panel-2: light-dark(#f5f6f8, #15181d);
  --line:    light-dark(#e8eaee, #21252c);
  --line-2:  light-dark(#dfe1e6, #2b2f37);
  --text:    light-dark(#14161a, #e6e8ec);
  --muted:   light-dark(#6a7079, #767d88);
  --faint:   light-dark(#a3a8b0, #474d56);
  --btc:     #f7931a;
  --green:   light-dark(#1a7f37, #3fb950);
  --red:     light-dark(#cf222e, #f0726a);
  --amber:   light-dark(#bf8700, #d29922);
  --blue:    light-dark(#2f6fdb, #4493f8);
  --cash:    light-dark(#1f8a86, #39b0ac);
  --purple:  light-dark(#7c5cff, #a78bfa);
  /* signal tiers: strong buy → strong sell */
  --t-sbuy:  light-dark(#7c5cff, #a78bfa); /* purple (strong buy) */
  --t-buy:   light-dark(#2f6fdb, #4493f8); /* blue (buy) */
  --t-hold:  light-dark(#d7dade, #ffffff); /* white (hold) */
  --t-sell:  #e8c020;                      /* yellow (sell) */
  --t-ssell: #e5484d;                      /* red (strong sell) */
  --mono: ui-monospace, "SF Mono", SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
  --r: 8px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  font-size: 13.5px;
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}
.wrap { max-width: 680px; margin: 0 auto; padding: 24px 16px 56px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }

/* Masthead */
.masthead { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 14px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 9px; }
.logo {
  width: 24px; height: 24px; display: grid; place-items: center; flex: none;
  font-size: 14px; font-weight: 700; color: var(--btc);
  border: 1px solid var(--line-2); border-radius: 6px; background: var(--panel-2);
}
h1 { font-family: var(--mono); font-size: 14px; margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 span { color: var(--muted); font-weight: 400; }

.mast-right { display: flex; align-items: center; gap: 14px; }
.gear { background: var(--panel-2); border: 1px solid var(--line-2); color: var(--muted); border-radius: 6px; width: 28px; height: 28px; flex: none; display: grid; place-items: center; font-size: 14px; line-height: 1; cursor: pointer; padding: 0; transition: .12s; }
.gear:hover { border-color: var(--btc); color: var(--text); }
.ticker { display: flex; align-items: center; gap: 16px; font-family: var(--mono); }
.ticker .t { display: flex; flex-direction: column; line-height: 1.2; }
.ticker .t i { font-style: normal; font-size: 9px; letter-spacing: .1em; color: var(--muted); }
.ticker .t b { font-size: 12.5px; font-weight: 600; letter-spacing: -.02em; transition: color .25s; }
.ticker .t b.closed { color: var(--faint); }              /* market closed → greyed */
.ticker .t b.up { animation: flashUp .7s ease-out; }
.ticker .t b.down { animation: flashDown .7s ease-out; }
@keyframes flashUp { from { color: var(--green); } }
@keyframes flashDown { from { color: var(--red); } }

/* Cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 15px; margin-bottom: 12px; }
.eyebrow { display: flex; align-items: center; font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); margin-bottom: 13px; }
.eyebrow::before { content: ""; width: 5px; height: 5px; background: var(--btc); border-radius: 1px; margin-right: 8px; }
h4 { margin: 0 0 8px; font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }
.grid2.pair { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } /* two-up, never overflow */
@media (max-width: 430px) {
  .masthead { gap: 8px; }
  .ticker { gap: 11px; }
  .ticker .t b { font-size: 11.5px; }
  .ticker .t i { font-size: 8.5px; }
}
.disclaimer { margin: 12px 0 0; font-size: 10.5px; color: var(--faint); }

/* Fields */
.field { margin-bottom: 13px; }
.field:last-child { margin-bottom: 0; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; }
.field label.sec { display: flex; align-items: baseline; justify-content: space-between; }
.field label.sec .sum { font-family: var(--mono); font-weight: 600; font-size: 12px; color: var(--text); }
.field label i { display: block; font-style: normal; font-weight: 400; color: var(--muted); font-size: 10.5px; margin-top: 1px; }
.money { display: flex; align-items: center; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 0 9px; transition: border-color .12s, box-shadow .12s; }
.money:focus-within { border-color: var(--btc); box-shadow: 0 0 0 2px rgba(247,147,26,.16); }
/* cash fields ($) read green: label + focus ring */
.money:not(.btc):not(.voo):focus-within { border-color: var(--green); box-shadow: 0 0 0 2px rgba(63,185,80,.18); }
.money.voo:focus-within { border-color: var(--text); box-shadow: 0 0 0 2px rgba(150,155,165,.22); }
.money span { color: var(--muted); font-size: 12px; font-family: var(--mono); }
.money:not(.btc):not(.voo) span { color: var(--green); }
.money.btc span { color: var(--btc); }
.money.voo span { color: var(--text); font-size: 10px; letter-spacing: .03em; }
.money input { flex: 1; background: transparent; border: 0; outline: 0; color: var(--text); font-family: var(--mono); font-size: 14px; padding: 9px 7px; min-width: 0; text-align: right; }
.money input::placeholder { color: var(--faint); }
.cap { display: block; font-size: 10px; color: var(--muted); margin-top: 5px; }
.cap em { color: var(--btc); font-style: normal; font-family: var(--mono); }
.ghost { background: var(--panel-2); border: 1px solid var(--line-2); color: var(--muted); border-radius: 6px; padding: 4px 9px; font-family: var(--mono); font-size: 11px; cursor: pointer; transition: .12s; }
.ghost:hover { border-color: var(--btc); color: var(--text); }

/* Accounts table */
/* Retirement: transposed grid — accounts across the top, assets down the side.
   Horizontally scrollable when it outgrows the card. */
.acct-scroll { overflow-x: auto; margin: 8px 0 0; padding-bottom: 3px; }
.acct-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(94px, 1fr)) minmax(56px, auto);
  gap: 5px 6px; align-items: center; min-width: 560px;
}
.acct-head { font-family: var(--mono); font-size: 9.5px; color: var(--muted); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-bottom: 2px; }
.acct-head.tot { text-align: right; }
.acct-grid .money { padding: 0 7px; }
.acct-grid .money span { font-size: 9px; }
.acct-grid .money input { font-size: 12px; padding: 6px 3px; text-align: right; min-width: 0; }
.acct-rowtot { font-family: var(--mono); font-size: 11px; text-align: right; color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Signal */
.badge { font-family: var(--mono); font-size: 10.5px; font-weight: 600; letter-spacing: .04em; padding: 4px 9px; border-radius: 5px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line-2); }
.badge.buy  { color: var(--green); border-color: color-mix(in srgb, var(--green) 40%, transparent); background: color-mix(in srgb, var(--green) 12%, transparent); }
.badge.hold { color: var(--amber); border-color: color-mix(in srgb, var(--amber) 40%, transparent); background: color-mix(in srgb, var(--amber) 12%, transparent); }
.badge.sell { color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, transparent); background: color-mix(in srgb, var(--red) 12%, transparent); }
.gauge { margin: 10px 0 14px; padding-top: 21px; }
.gauge-value { position: absolute; bottom: calc(100% + 6px); transform: translateX(-50%); font-family: var(--mono); font-size: 11px; font-weight: 600; letter-spacing: -.02em; white-space: nowrap; transition: left .5s cubic-bezier(.2,.7,.2,1); }
.gauge-track {
  position: relative; height: 7px; border-radius: 3px;
  background: linear-gradient(90deg,
    var(--t-sbuy)  0            calc(20% - 1.5px), var(--panel) calc(20% - 1.5px) calc(20% + 1.5px),
    var(--t-buy)   calc(20% + 1.5px) calc(40% - 1.5px), var(--panel) calc(40% - 1.5px) calc(40% + 1.5px),
    var(--t-hold)  calc(40% + 1.5px) calc(60% - 1.5px), var(--panel) calc(60% - 1.5px) calc(60% + 1.5px),
    var(--t-sell)  calc(60% + 1.5px) calc(80% - 1.5px), var(--panel) calc(80% - 1.5px) calc(80% + 1.5px),
    var(--t-ssell) calc(80% + 1.5px) 100%);
}
.gauge-marker { position: absolute; top: 50%; left: 50%; width: 2px; height: 16px; background: var(--text); transform: translate(-50%,-50%); box-shadow: 0 0 0 2px var(--panel); transition: left .5s cubic-bezier(.2,.7,.2,1); }
.gauge-bounds { position: relative; height: 11px; margin-top: 4px; font-family: var(--mono); font-size: 8px; color: var(--muted); }
.gauge-bounds span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.gauge-labels { display: grid; grid-template-columns: repeat(5, 1fr); margin-top: 2px; font-family: var(--mono); font-size: 8.5px; letter-spacing: .01em; text-transform: uppercase; color: var(--muted); text-align: center; }
.gauge-labels span:first-child { text-align: left; }
.gauge-labels span:last-child { text-align: right; }

.actions { display: flex; flex-direction: column; gap: 6px; }
.action { display: flex; gap: 9px; background: var(--panel-2); border: 1px solid var(--line); border-left: 2px solid var(--faint); border-radius: 6px; padding: 9px 11px; }
.action.buy  { border-left-color: var(--green); }
.action.sell { border-left-color: var(--red); }
.action.hold { border-left-color: var(--amber); }
.action .ico { font-size: 13px; opacity: .9; }
.action .a-title { font-size: 12.5px; font-weight: 600; }
.action .a-amt { font-family: var(--mono); font-weight: 600; }
.action .a-amt.buy { color: var(--green); }
.action .a-amt.sell { color: var(--red); }
.action .a-note { color: var(--muted); font-size: 11px; margin-top: 2px; line-height: 1.4; }

/* Metrics */
.metric-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; }
.metric { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 9px 10px; }
.metric i { font-style: normal; display: block; color: var(--muted); font-family: var(--mono); font-size: 9.5px; text-transform: uppercase; letter-spacing: .05em; }
.metric b { display: block; font-family: var(--mono); font-size: 15px; font-weight: 600; margin-top: 3px; letter-spacing: -.02em; }
.metric b .mult { color: var(--muted); font-size: 12px; font-weight: 400; }

/* Allocation */
.alloc { gap: 16px; }
.alloc h4 { display: flex; align-items: baseline; justify-content: space-between; }
.alloc h4 .sum { font-family: var(--mono); font-weight: 600; font-size: 11px; color: var(--text); text-transform: none; letter-spacing: 0; }
.bar { display: flex; height: 10px; border-radius: 4px; overflow: hidden; background: var(--panel-2); border: 1px solid var(--line); gap: 1px; }
.bar span { transition: width .5s cubic-bezier(.2,.7,.2,1); }
.seg-btc  { background: var(--btc); }
.seg-eq   { background: var(--blue); }
.seg-cash { background: var(--cash); }
.seg-buffer { background: var(--red); }
.seg-bridge { background: var(--blue); }
.seg-retire { background: var(--cash); }
.legend { list-style: none; margin: 11px 0 0; padding: 0; display: grid; gap: 5px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 11.5px; }
.legend .sw { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.legend .v { margin-left: auto; color: var(--muted); font-family: var(--mono); font-size: 11px; }

.chartwrap { position: relative; }
canvas { width: 100%; height: auto; display: block; margin-top: 2px; }
.chartdot { position: absolute; width: 9px; height: 9px; border-radius: 50%; background: var(--btc); box-shadow: 0 0 0 2px var(--panel); transform: translate(-50%, -50%); pointer-events: none; animation: blink 1.2s ease-in-out infinite; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
/* Settings modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; width: 100%; max-width: 340px; box-shadow: 0 16px 48px rgba(0,0,0,.35); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head .eyebrow { margin-bottom: 0; }
.modal-close { background: transparent; border: 0; color: var(--muted); font-size: 13px; cursor: pointer; padding: 3px 7px; border-radius: 5px; line-height: 1; }
.modal-close:hover { color: var(--text); background: var(--panel-2); }
.modal .field:last-child { margin-bottom: 0; }
.modal input[type="date"] { text-align: left; color-scheme: light dark; }
.modal input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(.5); cursor: pointer; }

footer { margin-top: 18px; color: var(--muted); font-size: 10.5px; text-align: center; line-height: 1.6; }
footer a { color: var(--btc); text-decoration: none; }
footer a:hover { text-decoration: underline; }
