/* ===== 기본 리셋 & 토큰 ===== */
:root {
  --bg: #f5f5f4;            /* 페이지 배경 */
  --surface: #ffffff;      /* 카드/헤더 */
  --ink: #1c1a19;          /* 본문 글자 */
  --ink-soft: #6b6560;     /* 보조 글자 */
  --line: #e7e4e1;         /* 경계선 */
  --accent: #ff5b3a;       /* 포인트(웹툰 느낌의 코랄) */
  --accent-ink: #ffffff;
  --shadow: 0 6px 24px rgba(28, 26, 25, .08);
  --radius: 14px;
  --maxw: 900px;           /* 웹툰 스트립 최대 폭 */
}

* { box-sizing: border-box; }
/* hidden 속성은 항상 최우선으로 숨김 (아래 display:grid 등이 덮어쓰지 못하도록) */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
button { font-family: inherit; cursor: pointer; }
img { display: block; max-width: 100%; }

/* ===== 헤더 ===== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, .85);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto;
  height: 60px; padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between;
}
.brand {
  display: flex; align-items: center; gap: 9px;
  background: none; border: 0; padding: 4px; color: var(--ink);
}
.brand-mark { color: var(--accent); font-size: 22px; line-height: 1; }
.brand-name { font-weight: 800; font-size: 18px; letter-spacing: -.02em; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.who { color: var(--ink-soft); font-size: 13px; }

/* ===== 버튼 ===== */
.btn {
  border: 1px solid transparent; border-radius: 10px;
  padding: 9px 15px; font-size: 14px; font-weight: 700;
  transition: transform .05s ease, background .15s ease, border-color .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #ef4a2a; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: #efece9; }
.btn-block { width: 100%; padding: 12px; font-size: 15px; }
.icon-btn {
  background: none; border: 0; font-size: 18px; color: var(--ink-soft);
  width: 34px; height: 34px; border-radius: 8px;
}
.icon-btn:hover { background: #efece9; color: var(--ink); }

/* ===== 공통 뷰 ===== */
.view { max-width: 1080px; margin: 0 auto; padding: 28px 20px 80px; }

/* ===== 로그인 ===== */
#viewLogin { display: grid; place-items: center; min-height: calc(100vh - 60px); }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 36px 30px; text-align: center;
}
.login-logo { font-size: 44px; color: var(--accent); line-height: 1; }
.login-title { margin: 10px 0 4px; font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.login-sub { margin: 0 0 24px; color: var(--ink-soft); font-size: 14px; }
.login-form { display: grid; gap: 14px; text-align: left; }
.login-error { margin: 0; color: var(--accent); font-size: 13px; font-weight: 600; }

/* ===== 폼 필드 ===== */
.field { display: grid; gap: 6px; }
.field-grow { flex: 1; }
.field-label { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.field input[type="text"],
.field input[type="password"],
.field input[type="number"] {
  width: 100%; padding: 11px 13px; font-size: 15px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fafafa; color: var(--ink); outline: none;
  transition: border-color .15s ease, background .15s ease;
}
.field input:focus { border-color: var(--accent); background: #fff; }

/* ===== 목록 헤더 ===== */
.list-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.list-title { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.list-count { margin: 2px 0 0; color: var(--ink-soft); font-size: 14px; }
.sort-toggle {
  display: inline-flex; background: #ece9e6; border-radius: 10px; padding: 3px;
}
.sort-btn {
  border: 0; background: transparent; color: var(--ink-soft);
  padding: 8px 14px; font-size: 13px; font-weight: 700; border-radius: 8px;
}
.sort-btn.is-active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* ===== 에피소드 그리드 ===== */
.episode-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
}
.ep-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; text-align: left;
  padding: 0; transition: transform .12s ease, box-shadow .12s ease;
}
.ep-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.ep-cover {
  width: 100%; aspect-ratio: 3 / 4; object-fit: cover; background: #eceae8;
  display: block;
}
.ep-cover-empty {
  width: 100%; aspect-ratio: 3 / 4; background: linear-gradient(135deg, #f0ede9, #e3ded9);
  display: grid; place-items: center; color: #b9b2ab; font-size: 30px;
}
.ep-meta { padding: 12px 13px 14px; position: relative; }
.ep-badge {
  display: inline-block; background: #fff0ec; color: var(--accent);
  font-size: 12px; font-weight: 800; padding: 2px 8px; border-radius: 999px; margin-bottom: 6px;
}
.ep-name {
  margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ep-date { margin: 4px 0 0; font-size: 12px; color: var(--ink-soft); }
.ep-del, .ep-edit {
  position: absolute; top: 10px;
  background: rgba(255,255,255,.92); border: 1px solid var(--line);
  width: 26px; height: 26px; border-radius: 8px; font-size: 12px; color: var(--ink-soft);
  opacity: 0; transition: opacity .12s ease; display: grid; place-items: center; line-height: 1;
}
.ep-del { right: 10px; }
.ep-edit { right: 42px; }
.ep-card:hover .ep-del, .ep-card:hover .ep-edit { opacity: 1; }
.ep-del:hover, .ep-edit:hover { color: var(--accent); border-color: var(--accent); }
/* 터치 기기(hover 없음)에선 항상 보이게 → 모바일 관리자도 탭 가능 */
@media (hover: none) { .ep-del, .ep-edit { opacity: 1; } }

/* ===== 빈 상태 ===== */
.empty { text-align: center; padding: 70px 20px; color: var(--ink-soft); }
.empty-mark { font-size: 40px; opacity: .5; }
.empty-title { margin: 14px 0 4px; font-size: 17px; font-weight: 700; color: var(--ink); }
.empty-sub { margin: 0; font-size: 14px; }

/* ===== 뷰어 ===== */
.view-reader { padding-top: 20px; }
.reader-topinfo { max-width: var(--maxw); margin: 0 auto 14px; text-align: center; }
.reader-ep { color: var(--accent); font-weight: 800; font-size: 13px; }
.reader-title { margin: 4px 0 0; font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.reader-strip {
  max-width: var(--maxw); margin: 0 auto;
  background: #111; border-radius: 8px; overflow: hidden;
}
.reader-strip img { width: 100%; height: auto; display: block; }
.reader-strip .img-broken {
  display: grid; place-items: center; min-height: 160px;
  background: #1b1b1b; color: #9a9a9a; font-size: 14px;
}
.reader-sentinel { height: 1px; }
.reader-endbar { max-width: var(--maxw); margin: 24px auto 0; text-align: center; }

/* ===== 모달 ===== */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(20, 18, 17, .5);
  display: grid; place-items: center; padding: 20px;
}
.modal {
  width: 100%; max-width: 520px; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
  max-height: 90vh; display: flex; flex-direction: column;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 18px; font-weight: 800; }
.modal-body { padding: 20px; overflow-y: auto; display: grid; gap: 16px; }
.row2 { display: flex; gap: 12px; }
.row2 .field:first-child { width: 110px; flex: 0 0 110px; }
.modal-error { margin: 0; color: var(--accent); font-size: 13px; font-weight: 600; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

/* 드롭존 */
.drop {
  border: 2px dashed var(--line); border-radius: 12px; padding: 26px;
  text-align: center; cursor: pointer; transition: border-color .15s ease, background .15s ease;
}
.drop:hover, .drop.is-over { border-color: var(--accent); background: #fff6f4; }
.drop-inner { display: grid; gap: 6px; color: var(--ink-soft); }
.drop-mark { font-size: 26px; color: var(--accent); }
.drop-text { font-size: 13px; }

/* 썸네일 미리보기 */
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumbs:empty { display: none; }
.thumb {
  position: relative; width: 62px; height: 62px; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--line); background: #eee;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-idx {
  position: absolute; left: 3px; top: 3px; background: rgba(0,0,0,.6); color: #fff;
  font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 999px;
}

/* ===== 다음 화 팝업 ===== */
.nextpop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20, 18, 17, .5);
  display: grid; place-items: center; padding: 20px;
  animation: fade .18s ease;
}
.nextpop-card {
  position: relative;
  width: 100%; max-width: 380px; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 28px 26px; text-align: center;
  animation: pop .2s cubic-bezier(.2,.8,.3,1.2);
}
.nextpop-close {
  position: absolute; top: 10px; right: 10px;
  background: transparent; border: 0; color: var(--ink-soft);
  width: 32px; height: 32px; border-radius: 8px; font-size: 16px; line-height: 1;
}
.nextpop-close:hover { background: #efece9; color: var(--ink); }
.nextpop-dismiss {
  margin-top: 14px; background: none; border: 0; color: var(--ink-soft);
  font-size: 13px; text-decoration: underline; text-underline-offset: 3px; padding: 4px;
}
.nextpop-dismiss:hover { color: var(--ink); }
.nextpop-kicker { margin: 0 0 6px; color: var(--ink-soft); font-size: 14px; font-weight: 600; }
.nextpop-title { margin: 0 0 20px; font-size: 19px; font-weight: 800; letter-spacing: -.02em; }
.nextpop-actions { display: flex; gap: 10px; }
.nextpop-actions .btn { flex: 1; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ===== 상단 네비 ===== */
.topnav { display: flex; gap: 4px; margin-left: 18px; margin-right: auto; }
.nav-link {
  background: none; border: 0; padding: 8px 12px; border-radius: 8px;
  font-size: 14px; font-weight: 700; color: var(--ink-soft);
}
.nav-link:hover { background: #efece9; color: var(--ink); }
.nav-link.is-active { color: var(--accent); }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.linkbtn {
  background: none; border: 0; color: var(--ink-soft); font-size: 13px; font-weight: 700;
  padding: 4px 6px; border-radius: 6px;
}
.linkbtn:hover { color: var(--accent); background: #fff6f4; }

/* ===== 홈 섹션 ===== */
.home-section { margin-bottom: 34px; }
.section-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 14px;
}
.section-title { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -.02em; }
.section-head-btns { display: flex; align-items: center; gap: 8px; }
.section-empty { margin: 0; color: var(--ink-soft); font-size: 14px; padding: 8px 0; }

/* 공지 */
.notice-list { display: grid; gap: 10px; }
.notice {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-left: 4px solid var(--accent); border-radius: 10px; padding: 14px 16px;
}
.notice-main { flex: 1; min-width: 0; }
.notice-title { margin: 0 0 4px; font-size: 15px; font-weight: 800; }
.notice-body { margin: 0 0 6px; font-size: 14px; color: var(--ink); white-space: pre-wrap; word-break: break-word; }
.notice-date { margin: 0; font-size: 12px; color: var(--ink-soft); }
.notice-del {
  background: transparent; border: 1px solid var(--line); color: var(--ink-soft);
  width: 26px; height: 26px; border-radius: 8px; font-size: 12px; flex: 0 0 auto;
}
.notice-del:hover { color: var(--accent); border-color: var(--accent); }

/* 카테고리 가로 스크롤 줄 */
.cat-row {
  display: flex; gap: 16px; overflow-x: auto; padding: 4px 2px 12px;
  scroll-snap-type: x proximity;
}
.cat-row .ep-card { flex: 0 0 180px; scroll-snap-align: start; }
.cat-row::-webkit-scrollbar { height: 8px; }
.cat-row::-webkit-scrollbar-thumb { background: #d9d5d1; border-radius: 999px; }

/* ===== 카테고리 칩 ===== */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.chip {
  background: var(--surface); border: 1px solid var(--line); color: var(--ink-soft);
  padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 700;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ===== 뷰어 카테고리 뱃지 ===== */
.reader-cat {
  display: inline-block; margin-top: 8px; background: #fff0ec; color: var(--accent);
  font-size: 12px; font-weight: 800; padding: 3px 10px; border-radius: 999px;
}

/* ===== 댓글 ===== */
.comments {
  max-width: var(--maxw); margin: 32px auto 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px;
}
.comments-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.comments-title { margin: 0; font-size: 17px; font-weight: 800; }
.comments-title span { color: var(--accent); }
.comments-head .sort-btn { padding: 6px 12px; font-size: 12px; }
.comment-form { display: grid; gap: 8px; margin-bottom: 18px; }
.cm-name {
  width: 160px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px;
  background: #fafafa; font-size: 14px; outline: none;
}
.cm-name:focus { border-color: var(--accent); background: #fff; }
.cm-row { display: flex; gap: 8px; align-items: flex-end; }
.cm-text {
  flex: 1; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px;
  background: #fafafa; font-size: 14px; font-family: inherit; resize: none; outline: none;
  line-height: 1.5; max-height: 160px;
}
.cm-text:focus { border-color: var(--accent); background: #fff; }
.cm-row .btn { flex: 0 0 auto; }

.comment-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.comment-block { padding: 14px 0; border-bottom: 1px solid var(--line); }
.comment-block:first-child { padding-top: 0; }
.comment-block:last-child { border-bottom: 0; padding-bottom: 0; }
.comment { position: relative; }
/* 대댓글 */
.replies { margin: 10px 0 0 14px; padding-left: 12px; border-left: 2px solid var(--line); display: grid; gap: 12px; }
.replies:empty { display: none; }
.reply-arrow { color: var(--ink-soft); font-weight: 800; margin-right: 2px; }
.reply-btn {
  background: transparent; border: 1px solid var(--line); color: var(--ink-soft);
  font-size: 12px; font-weight: 700; padding: 5px 11px; border-radius: 999px;
}
.reply-btn:hover { border-color: var(--accent); color: var(--accent); }
.reply-form-slot { margin: 8px 0 0 26px; }
.reply-form-slot:empty { display: none; }
.reply-form { display: grid; gap: 8px; }
.comment-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.comment-name { font-size: 14px; font-weight: 800; }
.comment-date { font-size: 12px; color: var(--ink-soft); }
.comment-text { margin: 0; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.comment-empty { margin: 0; color: var(--ink-soft); font-size: 14px; }

/* ===== 카드 통계(조회/좋아요/댓글) ===== */
.ep-stats { margin: 3px 0 0; font-size: 12px; color: var(--ink-soft); }

/* ===== 뷰어 좋아요/조회 바 ===== */
.reader-actions {
  max-width: var(--maxw); margin: 20px auto 0;
  display: flex; align-items: center; justify-content: center; gap: 18px;
}
.like-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
  padding: 10px 20px; border-radius: 999px; font-size: 15px; font-weight: 800;
  transition: transform .08s ease, border-color .15s ease, background .15s ease, color .15s ease;
}
.like-btn:hover { border-color: var(--accent); }
.like-btn:active { transform: scale(.96); }
.like-btn .like-ico { font-size: 18px; line-height: 1; color: var(--accent); }
.like-btn.is-liked { background: var(--accent); border-color: var(--accent); color: #fff; }
.like-btn.is-liked .like-ico { color: #fff; }
.view-stat { color: var(--ink-soft); font-size: 14px; }
.view-stat b { color: var(--ink); font-weight: 800; }

/* ===== 댓글 입력(닉네임/비번) ===== */
.cm-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.cm-name, .cm-pw {
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px;
  background: #fafafa; font-size: 14px; outline: none; font-family: inherit;
}
.cm-name { width: 150px; }
.cm-pw { width: 190px; }
.cm-name:focus, .cm-pw:focus { border-color: var(--accent); background: #fff; }

/* 댓글 버튼/수정 */
.comment-edit, .comment-del {
  background: transparent; border: 1px solid var(--line); color: var(--ink-soft);
  font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 7px;
}
.comment-edit:hover, .comment-del:hover { color: var(--accent); border-color: var(--accent); }
.comment-edited { color: var(--ink-soft); font-size: 11px; }

/* 베스트 댓글 강조 */
.comment.is-best {
  background: #fff6f3;
  border: 1px solid #ffd9cf;
  border-radius: 10px;
  padding: 12px 14px 14px;
  margin-bottom: 2px;
}
.comment.is-best + .comment.is-best { margin-top: 0; }
.best-badge {
  display: inline-block; background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 800; letter-spacing: .04em;
  padding: 2px 7px; border-radius: 999px; margin-right: 2px;
}

/* 댓글 하단 액션바 (추천/비추천 + 수정/삭제) — 한 줄 플렉스, 좁으면 자동 줄바꿈 */
.comment-actions {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 10px;
}
.comment-manage { margin-left: auto; display: flex; gap: 6px; }
.vote-btn {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink-soft);
  font-size: 12px; font-weight: 700; padding: 5px 11px; border-radius: 999px;
  transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.vote-btn:hover { border-color: var(--accent); color: var(--accent); }
.vote-btn.is-on { background: #fff0ec; border-color: var(--accent); color: var(--accent); }
.vote-btn.is-on.down { background: #eef2ff; border-color: #6b7fd6; color: #4457ad; }
.comment.is-editing { padding-bottom: 14px; }
.cm-edit { width: 100%; margin: 4px 0 8px; box-sizing: border-box; }
.comment-editbtns { display: flex; justify-content: flex-end; gap: 8px; }

/* ===== 화 수정 모달 이미지 목록 ===== */
.edit-imgs { display: flex; flex-direction: column; gap: 10px; max-height: 46vh; overflow-y: auto; padding: 2px; }
.edit-img {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: #fafafa;
}
.edit-img img {
  width: 64px; height: 64px; object-fit: cover; border-radius: 7px; background: #eee; flex: 0 0 auto;
}
.edit-img-idx { font-weight: 800; color: var(--ink-soft); font-size: 13px; min-width: 20px; text-align: center; }
.edit-img-ctrl { margin-left: auto; display: flex; gap: 6px; }
.edit-img-ctrl button {
  width: 34px; height: 34px; border: 1px solid var(--line); background: var(--surface);
  border-radius: 8px; font-size: 13px; color: var(--ink); display: grid; place-items: center;
}
.edit-img-ctrl button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.edit-img-ctrl button:disabled { opacity: .35; cursor: default; }
.edit-img-del:hover:not(:disabled) { color: var(--accent) !important; }
.edit-metarow { display: flex; align-items: center; gap: 10px; }
.edit-metamsg { color: #1f9d57; font-size: 13px; font-weight: 700; }

/* 관리자 전용 요소는 로그인 전 숨김(JS가 hidden 토글, CSS는 보조) */
body:not(.is-admin) .admin-only { display: none !important; }

@media (max-width: 480px) {
  .edit-img img { width: 52px; height: 52px; }
  .edit-img-ctrl button { width: 38px; height: 38px; } /* 모바일 탭 영역 확보 */
}

/* ===== 반응형 ===== */
@media (max-width: 560px) {
  .list-head { align-items: stretch; }
  .episode-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
  .brand-name { font-size: 16px; }
  .topnav { margin-left: 8px; }
  .nav-link { padding: 8px 8px; }
  .reader-title { font-size: 19px; }
  .comments { padding: 16px; border-radius: 0; }
  .cat-row .ep-card { flex-basis: 150px; }
}
