/* ============ Tokens ============ */
:root {
  --font-display: Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "Courier New", Courier, monospace;

  --cork: #8a5a3b;
  --cork-dark: #6e4529;
  --cork-shadow: #4c2f1c;
  --card: #f7efdd;
  --card-edge: #e5d6b4;
  --ink: #2c2117;
  --ink-soft: #5b4a38;
  --rust: #b5502f;
  --rust-dark: #8f3d22;
  --brass: #c8a24d;
  --pin-red: #c0392b;
  --focus: #ffd35c;

  --cat-baking: #8a5a1f;
  --cat-ceramics: #8f4423;
  --cat-floristry: #4f6b34;
  --cat-painting: #2f5770;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 40px;

  --shadow-card: 0 10px 18px -8px rgba(28, 17, 6, 0.55), 0 2px 4px rgba(28, 17, 6, 0.35);
  --shadow-card-hover: 0 16px 26px -10px rgba(28, 17, 6, 0.6), 0 4px 8px rgba(28, 17, 6, 0.4);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background:
    radial-gradient(circle at 8px 8px, rgba(0,0,0,0.10) 1.4px, transparent 1.6px),
    radial-gradient(circle at 26px 22px, rgba(0,0,0,0.08) 1.2px, transparent 1.4px),
    radial-gradient(circle at 18px 40px, rgba(255,255,255,0.05) 1px, transparent 1.2px),
    linear-gradient(160deg, var(--cork) 0%, var(--cork-dark) 55%, var(--cork-shadow) 100%);
  background-size: 34px 34px, 34px 34px, 34px 34px, 100% 100%;
  min-height: 100vh;
}

img { max-width: 100%; display: block; }

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--card);
  color: var(--ink);
  padding: var(--space-2) var(--space-3);
  z-index: 200;
  border-radius: 0 0 6px 0;
}
.skip-link:focus {
  left: 0;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 2px;
}
:focus:not(:focus-visible) {
  outline: none;
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* ============ Hero ============ */
.hero {
  position: relative;
  min-height: 260px;
  display: flex;
  align-items: flex-end;
  background-image: url("assets/studio.jpg");
  background-size: cover;
  background-position: center 60%;
  padding: var(--space-5) var(--space-4) var(--space-4);
  isolation: isolate;
}
.hero__scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(30, 19, 10, 0.55) 0%, rgba(30, 19, 10, 0.85) 100%);
  z-index: 0;
}
.hero__content {
  position: relative;
  z-index: 1;
  color: #fbf3e2;
  max-width: 720px;
}
.hero__eyebrow {
  font-family: var(--font-mono);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.78rem;
  margin: 0 0 var(--space-1);
  color: var(--brass);
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}
.hero__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.6rem, 6vw, 4rem);
  margin: 0 0 var(--space-2);
  text-shadow: 0 3px 0 rgba(0,0,0,0.25);
}
.hero__tag {
  margin: 0;
  font-size: 1.05rem;
  color: #f1e3c8;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}

/* ============ Controls ============ */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--cork-shadow);
  border-bottom: 4px solid var(--cork-dark);
}
.control {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 180px;
}
.control--search { flex: 2 1 260px; }
.control--filter { flex: 1 1 180px; }

.control label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--brass);
}

.control input,
.control select {
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 10px 12px;
  min-height: 44px;
  border-radius: 6px;
  border: 2px solid var(--card-edge);
  background: var(--card);
  color: var(--ink);
}
.control input:focus-visible,
.control select:focus-visible {
  outline-offset: 1px;
}

.apron-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 999px;
  border: 2px solid var(--brass);
  background: transparent;
  color: #fbf3e2;
  font-weight: 600;
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.apron-toggle__icon { width: 20px; height: 20px; }
.apron-toggle__count {
  background: rgba(251, 243, 226, 0.18);
  border-radius: 999px;
  padding: 1px 8px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}
.apron-toggle[aria-pressed="true"] {
  background: var(--brass);
  color: var(--ink);
  border-color: var(--brass);
}
.apron-toggle[aria-pressed="true"] .apron-toggle__count {
  background: rgba(44, 33, 23, 0.15);
}
.apron-toggle:hover { transform: translateY(-1px); }

/* ============ Board ============ */
main { padding: var(--space-5) var(--space-4) var(--space-5); }

.board {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-5) var(--space-4);
  max-width: 1280px;
  margin-inline: auto;
}

.tag-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: 8px;
  box-shadow: var(--shadow-card);
  transform: rotate(var(--rot, 0deg));
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  padding-top: var(--space-3);
}
.tag-card:hover,
.tag-card:focus-within {
  transform: rotate(var(--rot, 0deg)) translateY(-6px);
  box-shadow: var(--shadow-card-hover);
}

