/* ---------------------------------------------------------------
   Forma — the workshop card catalog
   Visual idea: an old library card catalog / recipe box. Workshops
   are index cards filed in a wooden drawer; saving files a card
   into your own box.
----------------------------------------------------------------*/

:root {
  --font-display: Georgia, 'Iowan Old Style', 'Times New Roman', serif;
  --font-mono: 'Courier New', Courier, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --paper: #f4ecdb;
  --paper-deep: #e9dcc0;
  --card: #fbf6ea;
  --ink: #2b2217;
  --ink-soft: #5b4d3a;
  --ink-faint: #8a7a63;
  --wood: #5c3a24;
  --wood-deep: #432a19;
  --wood-light: #8a5a35;
  --line: #c9b48a;
  --focus-ring: #b3261e;

  --cat-baking: #7a4419;
  --cat-ceramics: #395973;
  --cat-floristry: #3a5c34;
  --cat-painting: #5b3170;

  --radius-card: 6px;
  --shadow-card: 0 3px 8px rgba(43, 34, 23, 0.25), 0 1px 0 rgba(255,255,255,0.4) inset;
  --shadow-lift: 0 12px 24px rgba(43, 34, 23, 0.32), 0 1px 0 rgba(255,255,255,0.4) inset;

  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

html {
  overflow-x: hidden;
}

button,
input,
select {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-mono);
  color: var(--ink);
  background:
    radial-gradient(ellipse at 20% 0%, rgba(255,255,255,0.35), transparent 60%),
    repeating-linear-gradient(0deg, rgba(0,0,0,0.015) 0 2px, transparent 2px 4px),
    var(--paper);
  line-height: 1.5;
}

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

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--ink);
  color: var(--paper);
  padding: 0.75rem 1.25rem;
  z-index: 200;
  font-family: var(--font-mono);
  text-decoration: none;
  border-radius: 0 0 4px 0;
}
.skip-link:focus {
  left: 0;
}

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

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

/* ---------------- Header ---------------- */

.site-header {
  display: flex;
  justify-content: center;
  padding: 2.25rem 1.25rem 1.5rem;
}

.header-plate {
  max-width: 720px;
  text-align: center;
  background: linear-gradient(180deg, var(--wood-light), var(--wood) 60%, var(--wood-deep));
  color: var(--paper);
  padding: 1.75rem 2rem 2rem;
  border-radius: 10px;
  box-shadow: var(--shadow-lift);
  border: 1px solid rgba(0,0,0,0.35);
  position: relative;
}

.header-plate::before,
.header-plate::after {
  content: "";
  position: absolute;
  top: 10px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f0d9a0, #a3762f 70%);
  box-shadow: 0 1px 2px rgba(0,0,0,0.5);
}
.header-plate::before { left: 12px; }
.header-plate::after { right: 12px; }

.plate-eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #e7d3ac;
}

.wordmark {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 6vw, 3.4rem);
  letter-spacing: 0.08em;
  font-weight: 700;
  text-wrap: balance;
}

.tagline {
  margin: 0.65rem auto 0;
  max-width: 46ch;
  font-size: 0.92rem;
  color: #f1e5c8;
}

/* ---------------- Cabinet layout ---------------- */

.cabinet {
  display: flex;
  align-items: flex-start;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.25rem 2rem;
  gap: 0;
}

.tab-rail {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  gap: 0.6rem;
  padding-top: 1.2rem;
  margin-right: -1px;
  position: sticky;
  top: 1rem;
}

.rail-tab {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  background: var(--paper-deep);
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-right: none;
  padding: 0.55rem 1.1rem 0.55rem 0.85rem;
  border-radius: 6px 0 0 6px;
  clip-path: polygon(0 0, 88% 0, 100% 50%, 88% 100%, 0 100%);
  transition: transform 0.15s ease, background 0.15s ease;
  white-space: nowrap;
}

.rail-tab:hover { transform: translateX(3px); }

.rail-tab[aria-current="true"] {
  background: var(--card);
  color: var(--ink);
  font-weight: 700;
  box-shadow: -2px 2px 6px rgba(43,34,23,0.15) inset;
  transform: translateX(4px);
}

.drawer-front {
  flex: 1;
  min-width: 0;
  background: var(--paper-deep);
  border: 1px solid var(--line);
  border-radius: 4px 10px 10px 10px;
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
}

/* ---------------- Controls ---------------- */

.controls {
  display: grid;
  grid-template-columns: 2fr 1fr auto;
  gap: 1rem;
  align-items: end;
  margin-bottom: 0.5rem;
}

.field label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  margin-bottom: 0.35rem;
  font-weight: 700;
}

.field input {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  padding: 0.6rem 0.75rem;
  border: 1px dashed var(--ink-faint);
  background: var(--card);
  color: var(--ink);
  border-radius: 4px;
}

