* {
  box-sizing: border-box;
}

:root {
  --bg: #f6f1e8;
  --paper: #fffdf8;
  --ink: #111111;
  --muted: #6f675d;
  --soft-muted: #9d9182;
  --line: #e2d4bf;
  --line-dark: #c9b79c;
  --soft: #efe4d2;
  --soft-2: #fbf5ea;
  --beige: #eadcc7;
  --beige-light: #f8efe1;
  --beige-deep: #d5bea0;
  --danger: #8a1515;
  --shadow: 0 18px 45px rgba(77,55,30,0.055);
  --shadow-soft: 0 10px 26px rgba(77,55,30,0.04);
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top right, rgba(181,140,91,0.16), transparent 28%),
    radial-gradient(circle at 10% 8%, rgba(234,220,199,0.55), transparent 24%),
    linear-gradient(180deg, #fffaf2 0%, var(--bg) 100%);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

.site-header,
main {
  width: min(1160px, calc(100% - 32px));
  margin: 0 auto;
}

.site-header {
  padding: 20px 0 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 36px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  color: #fff;
  background: var(--ink);
  font-size: 0.78rem;
}

.primary-pill,
.ghost-pill,
.icon-btn {
  border: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 15px;
  transition: 0.18s ease;
}

.primary-pill {
  background: var(--ink);
  color: #fff;
}

.primary-pill:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(92,63,31,0.16);
}

.ghost-pill:hover,
.icon-btn:hover {
  background: var(--beige-light);
}

.ghost-pill.danger {
  color: var(--danger);
  border-color: rgba(138,21,21,0.32);
}

.icon-btn {
  width: 42px;
  height: 42px;
  padding: 0;
  font-size: 1.4rem;
  line-height: 1;
}

.intro {
  border-bottom: 1px solid var(--line);
  padding-bottom: 24px;
  background:
    linear-gradient(90deg, rgba(234,220,199,0.34), transparent 64%);
  border-radius: 0 0 28px 28px;
}

.overline {
  margin: 0 0 9px;
  color: var(--soft-muted);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: clamp(2.35rem, 6.4vw, 4.7rem);
  line-height: 0.95;
  letter-spacing: -0.065em;
}

h2 {
  margin-bottom: 6px;
  font-size: clamp(1.45rem, 3vw, 2.1rem);
  line-height: 1;
  letter-spacing: -0.045em;
}

h3 {
  margin-bottom: 0;
}

.mini-stats {
  margin: 0;
  color: var(--muted);
  font-size: 0.98rem;
}

.catalog-tools {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 18px;
  align-items: end;
  padding: 22px 0 18px;
}

.search-wrap label,
.sort-wrap span,
.field label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 700;
}

.search-wrap input,
.sort-wrap select,
.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255,253,248,0.92);
  color: var(--ink);
  border-radius: 16px;
  padding: 13px 14px;
  outline: none;
  transition: 0.18s ease;
}

.search-wrap input:focus,
.sort-wrap select:focus,
.field input:focus,
.field select:focus,
.field textarea:focus {
  background: #fffdf8;
  border-color: var(--ink);
  box-shadow: 0 0 0 4px rgba(213,190,160,0.34);
}

.tool-row {
  display: flex;
  gap: 10px;
  align-items: end;
  justify-content: flex-end;
}

.sort-wrap {
  min-width: 170px;
}

.filters {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding-top: 2px;
}

.filter {
  border: 0;
  background: transparent;
  padding: 7px 0;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}

.filter:hover,
.filter.active {
  color: var(--ink);
  border-bottom-color: var(--beige-deep);
}

.catalog-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 30px;
}

.catalog-grid.compact {
  grid-template-columns: 1fr;
  gap: 10px;
}

