:root {
  --bg: #f4f1ec;
  --surface: #fffdf9;
  --surface-2: #f7f4ee;
  --ink: #2c2925;
  --ink-soft: #6f6a62;
  --line: #e7e1d7;
  --accent: #b08968;
  --accent-deep: #8c6a4e;
  --star: #e0a458;
  --star-off: #d8d2c6;
  --ok: #5b8c5a;
  --shadow: 0 1px 2px rgba(44, 41, 37, .04), 0 8px 28px rgba(44, 41, 37, .07);
  --radius: 18px;
  --radius-sm: 12px;
  --maxw: 1080px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

h1, h2 { margin: 0; font-weight: 800; letter-spacing: -0.01em; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(244, 241, 236, .82);
  backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { font-size: 30px; line-height: 1; }
.brand-text h1 { font-size: 20px; }
.sub { margin: 2px 0 0; font-size: 13px; color: var(--ink-soft); font-weight: 500; }
#progress { color: var(--accent-deep); font-weight: 700; }

.topbar-right { display: flex; align-items: center; gap: 14px; }

.user-switch {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px;
}
.user-switch button {
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  color: var(--ink-soft);
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: all .18s ease;
}
.user-switch button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.save-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  min-width: 96px;
}
.save-status .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--star-off);
  transition: background .2s;
}
.save-status[data-state="saving"] .dot { background: var(--star); animation: pulse 1s infinite; }
.save-status[data-state="saved"] .dot { background: var(--ok); }
.save-status[data-state="error"] .dot { background: #c0584e; }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- Layout ---------- */
.container { max-width: var(--maxw); margin: 0 auto; padding: 26px 20px 80px; }
.intro { color: var(--ink-soft); font-size: 15px; max-width: 68ch; margin: 4px 0 26px; }

.styles { display: flex; flex-direction: column; gap: 26px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

/* ---------- Style card ---------- */
.style-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.style-title { display: flex; align-items: baseline; gap: 12px; }
.style-index {
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  background: var(--accent);
  border-radius: 8px;
  padding: 3px 9px;
  line-height: 1.3;
}
.style-name { font-size: 23px; }
.desc { color: var(--ink-soft); margin: 12px 0 16px; font-size: 15px; max-width: 72ch; }

/* Stars */
.rating { display: flex; align-items: center; gap: 10px; }
.stars { display: inline-flex; gap: 3px; }
.star {
  border: 0; background: none; cursor: pointer; padding: 2px;
  font-size: 26px; line-height: 1; color: var(--star-off);
  transition: transform .1s ease, color .12s ease;
}
.star:hover { transform: scale(1.15); }
.star.on { color: var(--star); }
.score-label { font-size: 13px; font-weight: 700; color: var(--ink-soft); min-width: 26px; }

/* Gallery */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 10px;
}
.tile {
  position: relative;
  border: 0; padding: 0; margin: 0;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
  cursor: zoom-in;
}
.tile img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .35s ease, opacity .3s ease;
}
.tile:hover img { transform: scale(1.05); }
.tile.broken { display: none; }
.gallery-empty {
  grid-column: 1 / -1;
  color: var(--ink-soft);
  font-size: 14px;
  padding: 24px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
}

/* Card footer */
.card-foot { display: flex; gap: 12px; align-items: stretch; margin-top: 16px; flex-wrap: wrap; }
textarea {
  flex: 1 1 280px;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  resize: vertical;
  min-height: 46px;
}
textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

.upload-btn {
  display: inline-flex; align-items: center;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-soft);
  font-weight: 700; font-size: 13px;
  cursor: pointer; white-space: nowrap;
  transition: all .15s;
}
.upload-btn:hover { color: var(--accent-deep); border-color: var(--accent); }

/* Final card */
.final-card { margin-top: 28px; }
.final-card h2 { font-size: 20px; }
.final-hint { color: var(--ink-soft); font-size: 14px; margin: 6px 0 14px; }
.final-card textarea { width: 100%; }

.footer { text-align: center; color: var(--ink-soft); font-size: 13px; margin-top: 32px; }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(28, 25, 22, .92);
  display: flex; align-items: center; justify-content: center;
}
.lightbox[hidden] { display: none; }
.lb-img { max-width: 92vw; max-height: 86vh; border-radius: 10px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.lb-close, .lb-nav {
  position: absolute; border: 0; cursor: pointer;
  color: #fff; background: rgba(255,255,255,.12);
  border-radius: 50%; width: 48px; height: 48px;
  font-size: 26px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.lb-close:hover, .lb-nav:hover { background: rgba(255,255,255,.28); }
.lb-close { top: 18px; right: 18px; font-size: 20px; }
.lb-prev { left: 18px; }
.lb-next { right: 18px; }
.lb-counter { position: absolute; bottom: 22px; color: #fff; font-size: 14px; font-weight: 600; opacity: .85; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .topbar-inner { padding: 10px 14px; }
  .brand-text h1 { font-size: 17px; }
  .save-status { display: none; }
  .container { padding: 18px 14px 60px; }
  .card { padding: 16px; }
  .style-name { font-size: 20px; }
  .gallery { grid-template-columns: repeat(2, 1fr); }
  .lb-nav { width: 42px; height: 42px; }
}