.field input::placeholder {
  color: var(--ink-faint);
}

.field input::-webkit-search-cancel-button {
  cursor: pointer;
}

.select-wrap {
  position: relative;
}

.select-wrap::after {
  content: "▾";
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--ink-soft);
}

.field select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  padding: 0.6rem 2rem 0.6rem 0.75rem;
  border: 1px solid var(--ink-faint);
  background: var(--card);
  color: var(--ink);
  border-radius: 4px;
}

.saved-filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  font-weight: 700;
  background: var(--card);
  border: 1px solid var(--ink-faint);
  color: var(--ink);
  padding: 0.6rem 1rem;
  border-radius: 999px;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.saved-filter-btn:hover { transform: translateY(-1px); }

.saved-filter-btn[aria-pressed="true"] {
  background: var(--wood);
  color: var(--paper);
  border-color: var(--wood-deep);
}

.box-icon { font-size: 1rem; }

.results-count {
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin: 0.75rem 0 1.1rem;
}

/* ---------------- Card grid ---------------- */

.card-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.75rem 1.5rem;
}

.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 0.9rem 1rem 1.1rem 1.6rem;
  transform: rotate(var(--r, 0deg));
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.card:hover,
.card:focus-within {
  transform: rotate(0deg) translateY(-4px);
  box-shadow: var(--shadow-lift);
  z-index: 2;
}

.card-grid > li:nth-child(6n+1) { --r: -1.4deg; }
.card-grid > li:nth-child(6n+2) { --r: 1deg; }
.card-grid > li:nth-child(6n+3) { --r: -0.6deg; }
.card-grid > li:nth-child(6n+4) { --r: 1.6deg; }
.card-grid > li:nth-child(6n+5) { --r: -1.1deg; }
.card-grid > li:nth-child(6n+6) { --r: 0.7deg; }

.punch-holes {
  position: absolute;
  left: 0.45rem;
  top: 1rem;
  bottom: 1rem;
  width: 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
}
.punch-holes::before,
.punch-holes::after {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--paper-deep);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.35);
}

.card-photo {
  position: relative;
  margin: 0 0 0.7rem;
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  transform: rotate(-1deg);
}

.card-photo img {
  width: 100%;
  height: 130px;
  object-fit: cover;
}

.tape {
  position: absolute;
  width: 46px;
  height: 18px;
  background: rgba(255, 245, 210, 0.65);
  border: 1px solid rgba(255,255,255,0.5);
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.tape-a { top: -10px; left: -12px; transform: rotate(-38deg); }
.tape-b { top: -10px; right: -12px; transform: rotate(38deg); }

.tab-flag {
  position: absolute;
  top: -12px;
  right: 10px;
  padding: 0.2rem 0.6rem;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #fff;
  border-radius: 3px 3px 0 0;
}

.card[data-category="Baking"] .tab-flag,
.detail-card[data-category="Baking"] .tab-flag { background: var(--cat-baking); }
.card[data-category="Ceramics"] .tab-flag,
.detail-card[data-category="Ceramics"] .tab-flag { background: var(--cat-ceramics); }
.card[data-category="Floristry"] .tab-flag,
.detail-card[data-category="Floristry"] .tab-flag { background: var(--cat-floristry); }
.card[data-category="Painting"] .tab-flag,
.detail-card[data-category="Painting"] .tab-flag { background: var(--cat-painting); }

.card-kicker {
  margin: 0 0 0.15rem;
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 700;
}

.card-title {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: 1.3rem;
  line-height: 1.2;
  color: var(--ink);
  text-wrap: balance;
  overflow-wrap: break-word;
}

.card-meta {
  margin: 0 0 0.35rem;
  font-size: 0.82rem;
  color: var(--ink-soft);
  overflow-wrap: break-word;
}

.card-price {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  font-weight: 700;
}

.card-price .seats {
  font-weight: 400;
  color: var(--ink-soft);
  margin-left: 0.5rem;
}

.saved-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--wood);
  margin: 0 0 0.5rem;
}

.open-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: transparent;
  border: 1px solid var(--ink);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.4rem 0.85rem;
  border-radius: 4px;
  transition: background 0.15s ease, color 0.15s ease;
}

.open-item:hover {
  background: var(--ink);
  color: var(--paper);
}

/* ---------------- Empty state ---------------- */

.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  border: 2px dashed var(--line);
  border-radius: 8px;
  background: var(--card);
}

.empty-image {
  width: 120px;
  height: 90px;
  object-fit: cover;
  border-radius: 6px;
  margin: 0 auto 1.25rem;
  box-shadow: var(--shadow-card);
  filter: grayscale(0.25) sepia(0.15);
}

