/* =========================================================================
   URL 단축기 — 공개 프론트엔드 스타일시트
   shadcn/ui 디자인 언어를 그대로 옮긴 순수 CSS. 빌드 도구 불필요.
   토큰 → 리셋 → 레이아웃 → 컴포넌트 → 반응형 순서로 정리되어 있습니다.
   ========================================================================= */

/* =========================================================================
   1. 디자인 토큰
   shadcn 의 neutral 스케일을 기본으로, 브랜드 블루를 --primary 로 사용합니다.
   ========================================================================= */
:root {
  /* 타이포 */
  --font-sans: "Pretendard Variable", Pretendard, ui-sans-serif, -apple-system,
    BlinkMacSystemFont, system-ui, "Apple SD Gothic Neo", "Malgun Gothic",
    "Segoe UI", Roboto, "Noto Sans KR", sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, "JetBrains Mono",
    Menlo, Consolas, "Liberation Mono", monospace;

  /* 표면 */
  --background: #fafafa;          /* 페이지 바탕 */
  --foreground: #0a0a0a;          /* 기본 텍스트 */
  --card: #ffffff;                /* 카드 표면 */
  --card-foreground: #0a0a0a;

  /* 보조 */
  --muted: #f5f5f5;               /* 옅은 채움 */
  --muted-foreground: #6b6b6b;    /* 보조 텍스트 (#737373 은 --muted 위에서 AA 미달) */
  --secondary: #f5f5f5;           /* secondary 버튼 배경 */
  --secondary-foreground: #171717;
  --secondary-hover: #ebebeb;
  --accent: #f5f5f5;              /* hover 채움 */
  --accent-foreground: #171717;

  /* 선 / 입력 */
  --border: #e5e5e5;              /* 장식용 구분선 */
  --input: #8f8f8f;               /* 컨트롤 경계선 — WCAG 1.4.11 의 3:1 */
  --ring: #1570dd;                /* 포커스 링 */

  /* 강조 (브랜드) */
  --primary: #1570dd;
  --primary-hover: #1160c2;
  --primary-foreground: #ffffff;

  /* 상태 */
  --destructive: #b91c1c;
  --destructive-foreground: #ffffff;
  --success: #15803d;

  /* 반경 — shadcn 기본 0.625rem */
  --radius: 0.625rem;
  --radius-sm: calc(var(--radius) - 4px);  /* 6px */
  --radius-md: calc(var(--radius) - 2px);  /* 8px */
  --radius-lg: var(--radius);              /* 10px */
  --radius-xl: calc(var(--radius) + 4px);  /* 14px */
  --radius-full: 9999px;

  /* 그림자 — shadcn 은 아주 얕게 씁니다 */
  --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / .05);
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / .07), 0 1px 2px -1px rgb(0 0 0 / .07);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / .07), 0 2px 4px -2px rgb(0 0 0 / .05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / .08), 0 4px 6px -4px rgb(0 0 0 / .06);

  /* 컨트롤 치수 */
  --control-h: 2.75rem;    /* 44px — 본문용 */
  --control-h-lg: 3rem;    /* 48px — 히어로 입력행 */

  --content-w: 30rem;      /* 카드 최대 너비 */

  color-scheme: light;
}

/* 다크 모드 — OS 설정을 따릅니다 */
@media (prefers-color-scheme: dark) {
  :root {
    --background: #0a0a0a;
    --foreground: #fafafa;
    --card: #131316;
    --card-foreground: #fafafa;

    --muted: #1c1c1f;
    --muted-foreground: #a1a1aa;
    --secondary: #1c1c1f;
    --secondary-foreground: #fafafa;
    --secondary-hover: #26262b;
    --accent: #1c1c1f;
    --accent-foreground: #fafafa;

    --border: #27272a;
    --input: #66666e;             /* 컨트롤 경계선 — WCAG 1.4.11 의 3:1 */
    --ring: #4c9aff;

    --primary: #1e70e0;
    --primary-hover: #1a63c8;
    --primary-foreground: #ffffff;

    --destructive: #ef4444;
    --success: #22c55e;

    --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / .4);
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / .5), 0 1px 2px -1px rgb(0 0 0 / .5);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / .5), 0 2px 4px -2px rgb(0 0 0 / .4);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / .6), 0 4px 6px -4px rgb(0 0 0 / .5);

    color-scheme: dark;
  }
}

/* =========================================================================
   2. 리셋
   ========================================================================= */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--foreground);
  background-color: var(--background);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "tnum" 0;
}

img, svg { max-width: 100%; height: auto; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }

::selection { background: color-mix(in oklab, var(--primary) 22%, transparent); }

/* =========================================================================
   3. 레이아웃
   ========================================================================= */
.shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 2.5rem 1rem;
}

/* 은은한 배경 글로우 — 카드가 배경 위에 떠 보이게 합니다 */
.shell::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(60rem 30rem at 50% -10%,
      color-mix(in oklab, var(--primary) 9%, transparent), transparent 70%);
}

