/* Yggtree Web — 종이와 잉크, 나무의 초록 */
:root {
  --paper: #f7f3ec;
  --paper-2: #efe9df;
  --sheet: #fffdf9;
  --ink: #1f1d1a;
  --ink-2: #57524a;
  --ink-3: #8b857b;
  --line: #e2dbcf;
  --green: #2f5d4a;
  --green-2: #3f7a61;
  --green-soft: #e3ece6;
  --amber: #a5641f;
  --red: #b23b2e;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 8px 24px rgba(40, 30, 10, .06);
  --ui: "Inter", "Noto Sans KR", system-ui, sans-serif;
  --serif: "Noto Serif KR", "Fraunces", Georgia, serif;
  --display: "Fraunces", "Noto Serif KR", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 14px/1.5 var(--ui);
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; font-weight: 600; }
h2 { font-size: 15px; }
.muted { color: var(--ink-2); }
.small-text { font-size: 12px; }

/* ── 버튼 ── */
button { font: inherit; cursor: pointer; border: 0; border-radius: 8px; }
button:disabled { opacity: .45; cursor: not-allowed; }
.primary { background: var(--green); color: #fff; padding: 10px 18px; font-weight: 600; }
.primary:hover:not(:disabled) { background: var(--green-2); }
.secondary { background: var(--sheet); color: var(--ink); padding: 10px 14px; font-weight: 600; border: 1px solid var(--line); }
.secondary:hover:not(:disabled) { border-color: var(--green); color: var(--green); }
.ghost { background: transparent; color: var(--ink-2); padding: 8px 12px; border: 1px solid var(--line); }
.ghost:hover { color: var(--ink); border-color: var(--ink-3); }
.small { padding: 6px 10px; font-size: 13px; }
.full { width: 100%; }
.link { background: none; color: var(--green); padding: 0; font-size: 12px; font-weight: 600; }
.icon { background: none; color: var(--ink-2); width: 34px; height: 34px; display: grid; place-items: center; }
.icon svg { width: 20px; height: 20px; }
.icon:hover { color: var(--ink); background: var(--paper-2); }

input, select, textarea {
  font: inherit; color: var(--ink);
  background: var(--sheet); border: 1px solid var(--line); border-radius: 8px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green-soft); border-color: var(--green-2); }
select { padding: 5px 8px; }

/* ── 상단 바 ── */
.topbar {
  height: 56px; flex: none;
  display: flex; align-items: center; gap: 18px;
  padding-inline: 18px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--green); }
.brand-mark { width: 24px; height: 24px; }
.brand-name { font: 600 19px var(--display); letter-spacing: -.01em; color: var(--ink); }
.work-head { flex: 1; display: flex; align-items: center; gap: 12px; min-width: 0; }
.title-input {
  flex: 0 1 460px; min-width: 120px;
  font: 600 17px var(--serif); border-color: transparent; background: transparent; padding: 6px 8px;
}
.title-input:hover { border-color: var(--line); }
.loc { color: var(--ink-3); font-size: 13px; white-space: nowrap; }
.save-state { font-size: 12px; color: var(--ink-3); white-space: nowrap; }
.save-state.ok::before { content: "●"; color: var(--green-2); margin-inline-end: 6px; }
.save-state.pending::before { content: "●"; color: var(--amber); margin-inline-end: 6px; }
.save-state.err { color: var(--red); }
.top-actions { margin-inline-start: auto; display: flex; align-items: center; gap: 6px; }
.lang { display: flex; align-items: center; gap: 4px; color: var(--ink-2); padding-inline: 6px; border-radius: 8px; }
.lang svg { width: 17px; height: 17px; }
.lang select { border: 0; background: transparent; padding: 6px 2px; cursor: pointer; }
.lang:hover { background: var(--paper-2); }

