:root {
  --navy: #1e3a5f;
  --navy-2: #2c5282;
  --bg: #f5f6f8;
  --card: #ffffff;
  --line: #e2e6ec;
  --text: #1f2933;
  --muted: #6b7785;
  --accent: #d9480f;
  --danger: #c92a2a;
  --ok: #2b8a3e;
  --side: 210px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.6 system-ui, -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  color: var(--text);
  background: var(--bg);
}
body.noscroll { overflow: hidden; }
a { color: var(--navy-2); }
[hidden] { display: none !important; }

/* top bar */
#top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  height: 52px; padding: 0 16px;
  background: var(--navy); color: #fff;
}
#brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 17px; white-space: nowrap; }
#menuBtn { display: none; background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; padding: 4px 6px; }
#searchForm { display: flex; margin-left: auto; }
#searchForm input {
  width: 220px; padding: 6px 10px; border: 0; border-radius: 6px 0 0 6px; font: inherit;
}
#searchForm button { border: 0; border-radius: 0 6px 6px 0; background: #fff; cursor: pointer; padding: 0 10px; }
#meBox { white-space: nowrap; display: flex; gap: 10px; align-items: center; }
#settingsLink { color: #fff; text-decoration: none; font-size: 18px; }

/* layout */
#layout { display: flex; max-width: 1100px; margin: 0 auto; }
#rooms {
  width: var(--side); flex: none; padding: 16px 8px;
  position: sticky; top: 52px; align-self: flex-start; max-height: calc(100vh - 52px); overflow: auto;
}
#rooms a {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 10px; border-radius: 6px; color: var(--text); text-decoration: none;
}
#rooms a:hover { background: #e9edf3; }
#rooms a.active { background: var(--navy); color: #fff; }
#rooms .group { margin: 14px 10px 4px; font-size: 12px; color: var(--muted); }
#rooms .group::before, #rooms .group::after { content: " ── "; }
.badge {
  min-width: 22px; padding: 0 6px; border-radius: 11px; background: var(--accent); color: #fff;
  font-size: 12px; text-align: center; line-height: 20px;
}
.readall { margin: 16px 10px 0; }
#rooms .readall { width: calc(100% - 20px); }
#main { flex: 1; min-width: 0; padding: 16px; outline: none; }

