:root {
  --bg: #faf7f2;
  --panel: #ffffff;
  --ink: #221d18;
  --muted: #7a7066;
  --line: #e7dfd3;
  --accent: #8a3b2c;
  --accent-ink: #ffffff;
  --accent-soft: #f6e9e4;
  --ok: #2f6b4f;
  --ok-soft: #e4f1ea;
  --warn: #a8661a;
  --warn-soft: #fbf0dc;
  --err: #a32727;
  --err-soft: #fbe7e7;
  --radius: 12px;
  --sans: "Pretendard", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --serif: "Noto Serif KR", "Nanum Myeongjo", "Batang", "AppleMyungjo", serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 15px; line-height: 1.65; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { font-family: var(--serif); line-height: 1.35; margin: 0 0 .5em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .8em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
code { background: #f1ebe2; padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.muted { color: var(--muted); }
.tiny { font-size: .82rem; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: grid; gap: .5rem; margin: .8rem 0; }

/* layout */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: .8rem 1.4rem; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { font-family: var(--serif); font-weight: 700; font-size: 1.15rem; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--accent); }
.topbar nav { display: flex; gap: 1.1rem; }
.topbar nav a { color: var(--muted); font-size: .92rem; padding: .2rem 0; border-bottom: 2px solid transparent; }
.topbar nav a.on, .topbar nav a:hover { color: var(--ink); border-color: var(--accent); text-decoration: none; }
.wrap { max-width: 980px; margin: 0 auto; padding: 1.6rem 1.2rem 4rem; }
.bare { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.page-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.page-title h1 { margin: 0; }
.title-actions { display: flex; gap: .5rem; }
.cat { font-size: .8rem; color: var(--accent); letter-spacing: .04em; margin-bottom: .2rem; }
.sub { color: var(--muted); margin: .2rem 0 0; }
.crumbs { margin-bottom: .6rem; font-size: .9rem; }

/* controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: .55rem 1rem; border-radius: 10px; font: inherit; font-size: .92rem; cursor: pointer; transition: .12s; }
.btn:hover { border-color: #cfc4b4; text-decoration: none; background: #fffdf9; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.warn { background: var(--warn-soft); border-color: #ecd6a8; color: #7a4a0c; }
.btn.danger { color: var(--err); border-color: #e9c3c3; background: var(--err-soft); }
.btn.ghost { background: transparent; }
.btn.lg { padding: .8rem 1.4rem; font-size: 1rem; }
.btn.small { padding: .3rem .7rem; font-size: .82rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: .4rem .9rem; cursor: pointer; font: inherit; font-size: .88rem; }
.chip:hover, .chip.on { border-color: var(--accent); background: var(--accent-soft); }
.actions { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; margin-top: 1rem; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.3rem 1.4rem; margin-bottom: 1.1rem; }
.panel > h2:first-child { margin-bottom: .8rem; }
.form label { display: block; margin-bottom: .9rem; font-size: .9rem; font-weight: 600; }
.form label .hint, .hint { font-weight: 400; color: var(--muted); font-size: .8rem; margin-left: .3rem; }
.req { color: var(--accent); font-size: .72rem; font-weight: 600; margin-left: .3rem; }
input[type=text], input[type=password], input[type=number], select, textarea {
  display: block; width: 100%; margin-top: .3rem; padding: .6rem .75rem; border: 1px solid var(--line); border-radius: 9px; background: #fffefb; font: inherit; font-weight: 400; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; line-height: 1.6; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.check, .radio { display: flex !important; gap: .6rem; align-items: flex-start; font-weight: 400 !important; margin-bottom: .6rem !important; }
.check input, .radio input { margin-top: .35rem; }
.check.inline { display: inline-flex !important; margin: 0 !important; font-size: .85rem !important; }
fieldset.choice { border: 1px solid var(--line); border-radius: 10px; padding: .8rem 1rem .3rem; margin: 0 0 1rem; }
fieldset.choice legend { font-weight: 600; font-size: .9rem; padding: 0 .4rem; }
.presets { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.estimate { background: var(--accent-soft); border-radius: 8px; padding: .5rem .8rem; font-size: .88rem; }
.adv > summary { cursor: pointer; font-weight: 600; }
.adv[open] > summary { margin-bottom: .8rem; }
.provider { border-top: 1px dashed var(--line); padding-top: 1rem; margin-top: .6rem; }

/* flash / badges */
.flash { padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; background: var(--ok-soft); color: var(--ok); }
.flash.err { background: var(--err-soft); color: var(--err); }
.notice { background: var(--warn-soft); color: #7a4a0c; padding: .6rem .9rem; border-radius: 9px; font-size: .88rem; }
.badge { display: inline-block; font-family: var(--sans); font-size: .72rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; background: #eee6da; color: #5f554a; vertical-align: middle; margin-left: .4rem; }
.b-done { background: var(--ok-soft); color: var(--ok); }
.b-writing, .b-planning { background: var(--accent-soft); color: var(--accent); }
.b-error { background: var(--err-soft); color: var(--err); }
.b-paused, .b-outlined { background: var(--warn-soft); color: var(--warn); }
.pill { display: inline-block; font-size: .74rem; padding: .08rem .55rem; border-radius: 999px; background: #efe8dc; color: #5f554a; margin: 0 .15rem; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

/* cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; color: inherit; transition: .12s; }
.card:hover { text-decoration: none; border-color: #cfc4b4; transform: translateY(-1px); box-shadow: 0 4px 14px rgba(60, 40, 20, .07); }
.card h3 { margin: .5rem 0 .2rem; font-size: 1.08rem; }
.card-top { display: flex; justify-content: space-between; align-items: center; }
.card .meta { display: flex; gap: .9rem; color: var(--muted); font-size: .82rem; margin-top: .7rem; }
.empty { text-align: center; padding: 4rem 1rem; }
.empty-mark { font-size: 2.6rem; }
.bar { background: #efe8dc; border-radius: 999px; height: 7px; overflow: hidden; margin: .6rem 0 .3rem; }
.bar.big { height: 12px; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .5s; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .8rem; margin-bottom: 1.1rem; }
.stats > div { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: .7rem .9rem; }
.stats b { display: block; font-family: var(--serif); font-size: 1.35rem; }
.stats span { font-size: .78rem; color: var(--muted); }
.stats.small b { font-size: 1.1rem; }
.stats.small { margin: .6rem 0 1rem; }
.stats.small > div { background: #fffdf9; }

.log { background: #1e1b18; color: #e9e1d4; border-radius: 9px; padding: .8rem 1rem; font-size: .8rem; line-height: 1.55; white-space: pre-wrap; max-height: 190px; overflow: auto; margin: .6rem 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.logline { font-family: var(--serif); font-size: 1.1rem; margin-bottom: .4rem; }

.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-size: .78rem; color: var(--muted); font-weight: 600; padding: .4rem .5rem; border-bottom: 1px solid var(--line); }
.table td { padding: .55rem .5rem; border-bottom: 1px solid #f1eadf; vertical-align: top; }
.table th.num { text-align: right; }

.outline { display: grid; gap: .5rem; margin: .8rem 0; }
.oc { border: 1px solid var(--line); border-radius: 10px; padding: .5rem .9rem; background: #fffdf9; }
.oc summary { display: flex; align-items: center; gap: .6rem; cursor: pointer; list-style: none; }
.oc summary::-webkit-details-marker { display: none; }
.oc summary .ttl { font-weight: 600; }
.oc .no { font-size: .78rem; color: var(--accent); font-weight: 700; white-space: nowrap; }
.oc[open] summary { margin-bottom: .7rem; }
.toc { padding-left: 1.3rem; }

.downloads { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .8rem; margin-top: .8rem; }
.dl { display: block; border: 1px solid var(--line); border-radius: 10px; padding: .8rem 1rem; color: inherit; background: #fffdf9; }
.dl:hover { text-decoration: none; border-color: var(--accent); }
.dl b { display: block; font-family: var(--serif); font-size: 1.1rem; }
.dl span { display: block; font-size: .8rem; color: var(--muted); }
.dl em { display: block; font-style: normal; font-size: .78rem; color: var(--accent); margin-top: .3rem; }
.dl.off { opacity: .6; }

.editor-grid { display: grid; grid-template-columns: 1fr 300px; gap: 1.1rem; align-items: start; }
.manuscript { font-family: var(--serif); font-size: 1rem; line-height: 1.85; min-height: 60vh; }
.side textarea { margin-bottom: .6rem; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: .4rem .8rem; margin: 0; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 2rem 1.8rem; box-shadow: 0 10px 40px rgba(60, 40, 20, .08); }
.login-brand { font-family: var(--serif); font-size: 1.5rem; font-weight: 700; margin-bottom: .2rem; }
.login-card label { display: block; font-size: .9rem; font-weight: 600; margin: 1rem 0; }

.toast { position: fixed; left: 50%; bottom: 1.6rem; transform: translateX(-50%); background: #2a241f; color: #fff; padding: .65rem 1.1rem; border-radius: 10px; font-size: .9rem; z-index: 50; box-shadow: 0 6px 24px rgba(0, 0, 0, .25); }
.toast.err { background: var(--err); }

/* reader */
body.reader { --rbg: #fbf8f1; --rink: #251f19; --rmut: #8a7f72; --rline: #e5dccd; background: var(--rbg); color: var(--rink); }
body.reader[data-theme=sepia] { --rbg: #f1e6cf; --rink: #3b2f20; --rmut: #85735a; --rline: #dccbaa; }
body.reader[data-theme=night] { --rbg: #17150f; --rink: #d9d2c4; --rmut: #8f877a; --rline: #2e2a22; }
.reader-bar { position: sticky; top: 0; display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem; background: var(--rbg); border-bottom: 1px solid var(--rline); font-size: .88rem; z-index: 5; }
.reader-bar a { color: var(--rmut); }
.rb-title { flex: 1; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--serif); }
.rb-tools { display: flex; gap: .3rem; }
.rb-tools button { background: none; border: 1px solid var(--rline); color: var(--rink); border-radius: 8px; padding: .2rem .55rem; cursor: pointer; font: inherit; }
.reader-body { max-width: 680px; margin: 0 auto; padding: 2.5rem 1.4rem 5rem; font-family: var(--serif); font-size: 1.1rem; line-height: 1.95; }
.r-cover { text-align: center; padding: 4rem 0 2.5rem; }
.r-cover h1 { font-size: 2rem; }
.r-sub { color: var(--rmut); }
.r-author { margin-top: 2.5rem; }
.r-toc-h { text-align: center; margin: 2rem 0 1rem; }
.r-toc { list-style: none; padding: 0; margin: 0 0 3rem; }
.r-toc li { border-bottom: 1px solid var(--rline); }
.r-toc a { display: block; padding: .75rem .3rem; color: var(--rink); }
.r-toc .n { color: var(--rmut); font-size: .85em; margin-right: .8rem; }
.r-colophon { font-size: .8rem; color: var(--rmut); line-height: 1.7; }
.r-head { text-align: center; margin: 2rem 0 2.5rem; }
.r-num { color: var(--rmut); letter-spacing: .25em; font-size: .8rem; margin-bottom: .6rem; }
.r-text p { margin: 0 0 .1em; text-indent: 1em; text-align: justify; word-break: keep-all; }
.r-text p.first { text-indent: 0; }
.r-text h2 { margin: 2.2em 0 .8em; font-size: 1.2em; }
.r-text h3 { margin: 1.6em 0 .6em; font-size: 1.05em; }
.r-text blockquote { margin: 1.6em 0; padding: .2em 1.1em; border-left: 3px solid var(--rline); color: var(--rmut); }
.r-text blockquote p { text-indent: 0; }
.r-text ul { margin: 1em 0 1em 1.2em; padding: 0; }
.r-text .scene-break { text-align: center; text-indent: 0; color: var(--rmut); margin: 2em 0; }
.r-nav { display: flex; justify-content: space-between; margin-top: 3.5rem; padding-top: 1.2rem; border-top: 1px solid var(--rline); font-family: var(--sans); font-size: .92rem; }
.r-nav a { color: var(--rmut); }

@media (max-width: 760px) {
  .grid2, .editor-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .topbar { padding: .7rem 1rem; }
  .topbar nav { gap: .8rem; }
  .kv { grid-template-columns: 1fr; }
}
