/* ===== 색 (화이트 모드 기본) ===== */
:root {
  color-scheme: light;
  --bg: #ebecef; /* 페이지 바탕 (회색) */
  --surface: #ffffff; /* 흰 섹션 */
  --field: #f2f3f5; /* 회색 타일·입력칸 */
  --field-hover: #e7e8ec;
  --text: #18181b;
  --text-2: #4a4d55; /* 설명 글 */
  --muted: #767981; /* 보조 글자·아이콘 */
  --line: #eceef1;
  --accent: #18181b; /* 검은 버튼 */
  --accent-hover: #34343a;
  --on-accent: #ffffff;
  --accent-soft: #f2f3f5;
  --ok: #15803d;
  --warn: #b45309;
  --bad: #dc2626;
  --ins-bg: #dcfce7;
  --del-bg: #fee2e2;
  --mark: #fde68a;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

/* 다크 모드: <head> 의 스크립트가 <html data-theme="dark"> 로 켬 */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0a0b;
  --surface: #151517;
  --field: #212125;
  --field-hover: #2b2b30;
  --text: #f4f4f5;
  --text-2: #b9bbc2;
  --muted: #8f929a;
  --line: #27272c;
  --accent: #f4f4f5;
  --accent-hover: #d6d6da;
  --on-accent: #111113;
  --accent-soft: #212125;
  --ok: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --ins-bg: #12331f;
  --del-bg: #3d1719;
  --mark: #5e4b12;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
/* 한국어·일본어·중국어 페이지는 그 언어 글꼴로 (한자 모양이 언어마다 다름) */
/* (system-ui 보다 앞에 두어야 다른 나라 윈도우에서도 그 언어 글꼴이 쓰임) */
html:lang(ko) body { font-family: Inter, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif; word-break: keep-all; overflow-wrap: anywhere; }
html:lang(ja) body { font-family: Inter, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, "Noto Sans JP", system-ui, sans-serif; }
html:lang(zh) body { font-family: Inter, -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif; }
a { color: inherit; }
h1 { font-size: 1.85rem; font-weight: 700; line-height: 1.2; letter-spacing: -0.02em; margin: 6px 0 8px; }
h2, h3 { line-height: 1.3; letter-spacing: -0.01em; }
code, kbd, .mono { font-family: var(--mono); }
.mono { font-size: 0.92rem; }
.muted { color: var(--muted); }
.small { font-size: 0.88rem; }
.icon { width: 24px; height: 24px; flex: none; }

/* ===== 머리말 (흰 띠) ===== */
.site-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px max(16px, calc((100% - 1200px) / 2));
  background: var(--surface);
}
.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.logo-mark { width: 32px; height: 32px; flex: none; }
.logo-bg { fill: var(--text); }
.logo-fg { fill: var(--surface); }
.header-search { position: relative; flex: 1; max-width: 360px; margin-left: auto; }
.header-search .icon,
.search-box .icon {
  position: absolute;
  top: 50%;
  translate: 0 -50%;
  width: 19px;
  height: 19px;
  color: var(--muted);
  pointer-events: none;
}
.header-search .icon { left: 14px; }
.header-search input { width: 100%; padding: 10px 14px 10px 42px; }
.home .header-search { display: none; }
.home .lang-pick { margin-left: auto; }
/* 언어 선택 */
.lang-pick { position: relative; flex: none; }
.lang-pick .icon {
  position: absolute;
  top: 50%;
  left: 13px;
  translate: 0 -50%;
  width: 18px;
  height: 18px;
  color: var(--muted);
  pointer-events: none;
}
.lang-pick select { height: 44px; padding: 0 36px 0 38px; font-size: 0.92rem; font-weight: 600; }
.theme-toggle {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  color: var(--text);
  background: var(--field);
  border: 0;
  border-radius: 14px;
  cursor: pointer;
}
.theme-toggle:hover { background: var(--field-hover); }
.theme-toggle .icon { width: 20px; height: 20px; }
:root[data-theme="dark"] .i-moon,
:root:not([data-theme="dark"]) .i-sun { display: none; }

