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

body {
  font-family: "Segoe UI", Arial, sans-serif;
  background: #f5f5f5;
  color: #222;
  text-align: center;
  padding: 0 10px 40px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

h1, h2, h3 { font-weight: 600; }

/* ==================== Lucide icons ==================== */

.btn-with-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}

.btn-with-icon i,
.btn-with-icon svg {
  display: inline-flex;
}

svg.lucide {
  width: 1rem;
  height: 1rem;
  stroke: currentColor;
}

.lucide-brand {
  width: 1.35rem;
  height: 1.35rem;
  color: #4a90d9;
}

.lucide-user-avatar {
  width: 1.1rem;
  height: 1.1rem;
  color: #555;
}

.lucide-section {
  width: 1rem;
  height: 1rem;
  color: #4a90d9;
}

/* Heart badges and buttons (icon + number) */
.heart-preview-badge,
.heart-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.heart-icon,
.heart-badge svg,
.heart-preview-badge svg {
  width: 0.9rem;
  height: 0.9rem;
}

/* Like button: change icon color when active */
.like-btn.active {
  color: #8e2343;
}
.like-btn.active svg.lucide {
  fill: #d24b73;
  stroke: #d24b73;
}

/* ==================== Top bar ==================== */

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: nowrap;
  padding: 12px 16px;
  background: #fff;
  border-bottom: 1px solid #ddd;
  margin: 0 -10px 16px;
}

.top-bar h1 { font-size: 1.1rem; }

.top-bar-brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  white-space: nowrap;
}

.top-bar-brand h1 {
  white-space: nowrap;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
}

#username-display { font-weight: 600; }

.btn-small {
  padding: 4px 12px;
  font-size: 0.8rem;
  cursor: pointer;
  border: 1px solid #bbb;
  border-radius: 4px;
  background: #fff;
}
.btn-small:hover { background: #eee; }

/* ==================== Canvas ==================== */

.canvas-container {
  margin: 0;
  width: 250px;
  height: 250px;
  border: 2px solid #333;
  background: white;
  touch-action: none;
}

canvas {
  cursor: crosshair;
  display: block;
  width: 100%;
  height: 100%;
}

.canvas-tools {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-right: 6px;
}

.tool-colors,
.tool-sizes {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.tool-colors { padding-bottom: 6px; border-bottom: 1px solid #ddd; }

.color-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s, transform 0.1s;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.12);
  margin: 0;
}
.color-dot:hover { transform: scale(1.15); }
.color-dot.active {
  border-color: #4a90d9;
  box-shadow: 0 0 0 1px #4a90d9;
}

.size-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid transparent;
  padding: 0;
  cursor: pointer;
  background: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s;
  margin: 0;
}
.size-dot span {
  display: block;
  border-radius: 50%;
  background: #333;
}
.size-dot:hover { border-color: #aaa; }
.size-dot.active { border-color: #4a90d9; }

.canvas-container.shake {
  animation: shake 0.35s ease;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%  { transform: translateX(-4px); }
  40%  { transform: translateX(4px); }
  60%  { transform: translateX(-3px); }
  80%  { transform: translateX(3px); }
}

.buttons { margin: 10px; }

/* ==================== Layout ==================== */

.main-layout {
  display: grid;
  grid-template-columns: 280px minmax(320px, 1fr) 280px;
  gap: 24px;
  align-items: start;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 10px;
}

.main-left {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Canvas + image la plus aimée */
.canvas-top-row {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 20px;
  margin-bottom: 10px;
}

.top-liked {
  width: 280px;
  background: #fff;
  border: 1px solid #e9e9e9;
  border-radius: 12px;
  padding: 12px 12px 10px;
  position: sticky;
  top: 16px;
}

.top-liked-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 10px;
}

.top-liked-header h3 {
  font-size: 1.05rem;
  margin: 0;
}

.top-liked-icon {
  width: 1.15rem;
  height: 1.15rem;
  color: #d4af37;
}

.top-liked-image-frame {
  display: flex;
  justify-content: center;
  margin-bottom: 10px;
}

.top-liked-image-frame img {
  width: 180px;
  height: 180px;
  object-fit: cover;
  border: 3px solid #d4af37;
  border-radius: 14px;
  background: #fff;
}

.top-liked-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #666;
  font-size: 0.9rem;
  font-weight: 600;
}

.top-liked-like-icon {
  width: 1rem;
  height: 1rem;
  color: #4a90d9;
}

/* ==================== Leaderboard ==================== */

.leaderboard {
  width: 280px;
  background: #fff;
  border: 1px solid #e9e9e9;
  border-radius: 12px;
  padding: 14px 14px 10px;
  position: sticky;
  top: 16px;
}

.leaderboard-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.leaderboard-header h3 {
  margin: 0;
  font-size: 1.05rem;
}

.leaderboard-icon {
  width: 1.1rem;
  height: 1.1rem;
  color: #4a90d9;
}

.leaderboard-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 28px 1fr 1.5fr;
  column-gap: 8px;
  row-gap: 6px;
  align-items: center;
  padding-bottom: 10px;
  border-bottom: 1px dashed #eee;
}

