/* 1초 QR — 레이아웃/톤. 빌드 스텝 없음, 외부 리소스 없음. */

:root {
  --bg: #f2f3f6;
  --bg-glow: #e7eaf3;
  --card-bg: #ffffff;
  --card-border: #e3e5ea;
  --text: #1c1e24;
  --text-muted: #6b6f7b;
  --text-faint: #9498a3;
  --input-bg: #f7f8fa;
  --input-border: #dcdfe6;
  --input-border-focus: #3b6ff0;
  --accent: #3b6ff0;
  --accent-contrast: #ffffff;
  --tab-inactive: #6b6f7b;
  --stage-border: #d7dae1;
  --stage-bg: #f7f8fb;
  --shadow: 0 1px 2px rgba(20, 22, 30, 0.04), 0 12px 28px -14px rgba(20, 22, 30, 0.18);
  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101217;
    --bg-glow: #171a21;
    --card-bg: #1a1d24;
    --card-border: #2a2e38;
    --text: #eef0f4;
    --text-muted: #9599a6;
    --text-faint: #6c7080;
    --input-bg: #14161c;
    --input-border: #2e323d;
    --input-border-focus: #6d93f7;
    --accent: #6d93f7;
    --accent-contrast: #10131a;
    --tab-inactive: #9599a6;
    --stage-border: #2e323d;
    --stage-bg: #14161c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 20px 40px -20px rgba(0, 0, 0, 0.6);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--bg-glow), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Apple SD Gothic Neo",
    "Noto Sans KR", "Malgun Gothic", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.page {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 16px 32px;
}

/* ---------- hero ---------- */

.hero {
  width: 100%;
  max-width: 420px;
  text-align: center;
  margin-bottom: 24px;
}

.hero-title {
  margin: 0 0 8px;
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.hero-tagline {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--text-muted);
}

/* ---------- card / tabset ---------- */

.card {
  width: 100%;
  max-width: 420px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 8px;
}

.tabset {
  display: flex;
  flex-wrap: wrap;
}

/* visually-hidden but keyboard-focusable radio inputs (CSS-only tabs) */
.mode-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  white-space: nowrap;
  clip-path: inset(50%);
  border: 0;
  padding: 0;
  margin: -1px;
}

.tab {
  order: 1;
  flex: 1 1 0;
  text-align: center;
  padding: 12px 8px;
  margin: 4px 2px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--tab-inactive);
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.tab:hover {
  color: var(--text);
}

.mode-input:checked + .tab {
  background: var(--accent);
  color: var(--accent-contrast);
}

.mode-input:focus-visible + .tab {
  outline: 2px solid var(--input-border-focus);
  outline-offset: 2px;
}

/* panels: order 3 so they render below the tab row regardless of DOM order,
   hidden unless their radio is checked (no JS required) */
.panel {
  order: 3;
  flex-basis: 100%;
  display: none;
  flex-direction: column;
  gap: 14px;
  padding: 18px 12px 6px;
}

#mode-link:checked ~ .panel-link {
  display: flex;
}

#mode-wifi:checked ~ .panel-wifi {
  display: flex;
}

/* ---------- fields ---------- */

.field {
  display: block;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.input {
  width: 100%;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input::placeholder {
  color: var(--text-faint);
}

.input:focus {
  outline: none;
  border-color: var(--input-border-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--input-border-focus) 22%, transparent);
}

.select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M5 7.5 10 12.5 15 7.5' stroke='%239498a3' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.input-with-action {
  position: relative;
  display: block;
}

.input-with-action .input {
  padding-right: 46px;
}

