:root {
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --border: #e5e7eb;
  --text: #1a1d23;
  --text-dim: #6b7280;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

h2 {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin: 0 0 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-size: 20px;
  font-weight: 700;
}

.stats {
  display: flex;
  align-items: center;
  gap: 28px;
}

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}

.stat-value {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-sub {
  font-size: 12px;
  font-weight: 600;
}

.stat-sub.pos { color: var(--green); }
.stat-sub.neg { color: var(--red); }

.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn:hover { opacity: 0.88; }

.btn-primary { background: var(--accent); color: white; }
.btn-buy { background: var(--green); color: white; width: 100%; margin-top: 10px; }
.btn-sell { background: var(--red); color: white; width: 100%; margin-top: 10px; }
.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 7px 12px;
}

.account-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 16px;
  border-left: 1px solid var(--border);
}

.account-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}

.layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  padding: 24px;
  max-width: 1280px;
  margin: 0 auto;
}

.stock-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.stock-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s;
}
.stock-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}

.stock-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.stock-symbol {
  font-weight: 700;
  font-size: 15px;
}

.stock-name {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 1px;
}

.stock-sector {
  display: inline-block;
  font-size: 10px;
  color: var(--text-dim);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
  margin-top: 6px;
}

.founder-badge {
  font-size: 10px;
  color: var(--accent);
  font-weight: 700;
}

.stock-price {
  font-size: 20px;
  font-weight: 700;
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
}

.stock-change {
  font-size: 13px;
  font-weight: 600;
}
.stock-change.pos { color: var(--green); }
.stock-change.neg { color: var(--red); }

.sparkline {
  width: 100%;
  height: 40px;
  margin-top: 8px;
  display: block;
}

.panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.portfolio-list, .activity-feed {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
}

.portfolio-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.portfolio-row:last-child { border-bottom: none; }

.portfolio-symbol { font-weight: 700; }
.portfolio-meta { color: var(--text-dim); font-size: 11px; }
.portfolio-value { font-weight: 600; text-align: right; }

.empty-note {
  color: var(--text-dim);
  font-size: 13px;
  font-style: italic;
}

.leaderboard-heading {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin: 14px 0 6px;
}
.leaderboard-heading:first-of-type { margin-top: 0; }

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
.leaderboard-row:last-child { border-bottom: none; }

.leaderboard-rank {
  width: 20px;
  flex-shrink: 0;
  font-weight: 700;
  color: var(--text-dim);
  text-align: center;
}
.leaderboard-row.rank-1 .leaderboard-rank { color: #d4a017; }
.leaderboard-row.rank-2 .leaderboard-rank { color: #9ca3af; }
.leaderboard-row.rank-3 .leaderboard-rank { color: #b45309; }

.leaderboard-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.leaderboard-row.is-you .leaderboard-name {
  color: var(--accent);
  font-weight: 700;
}

.leaderboard-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.trade-tax-note {
  font-size: 11.5px;
  color: var(--text-dim);
  margin: -8px 0 14px;
}

.activity-item {
  font-size: 12.5px;
  line-height: 1.4;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.activity-item:last-child { border-bottom: none; }
.activity-item .a-time {
  color: var(--text-dim);
  font-size: 10.5px;
  display: block;
}
.activity-item.buy { color: var(--green); }
.activity-item.sell { color: var(--red); }
.activity-item.ipo { color: var(--accent); }

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 25, 0.4);
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg);
  border-radius: 14px;
  padding: 24px;
  width: 340px;
  max-width: 90vw;
  position: relative;
  box-shadow: 0 12px 40px rgba(0,0,0,0.18);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-dim);
}

.modal h3 { margin: 0 0 4px; }

.trade-price {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 14px;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  background: var(--bg-soft);
  border-radius: 8px;
  padding: 3px;
}
.tab {
  flex: 1;
  border: none;
  background: none;
  padding: 7px 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-dim);
}
.tab.active {
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow);
}

.tab-panel.hidden { display: none; }

label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin: 10px 0 4px;
}

input[type="text"], input[type="number"] {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--bg-soft);
  color: var(--text);
}
input:focus {
  outline: none;
  border-color: var(--accent);
}

.estimate {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 8px;
  min-height: 16px;
}

.modal-hint {
  font-size: 12.5px;
  color: var(--text-dim);
  margin-top: 0;
}

.modal-error {
  color: var(--red);
  font-size: 12.5px;
  margin-top: 10px;
  min-height: 14px;
}

#confirmCreate { width: 100%; margin-top: 16px; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: white;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .stats { gap: 16px; flex-wrap: wrap; }
}

.auth-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  align-items: center;
  justify-content: center;
  z-index: 300;
}
.auth-overlay.open { display: flex; }

.auth-card {
  width: 360px;
  max-width: 90vw;
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.auth-brand {
  justify-content: center;
  font-size: 24px;
  margin-bottom: 6px;
}

.auth-sub {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  margin: 0 0 20px;
}

.hidden { display: none; }

.auth-divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  margin: 18px 0 14px;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--border);
}
.auth-divider span { padding: 0 10px; }

.google-button-container {
  display: flex;
  justify-content: center;
}

.google-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 600;
}
.google-btn:hover { background: var(--bg-soft); opacity: 1; }

.auth-google-note {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 10px;
  line-height: 1.5;
}
.auth-google-note code {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}