/* ===== 본문 | 사이드바 : 회색 바탕 위 흰 섹션들 ===== */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  max-width: 1232px;
  margin: 20px auto 0;
  padding: 0 16px;
  align-items: start;
}
.layout.single { grid-template-columns: minmax(0, 1fr); }
.main, .side { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

.panel, .tool, .content { padding: 28px; background: var(--surface); }
.panel h2, .tool h2 { margin: 0; font-size: 1.15rem; font-weight: 700; }

/* 페이지 제목 섹션: 왼쪽 글, 오른쪽 아이콘 타일 */
.title-panel { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.title-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  background: var(--field);
  border-radius: 20px;
}
.title-icon .icon { width: 34px; height: 34px; }
.lead { margin: 0; font-size: 1.02rem; color: var(--muted); }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; font-size: 0.9rem; font-weight: 500; color: var(--muted); }
.crumbs a { text-decoration: none; }
.crumbs a:hover { color: var(--text); }
.crumbs .icon { width: 16px; height: 16px; }

/* ===== 도구 섹션 ===== */
.tool { display: flex; flex-direction: column; gap: 16px; }

input, select, textarea, button { font: inherit; color: inherit; }
:where(input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"]), select, textarea) {
  min-width: 0;
  padding: 11px 14px;
  line-height: 1.35;
  background-color: var(--field);
  border: 1.5px solid transparent;
  border-radius: 14px;
}
:where(input, select, textarea):focus-visible {
  outline: none;
  border-color: var(--text);
  background-color: var(--surface);
}
::placeholder { color: var(--muted); opacity: 1; }
textarea { width: 100%; min-height: 9em; resize: vertical; line-height: 1.55; tab-size: 4; }
select {
  appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23878a92' 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 14px center;
  background-size: 16px;
  cursor: pointer;
}
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="checkbox"], input[type="radio"] { width: 1.05rem; height: 1.05rem; margin: 0; accent-color: var(--accent); }
input[type="color"] {
  width: 52px;
  height: 46px;
  padding: 4px;
  background: var(--field);
  border: 0;
  border-radius: 12px;
  cursor: pointer;
}
input[type="file"] { max-width: 100%; }

