:root {
  --bg: #fafaf8; --fg: #1f2328; --muted: #6b7280; --line: #e2e2dc; --card: #fff;
  --accent: #3b6fd8; --accent-fg: #fff; --ok: #1a7f4b; --warn: #b45309; --danger: #c0392b;
  --read-bg: #fffefb;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a; --fg: #e6e6e3; --muted: #9aa0a6; --line: #2a2e35; --card: #1b1e24;
    --accent: #6d97f0; --accent-fg: #0b1220; --ok: #4cc38a; --warn: #f0a04b; --danger: #ff7a6b;
    --read-bg: #181b20;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: .4rem 0 .2rem; }
h2 { font-size: 1rem; margin: 1.2rem 0 .5rem; color: var(--muted); font-weight: 600; }

.top {
  display: flex; justify-content: space-between; align-items: center;
  padding: .7rem max(16px, env(safe-area-inset-left)); border-bottom: 1px solid var(--line);
  background: var(--card); position: sticky; top: 0; z-index: 5;
}
.logo { font-weight: 700; font-size: 1.1rem; color: var(--fg); }
.view { max-width: 760px; margin: 0 auto; padding: 14px 16px 90px; }
.back { display: inline-block; margin-bottom: .4rem; font-size: .9rem; }
.sub { color: var(--muted); font-size: .88rem; }
.sub.jp { font-size: .8rem; opacity: .8; }
.summary { white-space: pre-wrap; color: var(--muted); font-size: .88rem; }
.empty { color: var(--muted); }

button, .btn, input, select, textarea { font: inherit; color: inherit; }
button, .btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 8px;
  padding: .42rem .8rem; cursor: pointer; min-height: 36px; display: inline-flex; align-items: center; justify-content: center;
}
button:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: default; pointer-events: none; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; font-weight: 600; }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; background: var(--card); padding: .5rem .65rem;
}
textarea { resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: .88rem; }
input[type=number] { width: 5.2rem; }

.urlform { display: flex; gap: .5rem; }
.urlform input { flex: 1; min-width: 0; }
.error { color: var(--danger); margin: .5rem 0; white-space: pre-wrap; }
.notice { background: color-mix(in srgb, var(--accent) 10%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); padding: .6rem .8rem; border-radius: 8px; font-size: .9rem; }

.cards { display: grid; gap: .6rem; }
.card { display: flex; flex-direction: column; gap: .15rem; padding: .8rem 1rem; background: var(--card); border: 1px solid var(--line); border-radius: 10px; color: var(--fg); }
.card:hover { text-decoration: none; border-color: var(--accent); }

.toolbar { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin: .8rem 0; }
.toolbar.sticky { position: sticky; top: 49px; z-index: 4; background: var(--bg); padding: .4rem 0; margin: .4rem 0 0; }
.toolbar input { width: 4.4rem; }

