:root {
  --ink: #12161a;
  --ink-soft: #58616b;
  --paper: #f5f5f2;
  --card: #ffffff;
  --line: #d9dcdf;
  --accent: #1f8f3a;
  --accent-ink: #ffffff;
  --alien: #6ee05a;
  --danger: #b3261e;
  --stage-a: #eef0f1;
  --stage-b: #c6cace;
  --radius: 12px;
  --header-h: 52px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background: var(--paper);
  line-height: 1.4;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}
.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 10;
  padding: 10px 14px; border-radius: 8px; background: var(--ink); color: #fff;
}
.skip-link:focus { top: 8px; }

/* ---------- Header ---------- */
.site-header {
  flex: none; overflow: hidden;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: var(--header-h);
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: var(--ink); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-weight: 800; font-size: 1.1rem; letter-spacing: 0.01em; }
.brand img { display: block; flex: none; height: 22px; width: auto; max-height: calc(var(--header-h) - 24px); }
.brand-name { padding-left: 12px; border-left: 1.5px solid rgb(255 255 255 / 0.35); white-space: nowrap; }
.tagline { margin: 0; color: var(--alien); font-size: 1.05rem; font-weight: 700; white-space: nowrap; }

.header-right { display: flex; align-items: center; gap: 18px; min-width: 0; }
.nav-link {
  flex: none; padding: 6px 13px; border: 1.5px solid rgb(255 255 255 / 0.35); border-radius: 999px;
  color: #fff; font-size: 0.875rem; font-weight: 650; text-decoration: none; white-space: nowrap;
}
.nav-link:hover { border-color: var(--alien); color: var(--alien); }