.leaderboard-row:last-child {
  border-bottom: none;
}

.leaderboard-rank {
  font-weight: 800;
  color: #666;
  font-size: 0.95rem;
  text-align: left;
}

.leaderboard-username {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: none;
}

.leaderboard-stats {
  grid-column: 3;
  grid-row: 1;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: flex-end;
  color: #666;
  font-size: 0.85rem;
}

.leaderboard-stat {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.leaderboard-stat-icon {
  width: 0.95rem;
  height: 0.95rem;
  stroke: currentColor;
  color: #4a90d9;
}

.leaderboard-stat-num {
  font-weight: 700;
  color: #333;
}

.leaderboard-empty {
  color: #999;
  font-style: italic;
  font-size: 0.9rem;
}

@media (max-width: 900px) {
  .main-layout {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .top-liked,
  .leaderboard {
    width: 100%;
    position: relative;
    top: auto;
  }

  .canvas-top-row { flex-direction: column; }

  .canvas-tools {
    flex-direction: row;
    margin-right: 0;
    margin-bottom: 6px;
  }

  .tool-colors,
  .tool-sizes {
    flex-direction: row;
  }

  .tool-colors { padding-bottom: 0; border-bottom: none; border-right: 1px solid #ddd; padding-right: 8px; margin-right: 8px; }
}

button {
  padding: 8px 16px;
  margin: 0 5px;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid #bbb;
  border-radius: 4px;
  background: #fff;
}
button:hover { background: #eee; }

/* ==================== Gallery ==================== */

h2 { margin: 24px 0 12px; }

.gallery {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 12px;
}

.gallery-card {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 6px;
  position: relative;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  width: 100px;
  text-align: center;
}
.gallery-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.gallery-card img {
  border-radius: 4px;
  background: #fff;
  display: block;
  width: 80px;
  height: 80px;
  margin: 0 auto;
}

.gallery-image-wrap {
  width: 80px;
  margin: 0 auto;
}

.heart-preview-badge {
  position: absolute;
  top: -8px;
  left: -8px;
  background: #fff;
  color: #c62b5b;
  border: 1px solid #f2b4c7;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  z-index: 2;
}

.heart-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(255, 255, 255, 0.92);
  color: #c62b5b;
  border: 1px solid #f2b4c7;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
}

.gallery-meta {
  margin-top: 4px;
  font-size: 0.7rem;
  color: #666;
  line-height: 1.3;
}
.gallery-author { display: block; font-weight: 600; color: #333; }
.gallery-stats { display: block; }

/* ==================== Modal ==================== */

.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }

.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }

.modal-content {
  position: relative;
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  max-width: 420px;
  width: 92%;
  max-height: 90vh;
  overflow-y: auto;
  z-index: 1;
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  font-size: 1.6rem;
  cursor: pointer;
  color: #666;
  padding: 0;
  margin: 0;
}
.modal-close:hover { color: #000; }

.modal-close svg {
  width: 1.25rem;
  height: 1.25rem;
}

#detail-image {
  display: block;
  margin: 0 auto 8px;
  max-width: 260px;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fff;
}

.detail-image-wrap {
  position: relative;
  width: fit-content;
  margin: 0 auto;
}

.detail-image-wrap .heart-badge {
  top: 10px;
  left: 10px;
}

.detail-author {
  font-size: 0.85rem;
  color: #888;
  margin-bottom: 16px;
}

/* ==================== Reactions ==================== */

.like-btn {
  margin: 0 auto 20px;
  display: inline-block;
  min-width: 120px;
  border: 2px solid #f0c0d0;
  border-radius: 999px;
  background: #fff4f8;
  color: #b63258;
  font-weight: 700;
}
.like-btn:hover {
  background: #ffe8f0;
}
.like-btn.active {
  border-color: #d24b73;
  background: #ffdce8;
  color: #8e2343;
}

/* ==================== Comments ==================== */

.comments-section { text-align: left; }
.comments-section h3 { font-size: 0.95rem; margin-bottom: 8px; }

#comments-list {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 10px;
}

.comment {
  padding: 6px 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.85rem;
  line-height: 1.4;
}
.comment strong { margin-right: 6px; }

.no-comments { color: #aaa; font-size: 0.85rem; font-style: italic; }

#comment-form {
  display: flex;
  gap: 6px;
}
#comment-input {
  flex: 1;
  padding: 6px 10px;
  font-size: 0.85rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  outline: none;
}
#comment-input:focus { border-color: #4a90d9; }
#comment-form button { font-size: 0.8rem; padding: 6px 12px; }

