:root {
  --bg: #050608;
  --bg-elevated: #101219;
  --border-subtle: rgba(255, 255, 255, 0.06);
  --accent: #4ade80;
  --accent-soft: rgba(74, 222, 128, 0.1);
  --text: #f9fafb;
  --text-muted: #9ca3af;
  --danger: #f97373;

  --chat-owner: linear-gradient(90deg, #7c3aed, #f59e0b);
  --chat-owner-text: #fefce8;
  --chat-mod: #a855f7;
  --chat-donor: #facc15;
  --chat-user: #e5e7eb;
}

/* Light theme */
html[data-theme="light"] {
  --bg: #f3f4f6;
  --bg-elevated: #ffffff;
  --border-subtle: rgba(15, 23, 42, 0.08);
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --text: #020617;
  --text-muted: #6b7280;
}

/* Grey theme */
html[data-theme="grey"] {
  --bg: #111827;
  --bg-elevated: #1f2933;
  --border-subtle: rgba(148, 163, 184, 0.4);
  --accent: #d1d5db;
  --accent-soft: rgba(209, 213, 219, 0.08);
  --text: #f9fafb;
  --text-muted: #9ca3af;
}

/* Roblox-ish theme (simplified, no logo) */
html[data-theme="roblox"] {
  --bg: #111827;
  --bg-elevated: #111827;
  --border-subtle: rgba(248, 113, 113, 0.7);
  --accent: #ef4444;
  --accent-soft: rgba(239, 68, 68, 0.1);
  --text: #f9fafb;
  --text-muted: #fca5a5;
}

/* Paper theme */
html[data-theme="paper"] {
  --bg: #faf5e4;
  --bg-elevated: #fffaf0;
  --border-subtle: rgba(148, 124, 76, 0.3);
  --accent: #f59e0b;
  --accent-soft: rgba(245, 158, 11, 0.12);
  --text: #3f3a2c;
  --text-muted: #7c6f4f;
}

/* Nothing special theme (very neutral) */
html[data-theme="nothing"] {
  --bg: #1f2937;
  --bg-elevated: #111827;
  --border-subtle: rgba(156, 163, 175, 0.3);
  --accent: #60a5fa;
  --accent-soft: rgba(96, 165, 250, 0.12);
  --text: #e5e7eb;
  --text-muted: #9ca3af;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
    "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100vh;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 8px 10px 10px;
}

/* Top bar */

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
}

.brand-title {
  font-size: 16px;
  font-weight: 600;
}

.brand-subtitle {
  font-size: 11px;
  color: var(--text-muted);
}

.icon-button {
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 16px;
}

/* Tabs */

.main-tabs {
  margin-top: 8px;
  display: flex;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  padding: 2px;
}

.tab-button {
  flex: 1;
  border-radius: 999px;
  border: none;
  outline: none;
  padding: 6px 0;
  font-size: 13px;
  color: var(--text-muted);
  background: transparent;
}

.tab-button.active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Main content */

.content {
  flex: 1;
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tab {
  display: none;
  height: 100%;
}

.tab.active {
  display: flex;
  flex-direction: column;
}

/* Stocks layout */

#stocksTab {
  gap: 6px;
}

.stock-header {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
}

.stock-main {
  flex: 1;
}

.stock-name {
  font-size: 15px;
  font-weight: 600;
}

.stock-symbol {
  font-size: 11px;
  color: var(--text-muted);
}

.stock-price-block {
  text-align: right;
}

/* range buttons */
.stock-range {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-right: 10px;
}
.range-btn {
  padding: 6px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
}
.range-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.stock-price {
  font-size: 18px;
  font-weight: 600;
}

.stock-change {
  font-size: 11px;
}

.stock-change.negative {
  color: var(--danger);
}

.stock-change.positive {
  color: var(--accent);
}

.stock-refresh {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

.stock-chart-container {
  flex: 1;
  min-height: 120px;
  max-height: 160px;
  background: var(--bg-elevated);
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  padding: 8px;
}

#stockChart {
  width: 100%;
  height: 100%;
}

/* Stock list */

.stock-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 6px;
}

