:root {
  --ink: #2b2350;
  --paper: #fff8e7;
  --card: #ffffff;
  --pink: #ff6fa5;
  --yellow: #ffd93d;
  --blue: #4aa3ff;
  --green: #4cd37b;
  --purple: #a46bff;
  --shadow: 5px 5px 0 var(--ink);
}
@media (prefers-color-scheme: dark) {
  :root { --paper: #231c45; --card: #342b66; --ink: #fff8e7; --shadow: 5px 5px 0 #0f0a26; }
  .bead-outline { stroke: #0f0a26; }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--paper);
  background-image: radial-gradient(circle, rgba(164,107,255,.18) 3px, transparent 3.5px);
  background-size: 34px 34px;
  color: var(--ink);
  font-family: 'Patrick Hand', 'Comic Sans MS', cursive;
  font-size: 1.2rem;
  line-height: 1.5;
}
h1, h2, h3, .logo, nav a, .btn, .pill {
  font-family: 'Baloo 2', 'Comic Sans MS', cursive;
}
h1 { font-size: clamp(2rem, 6vw, 3.4rem); line-height: 1.1; margin: .2em 0; font-weight: 800; }
h2 { font-size: 1.8rem; margin: 1.2em 0 .4em; }
h3 { font-size: 1.3rem; margin: 0 0 .2em; }
a { color: inherit; }

.top {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 16px; max-width: 1000px; margin: 0 auto;
}
.logo { display: flex; align-items: center; gap: 8px; font-size: 1.7rem; font-weight: 800; text-decoration: none; }
nav { display: flex; gap: 8px; flex-wrap: wrap; }
nav a {
  text-decoration: none; font-weight: 700; padding: 6px 16px;
  border: 3px solid var(--ink); border-radius: 999px; background: var(--card);
  transition: transform .15s;
}
nav a:hover { transform: rotate(-3deg) scale(1.06); }
nav a.active { background: var(--yellow); color: #2b2350; }

main { max-width: 1000px; margin: 0 auto; padding: 8px 16px 40px; }
footer { text-align: center; padding: 20px; opacity: .7; }

.hero { text-align: center; padding: 20px 0 10px; }
.hero p { max-width: 560px; margin: 0 auto 16px; }
.hero .bracelet-wrap { margin: 18px auto; max-width: 520px; animation: bob 3s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(1.5deg); } }
@media (prefers-reduced-motion: reduce) { .hero .bracelet-wrap { animation: none; } }

.btn {
  display: inline-block; cursor: pointer; font-size: 1.15rem; font-weight: 700;
  color: #2b2350; background: var(--yellow); text-decoration: none;
  border: 3px solid var(--ink); border-radius: 18px 22px 16px 24px;
  padding: 8px 22px; box-shadow: 3px 3px 0 var(--ink);
  transition: transform .1s, box-shadow .1s;
}
.btn:hover { transform: translate(-1px, -1px) rotate(-1deg); box-shadow: 5px 5px 0 var(--ink); }
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }
.btn.pink { background: var(--pink); }
.btn.blue { background: var(--blue); }
.btn.small { font-size: .95rem; padding: 3px 14px; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 4px solid var(--purple); outline-offset: 2px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 22px; padding-right: 5px; }
.card {
  background: var(--card); border: 3px solid var(--ink); border-radius: 26px 20px 28px 18px;
  box-shadow: var(--shadow); padding: 16px; text-decoration: none; display: block;
  transition: transform .15s;
}
a.card:hover { transform: rotate(-1.2deg) translateY(-4px); }
.card .bracelet-wrap { background: var(--paper); border-radius: 16px; padding: 10px; margin-bottom: 10px; border: 2px dashed var(--ink); }
.card p { margin: .2em 0 .6em; }

.pill {
  display: inline-block; font-size: .9rem; font-weight: 700; padding: 0 12px; margin: 0 6px 4px 0;
  border: 2px solid var(--ink); border-radius: 999px; background: var(--green); color: #2b2350;
}
.pill.layers { background: var(--blue); }
.pill.time { background: var(--pink); }

.bracelet { width: 100%; height: auto; display: block; }
.bead-outline { stroke: #2b2350; }

.panel {
  background: var(--card); border: 3px solid var(--ink); border-radius: 24px 28px 20px 26px;
  box-shadow: var(--shadow); padding: 18px 22px; margin: 18px 5px 18px 0;
}
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 22px; }
@media (max-width: 720px) { .two-col { grid-template-columns: 1fr; } }

.swatches { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px 14px; }
.swatches li { display: flex; align-items: center; gap: 6px; }
.swatches i { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--ink); display: inline-block; }

