@import url("https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard.min.css");
@import url("https://fonts.googleapis.com/css2?family=Gowun+Batang:wght@700&display=swap");

:root {
  --paper: #fafaf7;
  --desk: #e9e7e0;
  --surface: #ffffff;
  --ink: #1a1a1a;
  --ink-2: #3d3c38;
  --ink-3: #5f5e57;
  --rule: #dcdad2;
  --rule-2: #c7c4ba;
  --seal: #b0362a;
  --seal-soft: #f6e5e1;
  --good: #1f7a5a;
  --good-soft: #e3f0ea;
  --warn: #94670a;
  --warn-soft: #f6eedb;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --focus: #1d3a6e;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(26, 26, 26, .06), 0 8px 24px rgba(26, 26, 26, .08);
  --sans: "Pretendard", -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  --brand: "Gowun Batang", "AppleMyungjo", "Batang", serif;
  --header: 56px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; background: var(--paper); color: var(--ink);
  font: 15px/1.6 var(--sans); word-break: keep-all; overflow-wrap: anywhere;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--seal-soft); color: var(--ink); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.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; }

/* ── 버튼 ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--rule-2); background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: 14.5px; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: #f3f2ee; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #333230; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(26, 26, 26, .06); }
.btn.danger { color: var(--danger); }
.btn.icon { width: 44px; padding: 0; }
.btn svg { width: 18px; height: 18px; flex: none; }
.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 입력 ── */
.field { display: grid; gap: 6px; }
.field > label, .field > .label { font-size: 13px; font-weight: 700; color: var(--ink-2); }
.hint { font-size: 12.5px; color: var(--ink-3); }
.input, .textarea, .select {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--rule-2); border-radius: var(--radius-sm);
  background: var(--surface); font-size: 16px; line-height: 1.5; transition: border-color .15s, box-shadow .15s;
}
.textarea { resize: vertical; min-height: 72px; field-sizing: content; max-height: 320px; }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px rgba(29, 58, 110, .15); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%235f5e57' stroke-width='1.6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

.seg { display: inline-flex; border: 1px solid var(--rule-2); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.seg button { min-height: 40px; min-width: 44px; padding: 0 12px; border: 0; border-right: 1px solid var(--rule); background: transparent; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--ink-3); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }

