/* ==========================================================================
   HMI Library — community pages (/s/{slug} symbol page, /u/{username} profile)
   Loaded after /styles.css: reuses its tokens (--g-*, --p1..--p4, --run,
   --radius*, --shadow*, --font-sans, --font-mono, --header-h, --container).
   Industrial calm gray, no decorative colour; state colours only for meaning.
   ========================================================================== */

/* ---------- shared primitives ------------------------------------------ */

.cta-modal[hidden],
#comment-form[hidden],
#comments-auth-cta[hidden],
#profile-load-more[hidden],
.quota-note[hidden] { display: none !important; }

body.cm-modal-open { overflow: hidden; }

/* Button look, independent from styles.css so SSR buttons (no .btn class) match. */
.cm-btn,
.sym-actions > button,
.sym-actions > a,
#comment-form button,
#profile-load-more {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px;
  font-family: var(--font-sans, 'Inter', system-ui, sans-serif);
  font-size: 14px; font-weight: 600; line-height: 1.2;
  color: var(--g-900);
  background: #fff;
  border: 1px solid var(--g-300);
  border-radius: var(--radius, 8px);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.cm-btn:hover,
.sym-actions > button:hover,
.sym-actions > a:hover,
#comment-form button:hover,
#profile-load-more:hover { background: var(--g-100); border-color: var(--g-500); }

.cm-btn--primary,
#btn-dl-svg,
#comment-form button[type="submit"] {
  background: var(--g-900); color: var(--g-50); border-color: var(--g-900);
}
.cm-btn--primary:hover,
#btn-dl-svg:hover,
#comment-form button[type="submit"]:hover {
  background: var(--g-800); border-color: var(--g-800); color: var(--g-50);
  transform: translateY(-1px);
}
.cm-btn--outline { background: transparent; }

.cm-btn:disabled, .cm-btn.is-busy,
.sym-actions > button:disabled, .sym-actions > button.is-busy,
#comment-form button:disabled,
#profile-load-more:disabled { opacity: .55; cursor: progress; transform: none; }

.cm-btn svg, .sym-actions svg { flex: 0 0 auto; }

/* ---------- toast ------------------------------------------------------ */

