:root {
  --bg: #ffffff;
  --bg-soft: #fafafa;
  --text: #262626;
  --text-soft: #8e8e8e;
  --border: #dbdbdb;
  --primary: #0095f6;
  --primary-hover: #1877f2;
  --danger: #ed4956;
  --radius: 12px;
  --max: 935px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Noto Sans Thai", "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-soft);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  font-family: "Noto Sans Thai", "Inter", sans-serif;
  font-weight: 700;
  font-size: 24px;
  letter-spacing: -.5px;
  background: linear-gradient(45deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: 8px;
  font-size: 18px;
  line-height: 1;
}
.icon-btn:hover { background: var(--bg-soft); }
.icon-btn.danger:hover { background: #fde8ea; }

.container { max-width: var(--max); margin: 0 auto; padding: 20px; }

/* Profile */
.profile {
  display: flex;
  gap: 32px;
  align-items: center;
  padding: 16px 0 32px;
}
.avatar-ring {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  padding: 4px;
  background: linear-gradient(45deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888);
  flex-shrink: 0;
}
.avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid var(--bg);
  background: #efefef;
}
.profile-info { flex: 1; }
.profile-top {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 20px;
}
.username { font-size: 22px; font-weight: 500; }

.btn {
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn-secondary { background: #efefef; color: var(--text); }
.btn-secondary:hover { background: #dbdbdb; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }

.stats {
  list-style: none;
  display: flex;
  gap: 40px;
  margin-bottom: 20px;
}
.stats li { font-size: 16px; }
.stats strong { font-weight: 600; margin-right: 6px; }
.stats span { color: var(--text); }

.bio-name { font-weight: 600; }
.bio-text { white-space: pre-wrap; margin-top: 2px; }

/* Tabs */
.tabs {
  display: flex;
  justify-content: center;
  gap: 60px;
  border-top: 1px solid var(--border);
}
.tab {
  background: none;
  border: none;
  border-top: 1px solid transparent;
  margin-top: -1px;
  padding: 16px 4px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
}
.tab.active { color: var(--text); border-top-color: var(--text); }

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-top: 4px;
}
.cell {
  position: relative;
  aspect-ratio: 1;
  background: #efefef;
  cursor: pointer;
  overflow: hidden;
}
.cell img, .cell video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.cell .article-cell {
  width: 100%;
  height: 100%;
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, #fdf2f8, #ede9fe);
}
.cell .article-cell h4 {
  font-size: 16px;
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.cell .article-cell p {
  font-size: 12px;
  color: var(--text-soft);
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.cell .badge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 15px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.4));
}
.cell .overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.3);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  font-weight: 600;
  opacity: 0;
  transition: opacity .15s;
}
.cell:hover .overlay { opacity: 1; }

.empty {
  text-align: center;
  color: var(--text-soft);
  padding: 60px 20px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--bg);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.view-card { max-width: 720px; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 16px; font-weight: 600; }
.head-actions { display: flex; gap: 4px; }
.modal-body { padding: 16px; overflow-y: auto; }
.modal-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

.type-picker {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.type-opt {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
}
.type-opt.active { border-color: var(--primary); color: var(--primary); background: #f0f8ff; }

.field { margin-bottom: 14px; }
.field.center { display: flex; justify-content: center; }
.field input[type="text"],
.field input[type="number"],
.field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  background: var(--bg-soft);
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--primary); }

.drop {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  border: 2px dashed var(--border);
  border-radius: 10px;
  cursor: pointer;
  color: var(--text-soft);
  background: var(--bg-soft);
  overflow: hidden;
  position: relative;
}
.drop:hover { border-color: var(--primary); }
.preview { width: 100%; }
.preview video { width: 100%; max-height: 320px; object-fit: contain; display: block; }
.prev-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: 100%;
}
.prev-thumb { position: relative; aspect-ratio: 1; }
.prev-thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; display: block; }
.prev-del {
  position: absolute;
  top: 4px; right: 4px;
  width: 22px; height: 22px;
  border: none; border-radius: 50%;
  background: rgba(0,0,0,.6); color: #fff;
  cursor: pointer; font-size: 12px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.prev-count { grid-column: 1 / -1; text-align: center; color: var(--text-soft); font-size: 13px; margin-top: 8px; }

/* Carousel (view modal) */
.carousel { position: relative; overflow: hidden; background: #000; }
.carousel-track { display: flex; transition: transform .3s ease; }
.carousel-track img { min-width: 100%; max-height: 60vh; object-fit: contain; display: block; }
.car-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 34px; height: 34px;
  border: none; border-radius: 50%;
  background: rgba(255,255,255,.85);
  color: #262626; font-size: 22px; line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.car-nav.prev { left: 10px; }
.car-nav.next { right: 10px; }
.car-dots {
  position: absolute;
  bottom: 10px; left: 0; right: 0;
  display: flex; justify-content: center; gap: 6px;
}
.car-dots span { width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,.5); }
.car-dots span.on { background: #fff; }

.avatar-edit { text-align: center; cursor: pointer; }
.avatar-edit img {
  width: 90px; height: 90px; border-radius: 50%; object-fit: cover;
  display: block; margin: 0 auto 6px; background: #efefef; border: 1px solid var(--border);
}
.avatar-edit span { color: var(--primary); font-weight: 600; font-size: 14px; }

/* View modal */
.view-body { overflow-y: auto; }
.view-body img, .view-body video { width: 100%; max-height: 60vh; object-fit: contain; background: #000; display: block; }
.view-text { padding: 16px; }
.view-text h2 { font-size: 20px; margin-bottom: 10px; }
.view-text .caption { white-space: pre-wrap; line-height: 1.6; }
.view-text .meta { color: var(--text-soft); font-size: 12px; margin-top: 14px; }

.login-card { max-width: 360px; }
.login-note { color: var(--text-soft); font-size: 14px; margin-bottom: 16px; text-align: center; }
.field input[type="email"], .field input[type="password"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  background: var(--bg-soft);
}
.field input[type="email"]:focus, .field input[type="password"]:focus { outline: none; border-color: var(--primary); }
.login-error { color: var(--danger); font-size: 13px; text-align: center; margin-top: 4px; }

.view-foot { justify-content: flex-start; }
.like-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  font-family: inherit;
  font-weight: 600;
}
.like-btn .heart { font-size: 24px; transition: transform .15s; }
.like-btn:active .heart { transform: scale(1.3); }

@media (max-width: 640px) {
  .profile { flex-direction: column; text-align: center; gap: 16px; }
  .avatar-ring { width: 100px; height: 100px; }
  .profile-top { flex-direction: column; gap: 12px; }
  .stats { justify-content: center; gap: 24px; }
  .stats { order: -1; }
  .tabs { gap: 30px; }
  .tab span, .tab { font-size: 11px; }
}
