/*
Theme Name: TUI Files
Description: superfile 스타일의 터미널(TUI) 워드프레스 테마. 키보드/마우스/터치 모두 지원, 1단·2단 반응형 파일 목록, BBS 스타일 댓글, Markdown 렌더링, 웹폰트 없음.
Version: 1.0.0
Requires at least: 6.0
Requires PHP: 7.4
License: GPL-2.0-or-later
Text Domain: tui-files
*/

/* ───────── 토큰 (Catppuccin Mocha / Latte) ───────── */
:root{
  --bg:#1e1e2e; --bg2:#181825; --bg3:#313244;
  --fg:#cdd6f4; --dim:#a6adc8; --mute:#9399b2; --line:#45475a;
  --acc:#cba6f7; --acc2:#89b4fa; --ok:#a6e3a1; --warn:#f9e2af; --err:#f38ba8; --pink:#f5c2e7;
  --on-acc:#1e1e2e; --ico-s:38%; --ico-l:30%; --ico-fg:#fff;
  --font:"D2Coding","JetBrains Mono","Cascadia Mono","SF Mono",ui-monospace,Menlo,Consolas,"Apple SD Gothic Neo","Malgun Gothic","Noto Sans Mono CJK KR",monospace;
  --hh:3.2rem; --sh:2.6rem;
  color-scheme:dark;
}
:root[data-theme="light"]{
  --bg:#eff1f5; --bg2:#e6e9ef; --bg3:#ccd0da;
  --fg:#4c4f69; --dim:#5c5f77; --mute:#6c6f85; --line:#acb0be;
  --acc:#8839ef; --acc2:#1e66f5; --ok:#2f7d1e; --warn:#a15c07; --err:#d20f39; --pink:#a8328a;
  --on-acc:#eff1f5; --ico-s:55%; --ico-l:82%; --ico-fg:#4c4f69;
  color-scheme:light;
}
@media (prefers-color-scheme:light){
  :root:not([data-theme="dark"]){
    --bg:#eff1f5; --bg2:#e6e9ef; --bg3:#ccd0da;
    --fg:#4c4f69; --dim:#5c5f77; --mute:#6c6f85; --line:#acb0be;
    --acc:#8839ef; --acc2:#1e66f5; --ok:#2f7d1e; --warn:#a15c07; --err:#d20f39; --pink:#a8328a;
    --on-acc:#eff1f5; --ico-s:55%; --ico-l:82%; --ico-fg:#4c4f69;
    color-scheme:light;
  }
}
@media (pointer:coarse){ :root{ --sh:3rem; } }

/* ───────── 기본 ───────── */
*,*::before,*::after{ box-sizing:border-box; }
html{ font-size:15px; -webkit-text-size-adjust:100%; }
@media (min-width:1400px){ html{ font-size:16px; } }
body{
  margin:0; background:var(--bg2); color:var(--fg);
  font:1rem/1.6 var(--font);
  word-break:keep-all; overflow-wrap:anywhere; -webkit-font-smoothing:antialiased;
  padding:0 env(safe-area-inset-right,0px) calc(var(--sh) + env(safe-area-inset-bottom,0px) + .5rem) env(safe-area-inset-left,0px);
}
body.admin-bar{ --ab:32px; }
@media (max-width:782px){ body.admin-bar{ --ab:46px; } }
a{ color:var(--acc2); text-decoration:none; }
a:hover{ text-decoration:underline; }
:focus-visible{ outline:2px solid var(--acc); outline-offset:2px; }
img,video,iframe,svg{ max-width:100%; }
kbd{ font:inherit; }
.sr,.screen-reader-text{ position:absolute!important; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; }
.skip{ position:absolute; left:-999px; top:0; z-index:60; background:var(--acc); color:var(--on-acc); padding:.3rem .7rem; }
.skip:focus{ left:.5rem; top:.5rem; }

.btn{
  font:inherit; color:var(--fg); background:var(--bg3); border:1px solid var(--line); border-radius:6px;
  padding:.15rem .7rem; min-height:2rem; cursor:pointer; text-decoration:none; display:inline-flex; align-items:center; gap:.3rem;
}
.btn:hover{ border-color:var(--acc); text-decoration:none; }
.btn.go{ background:var(--acc); color:var(--on-acc); border-color:var(--acc); font-weight:700; }
@media (pointer:coarse){ .btn{ min-height:2.6rem; } }

