:root {
  --bg: #f4f5f7;
  --card-bg: #ffffff;
  --text: #1d2129;
  --muted: #65676b;
  --primary: #4a6cf7;
  --primary-hover: #3955d1;
  --primary-tint: #eef1ff;
  --danger: #e0245e;
  --danger-hover: #c01f4f;
  --border: #e4e6eb;
  --warning-bg: #fdecea;
  --warning-border: #f5c6cb;
  --warning-text: #7a1f2b;
  --owner-color: #1e9e58;
  --primary-text: #ffffff;
  --radius: 10px;
}

html[data-theme="dark"] {
  --owner-color: #3ddc84;
  --bg: #16171a;
  --card-bg: #212226;
  --text: #e7e9ea;
  --muted: #9099a1;
  --primary: #6b87ff;
  --primary-hover: #8399ff;
  --primary-tint: #2a2f45;
  --danger: #f0517d;
  --danger-hover: #f57a9a;
  --border: #35373d;
  --warning-bg: #3a2327;
  --warning-border: #5c2a30;
  --warning-text: #f0a8b0;
}

html[data-theme="high-contrast"] {
  --owner-color: #ffff00;
  --primary-text: #000000;
  --bg: #000000;
  --card-bg: #000000;
  --text: #ffffff;
  --muted: #dddddd;
  --primary: #ffff00;
  --primary-hover: #ffee00;
  --primary-tint: #333300;
  --danger: #ff3b3b;
  --danger-hover: #ff6b6b;
  --border: #ffffff;
  --warning-bg: #330000;
  --warning-border: #ff3b3b;
  --warning-text: #ffcccc;
}

html[data-theme="ocean"] {
  --owner-color: #2a9d8f;
  --bg: #e6f7fb;
  --card-bg: #ffffff;
  --text: #023047;
  --muted: #4d7c8a;
  --primary: #0077b6;
  --primary-hover: #023e8a;
  --primary-tint: #d6efff;
  --danger: #e63946;
  --danger-hover: #c81d2c;
  --border: #a8dadc;
  --warning-bg: #ffe8d6;
  --warning-border: #ffb385;
  --warning-text: #7a3b00;
}

html[data-theme="sunset"] {
  --owner-color: #f77f00;
  --primary-text: #2b1400;
  --bg: #fff1e6;
  --card-bg: #ffffff;
  --text: #3d1f00;
  --muted: #8a5a3d;
  --primary: #ff6b35;
  --primary-hover: #e85a2a;
  --primary-tint: #ffe3d1;
  --danger: #d62828;
  --danger-hover: #b81f1f;
  --border: #ffd6a5;
  --warning-bg: #fbe0e0;
  --warning-border: #f5b3b3;
  --warning-text: #7a1f1f;
}

html[data-theme="cyberpunk"] {
  --owner-color: #00f0ff;
  --primary-text: #ffffff;
  --bg: #0a0014;
  --card-bg: #150829;
  --text: #e6e0ff;
  --muted: #8a7ca8;
  --primary: #ff2e88;
  --primary-hover: #ff5aa0;
  --primary-tint: #2a0f3d;
  --danger: #ff3860;
  --danger-hover: #ff6b85;
  --border: #3d1f5c;
  --warning-bg: #2a0f1a;
  --warning-border: #ff2e88;
  --warning-text: #ff9ec4;
}

html[data-theme="matrix"] {
  --owner-color: #ffffff;
  --primary-text: #000000;
  --bg: #000000;
  --card-bg: #0a0f0a;
  --text: #00ff41;
  --muted: #008f11;
  --primary: #00ff41;
  --primary-hover: #39ff6a;
  --primary-tint: #003b0f;
  --danger: #ff003c;
  --danger-hover: #ff4d6d;
  --border: #145214;
  --warning-bg: #1a0000;
  --warning-border: #ff003c;
  --warning-text: #ff9eb0;
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 24px 16px;
  line-height: 1.5;
}

