/*
 * Nichan: small-screen fixes that apply on top of every selectable style
 * (dark_nich, ukrchan, futaba, ...). Loaded after the theme stylesheet.
 */

/* Board menu: full links on wide screens, a <select> on phones - in every style, not only dark_nich. */
.mobileShow { display: none; }
.mobileHide { display: inline; }

/* Long words / URLs never widen the page. */
div.post, div.post div.body, .subject, .name, .omitted, blockquote {
	overflow-wrap: break-word;
	word-wrap: break-word;
}
div.post div.body pre, div.post div.body code { white-space: pre-wrap; }
div.post video, div.post img.post-image, div.post iframe, .youtube-player img { max-width: 100%; }

@media only screen and (max-width: 768px) {
	html, body { overflow-x: hidden; }
	body { margin: 0; padding: 0 6px; }
	.mobileShow { display: inline; }
	.mobileHide { display: none; }

	/* Post form: one column, full-width fields. 16px text stops iOS from zooming into inputs. */
	form[name="post"] table, form[name="post"] table tbody, form[name="post"] table tr { display: block; width: 100%; }
	form[name="post"] table th, form[name="post"] table td { display: block; width: auto; text-align: left; padding: 2px 0; }
	form[name="post"] table th { padding-top: 6px; }
	form[name="post"] input[type="text"], form[name="post"] input[type="password"], form[name="post"] input[type="email"],
	form[name="post"] textarea, form[name="post"] select {
		width: 100%;
		max-width: 100%;
		box-sizing: border-box;
		font-size: 16px;
	}
	form[name="post"] textarea { min-height: 8em; }
	form[name="post"] input[type="submit"] { font-size: 16px; padding: 6px 14px; }
	.dropzone { box-sizing: border-box; max-width: 100%; }

	/* Posts use the full width; replies keep only a small indent. */
	div.post.reply { display: block; max-width: 100%; box-sizing: border-box; margin-left: 0; margin-right: 0; }
	div.post.reply.post-hover { max-width: 94vw; }
	div.thread > .post.reply { margin-left: 4px; }
	div.post div.body { margin-left: 0.4em; margin-right: 0.2em; }
	div.post div.file, div.files { max-width: 100%; }
	div.post img.post-image { height: auto; }
	div.post .fileinfo { word-break: break-all; }
	div.post iframe { width: 100% !important; height: auto; aspect-ratio: 16 / 9; }

	/* Easier tapping on post checkboxes, controls and pagination. */
	div.post input.delete[type="checkbox"] { width: 20px; height: 20px; vertical-align: middle; }
	div.post .controls a, div.post .intro a.post_no { padding: 2px 1px; }
	div.pages { line-height: 2.2; }
	div.pages a { padding: 2px 5px; }

	/* Delete / report / moderation bar below the posts. */
	#post-moderation-fields { float: none; text-align: left; margin: 8px 0; }
	#post-moderation-fields input[type="text"], #post-moderation-fields input[type="password"] { max-width: 45vw; font-size: 16px; }
	#mod-mass-fields { margin-top: 6px; line-height: 2; }

	table.modlog, table.mod, .ban-list table { display: block; overflow-x: auto; }
	.box-wrap .box { width: auto !important; float: none !important; margin: 8px 0 !important; }
}

@media only screen and (max-width: 420px) {
	header h1 { font-size: 1.6em; }
	div.post div.body { font-size: 15px; }
}

/* Moderation bar (desktop). */
#mod-mass-fields { margin-top: 6px; padding-top: 4px; border-top: 1px dashed rgba(128, 128, 128, .5); }
#mod-mass-fields button, #mod-mass-fields select, #mod-mass-fields input { margin: 1px 2px; }

