:root { display: block !important }

area, base, basefont, datalist, head, link, meta, noembed,
param, rp, script, style, template, title, noframes { display: none }

address, article, aside, blockquote, body, center, dd, details, dialog,
dir, div, dl, dt, figcaption, figure, footer, form, h1, h2, h3, h4,
h5, h6, header, hgroup, hr, html, legend, listing, main, menu, nav,
noscript, ol, p, plaintext, pre, search, section, ul, xmp, frame {
	display: block
}

br[clear=left i] { clear: left }
br[clear=right i] { clear: right }
br[clear=all i], br[clear=both i] { clear: both }

fieldset { display: flow-root }

code { text-decoration: -cha-reverse }
pre code { text-decoration: none }

@media (scripting: enabled) { noscript { display: none } }

textarea, iframe, input, canvas, progress { display: inline-block }

ol, ul, menu, dir { padding-left: 4ch; margin: 1em 0 }
ol > li:nth-child(n+100) { margin-left: 1ch }
ol > li:nth-child(n+1000) { margin-left: 2ch }
ol > li:nth-child(n+10000) { margin-left: 3ch }

:is(ol, ul, menu, dir) :is(ol, ul, menu, dir) {
	margin-top: unset;
	margin-bottom: unset
}

blockquote { margin: 1em }

progress[value] {
	height: 0 !important;
	width: 20ch;
	border-top-style: -cha-hash
}

hr { border-bottom-style: outset; margin: 0 auto }
hr[align=left i] { margin-left: 0; margin-right: auto }
hr[align=right i] { margin-left: auto; margin-right: 0 }
hr[align=center i] { margin-left: auto; margin-right: auto }
hr:is([color], [noshade]) { border-bottom-style: solid }

q::before { content: open-quote }
q::after { content: close-quote }

table {
	display: table;
	border-spacing: 0.5ch 0;
	padding-left: 0.5ch;
	padding-right: 0.5ch;
	box-sizing: border-box
}

table:-cha-border-nonzero,
table:-cha-border-nonzero > tr > :is(td, th),
table:-cha-border-nonzero > :is(thead, tbody, tfoot) > tr > :is(td, th) {
	border-style: solid
}

tbody { display: table-row-group; vertical-align: middle }
thead { display: table-header-group }
tfoot { display: table-footer-group; }
colgroup { display: table-column-group; }
tr { display: table-row; vertical-align: inherit }
col { display: table-column }
th {
	display: table-cell;
	font-weight: bold;
	vertical-align: inherit;
	text-align: -cha-center
}
td { display: table-cell; text-align: unset; vertical-align: inherit }

caption { display: table-caption; text-align: center }
caption[align=top] { caption-side: top }
caption[align=bottom] { caption-side: bottom }

input {
	margin-right: 1ch;
	padding: 0 !important;
	white-space: pre !important;
	color: -cha-ansi(red) !important;
	text-decoration: underline;
	overflow-x: hidden !important;
	text-align: left !important;
	border-style: none -cha-bracket -cha-bracket !important;
	border-color: -cha-ansi(default) -cha-ansi(default) -cha-ansi(red) !important;
	height: 1em !important
}
input::before, input::after { content: '' !important }
input[type=hidden i] { display: none !important }
input:is([type=radio i], [type=checkbox i]) {
	text-decoration: none;
	border-style: none -cha-bracket !important
}
input:is([type=submit i], [type=button i], [type=reset i]) {
	text-decoration: none;
	border-style: none !important
}
input:is([type=submit i], [type=button i], [type=reset i])::before {
	content: '[' !important
}
input:is([type=submit i], [type=button i], [type=reset i])::after {
	content: ']' !important
}

input[type=radio i] { border-style: none -cha-paren !important }

input:is([type=submit i], [type=button i], [type=reset i]), button {
	color: -cha-ansi(red)
}

textarea { color: -cha-ansi(red); white-space: pre }

li, summary { display: list-item }

i, em, address, cite { font-style: italic }

b, strong { font-weight: bold }

u, ins { text-decoration: underline }

h1, h2, h3, h4, h5, h6 { margin: 1em 0; font-weight: bold }
body > :is(p, h1, h2, h3, h4, h5, h6):-cha-first-node { margin-top: 0 }

pre, xmp { margin: 1em 0; white-space: pre }

plaintext { white-space: pre }

nobr { white-space: nowrap }

p { margin: 1em 0 }

@media (prefers-color-scheme: light) {
	a[href] { color: -cha-ansi(blue) }
}
@media (prefers-color-scheme: dark) {
	a[href] { color: -cha-ansi(yellow) }
}
@media (monochrome) {
	a[href] { text-decoration: underline }
	a[href]:hover { font-weight: bold }
}

a[href]::-cha-link-marker {
	counter-increment: -cha-link-counter;
	content: '[' counter(-cha-link-counter) ']';
	white-space: pre
}

::-cha-link-hint {
	all: initial;
	position: absolute;
	background: -cha-ansi(bright-magenta);
	counter-increment: -cha-hint-counter;
	content: counter(-cha-hint-counter, -cha-hint)
}

