:root {
  --bg: #faf8f4; --fg: #22201c; --muted: #8a857c; --line: #e3ded4; --card: #ffffff;
  --accent: #3b5bdb; --accent-fg: #fff; --note: #fff4d6; --note-line: #e9b949;
  --inner: #8a857c; --reader: #eef3ff; --attempt: #d9480f; --danger: #c92a2a;
  --serif: "Noto Serif KR", "Nanum Myeongjo", "Batang", serif;
  --sans: -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a18; --fg: #ebe7df; --muted: #9a958b; --line: #34312c; --card: #24221f;
    --accent: #7c95f5; --accent-fg: #111; --note: #3a3120; --note-line: #b8902f;
    --inner: #938d82; --reader: #232a3d; --attempt: #ff8a4c; --danger: #ff6b6b;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--sans); font-size: 16px; }
a { color: var(--accent); }
button, select, textarea, input { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 8px 12px;
  min-height: 40px; cursor: pointer;
}
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button:disabled { opacity: .4; cursor: default; }
select { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 6px 8px; min-height: 40px; }

/* 상단 */
header.top {
  position: sticky; top: 0; z-index: 10; background: var(--bg); border-bottom: 1px solid var(--line);
  padding: 8px 12px;
}
header.top h1 { font-size: 17px; margin: 0 0 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header.top h1 a { text-decoration: none; color: var(--muted); font-weight: normal; }
.controls, .options { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.options { margin-top: 6px; font-size: 14px; }
.working { font-size: 14px; color: var(--accent); min-height: 20px; margin-top: 4px; }
.working:empty::before { content: " "; }

details.board { border-bottom: 1px solid var(--line); padding: 6px 12px; font-size: 14px; }
details.board summary { cursor: pointer; color: var(--muted); }
.board dl { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 6px 0; }
.board dt { color: var(--muted); }
.board dd { margin: 0; }
.notes-dir { margin: 4px 0 0; padding: 0; list-style: none; }
.notes-dir li { display: flex; gap: 8px; align-items: center; margin: 4px 0; }
.notes-dir button { min-height: 28px; padding: 2px 8px; font-size: 13px; }

.viewtabs { display: flex; gap: 0; padding: 8px 12px 0; }
.viewtabs button { border-radius: 0; flex: 1; border-bottom: 2px solid transparent; background: transparent; border-width: 0 0 2px; }
.viewtabs button.on { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }

/* 본문 */
main { padding: 12px 16px 170px; max-width: 760px; margin: 0 auto; }
#ms { font-family: var(--serif); font-size: 17px; line-height: 1.85; }
#ms h2 { font-family: var(--sans); font-size: 20px; margin: 8px 0 20px; }
#ms p { margin: 0 0 1em; white-space: pre-wrap; word-break: keep-all; overflow-wrap: anywhere; }
#ms p.inner { color: var(--inner); font-style: italic; }
#ms p.reader { background: var(--reader); padding: 6px 10px; border-radius: 6px; }
#ms p.break { text-align: center; color: var(--muted); letter-spacing: .4em; }
#ms p.interlude { font-family: var(--sans); font-weight: 600; color: var(--muted); }
#ms .empty, #feed .empty { color: var(--muted); font-family: var(--sans); font-size: 15px; }

#feed { font-size: 15px; line-height: 1.6; }
.ev { padding: 6px 0 6px 10px; border-left: 3px solid transparent; margin: 2px 0; overflow-wrap: anywhere; }
.ev .seq { color: var(--muted); font-size: 12px; margin-right: 6px; font-variant-numeric: tabular-nums; }
.ev .who { font-size: 12px; color: var(--muted); display: block; }
.ev .ms { font-size: 13px; color: var(--muted); display: block; font-family: var(--serif); }
.ev.inner { color: var(--inner); font-style: italic; }
.ev.reader_note { background: var(--reader); border-radius: 6px; }
.ev.attempt, .ev.resolution { border-left-color: var(--attempt); }
.ev .link { color: var(--attempt); font-size: 12px; display: block; }
.ev.hl { background: color-mix(in srgb, var(--attempt) 12%, transparent); }
.ev.sys { font-size: 12px; color: var(--muted); padding: 2px 0 2px 10px; }
.ev.sys.warn { color: var(--danger); }
.ev.note { background: var(--note); border: 1px solid var(--note-line); border-radius: 8px; padding: 8px 10px; margin: 8px 0; }
.ev.note b { font-size: 12px; display: block; }
.ev.scene { margin: 18px 0 6px; padding: 8px 10px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.ev.scenebreak { text-align: center; color: var(--muted); font-size: 13px; }

#newbtn {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 150px; z-index: 11; display: none;
  background: var(--accent); color: var(--accent-fg); border: 0; border-radius: 20px; padding: 6px 16px; min-height: 34px;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}

/* 하단 감독 메모 */
footer.notebox {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--bg);
  border-top: 2px solid var(--note-line); padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
}
footer.notebox textarea {
  width: 100%; min-height: 56px; max-height: 30vh; resize: vertical; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px; background: var(--card);
}
footer.notebox.flash textarea { outline: 3px solid var(--note-line); }
footer.notebox .row { display: flex; gap: 6px; margin-top: 6px; }
footer.notebox .row button { flex: 1; }
footer .label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }

/* 모달 */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: none; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.modal.on { display: flex; }
.modal .box { background: var(--card); border-radius: 12px; padding: 18px; max-width: 420px; width: 100%; }
.modal .box p { line-height: 1.6; margin: 0 0 14px; }
.modal .row { display: flex; gap: 8px; }
.modal .row button { flex: 1; }

/* 목록 */
.list { padding: 16px; max-width: 760px; margin: 0 auto; }
.card { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin: 10px 0; text-decoration: none; color: var(--fg); }
.card small { color: var(--muted); }
.toast { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); background: var(--danger); color: #fff; padding: 8px 14px; border-radius: 8px; z-index: 30; display: none; max-width: 90vw; }

/* M4: 링크 버튼, 업로드, 로그인, 작품·회차 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); background: var(--card);
  border-radius: 8px; padding: 8px 12px; min-height: 40px; color: var(--fg); text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 14px; }
.upload { cursor: pointer; }
.notice { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); margin: 10px 0; font-size: 15px; }
.notice.ok { border-color: #2f9e44; }
.notice.bad { border-color: var(--danger); }
.notice ul { margin: 6px 0 0; padding-left: 20px; font-size: 14px; }
.err { color: var(--danger); }
.card.ep a { color: var(--fg); text-decoration: none; }
.card .row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.login { max-width: 360px; margin: 18vh auto 0; padding: 0 16px; }
.login h1 { font-size: 22px; margin-bottom: 18px; }
.login label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.login input { width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 10px; min-height: 44px; }
.login button { width: 100%; margin-top: 12px; }
main.reading { padding-bottom: 40px; font-family: var(--serif); font-size: 17px; line-height: 1.85; }
main.reading h2 { font-family: var(--sans); font-size: 20px; }
main.reading p { margin: 0 0 1em; white-space: pre-wrap; word-break: keep-all; overflow-wrap: anywhere; }
main.reading p.inner { color: var(--inner); font-style: italic; }
main.reading p.reader { background: var(--reader); padding: 6px 10px; border-radius: 6px; }
main.reading p.break { text-align: center; color: var(--muted); letter-spacing: .4em; scroll-margin-top: 120px; }
main.reading p.interlude { font-family: var(--sans); font-weight: 600; color: var(--muted); }
.pager { display: flex; justify-content: space-between; margin-top: 24px; font-family: var(--sans); }
.seg { display: inline-flex; }
.seg button { border-radius: 0; min-height: 36px; }
.seg button:first-child { border-radius: 8px 0 0 8px; }
.seg button:last-child { border-radius: 0 8px 8px 0; }
.seg button.on { background: var(--accent); color: var(--accent-fg); opacity: 1; }
header.top h1 a { color: var(--muted); text-decoration: none; font-weight: normal; }

/* M5: 기기 관리, 편집본 */
.row-form { display: flex; gap: 6px; margin: 6px 0 10px; }
.row-form input { flex: 1; border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 8px; min-height: 40px; }
pre.token { white-space: pre-wrap; word-break: break-all; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px; font-size: 13px; }
.seg button:disabled { opacity: .4; }
.warn-line { color: var(--danger); font-family: var(--sans); font-size: 14px; margin-bottom: 12px; }
