:root {
  --bg: #0f1115;
  --card: #181b22;
  --border: #2a2f3a;
  --text: #e6e8ee;
  --muted: #8b93a7;
  --accent: #7aa2f7;
  --danger: #f7768e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  padding: 24px 32px 8px;
}

h1 { margin: 0 0 4px; }
h2 { margin: 0 0 8px; font-size: 1.1rem; }

.muted { color: var(--muted); font-size: 0.9rem; }

main {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  padding: 16px 32px 48px;
  max-width: 960px;
  margin: 0 auto;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

.row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 8px 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.thumb-wrap {
  margin-top: 12px;
}

.thumb-wrap img, .item img, .palette img, .suggestion img, #preview img {
  max-width: 100%;
  border-radius: 6px;
  display: block;
}

.item, .palette, .suggestion {
  background: #11141a;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.item .tag {
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 999px;
  background: #2a2f3a;
  width: fit-content;
}

.crop-badge {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 999px;
  background: #1f3a2a;
  color: #9be7a3;
  width: fit-content;
}

.attrs {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 4px;
}
.attr-row {
  font-size: 0.75rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
}
.attr-row select {
  flex: 1;
  background: #11141a;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 4px;
  font-size: 0.75rem;
}

.item button, .palette button, button {
  background: var(--accent);
  border: 0;
  color: #0f1115;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }

.item .remove { background: var(--danger); }

.palette.selected {
  outline: 2px solid var(--accent);
}

.palette {
  position: relative;
}

.fit-info {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 4px;
}
.fit-pct {
  font-weight: 600;
  color: var(--text);
}

.palette.best-fit::after {
  content: "★ best fit";
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 0.7rem;
  background: var(--accent);
  color: #0f1115;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}

.swatches {
  display: flex;
  height: 16px;
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.swatches > span { flex: 1; min-width: 4px; }

.palette .swatches { height: 28px; }

.suggestion .pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

/* ----- Skin kind badges & user-skin actions ----- */

.kind-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.kind-official { background: #2a2f3a; color: var(--muted); }
.kind-user { background: #3a2a4a; color: #cdb4dB; }

.palette .user-actions {
  position: absolute;
  bottom: 6px;
  right: 6px;
  display: flex;
  gap: 4px;
}
.palette .user-actions button {
  background: #2a2f3a;
  color: var(--text);
  font-size: 0.7rem;
  padding: 2px 6px;
  font-weight: 400;
}
.palette .user-actions .user-delete { background: var(--danger); color: #0f1115; }

button.secondary { background: #2a2f3a; color: var(--text); }
button.danger { background: var(--danger); }
.hidden { display: none !important; }

/* ----- Manage-my-Skins modal ----- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
  z-index: 100;
  overflow-y: auto;
}
.modal.hidden { display: none; }

.modal-card {
  width: 100%;
  max-width: 720px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}

/* ----- Shared form / factor editor styles (used by admin SPA and the modal) ----- */

.form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}
.form input[type="text"],
.form input[type="number"],
.form textarea,
.form select {
  background: #11141a;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  font: inherit;
}

#factors-container,
#us-factors-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.factor {
  background: #11141a;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  position: relative;
}
.factor h4 {
  margin: 0 0 8px;
  font-size: 0.9rem;
  display: inline-block;
  background: #2a2f3a;
  padding: 2px 8px;
  border-radius: 999px;
}
.factor .remove-factor {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--danger);
  color: #0f1115;
  font-size: 0.75rem;
  padding: 2px 8px;
}

.factor-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 6px;
}
.factor-row > label {
  flex: 1;
  min-width: 120px;
}

.color-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.color-list input[type="color"] {
  width: 40px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #11141a;
}
.color-list .remove-color {
  background: var(--danger);
  color: #0f1115;
  font-size: 0.7rem;
  padding: 1px 4px;
  margin-left: -3px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}
.color-pair {
  display: inline-flex;
  align-items: stretch;
}

.preferred-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.preferred-list label {
  display: inline-flex;
  flex-direction: row !important;
  gap: 4px;
  background: #11141a;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.8rem;
  cursor: pointer;
}
.preferred-list label.checked {
  background: var(--accent);
  color: #0f1115;
  border-color: var(--accent);
}
.preferred-list input { margin: 0; }

/* ----- Pre-upload crop modal (Phase F.4) ----- */

.crop-card {
  max-width: 720px;
}

.crop-stage {
  position: relative;
  width: 100%;
  /* Cropper.js sets the container's aspect via .cropper-container, but we
     reserve some viewport-relative height so the image and frame are usable
     on phones too. */
  max-height: 70vh;
  background: #11141a;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 8px;
}

.crop-stage img#crop-image {
  display: block;
  max-width: 100%;
  /* Cropper takes over once instantiated. The bare <img> is briefly visible
     while the file loads; the line below keeps that flicker neutral. */
  max-height: 70vh;
  margin: 0 auto;
}

#crop-silhouette {
  position: absolute;
  pointer-events: none;
  color: #ffffff;
  opacity: 0.35;
  /* Default position before Cropper signals ready; positionSilhouette()
     overrides on every cropmove. */
  inset: 0;
}

/* ----- F.5 attribute review pane ----- */

.review-grid {
  display: grid;
  grid-template-columns: minmax(160px, 220px) 1fr;
  gap: 16px;
  align-items: start;
  margin-top: 8px;
}

@media (max-width: 540px) {
  .review-grid { grid-template-columns: 1fr; }
}

#review-thumb {
  width: 100%;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #11141a;
}