.stock-pill {
  padding: 8px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stock-pill-header {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
}

.stock-pill-name {
  font-weight: 500;
}

.stock-pill-symbol {
  color: var(--text-muted);
}

.stock-pill-footer {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  margin-top: 2px;
}

.stock-pill-price {
  font-weight: 500;
}

.stock-pill-change {
  font-size: 11px;
}

.stock-pill-change.positive {
  color: var(--accent);
}

.stock-pill-change.negative {
  color: var(--danger);
}

/* Chat */

#chatTab {
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  padding: 8px;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-title {
  font-size: 14px;
  font-weight: 600;
}

.chat-status {
  font-size: 11px;
  color: var(--text-muted);
}

.chat-messages {
  margin-top: 6px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
  font-size: 12px;
  display: flex;
  flex-direction: column-reverse; /* newest at bottom, easier scroll */
}

/* Individual message */
.chat-message {
  margin-bottom: 6px;
  display: flex;
  flex-direction: column;
}

.chat-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 2px;
}

.chat-name-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.chat-name {
  font-weight: 500;
  font-size: 11px;
}

.chat-tag {
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 999px;
  border: 1px solid transparent;
}

.chat-tag.owner {
  background-image: var(--chat-owner);
  color: var(--chat-owner-text);
  border-color: transparent;
}

.chat-tag.moderator {
  background: rgba(168, 85, 247, 0.15);
  color: var(--chat-mod);
  border-color: rgba(168, 85, 247, 0.5);
}

.chat-tag.donor {
  background: rgba(250, 204, 21, 0.12);
  color: var(--chat-donor);
  border-color: rgba(250, 204, 21, 0.6);
}

.chat-tag.user {
  background: rgba(156, 163, 175, 0.15);
  color: var(--chat-user);
  border-color: rgba(156, 163, 175, 0.7);
}

.chat-role-dot.owner {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background-image: var(--chat-owner);
}

.chat-role-dot.moderator {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--chat-mod);
}

.chat-role-dot.donor {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--chat-donor);
}

.chat-role-dot.user {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--chat-user);
}

.chat-time {
  margin-left: auto;
  font-size: 10px;
  color: var(--text-muted);
}

.chat-text {
  padding: 5px 8px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.25);
  word-break: break-word;
}

.chat-image {
  margin-top: 4px;
  max-width: 100%;
  max-height: 200px;
  border-radius: 6px;
  display: block;
}

.chat-img-btn {
  font-size: 18px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  padding: 0;
}

.chat-text.self {
  border-color: var(--accent);
}

/* System messages */
.chat-message.system .chat-text {
  background: rgba(148, 163, 184, 0.12);
  border-style: dashed;
  border-color: rgba(148, 163, 184, 0.6);
  font-size: 11px;
  color: var(--text-muted);
}

/* Chat input */

.chat-input-row {
  margin-top: 6px;
  display: flex;
  gap: 4px;
}

.chat-input {
  flex: 1;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.7);
  color: var(--text);
  font-size: 13px;
  padding: 6px 10px;
  outline: none;
}

.chat-input::placeholder {
  color: var(--text-muted);
}

.chat-send-btn {
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #020617;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 600;
}

/* Sheets & modal */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}

.sheet-backdrop.hidden {
  display: none;
}

.sheet {
  width: 100%;
  max-width: 480px;
  background: var(--bg-elevated);
  border-radius: 16px 16px 0 0;
  border-top: 1px solid var(--border-subtle);
  border-left: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
  padding: 10px 12px 12px;
  animation: slideUp 0.18s ease-out;
}

.tos-sheet {
  max-width: 480px;
  margin-bottom: 30px;
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sheet-title {
  font-size: 14px;
  font-weight: 600;
}

.sheet-section {
  margin-top: 10px;
}

.sheet-section-title {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
}

.theme-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.theme-pill {
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 11px;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.7);
  color: var(--text-muted);
}

.theme-pill.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.toggle-row {
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.profile-link {
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
}

/* TOS modal */
.tos-body {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.tos-body ul {
  margin: 6px 0 6px 18px;
  padding: 0;
}

/* Buttons */

.primary-button {
  width: 100%;
  margin-top: 10px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #020617;
  font-weight: 600;
  font-size: 13px;
  padding: 7px 0;
}

/* Toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 80px;
  transform: translateX(-50%);
  max-width: 90%;
  background: rgba(15, 23, 42, 0.95);
  color: var(--text);
  border-radius: 999px;
  border: 1px solid rgba(248, 113, 113, 0.8);
  font-size: 11px;
  padding: 6px 12px;
  z-index: 40;
}

.toast.hidden {
  display: none;
}

/* Animations */

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0%);
  }
}