.empty-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  margin: 0 0 0.4rem;
  text-wrap: balance;
}

.empty-copy {
  color: var(--ink-soft);
  margin: 0 0 1rem;
}

.reset-btn {
  background: var(--wood);
  color: var(--paper);
  border: none;
  padding: 0.6rem 1.2rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
  transition: background 0.15s ease;
}

.reset-btn:hover {
  background: var(--wood-deep);
}

/* ---------------- Footer ---------------- */

.site-footer {
  text-align: center;
  font-size: 0.75rem;
  color: var(--ink-faint);
  padding: 1rem 1.25rem 2.5rem;
}

/* ---------------- Detail dialog ---------------- */

.catalog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30, 22, 12, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  z-index: 100;
}

.detail-card {
  position: relative;
  background: var(--card);
  width: min(560px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-radius: 8px;
  box-shadow: 0 24px 48px rgba(0,0,0,0.4);
  padding: 0 1.75rem 2rem;
}

.close-detail {
  position: sticky;
  top: 0.75rem;
  float: right;
  margin: 0.75rem 0.25rem 0 0;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  border: 1px solid var(--ink-faint);
  background: var(--card);
  font-size: 1.3rem;
  line-height: 1;
  color: var(--ink);
  z-index: 2;
}

.close-detail:hover { background: var(--ink); color: var(--paper); }

.detail-photo {
  position: relative;
  margin: 0 -1.75rem 1.25rem;
  border-bottom: 1px solid var(--line);
}

.detail-photo img {
  width: 100%;
  height: 220px;
  object-fit: cover;
}

.detail-photo .tape-a { top: -8px; left: 20px; transform: rotate(-20deg); }
.detail-photo .tape-b { top: -8px; right: 20px; transform: rotate(20deg); }

.detail-photo .tab-flag {
  top: auto;
  bottom: -1px;
  right: 1.5rem;
  border-radius: 3px 3px 0 0;
}

.detail-kicker {
  margin: 0 0 0.25rem;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 700;
}

.detail-title {
  margin: 0 0 1rem;
  font-family: var(--font-display);
  font-size: 1.9rem;
  line-height: 1.15;
  text-wrap: balance;
  overflow-wrap: break-word;
}

.detail-stamps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
  margin: 0 0 1.25rem;
  padding: 0;
}

.detail-stamps div {
  border: 2px solid var(--ink-soft);
  border-radius: 4px;
  padding: 0.4rem 0.55rem;
  transform: rotate(-1deg);
}
.detail-stamps div:nth-child(even) { transform: rotate(1deg); }

.detail-stamps dt {
  margin: 0;
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 700;
}

.detail-stamps dd {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink);
}

.detail-body {
  font-family: var(--font-display);
  font-size: 1.05rem;
  line-height: 1.6;
  color: var(--ink);
  margin: 0 0 1.5rem;
  overflow-wrap: break-word;
}

.save-item {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--paper);
  border: 2px solid var(--ink);
  color: var(--ink);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0.65rem 1.3rem;
  border-radius: 999px;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.save-item:hover { transform: translateY(-2px); }

.save-item[aria-pressed="true"] {
  background: var(--focus-ring);
  border-color: var(--focus-ring);
  color: #fff;
}

.save-icon { font-size: 1.1rem; }

/* ---------------- Reduced motion ---------------- */

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .card:hover, .card:focus-within {
    transform: rotate(0deg);
  }
}

/* ---------------- Responsive ---------------- */

@media (max-width: 860px) {
  .controls {
    grid-template-columns: 1fr 1fr;
  }
  .saved-filter-btn {
    grid-column: 1 / -1;
    justify-content: center;
  }
}

@media (max-width: 640px) {
  .cabinet {
    flex-direction: column;
  }
  .tab-rail {
    flex-direction: row;
    overflow-x: auto;
    position: static;
    width: 100%;
    padding: 0 0 0.75rem;
    gap: 0.5rem;
  }
  .rail-tab {
    border-radius: 6px;
    border-right: 1px solid var(--line);
    clip-path: none;
  }
  .rail-tab[aria-current="true"] { transform: none; }
  .drawer-front {
    border-radius: 8px;
  }
  .controls {
    grid-template-columns: 1fr;
  }
  .card-grid {
    grid-template-columns: 1fr;
  }
  .card, .card:hover, .card:focus-within {
    transform: rotate(0deg);
  }
  .catalog-backdrop {
    padding: 0;
  }
  .detail-card {
    width: 100%;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    padding-top: env(safe-area-inset-top);
    padding-bottom: max(2rem, env(safe-area-inset-bottom));
    padding-left: max(1.75rem, env(safe-area-inset-left));
    padding-right: max(1.75rem, env(safe-area-inset-right));
  }
}
