/* StitchMyPhoto Pattern Maker. Same tokens as the demo and website: named after DMC floss. */
:root {
  --paper: #FFFFFF;          /* B5200 */
  --ground: #EEF1F5;
  --grid: #D9DFE7;
  --grid-strong: #9AA8B8;
  --ink: #213063;            /* 823 */
  --ink-soft: #4F5F72;
  --red: #C72B3B;            /* 321 */
  --red-deep: #A11F2E;
  --green: #056517;          /* 699 */
  --amber: #8A5A00;
  --amber-bg: #FFF4DC;

  --display: "Zilla Slab", Georgia, serif;
  --body: "Atkinson Hyperlegible", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;

  --radius: 14px;
  --bar-h: 58px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; color: var(--ink); font: 400 16px/1.45 var(--body);
  background-color: var(--ground);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 12px 12px;
  min-height: 100vh;
}
button, input, select, textarea { color: inherit; font: inherit; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--red); outline-offset: 2px; border-radius: 6px; }
h1, h2 { font-family: var(--display); font-weight: 700; letter-spacing: -0.01em; line-height: 1.1; margin: 0; text-wrap: balance; }
h2 { font-size: 19px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 20px; border-radius: 999px; border: 2px solid transparent;
  font-weight: 700; font-size: 16px; cursor: pointer; text-decoration: none;
  transition: background-color .15s, border-color .15s, transform .1s;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--red); color: #fff; }
.btn--primary:hover { background: var(--red-deep); }
.btn--ghost { background: var(--paper); border-color: var(--ink); color: var(--ink); }
.btn--ghost:hover { background: var(--ground); }
.btn--big { min-height: 54px; font-size: 17px; padding: 0 28px; }
.btn[disabled] { opacity: .55; cursor: progress; }
.link-btn {
  background: none; border: 0; padding: 10px 0; margin: -10px 0; color: var(--ink); cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1.5px; font-size: 15px;
}