/* ── 홈 ── */
.screen { flex: 1; overflow: auto; }
.center { display: flex; justify-content: center; align-items: flex-start; padding: 9vh 24px 40px; }
.home { width: min(680px, 100%); }
.eyebrow { color: var(--green); font-weight: 600; font-size: 13px; letter-spacing: .04em; text-transform: uppercase; margin: 0 0 10px; }
.display { font: 600 38px/1.15 var(--display); letter-spacing: -.02em; }
.lead { font-size: 16px; line-height: 1.65; margin: 14px 0 28px; max-width: 58ch; }
.folder-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.folder-name { color: var(--ink-2); font-size: 13px; }
.folder-name:not(:empty)::before { content: "📁 "; }
.works-panel { margin-top: 36px; background: var(--sheet); border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); }
.works-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.works-list { list-style: none; margin: 0; padding: 0; }
.works-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 10px; border-top: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
.works-list li:first-child { border-top: 0; }
.works-list li:hover { background: var(--paper); }
.work-name { font: 500 15px var(--serif); }
.work-meta { color: var(--ink-3); font-size: 12px; }
.card { background: var(--sheet); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.card h1 { font: 600 24px var(--display); margin-bottom: 10px; }
.narrow { max-width: 520px; }

/* ── 작업실 ── */
.studio {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 280px minmax(0, 1fr) 360px;
}
.side {
  border-inline-end: 1px solid var(--line); overflow: auto;
  display: flex; flex-direction: column; gap: 4px; padding: 14px;
}
.side-block { padding: 10px 4px 14px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.side-block:last-child { border-bottom: 0; }
.side-block.grow { flex: 1; }
.label { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.chapter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 5px; max-height: 210px; overflow: auto; }
.chapter-grid button {
  background: var(--sheet); border: 1px solid var(--line); padding: 6px 0; font-size: 12px; color: var(--ink-2);
}
.chapter-grid button:hover { border-color: var(--green-2); color: var(--green); }
.chapter-grid button.active { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
.tree-preview {
  font: 13px/1.6 var(--serif); color: var(--ink-2);
  max-height: 140px; overflow: hidden; position: relative; white-space: pre-wrap;
}
.tree-preview::after { content: ""; position: absolute; inset: auto 0 0 0; height: 40px; background: linear-gradient(transparent, var(--paper)); }
.tree-preview .dflt { color: var(--red); }
.progress { font-size: 12px; color: var(--green); white-space: pre-line; }
textarea.note { min-height: 130px; resize: vertical; padding: 10px; font: 13px/1.6 var(--serif); }

.editor { display: flex; flex-direction: column; min-width: 0; background: var(--paper-2); }
.paper {
  flex: 1; min-height: 0; overflow: auto;
  display: flex; justify-content: center; padding: 28px 24px 0;
}
textarea.body {
  width: min(760px, 100%); min-height: 100%;
  border: 0; border-radius: 4px 4px 0 0; resize: none;
  background: var(--sheet); box-shadow: var(--shadow);
  padding: 56px 64px 120px;
  font: 500 17px/2 var(--serif); letter-spacing: .005em; color: var(--ink);
}
textarea.body:focus { outline: none; }
.editor-foot { height: 34px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 12px; }

.chat { border-inline-start: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--paper); }
.chat-head { padding: 16px 16px 8px; }
.chat-log { flex: 1; overflow: auto; padding: 4px 14px 12px; display: flex; flex-direction: column; gap: 10px; }
.chat-empty { color: var(--ink-3); font-size: 13px; line-height: 1.6; padding: 8px 2px; }
.msg { max-width: 92%; padding: 9px 12px; border-radius: 12px; white-space: pre-wrap; line-height: 1.55; font-size: 13.5px; }
.msg.user { align-self: flex-end; background: var(--green); color: #fff; border-end-end-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--sheet); border: 1px solid var(--line); border-end-start-radius: 4px; }
.status { margin: 0 14px 10px; padding: 10px 12px; border-radius: 10px; font-size: 13px; background: var(--green-soft); color: var(--green); white-space: pre-wrap; }
.status.warn { background: #f8ecdc; color: var(--amber); }
.status.err { background: #f6e1de; color: var(--red); }
.status ul { margin: 6px 0 0; padding-inline-start: 18px; }
.chat-form { display: flex; gap: 6px; padding: 10px 14px; border-top: 1px solid var(--line); }
.chat-form textarea { flex: 1; resize: none; padding: 9px 10px; }
.send { color: var(--green); }
.actions { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 8px; padding: 4px 14px 16px; }
.arrow { display: inline-block; }
[dir="rtl"] .arrow { transform: scaleX(-1); }

/* ── 작업 중 ── */
.busy { position: fixed; inset: 0; background: rgba(247, 243, 236, .72); backdrop-filter: blur(2px); display: grid; place-items: center; z-index: 30; }
.busy-card { background: var(--sheet); border: 1px solid var(--line); border-radius: 14px; padding: 26px 32px; box-shadow: var(--shadow); text-align: center; display: grid; gap: 8px; justify-items: center; font-weight: 600; }
.spinner { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--green-soft); border-top-color: var(--green); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 대화상자 ── */
.dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--sheet); color: var(--ink); box-shadow: var(--shadow); width: min(480px, 94vw); }
.dialog.wide { width: min(980px, 96vw); }
.dialog::backdrop { background: rgba(31, 29, 26, .35); }
.dialog-inner { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.dialog h2 { font: 600 19px var(--display); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field input, .field select { padding: 9px 10px; }
.tree-edit { height: 64vh; padding: 14px; font: 14px/1.7 var(--serif); resize: vertical; }
.dialog-foot { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.dialog-foot span { margin-inline-end: auto; font-size: 13px; }

.toast { position: fixed; bottom: 22px; inset-inline-start: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 40; box-shadow: var(--shadow); }
[dir="rtl"] .toast { transform: translateX(50%); }

@media (max-width: 1100px) {
  .studio { grid-template-columns: 240px minmax(0, 1fr) 300px; }
  textarea.body { padding: 40px 36px 100px; }
}