.card {
  background:
    linear-gradient(180deg, rgba(255,253,248,0.96), rgba(255,250,242,0.9));
  border: 1px solid var(--line);
  border-radius: 28px;
  overflow: hidden;
  box-shadow: var(--shadow);
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.card-image {
  position: relative;
  height: 260px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 35% 22%, rgba(255,255,255,0.82), transparent 28%),
    radial-gradient(circle at 78% 78%, rgba(213,190,160,0.36), transparent 30%),
    linear-gradient(145deg, #f7eddd 0%, #eadcc7 100%);
}

.card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.yarn-placeholder {
  display: grid;
  place-items: center;
  gap: 9px;
  color: var(--muted);
  text-align: center;
}

.yarn-icon {
  width: 86px;
  height: 86px;
  border: 1px solid var(--line-dark);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255,250,242,0.86);
}

.yarn-icon svg {
  width: 46px;
  height: 46px;
}

.yarn-placeholder span {
  font-size: 0.86rem;
}

.status {
  position: absolute;
  left: 14px;
  top: 14px;
  border-radius: 999px;
  padding: 7px 10px;
  background: rgba(255,253,248,0.92);
  color: var(--ink);
  border: 1px solid rgba(0,0,0,0.12);
  font-size: 0.74rem;
  font-weight: 800;
  backdrop-filter: blur(10px);
}

.favorite-btn {
  position: absolute;
  right: 14px;
  top: 14px;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 50%;
  background: rgba(255,253,248,0.92);
  color: var(--ink);
  font-size: 1rem;
  line-height: 1;
  backdrop-filter: blur(10px);
}

.favorite-btn.is-favorite {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}

.card-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 13px;
  flex: 1;
}

.card-main {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.card h3 {
  font-size: 1.2rem;
  line-height: 1.1;
  letter-spacing: -0.035em;
}

.card-meta {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.94rem;
}

.rating {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 9px;
  background: var(--beige-light);
  font-weight: 800;
  font-size: 0.88rem;
}

.color-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.color-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 8px;
  background: var(--beige-light);
  color: #3a332b;
  font-size: 0.8rem;
}

.color-dot {
  width: 12px;
  height: 12px;
  border: 1px solid rgba(0,0,0,0.18);
  border-radius: 50%;
  background: #d9c5aa;
}

.details-card {
  margin-top: auto;
  border-top: 1px solid var(--line);
  padding-top: 2px;
}

.details-card summary,
.backup-panel summary,
.form-block summary {
  list-style: none;
  cursor: pointer;
  font-weight: 800;
}

.details-card summary::-webkit-details-marker,
.backup-panel summary::-webkit-details-marker,
.form-block summary::-webkit-details-marker {
  display: none;
}

.details-card summary {
  padding: 12px 0 0;
  color: var(--ink);
}

.details-card summary::after,
.backup-panel summary::after,
.form-block summary::after {
  content: "+";
  float: right;
}

.details-card[open] summary::after,
.backup-panel[open] summary::after,
.form-block[open] summary::after {
  content: "−";
}

.details-content {
  display: grid;
  gap: 14px;
  padding-top: 14px;
}

.detail-group {
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    linear-gradient(180deg, var(--beige-light), #fffaf2);
  padding: 13px;
}

.detail-group h4 {
  margin: 0 0 9px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--soft-muted);
}

.detail-list {
  display: grid;
  gap: 7px;
  color: #333;
  line-height: 1.45;
}

.detail-list p {
  margin: 0;
}

.detail-list strong {
  color: var(--ink);
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.card-actions a,
.card-actions button {
  flex: 1;
  min-width: 88px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
  text-align: center;
  text-decoration: none;
  transition: 0.18s ease;
}

.card-actions a:hover,
.card-actions button:hover {
  background: var(--ink);
  color: #fff;
}

.card-actions .delete {
  border-color: var(--line);
  color: var(--muted);
}

.card-actions .delete:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

/* Vista compacta */
.catalog-grid.compact .card {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  border-radius: 22px;
}

.catalog-grid.compact .card-image {
  height: auto;
  min-height: 96px;
}

.catalog-grid.compact .status,
.catalog-grid.compact .favorite-btn,
.catalog-grid.compact .color-chips,
.catalog-grid.compact .details-content {
  display: none;
}

.catalog-grid.compact .card-body {
  padding: 15px;
  gap: 7px;
}

.catalog-grid.compact .details-card {
  border-top: 0;
}

.catalog-grid.compact .details-card summary {
  padding-top: 4px;
  color: var(--muted);
}

.empty-state,
.form-panel,
.backup-panel {
  border: 1px solid var(--line);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255,253,248,0.94), rgba(255,249,239,0.9));
  box-shadow: var(--shadow-soft);
}

