/*
 * P2 responsive layout.
 *
 * Replaces the old iPhone-only stylesheet (style-iphone.css), which was picked
 * by the browser's user agent and so never reached Android phones or iPads.
 * These rules follow the screen width instead, on every device:
 *
 *   > 1010px  the desktop layout, unchanged
 *   ≤ 1010px  same layout, but fluid instead of a fixed 980px
 *   ≤  800px  one column: the sidebar moves below the posts
 *   ≤  600px  phone: tighter spacing, smaller avatars, collapsible menu and
 *             post form, actions under the post meta
 */

/* Never let long words, links or wide media push the page sideways. */
.postcontent,
.commentcontent,
#sidebar {
	overflow-wrap: anywhere;
}
#main .postcontent img,
#main .commentcontent img {
	max-width: 100%;
	height: auto;
	box-sizing: border-box;
}
#main .postcontent table {
	display: block;
	max-width: 100%;
	overflow-x: auto;
}
#main .postcontent pre {
	max-width: 100%;
	overflow-x: auto;
}

/* Hidden on desktop; shown on phones. */
.menu-toggle {
	display: none;
}


/* =Fluid width (≤ 1010px)
----------------------------------------------- */

@media ( max-width: 1010px ) {
	#header,
	#wrapper,
	#footer {
		width: auto;
		margin-left: 12px;
		margin-right: 12px;
	}
	#post-types {
		/* Keep it a full row, so the avatar below still starts a new line. */
		width: calc( 100% - 60px );
	}
	.post-error {
		width: auto;
	}
}


/* =One column (≤ 800px)
----------------------------------------------- */

@media ( max-width: 800px ) {
	/* The sidebar comes first in the HTML; show it after the posts. */
	#wrapper {
		display: flex;
		flex-direction: column;
		background-image: none; /* The grey sidebar stripe. */
	}
	.sleeve_main {
		order: 1;
		margin-right: 0;
	}
	#sidebar {
		order: 2;
		float: none;
		width: auto;
		margin: 0;
		padding: 6px 14px 18px;
		background: #f7f7f7;
		border-top: 1px solid #e5e5e5;
	}
	#wrapper > .clear {
		order: 3;
	}
	div.entry {
		margin-right: 0;
	}
	#sidebar input[type="text"],
	#sidebar input[type="search"],
	#sidebar select {
		max-width: 100%;
		box-sizing: border-box;
	}
}


/* =Phone (≤ 600px)
----------------------------------------------- */

