:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --text: #191f28;
  --text-2: #4e5968;
  --text-3: #8b95a1;
  --accent: #3182f6;
  --accent-soft: rgba(49, 130, 246, .1);
  --danger: #f04452;
  --danger-soft: rgba(240, 68, 82, .08);
  /* 유리질 표면: 진한 테두리 대신 반투명 흰 테두리 + 이중 그림자로 경계를 만든다 */
  --glass: rgba(255, 255, 255, .82);
  --glass-strong: rgba(255, 255, 255, .94);
  --glass-shadow: inset 0 1px 0 rgba(255,255,255,.85), 0 10px 28px rgba(25,31,40,.08);
  --card-shadow: inset 0 1px 0 rgba(255,255,255,.8), 0 10px 26px rgba(25,31,40,.1);
  --btn-shadow: inset 0 1px 0 rgba(255,255,255,.6), 0 1px 3px rgba(25,31,40,.08);
  --hairline: rgba(25, 31, 40, .07);
  --canvas: #eef0f3;
  --radius: 20px;
  --radius-lg: 24px;
  --radius-sm: 12px;
  --pill: 980px;
  --bar: 60px;
  --side: 232px;
  --font: "Pretendard Variable", -apple-system, BlinkMacSystemFont, "SF Pro Text",
          "Apple SD Gothic Neo", "Segoe UI Variable", "Segoe UI", "Malgun Gothic", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0e0f12;
    --text: #f2f3f5; --text-2: #b0b8c1; --text-3: #7c8794;
    --accent: #4c93ff; --accent-soft: rgba(76,147,255,.16);
    --danger: #ff5b67; --danger-soft: rgba(255,91,103,.12);
    --glass: rgba(28, 30, 36, .72); --glass-strong: rgba(32, 34, 40, .86);
    --glass-shadow: inset 0 1px 0 rgba(255,255,255,.05), 0 10px 28px rgba(0,0,0,.35);
    --card-shadow: inset 0 1px 0 rgba(255,255,255,.05), 0 10px 26px rgba(0,0,0,.4);
    --btn-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 1px 3px rgba(0,0,0,.3);
    --hairline: rgba(255, 255, 255, .08);
    --canvas: #17181c;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 16px/1.6 var(--font);
  -webkit-font-smoothing: antialiased; letter-spacing: -.01em;
}