/* ── 알림 ── */
.alert { padding: 12px 14px; border-radius: var(--radius-sm); font-size: 14px; line-height: 1.5; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.warn { background: var(--warn-soft); color: #6b4a06; }
.alert.info { background: #eef2f8; color: var(--focus); }
.toast-wrap { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: var(--radius-sm); box-shadow: var(--shadow); font-size: 14.5px; pointer-events: auto; animation: rise .2s ease-out; }
.toast.error { background: var(--danger); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

/* ── 브랜드 ── */
.brand { display: inline-flex; align-items: center; min-height: 44px; font-weight: 800; font-size: 17px; letter-spacing: -.02em; color: var(--ink); text-decoration: none; }

/* ── 로그인 ── */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: var(--desk); }
.auth-card { width: min(100%, 400px); background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); padding: 32px 28px; display: grid; gap: 20px; }
.auth-card h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.auth-card p.lead { margin: -12px 0 0; color: var(--ink-3); font-size: 14px; }
.auth-card section { display: grid; gap: 18px; }
.auth-card form { display: grid; gap: 16px; }
.auth-card .btn.primary { width: 100%; min-height: 48px; font-size: 15.5px; }

/* ── 앱 머리 ── */
.app-head { position: sticky; top: 0; z-index: 20; height: var(--header); display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 max(16px, env(safe-area-inset-left)); background: rgba(250, 250, 247, .92); backdrop-filter: saturate(1.4) blur(8px); border-bottom: 1px solid var(--rule); }
.app-head .who { display: flex; align-items: center; gap: 6px; color: var(--ink-3); font-size: 13.5px; }

/* ── 문서 목록 ── */
.list-wrap { width: min(100%, 980px); margin: 0 auto; padding: 28px 16px 64px; }
.list-top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.list-top h1 { margin: 0; font-size: 26px; letter-spacing: -.02em; }
.list-top h1 span { font-size: 15px; color: var(--ink-3); font-weight: 600; margin-left: 6px; }
.toolbar-row { display: flex; gap: 10px; margin: 20px 0 12px; flex-wrap: wrap; }
.toolbar-row .input { flex: 1 1 240px; }
.doc-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
.doc-item { display: grid; grid-template-columns: 4px 1fr auto; align-items: center; gap: 14px; border-bottom: 1px solid var(--rule); }
.doc-item .bar { align-self: stretch; margin: 12px 0; border-radius: 2px; background: var(--tone, var(--ink-3)); }
.doc-open { display: grid; gap: 2px; padding: 14px 0; text-align: left; background: none; border: 0; cursor: pointer; min-width: 0; }
.doc-open:hover .doc-title { text-decoration: underline; text-underline-offset: 3px; }
.doc-title { font-weight: 700; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta { font-size: 13px; color: var(--ink-3); display: flex; gap: 8px; flex-wrap: wrap; }
.tag { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; color: var(--tone, var(--ink-3)); }
.tag::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.empty { text-align: center; padding: 56px 16px; border: 1px dashed var(--rule-2); border-radius: var(--radius); color: var(--ink-3); background: var(--surface); }
.empty h2 { color: var(--ink); font-size: 18px; margin: 0 0 6px; }
.empty .row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }

/* ── 메뉴·대화상자 ── */
.menu { position: absolute; z-index: 30; min-width: 240px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px; }
.menu button { display: grid; gap: 1px; width: 100%; text-align: left; padding: 10px 12px; border: 0; background: none; border-radius: var(--radius-sm); cursor: pointer; }
.menu button:hover, .menu button:focus-visible { background: #f3f2ee; }
.menu button b { font-size: 14.5px; }
.menu button span { font-size: 12.5px; color: var(--ink-3); }
dialog { border: 0; border-radius: 14px; padding: 0; width: min(92vw, 440px); box-shadow: var(--shadow); color: var(--ink); }
dialog::backdrop { background: rgba(26, 26, 26, .35); }
.dlg { padding: 24px; display: grid; gap: 14px; }
.dlg h2 { margin: 0; font-size: 18px; }
.dlg p { margin: 0; color: var(--ink-2); font-size: 14.5px; }
.dlg .actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }

/* ── 편집기 ── */
.ed { height: calc(100dvh - var(--header)); display: grid; grid-template-rows: auto 1fr; }
.ed-bar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-bottom: 1px solid var(--rule); background: var(--surface); }
.ed-bar .title { flex: 1 1 auto; min-width: 80px; border-color: transparent; font-weight: 700; font-size: 16px; background: transparent; }
.ed-bar .title:hover { border-color: var(--rule); }
.status { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.status.error { color: var(--danger); font-weight: 600; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--good); }
.status.saving::before { background: var(--warn); }
.status.error::before { background: var(--danger); }
.ed-tabs { display: none; }
.ed-body { min-height: 0; display: grid; grid-template-columns: minmax(360px, 440px) 1fr; }
.ed-form { overflow-y: auto; padding: 20px 20px 80px; border-right: 1px solid var(--rule); background: var(--paper); overscroll-behavior: contain; }
.ed-prev { overflow: auto; background: var(--desk); padding: 20px; position: relative; overscroll-behavior: contain; }
.prev-note { position: sticky; top: 0; z-index: 2; margin: -4px auto 14px; max-width: 794px; display: grid; gap: 8px; }
.prev-frame { margin: 0 auto; transform-origin: top left; overflow: hidden; }
.prev-frame iframe { display: block; width: 794px; border: 0; background: transparent; }

fieldset { border: 0; margin: 0 0 22px; padding: 0; display: grid; gap: 14px; min-width: 0; }
legend { font-size: 13px; font-weight: 800; letter-spacing: .04em; color: var(--seal); padding: 0; margin-bottom: 12px; width: 100%; display: flex; align-items: center; gap: 10px; }
legend::after { content: ""; flex: 1; height: 1px; background: var(--rule); }
.group { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 14px; display: grid; gap: 12px; }
.group-h { display: flex; align-items: center; justify-content: space-between; font-weight: 800; font-size: 14px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pillars { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.pillars .col { display: grid; gap: 6px; }
.pillars .col > span { font-size: 12px; font-weight: 700; color: var(--ink-3); text-align: center; }
.pillars .select { padding: 8px 22px 8px 8px; background-position: right 7px center; font-size: 15px; min-height: 42px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn { min-height: 40px; padding: 0 14px; border: 1px solid var(--rule-2); border-radius: 999px; background: var(--surface); cursor: pointer; font-weight: 600; font-size: 14px; color: var(--ink-2); }
.chip-btn[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.pages-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.page-opt { position: relative; display: grid; gap: 2px; padding: 14px; min-height: 84px; border: 1.5px solid var(--rule-2); border-radius: var(--radius); background: var(--surface); cursor: pointer; text-align: left; }
.page-opt b { font: 700 26px/1 var(--brand); color: var(--tone, var(--ink)); }
.page-opt span { font-size: 13px; color: var(--ink-3); font-weight: 600; }
.page-opt[aria-pressed="true"] { border-color: var(--tone, var(--ink)); box-shadow: inset 0 0 0 1px var(--tone, var(--ink)); }
.page-opt[aria-pressed="true"]::after { content: "✓"; position: absolute; top: 10px; right: 12px; font-weight: 800; color: var(--tone, var(--ink)); }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--rule-2); border-radius: var(--radius-sm); background: var(--surface); }
.stepper button { width: 44px; min-height: 42px; border: 0; background: none; cursor: pointer; font-size: 18px; }
.stepper output { min-width: 64px; text-align: center; font-weight: 700; }

/* 저장 내역 */
.drawer { position: fixed; inset: var(--header) 0 0 auto; width: min(100vw, 380px); background: var(--surface); border-left: 1px solid var(--rule); box-shadow: var(--shadow); z-index: 25; display: grid; grid-template-rows: auto 1fr; transform: translateX(100%); transition: transform .2s ease-out; visibility: hidden; }
.drawer.open { transform: none; visibility: visible; }
.drawer-h { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--rule); }
.drawer-h h2 { margin: 0; font-size: 16px; }
.rev-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; }
.rev-list button { width: 100%; text-align: left; display: grid; gap: 2px; padding: 12px; border: 0; background: none; border-radius: var(--radius-sm); cursor: pointer; }
.rev-list button:hover, .rev-list button[aria-current="true"] { background: #f3f2ee; }
.rev-list b { font-size: 14.5px; }
.rev-list span { font-size: 12.5px; color: var(--ink-3); }

@media (min-width: 960px) {
  .ed.with-drawer .ed-body { margin-right: min(100vw, 380px); }
}

.loading-block { display: grid; place-items: center; gap: 10px; padding: 64px 16px; color: var(--ink-3); }

/* ── 반응형 ── */
@media (max-width: 959px) {
  .ed { grid-template-rows: auto auto 1fr; }
  .ed-tabs { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--rule); background: var(--surface); }
  .ed-tabs button { min-height: 44px; border: 0; background: none; font-weight: 700; color: var(--ink-3); cursor: pointer; border-bottom: 2px solid transparent; }
  .ed-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
  .ed-body { grid-template-columns: 1fr; }
  .ed-form { border-right: 0; }
  .ed-body[data-tab="form"] .ed-prev, .ed-body[data-tab="preview"] .ed-form { display: none; }
  .ed-prev { padding: 12px; }
}
@media (max-width: 640px) {
  body { font-size: 15px; }
  .app-head .who .email { display: none; }
  .ed-bar { padding: 8px 10px; gap: 4px; flex-wrap: wrap; }
  .ed-bar .title { order: 3; flex-basis: 100%; }
  .ed-bar .status { margin-left: auto; }
  .btn .label-long { display: none; }
  .two { grid-template-columns: 1fr; }
  .list-top h1 { font-size: 22px; }
  .doc-item { grid-template-columns: 4px 1fr auto; gap: 10px; }
  .auth-card { padding: 26px 20px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
