* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; font-family: system-ui, Segoe UI, sans-serif; color: #222; background: #eee; }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; border: 0; background: none; }

#auth { position: fixed; inset: 0; display: grid; place-items: center; background: #f4f1ed; }
#authForm { background: #fff; padding: 28px; border-radius: 14px; width: 320px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 4px 24px #0002; }
#authForm h1 { margin: 0 0 4px; font-size: 22px; text-align: center; }
#authForm input { padding: 10px; border: 1px solid #ccc; border-radius: 8px; font: inherit; }
#authForm button { padding: 10px; background: #f05a28; color: #fff; border-radius: 8px; font-weight: 600; }
#authForm a { text-align: center; font-size: 14px; color: #f05a28; }
.err { color: #c00; font-size: 13px; min-height: 16px; }

#app { display: flex; height: 100%; }
#sidebar { width: 480px; max-width: 45vw; background: #f4f1ed; display: flex; flex-direction: column; border-right: 1px solid #ddd; position: relative; transition: margin .2s; }
#sidebar.collapsed { margin-left: -480px; }
#sidebar header { padding: 20px; text-align: center; }
#sidebar h2 { margin: 0; font-weight: 500; }
#files { flex: 1; overflow: auto; padding: 8px 16px 90px; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px; align-content: start; }
.card { cursor: pointer; }
.thumb { position: relative; aspect-ratio: 816 / 1056; background: #fff; border: 2px solid transparent; border-radius: 6px; overflow: hidden; box-shadow: 0 1px 4px #0002; }
.card.open .thumb { border-color: #f05a28; }
.thumb .mini { position: absolute; top: 0; left: 0; width: 816px; transform-origin: 0 0; pointer-events: none; padding: 40px; font-size: 16px; }
.thumb .mini img { max-width: 100%; }
.thumb img.d { position: absolute; left: 0; top: 0; width: 100%; height: auto; }
.card .meta { display: flex; align-items: flex-start; justify-content: space-between; margin-top: 6px; }
.card .name { font-size: 15px; word-break: break-word; }
.card.open .name { color: #f05a28; }
.card .date { font-size: 12px; color: #555; }
.card .dots { font-size: 20px; padding: 0 6px; line-height: 1; color: #444; }
#sidebar nav { position: absolute; left: 0; right: 0; bottom: 0; height: 80px; display: flex; justify-content: space-around; align-items: flex-end; padding-bottom: 8px; background: linear-gradient(transparent, #f4f1ed 30%); }
.navbtn { display: flex; flex-direction: column; align-items: center; font-size: 15px; color: #666; width: 120px; }
.navbtn span { font-size: 26px; }
.navbtn.active { color: #f05a28; }
#newDoc { width: 64px; height: 64px; border-radius: 50%; background: #f05a28; color: #fff; font-size: 40px; line-height: 1; margin-bottom: 24px; box-shadow: 0 3px 10px #0004; }

main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; background: #fafafa; }
#tabs { display: flex; align-items: center; gap: 4px; background: #e4e0db; padding: 4px 6px 0; min-height: 38px; }
#toggleSidebar { width: 34px; height: 30px; border-radius: 50%; background: #666; color: #fff; margin-bottom: 4px; flex: none; }
#tabList { display: flex; overflow-x: auto; gap: 2px; align-items: flex-end; }
.tab { display: flex; align-items: center; gap: 6px; padding: 7px 8px 7px 14px; background: #cfc9c2; border-radius: 8px 8px 0 0; max-width: 200px; cursor: pointer; font-size: 14px; flex: none; }
.tab.active { background: #fafafa; font-weight: 600; }
.tab .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab .x { width: 20px; height: 20px; border-radius: 50%; line-height: 18px; color: #555; }
.tab .x:hover { background: #0002; }

#net { margin: 0 8px 4px auto; padding: 3px 10px; border-radius: 12px; background: #c0392b; color: #fff; font-size: 12px; flex: none; }
.card .off { display: block; font-size: 12px; color: #555; margin-top: 4px; cursor: pointer; }
.card .off input { vertical-align: middle; }

#toolbar { align-self: center; margin: 10px; padding: 6px 12px; background: #5a5a5a; border-radius: 24px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: center; color: #fff; z-index: 5; box-shadow: 0 2px 8px #0004; }
#toolbar button { min-width: 32px; height: 32px; border-radius: 16px; color: #fff; font-size: 16px; }
#toolbar button:hover { background: #ffffff30; }
#toolbar button.on { background: #f05a28; }
#toolbar select { height: 28px; border-radius: 8px; border: 0; }
#toolbar input[type=color] { width: 28px; height: 28px; padding: 0; border: 0; background: none; cursor: pointer; }
#toolbar input[type=range] { width: 80px; }
#textTools, #drawTools { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.sep { width: 1px; height: 22px; background: #fff5; margin: 0 6px; }

#stage { flex: 1; overflow: auto; padding: 10px 20px 90px; position: relative; }
#empty { text-align: center; color: #888; margin-top: 120px; }
#pageWrap { margin: 0 auto; width: max-content; }
#page { zoom: 1; position: relative; width: 816px; min-height: 1056px; background: #fff; box-shadow: 0 1px 8px #0003;
  background-image: repeating-linear-gradient(transparent 0 27px, #dde3ea 27px 28px); background-position: 0 70px; }
#title { display: block; width: 100%; border: 0; outline: 0; background: transparent; font-size: 28px; font-weight: 600; padding: 28px 56px 6px; }
#editor { min-height: 960px; outline: 0; padding: 4px 56px 60px; font-size: 16px; line-height: 28px; }
#editor img { max-width: 100%; height: auto; cursor: pointer; vertical-align: bottom; }
#editor img.sel { outline: 2px solid #f05a28; }
#editor h1, #editor h2, #editor h3 { line-height: 1.3; margin: 0; }
#editor blockquote { margin: 0 0 0 8px; padding-left: 12px; border-left: 3px solid #ccc; color: #555; }
#editor p, #editor div { margin: 0; }
#draw { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; touch-action: none; }
#page.drawing #draw { pointer-events: auto; cursor: crosshair; }
#page.drawing #editor, #page.drawing #title { user-select: none; }

#zoom, #history { position: absolute; bottom: 18px; display: flex; align-items: center; background: #6a6a6a; color: #fff; border-radius: 24px; padding: 4px 6px; z-index: 6; }
#zoom { left: 18px; }
#history { right: 18px; }
#zoom button, #history button { width: 38px; height: 38px; font-size: 22px; color: #fff; border-radius: 50%; }
#zoomLabel { min-width: 56px; text-align: center; }
#status { position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%); font-size: 12px; color: #888; }

#menu { position: fixed; background: #fff; border-radius: 8px; box-shadow: 0 4px 16px #0004; z-index: 20; overflow: hidden; }
#menu button { display: block; width: 100%; padding: 10px 18px; text-align: left; }
#menu button:hover { background: #f4f1ed; }
#menu .danger { color: #c00; }
#settings { position: fixed; inset: 0; background: #0006; display: grid; place-items: center; z-index: 30; }
#settings .card { background: #fff; padding: 24px; border-radius: 12px; display: flex; flex-direction: column; gap: 10px; min-width: 260px; cursor: default; }
#settings button { padding: 10px; border-radius: 8px; background: #eee; }

@media (max-width: 800px) { #sidebar { position: absolute; z-index: 15; height: 100%; width: 85vw; max-width: none; } #sidebar.collapsed { margin-left: -90vw; } }