.card {
  width: min(100%, var(--content-w));
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 2.5rem 2rem;
  position: relative;
}

/* =========================================================================
   4. 히어로 (로고 · 제목 · 설명)
   여기가 기존에 무너져 있던 세로 리듬입니다. 로고 → 제목 → 설명 → 폼 순으로
   간격을 명시적으로 나눠 문구가 입력칸에 달라붙지 않게 합니다.
   ========================================================================= */
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

/* 로고는 가로형 워드마크입니다. 높이만 고정하고 너비는 비율대로 두어야
   찌그러지지 않습니다. (예전의 56×56 원형 마스크가 문제였습니다) */
.hero__logo {
  height: 2.75rem;
  width: auto;
  max-width: 70%;
  object-fit: contain;
}
.hero__logo--dark { display: none; }

.hero__title {
  margin-top: 1.75rem;
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.025em;
}

.hero__lead {
  margin-top: 0.625rem;
  max-width: 24rem;
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--muted-foreground);
  text-wrap: balance;
  word-break: keep-all;   /* 한글이 어절 중간에서 끊기지 않도록 */
}

/* 설명 문구와 입력행 사이의 숨 쉴 공간.
   히어로 바로 아래에 오는 형제가 무엇이든(숨겨진 알림이 끼어들 수도 있다)
   간격이 유지되도록, 인접 형제 선택자가 아니라 히어로 자신의 아래 여백으로 잡는다.
   숨겨진 요소(display:none)는 박스가 없어 여백을 만들지 않으므로 계산에서 자연히 빠진다. */
.hero { margin-bottom: 2rem; }

/* =========================================================================
   5. 폼 컨트롤
   ========================================================================= */
.field {
  display: flex;
  width: 100%;
  min-width: 0;
  height: var(--control-h);
  padding: 0 0.875rem;
  font-size: 0.9375rem;
  color: var(--foreground);
  background: transparent;
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field::placeholder { color: var(--muted-foreground); }
.field:hover { border-color: color-mix(in oklab, var(--foreground) 20%, var(--input)); }
.field:focus-visible,
.field:focus {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 45%, transparent);
}
.field:read-only { background: var(--muted); }
.field--lg { height: var(--control-h-lg); font-size: 1rem; padding: 0 1rem; }
.field--mono {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  letter-spacing: -0.01em;
}

/* 입력 + 버튼 한 줄 */
.field-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

/* ---- 버튼 ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: var(--control-h);
  padding: 0 1rem;
  font-size: 0.9375rem;
  font-weight: 500;
  white-space: nowrap;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  user-select: none;
  text-decoration: none;
  transition: background-color .15s ease, border-color .15s ease,
              color .15s ease, box-shadow .15s ease, opacity .15s ease;
}
.btn:focus-visible {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 45%, transparent);
}
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn--lg { height: var(--control-h-lg); padding: 0 1.5rem; font-size: 1rem; }
.btn--block { width: 100%; }

/* default */
.btn-primary {
  flex: 0 0 auto;
  background: var(--primary);
  color: var(--primary-foreground);
  font-weight: 600;
  box-shadow: var(--shadow-xs);
}
.btn-primary:hover { background: var(--primary-hover); }

/* outline */
.btn-outline {
  flex: 0 0 auto;
  background: var(--card);
  color: var(--foreground);
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}
.btn-outline:hover { background: var(--accent); color: var(--accent-foreground); }
.btn-outline.is-copied {
  color: var(--success);
  border-color: color-mix(in oklab, var(--success) 45%, var(--border));
}

/* ghost */
.btn-ghost {
  height: 2.25rem;
  padding: 0 0.625rem;
  background: transparent;
  color: var(--muted-foreground);
  font-size: 0.875rem;
}
.btn-ghost:hover { background: var(--accent); color: var(--accent-foreground); }

/* icon-only */
.btn-icon {
  width: 2rem;
  height: 2rem;
  padding: 0;
  flex: 0 0 auto;
  background: transparent;
  color: var(--muted-foreground);
  border-radius: var(--radius-sm);
}
.btn-icon:hover { background: var(--accent); color: var(--accent-foreground); }
.btn-icon svg { width: 1rem; height: 1rem; }

/* =========================================================================
   6. 사용자 지정 주소 (접히는 영역)
   ========================================================================= */
.shorten-form { margin: 0; }
.login-form { margin: 0; }

.toggle-custom {
  margin-top: 0.75rem;
  margin-left: -0.625rem;   /* 고스트 버튼의 좌측 패딩만큼 당겨 입력칸과 왼쪽 선을 맞춘다 */
}
.toggle-custom .chevron {
  width: 0.875rem;
  height: 0.875rem;
  transition: transform .2s ease;
}
.toggle-custom[aria-expanded="true"] .chevron { transform: rotate(180deg); }

.custom-panel {
  display: grid;
  grid-template-rows: 0fr;
  overflow: hidden;
  /* 링(3px)이 잘리지 않도록 패널을 좌우로 4px 넓히고, 안쪽 패딩으로 되돌린다 */
  margin: 0 -4px;
  transition: grid-template-rows .25s cubic-bezier(.4, 0, .2, 1);
}
.custom-panel.is-open { grid-template-rows: 1fr; }
.custom-panel__inner { min-height: 0; padding: 0 4px 4px; }