#review-attrs {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#review-attrs .attr-row {
  font-size: 0.85rem;
  color: var(--muted);
}

#review-attrs .attr-row select {
  background: #11141a;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 6px;
  font: inherit;
}

/* ----- F.5 read-only item card with Edit button ----- */

.item-img-wrap {
  position: relative;
}

.item-img-wrap .crop-badge {
  position: absolute;
  bottom: 6px;
  left: 6px;
}

.item-edit {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(24, 27, 34, 0.85);
  color: var(--text);
  font-size: 0.85rem;
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 400;
  cursor: pointer;
}

.item-edit:hover {
  background: var(--accent);
  color: #0f1115;
}

.attrs-list {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.75rem;
}

.attrs-list li {
  color: var(--text);
}

.attrs-list li strong {
  color: var(--muted);
  font-weight: 500;
  text-transform: capitalize;
}

/* ----- F.6 brush refinement pane ----- */

.refine-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.refine-toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.refine-toolbar input[type="range"] {
  width: 120px;
}

.brush-keep,
.brush-erase {
  background: #2a2f3a;
  color: var(--text);
}
.brush-keep.selected {
  background: var(--accent);
  color: #0f1115;
}
.brush-erase.selected {
  background: var(--danger);
  color: #0f1115;
}

.refine-stage {
  margin-top: 8px;
  background: #11141a;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px;
  display: flex;
  justify-content: center;
}

#refine-canvas {
  display: block;
  max-width: 100%;
  max-height: 65vh;
  cursor: crosshair;
  touch-action: none;  /* prevent scroll while painting on touch */
}

#review-refine {
  margin-top: 8px;
  font-size: 0.8rem;
  padding: 4px 10px;
}

#review-refine[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Phase G: account chip + auth modal ------------------------------------ */
.account-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.account-chip #account-email {
  font-size: 0.75rem;
}

.auth-tab {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 8px 12px;
  cursor: pointer;
  color: var(--muted, #888);
  font-weight: 500;
}

.auth-tab.active {
  color: inherit;
  border-bottom-color: currentColor;
}

#auth-modal .modal-card {
  max-width: 420px;
}

.error {
  color: #c44;
}

/* Phase G.1: Google sign-in button + "or" divider ----------------------- */
.google-button-host {
  display: flex;
  justify-content: center;
  margin: 8px 0;
  min-height: 0;
}

.google-button-host:empty {
  display: none;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
  color: var(--muted, #888);
  font-size: 0.75rem;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: currentColor;
  opacity: 0.3;
}

.auth-divider span {
  padding: 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
