/* CSS 변수 정의 - 다크테마 기본 */
:root[data-theme="dark"] {
  --brand: #4f46e5;
  --ink: #ffffff;
  --ink-secondary: #e2e8f0;
  --muted: #94a3b8;
  --bg: #0f172a;
  --bg-secondary: #1e293b;
  --card: #1e293b;
  --card-hover: #334155;
  --line: #334155;
  --accent: #0891b2;
  --good: #10b981;
  --warn: #f59e0b;
  --bad: #ef4444;
  --shadow: rgba(0, 0, 0, 0.3);
  --focus: #4f46e5;
  --gradient: linear-gradient(135deg, #4f46e5 0%, #6366f1 50%, #0891b2 100%);
}

:root[data-theme="light"] {
  --brand: #4f46e5;
  --ink: #0f172a;
  --ink-secondary: #475569;
  --muted: #64748b;
  --bg: #ffffff;
  --bg-secondary: #f8fafc;
  --card: #ffffff;
  --card-hover: #f1f5f9;
  --line: #e2e8f0;
  --accent: #0891b2;
  --good: #10b981;
  --warn: #f59e0b;
  --bad: #ef4444;
  --shadow: rgba(0, 0, 0, 0.08);
  --focus: #4f46e5;
  --gradient: linear-gradient(135deg, #4f46e5 0%, #6366f1 50%, #0891b2 100%);
}

/* 버튼 기본 스타일 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.875rem;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
  height: 44px;
  vertical-align: middle;
  line-height: 1;
}

.btn-primary {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}

.btn-primary:hover {
  background: var(--accent);
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.btn-outline {
  background: transparent;
  color: var(--brand);
  border-color: var(--brand);
}

.btn-outline:hover {
  background: var(--brand);
  color: white;
  transform: translateY(-1px);
}

.btn-lg {
  padding: 1rem 2rem;
  font-size: 1rem;
  height: 52px;
}

/* Reset 및 기본 스타일 */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-size: 16px;
  transition: background-color 0.3s ease, color 0.3s ease;
  letter-spacing: -0.01em;
}

/* 접근성 - Skip Link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: var(--brand);
  color: white;
  padding: 8px;
  text-decoration: none;
  border-radius: 4px;
  z-index: 1000;
  font-weight: 500;
}

.skip-link:focus {
  top: 6px;
}

/* Focus 스타일 */
:focus {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.2;
  color: var(--ink);
  margin-bottom: 0.5em;
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.75rem; }
h4 { font-size: 1.5rem; }
h5 { font-size: 1.25rem; }
h6 { font-size: 1rem; }

p {
  margin-bottom: 1rem;
  color: var(--ink-secondary);
}

a {
  color: var(--brand);
  text-decoration: underline;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--accent);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: 'Pretendard', system-ui, -apple-system, sans-serif;
  text-decoration: none;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 44px;
  height: 44px;
  letter-spacing: -0.01em;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  position: relative;
  overflow: hidden;
  vertical-align: middle;
  line-height: 1;
}

.btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
  transition: left 0.5s ease;
}

.btn:hover::before {
  left: 100%;
}

.btn:hover {
  background: var(--card-hover);
  border-color: var(--brand);
  transform: translateY(-2px);
  color: var(--ink);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.btn:focus {
  box-shadow: 0 0 0 4px rgba(76, 110, 245, 0.25);
  outline: none;
}

.btn-primary {
  background: var(--gradient);
  color: white;
  border: 2px solid transparent;
  font-weight: 700;
  box-shadow: 0 4px 15px rgba(76, 110, 245, 0.3);
}

.btn-primary:hover {
  background: var(--gradient);
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(76, 110, 245, 0.4);
  filter: brightness(1.1);
}

.btn-outline {
  background: transparent;
  color: var(--brand);
  border: 2px solid var(--brand);
  box-shadow: 0 2px 8px rgba(76, 110, 245, 0.1);
}

.btn-outline:hover {
  background: var(--brand);
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(76, 110, 245, 0.3);
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.8125rem;
  min-height: 36px;
  border-radius: 8px;
}

.btn-lg {
  padding: 1rem 2rem;
  font-size: 1.0625rem;
  min-height: 52px;
  border-radius: 16px;
  font-weight: 700;
}

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1.5rem;
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px var(--shadow);
}

.card:hover {
  background: var(--card-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow);
}

/* Forms */
.form-group {
  margin-bottom: 1rem;
}

label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--ink);
}

input, textarea, select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  color: var(--ink);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(76, 110, 245, 0.1);
}

input::placeholder, textarea::placeholder {
  color: var(--muted);
}

/* Grid 시스템 */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

.grid {
  display: grid;
  gap: 1rem;
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 768px) {
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }
}

/* Flex 유틸리티 */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }

/* Spacing */
.p-1 { padding: 0.25rem; }
.p-2 { padding: 0.5rem; }
.p-3 { padding: 0.75rem; }
.p-4 { padding: 1rem; }
.p-6 { padding: 1.5rem; }
.p-8 { padding: 2rem; }

.m-1 { margin: 0.25rem; }
.m-2 { margin: 0.5rem; }
.m-3 { margin: 0.75rem; }
.m-4 { margin: 1rem; }
.m-6 { margin: 1.5rem; }
.m-8 { margin: 2rem; }

.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.mb-8 { margin-bottom: 2rem; }

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 4px;
  background: var(--muted);
  color: var(--bg);
}

.badge-success { background: var(--good); color: white; }
.badge-warning { background: var(--warn); color: white; }
.badge-error { background: var(--bad); color: white; }
.badge-info { background: var(--accent); color: white; }

/* Loading */
.loading {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--line);
  border-radius: 50%;
  border-top-color: var(--brand);
  animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* 반응형 */
@media (max-width: 768px) {
  html { font-size: 14px; }
  .container { padding: 0 0.75rem; }
  
  h1 { font-size: 2rem; }
  h2 { font-size: 1.75rem; }
  h3 { font-size: 1.5rem; }
}

/* 성능 최적화 */
.heavy-section {
  content-visibility: auto;
  contain-intrinsic-size: 300px;
}

/* 다크 모드 전환 애니메이션 */
* {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* 스크린 리더 전용 */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* 접근성 - 줄여진 모션 설정 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