/* prefix + input 이 하나의 컨트롤처럼 보이는 결합형 필드 */
.custom-field {
  display: flex;
  align-items: stretch;
  margin-top: 0.5rem;
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.custom-field:focus-within {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 45%, transparent);
}
.custom-field .prefix {
  display: inline-flex;
  align-items: center;
  padding: 0 0.5rem 0 0.875rem;
  color: var(--muted-foreground);
  background: var(--muted);
  border-right: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  white-space: nowrap;
}
.custom-field input {
  flex: 1 1 auto;
  min-width: 0;
  height: 2.5rem;
  padding: 0 0.875rem;
  font-size: 0.9375rem;
  background: transparent;
  border: none;
  outline: none;
}
.custom-field input::placeholder { color: var(--muted-foreground); }

/* =========================================================================
   7. 결과 영역
   ========================================================================= */
.result {
  margin-top: 2rem;
  padding-top: 1.75rem;
  border-top: 1px solid var(--border);
  animation: fade-up .25s cubic-bezier(.4, 0, .2, 1) both;
}
.result__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.result__title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.result__note {
  margin-top: 0.25rem;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--muted-foreground);
  word-break: keep-all;
}

/* ---- QR ---- */
.qr {
  width: 11.5rem;
  aspect-ratio: 1 / 1;
  margin: 1.25rem auto 0;
  padding: 0.75rem;
  background: #ffffff;         /* 스캔 정확도를 위해 항상 흰 바탕 */
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.qr canvas { width: 100%; height: 100%; display: block; }

.qr-actions {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
  margin-top: 1rem;
}

/* ---- 셀렉트 ---- */
.select {
  flex: 0 0 auto;
  height: var(--control-h);
  padding: 0 2.25rem 0 0.875rem;
  font-size: 0.875rem;
  color: var(--foreground);
  background-color: transparent;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b6b6b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 1rem;
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
@media (prefers-color-scheme: dark) {
  .select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  }
}
.select:hover { border-color: color-mix(in oklab, var(--foreground) 20%, var(--input)); }
.select:focus-visible {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 45%, transparent);
}
.qr-actions .btn-outline { flex: 1 1 auto; }

/* =========================================================================
   8. 알림 (shadcn Alert)
   ========================================================================= */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  font-size: 0.875rem;
  line-height: 1.5;
}
.alert { margin-bottom: 1rem; }
.alert__icon { flex: 0 0 auto; width: 1rem; height: 1rem; margin-top: 0.15rem; }
.alert__icon svg { width: 100%; height: 100%; }
.alert__msg { flex: 1 1 auto; min-width: 0; word-break: keep-all; }
.alert a { color: var(--primary); font-weight: 500; text-decoration: none; }
.alert a:hover { text-decoration: underline; }

.alert--error {
  color: var(--destructive);
  border-color: color-mix(in oklab, var(--destructive) 35%, var(--border));
  background: color-mix(in oklab, var(--destructive) 7%, var(--card));
}
.alert--error a { color: inherit; }
.alert--ok {
  border-color: color-mix(in oklab, var(--success) 35%, var(--border));
  background: color-mix(in oklab, var(--success) 7%, var(--card));
}
.alert--ok .alert__icon { color: var(--success); }

/* =========================================================================
   9. 로그인 폼 (requireAuth = true 일 때)
   ========================================================================= */
.login-form { display: grid; gap: 1rem; }
.login-form .field-group { display: grid; gap: 0.5rem; }
.login-form label {
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1;
  color: var(--foreground);
}

/* =========================================================================
   10. 푸터 / 토스트 / 스피너
   ========================================================================= */
.page-foot {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted-foreground);
  font-size: 0.8125rem;
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 2rem;
  z-index: 50;
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  color: var(--card);
  background: var(--foreground);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateX(-50%) translateY(0.75rem);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.is-shown { opacity: 1; transform: translateX(-50%) translateY(0); }

.spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid color-mix(in oklab, currentColor 30%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

/* =========================================================================
   11. 애니메이션
   ========================================================================= */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(0.5rem); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================================
   12. 반응형
   ========================================================================= */
@media (max-width: 30rem) {
  .card { padding: 1.75rem 1.25rem; border-radius: var(--radius-lg); }
  .hero__logo { height: 2.25rem; max-width: 80%; }
  .hero__title { margin-top: 1.5rem; font-size: 1.5rem; }
  .field-row { flex-direction: column; }
  .field-row .btn { width: 100%; }
  .qr { width: 10rem; }
  .qr-actions { flex-direction: column; }
  .select { width: 100%; }
}

/* 어두운 배경에서는 흰색 워드마크로 교체합니다 */
@media (prefers-color-scheme: dark) {
  .hero__logo--light { display: none; }
  .hero__logo--dark { display: block; }
}

/* =========================================================================
   13. 모션 감소
   ========================================================================= */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
