/* KTC on a phone: loaded after every other stylesheet, so it wins without !important where it can.
   The mobile UI overhaul grows this file; see issue #26.

   The kit, for building a new phone screen out of what's already here:
     colours and sizes   the --kt-* tokens below
     app bar             #chat_head, and .float_top on a page
     tab bar             .ktc_tab in #my_menu
     page                any .sysmenu.float_menu fills the screen above the tab bar
     sheet               overModal / topModal / showModal (a swipe closes it: KtcSheet)
     full screen         the large modal
     list row            .fmenu_item, under a .ktc_settings_label
     actions             .reg_button.theme_btn in a .modal_control: full width and sticky
     balance             .ktc_balance with .ktc_balance_gold, kept true by KtcTabs.mark
     search              .ktc_item_search
*/

:root {
	--kt-ink: #ffffff;
	--kt-muted: #999;
	--kt-faint: #bdb1cb;
	--kt-edge: #14061f;
	--kt-violet: #7a5cff;
	--kt-cyan: #00dbde;
	--kt-pink-dark: #c400c7;
	--kt-teal-dark: #007f81;
	--kt-deep: #1c1430;
	--kt-up: #66e394;
	--kt-danger: #ff8a97;
	--kt-line: rgba(255, 255, 255, 0.08);
	--kt-wash: rgba(255, 255, 255, 0.1);
	--kt-press: rgba(255, 255, 255, 0.12);
	--kt-target: 44px;
	--kt-action: 48px;
	/* zero everywhere except a device with a notch, rounded corners or a home indicator */
	--safe-top: env(safe-area-inset-top, 0px);
	--safe-right: env(safe-area-inset-right, 0px);
	--safe-bottom: env(safe-area-inset-bottom, 0px);
	--safe-left: env(safe-area-inset-left, 0px);
}

/* ── Zoom ── off, by pinch and by double tap: double-tapping a message quotes it and the casino
   buttons get tapped quickly. The viewport tag in head_load.php does the same */
html { touch-action: pan-x pan-y; }

/* ── The page itself never scrolls ── the chat fills the screen and scrolls inside its own panels, but
   on iOS the page could still slide out from under the tab bar and leave a gap. Only the chat has #my_menu */
@media (max-width: 768px), (pointer: coarse) {
	html:has(#my_menu), html:has(#my_menu) body { overflow: hidden; overscroll-behavior: none; }
	html:has(#my_menu) body { position: fixed; inset: 0; }
}

@media (pointer: coarse) {
	/* iOS zooms the page when a field under 16px takes focus */
	input:not([type="checkbox"], [type="radio"], [type="range"], [type="file"]), textarea, select { font-size: 16px !important; }
}

/* ── Safe areas ── main.css sizes these in px and adjustHeight() reads their outerHeight, so the
   chat below them follows */
#chat_head { height: calc(50px + var(--safe-top)); padding: var(--safe-top) max(5px, var(--safe-right)) 0 max(5px, var(--safe-left)); }
#header_full { padding-top: var(--safe-top); }
#my_menu { height: calc(50px + var(--safe-bottom)); padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left); }
.pfull, .pboxed, #player_menu, #station_menu { bottom: var(--tabbar-total, calc(50px + var(--safe-bottom))); }
#left_menu, #chat_left { padding-left: var(--safe-left); }
#container_input, #main_disabled, #main_load, #private_input { padding-left: max(4px, var(--safe-left)); padding-right: max(4px, var(--safe-right)); }
#top_notify { margin-top: var(--safe-top); }
.small_modal_out, .large_modal_out, .over_modal_out, .over_emodal_out, .top_modal_out {
	padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}
.case_stage { padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left); }
@media (max-width: 600px) {
	html .ktc_casino {
		padding: calc(12px + var(--safe-top)) max(16px, var(--safe-right)) calc(16px + var(--safe-bottom)) max(16px, var(--safe-left));
	}
	html #large_modal:has(.ktc_casino) { padding: 0; }
	html .ktc_casino .kc_head { top: var(--safe-top); }
	html .ktc_casino .kc_recent { top: calc(56px + var(--safe-top)); }
}

/* ── Touch targets ── var(--kt-target) on touch screens. Controls in tight rows keep their look and get a larger
   invisible hit area instead */
@media (pointer: coarse) {
	.head_option, .footer_item, .main_item, .private_opt, .panel_bar_item, .panel_option, .left_bar_item, .ftop_action { width: var(--kt-target); }
	.ftop_action, .modal_top_item { height: var(--kt-target); }
	.modal_top_item { width: var(--kt-target); }
	.panel_bar, #chat_right_top { height: 45px; } /* 1px of that is the bar's border */
	#private_top { height: var(--kt-target); }
	.pboxed .pcontent { height: 303px !important; } /* the docked box stays 400px: its top bar and input grew */
	#main_input, #disabled_content, #main_load_content, #message_form { height: var(--kt-target); }
	#left_menu_content { padding-left: 3px; padding-right: 3px; }

	html .modal_menu ul li.modal_menu_item { min-height: var(--kt-target); display: inline-flex; align-items: center; justify-content: center; padding-top: 0; padding-bottom: 0; }
	html .modal_menu_item .wlike_icon { margin-right: 6px; } /* inline-flex drops the space between a reaction and its count */
	.reg_menu ul li { padding: 14px 12px; }
	html .reg_button { min-height: var(--kt-target); }
	html .shop_rarity { min-height: var(--kt-target); }
	.shop_ad_tool { width: var(--kt-target); height: var(--kt-target); }
	html .kc_icon_btn { width: var(--kt-target); height: var(--kt-target); }
	html .cover_item, html .avatar_button { width: var(--kt-target); min-width: var(--kt-target); height: var(--kt-target); }
	html .proitem { height: var(--kt-target); }
	.trade_row .trade_item { width: var(--kt-target); height: var(--kt-target); flex: none; }

	.cclear, .spclear, .tpclear, .plevel_item, .plikepro, .chat_avatar { position: relative; }
	.cclear::after, .spclear::after, .tpclear::after {
		content: ""; position: absolute; top: 50%; left: 50%; width: var(--kt-target); height: var(--kt-target); transform: translate(-50%, -50%);
	}
	.plevel_item::after, .plikepro::after, .chat_avatar::after { content: ""; position: absolute; inset: -7px -2px; }
	.cclear, .spclear, .tpclear { font-size: 14px; }
}

/* ── Loading the chat ── the message list fills its space from the first paint, its messages at its foot, so the
   first ones arriving don't move it; until the first reply a few placeholder rows show it's loading (ktc_mobile.js) */
#show_chat #chat_logs_container { display: flex; flex-direction: column; height: 100%; box-sizing: border-box; }
#show_chat #chat_logs_container > * { flex-shrink: 0; }
#show_chat #chat_logs_container > :first-child { margin-top: auto; }
#show_chat #chat_logs_container:not(.ktc_logs_ready)::after {
	--skel: color-mix(in srgb, currentColor 12%, transparent);
	content: ""; flex: none; height: 280px; max-height: 100%; margin-top: auto;
	background:
		radial-gradient(circle at 28px 28px, var(--skel) 15.5px, transparent 16px) 0 0 / 100% 56px repeat-y,
		linear-gradient(to bottom, transparent 16px, var(--skel) 16px, var(--skel) 26px, transparent 26px) 56px 0 / 28% 56px repeat-y,
		linear-gradient(to bottom, transparent 32px, var(--skel) 32px, var(--skel) 42px, transparent 42px) 56px 0 / 55% 56px repeat-y;
	animation: ktc_skel 1.2s ease-in-out infinite alternate;
}
@keyframes ktc_skel { to { opacity: 0.45; } }
/* the heights adjustHeight() will set, so the list and the input bar are in place before the scripts run: the
   screen less the header (#chat_head), on a phone the tab bar, and for the list the input bar */