.cm-toasts {
  position: fixed; bottom: 24px; right: 24px; z-index: 300;
  display: flex; flex-direction: column; gap: 8px;
  max-width: min(380px, calc(100vw - 48px));
  pointer-events: none;
}
.cm-toast {
  background: var(--g-900); color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius, 8px);
  font-size: 14px; font-weight: 500; line-height: 1.4;
  box-shadow: var(--shadow-lg, 0 16px 40px rgba(0,0,0,.10));
  animation: cm-slide-in .25s ease-out;
  transition: opacity .25s ease, transform .25s ease;
  pointer-events: auto;
}
.cm-toast--success { background: var(--run, #2E7D32); }
.cm-toast--error   { background: var(--p1, #D32F2F); }
.cm-toast.is-leaving { opacity: 0; transform: translateX(12px); }
@keyframes cm-slide-in { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes cm-fade    { from { opacity: 0; } to { opacity: 1; } }
@keyframes cm-up      { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- CTA modal (auth / quota) ----------------------------------- */

.cta-modal {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  padding: 24px;
  background: rgba(26,26,24,.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: cm-fade .15s ease-out;
}
.cta-card {
  position: relative;
  width: 100%; max-width: 440px;
  background: #fff;
  border-radius: var(--radius-lg, 14px);
  padding: 32px;
  box-shadow: var(--shadow-lg, 0 16px 40px rgba(0,0,0,.10));
  animation: cm-up .2s ease-out;
}
.cta-close {
  position: absolute; top: 14px; right: 14px;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  background: transparent; border: 0;
  border-radius: var(--radius-sm, 4px);
  color: var(--g-600); cursor: pointer;
}
.cta-close:hover { background: var(--g-100); color: var(--g-900); }
.cta-kicker {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--g-600); margin: 0 0 8px;
}
.cta-title {
  font-size: 22px; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em;
  color: var(--g-900); margin: 0 0 8px; padding-right: 28px;
}
.cta-text { font-size: 14px; line-height: 1.55; color: var(--g-600); margin: 0 0 22px; }
.cta-meter {
  height: 6px; border-radius: 999px; overflow: hidden;
  background: var(--g-150); margin: -8px 0 22px;
}
.cta-meter > span { display: block; height: 100%; background: var(--g-900); border-radius: inherit; }
.cta-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.cta-actions > .cm-btn { flex: 1 1 0; min-width: 120px; }
.cta-foot { font-size: 12px; color: var(--g-600); margin: 16px 0 0; text-align: center; }

/* ---------- symbol page layout ----------------------------------------- */

/* The Worker wraps <main> in `.wrap` (max-width 1100px, padding 40px 24px 80px,
   defined in its inline PAGE_CSS). That wrapper owns the outer spacing, so the
   page roots add none of their own — otherwise side padding doubles to 48px. */
#symbol-page,
#profile-page {
  max-width: 100%;
  margin: 0;
  padding: 0;
}

/* Two columns when the preview is a direct child: image left, meta right,
   comments full width underneath. Falls back to a single column otherwise. */
#symbol-page:has(> .sym-preview) {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  column-gap: 56px; row-gap: 0;
  align-items: start;
}
#symbol-page > .sym-preview { grid-column: 1; grid-row: 1 / span 24; }
#symbol-page > :not(.sym-preview):not(#comments):not(.cta-modal):not(script):not(style) { grid-column: 2; }
#symbol-page > #comments { grid-column: 1 / -1; }

.sym-preview {
  display: block;
  width: 100%; height: auto;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  padding: 40px;
  background: var(--g-100);
  border: 1px solid var(--g-200);
  border-radius: var(--radius-lg, 14px);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.6);
}

.sym-title {
  font-size: 30px; font-weight: 700; line-height: 1.15; letter-spacing: -0.02em;
  color: var(--g-900); margin: 0 0 10px;
}
.sym-author {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 14px; font-weight: 500; color: var(--g-600);
  margin: 0 0 12px;
  width: fit-content;
}
.sym-author::before { content: 'by'; color: var(--g-600); font-weight: 400; }
.sym-author:hover { color: var(--g-900); text-decoration: underline; text-underline-offset: 3px; }

.isa-badge {
  display: inline-flex; align-items: center; gap: 7px;
  width: fit-content;
  padding: 4px 10px 4px 8px;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--g-800);
  background: var(--g-100);
  border: 1px solid var(--g-300);
  border-radius: 999px;
  margin: 0 0 18px;
}
.isa-badge::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%;
  background: var(--run, #2E7D32);
}

.sym-desc {
  font-size: 15px; line-height: 1.6; color: var(--g-700);
  margin: 0 0 18px;
  white-space: pre-line; overflow-wrap: anywhere;
}

.sym-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 22px; }
.sym-tags .tag {
  display: inline-flex; align-items: center;
  padding: 4px 10px;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 12px; color: var(--g-700);
  background: var(--g-100);
  border: 1px solid var(--g-200);
  border-radius: 999px;
  transition: border-color .15s, color .15s, background .15s;
}
.sym-tags .tag:hover { border-color: var(--g-500); color: var(--g-900); background: #fff; }

/* The Worker emits "<span id="stat-likes">7</span> likes · <span id="stat-downloads">3</span> downloads · …"
   (labels are real text so crawlers / no-CSS readers get them). Keep this block
   `display:block`: a flex container would turn the loose label text into
   separate flex items with gaps. Do NOT re-add ::after label content here. */
.sym-stats {
  display: block;
  padding: 12px 0;
  margin: 0 0 20px;
  border-top: 1px solid var(--g-150);
  border-bottom: 1px solid var(--g-150);
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 13px; line-height: 1.7; color: var(--g-600);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.sym-stats > span { color: var(--g-900); font-weight: 600; }

.sym-meta a { color: var(--g-700); text-decoration: underline; text-underline-offset: 3px; }
.sym-meta a:hover { color: var(--g-900); }

.sym-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 12px; }

#btn-like[aria-pressed="true"] { border-color: var(--g-900); }
#btn-like[aria-pressed="true"] svg { fill: currentColor; }
#btn-like svg { transition: transform .15s ease, fill .15s ease; }
#btn-like:active svg { transform: scale(.9); }

#btn-report {
  margin-left: auto;
  padding: 8px 10px;
  font-size: 13px; font-weight: 500;
  color: var(--g-600);
  background: transparent; border-color: transparent;
}
#btn-report:hover { color: var(--g-900); background: var(--g-100); border-color: transparent; }

.sym-edit-link { font-size: 13px; padding: 8px 12px; }

.quota-note {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 12px; color: var(--g-600);
  margin: 0 0 28px;
}
.quota-note:empty { display: none; }
.quota-note.is-empty { color: var(--g-800); }
.quota-note a { color: var(--g-900); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- comments --------------------------------------------------- */

#comments {
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px solid var(--g-200);
  max-width: 760px;
}
#comments h2 {
  font-size: 20px; font-weight: 700; letter-spacing: -0.01em;
  color: var(--g-900); margin: 0 0 16px;
}
#comments-list[aria-busy="true"] { min-height: 48px; opacity: .6; }
.comments-empty { font-size: 14px; color: var(--g-600); margin: 0; padding: 14px 0; }