.eplist { list-style: none; margin: .5rem 0 0; padding: 0; }
.ep .chapter { margin: 1rem 0 .3rem; font-weight: 600; color: var(--muted); font-size: .88rem; }
.ep .row { display: flex; align-items: center; gap: .5rem; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.ep-title { flex: 1; min-width: 0; color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ep-title .no { display: inline-block; min-width: 2.6em; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip { font-size: .78rem; padding: .1rem .5rem; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; min-height: 0; }
.chip.ok { color: var(--ok); border-color: var(--ok); }
.chip.part { color: var(--warn); border-color: var(--warn); }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem; }
.chips .chip { cursor: pointer; }

.field { display: block; margin: 1rem 0; }
.field .label { display: block; font-weight: 600; margin-bottom: .25rem; }
.field .hint { display: block; color: var(--muted); font-size: .82rem; margin-top: .25rem; }

.progress { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; margin: .3rem 0; }
.progress .fill { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.status { color: var(--muted); font-size: .85rem; margin: .2rem 0 .6rem; }

.reading {
  background: var(--read-bg-c, var(--read-bg)); color: var(--read-color, var(--fg));
  border: 1px solid var(--line); border-radius: 10px;
  padding: 1.1rem var(--read-pad-x, 18px);
  font-family: var(--read-font, "Noto Serif KR", "Nanum Myeongjo", Georgia, serif);
  font-size: var(--read-size, 17px); font-weight: var(--read-weight, 400);
  line-height: var(--read-lh, 1.85);
  word-break: var(--word-break, keep-all); overflow-wrap: break-word;
}
body.break-all .reading { --word-break: break-all; }
body.nav-pb .reading { margin-bottom: calc(50vh - 5rem); }
.reading .ln { margin-bottom: var(--sentence-gap, 4px); }
.reading .ln p { margin: 0; }
.reading .tr { white-space: pre-line; }
.reading .tr:not(.title) { text-indent: var(--indent, 1em); }
.reading .title { font-size: 1.2em; font-weight: 700; margin-bottom: .2rem; }
body.no-head .reading .ln:first-child { display: none; }
.reading .gap { height: .9em; }
body.no-empty .reading .gap { display: none; }
body.pb .reading .ln { margin-bottom: calc(var(--sentence-gap, 4px) + .7em); }
body.qb .reading .ln.quote { margin-top: calc(var(--sentence-gap, 4px) + .4em); margin-bottom: calc(var(--sentence-gap, 4px) + .4em); }
.reading .pending .tr { color: var(--muted); opacity: .7; }
.reading .blocked .tr { color: var(--danger); text-decoration: underline dotted; }
.reading .orig, .reading .gt, .reading .rm { display: none; font-size: .82em; font-family: system-ui, "Yu Gothic", "Hiragino Sans", sans-serif; }
body.show-orig .reading .orig, body.show-orig .reading .gt:not(:empty), body.show-orig .reading .rm:not(:empty) { display: block; opacity: var(--orig-opacity, .6); }
body.show-orig .reading .pending .orig { display: none; }
.reading .ln:not(.pending) { cursor: pointer; }
.reading .ln.open .orig, .reading .ln.open .gt:not(:empty), .reading .ln.open .rm:not(:empty) { display: block; opacity: .85; }
.reading .ln.open .tr { background: color-mix(in srgb, var(--accent) 10%, transparent); border-radius: 4px; }
body.show-orig .reading .gt { color: var(--accent); }
body.orig-first .reading .ln { display: flex; flex-direction: column; }
body.orig-first .reading .orig { order: -1; }
body.orig-first .reading .rm { order: -1; }

.reading .pgclip { overflow: hidden; }
.reading.pagination .pg { column-gap: 0; column-fill: auto; transition: transform .15s ease; }
.reading.pagination .ln, .reading.pagination .gap { break-inside: avoid; }
@media (prefers-reduced-motion: reduce) { .reading.pagination .pg { transition: none; } }

.statusbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; gap: .6rem; align-items: center; justify-content: space-between;
  padding: .6rem max(14px, env(safe-area-inset-left)) calc(.6rem + env(safe-area-inset-bottom));
  background: var(--accent); color: var(--accent-fg); font-size: .88rem;
}
.statusbar a { color: inherit; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.statusbar button { background: transparent; color: inherit; border-color: color-mix(in srgb, var(--accent-fg) 60%, transparent); min-height: 32px; }
.toast { position: fixed; left: 50%; bottom: 70px; transform: translateX(-50%); background: #222; color: #fff; padding: .5rem .9rem; border-radius: 8px; z-index: 20; max-width: 90vw; font-size: .88rem; }

@media (min-width: 700px) { body { font-size: 16px; } .reading { padding-top: 1.6rem; padding-bottom: 1.6rem; } }

.section { border: 1px solid var(--line); border-radius: 10px; padding: .2rem .9rem; margin: .8rem 0; background: var(--card); }
.section .section { background: transparent; }
.section > summary { cursor: pointer; font-weight: 700; padding: .6rem 0; }
details > summary { cursor: pointer; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .2rem .8rem; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.toggle small { display: block; color: var(--muted); font-size: .8rem; }
.toggle input { width: 1.25rem; height: 1.25rem; flex: none; }
textarea.plain { font-family: inherit; }
.defprompt { white-space: pre-wrap; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .6rem; font-size: .8rem; max-height: 18rem; overflow: auto; }
.modelload { margin-bottom: .6rem; }