/* buttons */
.btn, .readall {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px;
  background: #fff; color: var(--text); font: inherit; text-decoration: none; cursor: pointer;
}
.btn:hover, .readall:hover { background: #eef1f5; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-2); }
.btn.small { padding: 1px 8px; font-size: 13px; margin-left: 6px; }
.btn.danger { color: var(--danger); }
.muted { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

.viewhead { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
h1 { font-size: 20px; margin: 4px 0; }
h2 { font-size: 16px; margin: 20px 0 8px; }

/* feed */
.feed { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
.feed li + li { border-top: 1px solid var(--line); }
.feed a {
  display: flex; gap: 12px; align-items: baseline; padding: 10px 14px;
  color: var(--text); text-decoration: none;
}
.feed a:hover { background: #f8f9fb; }
.ftitle { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.froom { color: var(--muted); margin-right: 6px; text-decoration: none; }
.new { margin-right: 4px; }
.fmeta { flex: none; color: var(--muted); font-size: 13px; white-space: nowrap; }
.feed li.unread .tt { font-weight: 700; }
.more { display: block; margin: 12px auto; min-width: 140px; }

/* post */
.posthead { background: var(--card); border: 1px solid var(--line); border-radius: 8px 8px 0 0; padding: 14px 16px 8px; }
.posthead h1 { overflow-wrap: anywhere; }
.pmeta { color: var(--muted); font-size: 13px; }
#main > .body { background: var(--card); border: 1px solid var(--line); border-top: 0; padding: 4px 16px 14px; }
.body { overflow-wrap: anywhere; }
.body img { max-width: 100%; }
.body pre { overflow: auto; background: #f1f3f5; padding: 8px; border-radius: 6px; }
.aiband { background: #e7f0ff; color: var(--navy); border-radius: 8px; padding: 6px 12px; margin-bottom: 8px; font-weight: 600; }
.notice { background: #fff4e6; border: 1px solid #ffd8a8; border-radius: 8px; padding: 10px 14px; margin-bottom: 10px; }
.files { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.thumb {
  display: block; width: 100%; height: auto; max-height: 75vh; object-fit: contain;
  background: #eef1f5; border-radius: 6px; cursor: zoom-in;
}
.chip {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
  padding: 8px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 8px;
}
.chip .fname { overflow-wrap: anywhere; }
.fsize { color: var(--muted); font-size: 13px; }
.clabel { margin-top: 24px; }
.comments { list-style: none; margin: 0; padding: 0; }
.comment { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; margin-bottom: 8px; }
.cmeta { font-size: 13px; color: var(--muted); }
.cmeta b { color: var(--text); }
.comment .body p { margin: 4px 0; }

/* editors */
.cbox, .editor { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.cbox.editing { margin-bottom: 8px; }
.cbox.dragging, .editor.dragging { outline: 3px dashed var(--navy-2); outline-offset: -3px; }
.crow { display: flex; gap: 6px; align-items: flex-start; }
.crow textarea { flex: 1; }
textarea, input[type=text], input[type=email], input[type=search], select {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text);
}
textarea { resize: vertical; width: 100%; }
.editor { display: flex; flex-direction: column; gap: 10px; }
.etitle { width: 100%; font-size: 17px; }
.erow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.erow.end { justify-content: flex-end; }
.uploads { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.uploads:empty { display: none; }
.uploads li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 4px 8px; background: #f8f9fb; border-radius: 6px; }
.uploads li.error { background: #fff0f0; }
.uploads li.error .ustatus { color: var(--danger); }
.uploads progress { flex: 1; min-width: 80px; height: 8px; }
.uthumb { width: 48px; height: 48px; object-fit: cover; border-radius: 4px; }
.ustatus { color: var(--muted); font-size: 13px; }
.cbox .uploads { margin-top: 8px; }

/* search & settings */
.searchbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.searchbar input { flex: 1; min-width: 160px; }
.setrow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.setrow label { width: 60px; font-weight: 600; }
.setrow input { flex: 1; min-width: 140px; }

/* message, fab, viewer */
#msg {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 8px; color: #fff; background: var(--danger);
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
#msg.ok { background: var(--ok); }
#fab { display: none; }
#viewer {
  position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.92);
  display: flex; align-items: center; justify-content: center; cursor: zoom-out;
}
#viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
#backdrop { display: none; }

/* phone */
@media (max-width: 720px) {
  #top { gap: 8px; padding: 0 8px; }
  #menuBtn { display: block; }
  #brand { font-size: 15px; }
  #siteName { display: none; }
  #brand::after { content: "공부방"; }
  #searchForm { min-width: 0; }
  #searchForm input { width: 100%; min-width: 60px; max-width: 140px; }
  #meBox { font-size: 13px; gap: 6px; }
  #rooms {
    position: fixed; top: 52px; left: 0; bottom: 0; z-index: 30; max-height: none; align-self: stretch;
    width: 240px; background: var(--card);
    transform: translateX(-100%); visibility: hidden; transition: transform .2s, visibility .2s;
  }
  body.menu-open #rooms { transform: none; visibility: visible; box-shadow: 2px 0 12px rgba(0,0,0,.15); }
  body.menu-open #backdrop { display: block; position: fixed; inset: 52px 0 0 0; z-index: 25; background: rgba(0,0,0,.3); }
  #main { padding: 12px 10px 88px; }
  .feed a { flex-direction: column; gap: 2px; }
  .ftitle { white-space: normal; overflow-wrap: anywhere; }
  .fmeta { white-space: normal; }
  .write-btn { display: none; }
  #fab:not([hidden]) {
    display: flex; align-items: center; justify-content: center;
    position: fixed; right: 18px; bottom: 22px; z-index: 40;
    width: 58px; height: 58px; border-radius: 50%;
    background: var(--navy); color: #fff; font-size: 32px; line-height: 1; text-decoration: none;
    box-shadow: 0 4px 14px rgba(0,0,0,.3);
  }
  .crow { flex-wrap: wrap; }
  .crow textarea { flex-basis: 100%; }
  .chip .btn.small { margin-left: 0; }
}

/* trash list */
.trashrow { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 10px 14px; }
.feed .trashrow a { display: block; padding: 0; flex: 1; min-width: 0; }
.trashrow .btn.small { margin-left: 0; }
