  :root{
    --bg: #0E141B;
    --bg-panel: #161D27;
    --bg-panel-alt: #1C2531;
    --bg-card-hover: #202A37;
    --border: #2A3441;
    --text: #ECEFE7;
    --text-muted: #8993A3;
    --text-faint: #5C6472;
    --accent: #E8A33D;
    --accent-soft: rgba(232,163,61,0.14);
    --positive: #4CAF6D;
    --positive-soft: rgba(76,175,109,0.14);
    --negative: #E2574C;
    --negative-soft: rgba(226,87,76,0.14);
    --font-display: 'Oswald', 'Arial Narrow', sans-serif;
    --font-mono: 'IBM Plex Mono', 'Courier New', monospace;
    --font-body: 'Inter', -apple-system, sans-serif;
    box-sizing: border-box;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  *{box-sizing:border-box;}
  html{scroll-padding-top: env(safe-area-inset-top, 0px);}
  html,body{
    height:100%;
    margin:0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
  }
  a{color:inherit;}

  /* ---------- Ticker tape ---------- */
  .tape-wrap{
    background: #0A0F14;
    border-bottom: 1px solid var(--border);
    overflow: hidden;
    white-space: nowrap;
    padding: 8px 0;
  }
  .tape{
    display: inline-flex;
    animation: scroll-left 34s linear infinite;
  }
  @media (prefers-reduced-motion: reduce){
    .tape{ animation: none; }
    .tape-wrap{ overflow-x: auto; }
  }
  @keyframes scroll-left{
    from{ transform: translateX(0); }
    to{ transform: translateX(-50%); }
  }
  .tape-item{
    display:inline-flex;
    align-items:baseline;
    gap:6px;
    font-family: var(--font-mono);
    font-size: 13px;
    padding: 0 20px;
    border-right: 1px solid var(--border);
  }
  .tape-item .tk{ color: var(--text); font-weight:600; }
  .tape-item .px{ color: var(--text-muted); }
  .tape-item .ch.up{ color: var(--positive); }
  .tape-item .ch.down{ color: var(--negative); }

  /* ---------- Header ---------- */
  header.app-header{
    position: sticky;
    top: env(safe-area-inset-top, 0px);
    z-index: 10;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    padding: 14px 24px;
    display:flex;
    align-items:center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
  }
  .brand{
    display:flex;
    align-items:baseline;
    gap: 10px;
  }
  .brand .mark{
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 21px;
    letter-spacing: 0.3px;
  }
  .brand .mark span{ color: var(--accent); }
  .brand .tag{
    font-size: 12.5px;
    color: var(--text-muted);
  }
  nav.tabs{
    display:flex;
    gap: 4px;
    background: var(--bg-panel-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 3px;
  }
  nav.tabs button{
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 13.5px;
    color: var(--text-muted);
    background: transparent;
    border: none;
    padding: 7px 16px;
    border-radius: 6px;
    cursor: pointer;
  }
  nav.tabs button.active{
    background: var(--bg-card-hover);
    color: var(--text);
  }
  .acct{
    display:flex;
    gap: 22px;
    align-items:center;
  }
  .acct .stat{ text-align:right; }
  .acct .stat .label{
    font-size: 11px;
    color: var(--text-faint);
    text-transform: lowercase;
  }
  .acct .stat .value{
    font-family: var(--font-mono);
    font-size: 15px;
    font-weight: 600;
  }

  main{
    max-width: 1180px;
    margin: 0 auto;
    padding: 28px 24px 80px;
  }

  .section-head{
    display:flex;
    align-items:flex-end;
    justify-content:space-between;
    flex-wrap: wrap;
    gap: 14px;
    margin-bottom: 18px;
  }
  .section-head h1{
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 600;
    margin: 0 0 4px;
  }
  .section-head p{
    margin:0;
    color: var(--text-muted);
    font-size: 13.5px;
  }
  .btn-primary{
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 14px;
    background: var(--accent);
    color: #221806;
    border: none;
    padding: 11px 20px;
    border-radius: 8px;
    cursor: pointer;
  }
  .btn-primary:hover{ filter: brightness(1.06); }
  .btn-secondary{
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 13.5px;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    padding: 9px 16px;
    border-radius: 8px;
    cursor: pointer;
  }
  .btn-secondary:hover{ color: var(--text); border-color: var(--text-faint); }

  /* ---------- Market grid ---------- */
  .grid{
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 14px;
  }
  .card{
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-left: 3px solid var(--tag-color, var(--accent));
    border-radius: 10px;
    padding: 16px 16px 14px;
    cursor: pointer;
    transition: background 0.12s ease, transform 0.12s ease;
  }
  .card:hover{ background: var(--bg-card-hover); transform: translateY(-1px); }
  .card-top{
    display:flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
  }
  .card-top .tk{
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 15px;
  }
  .card-top .nm{
    font-size: 12.5px;
    color: var(--text-muted);
    margin-top: 2px;
    max-width: 140px;
  }
  .card-top .held-badge{
    font-size: 10.5px;
    color: var(--accent);
    background: var(--accent-soft);
    padding: 2px 7px;
    border-radius: 20px;
    white-space: nowrap;
  }
  .card-mid{
    display:flex;
    justify-content: space-between;
    align-items:center;
    margin-bottom: 10px;
  }
  .card-mid .px{
    font-family: var(--font-mono);
    font-size: 22px;
    font-weight: 600;
  }
  .card-mid .ch{
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 6px;
  }
  .ch.up{ color: var(--positive); background: var(--positive-soft); }
  .ch.down{ color: var(--negative); background: var(--negative-soft); }
  .ch.flat{ color: var(--text-muted); background: var(--bg-panel-alt); }
  .spark{ display:block; width:100%; height:36px; }
  .cover-tag{
    font-family: var(--font-mono);
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 2px 6px;
    border-radius: 5px;
    display: inline-block;
    margin-top: 4px;
  }
  .cover-tag.covered{ color: var(--positive); background: var(--positive-soft); }
  .cover-tag.missed{ color: var(--accent); background: var(--accent-soft); }

  /* ---------- Detail view ---------- */
  .detail-back{
    display:inline-flex;
    align-items:center;
    gap:6px;
    color: var(--text-muted);
    font-size: 13.5px;
    background:none;
    border:none;
    cursor:pointer;
    padding: 0 0 16px;
  }
  .detail-back:hover{ color: var(--text); }
  .detail-head{
    display:flex;
    justify-content:space-between;
    align-items:flex-start;
    flex-wrap:wrap;
    gap: 20px;
    margin-bottom: 22px;
  }
  .detail-head .tk-name .tk{
    font-family: var(--font-mono);
    font-size: 15px;
    color: var(--text-muted);
    letter-spacing: 0.5px;
  }
  .detail-head .tk-name h1{
    font-family: var(--font-display);
    font-size: 26px;
    margin: 3px 0 0;
  }
  .detail-price{ text-align: right; }
  .detail-price .px{
    font-family: var(--font-mono);
    font-size: 30px;
    font-weight: 600;
  }
  .detail-price .ch{
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 600;
  }
  .detail-body{
    display:grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 22px;
  }
  @media (max-width: 780px){ .detail-body{ grid-template-columns: 1fr; } }
  .panel{
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 18px 18px 16px;
  }
  .panel h2{
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 600;
    text-transform: lowercase;
    color: var(--text-muted);
    margin: 0 0 14px;
    letter-spacing: 0.3px;
  }
  .chart-wrap{ overflow: visible; }
  .chart-wrap svg{ display:block; }
  .axis-label{ font-family: var(--font-mono); font-size: 10.5px; fill: var(--text-faint); }

  .log-list{ display:flex; flex-direction:column; gap:10px; max-height: 260px; overflow-y:auto; }
  .log-item{
    font-size: 13px;
    color: var(--text-muted);
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
  }
  .log-item:last-child{ border-bottom:none; padding-bottom:0; }
  .log-item .lw{ color: var(--text-faint); font-family: var(--font-mono); font-size: 11px; }
  .log-item .ld{ font-family: var(--font-mono); font-weight: 600; }

  .trade-form{ display:flex; flex-direction:column; gap:12px; }
  .trade-row{ display:flex; gap:10px; }
  .trade-row input[type="number"]{
    flex:1;
    background: var(--bg-panel-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 15px;
    padding: 10px 12px;
  }
  .trade-row input[type="number"]:focus{ outline: 1px solid var(--accent); border-color: var(--accent); }
  .trade-summary{
    display:flex;
    justify-content:space-between;
    font-size: 13px;
    color: var(--text-muted);
  }
  .trade-summary strong{ color: var(--text); font-family: var(--font-mono); }
  .trade-buttons{ display:flex; gap:10px; }
  .trade-buttons button{ flex:1; }
  .btn-buy{
    background: var(--positive); color: #0c1f14; border:none; font-weight:700;
    padding: 11px; border-radius: 8px; cursor:pointer; font-size: 14px;
  }
  .btn-sell{
    background: var(--negative-soft); color: var(--negative); border: 1px solid var(--negative);
    font-weight:700; padding: 11px; border-radius: 8px; cursor:pointer; font-size: 14px;
  }
  .btn-buy:disabled, .btn-sell:disabled{ opacity: 0.4; cursor: not-allowed; }
  .position-note{
    font-size: 12.5px; color: var(--text-muted); padding-top:2px;
  }

  /* ---------- Portfolio ---------- */
  table.holdings{ width:100%; border-collapse: collapse; }
  table.holdings th{
    text-align: left;
    font-size: 11px;
    text-transform: lowercase;
    color: var(--text-faint);
    font-weight: 600;
    padding: 0 10px 10px;
    border-bottom: 1px solid var(--border);
  }
  table.holdings td{
    font-family: var(--font-mono);
    font-size: 13.5px;
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
  }
  table.holdings td.nm-cell{ font-family: var(--font-body); }
  table.holdings td.nm-cell .nm-flex{ display: flex; align-items: center; gap: 10px; }
  .mini-mark{ display: inline-flex; vertical-align: middle; margin-right: 5px; }
  .nm-flex .mini-mark{ margin-right: 0; }
  table.holdings td.nm-cell .tk-mini{ color: var(--text-muted); font-family: var(--font-mono); font-size: 11.5px; }
  table.holdings tr:last-child td{ border-bottom:none; }
  .empty-state{
    padding: 40px 20px;
    text-align:center;
    color: var(--text-muted);
  }
  .empty-state .big{
    font-family: var(--font-display);
    font-size: 18px;
    color: var(--text);
    margin-bottom: 6px;
  }

  .summary-row{
    display:grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-bottom: 20px;
  }
  @media (max-width: 640px){ .summary-row{ grid-template-columns: 1fr; } }
  .summary-card{
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 18px;
  }
  .summary-card .label{ font-size: 12px; color: var(--text-muted); margin-bottom:6px; }
  .summary-card .val{ font-family: var(--font-mono); font-size: 22px; font-weight: 600; }

  footer.simfoot{
    text-align:center;
    color: var(--text-faint);
    font-size: 12px;
    padding: 30px 20px 10px;
  }

  .team-mark{ display: inline-flex; align-items: center; justify-content: center; flex: none; }
  .team-logo{ width: 100%; height: 100%; object-fit: contain; }

  footer.simfoot a{ color: var(--text-muted); }

  /* Privacy / Terms pages */
  .doc-page{ max-width: 720px; margin: 0 auto; padding: 28px 20px 10px; line-height: 1.6;
    font-size: 15px; color: var(--text-muted); }
  .doc-page h1{ font-family: var(--font-display, inherit); color: var(--text); font-size: 30px; margin: 0 0 4px; }
  .doc-page h2{ color: var(--text); font-size: 18px; margin: 28px 0 8px; }
  .doc-page .doc-date{ color: var(--text-faint); font-size: 13px; margin: 0 0 18px; }
  .doc-page strong{ color: var(--text); }
  .doc-page a{ color: var(--accent); }
  .doc-page ul{ padding-left: 20px; }

  /* ---------- Additions for the server-backed app ---------- */
  nav.tabs a.tab{
    font-family: var(--font-body); font-weight: 600; font-size: 13.5px;
    color: var(--text-muted); text-decoration: none;
    padding: 7px 16px; border-radius: 6px;
  }
  nav.tabs a.tab.active{ background: var(--bg-card-hover); color: var(--text); }
  a.card{ display:block; text-decoration:none; color: inherit; }
  a.card:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible{
    outline: 2px solid var(--accent); outline-offset: 2px;
  }
  .acct .btn-secondary{ padding: 7px 14px; }
  .acct .who{ font-size: 11.5px; color: var(--text-faint); max-width: 180px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .auth-panel{ max-width: 420px; margin: 20px auto; }
  .auth-panel p{ color: var(--text-muted); font-size: 13.5px; line-height: 1.5; margin: 0 0 14px; }
  .field{
    width: 100%;
    background: var(--bg-panel-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 15px;
    padding: 10px 12px;
    margin-bottom: 12px;
  }
  /* Google's sign-in button guidelines: white, grey border, the "G" mark. */
  .btn-google{
    width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px;
    font-family: var(--font-body); font-weight: 600; font-size: 15px;
    background: #fff; color: #1f1f1f; border: 1px solid #747775;
    padding: 10px 16px; border-radius: 8px; cursor: pointer;
  }
  .btn-google:hover{ background: #f2f2f2; }
  .btn-google:disabled{ opacity: .6; cursor: default; }
  .auth-or{ display: flex; align-items: center; gap: 10px; margin: 16px 0;
    color: var(--text-faint); font-size: 12px; }
  .auth-or::before, .auth-or::after{ content: ""; flex: 1; border-top: 1px solid var(--border); }
  .code-field{ font-family: var(--font-mono, monospace); font-size: 20px; letter-spacing: .2em; text-align: center; }
  .auth-help{ margin-top: 18px; padding: 12px 14px; background: var(--bg-panel-alt);
    border: 1px solid var(--border); border-radius: 8px; font-size: 13px; color: var(--text-muted); line-height: 1.5; }
  .auth-help-title{ font-weight: 600; color: var(--text); margin-bottom: 4px; }
  .auth-help ul{ margin: 0; padding-left: 18px; }
  .auth-help strong{ color: var(--text); overflow-wrap: anywhere; }
  .auth-panel p strong{ color: var(--text); overflow-wrap: anywhere; }
  .auth-actions{ display: flex; align-items: center; justify-content: space-between; gap: 12px;
    flex-wrap: wrap; margin-top: 14px; }
  .btn-secondary:disabled{ opacity: .6; cursor: default; }
  .link-btn{ background: none; border: none; padding: 0; cursor: pointer;
    color: var(--accent); font: inherit; font-size: 13px; text-decoration: underline; }
  .form-msg{ font-size: 13px; margin-top: 10px; min-height: 18px; }
  .form-msg.err{ color: var(--negative); }
  .form-msg.ok{ color: var(--positive); }

  .toast{
    position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    background: var(--bg-panel-alt); border: 1px solid var(--border);
    border-left: 3px solid var(--positive);
    color: var(--text); font-size: 13.5px;
    padding: 11px 16px; border-radius: 8px; z-index: 50;
    max-width: calc(100vw - 32px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  }
  .toast.err{ border-left-color: var(--negative); }

  .upcoming-list{ display:flex; flex-direction:column; gap:8px; }
  .upcoming-item{ font-size: 13px; color: var(--text-muted); display:flex; justify-content:space-between; gap: 10px; }
  .upcoming-item .opp{ color: var(--text); }
  .proj-tag{
    font-family: var(--font-mono); font-size: 9.5px; font-weight: 700; letter-spacing: 0.5px;
    padding: 2px 6px; border-radius: 5px; color: var(--text-muted); background: var(--bg-panel-alt);
    white-space: nowrap;
  }
  .real-tag{ color: var(--positive); background: var(--positive-soft); }

  .loading{ padding: 40px 20px; text-align:center; color: var(--text-muted); }
  .stale-note{ font-size: 12px; color: var(--text-faint); }

  @media (max-width: 640px){
    header.app-header{ padding: 12px 16px; }
    main{ padding: 20px 16px 70px; }
    .acct{ gap: 14px; }
    .table-scroll{ overflow-x: auto; }
  }
  .detail-price .ch{ display: inline-block; padding: 3px 8px; border-radius: 6px; }
  .detail-price .cover-tag{ display: table; margin-left: auto; }

  /* ---------- Leaderboard ---------- */
  table.holdings tr.me-row td{ background: var(--accent-soft); }
  .medal{
    display:inline-flex; align-items:center; justify-content:center;
    width: 22px; height: 22px; border-radius: 50%;
    font-size: 12px; font-weight: 700; color: #1a1406;
  }
  .medal-1{ background: #E8A33D; }
  .medal-2{ background: #B8C0CC; }
  .medal-3{ background: #C98B5A; }
  .position-note a, .stale-note a{ color: var(--accent); }
  .you-badge{
    font-size: 10.5px; color: var(--accent); background: var(--accent-soft);
    padding: 2px 7px; border-radius: 20px; white-space: nowrap; margin-left: 4px;
  }
  table.holdings tr.me-row .you-badge{ background: rgba(232,163,61,0.22); }
  .txt-up{ color: var(--positive); }
  .txt-down{ color: var(--negative); }
  .txt-flat{ color: var(--text-muted); }

  /* ---------- Price chart details ---------- */
  .chart-box{ position: relative; }
  .chart-value{
    font-family: var(--font-mono); font-size: 11.5px; font-weight: 600; fill: var(--text);
    stroke: var(--bg-panel); stroke-width: 4px; paint-order: stroke; stroke-linejoin: round;
  }
  .chart-tip.below{ transform: translate(-50%, 0); }
  .chart-hit{ cursor: pointer; outline: none; }
  .chart-hit:focus-visible{ stroke: var(--accent); stroke-width: 1.5; }
  .chart-tip{
    position: absolute; transform: translate(-50%, -100%);
    background: var(--bg-panel-alt); border: 1px solid var(--border); border-radius: 8px;
    padding: 8px 10px; font-size: 12.5px; color: var(--text-muted);
    width: max-content; max-width: min(270px, 86vw); white-space: normal; pointer-events: none; z-index: 5;
    box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  }
  .chart-tip .tip-head{ color: var(--text-muted); margin-bottom: 3px; }
  .chart-tip .tip-price{ font-family: var(--font-mono); font-size: 15px; font-weight: 600; color: var(--text); }
  .chart-tip .tip-price span{ font-size: 12.5px; margin-left: 4px; }
  .chart-tip .tip-note{ font-size: 11.5px; color: var(--text-faint); margin-top: 3px; }
  .log-price{ font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); white-space: nowrap; margin-left: 4px; }

  /* ---------- Records ---------- */
  .card-top .rec{
    font-family: var(--font-mono); font-size: 11.5px; color: var(--text-muted);
    margin-top: 3px; white-space: nowrap;
  }
  .rec-row{ display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
  .rec-chip{
    background: var(--bg-panel-alt); border: 1px solid var(--border); border-radius: 8px;
    padding: 5px 10px; min-width: 64px;
  }
  .rec-chip .rec-label{ font-size: 10.5px; color: var(--text-faint); }
  .rec-chip .rec-value{ font-family: var(--font-mono); font-size: 15px; font-weight: 600; color: var(--text); }
