:root {
  --primary: #6c5ce7;
  --primary-light: #a29bfe;
  --primary-bg: #f0eeff;
  --accent: #fd79a8;
  --danger: #e17055;
  --success: #00b894;
  --bg: #f0f2f5;
  --sidebar-bg: #ffffff;
  --card-bg: #ffffff;
  --text: #2d3436;
  --text-muted: #636e72;
  --border: #e8e8e8;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.14);
  --radius: 16px;
  --radius-sm: 10px;
  --sidebar-width: 230px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* ── Utility ── */
.hidden { display: none !important; }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(6px);
}

.modal {
  background: white;
  border-radius: var(--radius);
  padding: 44px 36px;
  width: 90%;
  max-width: 400px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.28s ease;
}

.modal-icon { font-size: 52px; margin-bottom: 14px; }

.modal h2 {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 8px;
}

.modal p {
  color: var(--text-muted);
  margin-bottom: 22px;
  font-size: 15px;
}

.modal input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: inherit;
  margin-bottom: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.modal input:focus { border-color: var(--primary); }

/* ── Layout ── */
#app {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 14px;
  gap: 20px;
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
}

.logo-icon { font-size: 26px; }

.logo-text {
  font-size: 21px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.3px;
}

.nav-links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
  user-select: none;
}

.nav-item:hover {
  background: var(--bg);
  color: var(--text);
}

.nav-item.active {
  background: var(--primary-bg);
  color: var(--primary);
}

.nav-icon { font-size: 17px; }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}

.user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.user-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.user-name {
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.change-name-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 11px;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
  font-weight: 600;
  text-align: left;
}

.change-name-btn:hover { text-decoration: underline; }

/* ── Main Content ── */
#content {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
}

.page {
  display: none;
  min-height: 100%;
  padding: 28px 32px;
  max-width: 660px;
  margin: 0 auto;
}

.page.active { display: block; }

.page-header {
  margin-bottom: 20px;
}

.page-header h1 {
  font-size: 24px;
  font-weight: 800;
}

/* ── Feed ── */
#posts-container {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.post-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: fadeIn 0.28s ease;
}

.post-header {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  gap: 11px;
}

.post-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.post-user-info { flex: 1; min-width: 0; }

.post-username {
  font-weight: 700;
  font-size: 13px;
}

.post-time {
  color: var(--text-muted);
  font-size: 11px;
  margin-top: 1px;
}

.post-delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
}

.post-delete-btn:hover { background: #fee8e4; color: var(--danger); }

.post-image {
  width: 100%;
  display: block;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.post-footer { padding: 12px 16px; }

.post-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.like-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: 20px;
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
}

.like-btn:hover { background: #fff0f5; color: var(--accent); }

.like-btn.liked { color: var(--accent); }

.like-heart {
  font-size: 16px;
  display: inline-block;
  transition: transform 0.15s;
}

.like-btn.liked .like-heart { animation: heartPop 0.25s ease; }

.post-caption {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
}

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 56px 20px;
  color: var(--text-muted);
}

.empty-icon { font-size: 52px; margin-bottom: 14px; }

.empty-state p {
  font-size: 15px;
  line-height: 1.7;
  margin-bottom: 20px;
}

/* ── Draw Page ── */
.draw-container {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#toolbar {
  background: white;
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 7px;
}

.tool-group + .tool-group {
  padding-left: 14px;
  border-left: 1px solid var(--border);
}

.tool-btn {
  height: 34px;
  padding: 0 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: white;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  color: var(--text-muted);
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  white-space: nowrap;
}

.tool-btn:hover {
  border-color: var(--primary-light);
  color: var(--primary);
  background: var(--primary-bg);
}

.tool-btn.active {
  border-color: var(--primary);
  background: var(--primary-bg);
  color: var(--primary);
}

.tool-btn.danger:hover {
  border-color: var(--danger);
  background: #fff0ee;
  color: var(--danger);
}

.color-palette {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  align-items: center;
}

.color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s;
  flex-shrink: 0;
}

.color-swatch:hover { transform: scale(1.25); }

.color-swatch.active {
  border-color: #2d3436;
  transform: scale(1.15);
  box-shadow: 0 0 0 1px white inset;
}

#custom-color {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border);
  padding: 0;
  cursor: pointer;
  background: none;
  flex-shrink: 0;
}

.size-group { gap: 8px; }

.size-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

#brush-size {
  width: 80px;
  accent-color: var(--primary);
  cursor: pointer;
}

#brush-size-display {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 18px;
  text-align: center;
}

.canvas-wrapper {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: crosshair;
  line-height: 0;
}

#drawing-canvas {
  display: block;
  max-width: 100%;
  touch-action: none;
}

.post-controls {
  background: white;
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  gap: 10px;
  box-shadow: var(--shadow);
}

.post-controls input {
  flex: 1;
  padding: 9px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.post-controls input:focus { border-color: var(--primary-light); }

/* ── Buttons ── */
.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn-primary:hover { background: #5b4bc4; transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

/* ── Profile ── */
.profile-header-card {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 22px 24px;
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.profile-avatar {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

#profile-username {
  font-size: 20px;
  font-weight: 800;
}

#profile-stats {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 4px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  background: white;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.gallery-item {
  aspect-ratio: 1;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  background: var(--bg);
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s;
}

.gallery-item:hover img { transform: scale(1.06); }

.gallery-item-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.38);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
  color: white;
  font-weight: 700;
  font-size: 13px;
  gap: 6px;
}

.gallery-item:hover .gallery-item-overlay { opacity: 1; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: #2d3436;
  color: white;
  padding: 11px 22px;
  border-radius: 24px;
  font-size: 13px;
  font-weight: 600;
  z-index: 999;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
  animation: fadeIn 0.25s ease;
  white-space: nowrap;
}

/* ── Animations ── */
@keyframes slideUp {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeOut {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(0.96); }
}

@keyframes heartPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.5); }
  100% { transform: scale(1); }
}

/* ── Responsive ── */
@media (max-width: 780px) {
  :root { --sidebar-width: 195px; }
  .page { padding: 20px 18px; }
}

@media (max-width: 580px) {
  #sidebar {
    width: 60px;
    padding: 16px 8px;
  }
  .logo-text,
  .nav-label,
  .sidebar-user .user-details {
    display: none;
  }
  .nav-item { justify-content: center; padding: 11px; }
  .gallery-grid { grid-template-columns: repeat(2, 1fr); }
  #toolbar { gap: 8px; }
}
