/* 데이터 변신 공장(6학년 3차시) — 공통 스타일과 2진수 변환소의 스타일(binary.css: 탭 · 색 · TV 크기) 위에 얹는다.
   body 에 class="green digital binary datafactory" 를 준다.
   낱말: 길(pipe) = 넣는 것 → 숫자로 → 0과 1로. 0 · 1 칸(df-bit)은 2진수 변환소의 카드 아래 칸과 같은 색이다(1은 노랑, 0은 흰색). */
.datafactory .df-lead { margin: 0 0 12px; max-width: 50em; font-size: 1.08rem; }
.datafactory .df-how { margin: 0 0 12px; max-width: 50em; }
.df-note { margin: 6px 0 0; color: var(--muted); font-size: .95rem; }
.df-say { min-height: 1.5em; margin: 6px 0 0; color: var(--primary-dark); font-weight: 700; font-size: .95rem; }
.df-say.bad { color: var(--warn); }
.df-foot { margin: 12px 0 0; color: var(--muted); font-size: .95rem; max-width: 52em; }
.df-more { margin: 12px 0 0; }
.df-more a { color: var(--primary-dark); font-weight: 800; }
.df-empty { margin: 0; padding: 18px; border-radius: 14px; background: var(--soft); color: var(--muted); text-align: center; }
.df-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.df-ctl { margin: 10px 0 4px; font-weight: 800; font-size: .95rem; color: var(--primary-dark); }