/* ───────── 헤더 ───────── */
.bar{
  display:flex; flex-wrap:wrap; align-items:center; gap:.4rem .9rem;
  padding:.7rem 1rem .2rem; padding-top:calc(.7rem + env(safe-area-inset-top,0px));
}
.brand{ color:var(--acc); font-weight:700; white-space:nowrap; margin-right:auto; }
.brand:hover{ text-decoration:none; }
.brand .cur{ animation:blink 1.1s steps(1) infinite; }
@keyframes blink{ 50%{ opacity:0; } }
.tabs{ flex:1 1 100%; order:3; overflow-x:auto; scrollbar-width:none; }
.tabs::-webkit-scrollbar{ display:none; }
.tabs ul{ display:flex; gap:.3rem; margin:0; padding:.1rem 0; list-style:none; counter-reset:t; }
.tabs li{ counter-increment:t; white-space:nowrap; }
.tabs li ul{ display:none; }
.tabs a{ display:block; padding:.15rem .65rem; border:1px solid transparent; border-radius:6px; color:var(--dim); }
.tabs a::before{ content:counter(t) " "; color:var(--mute); }
.tabs a:hover{ text-decoration:none; border-color:var(--line); color:var(--fg); }
.tabs .current-menu-item>a,.tabs .current-menu-ancestor>a,.tabs .current_page_item>a,.tabs .current-cat>a{
  border-color:var(--acc); color:var(--acc);
}
@media (pointer:coarse){ .tabs a{ padding:.45rem .8rem; } }
.find{
  display:flex; align-items:center; gap:.4rem; background:var(--bg); border:1px solid var(--line);
  border-radius:6px; padding:0 .5rem; margin:0;
}
.find:focus-within{ border-color:var(--acc); }
.find label{ color:var(--mute); }
.find input{
  font:inherit; font-size:16px; color:var(--fg); background:transparent; border:0; outline:0;
  width:9.5rem; padding:.3rem 0; min-width:0; box-shadow:none; border-radius:0;
}
@media (min-width:900px){
  .bar{ flex-wrap:nowrap; height:var(--hh); padding-bottom:.7rem; flex:none; }
  .brand{ margin-right:0; }
  .tabs{ order:0; flex:1 1 auto; }
  .find input{ font-size:1rem; }
}