.comment {
  display: flex; gap: 12px;
  padding: 16px 0;
  border-bottom: 1px solid var(--g-150);
}
.comment:last-child { border-bottom: 0; }
.comment-avatar {
  flex: 0 0 34px; width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--g-200); color: var(--g-700);
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 13px; font-weight: 600;
  overflow: hidden;
}
.comment-avatar img { width: 100%; height: 100%; object-fit: cover; }
.comment-main { flex: 1 1 auto; min-width: 0; }
.comment-head { display: flex; align-items: baseline; gap: 10px; font-size: 13px; }
.comment-author { font-weight: 600; color: var(--g-900); }
a.comment-author:hover { text-decoration: underline; text-underline-offset: 3px; }
.comment-time {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 12px; color: var(--g-600);
}
.comment-report {
  margin-left: auto;
  padding: 0 4px;
  background: none; border: 0;
  font-family: inherit; font-size: 12px;
  color: var(--g-400); cursor: pointer;
  opacity: 0; transition: opacity .15s, color .15s;
}
.comment:hover .comment-report,
.comment-report:focus-visible { opacity: 1; }
.comment-report:hover { color: var(--g-900); }
@media (hover: none) { .comment-report { opacity: 1; } }
.comment-body {
  margin: 4px 0 0;
  font-size: 14.5px; line-height: 1.55; color: var(--g-700);
  white-space: pre-wrap; overflow-wrap: anywhere;
}

#comment-form {
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
  margin-top: 20px;
}
#comment-body {
  width: 100%; min-height: 96px;
  resize: vertical;
  padding: 12px 14px;
  font: inherit; font-size: 14px; line-height: 1.5;
  color: var(--g-800);
  background: #fff;
  border: 1px solid var(--g-200);
  border-radius: var(--radius, 8px);
  transition: border-color .15s, box-shadow .15s;
}
#comment-body::placeholder { color: var(--g-400); }
#comment-body:focus {
  outline: none; border-color: var(--g-900);
  box-shadow: 0 0 0 3px rgba(26,26,24,.08);
}
#comments-auth-cta {
  margin-top: 20px;
  padding: 14px 16px;
  text-align: center;
  font-size: 14px; font-weight: 500; color: var(--g-600);
  border: 1px dashed var(--g-300);
  border-radius: var(--radius, 8px);
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
#comments-auth-cta:hover { border-color: var(--g-500); color: var(--g-900); background: #fff; }

/* ---------- profile page ----------------------------------------------- */

/* Mirrors the SSR markup emitted by src/worker.js renderProfile():
     <header class="profile-head">
       <img class="profile-avatar" width="96" height="96"> | <div class="profile-avatar profile-avatar-initials">
       <div class="profile-id"><h1>@user</h1><p class="profile-name"><p class="profile-bio"><a class="profile-website"><p class="profile-count">
     </header>
   The h1 is the @username (28px); .profile-name is the secondary full name.
   Keep these values in sync with the PAGE_CSS fallbacks in the Worker. */
.profile-head {
  display: flex; align-items: flex-start; flex-wrap: wrap; gap: 24px;
  margin: 0 0 32px;
}
.profile-avatar {
  width: 96px; height: 96px; flex: 0 0 96px;
  border-radius: 50%; object-fit: cover;
  background: var(--g-200); border: 1px solid var(--g-200);
}
.profile-avatar-initials {
  display: grid; place-items: center;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-weight: 700; font-size: 28px;
  color: var(--g-50); background: var(--g-900); border-color: var(--g-900);
}
.profile-id { flex: 1 1 280px; min-width: 0; }
.profile-head h1 { margin: 0 0 4px; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; color: var(--g-900); }
.profile-name { margin: 0 0 8px; font-size: 14px; font-weight: 500; color: var(--g-700); }
.profile-bio { margin: 0 0 8px; font-size: 15px; line-height: 1.55; color: var(--g-700); max-width: 640px; white-space: pre-line; overflow-wrap: anywhere; }
.profile-website { font-size: 14px; color: var(--g-700); text-decoration: underline; text-underline-offset: 3px; }
.profile-website:hover { color: var(--g-900); }
.profile-count {
  margin: 8px 0 0;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 12px; color: var(--g-600);
  text-transform: uppercase; letter-spacing: .06em;
}