/* 버튼: 회색 타일, 주요 버튼은 검정 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px; /* 입력칸과 같은 높이 */
  padding: 11px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  color: var(--text);
  background: var(--field);
  border: 0;
  border-radius: 14px;
  cursor: pointer;
}
.btn:hover { background: var(--field-hover); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { color: var(--on-accent); background: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.sm { min-height: 0; padding: 7px 12px; font-size: 0.85rem; border-radius: 10px; }
.btn.big { padding: 16px 34px; font-size: 1.05rem; border-radius: 16px; }

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span:first-child { font-size: 0.88rem; font-weight: 500; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }

/* 탭 (Encode | Decode 등): 고른 것만 회색 알약 */
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; align-self: flex-start; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block;
  padding: 9px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  border-radius: 12px;
  cursor: pointer;
}
.seg span:hover { color: var(--text); }
.seg input:checked + span { color: var(--text); background: var(--field); }
.seg input:focus-visible + span { outline: 2px solid var(--text); outline-offset: 1px; }

/* 결과 */
.out {
  min-height: 3em;
  padding: 14px 16px;
  font-family: var(--mono);
  font-size: 0.92rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--field);
  border-radius: 14px;
}
.status { min-height: 1.5em; font-size: 0.92rem; color: var(--muted); }
.status.ok, .ok { color: var(--ok); }
.status.err, .err { color: var(--bad); }
.result { font-size: 1.6rem; font-weight: 700; line-height: 1.3; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.stat { padding: 16px 10px; text-align: center; background: var(--field); border-radius: 16px; }
.stat b { display: block; font-size: 1.6rem; line-height: 1.2; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat span { font-size: 0.82rem; font-weight: 500; color: var(--muted); }
.kv { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.kv th, .kv td { padding: 11px 6px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.kv th { width: 34%; font-weight: 500; color: var(--muted); }
.kv td { overflow-wrap: anywhere; }
.kv tr:last-child > * { border-bottom: 0; }
.scroll-x { overflow-x: auto; }

/* ===== 설명 글 ===== */
.content h2 { margin: 1.7em 0 0.5em; font-size: 1.2rem; }
.content > h2:first-child { margin-top: 0; }
.content h3 { margin: 1.3em 0 0.25em; font-size: 1rem; }
.content p, .content li { color: var(--text-2); }
.content strong { color: var(--text); }
.content ul, .content ol { padding-left: 1.3em; }
.content a { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.content code { padding: 2px 6px; font-size: 0.88em; background: var(--field); border-radius: 6px; }
.content > :last-child { margin-bottom: 0; }
.page > * { max-width: 760px; }
.page h1 { margin-top: 0; }

/* ===== 사이드바 목록: 회색 아이콘 + 굵은 이름 ===== */
.list-panel { padding: 24px 18px 14px; }
.list-panel h2 { margin: 0 0 6px 10px; font-size: 1.05rem; }
.list-panel ul { margin: 0; padding: 0; list-style: none; }
.list-panel a {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 11px 10px;
  font-weight: 600;
  text-decoration: none;
  border-radius: 12px;
}
.list-panel a:hover { background: var(--field); }
.list-panel .icon { color: var(--muted); }

/* ===== 홈 ===== */
.hero h1 { margin: 0 0 8px; font-size: 2.2rem; }
.hero .lead { max-width: 640px; }
.search-box { position: relative; max-width: 640px; margin: 22px 0 14px; }
.search-box .icon { left: 16px; width: 20px; height: 20px; }
.search-box input { width: 100%; padding: 15px 16px 15px 48px; font-size: 1.05rem; border-radius: 16px; }
.tabs { display: flex; gap: 4px; margin: 0 -4px; padding: 0 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: none;
  padding: 9px 16px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-pressed="true"] { color: var(--text); background: var(--field); }
.cat { scroll-margin-top: 12px; }
.cat h2 { display: flex; align-items: center; gap: 10px; margin: 0 0 18px; font-size: 1.2rem; }
.cat h2 .icon { color: var(--muted); }
.cat .count { font-size: 0.95rem; font-weight: 600; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 124px;
  padding: 20px 12px;
  text-align: center;
  color: var(--text);
  text-decoration: none;
  background: var(--field);
  border-radius: 18px;
}
.card:hover { background: var(--field-hover); }
.card-icon { width: 30px; height: 30px; }
.card-name { font-size: 0.95rem; font-weight: 600; line-height: 1.3; }
.no-results { margin: 0; text-align: center; color: var(--muted); }

/* ===== 꼬리말 (모든 도구 목록) ===== */
.site-footer {
  margin-top: 20px;
  padding: 36px max(16px, calc((100% - 1200px) / 2)) 44px;
  font-size: 0.92rem;
  color: var(--muted);
  background: var(--surface);
}
.footer-tools { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 24px; }
.footer-cat { margin: 0 0 10px; font-weight: 700; color: var(--text); }
.footer-tools ul { margin: 0; padding: 0; list-style: none; }
.footer-tools li { margin: 7px 0; }
.footer-tools a, .footer-meta a { text-decoration: none; }
.footer-tools a:hover, .footer-meta a:hover { color: var(--text); }
.footer-langs { margin: 28px 0 0; text-align: center; }
.footer-langs a { text-decoration: none; }
.footer-langs a:hover { color: var(--text); }
.footer-meta { margin: 10px 0 0; text-align: center; }

/* ===== 광고 자리 (config.mjs 에 광고 ID 를 넣은 자리만 생김) ===== */
.ad { min-height: 90px; text-align: center; overflow: hidden; }
.ad-side { min-height: 250px; }

/* ===== 좁은 화면 ===== */
@media (max-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .ad-side { display: none; }
}
/* 휴대폰: 흰 섹션을 화면 끝까지 (앱처럼) */
@media (max-width: 640px) {
  .layout { gap: 12px; margin-top: 12px; padding: 0; }
  .main, .side { gap: 12px; }
  .panel, .tool, .content { padding: 22px 18px; }
  .list-panel { padding: 20px 10px 10px; }
  h1 { font-size: 1.55rem; }
  .hero h1 { font-size: 1.8rem; }
  .title-icon { width: 58px; height: 58px; border-radius: 16px; }
  .title-icon .icon { width: 28px; height: 28px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .site-header { gap: 8px; padding-block: 12px; }
  .header-search { display: none; }
  .lang-pick { margin-left: auto; }
  .lang-pick select { padding-right: 30px; background-position: right 10px center; }
  .site-footer { margin-top: 12px; }
}
@media (max-width: 360px) {
  .logo span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