video, audio, iframe, frame { color: -cha-ansi(red) }

:is(a[href], video, audio, iframe, frame):hover { text-decoration: underline }

sup::before { content: '^' }
sub::before { content: '~' }

:is(ol, ul, menu, dir) ul { list-style-type: circle }
:is(ol, ul, menu, dir) :is(ol, ul, menu, dir) ul { list-style-type: square }

dl { margin: 1em 0 }
:is(ul, ol, dir, menu, dl) dl { margin-bottom: unset }
dt { font-weight: bold }
dd { margin-left: 4ch }
dl[compact] dt + br { display: none }

select, optgroup { display: inline-flex !important; white-space: nowrap !important }
select {
	height: 1em !important;
	border-style: none -cha-bracket !important;
	border-color: initial
}
:is(select, select > optgroup) > option { display: none }
:is(select, select > optgroup) > option:checked {
	height: 1em !important;
	overflow: hidden;
	display: block;
	color: -cha-ansi(red)
}

select[multiple] {
	overflow: auto;
	display: flow-root !important;
	margin-top: 1em
}
select[multiple] { border-style: none !important }
select[multiple] > optgroup { display: flow-root !important }
:is(select[multiple], select[multiple] > optgroup) > option {
	display: flex !important;
	color: initial
}

center { text-align: -cha-center }

blink { text-decoration: blink }

del, s, strike { text-decoration: line-through }

rt::before { content: '（' }
rt::after { content: '）' }

img[align=left i] { float: left }
img[align=right i] { float: right }
img[align=top i] { vertical-align: top }
img[align=middle i], img[align=center i] { vertical-align: middle }
img[align=bottom i] { vertical-align: bottom }

table[align=left i] { float: left }
table[align=right i] { float: right }
table[align=center i] { margin-left: auto; margin-right: auto }

:is(div, p, td, th, thead, tbody, tfoot, tr,
	h1, h2, h3, h4, h5, h6)[align=left i] {
	text-align: -cha-left
}
:is(div, p, td, th, thead, tbody, tfoot, tr,
	h1, h2, h3, h4, h5, h6)[align=center i] {
	text-align: -cha-center
}
:is(div, p, td, th, thead, tbody, tfoot, tr,
	h1, h2, h3, h4, h5, h6)[align=middle i] {
	text-align: -cha-center
}
:is(div, p, td, th, thead, tbody, tfoot, tr,
	h1, h2, h3, h4, h5, h6)[align=right i] {
	text-align: -cha-right
}

:is(td, th, thead, tbody, tfoot, tr)[valign=top i] { vertical-align: top }
:is(td, th, thead, tbody, tfoot, tr)[valign=middle i] { vertical-align: middle }
:is(td, th, thead, tbody, tfoot, tr)[valign=bottom i] { vertical-align: bottom }
:is(td, th, thead, tbody, tfoot, tr)[valign=baseline i] {
	vertical-align: baseline
}

ol { list-style-type: decimal; counter-reset: list-item 0 }
ol[type="1"] { list-style-type: decimal }
ol[type=a s] { list-style-type: lower-alpha }
ol[type=A s] { list-style-type: upper-alpha }
ol[type=i s] { list-style-type: lower-roman }
ol[type=I s] { list-style-type: upper-roman }

ul { list-style-type: disc; counter-reset: list-item 0 }
ul[type=none i] { list-style-type: none }
ul[type=disc i] { list-style-type: disc }
ul[type=circle i] { list-style-type: circle }
ul[type=square i] { list-style-type: square }

@media (-cha-content-type: "text/gemini") {
	a { display: block }
	body { white-space: pre-line }
	a, pre, ul, blockquote, li, h1, h2, h3 { margin-top: 0; margin-bottom: 0 }
}

@media (-cha-content-type: "text/x-ansi") { pre { margin: 0 } }

@media (-cha-content-type: "text/gopher") {
	a[item-type]::before { content: "[unsupported] " }
	a[item-type='0']::before { content: "[text file] " }
	a[item-type='1']::before { content: "[directory] " }
	a[item-type='3']::before { content: "[error] " }
	a[item-type='5']::before { content: "[DOS binary] " }
	a[item-type='7']::before { content: "[search] " }
	a[item-type='m']::before { content: "[message] " }
	a:is([item-type='s'], [item-type='>'])::before { content: "[sound] " }
	a[item-type='g']::before { content: "[gif] " }
	a[item-type='h']::before { content: "[HTML] " }
	a[item-type='I']::before { content: "[image] " }
	a[item-type='9']::before { content: "[binary] " }
	a[item-type='p']::before { content: "[png] " }
	a[item-type=';']::before { content: "[video] " }
}

@media (-cha-content-type: "text/x-dirlist") {
	pre, h1 { margin-top: 0 }
	table { padding: 0; border-spacing: 0 }
	hr { border-bottom-style: -cha-period; min-width: 20ch; margin-right: 1ch }
	a[href] { margin-top: -1em; display: block; margin-right: 1ch }
	a[first] { margin: 0 }
}