.visibility-toggle {
  -webkit-appearance: none;
  appearance: none;
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  color: var(--text-faint);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.visibility-toggle:hover {
  color: var(--text-muted);
}

.visibility-toggle:focus-visible {
  outline: 2px solid var(--input-border-focus);
  outline-offset: 2px;
}

.icon {
  width: 20px;
  height: 20px;
}

/* ---------- QR display stage ---------- */

.qr-stage {
  order: 4;
  flex-basis: 100%;
  padding: 6px 12px 16px;
}

.qr-frame {
  aspect-ratio: 1 / 1;
  width: 100%;
  max-width: 260px;
  margin: 0 auto;
  border: 1.5px dashed var(--stage-border);
  border-radius: var(--radius-md);
  background: var(--stage-bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px;
  color: var(--text-faint);
  text-align: center;
}

.icon-qr {
  width: 32px;
  height: 32px;
}

.qr-placeholder-text {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.4;
}

/* ---------- print controls (screen only; actual print layout is #print-sheet below) ---------- */

.print-controls {
  width: 100%;
  max-width: 420px;
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
}

.print-count-field {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.print-count-field .field-label {
  margin-bottom: 0;
  white-space: nowrap;
}

.print-count-input {
  width: 72px;
  text-align: center;
  padding: 10px 8px;
}

.print-button {
  flex: 1 1 160px;
  border: none;
  background: var(--accent);
  color: var(--accent-contrast);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.print-button:hover {
  opacity: 0.9;
}

.print-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.print-button-sub {
  font-weight: 500;
  opacity: 0.85;
  font-size: 0.82rem;
}

/* 다운로드/공유 버튼은 인쇄 버튼과 같은 크기를 쓰되 강조색을 뺀 보조 스타일 */
.secondary-button {
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--input-border);
}

.secondary-button:hover {
  opacity: 1;
  background: var(--stage-bg);
}

.print-hint {
  flex-basis: 100%;
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-faint);
  line-height: 1.4;
}

.share-outcome {
  flex-basis: 100%;
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
  min-height: 1.1em;
}

.share-outcome:empty {
  display: none;
}

/* ---------- footer ---------- */

.foot {
  margin-top: 20px;
  text-align: center;
}

.foot p {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-faint);
}

/* ---------- small screens (down to 360px) ---------- */

@media (max-width: 380px) {
  .page {
    padding: 28px 10px 24px;
  }

  .hero-title {
    font-size: 1.6rem;
  }

  .card {
    border-radius: var(--radius-md);
  }

  .panel {
    padding: 16px 8px 4px;
  }

  .tab {
    padding: 10px 6px;
    font-size: 0.88rem;
  }

  .print-controls {
    padding: 12px;
    flex-direction: column;
    align-items: stretch;
  }

  .print-count-field {
    justify-content: space-between;
  }

  .print-count-field .field-label {
    font-size: 0.75rem;
  }

  .print-button {
    flex: 1 1 auto;
  }
}

/* ---------- reduced motion ---------- */

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

/* ---------- print layout ----------
   화면 UI(.page 전체)는 인쇄 시 전부 숨기고 #print-sheet만 보여준다.
   실제 항목(QR + 텍스트 라벨) 채우기와 최종 열/행 수 조정은 QR-08(dev) 담당 — 여기서는
   3열 그리드(칸당 QR+라벨 공간을 감안, A4 한 장에 3x8=24개 안팎이 들어가는 걸 기준으로
   #print-count의 max=24를 잡았다) 뼈대만 만든다.

   QR-08이 각 칸에 채워 넣을 예상 마크업(참고용, 실제 삽입은 dev 담당):
     <div class="print-item">
       <div class="print-item-qr"><img ...></div>
       <p class="print-item-label">https://example.com</p>  <!-- 링크 모드 -->
       <!-- 또는 와이파이 모드: SSID / 비밀번호 / 암호화방식을 줄바꿈으로 -->
     </div>
*/

#print-sheet {
  display: none;
}

@media print {
  @page {
    size: A4;
    margin: 12mm;
  }

  body {
    background: #fff;
    margin: 0;
  }

  body > *:not(#print-sheet) {
    display: none !important;
  }

  .no-print {
    display: none !important;
  }

  #print-sheet {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: min-content;
    gap: 8mm 6mm;
    align-content: start;
  }

  /* 칸 하나 = QR 이미지 + 그 아래 텍스트 라벨(내용 문자열). break-inside: avoid로
     페이지 넘침 시 QR이나 라벨이 잘리지 않도록 한다. 클래스명은 QR-08에서 그대로
     쓰거나 필요하면 바꿔도 된다. */
  #print-sheet .print-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3mm;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* QR 이미지가 들어갈 슬롯. 정사각형 비율 유지, 칸 너비에 맞춰 축소. */
  #print-sheet .print-item-qr {
    width: 100%;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  #print-sheet .print-item-qr img,
  #print-sheet .print-item-qr canvas,
  #print-sheet .print-item-qr svg {
    width: 100%;
    height: 100%;
  }

  /* QR이 담은 문자열(링크 URL, 또는 와이파이 SSID/비밀번호/암호화방식)을 보여줄
     텍스트 라벨. 길어도 칸 밖으로 넘치지 않게 줄바꿈을 허용한다. */
  #print-sheet .print-item-label {
    margin: 0;
    width: 100%;
    max-width: 100%;
    font-size: 8pt;
    line-height: 1.35;
    text-align: center;
    color: #000;
    white-space: pre-line;
    overflow-wrap: break-word;
    word-break: break-word;
  }
}
