:root {
  --bg-page: #edf2f9;
  --bg-surface: #ffffff;
  --bg-subtle: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --accent: #1d63eb;
  --accent-hover: #1550c8;
  --accent-soft: #eff6ff;
  --border-color: #dbe3ef;
  --border-subtle: #e2e8f0;
  --shadow-sm: 0 2px 6px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-pill: 9999px;
  --font-sans: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, system-ui, Roboto, "Malgun Gothic", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(circle at 50% 0%, #f5f8fc 0%, var(--bg-page) 100%);
  color: var(--text-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  padding: clamp(1.25rem, 3vw, 2.5rem) clamp(1rem, 3vw, 2rem) 4.5rem;
}

.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;
}

.app-shell {
  max-width: 1020px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* 상단 헤더 및 탭 */
.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 0.25rem;
}

.brand-group {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.app-title {
  margin: 0;
  font-size: clamp(1.4rem, 1.1rem + 1vw, 1.75rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.app-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.category-tabs {
  display: inline-flex;
  align-items: center;
  background: var(--bg-surface);
  padding: 0.32rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  gap: 0.25rem;
}

.tab-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.55rem 1.15rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: background-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.tab-btn:hover:not(.is-active) {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.tab-btn.is-active {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 3px 10px rgba(29, 99, 235, 0.28);
}

/* 입력창 박스 */
.input-section {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.input-box {
  display: flex;
  align-items: center;
  background: var(--bg-surface);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 0.75rem 1.1rem 0.75rem 1.5rem;
  box-shadow: var(--shadow-md);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
  gap: 0.75rem;
}

.input-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(29, 99, 235, 0.12), var(--shadow-md);
}

#main-value-input {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: clamp(1.85rem, 1.35rem + 2vw, 2.65rem);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

#main-value-input::-webkit-outer-spin-button,
#main-value-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.active-unit-badge {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 0.35rem 0.8rem;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.reset-btn {
  appearance: none;
  border: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.6rem 1rem;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.reset-btn:hover {
  background: #e2e8f0;
  color: var(--text-primary);
}

/* 프리셋 및 옵션 툴바 */
.toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.preset-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.preset-btn {
  appearance: none;
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.75);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.32rem 0.7rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all 0.15s ease;
}

.preset-btn:hover {
  background: var(--bg-surface);
  border-color: var(--accent);
  color: var(--accent);
}

.options-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.option-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.precision-select {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.3rem 0.55rem;
  cursor: pointer;
}

/* 단위 선택 칩 (Choice Cards / Chips pattern using :has(> :checked)) */
.unit-chips {
  margin: 0;
  padding: 0;
  border: none;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 0.6rem;
}

.unit-chip {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-pill);
  padding: 0.62rem 0.75rem;
  font-size: 0.98rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.unit-chip > input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.unit-chip:hover {
  border-color: #94a3b8;
}

/* 레이아웃 점프 방지를 위해 border-width/padding/font-weight는 고정하고 색상과 그림자만 변경 */
.unit-chip:has(> :checked) {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(29, 99, 235, 0.28);
}

.unit-chip:has(> :focus-visible) {
  outline: 3px solid rgba(29, 99, 235, 0.45);
  outline-offset: 2px;
}

/* 상단 핵심 변환 2열 카드 & 하단 전체 단위 3열 그리드 */
.primary-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.1rem;
}

.secondary-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.95rem;
}

/* 카드 컴포넌트 (<article class="unit-card"> + container query) */
.unit-card {
  container-type: inline-size;
  background: var(--bg-surface);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.4rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.35rem;
  cursor: pointer;
  transition: border-color 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
}

.unit-card:hover {
  border-color: #93c5fd;
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.unit-card.is-primary-highlight {
  border-color: var(--accent);
  box-shadow: 0 8px 24px rgba(29, 99, 235, 0.09);
}

.unit-card.is-source-unit {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.unit-card > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.unit-card h2,
.unit-card h3 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.copy-btn {
  appearance: none;
  border: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.3rem 0.65rem;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.copy-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: #bfdbfe;
}

.card-value {
  margin: 0.15rem 0;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  word-break: break-all;
  font-size: clamp(1.55rem, 1.2rem + 1.2vw, 2.1rem);
}

.unit-card.is-primary .card-value {
  font-size: clamp(1.95rem, 1.45rem + 1.6vw, 2.65rem);
}

.card-desc {
  margin: 0.1rem 0 0;
  font-size: 0.88rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* 카드 내부 가용 폭에 맞춘 Container Query 타이포그래피 조정 */
@container (max-width: 260px) {
  .card-value {
    font-size: 1.45rem;
  }
  .unit-card.is-primary .card-value {
    font-size: 1.75rem;
  }
}

/* 하단 토스트 알림 (Popover Manual + Legacy Fallback) */
.toast {
  position: fixed;
  inset: auto 0 1.6rem 0;
  margin: 0 auto;
  width: fit-content;
  max-width: calc(100vw - 2rem);
  background: #1e293b;
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-pill);
  padding: 0.7rem 1.25rem;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.28);
  font-size: 0.92rem;
  font-weight: 600;
  align-items: center;
  gap: 0.55rem;
  z-index: 9999;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease, overlay 0.2s ease allow-discrete, display 0.2s ease allow-discrete;
  transition-behavior: allow-discrete;
}

.toast:not([popover]),
[popover].toast:is(:popover-open, .\:popover-open),
.toast.is-fallback-open {
  display: inline-flex;
  opacity: 1;
  transform: translateY(0);
}

@starting-style {
  [popover].toast:is(:popover-open, .\:popover-open) {
    opacity: 0;
    transform: translateY(12px);
  }
}

.toast-close {
  appearance: none;
  border: none;
  background: transparent;
  color: #94a3b8;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.1rem 0.25rem;
  margin-left: 0.25rem;
}

.toast-close:hover {
  color: #ffffff;
}

@media (max-width: 640px) {
  .top-header {
    flex-direction: column;
    align-items: stretch;
  }
  .category-tabs {
    justify-content: space-between;
  }
  .tab-btn {
    flex: 1;
    justify-content: center;
    padding: 0.55rem 0.5rem;
  }
}