.empty-state {
  text-align: center;
  padding: 34px;
  margin-bottom: 30px;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
}

.form-panel {
  padding: 22px;
  margin-bottom: 30px;
}

.form-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.form-note {
  max-width: 560px;
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.autosave-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: min(100%, 520px);
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--beige-light);
  padding: 13px 14px;
  margin-bottom: 18px;
}

.autosave-row strong,
.autosave-row span {
  display: block;
}

.autosave-row span {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 3px;
}

.switch {
  position: relative;
  display: inline-flex;
  width: 48px;
  height: 28px;
}

.switch input {
  width: 0;
  height: 0;
  opacity: 0;
}

.switch span {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background: #d7d4ca;
  border-radius: 999px;
  transition: 0.2s ease;
}

.switch span::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 22px;
  height: 22px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s ease;
  box-shadow: 0 2px 7px rgba(0,0,0,0.2);
}

.switch input:checked + span {
  background: var(--ink);
}

.switch input:checked + span::before {
  transform: translateX(20px);
}

.yarn-form {
  display: grid;
  gap: 12px;
}

.form-block {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255,250,242,0.78);
  padding: 0;
}

.form-block summary {
  padding: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 15px;
  padding: 0 16px 16px;
}

.field.wide {
  grid-column: 1 / -1;
}

.check-card {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 13px 14px;
  background: var(--beige-light);
  align-self: end;
  min-height: 48px;
  color: #333;
}

.check-card input {
  width: 18px;
  height: 18px;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  padding-top: 6px;
}

.backup-panel {
  padding: 0;
  margin-bottom: 42px;
}

.backup-panel summary {
  padding: 18px 20px;
}

.backup-content {
  border-top: 1px solid var(--line);
  padding: 18px 20px 20px;
}

.backup-content p {
  margin: 0 0 14px;
  color: var(--muted);
}

.backup-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.file-btn {
  position: relative;
  overflow: hidden;
  display: inline-flex;
}

.file-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

footer {
  text-align: center;
  color: var(--muted);
  padding: 0 16px 42px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #fff;
  border-radius: 999px;
  padding: 12px 16px;
  box-shadow: 0 14px 36px rgba(0,0,0,0.22);
  opacity: 0;
  pointer-events: none;
  transition: 0.22s ease;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 980px) {
  .catalog-tools,
  .catalog-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .tool-row {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .sort-wrap {
    flex: 1;
    min-width: 180px;
  }
}

@media (max-width: 620px) {
  .site-header,
  main {
    width: min(100% - 22px, 1160px);
  }

  .topbar {
    margin-bottom: 30px;
  }

  .brand span:last-child {
    font-size: 0.94rem;
  }

  h1 {
    font-size: clamp(2.25rem, 14vw, 3.25rem);
  }

  .primary-pill,
  .ghost-pill {
    padding: 9px 12px;
  }

  .catalog-tools {
    padding: 18px 0;
  }

  .card-image {
    height: 230px;
  }

  .empty-state,
  .form-panel,
  .backup-panel,
  .card {
    border-radius: 22px;
  }

  .form-panel {
    padding: 16px;
  }

  .catalog-grid.compact .card {
    grid-template-columns: 82px minmax(0, 1fr);
  }

  .toast {
    width: calc(100% - 28px);
    text-align: center;
  }
}