/* ───────── 패널 (superfile 스타일 테두리 + 제목) ───────── */
.layout{ display:grid; gap:1.7rem; padding:1.2rem 1rem 1rem; max-width:1600px; margin:0 auto; width:100%; }
.pane{ position:relative; border:1px solid var(--line); border-radius:10px; background:var(--bg); min-width:0; }
.pane.is-active{ border-color:var(--acc); }
.pane-title,.pane-foot{
  position:absolute; margin:0; padding:0 .5rem; font:inherit; line-height:1.9; z-index:2;
  color:var(--mute); white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
.pane-title{ top:-.95em; left:.9rem; max-width:calc(100% - 1.8rem); font-weight:700; background:linear-gradient(var(--bg2) 50%,var(--bg) 50%); }
.pane-foot{ bottom:-.95em; right:.9rem; background:linear-gradient(var(--bg) 50%,var(--bg2) 50%); }
.pane-foot:empty{ display:none; }
.pane.is-active>.pane-title{ color:var(--acc); }
.pane-body{ min-width:0; }

/* ───────── 파일 목록 ───────── */
.rows{ list-style:none; margin:0; padding:.7rem .45rem .5rem; }
.row{ margin:0; scroll-margin:.6rem 0 calc(var(--sh) + 1.2rem); }
.row-a{
  display:grid; grid-template-columns:2.7rem minmax(0,1fr) auto; gap:.15rem .8rem; align-items:center;
  padding:.35rem .6rem; border-radius:6px; border-left:3px solid transparent; color:var(--fg);
}
.row-a:hover{ text-decoration:none; background:var(--bg2); }
body.show-sel .row.is-sel .row-a{ background:var(--bg3); border-left-color:var(--acc); }
body.show-sel .row.is-sel .t{ color:var(--acc); }
.ico{ width:2.7rem; height:2.7rem; border-radius:6px; overflow:hidden; background:var(--bg3); display:block; }
.ico img{ width:100%; height:100%; object-fit:cover; display:block; }
.ico-t{
  width:100%; height:100%; display:grid; place-items:center; font-weight:700;
  background:hsl(var(--h,260) var(--ico-s) var(--ico-l)); color:var(--ico-fg);
}
.nm{ display:flex; flex-direction:column; min-width:0; }
.t{ white-space:nowrap; overflow:hidden; text-overflow:ellipsis; font-weight:600; }
.pin{ color:var(--warn); }
.m,.side{ color:var(--mute); font-size:.86em; }
.m{ white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.side{ display:flex; flex-direction:column; align-items:flex-end; white-space:nowrap; line-height:1.6; }

.pager{ display:flex; flex-wrap:wrap; gap:.35rem; align-items:center; padding:.5rem 1rem 1rem; color:var(--mute); }
.pager a,.pager .cur,.pager .gap{ padding:.1rem .6rem; border:1px solid var(--line); border-radius:6px; color:var(--fg); }
.pager .gap{ border-color:transparent; color:var(--mute); }
.pager .cur{ border-color:var(--acc); color:var(--acc); }
.pager a:hover{ text-decoration:none; border-color:var(--acc); }
@media (pointer:coarse){ .pager a,.pager .cur{ padding:.45rem .8rem; } }

.empty{ padding:1.2rem 1.4rem; color:var(--dim); margin:0; }
.empty .ps{ color:var(--ok); }
.err{ color:var(--err); }

/* ───────── 미리보기 패널 ───────── */
.pane-preview{ display:none; }
.pv{ padding:1.1rem 1.3rem 1.4rem; }
.pv-img{ width:100%; height:auto; max-height:17rem; object-fit:cover; border-radius:8px; border:1px solid var(--line); display:block; margin-bottom:1rem; }
.pv-t{ margin:0 0 .4rem; font-size:1.2rem; line-height:1.4; color:var(--acc); }
.pv-t::before{ content:"# "; color:var(--mute); }
.pv-x{ color:var(--dim); margin:.9rem 0 1.1rem; line-height:1.75; }
.pv-hint{ color:var(--mute); font-size:.9em; margin:1rem 0 0; }
.pane-list:focus{ outline:none; }
.pv.md{ line-height:1.75; }
.pv-empty{ padding:1.2rem 1.4rem; color:var(--mute); }

/* 데스크톱: 2단 + 패널 내부 스크롤 (진짜 TUI) */
@media (min-width:900px){
  .layout[data-view="list"]{ grid-template-columns:minmax(0,1fr) minmax(0,1fr); grid-template-rows:minmax(0,1fr); }
  .pane-preview{ display:block; }
  body.v-list{ display:flex; flex-direction:column; height:calc(100vh - var(--ab,0px)); height:calc(100dvh - var(--ab,0px)); overflow:hidden; }
  body.v-list .layout{ flex:1; min-height:0; padding-bottom:1.3rem; }
  body.v-list .pane{ display:flex; flex-direction:column; min-height:0; }
  body.v-list .pane-body{ flex:1; min-height:0; overflow:auto; overscroll-behavior:contain; }
  .row{ scroll-margin:.6rem 0; }
}

/* ───────── 글 / 페이지 ───────── */
.layout[data-view="single"],.layout[data-view="page"],.layout[data-view="other"]{ max-width:980px; grid-template-columns:minmax(0,1fr); }
.doc{ padding:1.3rem 1.5rem 1.6rem; }
@media (max-width:600px){ .doc{ padding:1.1rem .95rem 1.3rem; } }
.post-title{ font-size:1.55rem; line-height:1.35; margin:.1rem 0 .5rem; color:var(--acc); }
.post-title::before{ content:"# "; color:var(--mute); }
.fm{ margin:.4rem 0 1.6rem; color:var(--mute); font-size:.9em; line-height:1.7; }
.fm::before,.fm::after{ content:"---"; display:block; color:var(--line); }
.fm>div{ display:flex; gap:.8rem; }
.fm dt{ color:var(--ok); min-width:9ch; }
.fm dt::after{ content:":"; }
.fm dd{ margin:0; color:var(--dim); min-width:0; }
.fm a{ color:var(--acc2); }
.doc-foot{ display:flex; flex-wrap:wrap; gap:.6rem 1.2rem; margin-top:2rem; color:var(--mute); }
.post-nav{ display:flex; justify-content:space-between; gap:1rem; margin-top:1.6rem; padding-top:1rem; border-top:1px dashed var(--line); }
.post-nav a{ max-width:48%; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; color:var(--dim); }
.post-nav .nxt{ margin-left:auto; text-align:right; }
.post-nav b{ color:var(--warn); font-weight:400; }

/* ───────── 본문 (Markdown / 블록 / 클래식 공용) ───────── */
.md{ line-height:1.85; }
.md::after{ content:""; display:table; clear:both; }
.md>:first-child{ margin-top:0; }
.md p{ margin:1em 0; }
.md h1,.md h2,.md h3,.md h4,.md h5,.md h6{ line-height:1.4; margin:2em 0 .6em; color:var(--warn); scroll-margin-top:1rem; }
.md h1{ font-size:1.4rem; } .md h1::before{ content:"# "; color:var(--mute); }
.md h2{ font-size:1.3rem; } .md h2::before{ content:"## "; color:var(--mute); }
.md h3{ font-size:1.15rem; } .md h3::before{ content:"### "; color:var(--mute); }
.md h4{ font-size:1.05rem; } .md h4::before{ content:"#### "; color:var(--mute); }
.md h5,.md h6{ font-size:1rem; } .md h5::before{ content:"##### "; color:var(--mute); } .md h6::before{ content:"###### "; color:var(--mute); }
.md a{ text-decoration:underline; text-underline-offset:.2em; }
.md ul,.md ol{ list-style:none; padding:0; margin:1em 0; }
.md ul>li,.md ol>li{ position:relative; padding-left:2.2ch; margin:.2em 0; }
.md ul>li::before{ content:"-"; position:absolute; left:0; color:var(--mute); }
.md ol{ counter-reset:o; } .md ol>li{ counter-increment:o; padding-left:3.2ch; }
.md ol>li::before{ content:counter(o) "."; position:absolute; left:0; color:var(--mute); }
.md li>ul,.md li>ol{ margin:.2em 0; }
.md blockquote{ margin:1.2em 0; padding:.1em 1em; border-left:3px solid var(--acc); background:var(--bg2); color:var(--dim); border-radius:0 6px 6px 0; }
.md blockquote p{ margin:.6em 0; }
.md code,.md kbd,.md samp{ font-family:inherit; font-size:.95em; }
.md code{ background:var(--bg3); color:var(--pink); padding:.1em .4em; border-radius:4px; }
.md pre{
  background:var(--bg2); border:1px solid var(--line); border-radius:8px; padding:.9em 1em; margin:1.2em 0;
  overflow-x:auto; line-height:1.55; tab-size:4; -webkit-overflow-scrolling:touch;
}
.md pre code{ background:none; padding:0; color:var(--fg); white-space:pre; word-break:normal; overflow-wrap:normal; }
.md kbd{ border:1px solid var(--line); border-bottom-width:2px; border-radius:4px; padding:0 .4em; background:var(--bg2); }
.md mark{ background:var(--warn); color:var(--bg); padding:0 .2em; }
.md hr{ border:0; border-top:1px dashed var(--line); margin:2em 0; }
.md img{ height:auto; border-radius:6px; cursor:zoom-in; }
.md p>img:only-child,.md figure img{ display:block; margin-inline:auto; }
.md figure{ margin:1.4em 0; }
.md figcaption,.md .wp-caption-text{ color:var(--mute); font-size:.9em; text-align:center; margin-top:.4em; }
.md .wp-caption{ max-width:100%; }
.md .tbl,.md figure.wp-block-table{ overflow-x:auto; margin:1.2em 0; -webkit-overflow-scrolling:touch; }
.md table{ border-collapse:collapse; min-width:100%; }
.md th,.md td{ border:1px solid var(--line); padding:.4em .8em; text-align:left; vertical-align:top; }
.md th{ background:var(--bg2); color:var(--warn); }
.md iframe,.md video,.md embed,.md object{ max-width:100%; border:0; border-radius:8px; }
.md iframe[src*="youtube"],.md iframe[src*="youtu.be"],.md iframe[src*="vimeo"],.md iframe[src*="dailymotion"]{ width:100%; height:auto; aspect-ratio:16/9; }
.md audio{ width:100%; }
.md details{ border:1px solid var(--line); border-radius:6px; padding:.4em .9em; margin:1em 0; }
.md summary{ cursor:pointer; color:var(--acc); }
.md .alignleft{ float:left; margin:0 1.2em .6em 0; max-width:50%; }
.md .alignright{ float:right; margin:0 0 .6em 1.2em; max-width:50%; }
.md .aligncenter{ display:block; margin-inline:auto; }
.md .wp-block-gallery,.md .gallery{ display:grid; grid-template-columns:repeat(auto-fill,minmax(9.5rem,1fr)); gap:.6rem; list-style:none; padding:0; margin:1.2em 0; }
.md .wp-block-gallery::before,.md .wp-block-gallery>li::before{ content:none; }
.md .wp-block-gallery figure,.md .gallery-item{ margin:0; width:auto; }
.md .wp-block-gallery img,.md .gallery img{ width:100%; height:100%; object-fit:cover; aspect-ratio:1; }
.md .wp-block-columns{ display:flex; flex-wrap:wrap; gap:1.2rem; }
.md .wp-block-column{ flex:1 1 14rem; min-width:0; }
.md .wp-block-button__link,.md .button{ display:inline-block; padding:.3em 1em; border:1px solid var(--acc); border-radius:6px; color:var(--acc); text-decoration:none; }
.md .footnotes{ font-size:.9em; color:var(--dim); margin-top:2.2em; }
.md .footnotes hr{ margin:0 0 1em; }
.md .footnote-ref{ font-size:.8em; }

/* ───────── 댓글 (BBS) ───────── */
.pane-comments{ margin-top:.6rem; }
.cm-list{ list-style:none; margin:0; padding:.5rem 0; }
.cm{
  position:relative; border-left:3px solid transparent; cursor:default;
  padding:.65rem 1rem .75rem calc(1rem + min(var(--d,0),4)*1.6rem);
  scroll-margin:3rem 0 calc(var(--sh) + 3rem);
}
.cm+.cm{ border-top:1px dashed var(--line); }
.cm.is-sel{ background:var(--bg3); border-left-color:var(--acc); }
.cm-head{ display:flex; flex-wrap:wrap; align-items:baseline; gap:.15rem .9rem; color:var(--mute); font-size:.92em; }
.cm-no{ color:var(--warn); }
.cm-th{ color:var(--mute); margin-right:-.5rem; }
.cm-au{ color:var(--acc2); font-weight:700; }
.cm-op{ color:var(--ok); }
.cm-act{ margin-left:auto; display:flex; gap:.9rem; }
.cm-act a{ color:var(--dim); }
.cm-fold{ font:inherit; background:none; border:0; padding:0; color:var(--mute); cursor:pointer; }
.cm-fold::before{ content:"[-]"; }
.cm.is-folded .cm-fold::before{ content:"[+]"; }
.cm-body{ margin:.35rem 0 0; line-height:1.75; }
.cm-body p{ margin:.3em 0; }
.cm.is-folded .cm-body{ display:none; }
.cm-wait{ color:var(--warn); }
.cm-pg{ padding:.3rem 1rem .8rem; display:flex; gap:.5rem; flex-wrap:wrap; }

#respond{ padding:1rem 1.2rem 1.4rem; border-top:1px solid var(--line); }
.cm-list:empty+#respond{ border-top:0; }
#reply-title{ font-size:1rem; margin:0 0 .8rem; color:var(--ok); font-weight:700; }
#reply-title::before{ content:"$ "; }
#reply-title kbd{ color:var(--mute); font-weight:400; margin-left:.4em; }
#reply-title small{ margin-left:.8em; font-weight:400; }
.fields{ display:grid; grid-template-columns:repeat(auto-fit,minmax(13rem,1fr)); gap:.6rem; margin-bottom:.6rem; }
.f,#respond p{ margin:0 0 .6rem; }
.f{ display:flex; flex-direction:column; gap:.2rem; margin:0; }
.f label,.comment-form-comment label{ color:var(--mute); font-size:.9em; }
#respond input[type=text],#respond input[type=email],#respond input[type=url],#respond input[type=password],#respond textarea{
  font:inherit; font-size:16px; color:var(--fg); background:var(--bg2); border:1px solid var(--line); border-radius:6px;
  padding:.45rem .65rem; width:100%;
}
#respond textarea{ min-height:7.5rem; resize:vertical; line-height:1.6; display:block; }
#respond input:focus,#respond textarea:focus{ outline:none; border-color:var(--acc); box-shadow:0 0 0 1px var(--acc); }
.comment-form-cookies-consent,.f-check{ display:flex; gap:.5rem; align-items:center; color:var(--mute); font-size:.9em; }
.form-submit{ margin:.8rem 0 0!important; display:flex; align-items:center; gap:.8rem; flex-wrap:wrap; }
.hint-line{ color:var(--mute); font-size:.88em; }
.logged-in-as{ color:var(--mute); font-size:.9em; }

/* ───────── 상태바 / 도움말 ───────── */
.status{
  position:fixed; left:0; right:0; bottom:0; z-index:30; display:flex; align-items:center; gap:.6rem;
  height:calc(var(--sh) + env(safe-area-inset-bottom,0px)); padding:0 calc(.6rem + env(safe-area-inset-right,0px)) env(safe-area-inset-bottom,0px) calc(.6rem + env(safe-area-inset-left,0px));
  background:var(--bg3); border-top:1px solid var(--line); overflow-x:auto; white-space:nowrap; scrollbar-width:none;
}
.status::-webkit-scrollbar{ display:none; }
.mode{ background:var(--acc); color:var(--on-acc); font-weight:700; padding:.1rem .65rem; border-radius:4px; flex:none; }
.mode[data-m="INSERT"]{ background:var(--ok); }
.mode[data-m="COMMENTS"]{ background:var(--pink); }
.mode[data-m="READ"]{ background:var(--acc2); }
.mode[data-m="HELP"]{ background:var(--warn); }
.keys{ display:flex; gap:.2rem; margin-left:auto; }
.keys button{
  font:inherit; font-size:.92em; background:none; border:0; border-radius:4px; color:var(--dim);
  padding:.25rem .55rem; cursor:pointer; white-space:nowrap; min-height:1.9rem;
}
.keys button:hover{ background:var(--bg); color:var(--fg); }
.keys kbd{ color:var(--warn); margin-right:.3em; }
@media (pointer:coarse){ .keys button{ min-height:2.5rem; padding:.3rem .8rem; } }

dialog{
  background:var(--bg); color:var(--fg); border:1px solid var(--acc); border-radius:10px; padding:0;
  width:calc(100% - 2rem); max-width:46rem; max-height:calc(100dvh - 3rem);
}
dialog::backdrop{ background:rgba(0,0,0,.55); }
.help{ padding:1rem 1.4rem 1.3rem; overflow:auto; max-height:calc(100dvh - 3rem); }
.help h2{ margin:0 0 .4rem; font-size:1.1rem; color:var(--acc); display:flex; justify-content:space-between; align-items:center; }
.help h3{ margin:1.1rem 0 .3rem; font-size:1rem; color:var(--warn); }
.help dl{ display:grid; grid-template-columns:max-content 1fr; gap:.25rem 1.4rem; margin:0; }
.help dt{ white-space:nowrap; }
.help dd{ margin:0; color:var(--dim); }
.help kbd{ border:1px solid var(--line); border-bottom-width:2px; border-radius:4px; padding:0 .4em; background:var(--bg2); font-size:.92em; margin-right:.2em; }
.help p{ color:var(--dim); margin:.8rem 0 0; }
dialog.lb{ background:transparent; border:0; max-width:96vw; width:auto; max-height:96dvh; }
dialog.lb img{ max-width:96vw; max-height:92dvh; object-fit:contain; border-radius:6px; display:block; cursor:zoom-out; }

@media (prefers-reduced-motion:reduce){ .brand .cur{ animation:none; } *{ scroll-behavior:auto!important; } }