.tack {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f0d488, var(--brass) 55%, #8a6a26 100%);
  box-shadow: 0 3px 4px rgba(0,0,0,0.45);
  z-index: 2;
}
.tack--saved {
  background: radial-gradient(circle at 35% 30%, #ef8a7c, var(--pin-red) 55%, #7c231a 100%);
}

.tag-photo {
  margin: 0 var(--space-3);
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 4px;
  border: 1px solid var(--card-edge);
}
.tag-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tag-body { padding: var(--space-3); }

.tag-category {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #fff;
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: var(--space-2);
}
[data-category="Baking"] .tag-category,
#detail-category.cat-baking { background: var(--cat-baking); }
[data-category="Ceramics"] .tag-category,
#detail-category.cat-ceramics { background: var(--cat-ceramics); }
[data-category="Floristry"] .tag-category,
#detail-category.cat-floristry { background: var(--cat-floristry); }
[data-category="Painting"] .tag-category,
#detail-category.cat-painting { background: var(--cat-painting); }

.tag-title {
  font-family: var(--font-display);
  font-size: 1.35rem;
  margin: 0 0 var(--space-2);
  color: var(--ink);
}

.tag-facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-1) var(--space-2);
  margin: 0 0 var(--space-3);
  font-size: 0.88rem;
}
.tag-facts dt {
  font-family: var(--font-mono);
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
}
.tag-facts dd { margin: 0; }

.tag-stub {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: var(--space-3);
  border-top: 2px dashed var(--card-edge);
}
.tag-stub::before,
.tag-stub::after {
  content: "";
  position: absolute;
  top: -8px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--cork);
}
.tag-stub::before { left: -24px; }
.tag-stub::after { right: -24px; }

.price {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--rust-dark);
}

.open-item {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.92rem;
  color: #fff;
  background: var(--rust);
  border: none;
  min-height: 44px;
  padding: 0 var(--space-3);
  border-radius: 6px;
  transition: background-color 0.15s ease;
}
.open-item:hover { background: var(--rust-dark); }

.pinned-badge {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  background: var(--pin-red);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 999px;
  z-index: 2;
}

/* rotations for a hand-pinned feel */
.board li:nth-child(6n+1) { --rot: -2.2deg; }
.board li:nth-child(6n+2) { --rot: 1.6deg; }
.board li:nth-child(6n+3) { --rot: -1deg; }
.board li:nth-child(6n+4) { --rot: 2.4deg; }
.board li:nth-child(6n+5) { --rot: -1.8deg; }
.board li:nth-child(6n+6) { --rot: 1.2deg; }

/* ============ Empty state ============ */
.empty-state {
  max-width: 520px;
  margin: var(--space-5) auto;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: 8px;
  padding: var(--space-4);
  box-shadow: var(--shadow-card);
}
.empty-state p { font-family: var(--font-display); font-size: 1.1rem; margin-top: 0; }
.empty-state button {
  min-height: 44px;
  padding: 0 var(--space-3);
  background: var(--rust);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-weight: 600;
}
.empty-state button:hover { background: var(--rust-dark); }

/* ============ Detail dialog ============ */
dialog#detail-dialog {
  border: none;
  padding: 0;
  background: transparent;
  max-width: min(560px, 92vw);
  width: 100%;
  max-height: 88vh;
  overflow: visible;
}
dialog#detail-dialog::backdrop {
  background: rgba(20, 12, 6, 0.72);
}
dialog#detail-dialog[open] {
  animation: pop-in 0.18s ease-out;
}
@keyframes pop-in {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.tag-card--detail {
  --rot: -0.6deg;
  max-height: 88vh;
  overflow-y: auto;
  padding-bottom: var(--space-4);
}
.tag-card--detail .tag-photo { margin-top: var(--space-2); }

.close-detail {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  z-index: 3;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(44, 33, 23, 0.08);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
}
.close-detail:hover { background: rgba(44, 33, 23, 0.18); }
.close-detail svg { width: 18px; height: 18px; }

.detail-instructor {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin: 0 0 var(--space-3);
}
.detail-facts {
  grid-template-columns: 1fr 1fr 1fr;
}
.detail-body {
  font-size: 1rem;
  line-height: 1.6;
  margin: 0 0 var(--space-4);
}

.save-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  width: 100%;
  justify-content: center;
  padding: 0 var(--space-3);
  border-radius: 6px;
  border: 2px solid var(--rust);
  background: transparent;
  color: var(--rust-dark);
  font-weight: 700;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.save-toggle__icon { width: 18px; height: 18px; }
.save-toggle[aria-pressed="true"] {
  background: var(--rust);
  color: #fff;
}

/* ============ Responsive ============ */
@media (max-width: 640px) {
  .hero { min-height: 220px; padding: var(--space-4) var(--space-3); }
  .controls { padding: var(--space-3); flex-direction: column; align-items: stretch; }
  .control { min-width: 0; }
  .apron-toggle { justify-content: center; }
  main { padding: var(--space-4) var(--space-3); }
  .board { grid-template-columns: 1fr; gap: var(--space-5) 0; }
  .tag-card { transform: none; }
  .tag-card:hover, .tag-card:focus-within { transform: translateY(-4px); }
  .detail-facts { grid-template-columns: 1fr 1fr; }
}

/* ============ Reduced motion ============ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