/* ---------- Post form editor (js/nichan.js) ---------- */
.nichan-ed-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 3px 8px; margin: 0 0 3px; }
.nichan-ed-modes, .nichan-ed-tools { display: inline-flex; flex-wrap: wrap; gap: 3px; }
.nichan-ed-bar button { font: inherit; font-size: 12px; line-height: 1.4; padding: 2px 7px; min-width: 26px; cursor: pointer; }
.nichan-ed-modes button[aria-pressed="true"] { font-weight: bold; text-decoration: underline; }
.nichan-ed-modes { padding-right: 6px; border-right: 1px solid rgba(128, 128, 128, .5); }
.nichan-ed-visual { box-sizing: border-box; min-width: 300px; min-height: 7.5em; max-height: 45vh; overflow: auto; white-space: pre-wrap;
	word-wrap: break-word; resize: vertical; text-align: left; outline: none; background: #fff; color: #000; border: 1px solid #aaa; }
.nichan-ed-visual:focus { box-shadow: 0 0 0 1px rgba(90, 157, 240, .7); }
.nichan-ed-visual .quote { color: #789922; }
.nichan-ed-visual .spoiler { background: rgba(128, 128, 128, .45); }
.nichan-ed-visual .heading { font-weight: bold; font-size: 1.15em; color: #af0a0f; }
.nichan-ed-visual code { font-family: monospace; background: rgba(128, 128, 128, .2); padding: 0 2px; }
#quick-reply .nichan-ed-visual { min-width: 0; width: 100% !important; }

/* ---------- Post previews ---------- */
.nichan-preview { position: absolute; z-index: 1000; display: block !important; margin: 0 !important; max-height: 70vh; overflow: auto;
	border-style: solid; box-shadow: 1px 2px 6px rgba(0, 0, 0, .5); }
.nichan-preview img.post-image { max-width: 200px; max-height: 200px; height: auto; }

/* ---------- Word filter ---------- */
.nichan-filter-panel { display: block; position: fixed; right: 10px; bottom: 10px; z-index: 1000; text-align: left; margin: 0; padding: 8px 12px; border: 1px solid rgba(128, 128, 128, .6); border-radius: 4px; box-shadow: 0 2px 12px rgba(0, 0, 0, .35); width: 460px; max-width: calc(100vw - 20px); max-height: 70vh; overflow: auto; box-sizing: border-box; }
.nichan-filter-title { font-weight: bold; margin-bottom: 4px; }
.nichan-filter-list { margin: 6px 0 0; padding-left: 18px; }
.nichan-filter-list li { margin: 2px 0; }
.nichan-filtered { margin: 4px 0 4px 1em; font-size: 90%; opacity: .75; font-style: italic; }
.nichan-post-tool { margin-left: 3px; cursor: pointer; }

@media only screen and (max-width: 768px) {
	.nichan-ed-visual { width: 100% !important; min-width: 0; font-size: 16px; }
	.nichan-ed-bar button { font-size: 14px; padding: 4px 9px; }
	.nichan-preview { max-width: calc(100vw - 16px) !important; }
}

/* Standalone pages (FAQ, statistics, /dm/): keep the title clear of the fixed top bar. */
body.active-page > header h1 { margin-top: 1.6em; }
@media only screen and (max-width: 768px) {
	body.active-page > header h1 { margin-top: 2.2em; font-size: 1.5em; }
}

/* Custom tripcodes (imp.php -> Tripcodes) */
.nichan-trip { font-weight: normal; }
.nichan-blink { animation: nichan-blink 1.1s steps(2, start) infinite; }
@keyframes nichan-blink { to { visibility: hidden; } }
@media (prefers-reduced-motion: reduce) { .nichan-blink { animation: none; } }

/* ---------- Inline reply (js/nichan.js) ---------- */
.nichan-inline-reply { margin: 6px 0 10px 2em; padding: 4px 6px; border: 1px dashed rgba(128, 128, 128, .6); display: table; max-width: calc(100% - 2em); box-sizing: border-box; }
.nichan-inline-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; font-size: 90%; }
.nichan-inline-title { flex: 1; font-weight: bold; }
.nichan-inline-reply.detached { position: fixed; right: 12px; bottom: 12px; margin: 0; z-index: 900; max-height: 90vh; overflow: auto;
	background: inherit; box-shadow: 0 4px 18px rgba(0, 0, 0, .5); border-style: solid; }
.nichan-inline-reply.detached .nichan-inline-bar { cursor: move; user-select: none; }
.nichan-inline-reply form[name="post"] { margin: 0; }

/* ---------- Replies, hidden posts, thread updates, embeds ---------- */
.nichan-replies { clear: both; font-size: 85%; margin: 4px 0 2px 0.4em; opacity: .9; }
.nichan-replies em { margin-right: 4px; }
.nichan-filter-panel { padding-right: 28px; }
.nichan-filter-close { position: absolute; top: 2px; right: 4px; font-size: 16px; line-height: 1; padding: 0 5px; cursor: pointer; background: transparent; color: inherit; border: 0; }
.nichan-thread-updates { margin: 8px 0; display: flex; flex-wrap: wrap; gap: 4px 16px; }
.nichan-embed { margin: 6px 0; }
.nichan-embed-open { cursor: pointer; font: inherit; padding: 6px 12px; position: relative; }
.nichan-embed-open.has-thumb { padding: 0; border: 0; background: #000; display: inline-block; }
.nichan-embed-open.has-thumb img { display: block; width: 320px; max-width: 100%; height: auto; opacity: .85; }
.nichan-embed-open.has-thumb span { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); color: #fff;
	background: rgba(0, 0, 0, .65); padding: 6px 14px; border-radius: 6px; white-space: nowrap; }
.nichan-embed iframe { display: block; background: #000; }
@media only screen and (max-width: 768px) {
	.nichan-inline-reply { margin-left: 0; max-width: 100%; display: block; }
	.nichan-inline-reply.detached { left: 4px !important; right: 4px; top: auto !important; bottom: 4px; }
}

/* "Post too long. Click here" - the link must look like a link in every style */
span.toolong a { text-decoration: underline; font-weight: bold; }

/* picture captcha (two words) in the post form */
.nichan-tcaptcha .tc-pic { display: block; min-height: 20px; margin-bottom: 3px; text-decoration: none; }
.nichan-tcaptcha .tc-pic img { display: block; width: 300px; max-width: 100%; height: auto; border-radius: 3px; cursor: pointer; }
.nichan-tcaptcha input[type=text] { width: 300px; max-width: 100%; box-sizing: border-box; }

/* post menu (icon next to the post number) */
/* no taller than the digits of the post number, so the line keeps its height
   (style.css gives every icon in a post 16px, hence the specific selector) */
.nichan-menu-btn { display: inline-block; text-decoration: none; margin-left: 3px; padding: 0 2px; font-size: 10px; line-height: 10px; height: 10px; opacity: .75; }
div.post .nichan-menu-btn i.fa { font-size: 10px; line-height: 10px; margin: 0; vertical-align: top; }
.nichan-menu-btn:hover { opacity: 1; }
.thread-hidden .nichan-menu-btn { display: none; }
.nichan-menu { position: absolute; z-index: 1001; min-width: 170px; padding: 4px 0; border: 1px solid rgba(128, 128, 128, .6); border-radius: 4px; box-shadow: 0 2px 12px rgba(0, 0, 0, .35); }
.nichan-menu a { display: block; padding: 6px 14px; text-decoration: none; white-space: nowrap; }
.nichan-menu a:hover { background: rgba(128, 128, 128, .2); }

/* report / delete dialogs */
.nichan-dialog-back { position: fixed; inset: 0; z-index: 1002; background: rgba(0, 0, 0, .45); display: flex; align-items: center; justify-content: center; padding: 16px; box-sizing: border-box; }
.nichan-dialog { position: relative; width: 380px; max-width: 100%; padding: 12px 16px; border: 1px solid rgba(128, 128, 128, .6); border-radius: 6px; box-shadow: 0 4px 24px rgba(0, 0, 0, .5); box-sizing: border-box; }
.nichan-dialog-title { font-weight: bold; margin: 0 24px 8px 0; }
.nichan-dialog textarea { width: 100%; box-sizing: border-box; }
.nichan-dialog-msg { min-height: 1em; margin-top: 6px; font-weight: bold; }
.nichan-dialog-buttons { margin: 8px 0 0; text-align: right; }
.nichan-dialog-close { position: absolute; top: 4px; right: 6px; font-size: 18px; line-height: 1; padding: 0 5px; cursor: pointer; background: transparent; color: inherit; border: 0; }
.nichan-thread-updates .u-now { text-decoration: none; }

/* replies to your posts: a mark on the post and a counter that jumps from one to the next */
div.post.nichan-to-you { border-left: 3px solid #e0a000 !important; }
.nichan-you-box { position: fixed; left: 10px; bottom: 10px; z-index: 999; padding: 4px 10px; border-radius: 4px; font-size: 13px; text-decoration: none;
	background: #e0a000; color: #1a1a1a !important; box-shadow: 0 2px 8px rgba(0, 0, 0, .35); }
.nichan-saved-toggle.to-you, .nichan-saved-new.to-you { font-weight: bold; }
.nichan-saved-new { opacity: .85; }