/* ---------- symbol grid / cards (Noun-Project clean) ------------------- */

.sym-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}
.sym-grid:empty::after {
  content: 'No published symbols yet.';
  grid-column: 1 / -1;
  padding: 40px 0; text-align: center;
  font-size: 14px; color: var(--g-600);
}
.sym-card {
  display: flex; flex-direction: column;
  min-width: 0;
  background: #fff;
  border: 1px solid var(--g-200);
  border-radius: var(--radius-lg, 14px);
  overflow: hidden;
  color: inherit; text-decoration: none;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.sym-card:hover { border-color: var(--g-400); box-shadow: var(--shadow, 0 4px 14px rgba(0,0,0,.06)); transform: translateY(-1px); }
.sym-card img {
  display: block;
  width: 100%; height: auto;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  padding: 18px;
  background: var(--g-100);
  border-bottom: 1px solid var(--g-150);
}
.sym-card-title {
  padding: 12px 14px 2px;
  font-size: 14px; font-weight: 600; line-height: 1.3;
  color: var(--g-900);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sym-card-meta {
  padding: 0 14px 12px;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 12px; color: var(--g-600);
  font-variant-numeric: tabular-nums;
}
#profile-load-more { display: flex; margin: 28px auto 0; min-width: 160px; }

/* styles.css:286 da `section { padding: 80px 0 }` — es una regla de la portada,
   donde cada seccion es una franja de pantalla completa. En el perfil y en la
   ficha las secciones ya se separan con su propio margen, asi que ahi ese
   relleno solo abre una banda vacia: 92px entre "37 simbolos" y el titulo
   "Simbolos" en un telefono (medido a 375px), 136px en escritorio. */
#profile-page .profile-section { padding: 0; }
/* En #comments solo sobra el relleno de abajo: el de arriba lo fija la regla de
   la linea 271 (32px, junto al borde superior) y ese si hace falta. */
#symbol-page > #comments { padding-bottom: 0; }

/* ---------- responsive ------------------------------------------------- */

@media (max-width: 1100px) {
  .sym-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  #symbol-page:has(> .sym-preview) { display: block; }
  .sym-preview { max-width: 560px; margin: 0 0 22px; padding: 28px; }
  .wrap { padding: 24px 20px 64px; }
  .sym-title { font-size: 26px; }
  .sym-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  #comments { margin-top: 36px; }
}
@media (max-width: 560px) {
  /* Una sola columna dejaba la rejilla del perfil en 24 tarjetas de 335x284 y la
     pagina en 9.258px de alto en un telefono (medido en /u/pauserrano a 375px).
     Dos columnas de 163px la dejan en 4.194px y coinciden con las de /explore/,
     que ya usa minmax(150px,1fr). El titulo pasa de recortarse con puntos
     suspensivos a dos lineas, porque a 163px de ancho no cabia ni la mitad. */
  .sym-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .sym-card img { padding: 12px; }
  .sym-card-title {
    white-space: normal;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden;
    padding: 10px 12px 2px; font-size: 13.5px;
  }
  .sym-card-meta { padding: 0 12px 10px; font-size: 11.5px; }
  /* .profile-id pide 280px de base y a 375px solo le quedan 215, asi que el
     nombre caia debajo del avatar y la cabecera gastaba 237px de alto antes de
     enseñar un solo simbolo. Con el avatar a 64px caben en la misma fila. */
  .profile-head { gap: 14px; margin-bottom: 24px; }
  .profile-avatar { width: 64px; height: 64px; flex: 0 0 64px; }
  .profile-avatar-initials { font-size: 22px; }
  .profile-id { flex: 1 1 0; }
  .profile-head h1 { font-size: 22px; }
  .sym-actions > button, .sym-actions > a { flex: 1 1 calc(50% - 4px); }
  #btn-report { flex: 0 0 auto; margin-left: auto; }
  .sym-stats { font-size: 12px; }
  .cta-card { padding: 24px; }
  .cta-actions > .cm-btn { flex-basis: 100%; }
  .cm-toasts { left: 16px; right: 16px; bottom: 16px; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  .cm-toast, .cta-modal, .cta-card, .sym-card, #btn-like svg { animation: none; transition: none; }
}