/* ---------- Top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 20; height: var(--bar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 16px; background: rgba(255, 255, 255, 0.95); background: color-mix(in srgb, var(--paper) 94%, transparent);
  backdrop-filter: blur(6px); border-bottom: 1px solid var(--grid);
}
.wordmark { font: 700 21px/1 var(--display); text-decoration: none; padding: 10px 0; }
.wordmark span { color: var(--red); }
.bar-nav { display: flex; align-items: center; gap: 6px; }
.bar-link { text-decoration: none; font-weight: 700; padding: 12px 10px; border-radius: 8px; font-size: 15px; }
.bar-link:hover { background: var(--ground); }
.bar-license {
  min-height: 40px; padding: 0 14px; border-radius: 999px; cursor: pointer; font-size: 14px; font-weight: 700;
  border: 1.5px solid var(--red); background: var(--paper); color: var(--red);
}
.bar-license.is-on { border-color: var(--green); color: var(--green); }
.bar-link, .bar-license { white-space: nowrap; }
@media (max-width: 420px) {
  .bar { padding: 0 12px; gap: 6px; }
  .wordmark { font-size: 18px; }
  .bar-link { padding: 12px 6px; font-size: 14px; }
  .bar-license { padding: 0 10px; font-size: 13px; min-height: 38px; }
}

main { max-width: 1280px; margin: 0 auto; }
.screen { padding: 20px 16px 48px; }

/* ---------- Start ---------- */
.home { max-width: 760px; margin: 0 auto; display: grid; gap: 22px; }
.drop {
  background: var(--paper); border: 2px dashed var(--grid-strong); border-radius: 20px;
  padding: 40px 22px; text-align: center; display: grid; justify-items: center; gap: 14px;
  transition: border-color .15s, background-color .15s;
}
.drop.is-over { border-color: var(--red); background: #FFF7F7; }
.drop h1 { font-size: clamp(30px, 7vw, 44px); }
.drop-lede { margin: 0; color: var(--ink-soft); max-width: 30em; font-size: 17px; }
.drop-hint { margin: 0; color: var(--ink-soft); font-size: 14px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.section-head a { font-weight: 700; padding: 8px 0; }
.tips { background: var(--paper); border-radius: var(--radius); padding: 18px 20px; border: 1px solid var(--grid); }
.tips ul { margin: 10px 0 0; padding-left: 20px; display: grid; gap: 6px; color: var(--ink-soft); }
.tips b { color: var(--ink); }

/* ---------- Pattern cards ---------- */
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.pcard { background: var(--paper); border: 1px solid var(--grid); border-radius: var(--radius); overflow: hidden; display: grid; }
.pcard-open { display: grid; text-decoration: none; }
.pcard-open img { width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--ground); display: block; }
.pcard-text { padding: 10px 12px 4px; display: grid; gap: 2px; }
.pcard-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard-meta { font-size: 13px; color: var(--ink-soft); }
.pcard-actions { display: flex; gap: 4px; padding: 2px 6px 6px; }
.pcard-actions button { background: none; border: 0; padding: 10px 6px; font-size: 14px; color: var(--ink-soft); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.pcard-actions button:hover { color: var(--ink); }

/* ---------- Editor ---------- */
.editor { padding-top: 12px; padding-bottom: 96px; }
.ed-top { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.back { text-decoration: none; font-weight: 700; padding: 10px 8px 10px 0; white-space: nowrap; }
.name-field { flex: 1 1 200px; min-width: 0; }
.name-field input {
  width: 100%; font: 700 22px/1.2 var(--display); border: 1.5px solid transparent; border-radius: 10px;
  background: transparent; padding: 6px 8px; min-height: 44px;
}
.name-field input:hover { border-color: var(--grid-strong); }
.name-field input:focus { border-color: var(--ink); background: var(--paper); outline: none; }
.saved { font: 500 12px/1 var(--mono); color: var(--ink-soft); letter-spacing: .04em; white-space: nowrap; }

.ed-grid { display: grid; gap: 16px; }
.stage { position: relative; background: var(--paper); border-radius: var(--radius); border: 1px solid var(--grid); overflow: hidden; }
.tabs { display: flex; border-bottom: 1px solid var(--grid); }
.tabs button {
  flex: 1; min-height: 48px; background: none; border: 0; cursor: pointer; font-weight: 700; color: var(--ink-soft);
  border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--red); }
.view { position: relative; aspect-ratio: 1; }
.view canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.view--chart canvas { touch-action: none; cursor: grab; }
.view--chart canvas:active { cursor: grabbing; }
.chart-tools { position: absolute; left: 38px; right: 8px; bottom: 8px; display: flex; justify-content: space-between; gap: 8px; pointer-events: none; }
.chart-tools > * { pointer-events: auto; }
.zoom { display: flex; background: var(--paper); border: 1px solid var(--grid-strong); border-radius: 999px; overflow: hidden; box-shadow: 0 2px 8px rgba(33,48,99,.12); }
.zoom button { min-width: 44px; min-height: 44px; border: 0; background: none; cursor: pointer; font-weight: 700; font-size: 18px; }
.zoom button#zoomFit { font-size: 14px; border-left: 1px solid var(--grid); border-right: 1px solid var(--grid); }
.cell-info {
  position: absolute; left: 38px; top: 30px; margin: 0; padding: 6px 10px; border-radius: 8px;
  background: rgba(255,255,255,.94); border: 1px solid var(--grid-strong); font-size: 14px; pointer-events: none;
}
.cell-info:empty { display: none; }
.hl-chip {
  position: absolute; right: 8px; top: 30px; display: flex; align-items: center; gap: 8px;
  background: var(--ink); color: #fff; border-radius: 999px; padding: 4px 4px 4px 14px; font-size: 14px;
}
.hl-chip button { min-height: 36px; border: 0; border-radius: 999px; padding: 0 12px; background: #fff; color: var(--ink); font-weight: 700; cursor: pointer; }

.seg { display: flex; flex-wrap: wrap; background: var(--ground); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button {
  flex: 1 1 auto; min-height: 42px; padding: 0 12px; border: 0; border-radius: 9px; background: transparent;
  cursor: pointer; font-weight: 700; color: var(--ink-soft);
}
.seg button[aria-checked="true"] { background: var(--paper); color: var(--ink); box-shadow: 0 1px 3px rgba(33,48,99,.18); }
.seg--small { background: var(--paper); border: 1px solid var(--grid-strong); border-radius: 999px; box-shadow: 0 2px 8px rgba(33,48,99,.12); }
.seg--small button { min-height: 36px; border-radius: 999px; font-size: 14px; }
.seg--small button[aria-checked="true"] { background: var(--ink); color: #fff; box-shadow: none; }

.busy {
  position: absolute; inset: 49px 0 0; display: flex; align-items: center; justify-content: center; gap: 12px;
  background: rgba(255,255,255,.86); font-weight: 700; z-index: 3; padding: 20px; text-align: center;
}
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--grid); border-top-color: var(--red); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.panel { display: grid; gap: 12px; align-content: start; }
.card { background: var(--paper); border-radius: var(--radius); border: 1px solid var(--grid); padding: 16px; }
.card > h2 { margin-bottom: 12px; }
.field { display: grid; gap: 8px; margin-bottom: 16px; }
.field--sub { margin: -4px 0 4px 58px; }
.label { font-weight: 700; font-size: 15px; }
.label-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.value { font: 500 15px/1 var(--mono); color: var(--ink); display: inline-flex; align-items: center; gap: 6px; }
.value input {
  width: 74px; min-height: 40px; padding: 0 8px; border: 1.5px solid var(--grid-strong); border-radius: 8px;
  font: 500 15px/1 var(--mono); text-align: right; background: var(--paper);
}
.hint { margin: 0; font-size: 14px; color: var(--ink-soft); }
select { min-height: 44px; border: 1.5px solid var(--grid-strong); border-radius: 8px; padding: 0 10px; background: var(--paper); }

input[type="range"] { width: 100%; accent-color: var(--red); min-height: 32px; margin: 0; }

.switches { display: grid; gap: 4px; }
.switch { display: grid; grid-template-columns: 46px 1fr; gap: 12px; align-items: start; padding: 8px 0; cursor: pointer; position: relative; }
.switch input { position: absolute; opacity: 0; width: 46px; height: 28px; margin: 0; cursor: pointer; }
.switch-ui { width: 46px; height: 28px; border-radius: 999px; background: var(--grid-strong); position: relative; transition: background-color .15s; margin-top: 1px; }
.switch-ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + .switch-ui { background: var(--green); }
.switch input:checked + .switch-ui::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-ui { outline: 3px solid var(--red); outline-offset: 2px; }
.switch input:disabled + .switch-ui { opacity: .45; }
.switch b { display: block; font-size: 15px; }
.switch small { display: block; color: var(--ink-soft); font-size: 14px; margin-top: 2px; }
.switches .link-btn { justify-self: start; margin: -4px 0 0 58px; }

/* Photo check */
.check-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.check-list li { display: grid; grid-template-columns: 24px 1fr; gap: 10px; font-size: 15px; }
.check-list .mark { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff; margin-top: 1px; }
.check-list .ok .mark { background: var(--green); }
.check-list .warn .mark { background: var(--amber); }
.check-list .warn { background: var(--amber-bg); border-radius: 10px; padding: 8px 10px; margin: 0 -10px; }
.check-list small { display: block; color: var(--ink-soft); font-size: 14px; }

/* Summary */
.sum { margin: 0; display: grid; gap: 10px; }
.sum div { display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: 10px; }
.sum dt { color: var(--ink-soft); font-size: 14px; }
.sum dd { margin: 0; font-weight: 700; }
.sum dd small { display: block; font-weight: 400; color: var(--ink-soft); font-size: 13px; }
.sum dd input { width: 64px; min-height: 36px; padding: 0 6px; border: 1.5px solid var(--grid-strong); border-radius: 8px; font: 500 14px/1 var(--mono); text-align: right; }

/* Floss list */
.threads { list-style: none; margin: 10px 0 0; padding: 0; display: grid; }
.thread { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; border-top: 1px solid var(--ground); }
.thread-main {
  display: grid; grid-template-columns: 32px 1fr auto; align-items: center; gap: 10px; padding: 8px 4px;
  background: none; border: 0; text-align: left; cursor: pointer; border-radius: 8px; min-height: 48px;
}
.thread-main:hover { background: var(--ground); }
.thread.is-hl .thread-main { background: #FFEFF0; }
.thread canvas { width: 30px; height: 30px; border-radius: 6px; display: block; box-shadow: inset 0 0 0 1px rgba(33,48,99,.15); }
.thread-name { display: grid; min-width: 0; }
.thread-code { font: 500 14px/1.2 var(--mono); }
.thread-label { font-size: 14px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-count { text-align: right; font-size: 13px; color: var(--ink-soft); white-space: nowrap; }
.thread-count b { display: block; color: var(--ink); font-size: 14px; }
.have { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-soft); padding: 8px 4px; cursor: pointer; min-height: 44px; }
.have input { width: 20px; height: 20px; accent-color: var(--green); margin: 0; }
.thread.is-owned .thread-code, .thread.is-owned .thread-label { text-decoration: line-through; text-decoration-color: var(--grid-strong); }

.actions { display: grid; gap: 10px; }

.mobile-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.95); background: color-mix(in srgb, var(--paper) 94%, transparent); backdrop-filter: blur(6px); border-top: 1px solid var(--grid);
}
.mobile-bar .btn { width: 100%; }

@media (min-width: 960px) {
  .ed-grid { grid-template-columns: minmax(0, 1fr) 380px; align-items: start; }
  .stage { position: sticky; top: calc(var(--bar-h) + 12px); }
  .view { aspect-ratio: auto; height: calc(100vh - var(--bar-h) - 150px); min-height: 420px; }
  .panel { max-height: none; }
  .mobile-bar { display: none; }
  .editor { padding-bottom: 48px; }
}

/* ---------- My patterns ---------- */
.patterns { max-width: 1080px; margin: 0 auto; }
.patterns h1 { font-size: clamp(30px, 6vw, 40px); }
.patterns .lede { color: var(--ink-soft); margin: 8px 0 16px; max-width: 40em; }
.row-btns { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.empty { color: var(--ink-soft); }

/* ---------- Dialogs ---------- */
.dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(480px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
  color: var(--ink); box-shadow: 0 20px 60px rgba(33,48,99,.3);
}
.dialog::backdrop { background: rgba(23,32,66,.45); }
.dialog form { padding: 22px; display: grid; gap: 14px; }
.dialog h2 { font-size: 24px; }
.dialog p { margin: 0; }
.dialog fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 4px; }
.dialog legend { font-weight: 700; margin-bottom: 4px; padding: 0; }
.radio, .checkline { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.radio input, .checkline input { width: 20px; height: 20px; accent-color: var(--red); margin: 0; }
.radio small { color: var(--ink-soft); }
.dialog textarea {
  width: 100%; border: 1.5px solid var(--grid-strong); border-radius: 10px; padding: 10px; resize: vertical;
  font: 500 13px/1.4 var(--mono); word-break: break-all; margin-top: 6px;
}
.error { color: var(--red-deep); font-weight: 700; font-size: 15px; }
.dialog-btns { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.ent-list { margin: 0; padding-left: 20px; }
.dialog--tall form { max-height: calc(100vh - 32px); grid-template-rows: auto auto auto auto minmax(0, 1fr) auto; }
.stash-tools { display: grid; gap: 10px; }
.stash-tools input { min-height: 46px; border: 1.5px solid var(--grid-strong); border-radius: 10px; padding: 0 12px; width: 100%; }
.stash-count { font: 500 13px/1 var(--mono); color: var(--ink-soft); }
.stash-list { list-style: none; margin: 0; padding: 0; overflow: auto; min-height: 160px; max-height: 50vh; border-top: 1px solid var(--grid); }
.stash-list label { display: grid; grid-template-columns: 22px 26px 64px 1fr; align-items: center; gap: 10px; min-height: 44px; border-bottom: 1px solid var(--ground); cursor: pointer; padding: 0 4px; }
.stash-list input { width: 20px; height: 20px; accent-color: var(--green); margin: 0; }
.stash-list .sw { width: 24px; height: 24px; border-radius: 6px; box-shadow: inset 0 0 0 1px rgba(33,48,99,.15); }
.stash-list .code { font: 500 14px/1 var(--mono); }
.stash-list .nm { font-size: 14px; color: var(--ink-soft); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; max-width: calc(100vw - 32px);
  box-shadow: 0 8px 24px rgba(33,48,99,.3); font-size: 15px;
}
@media (min-width: 960px) { .toast { bottom: 24px; } }

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

/* ---------- Free version: locked chart and floss list ---------- */
.lock {
  position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; padding: 20px;
  background-color: var(--ground);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 12px 12px;
}
.lock-card { background: var(--paper); border: 1px solid var(--grid); border-radius: var(--radius); padding: 22px; max-width: 380px; display: grid; gap: 12px; text-align: center; box-shadow: 0 10px 30px rgba(33,48,99,.14); }
.lock-card h2 { font-size: 22px; }
.lock-card p { margin: 0; color: var(--ink-soft); }
.lock-card .link-btn { justify-self: center; }
a.btn--primary { color: #fff; }
.thread-more { padding: 12px 0 2px; border-top: 1px solid var(--ground); display: grid; }
.lic-buy { font-size: 15px; }
.lic-buy a { font-weight: 700; }
.ios-tip { background: var(--amber-bg); border-radius: 12px; padding: 12px 14px; margin: 0 0 16px; max-width: 46em; font-size: 15px; }
