@import './tokens.css';

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

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: background 0.2s, color 0.2s;
  min-height: 100vh;
}

/* ── Layout ── */
.app-layout {
  display: grid;
  grid-template-columns: 240px 1fr 300px;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
}

@media (max-width: 900px) {
  .app-layout { grid-template-columns: 1fr; }
  .sidebar, .sidebar-right { display: none; }
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.topbar .logo {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
  text-decoration: none;
  letter-spacing: -0.5px;
}

.topbar nav { display: flex; gap: 8px; margin-left: auto; }

.sidebar {
  padding: 24px 16px;
  border-right: 1px solid var(--border);
  position: sticky;
  top: 57px;
  height: calc(100vh - 57px);
  overflow-y: auto;
}

.sidebar-right {
  padding: 24px 16px;
  border-left: 1px solid var(--border);
  position: sticky;
  top: 57px;
  height: calc(100vh - 57px);
  overflow-y: auto;
}

.main-content {
  padding: 0;
  overflow-y: auto;
  max-height: calc(100vh - 57px);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border: none;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-secondary); color: var(--text-primary); }

.btn-icon {
  padding: 8px;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s;
  font-size: 18px;
}
.btn-icon:hover { background: var(--bg-secondary); color: var(--text-primary); }

.btn:disabled, .btn-icon:disabled, .action-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* ── Nav Items ── */
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
  transition: all 0.15s;
  cursor: pointer;
}
.nav-item:hover, .nav-item.active {
  background: var(--bg-secondary);
  color: var(--text-primary);
}
.nav-item .icon { font-size: 20px; width: 24px; text-align: center; }

/* ── Cards ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* ── Scribble Card ── */
.scribble-card {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 16px;
  transition: background 0.15s;
}
.scribble-card:hover { background: var(--bg-secondary); }

.scribble-card__header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.scribble-card__author {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
}
.scribble-card__meta {
  font-size: 12px;
  color: var(--text-muted);
}
.scribble-card__gallery {
  font-size: 12px;
  color: var(--accent);
  margin-left: auto;
  text-decoration: none;
  font-weight: 500;
}

.scribble-thumbnail {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--canvas-bg);
  display: block;
  cursor: pointer;
  max-height: 300px;
  object-position: center;
}

.scribble-thumbnail-img {
  width: 100%;
  max-height: 280px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  background: var(--canvas-bg);
  cursor: pointer;
}

.scribble-preview-pad {
  display: block;
  width: 100%;
  aspect-ratio: 4/3;
  max-height: 280px;
  border-radius: var(--radius-sm);
  background: var(--canvas-bg);
  overflow: hidden;
  cursor: pointer;
}

.scribble-thumbnail--empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
}

.scribble-card__actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 12px;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.action-btn:hover { background: var(--bg-secondary); }
.action-btn.liked { color: var(--like-color); }
.action-btn .count { font-weight: 600; }

.emoji-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.emoji-badge {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  font-size: 13px;
  cursor: pointer;
}
.emoji-badge:hover { border-color: var(--accent); }

/* ── Thread View ── */
.thread-reply {
  margin-left: 24px;
  border-left: 2px solid var(--border);
  padding-left: 16px;
}

/* ── Forms ── */
.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-secondary);
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: border-color 0.15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Auth Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal h2 { margin: 0 0 24px; font-size: 22px; }

/* ── Draw Pad Modal ── */
.draw-modal {
  max-width: 680px;
}
.draw-controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  padding: 12px 0;
}

/* ── Color picker ── */
.color-swatches {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  transition: transform 0.1s;
  position: relative;
}
.color-swatch.active { border-color: var(--text-primary); transform: scale(1.15); }
.color-swatch.used { opacity: 0.3; cursor: not-allowed; }

/* ── Feed ── */
.feed { border-top: 1px solid var(--border); }

.sentinel { height: 20px; }

.page-header {
  padding: 24px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.page-header h1 {
  margin: 0;
  font-size: 24px;
}
.page-header p {
  margin: 6px 0 0;
  color: var(--text-secondary);
  font-size: 14px;
}

.empty-state {
  padding: 48px 24px;
  text-align: center;
  max-width: 520px;
  margin: 0 auto;
}
.empty-state h2 {
  margin: 0 0 8px;
  font-size: 22px;
}
.empty-state p {
  margin: 0 auto 18px;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
}
.empty-card {
  padding: 32px;
  color: var(--text-muted);
}

/* ── Gallery ── */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  padding: 16px;
}

/* ── Profile ── */
.profile-header {
  padding: 32px 24px 16px;
  border-bottom: 1px solid var(--border);
  text-align: center;
}
.profile-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--accent);
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 800;
  color: white;
}
.profile-username { font-size: 20px; font-weight: 700; }
.profile-stats { display: flex; gap: 24px; justify-content: center; margin-top: 12px; }
.profile-stat { text-align: center; }
.profile-stat .num { font-size: 18px; font-weight: 700; }
.profile-stat .lbl { font-size: 12px; color: var(--text-muted); }

/* ── Alerts ── */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 12px;
}
.alert-error { background: #ffe0e0; color: #c00; border: 1px solid #fcc; }
.alert-success { background: #e0ffe0; color: #060; border: 1px solid #cfc; }
[data-theme="dark"] .alert-error { background: rgba(200,0,0,0.2); color: #ff8080; border-color: rgba(200,0,0,0.3); }
[data-theme="dark"] .alert-success { background: rgba(0,200,0,0.2); color: #80ff80; border-color: rgba(0,200,0,0.3); }

/* ── Loading ── */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Utilities ── */
.hidden { display: none !important; }
.text-center { text-align: center; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.gap-2 { gap: 8px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }


.draw-modal wasm-draw-pad {
  display: block;
  width: 100%;
  min-height: 320px;
}

@media (max-width: 768px) {
  .modal-overlay { padding: 0; align-items: stretch; }
  .draw-modal {
    max-width: 100%;
    min-height: 100dvh;
    height: 100dvh;
    border-radius: 0;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .draw-modal h2 { margin: 0; font-size: 18px; }
  .draw-modal .draw-controls { order: 2; padding: 4px 0; gap: 8px; }
  .draw-modal #color-picker-container { order: 3; margin-bottom: 6px !important; }
  .draw-modal wasm-draw-pad {
    order: 1;
    flex: 1;
    min-height: 45dvh;
    max-height: 58dvh;
  }
  .draw-modal #post-area {
    order: 4;
    margin-top: auto !important;
    padding-bottom: calc(env(keyboard-inset-height, 0px) + env(safe-area-inset-bottom, 0px));
    background: var(--bg-card);
  }
}