body.page-narrow { max-width: 380px; margin: 50px auto; }
body.page-medium { max-width: 540px; margin: 30px auto; }
body.page-wide { max-width: 780px; margin: 30px auto; }
body.page-home { max-width: 900px; margin: 0 auto; padding: 0 16px 60px; }

.btn {
  display: inline-block;
  background: var(--primary);
  color: var(--primary-text);
  padding: 10px 22px;
  border-radius: 8px;
  font-weight: 600;
  text-decoration: none;
}
.btn:hover { background: var(--primary-hover); text-decoration: none; }
.btn.secondary { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn.secondary:hover { background: var(--primary-tint); }

.hero { text-align: center; padding: 70px 20px 40px; }
.hero h1 { font-size: 2.3em; margin-bottom: 8px; }
.hero p { color: var(--muted); font-size: 1.1em; max-width: 480px; margin: 0 auto 28px; }
.hero-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 40px;
}
.features .card { text-align: center; }
.features a.card { display: block; text-decoration: none; color: inherit; transition: transform 0.15s ease, box-shadow 0.15s ease; }
.features a.card:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(0,0,0,0.08); }
.features .card .icon { font-size: 1.8em; margin-bottom: 6px; }

.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.85em;
  margin-top: 60px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* Tables can get wide (admin panel) - let them scroll horizontally instead of breaking layout */
.table-scroll { width: 100%; overflow-x: auto; margin-bottom: 24px; }
.table-scroll table { margin-bottom: 0; }

/* Small screens */
@media (max-width: 480px) {
  body { padding: 12px; }
  body.page-narrow, body.page-medium, body.page-wide, body.page-home { margin-top: 12px; margin-bottom: 12px; }
  .hero { padding: 30px 8px 24px; }
  .hero h1 { font-size: 1.6em; }
  .hero p { font-size: 1em; }
  .nav { font-size: 0.85em; padding: 8px 10px; gap: 4px 10px; }
  table, th, td { font-size: 0.8em; }
  form.inline button { padding: 5px 8px; font-size: 0.78em; }
  #messages { height: 320px; }
}

h2, h3 { margin-top: 0; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Top nav bar */
.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  align-items: center;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 20px;
  font-size: 0.9em;
}
.nav .brand { font-weight: 700; color: var(--text); margin-right: auto; }
.nav a { color: var(--muted); }
.nav a:hover { color: var(--primary); text-decoration: none; }

/* Generic containers */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

/* Forms */
input[type=text], input[type=email], input[type=password], textarea, select {
  display: block;
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95em;
  background: var(--card-bg);
  color: var(--text);
  font-family: inherit;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
}
label { display: block; padding: 4px 0; font-size: 0.9em; }

button, input[type=submit] {
  background: var(--primary);
  color: var(--primary-text);
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 0.9em;
  cursor: pointer;
  transition: background 0.15s ease;
  font-family: inherit;
}
button:hover { background: var(--primary-hover); }

/* Chat / messages */
#messages {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  height: 400px;
  overflow-y: auto;
  padding: 12px;
  margin-bottom: 12px;
  background: var(--card-bg);
}
.msg { margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.msg:last-child { border-bottom: none; margin-bottom: 0; }

@keyframes msgFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg-new { animation: msgFadeIn 0.3s ease; }
.msg-sending { opacity: 0.6; }
.msg .user { font-weight: 600; }
.msg .time { color: var(--muted); font-size: 0.75em; margin-left: 6px; }
.admin-tag { color: var(--danger); font-weight: 700; margin-right: 4px; }
.owner-tag { color: var(--owner-color); font-weight: 700; margin-right: 4px; }
.custom-tag { color: #fff; font-weight: 700; font-size: 0.75em; padding: 1px 7px; border-radius: 6px; margin-right: 4px; }

/* Profile pictures */
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  vertical-align: middle;
  margin-right: 8px;
}
.avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: var(--primary-text);
  font-weight: 700;
  font-size: 0.8em;
}
.avatar-large {
  width: 80px;
  height: 80px;
  font-size: 2em;
}

