:root {
  --bg: #f6f2ec; --panel: #fff; --ink: #2f2820; --muted: #8b7f72; --line: #e8e0d5;
  --accent: #8a6d3b; --accent-2: #b8955a; --danger: #c0392b; --ok: #2e7d4f; --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: Inter, system-ui, sans-serif; font-size: 14px; color: var(--ink); background: var(--bg); }
[hidden] { display: none !important; }
.brand { font-family: 'Cormorant Garamond', Georgia, serif; font-size: 30px; font-weight: 600; margin: 0; color: var(--accent); letter-spacing: .01em; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.row { display: flex; gap: 10px; align-items: center; }
.spacer { flex: 1; }
input, select, textarea { font: inherit; color: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; background: #fff; width: 100%; outline: none; transition: border .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--accent-2); }
input[type=color] { padding: 2px; height: 38px; cursor: pointer; }
input[type=range] { padding: 0; border: 0; accent-color: var(--accent); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }
label { display: block; font-weight: 500; font-size: 13px; }
label > input, label > select, label > textarea { margin-top: 5px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 8px; padding: 10px 16px; font: 500 14px Inter, sans-serif; cursor: pointer; transition: all .15s; text-decoration: none; color: var(--ink); background: #fff; white-space: nowrap; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: #765c30; }
.btn.ghost { border-color: var(--line); background: #fff; }
.btn.ghost:hover { border-color: var(--accent-2); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

/* login */
#login { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); padding: 36px 30px; border-radius: 16px; box-shadow: 0 20px 50px rgba(80,60,30,.1); display: grid; gap: 14px; text-align: center; }
.login-card label { text-align: left; }
.error { color: var(--danger); min-height: 1em; margin: 0; }

/* home */
#home { display: grid; grid-template-columns: 240px 1fr; min-height: 100%; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 24px 16px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
#folderNav { display: grid; gap: 2px; overflow-y: auto; }
.folder { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 8px; cursor: pointer; color: var(--ink); }
.folder:hover { background: var(--bg); }
.folder.active { background: #f1e8d9; font-weight: 600; }
.folder .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder .count { color: var(--muted); font-size: 12px; }
.folder .fa { display: none; border: 0; background: none; cursor: pointer; padding: 2px 4px; color: var(--muted); font-size: 13px; }
.folder:hover .fa { display: inline; }
.folder.drop-over { outline: 2px dashed var(--accent-2); }
.folder-sep { height: 1px; background: var(--line); margin: 8px 4px; }
.sidebar-foot { margin-top: auto; }
.home-main { padding: 28px 34px; min-width: 0; }
.home-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.home-head h2 { margin: 0; font-family: 'Cormorant Garamond', serif; font-size: 32px; font-weight: 600; }
.home-head p { margin: 4px 0 0; }
#search { width: 220px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 22px; }
.card { background: var(--panel); border-radius: 12px; overflow: hidden; box-shadow: 0 2px 10px rgba(80,60,30,.06); transition: transform .15s, box-shadow .15s; position: relative; }
.card:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(80,60,30,.12); }
.card .cover { aspect-ratio: 3/4; background: #efe7da center/cover no-repeat; cursor: pointer; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.card .info { padding: 12px 14px; }
.card .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .meta { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: 12px; color: var(--muted); }
.pill { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 10px; background: #eee; color: #777; }
.pill.on { background: #e3f2e8; color: var(--ok); }
.card .menu-btn { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; border-radius: 50%; border: 0; background: rgba(255,255,255,.92); cursor: pointer; font-size: 18px; line-height: 1; box-shadow: 0 2px 6px rgba(0,0,0,.1); }
.dropdown { position: fixed; background: #fff; border-radius: 10px; box-shadow: 0 12px 30px rgba(0,0,0,.16); padding: 6px; z-index: 100; min-width: 190px; }
.dropdown button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 12px; border-radius: 6px; font: inherit; cursor: pointer; }
.dropdown button:hover { background: var(--bg); }
.dropdown button.danger { color: var(--danger); }
.empty { text-align: center; padding: 80px 20px; color: var(--muted); }

/* editor */
#editor { height: 100vh; display: flex; flex-direction: column; }
.ed-top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.title-input { border-color: transparent; font-weight: 600; font-size: 16px; max-width: 340px; }
.title-input:hover { border-color: var(--line); }
.save-state { font-size: 12px; color: var(--muted); white-space: nowrap; }
.save-state.saving { color: var(--accent); }
.save-state.err { color: var(--danger); }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.switch input { display: none; }
.switch span { width: 38px; height: 22px; border-radius: 11px; background: #d9d2c8; position: relative; transition: .2s; flex: none; }
.switch span::after { content: ''; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { left: 19px; }
.switch b { font-weight: 500; min-width: 64px; }

.ed-body { flex: 1; display: grid; grid-template-columns: 170px 1fr 320px; min-height: 0; }
.ed-pages { background: var(--panel); border-right: 1px solid var(--line); padding: 14px 12px; overflow-y: auto; }
.ed-pages-head { display: flex; justify-content: space-between; margin-bottom: 10px; }
.add-pages { display: grid; gap: 6px; margin-bottom: 14px; }
.page-list { display: grid; gap: 12px; }
.pthumb { position: relative; cursor: pointer; border-radius: 6px; padding: 4px; border: 2px solid transparent; }
.pthumb.active { border-color: var(--accent); background: #faf5ec; }
.pthumb img { width: 100%; display: block; border-radius: 3px; box-shadow: 0 2px 6px rgba(0,0,0,.12); pointer-events: none; }
.pthumb .n { position: absolute; left: 8px; bottom: 8px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 8px; }
.pthumb .ec { position: absolute; right: 8px; bottom: 8px; background: var(--accent); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 8px; }
.sortable-ghost { opacity: .35; }

.ed-canvas { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.tools { display: flex; gap: 6px; align-items: center; padding: 10px 16px; flex-wrap: wrap; border-bottom: 1px solid var(--line); background: #fbf8f3; }
.tools button { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 10px; cursor: pointer; font: 500 13px Inter, sans-serif; }
.tools button:hover { border-color: var(--accent-2); background: #fffaf2; }
.stage-area { flex: 1; position: relative; display: grid; place-items: center; padding: 20px; overflow: auto; min-height: 0; }
.stage-area.dragover { background: #efe5d4; }
.page-stage { position: relative; line-height: 0; box-shadow: 0 12px 34px rgba(60,40,10,.18); user-select: none; }
.page-stage img { max-width: 100%; max-height: calc(100vh - 210px); display: block; pointer-events: none; }
.overlay { position: absolute; inset: 0; }
.box { position: absolute; border: 2px dashed rgba(138,109,59,.9); background: rgba(184,149,90,.18); cursor: move; display: grid; place-items: center; overflow: hidden; touch-action: none; }
.box.sel { border-style: solid; border-color: #d35400; background: rgba(211,84,0,.14); z-index: 2; overflow: visible; }
.box .tag { font: 600 11px Inter, sans-serif; line-height: 1.2; color: #fff; background: rgba(0,0,0,.55); padding: 3px 6px; border-radius: 6px; pointer-events: none; max-width: 95%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.box .prev { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; opacity: .9; }
.box .rz { position: absolute; right: -7px; bottom: -7px; width: 14px; height: 14px; background: #d35400; border: 2px solid #fff; border-radius: 50%; cursor: nwse-resize; display: none; }
.box.sel .rz { display: block; }
.drop-hint { text-align: center; max-width: 420px; line-height: 1.6; }
.page-actions { display: flex; justify-content: center; gap: 8px; padding: 0 16px 14px; }

.ed-panel { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; background: none; padding: 13px; font: 600 13px Inter, sans-serif; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }
.tab-body { padding: 16px; overflow-y: auto; display: grid; gap: 14px; align-content: start; }
.group { display: grid; gap: 12px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.group:last-child { border-bottom: 0; }
.group h4 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; cursor: pointer; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.file-box { border: 1px dashed var(--line); border-radius: 8px; padding: 10px; display: grid; gap: 8px; font-size: 13px; }
.file-box img, .file-box video { max-width: 100%; max-height: 140px; border-radius: 6px; display: block; }
.file-box audio { width: 100%; }
.file-box .fname { word-break: break-all; color: var(--muted); font-size: 12px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: #fff; padding: 8px 6px; font: 500 12px Inter, sans-serif; cursor: pointer; }
.seg button.on { background: var(--accent); color: #fff; }
.slug-row { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-top: 5px; }
.slug-row span { padding: 0 0 0 10px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.slug-row input { border: 0; padding-left: 2px; margin: 0; }
.empty-el { color: var(--muted); text-align: center; padding: 30px 10px; line-height: 1.6; }

/* modal / progress / toast */
.modal { position: fixed; inset: 0; background: rgba(30,22,12,.45); display: grid; place-items: center; z-index: 200; padding: 20px; }
.modal-card { background: #fff; border-radius: 14px; padding: 24px; width: 100%; max-width: 400px; display: grid; gap: 14px; box-shadow: 0 30px 60px rgba(0,0,0,.25); }
.modal-card h3 { margin: 0; font-size: 18px; }
.modal-card .actions { display: flex; justify-content: flex-end; gap: 8px; }
.progress { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #2f2820; color: #fff; padding: 14px 18px; border-radius: 12px; z-index: 300; min-width: 300px; display: grid; gap: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.3); }
.progress .bar { height: 6px; background: rgba(255,255,255,.2); border-radius: 3px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent-2); transition: width .2s; }
.toast { position: fixed; left: 50%; top: 20px; transform: translateX(-50%); background: #2f2820; color: #fff; padding: 11px 18px; border-radius: 10px; z-index: 300; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.toast.err { background: var(--danger); }

@media (max-width: 900px) {
  #home { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .ed-body { grid-template-columns: 110px 1fr; }
  .ed-panel { grid-column: 1 / -1; max-height: 45vh; }
  .home-main { padding: 20px; }
}

textarea.mono { font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; min-height: 150px; white-space: pre; overflow-x: auto; }
.box iframe.prev { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; opacity: 1; }
