/* ============================================================================
   SCREEN: USER PROFILE — #user/<slug-or-id>
   Block-based per-user page. Each section.u-block is one block instance; the
   layout is a flat vertical stack. Header is always the first block (and
   visually distinct). Mobile-first; the game-card grid collapses to one
   column at narrow widths.
   ========================================================================= */

.user-page {
  --user-accent: var(--warn, #d59148);
  /* Outer page is a vertical flex stack of rows. Each row is its own grid
     container — Sortable runs once per row + per drop-zone, so reorder is
     unambiguous (one block lives in exactly one row). */
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px;
}
.u-row {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
  align-items: start;
}
.u-block {
  grid-column: span var(--bw, 12);
  min-width: 0;
  align-self: start;
}
@media (max-width: 720px) {
  .u-row { grid-template-columns: repeat(4, 1fr); }
  .u-block { grid-column: span var(--bwm, 4); }
}
/* Empty row = drop-target for a block that should become a new row. Always
   full width, dashed, dim. While a drag is in flight it pulses. */
.u-row-empty {
  min-height: 32px;
  border: 2px dashed var(--border-2, rgba(255,220,180,0.15));
  border-radius: var(--r-md, 10px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--muted, #b3a89c);
  font-style: italic;
  user-select: none;
  padding: 6px;
}
.u-row-empty:hover {
  border-color: var(--user-accent, #d59148);
  color: var(--user-accent, #d59148);
}

section.u-block {
  background: var(--surface, #221d19);
  border: 1px solid var(--border, rgba(255,220,180,0.07));
  border-radius: var(--r-md, 10px);
  padding: 14px 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}

/* SortableJS visual feedback during drag */
.u-block.sortable-ghost { opacity: 0.4; }
.u-block.sortable-chosen { cursor: grabbing; }
.u-block.sortable-drag { box-shadow: 0 8px 24px rgba(0,0,0,0.5); cursor: grabbing; }


/* Drag-handle (only visible in edit mode, replaces the ↑/↓ buttons) */
.u-drag-handle {
  cursor: grab;
  user-select: none;
  font-size: 16px;
  padding: 0 6px;
  color: var(--muted, #b3a89c);
  border: 1px solid var(--border, rgba(255,220,180,0.07));
  border-radius: 6px;
  background: var(--surface-2, #2a231e);
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: 4px;
}
.u-drag-handle:hover { color: var(--text, #f1e8de); border-color: var(--warn, #d59148); }
.u-drag-handle:active { cursor: grabbing; }

.u-block.empty {
  opacity: 0.7;
  font-style: italic;
}

.u-block-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text, #f1e8de);
  margin: 0 0 12px 0;
  padding-left: 10px;
  border-left: 3px solid var(--user-accent, #d59148);
  line-height: 1.2;
}

.u-block-empty {
  font-size: 12px;
  color: var(--muted, #b3a89c);
}

/* -------- Header block -------- */
section.u-block-header {
  display: flex;
  gap: 20px;
  align-items: center;
  border-top: 3px solid var(--user-accent);
  padding: 20px;
  background:
    linear-gradient(135deg,
      color-mix(in srgb, var(--user-accent) 12%, transparent) 0%,
      transparent 55%),
    var(--surface, #221d19);
}

.u-header-avatar {
  flex: 0 0 auto;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--surface-2, #2a231e);
  border: 2px solid color-mix(in srgb, var(--user-accent) 55%, transparent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--user-accent) 12%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.u-header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.u-header-avatar-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 600;
  color: var(--muted, #b3a89c);
}

.u-header-meta {
  flex: 1 1 auto;
  min-width: 0;
}
.u-header-name-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 4px;
}
.u-header-name {
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text, #f1e8de);
  margin: 0;
  word-break: break-word;
}
.u-header-slug {
  font-size: 13px;
  color: var(--user-accent, #d59148);
  background: color-mix(in srgb, var(--user-accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--user-accent) 28%, transparent);
  padding: 2px 10px;
  border-radius: 999px;
  font-family: monospace;
}
.u-edit-toggle {
  margin-left: auto;
}
.u-header-bio {
  font-size: 13px;
  color: var(--text, #f1e8de);
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* -------- Bio text block -------- */
.u-block-bio p {
  margin: 0 0 8px 0;
  font-size: 14px;
  color: var(--text, #f1e8de);
  white-space: pre-wrap;
}
.u-block-bio p:last-child { margin-bottom: 0; }

/* -------- Link block -------- */
.u-block-link {
  padding: 0;
  background: transparent;
  border: none;
}
.u-link-btn {
  display: block;
  background: var(--surface, #221d19);
  border: 1px solid var(--border, rgba(255,220,180,0.07));
  border-radius: var(--r-md, 10px);
  padding: 12px 16px;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  color: var(--text, #f1e8de);
  text-decoration: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.u-link-btn:hover {
  border-color: var(--user-accent);
  background: var(--surface-2, #2a231e);
}

/* -------- Image block -------- */
.u-block-image img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--r-md, 10px);
}
.u-image-caption {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted, #b3a89c);
  text-align: center;
}

/* -------- Games / Favorites — reuses the canonical `.my-tile` from
   `modules/screens/my-games.css` (cover, live preview frame, play button,
   rating chip). The `.my-grid` container that wraps them is also defined
   in my-games.css; we don't override anything here. */

/* -------- Comments + ratings blocks -------- */
.u-comment-list, .u-rating-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.u-comment-row, .u-rating-row {
  background: var(--surface-2, #2a231e);
  border: 1px solid var(--border, rgba(255,220,180,0.07));
  border-radius: var(--r-md, 10px);
  padding: 8px 12px;
}
.u-comment-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 12px;
}
.u-comment-meta a {
  color: var(--text, #f1e8de);
  text-decoration: none;
  border-bottom: 1px dashed transparent;
}
.u-comment-meta a:hover { border-bottom-color: var(--warn, #d59148); }
.u-comment-status {
  font-size: 10px;
  color: var(--muted, #b3a89c);
  text-transform: uppercase;
  font-family: monospace;
}
.u-comment-body {
  font-size: 13px;
  color: var(--text, #f1e8de);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.u-rating-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
}
.u-rating-score {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--user-accent);
  color: #1a1612;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.u-rating-game {
  flex: 1 1 auto;
  color: var(--text, #f1e8de);
  text-decoration: none;
  border-bottom: 1px dashed transparent;
}
.u-rating-game:hover { border-bottom-color: var(--warn, #d59148); }

/* -------- Counters -------- */
.u-counter-tiles {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.u-counter-tile {
  flex: 0 0 auto;
  min-width: 100px;
  background: var(--surface-2, #2a231e);
  border: 1px solid var(--border, rgba(255,220,180,0.07));
  border-radius: var(--r-md, 10px);
  padding: 12px 16px;
  text-align: center;
  transition: border-color 0.15s ease;
}
.u-counter-tile:hover {
  border-color: color-mix(in srgb, var(--user-accent) 45%, transparent);
}
.u-counter-tile-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--user-accent, #d59148);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.u-counter-tile-label {
  font-size: 11px;
  color: var(--muted, #b3a89c);
  margin-top: 2px;
}

/* -------- Heading / divider -------- */
.u-block-heading {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 8px 4px 0;
}
.u-heading-text {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text, #f1e8de);
  margin: 0;
}
.u-heading-divider {
  border: none;
  height: 2px;
  margin: 10px 0 0;
  background: linear-gradient(to right, var(--user-accent, #d59148), transparent);
}

/* -------- Quote -------- */
.u-block-quote {
  border-left: 3px solid var(--user-accent, #d59148);
}
.u-quote-body {
  margin: 0;
  font-size: 16px;
  font-style: italic;
  line-height: 1.5;
  color: var(--text, #f1e8de);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.u-quote-author {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted, #b3a89c);
  text-align: right;
}

/* -------- Featured (pinned) game — reuses the canonical .my-tile, centered
   and capped so a single tile reads as a highlight, not a stray grid cell. */
.u-block-featured {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}
.u-featured-wrap .my-tile {
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
}

/* -------- Portfolio stats (audience KPIs) -------- */
.u-portfolio-tiles {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.u-portfolio-tile {
  flex: 1 1 auto;
  min-width: 110px;
  background: var(--surface-2, #2a231e);
  border: 1px solid var(--border, rgba(255,220,180,0.07));
  border-radius: var(--r-md, 10px);
  padding: 14px 16px;
  text-align: center;
  transition: border-color 0.15s ease;
}
.u-portfolio-tile:hover {
  border-color: color-mix(in srgb, var(--user-accent) 45%, transparent);
}
.u-portfolio-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--user-accent, #d59148);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.u-portfolio-label {
  font-size: 11px;
  color: var(--muted, #b3a89c);
  margin-top: 4px;
}

/* -------- Author link on the game page (under preview) -------- */
.game-author-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted, #b3a89c);
  margin-top: 4px;
  margin-bottom: 8px;
}
.game-author-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text, #f1e8de);
  text-decoration: none;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid transparent;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.game-author-link:hover {
  border-color: var(--warn, #d59148);
  background: rgba(213, 145, 72, 0.06);
}
.game-author-avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
  flex: 0 0 auto;
  background: var(--surface-2, #2a231e);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted, #b3a89c);
}
.game-author-name {
  font-size: 12px;
  font-weight: 500;
}

/* -------- Edit mode: per-block controls + settings forms -------- */
.user-page-editing .u-block {
  border-style: dashed;
}

.u-block[data-edit-mode="1"] {
  position: relative;
}

.u-edit-controls {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.u-edit-controls-sep {
  color: var(--muted, #b3a89c);
  opacity: 0.4;
  padding: 0 2px;
}
.u-row-break.active {
  background: var(--user-accent, #d59148);
  border-color: var(--user-accent, #d59148);
  color: #1a1612;
  font-weight: 700;
}

/* ----- Drag-to-resize handle (right edge of each block in edit mode) ----- */
.u-resize-handle {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 14px;
  cursor: col-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(to left, var(--user-accent, #d59148) 0%, transparent 100%);
  opacity: 0.5;
  transition: opacity 0.15s ease;
  touch-action: none;
  z-index: 2;
  border-top-right-radius: var(--r-md, 10px);
  border-bottom-right-radius: var(--r-md, 10px);
}
.u-resize-handle:hover, .u-resizing .u-resize-handle { opacity: 1; }
.u-resize-grip {
  font-size: 10px;
  color: #1a1612;
  font-weight: 700;
  letter-spacing: -1px;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  user-select: none;
  pointer-events: none;
}
.u-size-badge {
  position: absolute;
  bottom: 4px;
  right: 18px;
  background: var(--surface-2, #2a231e);
  border: 1px solid var(--user-accent, #d59148);
  color: var(--text, #f1e8de);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  padding: 1px 6px;
  border-radius: 999px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s ease;
  z-index: 2;
}
.user-page-editing .u-block:hover .u-size-badge,
.u-resizing .u-size-badge { opacity: 1; }
.u-resizing { user-select: none; }

/* Make blocks position:relative so absolute children (handle, badge) anchor
   to them. Already implicit for sections with edit-mode controls, but make
   it explicit for all edit-mode blocks. */
.user-page-editing .u-block { position: relative; padding-right: 22px; }

.u-edit-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 6px;
  background: var(--surface-2, #2a231e);
  border: 1px solid var(--border, rgba(255,220,180,0.07));
  color: var(--text, #f1e8de);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.u-edit-btn:hover {
  border-color: var(--warn, #d59148);
}
.u-edit-btn-danger:hover {
  border-color: #d04848;
  color: #d04848;
}

/* -------- Add-block bar at the bottom -------- */
.u-block-addbar form {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.u-block-addbar select {
  flex: 1 1 auto;
  min-width: 200px;
  background: var(--surface-2, #2a231e);
  border: 1px solid var(--border, rgba(255,220,180,0.07));
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--text, #f1e8de);
  font-size: 13px;
}

/* -------- Settings form (inline under a block) -------- */
.u-settings-form {
  margin-top: 10px;
  padding: 10px;
  background: var(--surface-2, #2a231e);
  border-radius: 6px;
  border: 1px solid var(--border, rgba(255,220,180,0.07));
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.u-form-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.u-form-row-check {
  flex-direction: row;
  align-items: center;
}
.u-form-row > span {
  font-size: 12px;
  color: var(--muted, #b3a89c);
}
.u-form-row input[type=text],
.u-form-row input[type=number],
.u-form-row textarea,
.u-form-row select {
  background: var(--surface, #221d19);
  border: 1px solid var(--border, rgba(255,220,180,0.07));
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--text, #f1e8de);
  font-size: 13px;
  font-family: inherit;
}
.u-form-row textarea { resize: vertical; min-height: 60px; }
.u-form-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.u-form-hint {
  font-size: 11px;
  color: var(--muted, #b3a89c);
  font-style: italic;
}

.u-accent-row { display: flex; gap: 8px; align-items: center; }
.u-accent-row input[type=color] {
  width: 38px;
  height: 32px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
}

/* Range slider + numeric readout used by the width fields */
.u-range-pair {
  display: flex;
  align-items: center;
  gap: 10px;
}
.u-range-pair input[type=range] { flex: 1 1 auto; min-width: 0; }
.u-range-val {
  flex: 0 0 auto;
  min-width: 48px;
  font-size: 12px;
  color: var(--muted, #b3a89c);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* -------- Games picker (checkbox list of all owner's games) -------- */
.u-games-picker {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.u-games-picker > span {
  font-size: 12px;
  color: var(--muted, #b3a89c);
}
.u-games-picker-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 280px;
  overflow-y: auto;
  padding: 6px 8px;
  background: var(--surface, #221d19);
  border: 1px solid var(--border, rgba(255,220,180,0.07));
  border-radius: 6px;
}
.u-games-picker-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 2px;
  font-size: 13px;
  cursor: pointer;
  flex-direction: row;
}
.u-games-picker-row:hover { background: var(--surface-2, #2a231e); }
.u-games-picker-title {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text, #f1e8de);
}
.u-games-picker-status {
  flex: 0 0 auto;
  font-size: 10px;
  color: var(--muted, #b3a89c);
  text-transform: uppercase;
  font-family: monospace;
}

/* -------- Avatar upload (inside the header edit drawer) -------- */
.u-avatar-upload {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
}
.u-avatar-dropzone {
  position: relative;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: var(--surface-2, #2a231e);
  border: 2px dashed var(--border-2, rgba(255,220,180,0.20));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s ease;
  flex: 0 0 auto;
}
.u-avatar-dropzone:hover, .u-avatar-dropzone.drag {
  border-color: var(--user-accent, #d59148);
  border-style: solid;
}
.u-avatar-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}
.u-avatar-placeholder {
  font-size: 36px;
  color: var(--muted, #b3a89c);
  line-height: 1;
}
.u-avatar-hint {
  position: relative;
  z-index: 1;
  font-size: 10px;
  color: var(--muted, #b3a89c);
  text-align: center;
  background: rgba(0,0,0,0.55);
  border-radius: 4px;
  padding: 2px 6px;
  pointer-events: none;
}
.u-avatar-dropzone:has(.u-avatar-preview) .u-avatar-hint {
  opacity: 0;
  transition: opacity 0.15s ease;
}
.u-avatar-dropzone:has(.u-avatar-preview):hover .u-avatar-hint {
  opacity: 1;
}
.u-avatar-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-left: auto;
}

/* Image-block settings — pick-from-library row */
.u-image-block-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.u-image-block-preview {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border, rgba(255,220,180,0.07));
}
.u-image-block-placeholder {
  width: 96px;
  height: 96px;
  border-radius: 8px;
  border: 1px dashed var(--border-2, rgba(255,220,180,0.15));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--muted, #b3a89c);
  font-style: italic;
}
.u-image-block-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 auto;
}

/* -------- Header inline edit (open on details > summary) -------- */
.u-header-edit {
  background: var(--surface, #221d19);
  border: 1px dashed var(--border-2, rgba(255,220,180,0.12));
  border-radius: var(--r-md, 10px);
  padding: 0 14px;
}
.u-header-edit > summary {
  cursor: pointer;
  padding: 10px 0;
  font-size: 13px;
  color: var(--muted, #b3a89c);
  list-style: revert;
}
.u-header-edit[open] > summary {
  border-bottom: 1px dashed var(--border-2, rgba(255,220,180,0.12));
}
.u-header-edit .u-settings-form {
  background: transparent;
  border: none;
  padding: 10px 0;
}

/* -------- Narrow viewports -------- */
@media (max-width: 540px) {
  section.u-block-header { flex-direction: column; align-items: stretch; }
  .u-header-avatar { width: 64px; height: 64px; }
  .u-header-name { font-size: 18px; }
  /* P1 fix: .u-game-card-grid never existed; the real container is .my-grid
     (defined in my-games.css). Override it here for the user profile page. */
  .my-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}

/* ============================================================
   MOBILE ADAPTIVE — user profile page
   ============================================================ */

/* P1 — .u-edit-btn: 44px tap-target on mobile */
@media (max-width: 640px) {
  .u-edit-btn {
    min-width: 44px;
    min-height: 44px;
  }
  /* P1 — .u-drag-handle: touch-action + 44px tap-target */
  .u-drag-handle {
    touch-action: none;
    min-width: 44px;
    min-height: 44px;
    height: auto;
  }
  /* P2 — .u-counter-tile: prevent overflow on very narrow phones */
  .u-counter-tiles {
    gap: 6px;
  }
  .u-counter-tile {
    min-width: 80px;
    overflow: hidden;
  }
  .u-counter-tile-value {
    font-size: 20px;
  }
  /* P2 — .u-block-addbar select: prevent iOS font-size zoom (16px) */
  .u-block-addbar select {
    font-size: 16px;
  }
}

/* P2 — .game-author-link: tappable hit-area on touch devices */
@media (hover: none) {
  .game-author-link {
    padding: 6px 8px;
    min-height: 44px;
    align-items: center;
  }
}

/* P2 — .u-link-btn hover → active-only on touch */
@media (hover: hover) {
  .u-link-btn:hover {
    border-color: var(--user-accent);
    background: var(--surface-2, #2a231e);
  }
  .u-row-empty:hover {
    border-color: var(--user-accent, #d59148);
    color: var(--user-accent, #d59148);
  }
}