/* Owner-only strip (appears after logging in to the admin page) */
.admin-bar {
  flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  padding: 8px 16px; background: #fff3cd; border-bottom: 1px solid #e6c65c; font-size: 0.9rem;
}
.admin-bar .button, .admin-bar .button.primary { flex: none; min-height: 34px; }
.admin-tag { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.75rem; }
.admin-year { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.admin-year input { width: 5.5rem; min-height: 34px; padding: 4px 8px; font-size: 1rem; border: 1.5px solid var(--line); border-radius: 8px; background: #fff; }

.review-banner { flex: none; margin: 0; padding: 6px 16px; background: #ffe08a; font-size: 0.85rem; text-align: center; }
.noscript { padding: 24px; text-align: center; }

/* ---------- Layout ---------- */
.customizer {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(360px, 32vw, 560px);
}

.stage {
  position: relative; min-width: 0; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  padding: clamp(8px, 2vw, 28px);
  background: radial-gradient(circle at 50% 42%, var(--stage-a), var(--stage-b));
}
#beanie {
  display: block;
  max-width: 100%; max-height: 100%;
  width: auto; height: auto;
  opacity: 0; transition: opacity 0.25s;
  filter: drop-shadow(0 18px 22px rgb(0 0 0 / 0.22));
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
#beanie.ready { opacity: 1; }
#beanie.can-select { cursor: pointer; }

.hover-label {
  position: absolute; z-index: 2; pointer-events: none;
  transform: translate(14px, 18px);
  padding: 5px 10px; border-radius: 999px;
  background: var(--ink); color: #fff; font-size: 0.85rem; font-weight: 600; white-space: nowrap;
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.25);
}
.official {
  position: absolute; top: clamp(8px, 2vw, 20px); left: 10px; right: 10px; z-index: 2;
  width: fit-content; max-width: calc(100% - 20px); margin: 0 auto; padding: 7px 14px 7px 8px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 6px;
  background: var(--ink); color: #fff; border-radius: 18px; font-size: 0.9rem; text-align: center;
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.28);
  pointer-events: none; /* never gets in the way of clicking the beanie */
}
.official strong { color: var(--alien); }
.official-badge {
  padding: 2px 9px; border-radius: 999px; background: var(--alien); color: var(--ink);
  font-size: 0.72rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase;
}
.official.pop { animation: official-pop 0.45s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes official-pop { from { transform: translateY(-10px) scale(0.92); opacity: 0; } }
.stage-status { position: absolute; margin: 0; color: var(--ink-soft); }
.stage-status.failed { display: grid; justify-items: center; gap: 12px; padding: 16px; text-align: center; color: var(--ink); }

.panel {
  min-height: 0; overflow: hidden; /* only the colour list scrolls */
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px 20px;
  background: var(--card);
  border-left: 1px solid var(--line);
}

/* ---------- Section buttons ---------- */
.sections { flex: none; display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: 8px; }
.name-field, .actions, .status { flex: none; }
.section-button {
  display: flex; align-items: center; gap: 12px;
  min-width: 0; min-height: 48px; padding: 6px 10px;
  text-align: left;
  background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius);
}
.section-button:hover { border-color: var(--ink-soft); }
.section-button[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.chip-color {
  flex: none; width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid rgb(0 0 0 / 0.25);
}
.chip-color.empty, .swatch-color.empty {
  background: repeating-linear-gradient(45deg, #e9ebed 0 6px, #cfd3d7 6px 12px);
}
.section-labels { display: flex; flex-direction: column; min-width: 0; }
.section-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-value { color: var(--ink-soft); font-size: 0.875rem; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Palette ---------- */
.palette {
  flex: 1 1 0; min-height: 0; overflow: hidden;
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px 14px 0; border: 1.5px solid var(--line); border-radius: var(--radius);
  background: #fafaf8;
}
.palette-scroll {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 10px;
  margin: 0 -6px; padding: 3px 6px 14px;
}
.palette-scroll > * { flex: none; }
.palette-head { flex: none; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.palette-head > div { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 12px; min-width: 0; }
.palette-head { align-items: center; }
.palette-head h2 { margin: 0; font-size: 1.1rem; }
.palette-current { margin: 0; color: var(--ink-soft); font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.icon-button {
  flex: none; display: grid; place-items: center; width: 36px; height: 36px;
  background: transparent; border: 1.5px solid var(--line); border-radius: 50%;
}
.icon-button:hover { background: #eceeef; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: #e7e9eb; border-radius: 10px; }
.segment { min-height: 40px; border: 0; border-radius: 7px; background: transparent; font-weight: 600; }
.segment[aria-pressed="true"] { background: var(--card); box-shadow: 0 1px 3px rgb(0 0 0 / 0.2); }

.yarn-tools { display: grid; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px; }
.chip {
  flex: none; min-height: 30px; padding: 2px 11px;
  background: var(--card); border: 1.5px solid var(--line); border-radius: 999px; font-size: 0.875rem;
}
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }

.palette-note { margin: 0; padding: 10px 12px; background: #eef0f1; border-radius: 10px; color: var(--ink-soft); font-size: 0.9rem; }

.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 8px; }
.swatches.named { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.swatches:empty { display: none; }
.swatch {
  position: relative;
  display: flex; flex-direction: column; align-items: stretch; gap: 3px;
  padding: 4px 4px 3px;
  background: var(--card); border: 1.5px solid var(--line); border-radius: 10px;
}
.swatch:hover { border-color: var(--ink-soft); }
.swatch[aria-selected="true"] { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink); }
.swatch-color { display: block; height: 34px; border-radius: 6px; border: 1px solid rgb(0 0 0 / 0.18); }
.swatch-color.knit { background-image: url("../assets/knit.svg"); background-size: 13.33px 10.67px; }
.swatch-code { font-size: 0.8125rem; font-weight: 650; text-align: center; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.swatch-name { font-size: 0.75rem; color: var(--ink-soft); text-align: center; }
.swatch-flag { font-size: 0.6875rem; text-align: center; color: #7a4b00; background: #ffe08a; border-radius: 4px; }

/* ---------- Design name + actions ---------- */
.name-field { display: grid; gap: 6px; }
.name-field label { font-weight: 650; }
.required { color: var(--ink-soft); font-weight: 400; font-size: 0.875rem; }
#design-name {
  width: 100%; min-height: 46px; padding: 8px 12px; font-size: 1rem;
  background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius);
}
#design-name[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 2px var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }
.button {
  display: inline-flex; align-items: center; justify-content: center;
  flex: 1 1 auto; min-height: 36px; padding: 4px 10px;
  background: var(--card); border: 1.5px solid var(--line); border-radius: 10px;
  color: var(--ink); font-size: 0.85rem; white-space: nowrap; font-weight: 650; text-decoration: none; text-align: center;
}
.button:hover { border-color: var(--ink-soft); }
.button.primary { flex-grow: 3; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.button.primary:hover { filter: brightness(1.08); }
.button.danger { color: var(--danger); }
.status { margin: 0; min-height: 1.3em; color: var(--ink-soft); font-size: 0.9rem; overflow-wrap: anywhere; }
.hint { margin: 0; color: var(--ink-soft); font-size: 0.875rem; }
.about-link { flex: none; margin: 0; font-size: 0.8rem; text-align: center; color: var(--ink-soft); }
.about-link a { color: var(--ink-soft); }
.about-link a:hover { color: var(--accent); }

/* ---------- Phones and small tablets ----------
   Beanie on top, parts in a swipeable row, colours in a bottom sheet.
   The beanie always stays visible above the sheet. */
@media (max-width: 899px) {
  :root { --header-h: 46px; }
  .tagline { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .wide-only { display: none; }
  .official { top: 6px; padding: 5px 12px 5px 6px; font-size: 0.8rem; border-radius: 14px; }
  .nav-link { padding: 5px 11px; }
  .hint { display: none; }
  .brand { gap: 8px; font-size: 1rem; }
  .brand img { height: 18px; }
  .brand-name { padding-left: 8px; }
  .customizer { display: flex; flex-direction: column; }
  .stage { flex: 1 1 0; min-height: 150px; padding: 8px; }

  .panel {
    flex: none; overflow: visible; gap: 8px;
    padding: 8px 0 max(8px, env(safe-area-inset-bottom));
    border-left: 0; border-top: 1px solid var(--line);
  }
  .sections { display: flex; gap: 8px; overflow-x: auto; padding: 2px 12px 4px; scrollbar-width: none; scroll-padding: 12px; }
  .sections::-webkit-scrollbar { display: none; }
  .section-button { flex: none; min-height: 48px; padding: 6px 12px 6px 8px; gap: 8px; border-radius: 999px; }
  .chip-color { width: 30px; height: 30px; border-radius: 50%; }
  .section-name { font-size: 0.875rem; line-height: 1.15; }
  .section-value { font-size: 0.75rem; max-width: 9.5rem; }

  .palette {
    flex: none; height: 40dvh;
    margin: 0; padding: 10px 12px 0;
    border: 0; border-top: 1.5px solid var(--line); border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 24px rgb(0 0 0 / 0.12);
    animation: sheet-up 0.22s ease-out;
  }
  .palette-head h2 { font-size: 1rem; }
  .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { min-height: 34px; }

  .name-field { margin: 0; padding: 0 12px; gap: 3px; }
  .name-field label { font-size: 0.875rem; }
  #design-name { min-height: 44px; }

  .actions { display: flex; flex-wrap: nowrap; overflow-x: auto; padding: 0 12px; margin-top: 0; scrollbar-width: none; }
  .actions::-webkit-scrollbar { display: none; }
  .button { flex: none; min-height: 44px; white-space: nowrap; }
  .status { padding: 0 12px; min-height: 0; }
  .status:empty { display: none; }

  /* While the colour sheet is open the name box steps aside; the send buttons stay put. */
  .palette-open .name-field, .palette-open .about-link { display: none; }
  .about-link { padding: 0 12px; }
}

/* Short landscape phones: put the beanie beside the controls instead of above. */
@media (max-width: 899px) and (max-height: 480px) and (orientation: landscape) {
  .customizer { flex-direction: row; }
  .stage { flex: 1 1 40%; }
  .panel { flex: 1 1 60%; min-width: 0; overflow-y: auto; border-top: 0; border-left: 1px solid var(--line); }
  .palette { height: auto; flex: 1 0 260px; }
}

@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Short desktop windows (small laptops): tighten the controls so the colours keep their room. */
@media (min-width: 900px) and (max-height: 800px) {
  .hint { display: none; }
  .panel { gap: 10px; padding: 12px 20px; }
  .sections { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .button { padding: 4px 8px; font-size: 0.8rem; }
  .section-button { gap: 8px; min-height: 44px; padding: 4px 8px; }
  .chip-color { width: 26px; height: 26px; }
  .section-name { font-size: 0.875rem; }
  .section-value { font-size: 0.75rem; }
  .chip { min-height: 26px; font-size: 0.8125rem; }
  .swatches { gap: 6px; }
  .swatch-color { height: 26px; }
}

/* ---------- Submit dialog ---------- */
.dialog {
  width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow-y: auto;
  padding: 22px; border: 0; border-radius: 16px; background: var(--card); color: var(--ink);
  box-shadow: 0 24px 60px rgb(0 0 0 / 0.35);
}
.dialog::backdrop { background: rgb(10 14 18 / 0.6); }
.dialog form, .dialog-done { display: grid; gap: 8px; }
.dialog h2 { margin: 0; font-size: 1.3rem; }
.dialog-lede, .dialog-note, .dialog-done p { margin: 0; color: var(--ink-soft); font-size: 0.9rem; }
.dialog label { margin-top: 6px; font-weight: 650; font-size: 0.9rem; }
.dialog input {
  width: 100%; min-height: 46px; padding: 8px 12px; font-size: 1rem;
  background: var(--card); border: 1.5px solid var(--line); border-radius: 10px;
}
.dialog-status { margin: 0; min-height: 1.3em; font-size: 0.9rem; font-weight: 600; }
.dialog-actions { display: flex; gap: 8px; margin-top: 6px; }
.dialog-actions .button { min-height: 44px; }
.button:disabled { opacity: 0.6; cursor: default; }
.spec-list { list-style: none; margin: 4px 0; padding: 10px 12px; display: grid; gap: 5px; background: #f3f4f2; border-radius: 10px; font-size: 0.85rem; }
.spec-list li { display: flex; align-items: center; gap: 8px; }
.dot {
  flex: none; width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgb(0 0 0 / 0.3);
  background: repeating-linear-gradient(45deg, #e9ebed 0 4px, #cfd3d7 4px 8px);
}
.dot.filled { background-image: none; }
.spec-name { color: var(--ink-soft); }
.spec-value { margin-left: auto; font-weight: 650; font-variant-numeric: tabular-nums; text-align: right; }
/* Spam trap field: moved far off screen so only bots fill it in. */
.hp { position: absolute; left: -9999px; top: auto; width: 1px; height: 1px; overflow: hidden; }

.dialog .check { display: flex; align-items: flex-start; gap: 10px; margin-top: 8px; font-weight: 400; font-size: 0.875rem; line-height: 1.35; cursor: pointer; }
.dialog .check input { flex: none; width: 22px; min-height: 22px; height: 22px; margin: 1px 0 0; padding: 0; accent-color: var(--accent); }

/* ---------- Share menu (pops up above the Share button) ---------- */
.share-menu {
  position: fixed; z-index: 20; width: min(240px, calc(100vw - 16px));
  display: grid; gap: 2px; padding: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 16px 40px rgb(0 0 0 / 0.28);
  animation: share-up 0.16s ease-out;
}
@keyframes share-up { from { transform: translateY(8px); opacity: 0; } }
.share-title { margin: 2px 8px 6px; color: var(--ink-soft); font-size: 0.8rem; font-weight: 650; }
.share-item {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 6px 8px;
  background: transparent; border: 0; border-radius: 9px;
  color: var(--ink); font-size: 0.95rem; font-weight: 600; text-align: left; text-decoration: none;
}
.share-item:hover, .share-item:focus-visible { background: #eef0f1; }
.share-badge {
  flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%;
  background: var(--ink); color: #fff; font-size: 0.8rem; font-weight: 800;
}
.share-badge.facebook { background: #1877f2; }
.share-badge.whatsapp { background: #128c4b; }
.share-badge.pinterest { background: #bd081c; }
.share-badge.reddit { background: #d93a00; }
.share-badge.instagram { background: linear-gradient(45deg, #f09433, #dc2743 50%, #bc1888); font-size: 0.7rem; }
.share-badge.save, .share-badge.copy { background: #e7e9eb; color: var(--ink); font-size: 1rem; }