/* ---- 생각 열기 ---- */
.df-think { border: 2px solid var(--line); border-radius: 14px; background: #fff; }
.df-think + .df-think { margin-top: 8px; }
.df-think summary { padding: 12px 14px; font-weight: 800; cursor: pointer; }
.df-think summary:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 12px; }
.df-think[open] { background: var(--soft); border-color: #c9cffa; }
.df-think p { margin: 0; padding: 0 14px 14px; max-width: 50em; }

/* ---- 데이터의 종류 고르기 ---- */
.df-waypick { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.df-waybtn {
  min-height: 52px; padding: 8px 10px; border: 2px solid var(--line); border-radius: 14px; background: #fff;
  font: inherit; font-size: 1.15rem; font-weight: 800; color: var(--text); cursor: pointer;
}
.df-waybtn:hover { border-color: var(--primary); }
.df-waybtn.on { border-color: var(--primary); background: var(--primary); color: #fff; }
.df-seen { color: var(--star); }
.df-waybtn.on .df-seen { color: var(--lit); }

/* ---- 길: 넣는 것 → 숫자로 → 0과 1로 ---- */
.df-pipe { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, .8fr) auto minmax(0, 1.5fr); gap: 8px; align-items: stretch; }
.df-pipe.image { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1.15fr) auto minmax(0, 1.1fr); }
.df-pipe.sound { grid-template-columns: minmax(0, 1.7fr) auto minmax(0, 1fr); }
.df-stage { min-width: 0; padding: 12px 14px 14px; border-radius: 16px; background: var(--soft); }
.df-stage-name { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-weight: 900; color: var(--primary-dark); }
.df-stage-n { display: grid; place-items: center; width: 26px; height: 26px; flex: none; border-radius: 50%; background: var(--primary-dark); color: #fff; font-size: .9rem; }
.df-arrow { display: grid; place-items: center; color: var(--primary); font-weight: 900; font-size: 1.5rem; line-height: 1; }
.df-field { display: grid; gap: 4px; font-weight: 700; }
.datafactory input.df-input {
  width: 6em; min-height: 48px; padding: 6px 10px; border: 2px solid var(--line); border-radius: 12px; background: #fff;
  font-size: 1.4rem; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums;
}
.datafactory input.df-input.wide { width: min(100%, 12em); }
.df-big { display: block; font-size: clamp(2.4rem, 7vw, 3.6rem); line-height: 1.1; font-weight: 900; color: var(--primary-dark); font-variant-numeric: tabular-nums; }
.df-code { font-weight: 900; font-size: 1.25rem; color: var(--primary-dark); font-variant-numeric: tabular-nums; }

/* 자리마다의 점 수와 0 · 1(숫자) */
.df-places { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; }
.df-place { display: grid; justify-items: center; gap: 2px; padding: 5px 0 6px; border-radius: 8px; background: #fff; border: 2px solid var(--line); }
.df-place small { color: var(--muted); font-size: .78rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.df-place b { font-size: 1.3rem; line-height: 1; color: var(--muted); }
.df-place.on { background: var(--lit); border-color: var(--lit-edge); }
.df-place.on small, .df-place.on b { color: var(--primary-dark); }

/* 0 · 1 칸 */
.df-bits { display: inline-flex; flex-wrap: wrap; gap: 3px; vertical-align: middle; }
.df-bit {
  display: grid; place-items: center; width: 1.45em; height: 1.7em; border-radius: 6px; background: #fff; border: 1.5px solid var(--line);
  color: var(--muted); font-style: normal; font-weight: 900; font-size: .98rem; line-height: 1; font-variant-numeric: tabular-nums;
}
.df-bit.on { background: var(--lit); border-color: var(--lit-edge); color: var(--primary-dark); }
.df-bit.gap { margin-left: 7px; }

/* 컴퓨터로 들어가는 0과 1의 줄 */
.df-stream { display: flex; align-items: center; gap: 14px; margin-top: 14px; padding: 12px 16px; border-radius: 16px; background: #1d2433; color: #fff; }
.df-stream-pc { flex: none; display: grid; place-items: center; width: 60px; height: 52px; border-radius: 12px; background: #fff; }
.df-stream-main { min-width: 0; flex: 1; }
.df-stream-label { margin: 0 0 2px; font-weight: 700; color: #cbd2e6; font-size: .95rem; }
.df-stream-count { margin-left: 4px; padding: 1px 10px; border-radius: 999px; background: var(--lit); color: var(--primary-dark); font-variant-numeric: tabular-nums; }
/* 줄이 길면 묶음(빈칸)에서 다음 줄로 넘긴다: 잘려서 안 보이는 0과 1이 없게 */
.df-stream-track { overflow: hidden; }
.df-stream-bits { display: block; font-weight: 800; font-size: 1.15rem; line-height: 1.45; letter-spacing: .08em; word-spacing: .12em; font-variant-numeric: tabular-nums; color: var(--lit); overflow-wrap: anywhere; }
.df-stream-bits.flow { animation: df-flow .7s cubic-bezier(.2, .7, .2, 1) both; }
@keyframes df-flow { from { transform: translateX(28%); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- 문자 ---- */
.df-textin { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 16px; margin-bottom: 14px; }
.df-chars { display: grid; gap: 8px; }
.df-char { display: grid; grid-template-columns: 4.2rem 1.6rem 6.2rem 1.6rem minmax(0, 1fr); align-items: center; gap: 6px; padding: 8px 12px; border-radius: 14px; background: var(--soft); }
.df-char.head { padding-top: 0; padding-bottom: 0; background: none; color: var(--muted); font-weight: 800; font-size: .9rem; }
.df-char .df-arrow { font-size: 1.2rem; }
.df-glyph { display: grid; place-items: center; min-height: 3.2rem; border-radius: 12px; background: #fff; border: 2px solid var(--primary); font-size: 2rem; line-height: 1; color: var(--primary-dark); }
.df-char .df-code { text-align: center; }

/* ---- 이미지 ---- */
.df-canvas { display: block; width: 100%; max-width: 300px; height: auto; margin: 0 auto 10px; border-radius: 10px; border: 2px solid var(--primary-dark); background: #fff; }
.df-canvas.pick { cursor: crosshair; touch-action: manipulation; }
/* 고른 픽셀의 숫자 한 줄: 길을 위아래로 쌓는 좁은 화면에서만 그림 바로 아래에 보인다(넓은 화면에서는 옆 칸에 자세히 나온다) */
.df-pickline { display: none; margin: 0 0 4px; text-align: center; font-weight: 800; font-size: .95rem; color: var(--primary-dark); font-variant-numeric: tabular-nums; }
.datafactory .df-canvas.pick:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }
.df-file { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.df-filebtn { position: relative; cursor: pointer; }
.df-filebtn:focus-within { outline: 3px solid var(--primary); outline-offset: 2px; }
.df-pixel { padding: 10px 12px; border-radius: 12px; background: #fff; }
.df-pixel-where { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-weight: 800; }
.df-swatch { display: inline-block; width: 28px; height: 28px; flex: none; border-radius: 8px; border: 2px solid var(--primary-dark); }
.df-pixel-rows { display: grid; gap: 6px; }
.df-pixel-row { display: grid; grid-template-columns: 2.3rem 2.3rem 1rem minmax(0, 1fr); align-items: center; gap: 4px; }
.df-pixel-row .df-arrow { font-size: 1rem; }
.df-pixel-row .df-code { font-size: 1.05rem; white-space: nowrap; text-align: right; }
.df-pixel-row .df-bits { flex-wrap: nowrap; gap: 2px; }
.df-pixel-row .df-bit { width: 1.2em; font-size: .78rem; }
.df-pixel-name { font-weight: 800; font-size: .92rem; }
.df-pixel-name.c-r { color: #c92a2a; }
.df-pixel-name.c-g { color: #2b8a3e; }
.df-pixel-name.c-b { color: #1c5fd4; }

/* ---- 소리 ---- */
.df-wave { display: block; width: 100%; height: auto; border-radius: 12px; background: #fff; }
.df-wave-level { stroke: #e3e7f3; stroke-width: 1; }
.df-wave-stem { stroke: rgba(38, 49, 143, .22); stroke-width: 1.5; }
.df-wave-smooth { fill: none; stroke: #8c97e8; stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; }
.df-wave-step { fill: none; stroke: var(--earth); stroke-width: 3; stroke-linejoin: round; }
.df-wave-dot { fill: var(--primary-dark); }
.df-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin: 8px 0 0; font-size: .92rem; font-weight: 700; color: var(--muted); }
.df-legend .k { display: inline-block; width: 26px; height: 4px; border-radius: 2px; }
.df-legend .k.smooth { background: #8c97e8; }
.df-legend .k.step { background: var(--earth); margin-left: 10px; }
/* 듣기 단추: 연한 바탕 위에서도 단추로 보이게 */
.datafactory .df-play { background: #fff; border-color: var(--primary); color: var(--primary-dark); }
.datafactory .df-play:hover { background: var(--primary); color: #fff; }
.df-listen { margin-top: 12px; }
.df-samples { display: grid; gap: 5px; }
.df-sample { display: grid; grid-template-columns: 4.4rem 4.4rem minmax(0, 1fr); align-items: center; gap: 6px; padding: 5px 10px; border-radius: 10px; background: #fff; font-weight: 700; }
.df-sample.head { background: none; padding-top: 0; padding-bottom: 0; color: var(--muted); font-size: .88rem; font-weight: 800; }
.df-sample .df-code { text-align: center; font-size: 1.1rem; }

/* ---- 칸들(픽셀 그림 · 픽셀아트) ---- */
.px-host { display: flex; justify-content: center; margin: 12px 0; }
/* 키가 낮은 화면(크롬북)에서도 칸들과 그 위의 색 고르기가 한 화면에 들어오게: 칸들의 키를 화면 높이에 맞춰 줄인다(너무 작아지지는 않게) */
.px-host .px-grid { width: min(100%, calc(var(--cols) * 46px), max(264px, calc((100vh - 250px) * var(--cols) / var(--rows)))); }
.px-grid {
  display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 1px; width: min(100%, calc(var(--cols) * 46px)); max-width: 540px;
  padding: 2px; border-radius: 8px; background: var(--primary-dark); container-type: inline-size; user-select: none; -webkit-user-select: none;
}
.px-grid.live { touch-action: none; }
.px-cell {
  display: grid; place-items: center; aspect-ratio: 1; min-width: 0; padding: 0; border: 0; border-radius: 0; background: #fff; color: var(--text);
  font: inherit; font-weight: 800; font-size: calc(54cqw / var(--cols)); line-height: 1; font-variant-numeric: tabular-nums;
}
button.px-cell { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.datafactory button.px-cell:focus-visible { outline: 3px solid var(--lit-edge); outline-offset: -3px; z-index: 1; }
/* 다른 칸: 흰 띠와 빨간 띠를 겹쳐서, 어떤 색으로 칠한 칸 위에서도 보이게 한다 */
.px-cell.wrong { box-shadow: inset 0 0 0 2px #fff, inset 0 0 0 5px #e03131, inset 0 0 0 6px #fff; }
.px-cell.num.zero { color: #a7adbd; }
.px-actions { justify-content: center; }
.datafactory .btn.armed { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); }
.px-art:focus { outline: none; }
.px-solonote { margin-bottom: 8px; }
.px-bitsnote { text-align: center; }
.px-bitsrow { display: block; margin-top: 2px; font-weight: 800; letter-spacing: .06em; color: var(--primary-dark); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.px-pickers { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; margin-bottom: 4px; }
.px-note { color: var(--muted); font-size: .92rem; font-weight: 700; text-align: center; }
p.px-note { margin: 0; }
.px-say { min-height: 1.5em; margin: 10px 0 0; padding: 0; text-align: center; font-weight: 700; }
.px-say.ok, .px-say.bad { padding: 10px 14px; border-radius: 12px; }
.px-say.ok { background: var(--ok-soft); color: #1f6a2e; }
.px-say.bad { background: var(--warn-soft); color: var(--warn); }

/* 모양 위에 칸을 얹어 색칠하기 */
.px-tracewrap { display: grid; grid-template-columns: minmax(0, 360px) minmax(0, 1fr); gap: 16px; align-items: start; margin-top: 10px; }
.px-trace { position: relative; width: 100%; aspect-ratio: 1; }
.px-under { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 8px; }
.px-grid.see-through { position: absolute; inset: 0; width: 100%; max-width: none; height: 100%; gap: 0; padding: 0; background: transparent; border: 2px solid var(--primary-dark); }
.px-grid.see-through .px-cell { background: transparent; box-shadow: inset 0 0 0 .5px rgba(29, 36, 51, .4); }
.px-grid.see-through .px-cell.on { background: rgba(38, 49, 143, .78); }
.px-side { min-width: 0; display: grid; gap: 8px; align-content: start; }
.px-ideal-name { margin: 0; font-weight: 800; color: var(--primary-dark); }
.px-data { width: fit-content; max-width: 100%; margin: 0; padding: 10px 12px; border-radius: 12px; background: #1d2433; color: var(--lit); font: 800 1rem/1.35 ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace; letter-spacing: .18em; overflow-x: auto; }
.px-ideal .px-grid { width: min(100%, 220px); }
.px-ideal .px-cell.on { background: var(--primary-dark); }

/* ---- 블라인드 픽셀아트 ---- */
.px-steps { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; padding: 0; list-style: none; counter-reset: pxstep; }
.px-steps li { counter-increment: pxstep; display: flex; align-items: center; gap: 6px; padding: 6px 12px 6px 8px; border-radius: 999px; background: #fff; border: 2px solid var(--line); color: var(--muted); font-weight: 800; font-size: .95rem; }
.px-steps li::before { content: counter(pxstep); display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--line); color: var(--text); font-size: .82rem; }
.px-steps li.now { border-color: var(--primary); background: var(--soft); color: var(--primary-dark); }
.px-steps li.now::before { background: var(--primary); color: #fff; }
.px-steps li.done::before { background: var(--ok); color: #fff; }
.px-palette { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.px-color { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 4px 12px 4px 6px; border: 2px solid var(--line); border-radius: 999px; background: #fff; font: inherit; font-weight: 700; color: var(--text); cursor: pointer; }
.px-color.on { border-color: var(--primary); box-shadow: 0 0 0 3px var(--soft); }
.px-color-dot { display: grid; place-items: center; width: 30px; height: 30px; flex: none; border-radius: 50%; border: 1.5px solid rgba(29, 36, 51, .3); font-weight: 900; font-size: .95rem; }
.px-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; margin: 0; padding: 0; list-style: none; font-weight: 700; }
.px-legend li { display: inline-flex; align-items: center; gap: 6px; }
.px-solo { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 12px; }
.px-solo-name { margin: 0; color: var(--muted); font-weight: 700; }
.px-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 12px 0; }
.px-pair figure { margin: 0; display: grid; gap: 6px; justify-items: center; }
.px-pair figcaption { font-weight: 800; color: var(--primary-dark); }
.px-pair .px-grid { width: 100%; max-width: 360px; }

@media (max-width: 900px) {
  /* 좁은 화면: 길을 위에서 아래로 쌓는다(화살표도 아래를 본다) */
  .df-pipe, .df-pipe.image, .df-pipe.sound { grid-template-columns: minmax(0, 1fr); }
  .df-pipe > .df-arrow { transform: rotate(90deg); padding: 2px 0; }
  .df-pickline { display: block; }
  .px-tracewrap { grid-template-columns: minmax(0, 1fr); justify-items: center; }
  .px-trace { max-width: 360px; }
  .px-side { width: 100%; }
}
@media (max-width: 560px) {
  .df-waypick { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* 글자 → 번호는 한 줄에, 0과 1은 그 아래 줄에 길게 */
  .df-char { grid-template-columns: 3.2rem 1.2rem minmax(0, 1fr) 1.2rem; padding: 10px; gap: 6px; }
  .df-char.head { display: none; }
  .df-char > .df-arrow:nth-of-type(2) { transform: rotate(90deg); }
  .df-char > .df-bits { grid-column: 1 / -1; }
  .df-glyph { font-size: 1.6rem; min-height: 2.8rem; }
  .df-char .df-code { text-align: left; }
  .df-bit { width: 1.2em; height: 1.5em; font-size: .86rem; }
  .df-bit.gap { margin-left: 6px; }
  .df-stream { padding: 10px 12px; gap: 10px; }
  .df-stream-pc { width: 48px; height: 44px; }
  .df-stream-bits { font-size: 1rem; }
  .px-pair { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  .df-stream-bits.flow { animation: none; }
}