@media (min-width: 769px) {
	#chat_center.chatheight { height: calc(100dvh - 50px - var(--safe-top)); }
	#warp_show_chat { height: calc(100dvh - 50px - var(--safe-top) - 49px); }
}
@media (max-width: 768px) {
	#chat_center.chatheight { height: calc(100dvh - 50px - var(--safe-top) - var(--tabbar-total)); }
	#warp_show_chat { height: calc(100dvh - 50px - var(--safe-top) - var(--tabbar-total) - 53px); }
}
@media (prefers-reduced-motion: reduce) {
	#show_chat #chat_logs_container::after { animation: none; }
}

/* ── Readable chat ── */
@media (max-width: 768px) {
	html .chat_message, html .hunter_private, html .target_private { font-size: 15px; line-height: 1.4; }
	html .chat_message > div { min-width: 0; overflow-wrap: anywhere; }
	.my_text .username { font-size: 13px; }
	.cdate { width: 72px; font-size: 12px; }
}

/* ── Press states ── no hover on a finger, so show the press instead */
* { -webkit-tap-highlight-color: transparent; }
.head_option:active, .footer_item:active, .main_item:active, .private_opt:active, .panel_bar_item:active, .panel_option:active,
.left_bar_item:active, .left_menu_item:active, .fmenu_item:active, .proitem:active, .modal_menu_item:active, .modal_top_item:active,
.ftop_action:active, .pgcard:active, .trade_row:active, .bhover:active { background: var(--kt-press); }
@media (hover: none) {
	html :is(.theme_btn, .default_btn, .defaultd_btn, .ok_btn, .warn_btn, .delete_btn):hover { filter: none; }
}
/* send lights up once there is something to send */
#main_input:has(#content:placeholder-shown) .send_btn, #message_form:has(#message_content:placeholder-shown) .send_btn { opacity: 0.45; }
#main_input:has(#content:not(:placeholder-shown)) .send_btn, #message_form:has(#message_content:not(:placeholder-shown)) .send_btn { color: var(--kt-cyan); }