/* ==================== Auth page ==================== */

.auth-page-header {
  margin: 60px auto 20px;
  max-width: 420px;
}

.auth-page-header h1 {
  margin: 0;
}

.auth-tagline {
  margin-top: 0.35rem;
  font-size: 0.9rem;
  color: #666;
}

.lucide-auth-logo {
  width: 12rem;
  height: 12rem;
  color: #4a90d9;
  display: block;
  margin: 0 auto;
}

.auth-submit {
  width: 100%;
}

.auth-container {
  max-width: 420px;
  margin: 60px auto 0;
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}

.auth-tabs {
  display: flex;
  margin-bottom: 20px;
  border-bottom: 2px solid #eee;
}

.tab {
  flex: 1;
  padding: 10px 8px;
  background: none;
  border: none;
  font-size: 0.95rem;
  cursor: pointer;
  color: #888;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  border-radius: 0;
  white-space: nowrap;
}
.tab:hover { color: #444; }
.tab.active {
  color: #222;
  border-bottom-color: #4a90d9;
  font-weight: 600;
}

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form input {
  padding: 10px 12px;
  font-size: 0.9rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  outline: none;
}
.auth-form input:focus { border-color: #4a90d9; }
.auth-form button {
  padding: 10px;
  font-size: 0.95rem;
  background: #4a90d9;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
.auth-form button:hover { background: #3a7bc8; }

.auth-error { color: #c0392b; font-size: 0.85rem; min-height: 1.2em; }

.hidden { display: none !important; }

/* ==================== Admin (kept) ==================== */

.admin-page-body {
  padding: 20px 10px 40px;
  max-width: 900px;
  margin: 0 auto;
  text-align: left;
}

.admin-header {
  margin-bottom: 1.25rem;
}

.admin-header-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.admin-header-title h1 {
  font-size: 1.25rem;
}

.admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.admin-gallery {
  justify-content: flex-start;
}

.btn-danger {
  background: #c0392b;
  color: #fff;
  border-color: #a93226;
}

.btn-danger:hover {
  background: #a93226;
}

.btn-danger-outline {
  border-color: #c0392b;
  color: #c0392b;
}

.btn-danger-outline:hover {
  background: rgba(192, 57, 43, 0.08);
}

.lucide-admin {
  width: 1.5rem;
  height: 1.5rem;
}

.admin-item img {
  cursor: pointer;
  border: 2px solid transparent;
  transition: 0.2s;
}
.admin-item img:hover { transform: scale(1.05); }
.admin-item img.selected {
  border: 3px solid #e74c3c;
  opacity: 0.7;
}
