:root {
  --ink: #111111;
  --ink-2: #333333;
  --ink-3: #777777;
  --stone: #beb8ad;
  --sand: #e6e1d7;
  --paper: #f6f4ee;
  --line: #d9d3c7;
  --fabric: #f2ecde;         /* Aida, same as render.FABRIC_RGB */
  --empty-cell: #e6e0d4;     /* cells of the piece with no stitch */
  --mono: "DM Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --sans: "Noto Sans KR", -apple-system, "Apple SD Gothic Neo", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* components below set display; hidden must still win */
html { background: var(--paper); }
body {
  margin: 0;
  padding: 56px clamp(16px, 5vw, 72px) 80px;
  color: var(--ink);
  font: 400 14px/1.6 var(--sans);
  letter-spacing: 0.02em;
  max-width: 1320px;
  margin-inline: auto;
}
h1, h2, h3, p, ul { margin: 0; }
button { font: inherit; color: inherit; }

/* ---------- type ---------- */
.eyebrow {
  font: 500 11px/1 var(--mono);
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.label { font-size: 12px; font-weight: 500; color: var(--ink-2); margin: 18px 0 8px; }
.hint { font-size: 12px; color: var(--ink-3); margin-top: 6px; }
.value { font: 400 12px/1 var(--mono); color: var(--ink-2); letter-spacing: 0.08em; }

/* ---------- masthead ---------- */
.masthead {
  display: flex;
  justify-content: space-between;
  gap: 40px;
  flex-wrap: wrap;
  margin-bottom: 56px;
}
.masthead h1 {
  font: 300 clamp(40px, 6vw, 64px)/1 var(--sans);
  letter-spacing: 0.06em;
}
.masthead-title .eyebrow { margin-top: 14px; letter-spacing: 0.5em; }
.tagline { margin-top: 22px; font-size: 15px; letter-spacing: 0.18em; }
.rule { display: block; width: 36px; height: 1.5px; background: var(--ink); margin-top: 28px; }
.masthead-concept { padding-top: 10px; min-width: 240px; }
.masthead-concept ol { list-style: none; padding: 0; margin-top: 16px; counter-reset: step; }
.masthead-concept li { font-size: 13px; letter-spacing: 0.14em; line-height: 2.2; counter-increment: step; }
.masthead-concept li::before { content: counter(step, decimal-leading-zero); margin-right: 10px; font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.masthead-concept .note { margin-top: 12px; font-size: 12px; letter-spacing: 0.08em; color: var(--ink-3); }

/* ---------- browser too old ---------- */
.unsupported { margin: 0 0 32px; padding: 14px 20px; border-radius: 14px; background: var(--ink); color: var(--paper);
               font-size: 14px; line-height: 1.6; }

/* ---------- language menu ---------- */
.langs { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 14px; margin: -32px 0 24px;
         font: 400 12px var(--mono); letter-spacing: .08em; }
.langs a { color: var(--ink-3); text-decoration: none; padding: 2px 0; border-bottom: 1px solid transparent; }
.langs a:hover { color: var(--ink); }
.langs a[aria-current="page"] { color: var(--ink); border-color: var(--ink); }
@media (max-width: 600px) { .langs { gap: 4px 10px; font-size: 11px; letter-spacing: 0; } }

/* ---------- colophon ---------- */
.colophon { margin-top: 64px; padding: 24px 0 40px; border-top: 1px solid var(--line); font-size: 11px; line-height: 1.9; letter-spacing: 0.04em; color: var(--ink-3); }
.colophon a { color: inherit; }

/* ---------- layout ---------- */
.studio {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 48px;
  align-items: start;
}
@media (max-width: 900px) {
  .studio { grid-template-columns: 1fr; gap: 32px; }
}

/* ---------- panel ---------- */
.panel { display: flex; flex-direction: column; }
.block { padding: 22px 0; border-top: 1px solid var(--line); }
.block:first-child { border-top: 0; padding-top: 0; }
.block > .eyebrow, .field-head { margin-bottom: 14px; }
.field-head { display: flex; justify-content: space-between; align-items: baseline; }
.field-head .label { margin: 18px 0 8px; }

.dropzone {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  border: 1px dashed var(--stone);
  border-radius: 14px;
  background: #fbfaf6;
  cursor: pointer;
  overflow: hidden;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.dragging { border-color: var(--ink); background: var(--sand); }
.dropzone img { width: 100%; height: 100%; object-fit: contain; }
.dropzone-hint { white-space: pre-line; text-align: center; font-size: 12px; letter-spacing: 0.12em; color: var(--ink-3); line-height: 2; }

/* range: a pill track like the gauge */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 12px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  background: linear-gradient(var(--ink), var(--ink)) 0 / var(--fill, 20%) 100% no-repeat, var(--sand);
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--paper);
  border: 1.5px solid var(--ink);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--paper);
  border: 1.5px solid var(--ink);
}

.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pills + .pills { margin-top: 10px; }
.pills button {
  padding: 5px 14px;
  border: 1px solid var(--ink-2);
  border-radius: 999px;
  background: transparent;
  font-size: 12px;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.pills button:hover { background: var(--sand); }
.pills button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.more summary { cursor: pointer; list-style: none; display: flex; justify-content: space-between; }
.more summary::-webkit-details-marker { display: none; }
.more summary::after { content: "+"; font-family: var(--mono); }
.more[open] summary::after { content: "−"; }

/* ---------- stage (device frame) ---------- */
.device {
  padding: 14px;
  border-radius: 40px;
  background: var(--ink);
  box-shadow: 0 1px 0 #444 inset, 0 24px 48px -28px rgba(0, 0, 0, .45);
}
.screen {
  position: relative;
  border-radius: 28px;
  background: var(--sand);
  overflow: hidden;
}
.screen-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 18px 24px 0;
  min-height: 52px;
}
.gauge { display: flex; align-items: center; gap: 12px; flex: 1 1 260px; }
.gauge-track {
  flex: 0 1 180px;
  height: 12px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  overflow: hidden;
}
.gauge-fill { display: block; height: 100%; width: 0; background: var(--ink); transition: width .3s ease; }
.gauge-text { font: 400 12px var(--mono); color: var(--ink-2); letter-spacing: .06em; }
.objects { flex: 1 1 auto; }
.objects button { padding: 3px 12px; font-family: var(--mono); }
.tabs { margin-left: auto; display: flex; gap: 18px; }
.tabs button {
  border: 0; background: none; padding: 4px 0; cursor: pointer;
  font: 500 11px/1 var(--mono); letter-spacing: .28em; text-transform: uppercase; color: var(--ink-3);
  border-bottom: 1.5px solid transparent;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-color: var(--ink); }

.canvas {
  display: grid;
  place-items: center;
  min-height: 460px;
  padding: 24px;
}
.canvas img {
  max-width: 100%;
  max-height: 62vh;
  image-rendering: pixelated;
  border-radius: 6px;
  box-shadow: 0 0 0 1px var(--line);
  transition: opacity .2s;
}
.canvas.busy img { opacity: .35; }
.link { border: 0; background: none; padding: 0; cursor: pointer; font: inherit; color: var(--ink-3);
        text-decoration: underline; text-underline-offset: 3px; }
.calibrate { display: grid; justify-items: center; gap: 14px; padding: 20px 24px; background: var(--paper);
             border-bottom: 1px solid var(--line); }
.calibrate input { width: min(100%, 420px); }
.card-outline {
  width: calc(8.56cm * var(--screen-scale, 1));
  height: calc(5.398cm * var(--screen-scale, 1));
  border: 1.5px dashed var(--ink);
  border-radius: calc(0.318cm * var(--screen-scale, 1));
}
.empty { white-space: pre-line; text-align: center; color: var(--ink-3); font-size: 13px; letter-spacing: .16em; line-height: 2.2; }

/* ---------- finished look: real size, shrunk only when it does not fit the box ---------- */
.finished { margin: 36px 0 0; }
.finished figcaption { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; margin-bottom: 12px; }
.finished-note { display: flex; gap: 14px; font: 400 12px var(--mono); letter-spacing: .12em; color: var(--ink-3); }
.finished-frame {
  display: grid;
  place-items: center;
  height: 400px;   /* ~9 cm of content: most patterns show at real size */
  padding: 24px;
  background: var(--fabric);
  border-radius: 12px;
  box-shadow: 0 0 0 1px var(--line);
}
@media (max-width: 600px) { .finished-frame { height: 300px; padding: 16px; } }
/* width label on top, height label on the right; a left spacer as wide as the height label
   keeps the piece itself centred */
/* real size in a full-window dialog; scrolls when the piece is bigger than the screen */
.real-size {
  width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: var(--fabric); color: var(--ink);
}
.real-size[open] { display: grid; grid-template-rows: auto auto minmax(0, 1fr); }
.real-size::backdrop { background: var(--ink); }
.real-size header {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 16px 24px; border-bottom: 1px solid var(--line); background: var(--paper);
}
.real-size header .link { font-size: 13px; }
.real-size header #calibrateToggle { margin-left: auto; }
.real-warning {
  padding: 6px 14px; border-radius: 999px; background: var(--ink); color: var(--paper);
  font-size: 12px; letter-spacing: .06em;
}
.real-body { display: flex; overflow: auto; padding: 32px; }
.real-body > .finished-piece { margin: auto; }   /* centred when it fits, scrollable when not */

.finished-piece {
  display: grid;
  grid-template-columns: var(--dim) auto var(--dim);
  grid-template-rows: var(--dim) auto;
  --dim: 26px;
}
.finished-grid { grid-area: 2 / 2; background-color: var(--empty-cell); }
.finished-grid.lined {   /* faint cell grid, only while cells are big enough to read */
  background-image:
    linear-gradient(to right, var(--fabric) 1px, transparent 1px),
    linear-gradient(to bottom, var(--fabric) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
}
.finished-grid img { display: block; image-rendering: pixelated; }
.dim {
  display: flex; align-items: center; gap: 8px;
  font: 400 11px/1 var(--mono); letter-spacing: .08em; color: var(--ink-3); white-space: nowrap;
}
.dim::before, .dim::after { content: ""; flex: 1; border: 0 solid var(--ink-3); opacity: .5; }
.dim-w { grid-area: 1 / 2; padding-bottom: 8px; }
.dim-w::before, .dim-w::after { border-top-width: 1px; }
.dim-h { grid-area: 2 / 3; flex-direction: column; padding-left: 8px; writing-mode: vertical-rl; }
.dim-h::before, .dim-h::after { border-left-width: 1px; }

/* ---------- stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin-top: 36px;
}
.stats > div { padding: 0 20px; border-left: 1px solid var(--line); }
.stats > div:first-child { border-left: 0; padding-left: 0; }
.stat { margin-top: 12px; font: 400 20px/1.2 var(--mono); letter-spacing: .02em; }
.stat-note { margin-top: 6px; font: 400 11px/1.4 var(--mono); letter-spacing: .12em; color: var(--ink-3); }
@media (max-width: 600px) {
  .stats { grid-template-columns: repeat(2, 1fr); row-gap: 24px; }
  .stats > div:nth-child(3) { border-left: 0; padding-left: 0; }
}

/* ---------- threads ---------- */
.threads { margin-top: 40px; padding-top: 28px; border-top: 1px solid var(--line); }
.threads-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 16px; }
.button {
  display: inline-block;
  padding: 10px 24px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  background: var(--ink);
  color: var(--paper);
  text-decoration: none;
  font-size: 13px;
  letter-spacing: .14em;
  transition: background .15s;
}
.button:hover { background: var(--ink-2); }
.button[aria-busy="true"] { opacity: .5; cursor: progress; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  font: 500 10px/1 var(--mono);
  letter-spacing: .22em;
  color: var(--ink-3);
  padding: 0 8px 10px;
  border-bottom: 1px solid var(--ink);
}
td { padding: 10px 8px; border-bottom: 1px solid var(--line); }
td.code, td.symbol, .num { font-family: var(--mono); }
.num { text-align: right; }
.swatch {
  display: inline-block;
  width: 22px; height: 22px;
  border-radius: 50%;
  vertical-align: middle;
  box-shadow: 0 0 0 1px rgba(17, 17, 17, .25);
}
@media (max-width: 600px) {
  td.name, th.name { display: none; }
  .canvas { min-height: 300px; }
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  padding: 10px 22px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  letter-spacing: .08em;
  max-width: calc(100vw - 32px);
}

/* ---------- privacy policy and other reading pages ---------- */
.document { max-width: 680px; margin: 0 auto; }
.document > .eyebrow a { color: inherit; text-decoration: none; }
.document h1 { margin-top: 28px; font: 300 clamp(28px, 4vw, 40px)/1.2 var(--sans); letter-spacing: 0.04em; }
/* headings are in the reader's language: sans, not the wide-tracked mono eyebrows (CJK falls apart) */
.document .updated { margin-top: 12px; font-size: 12px; letter-spacing: 0.04em; color: var(--ink-3); }
.document section { margin-top: 40px; }
.document h2 { font: 500 14px/1.4 var(--sans); letter-spacing: 0.06em; color: var(--ink);
               padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.document p, .document ul { margin-top: 14px; font-size: 14px; line-height: 1.85; color: var(--ink-2); }
.document ul { padding-left: 1.2em; }
.document li + li { margin-top: 6px; }
.document a { color: var(--ink); text-underline-offset: 3px; overflow-wrap: anywhere; }