@media ( max-width: 600px ) {

	/* Header */
	#header {
		min-height: 0;
		margin: 0;
	}
	#header .sleeve {
		display: block;
		margin: 0;
		position: relative;
		box-shadow: none;
		border-bottom: 1px solid #e5e5e5;
	}
	#header h1 {
		font-size: 2.4em;
		padding: 10px 12px 6px;
	}
	#header .p2-branding h1 {
		padding: 0;
	}
	#header small {
		font-size: 1.1em;
		padding: 0 12px 10px;
	}
	#header .p2-branding {
		padding: 10px 12px;
	}

	/* "Post" button in the header: opens the new-post form. */
	.p2-has-postbox #header #mobile-post-button {
		display: inline-block !important;
		position: absolute;
		top: 50%;
		right: 12px;
		transform: translateY( -50% );
		padding: 7px 16px;
		border: 1px solid #3478e3;
		border-radius: 999px;
		background: #3478e3;
		color: #fff;
		font-size: 14px;
		font-weight: bold;
		line-height: 1.2;
	}
	.p2-has-postbox #header #mobile-post-button:hover {
		border-bottom-width: 1px;
	}
	.p2-has-postbox.p2-postbox-open #header #mobile-post-button {
		background: #fff;
		color: #3478e3;
	}
	.p2-has-postbox #header .sleeve {
		padding-right: 84px; /* Room for the button. */
	}

	/* Menu: a "菜单" button that opens a stacked list. */
	.main-navigation {
		float: none;
		margin: 0;
		background: #fff;
		border-bottom: 1px solid #e5e5e5;
	}
	.menu-toggle {
		display: block;
		width: 100%;
		margin: 0 !important;
		padding: 10px 12px;
		border: 0;
		border-radius: 0;
		background: #fff;
		color: #333;
		font-size: 14px;
		text-align: left;
		cursor: pointer;
	}
	.menu-toggle::after {
		content: "";
		display: inline-block;
		margin-left: 8px;
		border-style: solid;
		border-width: 5px 4px 0;
		border-color: #777 transparent transparent;
		vertical-align: middle;
	}
	.site-navigation.is-open .menu-toggle::after {
		border-width: 0 4px 5px;
		border-color: transparent transparent #777;
	}
	.main-navigation .menu,
	.main-navigation div.menu > ul {
		display: none;
		float: none;
	}
	.site-navigation.is-open .menu,
	.site-navigation.is-open div.menu > ul {
		display: block;
	}
	.main-navigation .menu li {
		float: none;
		display: block;
		margin: 0;
		border-top: 1px solid #f0f0f0;
	}
	.main-navigation .menu li a {
		display: block;
		padding: 11px 12px;
		font-size: 15px;
		line-height: 1.4;
	}
	/* Sub-menus: shown inline and indented instead of as hover drop-downs. */
	.main-navigation .menu ul,
	.main-navigation .menu li:hover > ul {
		display: block;
		position: static;
		float: none;
		width: auto;
		box-shadow: none;
		background: transparent;
	}
	.main-navigation .menu li li {
		float: none;
		width: auto;
	}
	.main-navigation .menu li li a {
		padding-left: 28px;
		width: auto;
	}
	.main-navigation .menu li li li a {
		padding-left: 44px;
	}

	/* Page frame */
	#wrapper,
	#footer {
		margin-left: 0;
		margin-right: 0;
		border-left: 0;
		border-right: 0;
		box-shadow: none;
	}
	#wrapper {
		margin-top: 10px;
	}
	#footer {
		margin-top: 10px;
	}
	#main {
		padding-left: 12px;
		padding-right: 12px;
	}

	/* New post form: folded away until "Post" is tapped. */
	.p2-has-postbox #postbox {
		display: none;
	}
	.p2-has-postbox.p2-postbox-open #postbox {
		display: block;
	}
	#postbox {
		padding: 12px;
		border-bottom: 1px solid #e5e5e5;
	}
	#postbox div.avatar {
		display: none;
	}
	#postbox .inputarea {
		padding-left: 0;
	}
	#post-types {
		float: none;
		margin: 0 0 8px;
		width: auto;
		display: flex;
		flex-wrap: wrap;
		gap: 5px;
	}
	#post-types li {
		float: none;
		margin: 0;
	}
	#postbox label#post-prompt {
		float: none;
		max-width: none;
		font-size: 1.3em;
		margin-bottom: 6px;
	}
	#media-buttons {
		top: 0;
		right: 0;
		float: none;
		text-align: left;
		margin-bottom: 6px;
	}
	#postbox textarea#posttext,
	textarea.posttext {
		width: 100%;
		max-width: 100%;
		box-sizing: border-box;
		font-size: 16px; /* 16px stops iOS zooming in on focus. */
	}
	#postbox .postrow {
		height: auto;
		display: flex;
		gap: 8px;
		align-items: center;
	}
	#postbox input#tags {
		float: none;
		width: auto;
		flex: 1;
		min-width: 0;
		font-size: 16px;
	}
	#postbox input#submit {
		float: none;
		margin: 0;
	}

	/* Section titles; "Toggle Comment Threads" etc. under the title */
	#main h2 {
		font-size: 1.6em;
	}
	#main h2 .controls {
		position: static;
		display: block;
		line-height: 1.6;
		text-align: left;
		font-size: 0; /* Hides the "|" separators between the links. */
		margin-top: 4px;
	}
	#main h2 .controls a {
		font-size: 13px;
		margin-right: 14px;
	}
	#main h2 .controls #directions-keyboard {
		display: none; /* No keyboard on a phone. */
	}
	/* The same links on single posts sit above the post instead. */
	.single #main > .controls:not(.p2v-crumbs) {
		font-size: 0;
		text-align: left;
		line-height: 1.6;
	}
	.single #main > .controls:not(.p2v-crumbs) a {
		font-size: 13px;
		margin-right: 14px;
	}
	#main #directions-keyboard {
		display: none;
	}

	/* Posts */
	#main ul#postlist li {
		padding-top: 12px;
	}
	#main ul#postlist > li > a.post-avatar img.avatar,
	#main ul#postlist > li > .post-avatar img.avatar {
		width: 32px;
		height: 32px;
		margin-right: 8px;
	}
	#main h4 {
		margin-left: 40px;
		line-height: 1.4;
	}
	#main h4 .meta {
		display: block;
	}
	#main .actions {
		position: static;
		display: block;
		margin-top: 2px;
	}
	#main .actions a {
		display: inline-block;
		padding: 4px 0; /* Bigger tap targets. */
	}
	.postcontent {
		padding-left: 0;
		clear: left;
	}
	#main .postcontent,
	#main .commentcontent {
		font-size: 15px;
		line-height: 1.6;
	}
	#main .postcontent h2 {
		font-size: 1.4em;
	}
	#main ul#postlist li .tags {
		display: block;
	}

	/* Replies */
	#main ul.commentlist {
		margin-left: 0;
	}
	.commentlist .children li {
		margin-left: 14px;
	}
	#main ul.commentlist img.avatar {
		width: 24px;
		height: 24px;
	}
	#main .inlinecomments h4,
	#main ul.commentlist h4 {
		margin-left: 32px;
	}
	#main #respond,
	#main .commentlist #respond.replying {
		margin-left: 0;
		padding: 12px;
	}
	#main #respond textarea,
	#postpage #respond textarea,
	#postpage li ul #respond textarea {
		width: 100% !important;
		box-sizing: border-box;
		font-size: 16px;
	}
	#respond p.logged-in-as,
	#respond p.must-log-in,
	#respond p.comment-notes {
		position: static;
		margin: 0 0 6px;
	}
	#main .wpl-likebox {
		padding-left: 0 !important;
	}

	/* Older/newer links */
	.navigation p {
		width: auto;
		float: none;
	}
	.navigation p.nav-newer {
		float: none;
		text-align: left;
	}

	/* Video list: two per row */
	#main ul.p2v-grid {
		grid-template-columns: repeat( 2, minmax( 0, 1fr ) );
		gap: 16px 12px;
	}

	/* Keyboard-shortcut help and notices */
	#help {
		display: none !important;
	}
	#notify {
		left: 12px;
		right: 12px;
		width: auto;
	}
}