.like-btn {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.85em;
  color: var(--muted);
  padding: 2px 6px;
}
.like-btn:hover { color: var(--primary); }
.like-btn.liked { color: var(--danger); font-weight: bold; }

form.chat-form { display: flex; gap: 8px; margin-bottom: 0; }
form.chat-form input[type=text] { flex: 1; min-width: 0; margin-bottom: 0; font-size: 16px; }
form.chat-form button { flex-shrink: 0; }

/* Unread badges */
.badge {
  background: var(--danger);
  color: white;
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 0.75em;
  margin-left: 6px;
}

/* Row lists (friends, rooms, etc.) */
.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: none; }

/* Admin tables */
table { width: 100%; border-collapse: collapse; margin-bottom: 24px; }
td, th { padding: 8px; border-bottom: 1px solid var(--border); text-align: left; font-size: 0.88em; }
th { color: var(--muted); font-weight: 600; }
form.inline { display: inline; }
form.inline button { padding: 4px 10px; font-size: 0.8em; margin-left: 4px; }

.action-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.action-group form.inline {
  display: flex;
  align-items: center;
  gap: 4px;
}
.action-group form.inline button {
  margin-left: 0;
  padding: 3px 8px;
  font-size: 0.75em;
}
.action-group input[type=text] {
  margin-bottom: 0;
  padding: 4px 8px;
  font-size: 0.8em;
  width: 90px;
}
.action-group select {
  margin-bottom: 0;
  padding: 4px 6px;
  font-size: 0.8em;
  width: auto;
}

/* Report cards */
.report { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.report.reviewed { opacity: 0.55; }
.meta { color: var(--muted); font-size: 0.85em; }

/* Warning/notice box */
.warning {
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  color: var(--warning-text);
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 16px;
}

/* Feed posts */
.post { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.post img { max-width: 100%; border-radius: 8px; margin-top: 8px; }

/* Dashboard */
.profile-header { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.profile-header .username { font-size: 1.3em; font-weight: 700; }
.stats-row { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.stat-box { flex: 1; min-width: 90px; background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; text-align: center; }
.stat-box a { color: inherit; }
.stat-box a:hover { text-decoration: none; }
.stat-box .num { font-size: 1.6em; font-weight: 700; color: var(--primary); display: block; }
.stat-box .label { color: var(--muted); font-size: 0.8em; }
.toggle-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.toggle-row:last-child { border-bottom: none; }
.toggle-row .label { font-weight: 500; }
.toggle-row .desc { color: var(--muted); font-size: 0.85em; margin-top: 2px; }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; cursor: pointer; inset: 0; background: var(--border); border-radius: 24px; transition: 0.2s; }
.switch .slider::before { content: ""; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: 0.2s; }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(20px); }

.custom-theme-row { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; }
.custom-theme-row input[type=color] { width: 48px; height: 32px; padding: 2px; margin-bottom: 0; cursor: pointer; }
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #1d2129;
  color: #ffffff;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 9999;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  cursor: default;
}
.toast.clickable { cursor: pointer; }
.toast.clickable:hover { background: #2a2f38; }

html[data-theme="dark"] .toast {
  background: #ffffff;
  color: #1d2129;
}
html[data-theme="dark"] .toast.clickable:hover { background: #e9e9e9; }

/* Modal popup (used for reporting messages) */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 16px;
}
.modal {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.3);
}
.modal h3 { margin-top: 0; }
.modal textarea { margin-bottom: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-actions .secondary-btn { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.modal-actions .secondary-btn:hover { background: var(--bg); }

.lightbox-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10001;
  padding: 20px;
  cursor: zoom-out;
}
.lightbox-overlay img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  cursor: default;
}
.post img, .msg img { cursor: zoom-in; }