.steps { list-style: none; padding: 0; counter-reset: s; }
.steps > li {
  counter-increment: s; position: relative; margin: 0 0 16px; padding: 12px 16px 12px 66px;
  background: var(--card); border: 3px solid var(--ink); border-radius: 22px 18px 24px 16px;
  box-shadow: 3px 3px 0 var(--ink);
}
.steps > li::before {
  content: counter(s); position: absolute; left: 12px; top: 10px; width: 40px; height: 40px;
  border-radius: 50%; background: var(--pink); color: #2b2350; border: 3px solid var(--ink);
  font-family: 'Baloo 2', cursive; font-weight: 800; font-size: 1.3rem; text-align: center; line-height: 34px;
}
.steps.done > li, .steps > li.done { opacity: .6; }
.steps label { cursor: pointer; display: flex; gap: 10px; align-items: center; margin-top: 6px; font-weight: bold; }
.steps input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--green); }
.steps .bracelet-wrap { max-width: 460px; margin-top: 8px; }

.progress { height: 22px; border: 3px solid var(--ink); border-radius: 999px; overflow: hidden; background: var(--card); }
.progress div { height: 100%; width: 0; background: var(--green); transition: width .3s; }

/* Catalog */
form.upload { display: grid; gap: 12px; }
form.upload label { font-family: 'Baloo 2', cursive; font-weight: 700; display: grid; gap: 2px; }
input[type=text], select, textarea, input[type=file] {
  font: inherit; color: var(--ink); background: var(--paper); padding: 8px 12px;
  border: 3px solid var(--ink); border-radius: 14px; width: 100%;
}
.dropzone { text-align: center; }
.preview { max-height: 220px; max-width: 100%; border-radius: 14px; border: 3px solid var(--ink); margin: 6px auto 0; display: none; }
.photo-card img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 16px; border: 3px solid var(--ink); display: block; margin-bottom: 8px; }
.photo-card .meta { font-size: 1rem; opacity: .8; }
.photo-card .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 6px; }
.empty { text-align: center; padding: 30px 10px; }
.empty .bracelet-wrap { max-width: 260px; margin: 0 auto 8px; opacity: .85; }
.msg { font-weight: bold; min-height: 1.5em; }

/* Templates */
.tpl-card { position: relative; }
.cord-tag { display: inline-block; margin-bottom: 8px; padding: 4px 12px; background: var(--paper); border: 3px solid var(--ink); border-radius: 14px; font-family: 'Baloo 2', cursive; font-size: .9rem; line-height: 1.1; }
.cord-tag b { font-size: 1.3rem; color: var(--pink); }
.diagram-wrap { text-align: center; }
.diagram-wrap .diagram { max-height: 440px; margin: 0 auto; }
.tpl-card .diagram { max-height: 260px; }
.tpl-detail { align-items: start; }
.diagram text { fill: var(--ink); }
.rowlist { padding-left: 1.4em; columns: 2; column-gap: 28px; }
@media (max-width: 720px) { .rowlist { columns: 1; } }
@media print {
  .top, footer, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .panel, .card { box-shadow: none; }
}

/* Designer */
.palette { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 4px; }
.swatch {
  width: 46px; height: 46px; border-radius: 50%; border: 3px solid var(--ink); cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink); transition: transform .1s; padding: 0;
}
.swatch:hover { transform: scale(1.12) rotate(-6deg); }
.swatch[aria-checked="true"] { outline: 4px solid var(--purple); outline-offset: 3px; transform: scale(1.15); }
.swatch:focus-visible { outline: 4px solid var(--purple); outline-offset: 3px; }
.controls { display: flex; flex-wrap: wrap; gap: 14px 24px; align-items: center; margin-top: 14px; }
.stepper { display: flex; align-items: center; gap: 8px; font-family: 'Baloo 2', cursive; font-weight: 700; }
.stepper b { min-width: 1.6em; text-align: center; font-size: 1.3rem; }
#canvas { touch-action: none; user-select: none; }
.paintable { cursor: pointer; }
.paintable:hover rect.bead-outline { stroke: var(--purple); }