/* ── Message boxes ── textareas that wrap and grow with the text (KtcGrow in js/ktc/ktc_mobile.js), never scroll sideways */
html #main_input, html #message_form { height: auto; min-height: 40px; }
/* only what's typed wraps: the placeholder stays on one line (KtcGrow.label shortens it to fit, with …) */
html :is(#content, #message_content):placeholder-shown { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
html :is(#content, #message_content) {
	display: block; height: 40px; min-height: 40px; max-height: 128px; padding: 9px 12px; line-height: 20px; /* with the 1px border (ktc-shape.css), one line is 40px */
	resize: none; overflow-x: hidden; overflow-y: auto; white-space: pre-wrap; overflow-wrap: anywhere; border-radius: 20px;
}
.pboxed .pcontent { height: calc(310px - var(--ktc-pgrow, 0px)) !important; }
@media (pointer: coarse) {
	html #main_input, html #message_form { min-height: var(--kt-target); }
	html :is(#content, #message_content) { height: var(--kt-target); min-height: var(--kt-target); padding: 11px 12px; border-radius: 22px; }
	.pboxed .pcontent { height: calc(303px - var(--ktc-pgrow, 0px)) !important; }
}

/* ── Quotes in private messages ── one line of what's quoted; a tap goes to that message (findPrivateLog in function_main.js) */
html :is(.hunt_quote, .targ_quote) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
html :is(.hunt_quote, .targ_quote) * { display: inline !important; white-space: nowrap; }
html :is(.hunt_quote, .targ_quote) br { display: none !important; }
html :is(.hunt_quote, .targ_quote) img { max-height: 1.4em; width: auto; vertical-align: middle; }
.ktc_quote_found :is(.hunter_private, .target_private) { animation: ktcQuoteFound 1.6s ease-out; }
@keyframes ktcQuoteFound { from, 40% { box-shadow: 0 0 0 3px var(--kt-cyan); } to { box-shadow: 0 0 0 3px transparent; } }

/* ── Empty states ── */
.empty_zone_action { display: inline-block; margin-top: 12px; width: auto; }
.au_empty { padding: 24px 12px; text-align: center; }
#show_private:empty { width: 100%; }
#show_private:empty::before { content: "No messages yet. Say hello."; display: block; padding: 32px 16px; text-align: center; color: var(--kt-muted); }

/* ── Balance in the shop ── */
.shop_balance { display: flex; align-items: center; gap: 6px; margin: 0 0 0 auto; padding: 4px 10px; border: 1px solid var(--kt-edge); border-radius: 999px; background: rgba(255, 255, 255, 0.06); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.shop_balance img { width: 16px; height: 16px; }
.shop_bar .shop_clear { order: 1; }
.gift_have { margin: 8px 0 0; font-size: 14px; }
.gift_short { margin: 4px 0 0; font-size: 14px; font-weight: 600; color: var(--kt-danger, #ff8a97); }

/* ── Inventory ── names only where there is room for them */
.pgcard_name, .pgcard_rarity { display: none; }
@media (max-width: 640px) {
	/* ── Modal actions ── under the thumb and always in view */
	html .modal_in .modal_control:has(> .reg_button) {
		position: sticky; bottom: 0; z-index: 2; display: flex; flex-direction: column; gap: 8px;
		padding: 12px 16px 16px; background: var(--modal-bg, #191919);
	}
	html .modal_in .modal_control:has(> .reg_button) > .reg_button { width: 100%; min-height: var(--kt-action); margin: 0; }
	html .modal_control:has(> .reg_button) > :is(.theme_btn, .ok_btn, .warn_btn, .delete_btn) { order: -1; }
	html .modal_control:has(> .reg_button) > :is(.default_btn, .defaultd_btn) { background: none; box-shadow: none; }

	html :has(> .pgcard) { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 8px; }
	html .pgcard ~ :not(.pgcard) { grid-column: 1 / -1; }
	html .pgcard { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 4px; float: none; width: auto; height: auto; aspect-ratio: auto; margin: 0; padding: 8px 4px; text-align: center; }
	html .pgcard_img { width: 100%; height: 72px; max-height: 72px; object-fit: contain; }
	html .pgcard_count { top: 4px; right: 4px; bottom: auto; left: auto; }
	html .pgcard_name { display: block; margin: 0; font-size: 13px; font-weight: 600; line-height: 1.2; overflow-wrap: anywhere; }
	html .pgcard_rarity { display: block; margin: 0; font-size: 12px; line-height: 1.2; }
}

/* ── Private messages ── on a phone a conversation is a screen of its own, not a window: back on the
   left, the person, call and more on the right, the input at the bottom. Back is #private_close with
   a new icon; the docked, maximized and minimized modes don't exist here */
.ktc_phone_only { display: none; }
@media (max-width: 768px) {
	#private_center, #private_center.pboxed, #private_center.pfull, #private_center.ppanel {
		position: fixed; inset: 0 !important; z-index: 250; width: 100% !important; max-width: none !important; height: 100% !important; height: 100dvh !important;
	}
	#private_center #private_box { display: flex; flex-direction: column; height: 100%; }
	#private_center #private_top { display: flex; flex: none; align-items: center; gap: 2px; height: var(--appbar-total); padding: var(--safe-top) max(4px, var(--safe-right)) 0 max(4px, var(--safe-left)); }
	#private_center .private_opt { display: flex; flex: none; align-items: center; justify-content: center; width: var(--kt-target); height: var(--kt-target); font-size: 18px; }
	#private_center #private_close { order: -1; }
	#private_close i::before { content: "\f060"; }
	#private_min i::before { content: "\f141"; }
	#private_center :is(#private_boxing, #private_paneling, #priv_minimize, #private_search) { display: none; }
	#private_center #private_call.fhide { display: none; }
	#private_center #private_av_wrap { flex: none; width: 36px; }
	#private_center #private_av { width: 36px; height: 36px; }
	#private_center #private_name { flex: 1; min-width: 0; padding: 0 8px; font-size: 17px; font-weight: 600; }
	#private_center #private_wrap_content { flex: 1; min-height: 0; height: auto !important; }
	#private_center #private_content { height: 100% !important; }
	#private_center #priv_input { flex: none; padding-bottom: var(--safe-bottom); }
	#private_center #private_opt { position: absolute; top: 8px; right: 8px; left: auto; }
	#private_center :is(.hunter_private, .target_private, .hunt_quote, .targ_quote) { max-width: min(78vw, 480px); }
	#dpriv { display: none !important; }

	/* tab pages and the menus opened from them fill the screen above the tab bar */
	.sysmenu.float_menu:not(#private_opt, #player_menu, #station_menu) { position: fixed; inset: 0 0 var(--tabbar-total); z-index: 190; width: 100%; max-width: none; max-height: none !important; margin: 0; border-radius: 0; }
	.sysmenu.float_menu:not(#private_opt, #player_menu, #station_menu) > :is(.float_top, .float_ctop) { position: sticky; top: 0; z-index: 1; min-height: var(--appbar-total); padding: var(--safe-top) 4px 0 8px; background: inherit; }
	.sysmenu.float_menu .ftop_opt_text { font-size: 20px; }
	.sysmenu.float_menu .ftop_action { width: var(--kt-target); height: var(--kt-target); font-size: 18px; }
	.sysmenu.float_menu .fmenu_item { padding: 14px 10px; font-size: 16px; }
	.sysmenu.float_menu .ktc_phone_only { display: table-cell; }
	.sysmenu.float_menu .fmenu_item.ktc_phone_only { display: table; }
	.sysmenu.float_menu .ktc_me_rows { display: block; }
	#private_menu .ktc_list_search { display: block; padding: 8px 12px 0; }
	#private_menu .ktc_list_search input { width: 100%; height: var(--kt-target); padding: 0 14px; }
	#private_menu .float_content { padding: 8px; }
	#private_menu .fmuser { padding: 12px 8px; }
	#private_menu .fmenu_avatar { width: var(--kt-target); height: var(--kt-target); }
	#private_menu .fmenu_avatar img { width: var(--kt-target); height: var(--kt-target); }
	#private_menu .fmenu_name { padding: 0 10px; font-size: 16px; }
	#private_menu .fmenu_option { position: relative; width: var(--kt-target); }
	#private_menu .fmenu_option::after { content: ""; position: absolute; top: -12px; bottom: -12px; left: 0; right: 0; }
}

/* ── The tab bar ── five places, always in reach, in the space the bottom bar already had. The rail,
   both hamburgers and most of the header move here or into Me */
.ktc_tab { display: none; }
/* a desktop: who's here is People in the header, so the bottom bar's ☰ goes, and the bar itself
   with it unless it holds something (the radio, a call or stream, a minimised private chat). Then
   the private box sits on the bottom edge (adjustHeight() leaves the bar out once it's hidden) */
@media (min-width: 769px) {
	#rlist_open { display: none; }
	html:not(:has(#my_menu > .footer_item:not(.streamhide, .privhide, #rlist_open))) #wrap_footer { display: none; }
	html:not(:has(#my_menu > .footer_item:not(.streamhide, .privhide, #rlist_open))) :is(.pfull, .pboxed) { bottom: 0; }
}
@media (max-width: 768px) {
	/* the inset already adds height, so a phone that has one gets iOS's own 44px and 49px bars */
	:root { --appbar-total: max(52px, calc(44px + var(--safe-top))); --tabbar-total: max(56px, calc(49px + var(--safe-bottom))); }
	#my_menu { display: flex; height: var(--tabbar-total); }
	/* Chrome on Android draws its gesture pill over a browser tab: a black strip under the tabs, as the installed app has */
	@supports not (-webkit-touch-callout: none) {
		#my_menu { background: linear-gradient(#000, #000) bottom / 100% var(--safe-bottom) no-repeat; }
	}
	#my_menu > :not(.ktc_tab, #mstream, #mstream_call, #mstream_audio) { display: none !important; }
	#my_menu .ktc_tab { position: relative; display: flex; flex: 1 1 0; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0; padding: 0; border: 0; background: none; color: var(--kt-ink); font: 600 11px/1 var(--ktc-ui-font, inherit); opacity: 0.72; cursor: pointer; }
	#my_menu .ktc_tab i { font-size: 20px; }
	#my_menu .ktc_tab.is_on { opacity: 1; box-shadow: inset 0 -3px 0 var(--kt-ink); }
	#my_menu .ktc_tab:active { background: rgba(255, 255, 255, 0.15); }
	.ktc_tab_dot { display: none; position: absolute; top: 8px; left: calc(50% + 8px); width: 11px; height: 11px; border: 1px solid var(--kt-ink); border-radius: 50%; }
	.ktc_tab.has_dot .ktc_tab_dot { display: block; }
	.ktc_row_dot { display: none; width: 11px; height: 11px; margin-left: auto; border-radius: 50%; }
	.fmenu_item:has(.ktc_row_dot) { position: relative; }
	.ktc_row_dot { position: absolute; top: 50%; right: 14px; transform: translateY(-50%); }

	/* the header: where you are, who's here, what's new */
	#left_menu { display: none !important; }
	#chat_head > .head_option:not(#ktc_people, #ktc_head_wall, :has(#notify_notify)), #main_mob_menu { display: none; }
	#chat_head { height: max(50px, calc(44px + var(--safe-top))); padding-left: max(12px, var(--safe-left)); padding-right: max(4px, var(--safe-right)); }
	#ktc_people, #ktc_head_wall { display: table-cell; }
	.ktc_head_dot { display: none; }
	#empty_top_mob { padding: 0; cursor: pointer; }
	html .ktc_room_title { display: inline-block; max-width: 100%; font-size: 18px; font-weight: 700; vertical-align: middle; }
	#empty_top_mob::after { content: "\f107"; margin-left: 6px; font: 900 13px "Font Awesome 6 Free"; vertical-align: middle; }

	/* panels are screens too */
	#chat_left, #chat_left.cleft2, #chat_right, #chat_right.cright2 { position: fixed; inset: 0 0 var(--tabbar-total) !important; z-index: 195; width: 100% !important; max-width: none !important; height: auto !important; padding-top: var(--safe-top); }
	#chat_left .clheight { height: calc(100dvh - var(--tabbar-total) - var(--safe-top) - 45px) !important; }
	#chat_right .crheight { height: calc(100dvh - var(--tabbar-total) - var(--safe-top) - 45px) !important; }
}

/* the tab bar steps aside while the keyboard is up (js/ktc/ktc_mobile.js) */
@media (max-width: 768px) {
	html.ktc_keyboard { --tabbar-total: 0px; }
	html.ktc_keyboard #my_menu { height: 0; overflow: hidden; padding: 0; }
	html.ktc_keyboard #private_center #priv_input { padding-bottom: 0; }
}

/* ── Sheets ── on a phone modals rise from the bottom, in reach of a thumb, and swipe away
   (KtcSheet, js/ktc/ktc_mobile.js). The large modal (profiles, the casino) takes the whole screen */
@media (max-width: 768px) {
	html :is(.small_modal_out, .over_modal_out, .over_emodal_out, .top_modal_out, .large_modal_out) { padding: 0; overflow: hidden; }
	html :is(.small_modal_in, .over_modal_in, .over_emodal_in, .top_modal_in).modal_in {
		position: absolute; right: 0; bottom: 0; left: 0; width: 100%; max-width: none !important; max-height: calc(100dvh - 24px - var(--safe-top)); margin: 0; padding-top: 0; padding-bottom: var(--safe-bottom);
		overflow-y: auto; overscroll-behavior: contain; border: 0; border-radius: 20px 20px 0 0; animation: ktcSheetUp .24s cubic-bezier(.2, .8, .2, 1);
	}
	html :is(.small_modal_in, .over_modal_in, .over_emodal_in, .top_modal_in).modal_in::before {
		content: ""; position: sticky; top: 8px; z-index: 4; display: block; width: 40px; height: 4px; margin: 8px auto 10px; border-radius: 2px; background: rgba(255, 255, 255, 0.35);
	}
	html .large_modal_in.modal_in { position: absolute; inset: 0; width: 100%; max-width: none !important; min-height: 100%; margin: 0; padding-top: var(--safe-top); overflow-y: auto; overscroll-behavior: contain; border: 0; border-radius: 0; animation: ktcSheetUp .22s cubic-bezier(.2, .8, .2, 1); }
	html #large_modal:has(.ktc_casino) .large_modal_in.modal_in { padding-top: 0; }
	html .modal_in .modal_close { top: 8px; right: 8px; }
	.modal_in.is_dragged { transition: none !important; }
	.modal_in.is_released { transition: transform .2s ease-out; }
}
@keyframes ktcSheetUp { from { transform: translateY(100%); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) {
	html .modal_in { animation: none !important; }
}
@media (max-width: 768px) {
	.ktc_profile_actions { display: block; padding: 12px 16px 4px; }
	html .ktc_profile_actions .reg_button { width: 100%; min-height: var(--kt-action); }
}

/* ── Market ── one screen with four views, under the tab bar: the shop and My items are the over modal,
   trades and auctions the left panel, placed below the hub's own header (KtcMarket) */
#ktc_market { display: none; }
.ktc_item_search { display: none; }
.ktc_nomatch { display: none !important; }
.ktc_balance { display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 4px 10px; border: 1px solid var(--kt-edge); border-radius: 999px; background: var(--kt-line); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ktc_balance img { width: 16px; height: 16px; }
@media (max-width: 768px) {
	:root { --market-top: calc(var(--appbar-total) + 48px); }
	html.ktc_market_on #ktc_market { position: fixed; inset: 0 0 var(--tabbar-total); z-index: 185; display: block; }
	.ktc_market_top { display: flex; align-items: center; justify-content: space-between; height: var(--appbar-total); padding: var(--safe-top) 12px 0 16px; }
	.ktc_market_title { margin: 0; font-size: 20px; font-weight: 700; }
	.ktc_market_segments { display: flex; gap: 4px; height: var(--kt-target); margin: 0 8px; padding: 2px; border-radius: 12px; background: rgba(255, 255, 255, 0.07); }
	.ktc_segment { position: relative; flex: 1 1 0; min-width: 0; padding: 0; border: 0; border-radius: 10px; background: none; color: inherit; font: 600 14px/1 inherit; cursor: pointer; }
	.ktc_segment:active { background: var(--kt-press); }
	.ktc_segment.is_on { background: rgba(255, 255, 255, 0.16); }
	.ktc_segment.has_dot .ktc_tab_dot { display: block; top: 6px; left: auto; right: 6px; }

	html.ktc_market_on #over_modal:has(.ktc_shop, #view_gift_box) { position: fixed; inset: var(--market-top) 0 var(--tabbar-total); z-index: 192; width: auto; height: auto; background: none; }
	html.ktc_market_on #over_modal:has(.ktc_shop, #view_gift_box) .over_modal_in.modal_in { position: absolute; inset: 0; max-height: none; padding-bottom: 0; border-radius: 0; animation: none; background: none; }
	html.ktc_market_on #over_modal:has(.ktc_shop, #view_gift_box) .over_modal_in.modal_in::before { display: none; }
	html.ktc_market_on #over_modal:has(.ktc_shop, #view_gift_box) .modal_close { display: none; }
	html.ktc_market_on #over_modal:has(.ktc_shop, #view_gift_box) .over_modal_in.modal_in { height: auto; }
	html.ktc_market_on #chat_left, html.ktc_market_on #chat_left.cleft2 { inset: var(--market-top) 0 var(--tabbar-total) !important; z-index: 192; padding-top: 0; }
	html.ktc_market_on #chat_left #left_panel_bar { display: none; }
	html.ktc_market_on #chat_left .clheight { height: calc(100dvh - var(--market-top) - var(--tabbar-total)) !important; }
	html.ktc_market_on .shop_balance { display: none; }
	html .ktc_item_search { display: block; width: calc(100% - 16px); height: var(--kt-target); margin: 8px; padding: 0 14px; }

	/* ── Casino ── a lobby of tiles in solid KTC colours with dark edges */
	.ktc_balance_cell { display: table-cell; padding-right: 8px; text-align: right; vertical-align: middle; }
	:is(#game_menu_content, #game_menu .arcade_games_tab) { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
	html :is(#game_menu_content, #game_menu .arcade_games_tab) .fmenu_item { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 124px; padding: 12px; border: 2px solid var(--kt-edge); border-radius: 16px; box-shadow: 0 4px 0 var(--kt-edge); color: var(--kt-ink); text-align: center; background: var(--kt-violet); }
	html :is(#game_menu_content, #game_menu .arcade_games_tab) .fmenu_item:nth-child(4n + 2) { background: var(--kt-pink-dark); }
	html :is(#game_menu_content, #game_menu .arcade_games_tab) .fmenu_item:nth-child(4n + 3) { background: var(--kt-teal-dark); }
	html :is(#game_menu_content, #game_menu .arcade_games_tab) .fmenu_item:nth-child(4n) { background: var(--kt-deep); }
	html :is(#game_menu_content, #game_menu .arcade_games_tab) .fmenu_item:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--kt-edge); }
	html :is(#game_menu_content, #game_menu .arcade_games_tab) .fmenu_img { display: block; width: auto; }
	html :is(#game_menu_content, #game_menu .arcade_games_tab) .fmenu_text { display: block; padding: 0; overflow: visible; font-size: 16px; font-weight: 700; text-shadow: 0 1px 0 var(--kt-edge); }
	html #game_menu .kc_menu_icon { background: none; font-size: 40px; line-height: 1; -webkit-text-fill-color: var(--kt-ink); color: var(--kt-ink); filter: drop-shadow(0 2px 0 var(--kt-edge)); }
}

/* ── Messages ── quieter rows: the date and actions appear on a tap, a name once per run (KtcMessages) */
.log_copy { display: none; }
#logmenu .log_copy { display: block; }
@media (max-width: 768px) {
	#show_chat li.public__message { touch-action: pan-y; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
	#show_chat li.public__message.is_released { transition: transform .2s ease-out; }
	#show_chat li.public__message:not(.ktc_meta) :is(.cdate, .logs_menu) { display: none; }
	#show_chat li.ktc_grouped .chat_avatar img { visibility: hidden; height: 0; }
	#show_chat li.ktc_grouped .chat_avatar { height: 0; }
	#show_chat li.ktc_grouped:not(.ktc_meta) .my_text > .btable:first-child { display: none; }
	/* a run reads as one message: its lines sit close, with the usual space only around the run */
	#show_chat li.ktc_grouped { padding-top: 0; }
	#show_chat li:has(+ li.ktc_grouped) { padding-bottom: 1px; }
	#show_chat li.ktc_grouped .chat_message { padding-top: 1px; }
	#show_chat li.ktc_grouped :is(.cavatar, .chat_avatar) { height: 0; min-height: 0; }
}

/* ── Item card ── one main action, the rest a quiet row, Discard furthest away */
@media (max-width: 768px) {
	html .modal_in #item_card_actions { flex-direction: row; flex-wrap: wrap; gap: 8px; }
	html .modal_in #item_card_actions > .reg_button { flex: 1 1 0; width: auto; min-width: 0; min-height: var(--kt-action); padding: 0 8px; }
	html .modal_in #item_card_actions > .reg_button.theme_btn:not(.theme_btn ~ .theme_btn) { flex: 1 0 100%; order: -1; }
	html .modal_in #item_card_actions > .reg_button.theme_btn ~ .theme_btn, html .modal_in #item_card_actions > .reg_button.default_btn:not(.item_discard, .close_top) {
		background: var(--kt-wash); box-shadow: none; color: var(--kt-ink); text-shadow: none;
	}
	html .modal_in #item_card_actions > .item_discard { flex: 1 0 100%; order: 9; margin-top: 8px; }
	html .modal_in #item_card_actions > .item_discard:not(.item_discard_armed) { background: none; box-shadow: none; color: var(--kt-danger); }

	/* ── Trades ── You give above You get, the items at a real size with their names, and an Add tile
	   in place of a wall of empty slots */
	html .trade_sides { flex-direction: column; align-items: stretch; gap: 8px; }
	html .trade_side { width: 100%; flex: none; text-align: left; }
	html .trade_side_title { margin: 0 0 8px; font-weight: 700; }
	html .trade_swap { align-self: center; padding: 0; font-size: 14px; transform: rotate(90deg); }
	html .trade_grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 32px 8px; max-width: none; margin: 0 0 32px; }
	html .trade_grid > .trade_slot { display: none; }
	html .trade_grid > .trade_item { position: relative; width: 100%; }
	html .trade_grid > .trade_item::after { content: attr(data-name); position: absolute; top: calc(100% + 6px); left: -4px; right: -4px; overflow: hidden; color: var(--kt-ink); font-size: 11px; font-weight: 600; line-height: 1.2; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
	html .trade_compose .trade_grid > .trade_slot:first-child, html .trade_compose .trade_grid > .trade_item + .trade_slot { position: relative; display: block; cursor: pointer; }
	html .trade_compose .trade_grid > .trade_slot:first-child::before, html .trade_compose .trade_grid > .trade_item + .trade_slot::before { content: "+"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--kt-faint); font-size: 26px; }
	html .trade_window:not(.trade_compose) .trade_grid:not(:has(.trade_item)) { display: block; margin-bottom: 8px; }
	html .trade_window:not(.trade_compose) .trade_grid:not(:has(.trade_item))::before { content: "Nothing"; color: var(--kt-muted); font-size: 14px; }
	html .trade_gold { max-width: none; justify-content: flex-start; margin-top: 0; }
	html .trade_gold img { display: inline-block; }
	html .trade_gold input { max-width: 180px; text-align: left; padding: 0 12px; }
	html .trade_inventory { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); max-height: none; overflow: visible; }

	/* ── Auctions ── no scrolling box inside a scrolling sheet, larger items, and a listing fills the screen */
	html .au_pick_groups, html .au_pick_grid { max-height: none; overflow: visible; }
	html .au_pick_grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
	html .au_row { gap: 12px; min-height: 76px; padding: 6px 8px; }
	html .au_row_item { flex: 0 0 64px; width: 64px; }
	html .over_modal_in.modal_in:has(.au_view) { top: 0; max-height: none; padding-top: calc(16px + var(--safe-top)); border-radius: 0; }
	html .over_modal_in.modal_in:has(.au_view)::before { display: none; }
	html .au_view_head { flex-direction: column; align-items: center; gap: 16px; text-align: center; }
	html .au_view_item { flex: 0 0 auto; width: 160px; }
	html .au_bid_row { flex-direction: column; }
	html .au_bid_row .reg_button { width: 100%; min-height: var(--kt-action); }
	html .au_bid_row input { width: 100%; height: var(--kt-action); }
}

/* ── Between tabs ── the screen slides the way the tabs are laid out, the tab bar stays still (KtcTabs.slide).
   The Market's views load after the slide, so they fade in as they arrive */
@media (max-width: 768px) {
	#wrap_footer { view-transition-name: ktc-tabs; }
	::view-transition-group(ktc-tabs) { animation: none; }
	::view-transition-old(ktc-tabs), ::view-transition-new(ktc-tabs) { animation: none; }
	html[data-tab-slide]::view-transition-old(root) { animation: .24s cubic-bezier(.2, .8, .2, 1) both ktcTabOut; }
	html[data-tab-slide]::view-transition-new(root) { animation: .24s cubic-bezier(.2, .8, .2, 1) both ktcTabIn; }
	html[data-tab-slide="forward"] { --tab-slide-in: 28px; --tab-slide-out: -28px; }
	html[data-tab-slide="back"] { --tab-slide-in: -28px; --tab-slide-out: 28px; }
	html.ktc_market_on #over_modal:has(.ktc_shop, #view_gift_box) .over_modal_in.modal_in { animation: ktcTabFade .18s ease-out; }
	html.ktc_market_on #chat_left { animation: ktcTabFade .18s ease-out; }
}
/* ── Pages and sheets ── a page comes in from the right and leaves the same way, a sheet goes back down the
   way it came up (KtcMotion). .ktc_ghost is a copy of what just closed, there only while it moves */
@media (max-width: 768px) {
	/* the chat's showMenu() hides every .sysmenu it finds, these copies included */
	.ktc_ghost { display: block !important; pointer-events: none !important; }
	.ktc_ghost_hold { z-index: 189 !important; }
	/* a conversation covers the whole screen, and a video opened from it has to come out on top */
	html:has(#private_center:not(.privhide)) .streamers { z-index: 255; }
	/* Swipes (KtcSwipe): sideways is ours everywhere except what scrolls that way itself */
	html:has(#my_menu) body { touch-action: pan-y; }
	.shop_filter_list, .case_inside_list { touch-action: pan-x pan-y; }
	.ktc_swiping { box-shadow: -8px 0 24px rgba(0, 0, 0, 0.45); }
	.ktc_swipe_next#ktc_market { position: fixed; inset: 0 0 var(--tabbar-total); z-index: 186; }
	.ktc_swipe_settle { transition: transform .2s cubic-bezier(.2, .8, .2, 1); }
}
@media (max-width: 768px) and (prefers-reduced-motion: no-preference) {
	.ktc_enter { animation: ktcPageIn .24s cubic-bezier(.2, .8, .2, 1) backwards; }
	.ktc_ghost_page { animation: ktcPageOut .24s cubic-bezier(.2, .8, .2, 1) both; }
	.sysmenu.ktc_ghost_page { z-index: 191 !important; } /* over the page it uncovers */
	.ktc_ghost_sheet { animation: ktcTabFadeOut .24s ease-out both; }
	html .ktc_ghost_sheet .modal_in { animation: ktcSheetDown .24s cubic-bezier(.2, .8, .2, 1) both !important; }
}
@keyframes ktcPageIn { from { transform: translateX(100%); } to { transform: none; } }
@keyframes ktcPageOut { from { transform: none; } to { transform: translateX(100%); } }
@keyframes ktcSheetDown { from { transform: none; } to { transform: translateY(100%); } }
@keyframes ktcTabFadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes ktcTabIn { from { opacity: 0; transform: translateX(var(--tab-slide-in, 28px)); } to { opacity: 1; transform: none; } }
@keyframes ktcTabOut { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateX(var(--tab-slide-out, -28px)); } }
@keyframes ktcTabFade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
	html.ktc_market_on #over_modal:has(.ktc_shop, #view_gift_box) .over_modal_in.modal_in, html.ktc_market_on #chat_left { animation: none; }
}

/* ── Settings ── one grouped page, on a phone and on a desktop; the old profile editor keeps only your picture and cover */
#setting_menu .ktc_settings_group { display: block; margin-top: 8px; }
#setting_menu .ktc_settings_label { display: block; margin: 16px 10px 4px; color: var(--kt-muted); font-size: 13px; font-weight: 600; }
#setting_menu .float_content > .ktc_settings_group:first-child .ktc_settings_label { margin-top: 4px; }
#setting_menu .ktc_settings_danger { margin-top: 32px; padding-top: 8px; border-top: 1px solid var(--kt-wash); }
#setting_menu .ktc_settings_danger .fmenu_item, #setting_menu .ktc_settings_danger i { color: var(--kt-danger); }
@media (max-width: 768px) {
	/* the Games tab: the arcade's games, then the casino's, under their own labels */
	.sysmenu.float_menu .ftop_opt_text .ktc_phone_only { display: inline; }
	.ktc_desktop_only { display: none; }
	.sysmenu.float_menu .ktc_settings_label, .sysmenu.float_menu .ktc_phone_only.ktc_settings_label { display: block; margin: 16px 10px 4px; color: var(--kt-muted); font-size: 13px; font-weight: 600; }
	.sysmenu.float_menu .ktc_settings_label:first-child { margin-top: 4px; }
	.sysmenu.float_menu .fmenu_item.ktc_phone_only.nogranted { display: none; }
	#chat_main_menu .room_granted { display: none !important; }
	#large_modal:has(#personal_account) #meditprofile, #large_modal:has(#personal_account) .modal_menu { display: none; }
	/* a profile's labels stay quieter than what they label */
	#probio .proitem .bold { color: var(--kt-muted); font-weight: 500; }
	#probio .proitem .prodata { color: var(--kt-ink); font-weight: 600; }
}
@media (pointer: coarse) {
	html .avatar_control { left: 6px; width: 88px; }
}

/* ── Menus ── the + menu says what it holds, emoji can be searched, popovers rise as sheets, toasts
   stay clear of the header, and the wallet says where gold goes */
.ktc_emo_search, .ktc_emo_recent:empty, .ktc_option_name { display: none; }
/* what you used last, above the picker's emoji and the same size as them (24px; 34px on a phone, below) */
.ktc_emo_recent:not(:empty) { display: flex; gap: 2px; padding: 0 5px 6px; overflow: hidden; border-bottom: 1px solid var(--kt-line); }
.ktc_emo_recent .emoticon { flex: none; width: auto; height: 24px; }
.ktc_emo_recent .emoticon img { display: block; height: 100%; width: auto; max-width: 48px; object-fit: contain; }
/* the panels are as tall as what's in them (they grow up from the input bar), so the recent row adds to them instead of pushing the emoji out the bottom */
html :is(#main_emoticon, #private_emoticon) { height: auto; }
@media (max-width: 768px) {
	html :is(#main_input_extra, #priv_input_extra) { width: calc(100% - 16px); max-width: none; margin: 8px; padding: 8px; }
	html :is(.sub_options, .psub_options) { float: none; display: inline-flex; vertical-align: top; flex-direction: column; align-items: center; justify-content: flex-start; gap: 4px; width: 64px; height: auto; margin: 0; padding: 6px 2px; }
	html :is(.sub_options, .psub_options):hover { padding: 6px 2px; }
	html :is(.sub_options, .psub_options) img { width: 40px; height: 40px; object-fit: contain; }
	.ktc_option_name { display: block; font-size: 12px; font-weight: 600; text-align: center; }
	.ktc_emo_search { display: block; width: calc(100% - 16px); height: var(--kt-target); margin: 8px; padding: 0 14px; }
	.ktc_emo_recent .emoticon { width: 34px; height: 34px; }
	/* a phone adds a search box as well, so the emoji scroll inside a shorter grid */
	html :is(.emo_content, .emo_content_priv) { height: min(220px, 32vh); box-sizing: border-box; }

	#av_menu[style*="left"]:not([style*="-5000"]), #log_menu[style*="left"]:not([style*="-5000"]) {
		position: fixed !important; top: auto !important; right: 0 !important; bottom: var(--tabbar-total) !important; left: 0 !important; z-index: 260; width: 100% !important; border-radius: 20px 20px 0 0; box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.6);
	}
	

	#top_notify { top: calc(58px + var(--safe-top)) !important; right: 8px; left: 8px; width: auto; max-width: none; margin-top: 0; }
	#top_notify .top_notify { width: 100%; max-width: none; }

	html .ktc_room_title { max-width: calc(100% - 22px); }
	#empty_top_mob { white-space: nowrap; }

	#bank_menu .ktc_settings_label { margin-top: 20px; }
	.ktc_wallet_row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; padding: 8px 10px; border-bottom: 1px solid rgba(255, 255, 255, 0.05); }
	.ktc_wallet_row p { margin: 0; }
	.ktc_wallet_game { font-weight: 600; }
	.ktc_wallet_net { font-weight: 700; font-variant-numeric: tabular-nums; }
	.ktc_wallet_net.is_up { color: var(--kt-up); }
	.ktc_wallet_net.is_down { color: var(--kt-danger); }
}

/* ── Type ── headings keep their last line from being one word, words in text that are links look like links, labels are quieter than what they label */
@media (max-width: 768px) {
	html :is(h1, h2, h3, .modal_title, .kc_title) { text-wrap: balance; }
	html :is(.chat_message, .hunter_private, .target_private, .modal_content p) a:not([data-fancybox], [download]) { color: var(--kt-cyan); text-decoration: underline; text-underline-offset: 2px; }
	html .label { color: var(--kt-faint); font-weight: 500; }
}

/* ── Focus ── main.css removes every outline; keyboards and switch access need one. Fields keep their
   own focus border, and a dialog taking focus when it opens shows nothing */
html :focus-visible { outline: 2px solid var(--kt-cyan) !important; outline-offset: 2px; }
html :is(input, textarea, select):focus-visible, html .modal_in:focus { outline: none !important; }
/* the first Tab stop on a desktop: skips to the message box (js/ktc/ktc_mobile.js), out of sight until it has focus */
#ktc_skip { position: fixed; top: 8px; left: 8px; z-index: 10000; padding: 10px 16px; border: 2px solid #14061f; border-radius: 10px; background: #ffffff; color: #14061f; font: 700 15px/1.2 var(--ktc-ui-font, inherit); cursor: pointer; transform: translateY(-200%); }
#ktc_skip:focus { transform: none; }
@media (max-width: 768px) {
	#ktc_skip { display: none; }
}
/* a desktop: each message's actions button (…) is a 32px target, not 24×18. It sits 5px under the top of
   its row, which clips what leaves it, so the target starts at the row's edge and reaches down */
@media (min-width: 769px) {
	html .cclear { position: relative; z-index: 1; }
	html .cclear::after { content: ""; position: absolute; top: -5px; left: 50%; width: 32px; height: 32px; transform: translateX(-50%); }
}