/* ---------- 전체 골격: 좌측 메뉴바 + 본문 ---------- */
.shell { display: flex; height: 100dvh; background: var(--bg); }
.content { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.scrim { display: none; }

/* ---------- 좌측 메뉴바: 화면에서 떠 있는 유리 패널 ---------- */
.side {
  flex: 0 0 var(--side); width: var(--side); margin: 12px 0 12px 12px;
  border-radius: var(--radius-lg); background: var(--glass);
  box-shadow: var(--glass-shadow); backdrop-filter: blur(20px) saturate(1.9); -webkit-backdrop-filter: blur(20px) saturate(1.9);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.side-top { display: flex; flex-direction: column; gap: 10px; padding: 16px 14px 14px; }
.side-list { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 10px 10px; }
.side-item { display: flex; align-items: center; border-radius: var(--radius-sm); transition: background .12s; }
.side-item:hover { background: rgba(25, 31, 40, .04); }
.side-item.on { background: var(--glass-strong); box-shadow: 0 1px 3px rgba(25,31,40,.1), 0 3px 10px rgba(25,31,40,.07); }
.side-item > a { flex: 1; min-width: 0; display: flex; flex-direction: column;
  padding: 9px 4px 9px 10px; text-decoration: none; color: inherit; }
.side-item .t { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-item .m { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.side-item.on .t { font-weight: 700; }
.side-item .ico { flex: none; background: none; border: none; cursor: pointer; color: var(--text-3);
  padding: 6px 9px; border-radius: 8px; opacity: 0; transition: opacity .12s, background .12s; }
.side-item:hover .ico, .side-item.on .ico, .side-item .ico:focus-visible { opacity: 1; }
.side-item .ico:hover { color: var(--text); background: rgba(25, 31, 40, .08); }
.side-rename { margin: 5px 8px; font-size: 14px; }
.side-empty { color: var(--text-3); font-size: 13px; text-align: center; padding: 30px 12px; }
.side-foot { padding: 12px 14px; }
.badge { font-size: 12px; padding: 3px 9px; border-radius: var(--pill); background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------- 데모 모드 배너 ---------- */
.demo-banner {
  flex: none; padding: 10px 22px; font-size: 13px; line-height: 1.5;
  background: color-mix(in srgb, #ffb300 16%, var(--glass-strong));
  color: var(--text); box-shadow: 0 1px 0 var(--hairline);
}
.demo-banner[hidden] { display: none; }
.demo-banner a { color: var(--accent); font-weight: 600; }

/* ---------- 상단 바 ---------- */
.bar {
  flex: 0 0 var(--bar); display: flex; align-items: center; gap: 12px; padding: 0 22px;
  background: color-mix(in srgb, var(--bg) 75%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 1px 0 var(--hairline);
}
.bar .spacer { flex: 1; }
.bar .title { font-size: 15px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn { display: none; background: none; border: none; cursor: pointer; color: var(--text);
  font-size: 17px; line-height: 1; padding: 6px 8px; border-radius: 8px; }
.menu-btn:hover { background: rgba(25, 31, 40, .06); }

main { flex: 1; min-height: 0; overflow-y: auto; padding: 28px 24px 48px; }
main.wide { padding: 0; overflow: hidden; }
main.upload { display: flex; flex-direction: column; align-items: center; padding: 40px 24px; }

/* ---------- 컨트롤 ---------- */
button, input, select, textarea { font: inherit; color: inherit; }
input[type=text], input[type=search], textarea {
  background: var(--glass-strong); border: 1px solid var(--hairline); border-radius: var(--radius-sm);
  padding: 9px 12px; outline: none; transition: border-color .15s, box-shadow .15s; width: 100%;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 44px; line-height: 1.5; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  background: var(--accent); color: #fff; border: none;
  border-radius: var(--pill); padding: 9px 18px; font-size: 14px; font-weight: 600;
  box-shadow: var(--btn-shadow); cursor: pointer; transition: opacity .15s, transform .1s, background .15s;
}
.btn:hover { opacity: .9; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: default; transform: none; }
.btn.block { justify-content: center; width: 100%; text-decoration: none; }
.btn.quiet { background: var(--glass); color: var(--text); border: none; backdrop-filter: blur(10px); }
.btn.quiet:hover { background: var(--glass-strong); opacity: 1; }
.btn.danger { background: transparent; color: var(--danger); box-shadow: none; }
.btn.danger:hover { background: var(--danger-soft); opacity: 1; }

/* ---------- 업로드 화면 ---------- */
.upload-title { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin: 0 0 20px; align-self: flex-start; max-width: 520px; }
.drop {
  width: 100%; max-width: 520px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px; text-align: center;
  background: linear-gradient(135deg, #eaf2fe, #f1f5ff 55%, var(--glass-strong));
  border-radius: var(--radius); box-shadow: var(--card-shadow);
  padding: 30px 28px; cursor: pointer; transition: box-shadow .15s, transform .1s;
}
.drop:hover { transform: translateY(-1px); }
.drop.over { box-shadow: var(--card-shadow), 0 0 0 3px var(--accent-soft); }
.drop input { display: none; }
.drop-icon { font-size: 24px; line-height: 1; color: var(--accent); }
.drop-title { font-size: 15px; font-weight: 600; }
.drop-sub { font-size: 12.5px; color: var(--text-3); }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; max-width: 520px; }
.thumbs img { height: 64px; border-radius: 8px; border: 1px solid var(--hairline); background: #fff; }
.upload-actions { display: flex; justify-content: flex-end; width: 100%; max-width: 520px; margin-top: 16px; }
.empty { text-align: center; color: var(--text-3); padding: 56px 20px; font-size: 15px; }

/* ---------- 리더 (2분할) ---------- */
.reader { display: grid; grid-template-columns: minmax(320px, 46%) 1fr; height: 100%; min-height: 0; }
.pane-note { background: var(--canvas); display: flex; align-items: center; justify-content: center;
  padding: 20px; overflow: auto; min-width: 0; }
.pane-note img { max-width: 100%; max-height: 100%; border-radius: 14px; background: #fff;
  box-shadow: 0 2px 16px rgba(25,31,40,.14); }
.pane-exp { overflow-y: auto; min-width: 0; padding: 30px 34px 100px; }
/* KaTeX가 넣는 숨은 MathML은 absolute라, 기준을 여기로 묶지 않으면 페이지 전체가 늘어난다 */
.pane-exp .inner { max-width: 68ch; margin: 0 auto; position: relative; }

.pager { display: inline-flex; align-items: center; background: var(--glass);
  border-radius: var(--pill); box-shadow: var(--btn-shadow); overflow: hidden; }
.pager button { background: none; border: none; padding: 6px 13px; cursor: pointer; color: var(--accent); font-size: 15px; }
.pager button:disabled { color: var(--text-3); cursor: default; }
.pager span { padding: 0 4px; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--text-2); min-width: 56px; text-align: center; }

.status-line { display: flex; align-items: center; gap: 9px; color: var(--text-2); font-size: 14px; margin-bottom: 14px; }
.dots::after { content: "···"; animation: dots 1.4s steps(4) infinite; letter-spacing: 2px; }
@keyframes dots { 0% { content: "·"; } 33% { content: "··"; } 66% { content: "···"; } }
.cursor::after { content: "▍"; color: var(--accent); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.error-box { background: var(--danger-soft); color: var(--danger);
  border-radius: var(--radius-sm); padding: 14px 16px; font-size: 14px; }

/* ---------- 좁은 화면: 메뉴바를 서랍으로 ---------- */
@media (max-width: 860px) {
  .side { position: fixed; top: 12px; bottom: 12px; left: 12px; width: 82vw; max-width: 300px; z-index: 40;
    transform: translateX(-130%); transition: transform .22s ease; }
  .shell.side-open .side { transform: none; }
  .shell.side-open .scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(15,17,21,.35); backdrop-filter: blur(2px); }
  .menu-btn { display: inline-flex; }
  main.wide { overflow-y: auto; }
  .reader { grid-template-columns: 1fr; height: auto; }
  .pane-note { max-height: 44vh; }
  .pane-exp { padding: 22px 18px 80px; }
  main.upload { padding: 16px; }
}

/* ---------- 마크다운 ---------- */
.md { font-size: 17px; line-height: 1.72; overflow-wrap: break-word; }
.md > *:first-child { margin-top: 0; }
.md h2 { font-size: 21px; font-weight: 700; letter-spacing: -.015em; margin: 38px 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--hairline); }
.md h3 { font-size: 17px; font-weight: 700; margin: 26px 0 8px; }
.md p { margin: 0 0 14px; }
.md ul, .md ol { margin: 0 0 14px; padding-left: 22px; }
.md li { margin: 5px 0; }
.md blockquote { margin: 14px 0; padding: 14px 18px; background: var(--glass-strong);
  border-radius: var(--radius-sm); color: var(--text); font-size: 16px; box-shadow: var(--card-shadow); }
.md blockquote p:last-child { margin-bottom: 0; }
.md code { font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; font-size: .9em;
  background: var(--glass-strong); padding: 2px 6px; border-radius: 5px; }
.md pre { background: var(--glass-strong); padding: 14px 16px; border-radius: var(--radius-sm); overflow-x: auto; box-shadow: var(--card-shadow); }
.md pre code { background: none; padding: 0; }
.md a { color: var(--accent); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: 15px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--hairline); padding: 7px 12px; text-align: left; }
.md th { background: var(--glass-strong); font-weight: 700; }
.md hr { border: none; border-top: 1px solid var(--hairline); margin: 28px 0; }
.md .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

/* ---------- Q&A (노트 페이지 안 질문, 채팅 패널 둘 다 공유) ---------- */
.qa { margin-top: 44px; padding-top: 26px; border-top: 1px solid var(--hairline); }
.turn { margin-bottom: 26px; }
.q { font-weight: 700; margin-bottom: 8px; display: flex; gap: 8px; }
.q::before { content: "Q"; color: var(--accent); font-weight: 700; }
.ask-box { display: flex; gap: 10px; align-items: flex-end; margin-top: 18px; }

/* ---------- 자유 채팅 패널 ---------- */
.chat-fab {
  position: fixed; right: 24px; bottom: 24px; z-index: 50; width: 52px; height: 52px;
  border-radius: 50%; border: none; background: var(--accent); color: #fff; font-size: 22px;
  box-shadow: var(--btn-shadow), 0 8px 20px rgba(25,31,40,.18); cursor: pointer; transition: transform .1s, opacity .15s;
}
.chat-fab:hover { opacity: .92; }
.chat-fab:active { transform: scale(.94); }
.chat-panel {
  position: fixed; right: 24px; bottom: 88px; z-index: 50; width: min(380px, calc(100vw - 32px));
  height: min(560px, calc(100dvh - 120px)); display: flex; flex-direction: column;
  background: var(--glass-strong); border-radius: var(--radius); box-shadow: var(--glass-shadow);
  backdrop-filter: blur(20px) saturate(1.9); -webkit-backdrop-filter: blur(20px) saturate(1.9); overflow: hidden;
}
.chat-panel[hidden] { display: none; }
.chat-head { flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; font-size: 14px; font-weight: 700; box-shadow: 0 1px 0 var(--hairline); }
.chat-close { background: none; border: none; cursor: pointer; color: var(--text-3); font-size: 15px; padding: 4px 6px; border-radius: 8px; }
.chat-close:hover { background: rgba(25,31,40,.06); color: var(--text); }
.chat-msgs { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; }
.chat-empty { color: var(--text-3); font-size: 13px; text-align: center; padding: 30px 10px; }
.chat-input-row { flex: none; display: flex; gap: 8px; align-items: flex-end; padding: 12px; box-shadow: 0 -1px 0 var(--hairline); }
.chat-input-row textarea { flex: 1; }
@media (max-width: 860px) {
  .chat-panel { right: 16px; left: 16px; width: auto; bottom: 84px; }
  .chat-fab { right: 16px; bottom: 16px; }
}
